-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Stata's Ado and Mata (#3383)
- Loading branch information
1 parent
ca78cde
commit 63806d5
Showing
33 changed files
with
1,195 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// https://www.stata.com/manuals/m.pdf | ||
|
||
(function (Prism) { | ||
|
||
var orgType = /\b(?:(?:col|row)?vector|matrix|scalar)\b/.source; | ||
var type = /\bvoid\b|<org>|\b(?:complex|numeric|pointer(?:\s*\([^()]*\))?|real|string|(?:class|struct)\s+\w+|transmorphic)(?:\s*<org>)?/.source | ||
.replace(/<org>/g, orgType); | ||
|
||
Prism.languages.mata = { | ||
'comment': { | ||
pattern: /\/\/.*|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\*\//, | ||
greedy: true | ||
}, | ||
'string': { | ||
pattern: /"[^"\r\n]*"|[‘`']".*?"[’`']/, | ||
greedy: true | ||
}, | ||
|
||
'class-name': { | ||
pattern: /(\b(?:class|extends|struct)\s+)\w+(?=\s*(?:\{|\bextends\b))/, | ||
lookbehind: true | ||
}, | ||
'type': { | ||
pattern: RegExp(type), | ||
alias: 'class-name', | ||
inside: { | ||
'punctuation': /[()]/, | ||
'keyword': /\b(?:class|function|struct|void)\b/ | ||
} | ||
}, | ||
'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/, | ||
'constant': /\bNULL\b/, | ||
|
||
'number': { | ||
pattern: /(^|[^\w.])(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|\d[a-f0-9]*(?:\.[a-f0-9]+)?x[+-]?\d+)i?(?![\w.])/i, | ||
lookbehind: true | ||
}, | ||
'missing': { | ||
pattern: /(^|[^\w.])(?:\.[a-z]?)(?![\w.])/, | ||
lookbehind: true, | ||
alias: 'symbol' | ||
}, | ||
|
||
'function': /\b[a-z_]\w*(?=\s*\()/i, | ||
|
||
'operator': /\.\.|\+\+|--|&&|\|\||:?(?:[!=<>]=|[+\-*/^<>&|:])|[!?=\\#’`']/, | ||
'punctuation': /[()[\]{},;.]/ | ||
}; | ||
|
||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// https://www.stata.com/manuals/u.pdf | ||
// https://www.stata.com/manuals/p.pdf | ||
|
||
Prism.languages.stata = { | ||
'comment': [ | ||
{ | ||
pattern: /(^[ \t]*)\*.*/m, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
{ | ||
pattern: /(^|\s)\/\/.*|\/\*[\s\S]*?\*\//, | ||
lookbehind: true, | ||
greedy: true | ||
} | ||
], | ||
'string-literal': { | ||
pattern: /"[^"\r\n]*"|[‘`']".*?"[’`']/, | ||
greedy: true, | ||
inside: { | ||
'interpolation': { | ||
pattern: /\$\{[^{}]*\}|[‘`']\w[^’`'\r\n]*[’`']/, | ||
inside: { | ||
'punctuation': /^\$\{|\}$/, | ||
'expression': { | ||
pattern: /[\s\S]+/, | ||
inside: null // see below | ||
} | ||
} | ||
}, | ||
'string': /[\s\S]+/ | ||
} | ||
}, | ||
|
||
'mata': { | ||
pattern: /(^[ \t]*mata[ \t]*:)[\s\S]+?(?=^end\b)/m, | ||
lookbehind: true, | ||
greedy: true, | ||
alias: 'language-mata', | ||
inside: Prism.languages.mata | ||
}, | ||
'java': { | ||
pattern: /(^[ \t]*java[ \t]*:)[\s\S]+?(?=^end\b)/m, | ||
lookbehind: true, | ||
greedy: true, | ||
alias: 'language-java', | ||
inside: Prism.languages.java | ||
}, | ||
'python': { | ||
pattern: /(^[ \t]*python[ \t]*:)[\s\S]+?(?=^end\b)/m, | ||
lookbehind: true, | ||
greedy: true, | ||
alias: 'language-python', | ||
inside: Prism.languages.python | ||
}, | ||
|
||
|
||
'command': { | ||
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, | ||
lookbehind: true, | ||
greedy: true, | ||
alias: 'keyword' | ||
}, | ||
'variable': /\$\w+|[‘`']\w[^’`'\r\n]*[’`']/, | ||
'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/, | ||
|
||
|
||
'boolean': /\b(?:off|on)\b/, | ||
'number': /\b\d+(?:\.\d+)?\b|\B\.\d+/, | ||
'function': /\b[a-z_]\w*(?=\()/i, | ||
|
||
'operator': /\+\+|--|##?|[<>!=~]=?|[+\-*^&|/]/, | ||
'punctuation': /[(){}[\],:]/ | ||
}; | ||
|
||
Prism.languages.stata['string-literal'].inside.interpolation.inside.expression.inside = Prism.languages.stata; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h2>Full example</h2> | ||
<pre><code>// Source: https://www.stata.com/manuals/m-1first.pdf page 12 | ||
numeric matrix tanh(numeric matrix u) | ||
{ | ||
numeric matrix eu, emu | ||
eu = exp(u) | ||
emu = exp(-u) | ||
return( (eu-emu):/(eu+emu) ) | ||
}</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h2>Full example</h2> | ||
<pre><code>// Source: https://blog.stata.com/2018/10/09/how-to-automate-common-tasks/ | ||
program normalize | ||
version 15.1 | ||
|
||
syntax varlist [if] [in] [ , prefix(name) suffix(name) ] | ||
|
||
foreach var in `varlist' { | ||
summarize `var' `if' `in' | ||
generate `prefix'`var'`suffix' = (`var' - r(mean)) / r(sd) `if' `in' | ||
} | ||
end | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.