Skip to content

Commit 63806d5

Browse files
Added support for Stata's Ado and Mata (#3383)
1 parent ca78cde commit 63806d5

33 files changed

+1195
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@
861861
"require": "markup",
862862
"owner": "Golmote"
863863
},
864+
"mata": {
865+
"title": "Mata",
866+
"owner": "RunDevelopment"
867+
},
864868
"matlab": {
865869
"title": "MATLAB",
866870
"owner": "Golmote"
@@ -1313,6 +1317,11 @@
13131317
"title": "Stan",
13141318
"owner": "RunDevelopment"
13151319
},
1320+
"stata": {
1321+
"title": "Stata Ado",
1322+
"require": ["mata", "java", "python"],
1323+
"owner": "RunDevelopment"
1324+
},
13161325
"iecst": {
13171326
"title": "Structured Text (IEC 61131-3)",
13181327
"owner": "serhioromano"

components/prism-mata.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// https://www.stata.com/manuals/m.pdf
2+
3+
(function (Prism) {
4+
5+
var orgType = /\b(?:(?:col|row)?vector|matrix|scalar)\b/.source;
6+
var type = /\bvoid\b|<org>|\b(?:complex|numeric|pointer(?:\s*\([^()]*\))?|real|string|(?:class|struct)\s+\w+|transmorphic)(?:\s*<org>)?/.source
7+
.replace(/<org>/g, orgType);
8+
9+
Prism.languages.mata = {
10+
'comment': {
11+
pattern: /\/\/.*|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\*\//,
12+
greedy: true
13+
},
14+
'string': {
15+
pattern: /"[^"\r\n]*"|[`']".*?"[`']/,
16+
greedy: true
17+
},
18+
19+
'class-name': {
20+
pattern: /(\b(?:class|extends|struct)\s+)\w+(?=\s*(?:\{|\bextends\b))/,
21+
lookbehind: true
22+
},
23+
'type': {
24+
pattern: RegExp(type),
25+
alias: 'class-name',
26+
inside: {
27+
'punctuation': /[()]/,
28+
'keyword': /\b(?:class|function|struct|void)\b/
29+
}
30+
},
31+
'keyword': /\b(?:break|class|continue|do|else|end|extends|external|final|for|function|goto|if|pragma|private|protected|public|return|static|struct|unset|unused|version|virtual|while)\b/,
32+
'constant': /\bNULL\b/,
33+
34+
'number': {
35+
pattern: /(^|[^\w.])(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|\d[a-f0-9]*(?:\.[a-f0-9]+)?x[+-]?\d+)i?(?![\w.])/i,
36+
lookbehind: true
37+
},
38+
'missing': {
39+
pattern: /(^|[^\w.])(?:\.[a-z]?)(?![\w.])/,
40+
lookbehind: true,
41+
alias: 'symbol'
42+
},
43+
44+
'function': /\b[a-z_]\w*(?=\s*\()/i,
45+
46+
'operator': /\.\.|\+\+|--|&&|\|\||:?(?:[!=<>]=|[+\-*/^<>&|:])|[!?=\\#`']/,
47+
'punctuation': /[()[\]{},;.]/
48+
};
49+
50+
}(Prism));

components/prism-mata.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-stata.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// https://www.stata.com/manuals/u.pdf
2+
// https://www.stata.com/manuals/p.pdf
3+
4+
Prism.languages.stata = {
5+
'comment': [
6+
{
7+
pattern: /(^[ \t]*)\*.*/m,
8+
lookbehind: true,
9+
greedy: true
10+
},
11+
{
12+
pattern: /(^|\s)\/\/.*|\/\*[\s\S]*?\*\//,
13+
lookbehind: true,
14+
greedy: true
15+
}
16+
],
17+
'string-literal': {
18+
pattern: /"[^"\r\n]*"|[`']".*?"[`']/,
19+
greedy: true,
20+
inside: {
21+
'interpolation': {
22+
pattern: /\$\{[^{}]*\}|[`']\w[^`'\r\n]*[`']/,
23+
inside: {
24+
'punctuation': /^\$\{|\}$/,
25+
'expression': {
26+
pattern: /[\s\S]+/,
27+
inside: null // see below
28+
}
29+
}
30+
},
31+
'string': /[\s\S]+/
32+
}
33+
},
34+
35+
'mata': {
36+
pattern: /(^[ \t]*mata[ \t]*:)[\s\S]+?(?=^end\b)/m,
37+
lookbehind: true,
38+
greedy: true,
39+
alias: 'language-mata',
40+
inside: Prism.languages.mata
41+
},
42+
'java': {
43+
pattern: /(^[ \t]*java[ \t]*:)[\s\S]+?(?=^end\b)/m,
44+
lookbehind: true,
45+
greedy: true,
46+
alias: 'language-java',
47+
inside: Prism.languages.java
48+
},
49+
'python': {
50+
pattern: /(^[ \t]*python[ \t]*:)[\s\S]+?(?=^end\b)/m,
51+
lookbehind: true,
52+
greedy: true,
53+
alias: 'language-python',
54+
inside: Prism.languages.python
55+
},
56+
57+
58+
'command': {
59+
pattern: /(^[ \t]*(?:\.[ \t]+)?(?:(?:bayes|bootstrap|by|bysort|capture|collect|fmm|fp|frame|jackknife|mfp|mi|nestreg|noisily|permute|quietly|rolling|simulate|statsby|stepwise|svy|version|xi)\b[^:\r\n]*:[ \t]*|(?:capture|noisily|quietly|version)[ \t]+)?)[a-zA-Z]\w*/m,
60+
lookbehind: true,
61+
greedy: true,
62+
alias: 'keyword'
63+
},
64+
'variable': /\$\w+|[`']\w[^`'\r\n]*[`']/,
65+
'keyword': /\b(?:bayes|bootstrap|by|bysort|capture|clear|collect|fmm|fp|frame|if|in|jackknife|mi[ \t]+estimate|mfp|nestreg|noisily|of|permute|quietly|rolling|simulate|sort|statsby|stepwise|svy|varlist|version|xi)\b/,
66+
67+
68+
'boolean': /\b(?:off|on)\b/,
69+
'number': /\b\d+(?:\.\d+)?\b|\B\.\d+/,
70+
'function': /\b[a-z_]\w*(?=\()/i,
71+
72+
'operator': /\+\+|--|##?|[<>!=~]=?|[+\-*^&|/]/,
73+
'punctuation': /[(){}[\],:]/
74+
};
75+
76+
Prism.languages.stata['string-literal'].inside.interpolation.inside.expression.inside = Prism.languages.stata;

components/prism-stata.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-mata.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h2>Full example</h2>
2+
<pre><code>// Source: https://www.stata.com/manuals/m-1first.pdf page 12
3+
numeric matrix tanh(numeric matrix u)
4+
{
5+
numeric matrix eu, emu
6+
eu = exp(u)
7+
emu = exp(-u)
8+
return( (eu-emu):/(eu+emu) )
9+
}</code></pre>

examples/prism-stata.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h2>Full example</h2>
2+
<pre><code>// Source: https://blog.stata.com/2018/10/09/how-to-automate-common-tasks/
3+
program normalize
4+
version 15.1
5+
6+
syntax varlist [if] [in] [ , prefix(name) suffix(name) ]
7+
8+
foreach var in `varlist' {
9+
summarize `var' `if' `in'
10+
generate `prefix'`var'`suffix' = (`var' - r(mean)) / r(sd) `if' `in'
11+
}
12+
end
13+
</code></pre>

plugins/autoloader/prism-autoloader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
"sparql": "turtle",
140140
"sqf": "clike",
141141
"squirrel": "clike",
142+
"stata": [
143+
"mata",
144+
"java",
145+
"python"
146+
],
142147
"t4-cs": [
143148
"t4-templating",
144149
"csharp"

plugins/autoloader/prism-autoloader.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)