-
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.
- Loading branch information
1 parent
bf115f4
commit 2da2beb
Showing
13 changed files
with
512 additions
and
1 deletion.
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,49 @@ | ||
// https://mc-stan.org/docs/2_24/reference-manual/bnf-grammars.html | ||
|
||
Prism.languages.stan = { | ||
'comment': /\/\/.*|\/\*[\s\S]*?\*\/|#(?!include).*/, | ||
'string': { | ||
// String literals can contain spaces and any printable ASCII characters except for " and \ | ||
// https://mc-stan.org/docs/2_24/reference-manual/print-statements-section.html#string-literals | ||
pattern: /"[\x20\x21\x23-\x5B\x5D-\x7E]*"/, | ||
greedy: true | ||
}, | ||
'directive': { | ||
pattern: /^([ \t]*)#include\b.*/m, | ||
lookbehind: true, | ||
alias: 'property' | ||
}, | ||
|
||
'function-arg': { | ||
pattern: /(\b(?:algebra_solver|integrate_1d|integrate_ode|integrate_ode_bdf|integrate_ode_rk45|map_rect)\s*\(\s*)[a-zA-Z]\w*/, | ||
lookbehind: true, | ||
alias: 'function' | ||
}, | ||
'constraint': { | ||
pattern: /(\b(?:int|matrix|real|row_vector|vector)\s*)<[^<>]*>/, | ||
lookbehind: true, | ||
inside: { | ||
'expression': { | ||
pattern: /(=\s*)(?:(?!\s*(?:>$|,\s*\w+\s*=))[\s\S])+/, | ||
lookbehind: true, | ||
inside: null // see below | ||
}, | ||
'property': /\b[a-z]\w*(?=\s*=)/i, | ||
'operator': /=/, | ||
'punctuation': /^<|>$|[,]/ | ||
} | ||
}, | ||
'keyword': [ | ||
/\b(?:break|cholesky_factor_corr|cholesky_factor_cov|continue|corr_matrix|cov_matrix|data|else|for|functions|generated|if|in|increment_log_prob|int|matrix|model|ordered|parameters|positive_ordered|print|quantities|real|reject|return|row_vector|simplex|target|transformed|unit_vector|vector|void|while)\b/, | ||
// these are functions that are known to take another function as their first argument. | ||
/\b(?:algebra_solver|integrate_1d|integrate_ode|integrate_ode_bdf|integrate_ode_rk45|map_rect)\b/ | ||
], | ||
'function': /\b[a-z]\w*(?=\s*\()/i, | ||
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?\b/i, | ||
'boolean': /\b(?:false|true)\b/, | ||
|
||
'operator': /<-|\.[*/]=?|\|\|?|&&|[!=<>+\-*/]=?|['^%~?:]/, | ||
'punctuation': /[()\[\]{},;]/ | ||
}; | ||
|
||
Prism.languages.stan.constraint.inside.expression.inside = Prism.languages.stan; |
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,21 @@ | ||
<h2>Full example</h2> | ||
<pre><code>// source: https://github.com/stan-dev/example-models/blob/8a6964135560f54f52695ccd4d2492a8067f0c30/misc/linear-regression/regression_std.stan | ||
|
||
// normal mixture, unknown proportion and means, known variance | ||
// p(y|mu,theta) = theta * Normal(y|mu[1],1) + (1-theta) * Normal(y|mu[2],1); | ||
|
||
data { | ||
int<lower=0> N; | ||
real y[N]; | ||
} | ||
parameters { | ||
real<lower=0,upper=1> theta; | ||
real mu[2]; | ||
} | ||
model { | ||
theta ~ uniform(0,1); // equivalently, ~ beta(1,1); | ||
for (k in 1:2) | ||
mu[k] ~ normal(0,10); | ||
for (n in 1:N) | ||
target += log_mix(theta, normal_lpdf(y[n]|mu[1],1.0), normal_lpdf(y[n]|mu[2],1.0)); | ||
}</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,17 @@ | ||
# comment | ||
// comment | ||
/* | ||
comment | ||
*/ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "# comment"], | ||
["comment", "// comment"], | ||
["comment", "/*\ncomment\n*/"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
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,176 @@ | ||
real<lower=a> b; | ||
|
||
real<lower=a, upper=b> theta; | ||
|
||
int<lower=1> T; | ||
|
||
matrix<multiplier=5>[3, 4] B; | ||
|
||
row_vector<lower=-1,upper=1>[10] u; | ||
|
||
row_vector<offset=-42,multiplier=3>[3] u; | ||
|
||
real<lower=min(y), upper=max(y)> phi; | ||
|
||
real<offset=mu,multiplier=sigma> x; | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "real"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "lower"], | ||
["operator", "="], | ||
["expression", [ | ||
"a" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
" b", | ||
["punctuation", ";"], | ||
|
||
["keyword", "real"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "lower"], | ||
["operator", "="], | ||
["expression", [ | ||
"a" | ||
]], | ||
["punctuation", ","], | ||
["property", "upper"], | ||
["operator", "="], | ||
["expression", [ | ||
"b" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
" theta", | ||
["punctuation", ";"], | ||
|
||
["keyword", "int"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "lower"], | ||
["operator", "="], | ||
["expression", [ | ||
["number", "1"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
" T", | ||
["punctuation", ";"], | ||
|
||
["keyword", "matrix"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "multiplier"], | ||
["operator", "="], | ||
["expression", [ | ||
["number", "5"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "["], | ||
["number", "3"], | ||
["punctuation", ","], | ||
["number", "4"], | ||
["punctuation", "]"], | ||
" B", | ||
["punctuation", ";"], | ||
|
||
["keyword", "row_vector"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "lower"], | ||
["operator", "="], | ||
["expression", [ | ||
["operator", "-"], | ||
["number", "1"] | ||
]], | ||
["punctuation", ","], | ||
["property", "upper"], | ||
["operator", "="], | ||
["expression", [ | ||
["number", "1"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "["], | ||
["number", "10"], | ||
["punctuation", "]"], | ||
" u", | ||
["punctuation", ";"], | ||
|
||
["keyword", "row_vector"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "offset"], | ||
["operator", "="], | ||
["expression", [ | ||
["operator", "-"], | ||
["number", "42"] | ||
]], | ||
["punctuation", ","], | ||
["property", "multiplier"], | ||
["operator", "="], | ||
["expression", [ | ||
["number", "3"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "["], | ||
["number", "3"], | ||
["punctuation", "]"], | ||
" u", | ||
["punctuation", ";"], | ||
|
||
["keyword", "real"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "lower"], | ||
["operator", "="], | ||
["expression", [ | ||
["function", "min"], | ||
["punctuation", "("], | ||
"y", | ||
["punctuation", ")"] | ||
]], | ||
["punctuation", ","], | ||
["property", "upper"], | ||
["operator", "="], | ||
["expression", [ | ||
["function", "max"], | ||
["punctuation", "("], | ||
"y", | ||
["punctuation", ")"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
" phi", | ||
["punctuation", ";"], | ||
|
||
["keyword", "real"], | ||
["constraint", [ | ||
["punctuation", "<"], | ||
["property", "offset"], | ||
["operator", "="], | ||
["expression", [ | ||
"mu" | ||
]], | ||
["punctuation", ","], | ||
["property", "multiplier"], | ||
["operator", "="], | ||
["expression", [ | ||
"sigma" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
" x", | ||
["punctuation", ";"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for type constraints. |
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,14 @@ | ||
#include my-std-normal.stan // definition of standard normal | ||
#include my-std-normal.stan | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["directive", "#include my-std-normal.stan "], | ||
["comment", "// definition of standard normal"], | ||
["directive", "#include my-std-normal.stan"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for include directives. |
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,89 @@ | ||
break | ||
cholesky_factor_corr | ||
cholesky_factor_cov | ||
continue | ||
corr_matrix | ||
cov_matrix | ||
data | ||
else | ||
for | ||
functions | ||
generated | ||
if | ||
in | ||
increment_log_prob | ||
int | ||
matrix | ||
model | ||
ordered | ||
parameters | ||
positive_ordered | ||
quantities | ||
real | ||
reject | ||
return | ||
row_vector | ||
simplex | ||
target | ||
transformed | ||
unit_vector | ||
vector | ||
void | ||
while | ||
|
||
algebra_solver | ||
integrate_1d | ||
integrate_ode | ||
integrate_ode_bdf | ||
integrate_ode_rk45 | ||
map_rect | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "break"], | ||
["keyword", "cholesky_factor_corr"], | ||
["keyword", "cholesky_factor_cov"], | ||
["keyword", "continue"], | ||
["keyword", "corr_matrix"], | ||
["keyword", "cov_matrix"], | ||
["keyword", "data"], | ||
["keyword", "else"], | ||
["keyword", "for"], | ||
["keyword", "functions"], | ||
["keyword", "generated"], | ||
["keyword", "if"], | ||
["keyword", "in"], | ||
["keyword", "increment_log_prob"], | ||
["keyword", "int"], | ||
["keyword", "matrix"], | ||
["keyword", "model"], | ||
["keyword", "ordered"], | ||
["keyword", "parameters"], | ||
["keyword", "positive_ordered"], | ||
["keyword", "print"], | ||
["keyword", "quantities"], | ||
["keyword", "real"], | ||
["keyword", "reject"], | ||
["keyword", "return"], | ||
["keyword", "row_vector"], | ||
["keyword", "simplex"], | ||
["keyword", "target"], | ||
["keyword", "transformed"], | ||
["keyword", "unit_vector"], | ||
["keyword", "vector"], | ||
["keyword", "void"], | ||
["keyword", "while"], | ||
|
||
["keyword", "algebra_solver"], | ||
["keyword", "integrate_1d"], | ||
["keyword", "integrate_ode"], | ||
["keyword", "integrate_ode_bdf"], | ||
["keyword", "integrate_ode_rk45"], | ||
["keyword", "map_rect"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for keywords. |
Oops, something went wrong.