UNPKG

1.89 kBJavaScriptView Raw
1// https://mc-stan.org/docs/2_24/reference-manual/bnf-grammars.html
2
3Prism.languages.stan = {
4 'comment': /\/\/.*|\/\*[\s\S]*?\*\/|#(?!include).*/,
5 'string': {
6 // String literals can contain spaces and any printable ASCII characters except for " and \
7 // https://mc-stan.org/docs/2_24/reference-manual/print-statements-section.html#string-literals
8 pattern: /"[\x20\x21\x23-\x5B\x5D-\x7E]*"/,
9 greedy: true
10 },
11 'directive': {
12 pattern: /^([ \t]*)#include\b.*/m,
13 lookbehind: true,
14 alias: 'property'
15 },
16
17 'function-arg': {
18 pattern: /(\b(?:algebra_solver|integrate_1d|integrate_ode|integrate_ode_bdf|integrate_ode_rk45|map_rect)\s*\(\s*)[a-zA-Z]\w*/,
19 lookbehind: true,
20 alias: 'function'
21 },
22 'constraint': {
23 pattern: /(\b(?:int|matrix|real|row_vector|vector)\s*)<[^<>]*>/,
24 lookbehind: true,
25 inside: {
26 'expression': {
27 pattern: /(=\s*)\S(?:\S|\s+(?!\s))*?(?=\s*(?:>$|,\s*\w+\s*=))/,
28 lookbehind: true,
29 inside: null // see below
30 },
31 'property': /\b[a-z]\w*(?=\s*=)/i,
32 'operator': /=/,
33 'punctuation': /^<|>$|[,]/
34 }
35 },
36 'keyword': [
37 /\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/,
38 // these are functions that are known to take another function as their first argument.
39 /\b(?:algebra_solver|integrate_1d|integrate_ode|integrate_ode_bdf|integrate_ode_rk45|map_rect)\b/
40 ],
41 'function': /\b[a-z]\w*(?=\s*\()/i,
42 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?\b/i,
43 'boolean': /\b(?:false|true)\b/,
44
45 'operator': /<-|\.[*/]=?|\|\|?|&&|[!=<>+\-*/]=?|['^%~?:]/,
46 'punctuation': /[()\[\]{},;]/
47};
48
49Prism.languages.stan.constraint.inside.expression.inside = Prism.languages.stan;