]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/stan.js
1 /*! `stan` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Description: The Stan probabilistic programming language
9 Author: Sean Pinkney <sean.pinkney@gmail.com>
10 Website: http://mc-stan.org/
15 const regex
= hljs
.regex
;
16 // variable names cannot conflict with block identifiers
54 'cholesky_factor_corr|10',
55 'cholesky_factor_cov|10',
61 // to get the functions list
62 // clone the [stan-docs repo](https://github.com/stan-dev/docs)
63 // then cd into it and run this bash script https://gist.github.com/joshgoebel/dcd33f82d4059a907c986049893843cf
65 // the output files are
66 // distributions_quoted.txt
67 // functions_quoted.txt
75 'algebra_solver_newton',
95 'columns_dot_product',
97 'complex_schur_decompose',
98 'complex_schur_decompose_t',
99 'complex_schur_decompose_u',
109 'csr_matrix_times_vector',
110 'csr_to_dense_matrix',
117 'diag_post_multiply',
125 'eigendecompose_sym',
146 'generalized_inverse',
150 'hmm_hidden_state_prob',
157 'integrate_ode_adams',
159 'integrate_ode_rk45',
182 'linspaced_int_array',
183 'linspaced_row_vector',
195 'log_falling_factorial',
197 'log_inv_logit_diff',
200 'log_modified_bessel_first_kind',
201 'log_rising_factorial',
207 'matrix_exp_multiply',
211 'mdivide_left_tri_low',
213 'mdivide_right_tri_low',
216 'modified_bessel_first_kind',
217 'modified_bessel_second_kind',
218 'multiply_lower_tri_self_transpose',
227 'ode_adjoint_tol_ctl',
236 'one_hot_row_vector',
275 'scale_matrix_exp_multiply',
297 'symmetrize_from_lower_tri',
312 'trace_gen_quad_form',
323 const DISTRIBUTIONS
= [
326 'bernoulli_logit_glm',
334 'categorical_logit_glm',
339 'double_exponential',
351 'inv_wishart_cholesky',
362 'multi_normal_cholesky',
364 'multi_student_cholesky_t',
366 'multi_student_t_cholesky',
369 'neg_binomial_2_log',
370 'neg_binomial_2_log_glm',
374 'ordered_logistic_glm',
382 'scaled_inv_chi_square',
383 'skew_double_exponential',
396 const BLOCK_COMMENT
= hljs
.COMMENT(
404 match: /@(return|param)/
416 match: /[a-z][a-z-._]+/,
419 hljs
.C_LINE_COMMENT_MODE
423 const RANGE_CONSTRAINTS
= [
432 aliases: [ 'stanfuncs' ],
434 $pattern: hljs
.IDENT_RE
,
441 hljs
.C_LINE_COMMENT_MODE
,
443 hljs
.HASH_COMMENT_MODE
,
447 match: /\s(pi|e|sqrt2|log2|log10)(?=\()/,
451 match: regex
.concat(/[<,]\s*/, regex
.either(...RANGE_CONSTRAINTS
), /\s*=/),
452 keywords: RANGE_CONSTRAINTS
456 match: /\btarget(?=\s*\+=)/,
459 // highlights the 'T' in T[,] for only Stan language distributrions
462 regex
.either(...DISTRIBUTIONS
),
472 // highlights distributions that end with special endings
474 keywords: DISTRIBUTIONS
,
475 begin: regex
.concat(/\w*/, regex
.either(...DISTRIBUTIONS
), /(_lpdf|_lupdf|_lpmf|_cdf|_lcdf|_lccdf|_qf)(?=\s*[\(.*\)])/)
478 // highlights distributions after ~
482 regex
.concat(regex
.either(...DISTRIBUTIONS
), /(?=\s*[\(.*\)])/)
484 scope: { 3: "built_in" }
487 // highlights user defined distributions after ~
490 /\s*\w+(?=\s*[\(.*\)])/,
491 '(?!.*/\b(' + regex
.either(...DISTRIBUTIONS
) + ')\b)'
493 scope: { 2: "title.function" }
496 // highlights user defined distributions with special endings
497 scope: 'title.function',
498 begin: /\w*(_lpdf|_lupdf|_lpmf|_cdf|_lcdf|_lccdf|_qf)(?=\s*[\(.*\)])/
503 // Comes from @RunDevelopment accessed 11/29/2021 at
504 // https://github.com/PrismJS/prism/blob/c53ad2e65b7193ab4f03a1797506a54bbb33d5a2/components/prism-stan.js#L56
506 // start of big noncapture group which
507 // 1. gets numbers that are by themselves
508 // 2. numbers that are separated by _
509 // 3. numbers that are separted by .
510 /(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)/,
511 // grabs scientific notation
512 // grabs complex numbers with i
513 /(?:[eE][+-]?\d+(?:_\d+)*)?i?(?!\w)/
530 hljs
.registerLanguage('stan', hljsGrammar
);