rouge 3.26.0 → 3.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/lib/rouge/cli.rb +23 -20
  4. data/lib/rouge/demos/brainfuck +1 -1
  5. data/lib/rouge/demos/brightscript +1 -1
  6. data/lib/rouge/demos/bsl +1 -1
  7. data/lib/rouge/demos/cfscript +1 -1
  8. data/lib/rouge/demos/coq +1 -1
  9. data/lib/rouge/demos/csvs +1 -1
  10. data/lib/rouge/demos/dafny +16 -0
  11. data/lib/rouge/demos/datastudio +0 -1
  12. data/lib/rouge/demos/ecl +0 -1
  13. data/lib/rouge/demos/erlang +1 -1
  14. data/lib/rouge/demos/fluent +13 -0
  15. data/lib/rouge/demos/fsharp +1 -1
  16. data/lib/rouge/demos/glsl +1 -1
  17. data/lib/rouge/demos/haxe +0 -1
  18. data/lib/rouge/demos/idris +13 -0
  19. data/lib/rouge/demos/isabelle +16 -0
  20. data/lib/rouge/demos/lean +8 -0
  21. data/lib/rouge/demos/meson +10 -0
  22. data/lib/rouge/demos/nesasm +1 -1
  23. data/lib/rouge/demos/nial +35 -0
  24. data/lib/rouge/demos/opentype_feature_file +0 -1
  25. data/lib/rouge/demos/plsql +2 -0
  26. data/lib/rouge/demos/smarty +0 -1
  27. data/lib/rouge/demos/stan +13 -0
  28. data/lib/rouge/demos/stata +14 -0
  29. data/lib/rouge/demos/syzlang +15 -0
  30. data/lib/rouge/demos/syzprog +8 -0
  31. data/lib/rouge/formatter.rb +2 -2
  32. data/lib/rouge/formatters/html_inline.rb +0 -1
  33. data/lib/rouge/guessers/disambiguation.rb +7 -0
  34. data/lib/rouge/lexer.rb +2 -2
  35. data/lib/rouge/lexers/apache/keywords.rb +1 -1
  36. data/lib/rouge/lexers/apple_script.rb +1 -1
  37. data/lib/rouge/lexers/c.rb +12 -2
  38. data/lib/rouge/lexers/ceylon.rb +2 -2
  39. data/lib/rouge/lexers/console.rb +1 -1
  40. data/lib/rouge/lexers/cpp.rb +8 -5
  41. data/lib/rouge/lexers/cypher.rb +8 -0
  42. data/lib/rouge/lexers/dafny.rb +128 -0
  43. data/lib/rouge/lexers/dart.rb +10 -9
  44. data/lib/rouge/lexers/docker.rb +4 -0
  45. data/lib/rouge/lexers/eex.rb +2 -2
  46. data/lib/rouge/lexers/eiffel.rb +0 -1
  47. data/lib/rouge/lexers/factor.rb +2 -2
  48. data/lib/rouge/lexers/fluent.rb +74 -0
  49. data/lib/rouge/lexers/ghc_core.rb +1 -1
  50. data/lib/rouge/lexers/gherkin/keywords.rb +1 -1
  51. data/lib/rouge/lexers/groovy.rb +1 -1
  52. data/lib/rouge/lexers/handlebars.rb +1 -1
  53. data/lib/rouge/lexers/hcl.rb +1 -0
  54. data/lib/rouge/lexers/hylang.rb +0 -1
  55. data/lib/rouge/lexers/idris.rb +210 -0
  56. data/lib/rouge/lexers/isabelle.rb +251 -0
  57. data/lib/rouge/lexers/javascript.rb +1 -1
  58. data/lib/rouge/lexers/jsl.rb +6 -7
  59. data/lib/rouge/lexers/jsx.rb +1 -2
  60. data/lib/rouge/lexers/kotlin.rb +3 -1
  61. data/lib/rouge/lexers/lasso/keywords.rb +1 -1
  62. data/lib/rouge/lexers/lean.rb +164 -0
  63. data/lib/rouge/lexers/llvm/keywords.rb +1 -1
  64. data/lib/rouge/lexers/lua/keywords.rb +1 -1
  65. data/lib/rouge/lexers/mathematica/keywords.rb +1 -1
  66. data/lib/rouge/lexers/matlab/keywords.rb +1 -1
  67. data/lib/rouge/lexers/matlab.rb +3 -2
  68. data/lib/rouge/lexers/meson.rb +159 -0
  69. data/lib/rouge/lexers/nial.rb +166 -0
  70. data/lib/rouge/lexers/ocl.rb +0 -1
  71. data/lib/rouge/lexers/pascal.rb +2 -1
  72. data/lib/rouge/lexers/php/keywords.rb +1 -1
  73. data/lib/rouge/lexers/php.rb +7 -5
  74. data/lib/rouge/lexers/plsql.rb +578 -0
  75. data/lib/rouge/lexers/prometheus.rb +0 -1
  76. data/lib/rouge/lexers/python.rb +3 -1
  77. data/lib/rouge/lexers/q.rb +0 -1
  78. data/lib/rouge/lexers/rust.rb +82 -19
  79. data/lib/rouge/lexers/sparql.rb +5 -4
  80. data/lib/rouge/lexers/sqf/keywords.rb +1 -1
  81. data/lib/rouge/lexers/sql.rb +7 -7
  82. data/lib/rouge/lexers/stan.rb +451 -0
  83. data/lib/rouge/lexers/stata.rb +165 -0
  84. data/lib/rouge/lexers/supercollider.rb +0 -1
  85. data/lib/rouge/lexers/swift.rb +3 -3
  86. data/lib/rouge/lexers/syzlang.rb +317 -0
  87. data/lib/rouge/lexers/syzprog.rb +122 -0
  88. data/lib/rouge/lexers/tap.rb +0 -1
  89. data/lib/rouge/lexers/toml.rb +16 -9
  90. data/lib/rouge/lexers/tsx.rb +0 -1
  91. data/lib/rouge/lexers/tulip.rb +0 -1
  92. data/lib/rouge/lexers/viml/keywords.rb +1 -1
  93. data/lib/rouge/lexers/yaml.rb +1 -1
  94. data/lib/rouge/version.rb +1 -1
  95. metadata +30 -6
