prism-stan.js 1.8 KB

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