@@ -22,10 +22,13 @@ module Rouge
22
22
 
23
23
  def self.keywords
24
24
  @keywords ||= %w(
25
- as assert async await break const continue copy do drop else enum extern
26
- fail false fn for if impl let log loop match mod move mut priv pub pure
27
- ref return self static struct true trait type unsafe use where
28
- while box
25
+ as async await break const continue crate dyn else enum extern false
26
+ fn for if impl in let log loop match mod move mut pub ref return self
27
+ Self static struct super trait true type unsafe use where while
28
+ abstract become box do final macro
29
+ override priv typeof unsized virtual
30
+ yield try
31
+ union
29
32
  )
30
33
  end
31
34
 
@@ -40,6 +43,9 @@ module Rouge
40
43
  Right Send Shl Shr size_t Some ssize_t str Sub Success time_t
41
44
  u16 u32 u64 u8 usize uint uintptr_t
42
45
  Box Vec String Gc Rc Arc
46
+ u128 i128 Result Sync Pin Unpin Sized Drop drop Fn FnMut FnOnce
47
+ Clone PartialEq PartialOrd AsMut AsRef From Into Default
48
+ DoubleEndedIterator ExactSizeIterator Extend IntoIterator Iterator
43
49
  )
44
50
  end
45
51
 
@@ -54,12 +60,12 @@ module Rouge
54
60
 
55
61
  delim_map = { '[' => ']', '(' => ')', '{' => '}' }
56
62
 
57
- id = /[a-z_]\w*/i
63
+ id = /[\p{XID_Start}_]\p{XID_Continue}*/
58
64
  hex = /[0-9a-f]/i
59
65
  escapes = %r(
60
- \\ ([nrt'"\\0] | x#{hex}{2} | u#{hex}{4} | U#{hex}{8})
66
+ \\ ([nrt'"\\0] | x#{hex}{2} | u\{(#{hex}_*){1,6}\})
61
67
  )x
62
- size = /8|16|32|64/
68
+ size = /8|16|32|64|128|size/
63
69
 
64
70
  # Although not officially part of Rust, the rustdoc tool allows code in
65
71
  # comments to begin with `#`. Code like this will be evaluated but not
@@ -82,8 +88,62 @@ module Rouge
82
88
 
83
89
  state :whitespace do
84
90
  rule %r/\s+/, Text
85
- rule %r(//[^\n]*), Comment
86
- rule %r(/[*].*?[*]/)m, Comment::Multiline
91
+ mixin :comments
92
+ end
93
+
94
+ state :comments do
95
+ # Only 3 slashes are doc comments, `////` and beyond become normal
96
+ # comments again (for some reason), so match this before the
97
+ # doc line comments rather than figure out a
98
+ rule %r(////+[^\n]*), Comment::Single
99
+ # doc line comments — either inner (`//!`), or outer (`///`).
100
+ rule %r(//[/!][^\n]*), Comment::Doc
101
+ # otherwise, `//` is just a plain line comme
102
+ rule %r(//[^\n]*), Comment::Single
103
+ # /**/ and /***/ are self-closing block comments, not doc. Because this
104
+ # is self-closing, it doesn't enter the states for nested comments
105
+ rule %r(/\*\*\*?/), Comment::Multiline
106
+ # 3+ stars and it's a normal non-doc block comment.
107
+ rule %r(/\*\*\*+), Comment::Multiline, :nested_plain_block
108
+ # `/*!` and `/**` begin doc comments. These nest and can have internal
109
+ # block/doc comments, but they're still part of the documentation
110
+ # inside.
111
+ rule %r(/[*][*!]), Comment::Doc, :nested_doc_block
112
+ # any other /* is a plain multiline comment
113
+ rule %r(/[*]), Comment::Multiline, :nested_plain_block
114
+ end
115
+
116
+ # Multiline/block comments fully nest. This is true for ones that are
117
+ # marked as documentation too. The behavior here is:
118
+ #
119
+ # - Anything inside a block doc comment is still included in the
120
+ # documentation, even if it's a nested non-doc block comment. For
121
+ # example: `/** /* still docs */ */`
122
+ # - Anything inside of a block non-doc comment is still just a normal
123
+ # comment, even if it's a nested block documentation comment. For
124
+ # example: `/* /** not docs */ */`
125
+ #
126
+ # This basically means: if (on the outermost level) the comment starts as
127
+ # one kind of block comment (either doc/non-doc), then everything inside
128
+ # of it, including nested block comments of the opposite type, needs to
129
+ # stay that type.
130
+ #
131
+ # Also note that single line comments do nothing anywhere inside of block
132
+ # comments, thankfully.
133
+ #
134
+ # We just define this as two states, because this seems easier than
135
+ # tracking it with instance vars.
136
+ [
137
+ [:nested_plain_block, Comment::Multiline],
138
+ [:nested_doc_block, Comment::Doc]
139
+ ].each do |state_name, comment_token|
140
+ state state_name do
141
+ rule %r(\*/), comment_token, :pop!
142
+ rule %r(/\*), comment_token, state_name
143
+ # We only want to eat at most one `[*/]` at a time,
144
+ # but we can skip past non-`[*/]` in bulk.
145
+ rule %r([^*/]+|[*/]), comment_token
146
+ end
87
147
  end
88
148
 
89
149
  state :root do
@@ -110,6 +170,7 @@ module Rouge
110
170
  rule %r/\bmacro_rules!/, Name::Decorator, :macro_rules
111
171
  rule %r/#{id}!/, Name::Decorator, :macro
112
172
 
173
+ rule %r/'static\b/, Keyword
113
174
  rule %r/'#{id}/, Name::Variable
114
175
  rule %r/#{id}/ do |m|
115
176
  name = m[0]
@@ -154,33 +215,35 @@ module Rouge
154
215
 
155
216
  state :has_literals do
156
217
  # constants
157
- rule %r/\b(?:true|false|nil)\b/, Keyword::Constant
158
- # characters
218
+ rule %r/\b(?:true|false)\b/, Keyword::Constant
219
+
220
+ # characters/bytes
159
221
  rule %r(
160
- ' (?: #{escapes} | [^\\] ) '
222
+ b?' (?: #{escapes} | [^\\] ) '
161
223
  )x, Str::Char
162
224
 
163
- rule %r/"/, Str, :string
164
- rule %r/r(#*)".*?"\1/m, Str
225
+ rule %r/b?"/, Str, :string
226
+ rule %r/b?r(#*)".*?"\1/m, Str
165
227
 
166
228
  # numbers
167
- dot = /[.][0-9_]+/
168
- exp = /e[-+]?[0-9_]+/
229
+ dot = /[.][0-9][0-9_]*/
230
+ exp = /[eE][-+]?[0-9_]+/
169
231
  flt = /f32|f64/
170
232
 
171
233
  rule %r(
172
- [0-9_]+
234
+ [0-9][0-9_]*
173
235
  (#{dot} #{exp}? #{flt}?
174
236
  |#{dot}? #{exp} #{flt}?
175
237
  |#{dot}? #{exp}? #{flt}
238
+ |[.](?![._\p{XID_Start}])
176
239
  )
177
240
  )x, Num::Float
178
241
 
179
242
  rule %r(
180
243
  ( 0b[10_]+
181
244
  | 0x[0-9a-fA-F_]+
182
- | 0o[0-7]+
183
- | [0-9_]+
245
+ | 0o[0-7_]+
246
+ | [0-9][0-9_]*
184
247
  ) (u#{size}?|i#{size})?
185
248
  )x, Num::Integer
186
249
 
@@ -41,16 +41,17 @@ module Rouge
41
41
  rule %r('''), Str::Single, :string_single_literal
42
42
  rule %r('), Str::Single, :string_single
43
43
 
44
- rule %r([$?]\w+), Name::Variable
45
- rule %r((\w*:)(\w+)?) do |m|
44
+ rule %r([$?][[:word:]]+), Name::Variable
45
+ rule %r(([[:word:]-]*)(:)([[:word:]-]+)?) do |m|
46
46
  token Name::Namespace, m[1]
47
- token Str::Symbol, m[2]
47
+ token Operator, m[2]
48
+ token Str::Symbol, m[3]
48
49
  end
49
50
  rule %r(<[^>]*>), Name::Namespace
50
51
  rule %r(true|false)i, Keyword::Constant
51
52
  rule %r/a\b/, Keyword
52
53
 
53
- rule %r([A-Z]\w+\b)i do |m|
54
+ rule %r([A-Z][[:word:]]+\b)i do |m|
54
55
  if self.class.builtins.include? m[0].upcase
55
56
  token Name::Builtin
56
57
  elsif self.class.keywords.include? m[0].upcase
@@ -9,4 +9,4 @@ module Rouge
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -38,8 +38,8 @@ module Rouge
38
38
  DYNAMIC DYNAMIC_FUNCTION DYNAMIC_FUNCTION_CODE EACH ELSE
39
39
  ENCODING ENCRYPTED END END-EXEC EQUALS ESCAPE EVERY EXCEPT
40
40
  ESCEPTION EXCLUDING EXCLUSIVE EXEC EXECUTE EXISTING EXISTS
41
- EXPLAIN EXTERNAL EXTRACT FALSE FETCH FINAL FIRST FOR FORCE
42
- FOREIGN FORTRAN FORWARD FOUND FREE FREEZE FROM FULL FUNCTION
41
+ EXPLAIN EXTERNAL EXTRACT FALSE FETCH FINAL FIRST FOLLOWING FOR
42
+ FORCE FOREIGN FORTRAN FORWARD FOUND FREE FREEZE FROM FULL FUNCTION
43
43
  G GENERAL GENERATED GET GLOBAL GO GOTO GRANT GRANTED GROUP
44
44
  GROUPING HANDLER HAVING HIERARCHY HOLD HOST IDENTITY IGNORE
45
45
  ILIKE IMMEDIATE IMMUTABLE IMPLEMENTATION IMPLICIT IN INCLUDING
@@ -58,10 +58,10 @@ module Rouge
58
58
  ORDINALITY OUT OUTER OUTPUT OVERLAPS OVERLAY OVERRIDING
59
59
  OWNER PAD PARAMETER PARAMETERS PARAMETER_MODE PARAMATER_NAME
60
60
  PARAMATER_ORDINAL_POSITION PARAMETER_SPECIFIC_CATALOG
61
- PARAMETER_SPECIFIC_NAME PARAMATER_SPECIFIC_SCHEMA PARTIAL PASCAL
62
- PENDANT PLACING PLI POSITION POSTFIX PREFIX PREORDER
61
+ PARAMETER_SPECIFIC_NAME PARAMATER_SPECIFIC_SCHEMA PARTIAL PARTITION
62
+ PASCAL PENDANT PLACING PLI POSITION POSTFIX PREFIX PRECEDING PREORDER
63
63
  PREPARE PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE
64
- PUBLIC READ READS RECHECK RECURSIVE REF REFERENCES REFERENCING
64
+ PUBLIC RANGE READ READS RECHECK RECURSIVE REF REFERENCES REFERENCING
65
65
  REINDEX RELATIVE RENAME REPEATABLE REPLACE RESET RESTART
66
66
  RESTRICT RESULT RETURN RETURNED_LENGTH RETURNED_OCTET_LENGTH
67
67
  RETURNED_SQLSTATE RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
@@ -84,7 +84,7 @@ module Rouge
84
84
  USAGE USER USER_DEFINED_TYPE_CATALOG USER_DEFINED_TYPE_NAME
85
85
  USER_DEFINED_TYPE_SCHEMA USING VACUUM VALID VALIDATOR VALUES
86
86
  VARIABLE VERBOSE VERSION VIEW VOLATILE WHEN WHENEVER WHERE
87
- WITH WITHOUT WORK WRITE ZONE
87
+ WINDOW WITH WITHOUT WORK WRITE ZONE
88
88
  )
89
89
  end
90
90
 
@@ -126,7 +126,7 @@ module Rouge
126
126
  end
127
127
 
128
128
  rule %r([+*/<>=~!@#%&|?^-]), Operator
129
- rule %r/[;:()\[\],.]/, Punctuation
129
+ rule %r/[;:()\[\]\{\},.]/, Punctuation
130
130
  end
131
131
 
132
132
  state :multiline_comments do
@@ -0,0 +1,451 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Stan < RegexLexer
7
+ title "Stan"
8
+ desc 'Stan Modeling Language (mc-stan.org)'
9
+ tag 'stan'
10
+ filenames '*.stan', '*.stanfunctions'
11
+
12
+ # optional comment or whitespace
13
+ WS = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
14
+ ID = /[a-zA-Z_][a-zA-Z0-9_]*/
15
+ RT = /(?:(?:[a-z_]\s*(?:\[[0-9, ]\])?)\s+)*/
16
+ OP = Regexp.new([
17
+ # Assigment operators
18
+ "=",
19
+
20
+ # Comparison operators
21
+ "<", "<=", ">", ">=", "==", "!=",
22
+
23
+ # Boolean operators
24
+ "!", "&&", "\\|\\|",
25
+
26
+ # Real-valued arithmetic operators
27
+ "\\+", "-", "\\*", "/", "\\^",
28
+
29
+ # Transposition operator
30
+ "'",
31
+
32
+ # Elementwise functions
33
+ "\\.\\+", "\\.-", "\\.\\*", "\\./", "\\.\\^",
34
+
35
+ # Matrix division operators
36
+ "\\\\",
37
+
38
+ # Compound assigment operators
39
+ "\\+=", "-=", "\\*=", "/=", "\\.\\*=", "\\./=",
40
+
41
+ # Sampling
42
+ "~",
43
+
44
+ # Conditional operator
45
+ "\\?", ":"
46
+ ].join("|"))
47
+
48
+ def self.keywords
49
+ @keywords ||= Set.new %w(
50
+ if else while for break continue print reject return
51
+ )
52
+ end
53
+
54
+ def self.types
55
+ @types ||= Set.new %w(
56
+ int real vector ordered positive_ordered simplex unit_vector
57
+ row_vector matrix cholesky_factor_corr cholesky_factor_cov corr_matrix
58
+ cov_matrix data void complex array
59
+ )
60
+ end
61
+
62
+ def self.reserved
63
+ @reserved ||= Set.new [
64
+ # Reserved words from Stan language
65
+ "for", "in", "while", "repeat", "until", "if", "then", "else", "true",
66
+ "false", "target", "functions", "model", "data", "parameters",
67
+ "quantities", "transformed", "generated",
68
+
69
+ # Reserved names from Stan implementation
70
+ "var", "fvar", "STAN_MAJOR", "STAN_MINOR", "STAN_PATCH",
71
+ "STAN_MATH_MAJOR", "STAN_MATH_MINOR", "STAN_MATH_PATCH",
72
+
73
+ # Reserved names from C++
74
+ "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand",
75
+ "bitor", "bool", "break", "case", "catch", "char", "char16_t",
76
+ "char32_t", "class", "compl", "const", "constexpr", "const_cast",
77
+ "continue", "decltype", "default", "delete", "do", "double",
78
+ "dynamic_cast", "else", "enum", "explicit", "export", "extern",
79
+ "false", "float", "for", "friend", "goto", "if", "inline", "int",
80
+ "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq",
81
+ "nullptr", "operator", "or", "or_eq", "private", "protected",
82
+ "public", "register", "reinterpret_cast", "return", "short", "signed",
83
+ "sizeof", "static", "static_assert", "static_cast", "struct",
84
+ "switch", "template", "this", "thread_local", "throw", "true", "try",
85
+ "typedef", "typeid", "typename", "union", "unsigned", "using",
86
+ "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"
87
+ ]
88
+ end
89
+
90
+ def self.builtin_functions
91
+ @builtin_functions ||= Set.new [
92
+ # Integer-Valued Basic Functions
93
+
94
+ ## Absolute functions
95
+ "abs", "int_step",
96
+
97
+ ## Bound functions
98
+ "min", "max",
99
+
100
+ ## Size functions
101
+ "size",
102
+
103
+ # Real-Valued Basic Functions
104
+
105
+ ## Log probability function
106
+ "target", "get_lp",
107
+
108
+ ## Logical functions
109
+ "step", "is_inf", "is_nan",
110
+
111
+ ## Step-like functions
112
+ "fabs", "fdim", "fmin", "fmax", "fmod", "floor", "ceil", "round",
113
+ "trunc",
114
+
115
+ ## Power and logarithm functions
116
+ "sqrt", "cbrt", "square", "exp", "exp2", "log", "log2", "log10",
117
+ "pow", "inv", "inv_sqrt", "inv_square",
118
+
119
+ ## Trigonometric functions
120
+ "hypot", "cos", "sin", "tan", "acos", "asin", "atan", "atan2",
121
+
122
+ ## Hyperbolic trigonometric functions
123
+ "cosh", "sinh", "tanh", "acosh", "asinh", "atanh",
124
+
125
+ ## Link functions
126
+ "logit", "inv_logit", "inv_cloglog",
127
+
128
+ ## Probability-related functions
129
+ "erf", "erfc", "Phi", "inv_Phi", "Phi_approx", "binary_log_loss",
130
+ "owens_t",
131
+
132
+ ## Combinatorial functions
133
+ "beta", "inc_beta", "lbeta", "tgamma", "lgamma", "digamma",
134
+ "trigamma", "lmgamma", "gamma_p", "gamma_q",
135
+ "binomial_coefficient_log", "choose", "bessel_first_kind",
136
+ "bessel_second_kind", "modified_bessel_first_kind",
137
+ "log_modified_bessel_first_kind", "modified_bessel_second_kind",
138
+ "falling_factorial", "lchoose", "log_falling_factorial",
139
+ "rising_factorial", "log_rising_factorial",
140
+
141
+ ## Composed functions
142
+ "expm1", "fma", "multiply_log", "ldexp", "lmultiply", "log1p",
143
+ "log1m", "log1p_exp", "log1m_exp", "log_diff_exp", "log_mix",
144
+ "log_sum_exp", "log_inv_logit", "log_inv_logit_diff",
145
+ "log1m_inv_logit",
146
+
147
+ ## Special functions
148
+ "lambert_w0", "lambert_wm1",
149
+
150
+ # Complex-Valued Basic Functions
151
+
152
+ ## Complex constructors and accessors
153
+ "to_complex", "get_real", "get_imag",
154
+
155
+ ## Complex special functions
156
+ "arg", "norm", "conj", "proj", "polar",
157
+
158
+ # Array Operations
159
+
160
+ ## Reductions
161
+ "sum", "prod", "log_sum_exp", "mean", "variance", "sd", "distance",
162
+ "squared_distance", "quantile",
163
+
164
+ ## Array size and dimension function
165
+ "dims", "num_elements",
166
+
167
+ ## Array broadcasting
168
+ "rep_array",
169
+
170
+ ## Array concatenation
171
+ "append_array",
172
+
173
+ ## Sorting functions
174
+ "sort_asc", "sort_desc", "sort_indices_asc", "sort_indices_desc",
175
+ "rank",
176
+
177
+ ## Reversing functions
178
+ "reverse",
179
+
180
+ # Matrix Operations
181
+
182
+ ## Integer-valued matrix size functions
183
+ "num_elements", "rows", "cols",
184
+
185
+ ## Dot products and specialized products
186
+ "dot_product", "columns_dot_product", "rows_dot_product", "dot_self",
187
+ "columns_dot_self", "rows_dot_self", "tcrossprod", "crossprod",
188
+ "quad_form", "quad_form_diag", "quad_form_sym", "trace_quad_form",
189
+ "trace_gen_quad_form", "multiply_lower_tri_self_transpose",
190
+ "diag_pre_multiply", "diag_post_multiply",
191
+
192
+ ## Broadcast functions
193
+ "rep_vector", "rep_row_vector", "rep_matrix",
194
+ "symmetrize_from_lower_tri",
195
+
196
+ ## Diagonal matrix functions
197
+ "add_diag", "diagonal", "diag_matrix", "identity_matrix",
198
+
199
+ ## Container construction functions
200
+ "linspaced_array", "linspaced_int_array", "linspaced_vector",
201
+ "linspaced_row_vector", "one_hot_int_array", "one_hot_array",
202
+ "one_hot_vector", "one_hot_row_vector", "ones_int_array",
203
+ "ones_array", "ones_vector", "ones_row_vector", "zeros_int_array",
204
+ "zeros_array", "zeros_vector", "zeros_row_vector", "uniform_simplex",
205
+
206
+ ## Slicing and blocking functions
207
+ "col", "row", "block", "sub_col", "sub_row", "head", "tail",
208
+ "segment",
209
+
210
+ ## Matrix concatenation
211
+ "append_col", "append_row",
212
+
213
+ ## Special matrix functions
214
+ "softmax", "log_softmax", "cumulative_sum",
215
+
216
+ ## Covariance functions
217
+ "cov_exp_quad",
218
+
219
+ ## Linear algebra functions and solvers
220
+ "mdivide_left_tri_low", "mdivide_right_tri_low", "mdivide_left_spd",
221
+ "mdivide_right_spd", "matrix_exp", "matrix_exp_multiply",
222
+ "scale_matrix_exp_multiply", "matrix_power", "trace", "determinant",
223
+ "log_determinant", "inverse", "inverse_spd", "chol2inv",
224
+ "generalized_inverse", "eigenvalues_sym", "eigenvectors_sym",
225
+ "qr_thin_Q", "qr_thin_R", "qr_Q", "qr_R", "cholseky_decompose",
226
+ "singular_values", "svd_U", "svd_V",
227
+
228
+ # Sparse Matrix Operations
229
+
230
+ ## Conversion functions
231
+ "csr_extract_w", "csr_extract_v", "csr_extract_u",
232
+ "csr_to_dense_matrix",
233
+
234
+ ## Sparse matrix arithmetic
235
+ "csr_matrix_times_vector",
236
+
237
+ # Mixed Operations
238
+ "to_matrix", "to_vector", "to_row_vector", "to_array_2d",
239
+ "to_array_1d",
240
+
241
+ # Higher-Order Functions
242
+
243
+ ## Algebraic equation solver
244
+ "algebra_solver", "algebra_solver_newton",
245
+
246
+ ## Ordinary differential equation
247
+ "ode_rk45", "ode_rk45_tol", "ode_ckrk", "ode_ckrk_tol", "ode_adams",
248
+ "ode_adams_tol", "ode_bdf", "ode_bdf_tol", "ode_adjoint_tol_ctl",
249
+
250
+ ## 1D integrator
251
+ "integrate_1d",
252
+
253
+ ## Reduce-sum function
254
+ "reduce_sum", "reduce_sum_static",
255
+
256
+ ## Map-rect function
257
+ "map_rect",
258
+
259
+ # Deprecated Functions
260
+ "integrate_ode_rk45", "integrate_ode", "integrate_ode_adams",
261
+ "integrate_ode_bdf",
262
+
263
+ # Hidden Markov Models
264
+ "hmm_marginal", "hmm_latent_rng", "hmm_hidden_state_prob"
265
+ ]
266
+ end
267
+
268
+ def self.distributions
269
+ @distributions ||= Set.new(
270
+ [
271
+ # Discrete Distributions
272
+
273
+ ## Binary Distributions
274
+ "bernoulli", "bernoulli_logit", "bernoulli_logit_glm",
275
+
276
+ ## Bounded Discrete Distributions
277
+ "binomial", "binomial_logit", "beta_binomial", "hypergeometric",
278
+ "categorical", "categorical_logit_glm", "discrete_range",
279
+ "ordered_logistic", "ordered_logistic_glm", "ordered_probit",
280
+
281
+ ## Unbounded Discrete Distributions
282
+ "neg_binomial", "neg_binomial_2", "neg_binomial_2_log",
283
+ "neg_binomial_2_log_glm", "poisson", "poisson_log",
284
+ "poisson_log_glm",
285
+
286
+ ## Multivariate Discrete Distributions
287
+ "multinomial", "multinomial_logit",
288
+
289
+ # Continuous Distributions
290
+
291
+ ## Unbounded Continuous Distributions
292
+ "normal", "std_normal", "normal_id_glm", "exp_mod_normal",
293
+ "skew_normal", "student_t", "cauchy", "double_exponential",
294
+ "logistic", "gumbel", "skew_double_exponential",
295
+
296
+ ## Positive Continuous Distributions
297
+ "lognormal", "chi_square", "inv_chi_square",
298
+ "scaled_inv_chi_square", "exponential", "gamma", "inv_gamma",
299
+ "weibull", "frechet", "rayleigh",
300
+
301
+ ## Positive Lower-Bounded Distributions
302
+ "pareto", "pareto_type_2", "wiener",
303
+
304
+ ## Continuous Distributions on [0, 1]
305
+ "beta", "beta_proportion",
306
+
307
+ ## Circular Distributions
308
+ "von_mises",
309
+
310
+ ## Bounded Continuous Distributions
311
+ "uniform",
312
+
313
+ ## Distributions over Unbounded Vectors
314
+ "multi_normal", "multi_normal_prec", "multi_normal_cholesky",
315
+ "multi_gp", "multi_gp_cholesky", "multi_student_t",
316
+ "gaussian_dlm_obs",
317
+
318
+ ## Simplex Distributions
319
+ "dirichlet",
320
+
321
+ ## Correlation Matrix Distributions
322
+ "lkj_corr", "lkj_corr_cholesky",
323
+
324
+ ## Covariance Matrix Distributions
325
+ "wishart", "inv_wishart"
326
+ ].product([
327
+ "", "_lpmf", "_lupmf", "_lpdf", "_lcdf", "_lccdf", "_rng", "_log",
328
+ "_cdf_log", "_ccdf_log"
329
+ ]).map {|s| "#{s[0]}#{s[1]}"}
330
+ )
331
+ end
332
+
333
+ def self.constants
334
+ @constants ||= Set.new [
335
+ # Mathematical constants
336
+ "pi", "e", "sqrt2", "log2", "log10",
337
+
338
+ # Special values
339
+ "not_a_number", "positive_infinity", "negative_infinity",
340
+ "machine_precision"
341
+ ]
342
+ end
343
+
344
+ state :root do
345
+ mixin :whitespace
346
+ rule %r/#include/, Comment::Preproc, :include
347
+ rule %r/#.*$/, Generic::Deleted
348
+ rule %r(
349
+ functions
350
+ |(?:transformed\s+)?data
351
+ |(?:transformed\s+)?parameters
352
+ |model
353
+ |generated\s+quantities
354
+ )x, Name::Namespace
355
+ rule %r(\{), Punctuation, :bracket_scope
356
+ mixin :scope
357
+ end
358
+
359
+ state :include do
360
+ rule %r((\s+)(\S+)(\s*)) do |m|
361
+ token Text, m[1]
362
+ token Comment::PreprocFile, m[2]
363
+ token Text, m[3]
364
+ pop!
365
+ end
366
+ end
367
+
368
+ state :whitespace do
369
+ rule %r(\n+)m, Text
370
+ rule %r(//(\\.|.)*?$), Comment::Single
371
+ mixin :inline_whitespace
372
+ end
373
+
374
+ state :inline_whitespace do
375
+ rule %r([ \t\r]+), Text
376
+ rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
377
+ end
378
+
379
+ state :statements do
380
+ mixin :whitespace
381
+ rule %r/#include/, Comment::Preproc, :include
382
+ rule %r/#.*$/, Generic::Deleted
383
+ rule %r("), Str, :string
384
+ rule %r(
385
+ (
386
+ ((\d+[.]\d*|[.]?\d+)e[+-]?\d+|\d*[.]\d+|\d+)
387
+ (#{WS})[+-](#{WS})
388
+ ((\d+[.]\d*|[.]?\d+)e[+-]?\d+|\d*[.]\d+|\d+)i
389
+ )
390
+ |((\d+[.]\d*|[.]?\d+)e[+-]?\d+|\d*[.]\d+|\d+)i
391
+ |((\d+[.]\d*|[.]?\d+)e[+-]?\d+|\d*[.]\d+)
392
+ )mx, Num::Float
393
+ rule %r/\d+/, Num::Integer
394
+ rule %r(\*/), Error
395
+ rule OP, Operator
396
+ rule %r([\[\],.;]), Punctuation
397
+ rule %r([|](?![|])), Punctuation
398
+ rule %r(T\b), Keyword::Reserved
399
+ rule %r((lower|upper)\b), Name::Attribute
400
+ rule ID do |m|
401
+ name = m[0]
402
+
403
+ if self.class.keywords.include? name
404
+ token Keyword
405
+ elsif self.class.types.include? name
406
+ token Keyword::Type
407
+ elsif self.class.reserved.include? name
408
+ token Keyword::Reserved
409
+ else
410
+ token Name::Variable
411
+ end
412
+ end
413
+ end
414
+
415
+ state :scope do
416
+ mixin :whitespace
417
+ rule %r(
418
+ (#{RT}) # Return type
419
+ (#{ID}) # Function name
420
+ (?=\([^;]*?\)) # Signature or arguments
421
+ )mx do |m|
422
+ recurse m[1]
423
+
424
+ name = m[2]
425
+ if self.class.builtin_functions.include? name
426
+ token Name::Builtin, name
427
+ elsif self.class.distributions.include? name
428
+ token Name::Builtin, name
429
+ elsif self.class.constants.include? name
430
+ token Keyword::Constant
431
+ else
432
+ token Name::Function, name
433
+ end
434
+ end
435
+ rule %r(\{), Punctuation, :bracket_scope
436
+ rule %r(\(), Punctuation, :parens_scope
437
+ mixin :statements
438
+ end
439
+
440
+ state :bracket_scope do
441
+ mixin :scope
442
+ rule %r(\}), Punctuation, :pop!
443
+ end
444
+
445
+ state :parens_scope do
446
+ mixin :scope
447
+ rule %r(\)), Punctuation, :pop!
448
+ end
449
+ end
450
+ end
451
+ end