prism 1.9.0 → 2.0.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/CODE_OF_CONDUCT.md +1 -1
  4. data/LICENSE.md +1 -1
  5. data/Makefile +41 -12
  6. data/README.md +35 -97
  7. data/config.yml +174 -161
  8. data/docs/build_system.md +2 -2
  9. data/docs/configuration.md +5 -4
  10. data/docs/encoding.md +2 -2
  11. data/docs/fuzzing.md +4 -11
  12. data/docs/javascript.md +19 -4
  13. data/docs/mapping.md +1 -1
  14. data/docs/releasing.md +77 -5
  15. data/docs/relocation.md +2 -4
  16. data/docs/serialization.md +22 -24
  17. data/docs/testing.md +46 -29
  18. data/ext/prism/api_node.c +1461 -1401
  19. data/ext/prism/extconf.rb +3 -4
  20. data/ext/prism/extension.c +796 -422
  21. data/ext/prism/extension.h +3 -3
  22. data/include/prism/arena.h +37 -0
  23. data/include/prism/ast.h +2727 -610
  24. data/include/prism/buffer.h +52 -0
  25. data/include/prism/comments.h +55 -0
  26. data/include/prism/compiler/accel.h +26 -0
  27. data/include/prism/compiler/align.h +36 -0
  28. data/include/prism/compiler/assume.h +25 -0
  29. data/include/prism/compiler/bswap.h +46 -0
  30. data/include/prism/compiler/endianness.h +34 -0
  31. data/include/prism/compiler/exported.h +24 -0
  32. data/include/prism/compiler/fallthrough.h +22 -0
  33. data/include/prism/compiler/filesystem.h +32 -0
  34. data/include/prism/compiler/flex_array.h +19 -0
  35. data/include/prism/compiler/force_inline.h +21 -0
  36. data/include/prism/compiler/format.h +25 -0
  37. data/include/prism/compiler/inline.h +17 -0
  38. data/include/prism/compiler/nodiscard.h +22 -0
  39. data/include/prism/compiler/nonnull.h +18 -0
  40. data/include/prism/compiler/unused.h +18 -0
  41. data/include/prism/constant_pool.h +81 -0
  42. data/include/prism/diagnostic.h +38 -403
  43. data/include/prism/errors_format.h +53 -0
  44. data/include/prism/excludes.h +29 -0
  45. data/include/prism/integer.h +41 -0
  46. data/include/prism/internal/allocator.h +68 -0
  47. data/include/prism/internal/allocator_debug.h +88 -0
  48. data/include/prism/internal/arena.h +108 -0
  49. data/include/prism/internal/bit.h +42 -0
  50. data/include/prism/internal/buffer.h +94 -0
  51. data/include/prism/internal/char.h +145 -0
  52. data/include/prism/internal/comments.h +53 -0
  53. data/include/prism/internal/constant_pool.h +152 -0
  54. data/include/prism/internal/diagnostic.h +389 -0
  55. data/include/prism/{encoding.h → internal/encoding.h} +27 -68
  56. data/include/prism/internal/integer.h +68 -0
  57. data/include/prism/internal/isinf.h +16 -0
  58. data/include/prism/internal/line_offset_list.h +34 -0
  59. data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  60. data/include/prism/internal/magic_comments.h +23 -0
  61. data/include/prism/internal/memchr.h +15 -0
  62. data/include/prism/internal/node.h +38 -0
  63. data/include/prism/internal/options.h +232 -0
  64. data/include/prism/internal/parser.h +1004 -0
  65. data/include/prism/internal/regexp.h +26 -0
  66. data/include/prism/internal/serialize.h +39 -0
  67. data/include/prism/internal/source.h +72 -0
  68. data/include/prism/{static_literals.h → internal/static_literals.h} +26 -47
  69. data/include/prism/internal/stringy.h +35 -0
  70. data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  71. data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  72. data/include/prism/internal/tokens.h +11 -0
  73. data/include/prism/internal/xxh3.h +16 -0
  74. data/include/prism/json.h +32 -0
  75. data/include/prism/line_offset_list.h +61 -0
  76. data/include/prism/magic_comments.h +35 -0
  77. data/include/prism/node.h +18 -53
  78. data/include/prism/options.h +146 -280
  79. data/include/prism/parser.h +356 -867
  80. data/include/prism/prettyprint.h +6 -9
  81. data/include/prism/serialize.h +115 -0
  82. data/include/prism/source.h +155 -0
  83. data/include/prism/stream.h +28 -0
  84. data/include/prism/string_query.h +74 -0
  85. data/include/prism/stringy.h +72 -0
  86. data/include/prism/version.h +12 -3
  87. data/include/prism.h +43 -320
  88. data/lib/prism/compiler.rb +319 -305
  89. data/lib/prism/desugar_compiler.rb +105 -34
  90. data/lib/prism/dispatcher.rb +646 -473
  91. data/lib/prism/dot_visitor.rb +592 -511
  92. data/lib/prism/dsl.rb +391 -25
  93. data/lib/prism/ffi.rb +258 -90
  94. data/lib/prism/inspect_visitor.rb +357 -325
  95. data/lib/prism/lex_compat.rb +254 -212
  96. data/lib/prism/mutation_compiler.rb +313 -305
  97. data/lib/prism/node.rb +20966 -6992
  98. data/lib/prism/node_ext.rb +180 -187
  99. data/lib/prism/node_find.rb +215 -0
  100. data/lib/prism/parse_result/errors.rb +7 -1
  101. data/lib/prism/parse_result/newlines.rb +276 -8
  102. data/lib/prism/parse_result.rb +468 -139
  103. data/lib/prism/pattern.rb +65 -20
  104. data/lib/prism/reflection.rb +23 -12
  105. data/lib/prism/relocation.rb +149 -87
  106. data/lib/prism/serialize.rb +3460 -539
  107. data/lib/prism/string_query.rb +24 -1
  108. data/lib/prism/translation/parser/builder.rb +10 -2
  109. data/lib/prism/translation/parser/compiler.rb +44 -52
  110. data/lib/prism/translation/parser/lexer.rb +41 -92
  111. data/lib/prism/translation/parser.rb +1 -1
  112. data/lib/prism/translation/parser_current.rb +1 -1
  113. data/lib/prism/translation/ripper/lexer.rb +8 -10
  114. data/lib/prism/translation/ripper/sexp.rb +2 -10
  115. data/lib/prism/translation/ripper/shim.rb +2 -0
  116. data/lib/prism/translation/ripper.rb +967 -209
  117. data/lib/prism/translation/ruby_parser.rb +73 -316
  118. data/lib/prism/translation.rb +2 -0
  119. data/lib/prism/visitor.rb +632 -5
  120. data/lib/prism.rb +79 -9
  121. data/prism.gemspec +128 -62
  122. data/rbi/generated/prism/compiler.rbi +489 -0
  123. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  124. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  125. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  126. data/rbi/generated/prism/dsl.rbi +751 -0
  127. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  128. data/rbi/generated/prism/lex_compat.rbi +162 -0
  129. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  130. data/rbi/generated/prism/node.rbi +14407 -0
  131. data/rbi/generated/prism/node_ext.rbi +259 -0
  132. data/rbi/generated/prism/node_find.rbi +79 -0
  133. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  134. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  135. data/rbi/generated/prism/parse_result.rbi +776 -0
  136. data/rbi/generated/prism/pattern.rbi +134 -0
  137. data/rbi/generated/prism/reflection.rbi +89 -0
  138. data/rbi/generated/prism/relocation.rbi +329 -0
  139. data/rbi/generated/prism/serialize.rbi +184 -0
  140. data/rbi/generated/prism/string_query.rbi +43 -0
  141. data/rbi/generated/prism/translation.rbi +7 -0
  142. data/rbi/generated/prism/visitor.rbi +650 -0
  143. data/rbi/generated/prism.rbi +86 -0
  144. data/rbi/prism/translation/parser_versions.rbi +5 -0
  145. data/rbi/rubyvm/node_find.rbi +14 -0
  146. data/sig/generated/prism/compiler.rbs +492 -0
  147. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  148. data/sig/generated/prism/dispatcher.rbs +1292 -0
  149. data/sig/generated/prism/dot_visitor.rbs +635 -0
  150. data/sig/generated/prism/dsl.rbs +928 -0
  151. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  152. data/sig/generated/prism/lex_compat.rbs +166 -0
  153. data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
  154. data/sig/generated/prism/node.rbs +20896 -0
  155. data/sig/generated/prism/node_ext.rbs +290 -0
  156. data/sig/generated/prism/node_find.rbs +90 -0
  157. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  158. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  159. data/sig/generated/prism/parse_result.rbs +871 -0
  160. data/sig/generated/prism/pattern.rbs +156 -0
  161. data/sig/generated/prism/reflection.rbs +101 -0
  162. data/sig/generated/prism/relocation.rbs +428 -0
  163. data/sig/generated/prism/serialize.rbs +198 -0
  164. data/sig/generated/prism/string_query.rbs +43 -0
  165. data/sig/generated/prism/translation.rbs +8 -0
  166. data/sig/generated/prism/visitor.rbs +1111 -0
  167. data/sig/generated/prism.rbs +84 -0
  168. data/sig/manifest.yaml +2 -0
  169. data/src/arena.c +117 -0
  170. data/src/{util/pm_buffer.c → buffer.c} +53 -21
  171. data/src/{util/pm_char.c → char.c} +28 -57
  172. data/src/comments.c +454 -0
  173. data/src/constant_pool.c +406 -0
  174. data/src/diagnostic.c +97 -65
  175. data/src/encoding.c +8 -3
  176. data/src/errors_format.c +519 -0
  177. data/src/{util/pm_integer.c → integer.c} +33 -22
  178. data/src/json.c +5733 -0
  179. data/src/line_offset_list.c +100 -0
  180. data/src/list.c +24 -0
  181. data/src/{util/pm_memchr.c → memchr.c} +8 -6
  182. data/src/node.c +3504 -7674
  183. data/src/options.c +162 -49
  184. data/src/parser.c +367 -0
  185. data/src/prettyprint.c +421 -354
  186. data/src/prism.c +8402 -7161
  187. data/src/regexp.c +961 -45
  188. data/src/serialize.c +460 -424
  189. data/src/source.c +518 -0
  190. data/src/static_literals.c +111 -43
  191. data/src/string_query.c +180 -0
  192. data/src/stringy.c +91 -0
  193. data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  194. data/src/strpbrk.c +447 -0
  195. data/src/{token_type.c → tokens.c} +39 -18
  196. data/src/xxh3.c +292 -0
  197. metadata +128 -63
  198. data/ext/prism/api_pack.c +0 -276
  199. data/include/prism/defines.h +0 -260
  200. data/include/prism/pack.h +0 -163
  201. data/include/prism/regexp.h +0 -43
  202. data/include/prism/util/pm_buffer.h +0 -236
  203. data/include/prism/util/pm_char.h +0 -204
  204. data/include/prism/util/pm_constant_pool.h +0 -218
  205. data/include/prism/util/pm_integer.h +0 -130
  206. data/include/prism/util/pm_memchr.h +0 -29
  207. data/include/prism/util/pm_newline_list.h +0 -113
  208. data/include/prism/util/pm_string.h +0 -200
  209. data/lib/prism/pack.rb +0 -230
  210. data/lib/prism/parse_result/comments.rb +0 -188
  211. data/rbi/prism/compiler.rbi +0 -12
  212. data/rbi/prism/dsl.rbi +0 -524
  213. data/rbi/prism/inspect_visitor.rbi +0 -12
  214. data/rbi/prism/node.rbi +0 -8750
  215. data/rbi/prism/node_ext.rbi +0 -107
  216. data/rbi/prism/parse_result.rbi +0 -404
  217. data/rbi/prism/reflection.rbi +0 -58
  218. data/rbi/prism/string_query.rbi +0 -12
  219. data/rbi/prism/visitor.rbi +0 -473
  220. data/rbi/prism.rbi +0 -63
  221. data/sig/prism/compiler.rbs +0 -9
  222. data/sig/prism/dispatcher.rbs +0 -19
  223. data/sig/prism/dot_visitor.rbs +0 -6
  224. data/sig/prism/dsl.rbs +0 -351
  225. data/sig/prism/inspect_visitor.rbs +0 -22
  226. data/sig/prism/lex_compat.rbs +0 -10
  227. data/sig/prism/node.rbs +0 -4042
  228. data/sig/prism/node_ext.rbs +0 -149
  229. data/sig/prism/pack.rbs +0 -43
  230. data/sig/prism/parse_result/comments.rbs +0 -38
  231. data/sig/prism/parse_result.rbs +0 -197
  232. data/sig/prism/pattern.rbs +0 -13
  233. data/sig/prism/reflection.rbs +0 -50
  234. data/sig/prism/relocation.rbs +0 -185
  235. data/sig/prism/serialize.rbs +0 -8
  236. data/sig/prism/string_query.rbs +0 -11
  237. data/sig/prism/visitor.rbs +0 -169
  238. data/sig/prism.rbs +0 -272
  239. data/src/pack.c +0 -509
  240. data/src/util/pm_constant_pool.c +0 -342
  241. data/src/util/pm_list.c +0 -49
  242. data/src/util/pm_newline_list.c +0 -125
  243. data/src/util/pm_string.c +0 -381
  244. data/src/util/pm_strpbrk.c +0 -206
@@ -0,0 +1,389 @@
1
+ /*----------------------------------------------------------------------------*/
2
+ /* This file is generated by the templates/template.rb script and should not */
3
+ /* be modified manually. See */
4
+ /* templates/include/prism/internal/diagnostic.h.erb */
5
+ /* if you are looking to modify the */
6
+ /* template */
7
+ /*----------------------------------------------------------------------------*/
8
+
9
+ #ifndef PRISM_INTERNAL_DIAGNOSTIC_H
10
+ #define PRISM_INTERNAL_DIAGNOSTIC_H
11
+
12
+ #include "prism/internal/list.h"
13
+
14
+ #include "prism/arena.h"
15
+ #include "prism/diagnostic.h"
16
+
17
+ /*
18
+ * The diagnostic IDs of all of the diagnostics, used to communicate the types
19
+ * of errors between the parser and the user.
20
+ */
21
+ typedef enum {
22
+ /* These are the error diagnostics. */
23
+ PM_ERR_ALIAS_ARGUMENT,
24
+ PM_ERR_ALIAS_ARGUMENT_NUMBERED_REFERENCE,
25
+ PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
26
+ PM_ERR_ARGUMENT_AFTER_BLOCK,
27
+ PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
28
+ PM_ERR_ARGUMENT_BARE_HASH,
29
+ PM_ERR_ARGUMENT_BLOCK_MULTI,
30
+ PM_ERR_ARGUMENT_CONFLICT_AMPERSAND,
31
+ PM_ERR_ARGUMENT_CONFLICT_STAR,
32
+ PM_ERR_ARGUMENT_CONFLICT_STAR_STAR,
33
+ PM_ERR_ARGUMENT_FORMAL_CLASS,
34
+ PM_ERR_ARGUMENT_FORMAL_CONSTANT,
35
+ PM_ERR_ARGUMENT_FORMAL_GLOBAL,
36
+ PM_ERR_ARGUMENT_FORMAL_IVAR,
37
+ PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
38
+ PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND,
39
+ PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
40
+ PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA,
41
+ PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK,
42
+ PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
43
+ PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR,
44
+ PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT,
45
+ PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT,
46
+ PM_ERR_ARGUMENT_TERM_PAREN,
47
+ PM_ERR_ARGUMENT_UNEXPECTED_BLOCK,
48
+ PM_ERR_ARRAY_ELEMENT,
49
+ PM_ERR_ARRAY_EXPRESSION,
50
+ PM_ERR_ARRAY_EXPRESSION_AFTER_STAR,
51
+ PM_ERR_ARRAY_SEPARATOR,
52
+ PM_ERR_ARRAY_TERM,
53
+ PM_ERR_BEGIN_LONELY_ELSE,
54
+ PM_ERR_BEGIN_TERM,
55
+ PM_ERR_BEGIN_UPCASE_BRACE,
56
+ PM_ERR_BEGIN_UPCASE_TERM,
57
+ PM_ERR_BEGIN_UPCASE_TOPLEVEL,
58
+ PM_ERR_BLOCK_PARAM_LOCAL_VARIABLE,
59
+ PM_ERR_BLOCK_PARAM_PIPE_TERM,
60
+ PM_ERR_BLOCK_TERM_BRACE,
61
+ PM_ERR_BLOCK_TERM_END,
62
+ PM_ERR_CANNOT_PARSE_EXPRESSION,
63
+ PM_ERR_CANNOT_PARSE_STRING_PART,
64
+ PM_ERR_CASE_EXPRESSION_AFTER_CASE,
65
+ PM_ERR_CASE_EXPRESSION_AFTER_WHEN,
66
+ PM_ERR_CASE_MATCH_MISSING_PREDICATE,
67
+ PM_ERR_CASE_MISSING_CONDITIONS,
68
+ PM_ERR_CASE_TERM,
69
+ PM_ERR_CLASS_IN_METHOD,
70
+ PM_ERR_CLASS_NAME,
71
+ PM_ERR_CLASS_SUPERCLASS,
72
+ PM_ERR_CLASS_TERM,
73
+ PM_ERR_CLASS_UNEXPECTED_END,
74
+ PM_ERR_CLASS_VARIABLE_BARE,
75
+ PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
76
+ PM_ERR_CONDITIONAL_IF_PREDICATE,
77
+ PM_ERR_CONDITIONAL_PREDICATE_TERM,
78
+ PM_ERR_CONDITIONAL_TERM,
79
+ PM_ERR_CONDITIONAL_TERM_ELSE,
80
+ PM_ERR_CONDITIONAL_UNLESS_PREDICATE,
81
+ PM_ERR_CONDITIONAL_UNTIL_PREDICATE,
82
+ PM_ERR_CONDITIONAL_WHILE_PREDICATE,
83
+ PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT,
84
+ PM_ERR_DEF_ENDLESS,
85
+ PM_ERR_DEF_ENDLESS_PARAMETERS,
86
+ PM_ERR_DEF_ENDLESS_SETTER,
87
+ PM_ERR_DEF_ENDLESS_DO_BLOCK,
88
+ PM_ERR_DEF_NAME,
89
+ PM_ERR_DEF_PARAMS_TERM,
90
+ PM_ERR_DEF_PARAMS_TERM_PAREN,
91
+ PM_ERR_DEF_RECEIVER,
92
+ PM_ERR_DEF_RECEIVER_TERM,
93
+ PM_ERR_DEF_TERM,
94
+ PM_ERR_DEFINED_EXPRESSION,
95
+ PM_ERR_EMBDOC_TERM,
96
+ PM_ERR_EMBEXPR_END,
97
+ PM_ERR_EMBVAR_INVALID,
98
+ PM_ERR_END_UPCASE_BRACE,
99
+ PM_ERR_END_UPCASE_TERM,
100
+ PM_ERR_ESCAPE_INVALID_CONTROL,
101
+ PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT,
102
+ PM_ERR_ESCAPE_INVALID_HEXADECIMAL,
103
+ PM_ERR_ESCAPE_INVALID_META,
104
+ PM_ERR_ESCAPE_INVALID_META_REPEAT,
105
+ PM_ERR_ESCAPE_INVALID_UNICODE,
106
+ PM_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS,
107
+ PM_ERR_ESCAPE_INVALID_UNICODE_LIST,
108
+ PM_ERR_ESCAPE_INVALID_UNICODE_LITERAL,
109
+ PM_ERR_ESCAPE_INVALID_UNICODE_LONG,
110
+ PM_ERR_ESCAPE_INVALID_UNICODE_SHORT,
111
+ PM_ERR_ESCAPE_INVALID_UNICODE_TERM,
112
+ PM_ERR_EXPECT_ARGUMENT,
113
+ PM_ERR_EXPECT_EOL_AFTER_STATEMENT,
114
+ PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ,
115
+ PM_ERR_EXPECT_EXPRESSION_AFTER_COMMA,
116
+ PM_ERR_EXPECT_EXPRESSION_AFTER_EQUAL,
117
+ PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS,
118
+ PM_ERR_EXPECT_EXPRESSION_AFTER_LPAREN,
119
+ PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR,
120
+ PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
121
+ PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT,
122
+ PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
123
+ PM_ERR_EXPECT_EXPRESSION_AFTER_STAR,
124
+ PM_ERR_EXPECT_FOR_DELIMITER,
125
+ PM_ERR_EXPECT_IDENT_REQ_PARAMETER,
126
+ PM_ERR_EXPECT_IN_DELIMITER,
127
+ PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN,
128
+ PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER,
129
+ PM_ERR_EXPECT_LPAREN_REQ_PARAMETER,
130
+ PM_ERR_EXPECT_MESSAGE,
131
+ PM_ERR_EXPECT_RBRACKET,
132
+ PM_ERR_EXPECT_RPAREN,
133
+ PM_ERR_EXPECT_RPAREN_AFTER_MULTI,
134
+ PM_ERR_EXPECT_RPAREN_REQ_PARAMETER,
135
+ PM_ERR_EXPECT_SINGLETON_CLASS_DELIMITER,
136
+ PM_ERR_EXPECT_STRING_CONTENT,
137
+ PM_ERR_EXPECT_WHEN_DELIMITER,
138
+ PM_ERR_EXPRESSION_BARE_HASH,
139
+ PM_ERR_EXPRESSION_NOT_WRITABLE,
140
+ PM_ERR_EXPRESSION_NOT_WRITABLE_ENCODING,
141
+ PM_ERR_EXPRESSION_NOT_WRITABLE_FALSE,
142
+ PM_ERR_EXPRESSION_NOT_WRITABLE_FILE,
143
+ PM_ERR_EXPRESSION_NOT_WRITABLE_LINE,
144
+ PM_ERR_EXPRESSION_NOT_WRITABLE_NIL,
145
+ PM_ERR_EXPRESSION_NOT_WRITABLE_NUMBERED,
146
+ PM_ERR_EXPRESSION_NOT_WRITABLE_SELF,
147
+ PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE,
148
+ PM_ERR_FLOAT_PARSE,
149
+ PM_ERR_FOR_COLLECTION,
150
+ PM_ERR_FOR_IN,
151
+ PM_ERR_FOR_INDEX,
152
+ PM_ERR_FOR_TERM,
153
+ PM_ERR_GLOBAL_VARIABLE_BARE,
154
+ PM_ERR_HASH_EXPRESSION_AFTER_LABEL,
155
+ PM_ERR_HASH_KEY,
156
+ PM_ERR_HASH_ROCKET,
157
+ PM_ERR_HASH_TERM,
158
+ PM_ERR_HASH_VALUE,
159
+ PM_ERR_HEREDOC_IDENTIFIER,
160
+ PM_ERR_HEREDOC_TERM,
161
+ PM_ERR_INCOMPLETE_QUESTION_MARK,
162
+ PM_ERR_INCOMPLETE_VARIABLE_CLASS,
163
+ PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3,
164
+ PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
165
+ PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3,
166
+ PM_ERR_INSTANCE_VARIABLE_BARE,
167
+ PM_ERR_INVALID_BLOCK_EXIT,
168
+ PM_ERR_INVALID_CHARACTER,
169
+ PM_ERR_INVALID_COMMA,
170
+ PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
171
+ PM_ERR_INVALID_ESCAPE_CHARACTER,
172
+ PM_ERR_INVALID_FLOAT_EXPONENT,
173
+ PM_ERR_INVALID_LOCAL_VARIABLE_READ,
174
+ PM_ERR_INVALID_LOCAL_VARIABLE_WRITE,
175
+ PM_ERR_INVALID_MULTIBYTE_CHAR,
176
+ PM_ERR_INVALID_MULTIBYTE_CHARACTER,
177
+ PM_ERR_INVALID_MULTIBYTE_ESCAPE,
178
+ PM_ERR_INVALID_NUMBER_BINARY,
179
+ PM_ERR_INVALID_NUMBER_DECIMAL,
180
+ PM_ERR_INVALID_NUMBER_FRACTION,
181
+ PM_ERR_INVALID_NUMBER_HEXADECIMAL,
182
+ PM_ERR_INVALID_NUMBER_OCTAL,
183
+ PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER,
184
+ PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING,
185
+ PM_ERR_INVALID_PERCENT,
186
+ PM_ERR_INVALID_PERCENT_EOF,
187
+ PM_ERR_INVALID_PRINTABLE_CHARACTER,
188
+ PM_ERR_INVALID_RETRY_AFTER_ELSE,
189
+ PM_ERR_INVALID_RETRY_AFTER_ENSURE,
190
+ PM_ERR_INVALID_RETRY_WITHOUT_RESCUE,
191
+ PM_ERR_INVALID_SYMBOL,
192
+ PM_ERR_INVALID_VARIABLE_GLOBAL,
193
+ PM_ERR_INVALID_VARIABLE_GLOBAL_3_3,
194
+ PM_ERR_INVALID_YIELD,
195
+ PM_ERR_IT_NOT_ALLOWED_NUMBERED,
196
+ PM_ERR_IT_NOT_ALLOWED_ORDINARY,
197
+ PM_ERR_LAMBDA_OPEN,
198
+ PM_ERR_LAMBDA_TERM_BRACE,
199
+ PM_ERR_LAMBDA_TERM_END,
200
+ PM_ERR_LIST_I_LOWER_ELEMENT,
201
+ PM_ERR_LIST_I_LOWER_TERM,
202
+ PM_ERR_LIST_I_UPPER_ELEMENT,
203
+ PM_ERR_LIST_I_UPPER_TERM,
204
+ PM_ERR_LIST_W_LOWER_ELEMENT,
205
+ PM_ERR_LIST_W_LOWER_TERM,
206
+ PM_ERR_LIST_W_UPPER_ELEMENT,
207
+ PM_ERR_LIST_W_UPPER_TERM,
208
+ PM_ERR_MALLOC_FAILED,
209
+ PM_ERR_MIXED_ENCODING,
210
+ PM_ERR_MODULE_IN_METHOD,
211
+ PM_ERR_MODULE_NAME,
212
+ PM_ERR_MODULE_TERM,
213
+ PM_ERR_MULTI_ASSIGN_MULTI_SPLATS,
214
+ PM_ERR_MULTI_ASSIGN_UNEXPECTED_REST,
215
+ PM_ERR_NESTING_TOO_DEEP,
216
+ PM_ERR_NO_LOCAL_VARIABLE,
217
+ PM_ERR_NON_ASSOCIATIVE_OPERATOR,
218
+ PM_ERR_NOT_EXPRESSION,
219
+ PM_ERR_NUMBER_LITERAL_UNDERSCORE,
220
+ PM_ERR_NUMBERED_PARAMETER_INNER_BLOCK,
221
+ PM_ERR_NUMBERED_PARAMETER_IT,
222
+ PM_ERR_NUMBERED_PARAMETER_ORDINARY,
223
+ PM_ERR_NUMBERED_PARAMETER_OUTER_BLOCK,
224
+ PM_ERR_OPERATOR_MULTI_ASSIGN,
225
+ PM_ERR_OPERATOR_WRITE_ARGUMENTS,
226
+ PM_ERR_OPERATOR_WRITE_BLOCK,
227
+ PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
228
+ PM_ERR_PARAMETER_BLOCK_MULTI,
229
+ PM_ERR_PARAMETER_CIRCULAR,
230
+ PM_ERR_PARAMETER_FORWARDING_AFTER_REST,
231
+ PM_ERR_PARAMETER_METHOD_NAME,
232
+ PM_ERR_PARAMETER_NAME_DUPLICATED,
233
+ PM_ERR_PARAMETER_NO_DEFAULT,
234
+ PM_ERR_PARAMETER_NO_DEFAULT_KW,
235
+ PM_ERR_PARAMETER_NUMBERED_RESERVED,
236
+ PM_ERR_PARAMETER_ORDER,
237
+ PM_ERR_PARAMETER_SPLAT_MULTI,
238
+ PM_ERR_PARAMETER_STAR,
239
+ PM_ERR_PARAMETER_UNEXPECTED_FWD,
240
+ PM_ERR_PARAMETER_UNEXPECTED_NO_KW,
241
+ PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
242
+ PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS,
243
+ PM_ERR_PATTERN_CAPTURE_DUPLICATE,
244
+ PM_ERR_PATTERN_CAPTURE_IN_ALTERNATIVE,
245
+ PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
246
+ PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
247
+ PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
248
+ PM_ERR_PATTERN_EXPRESSION_AFTER_IN,
249
+ PM_ERR_PATTERN_EXPRESSION_AFTER_KEY,
250
+ PM_ERR_PATTERN_EXPRESSION_AFTER_PAREN,
251
+ PM_ERR_PATTERN_EXPRESSION_AFTER_PIN,
252
+ PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
253
+ PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
254
+ PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
255
+ PM_ERR_PATTERN_FIND_MISSING_INNER,
256
+ PM_ERR_PATTERN_HASH_IMPLICIT,
257
+ PM_ERR_PATTERN_HASH_KEY,
258
+ PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
259
+ PM_ERR_PATTERN_HASH_KEY_INTERPOLATED,
260
+ PM_ERR_PATTERN_HASH_KEY_LABEL,
261
+ PM_ERR_PATTERN_HASH_KEY_LOCALS,
262
+ PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
263
+ PM_ERR_PATTERN_LABEL_AFTER_COMMA,
264
+ PM_ERR_PATTERN_REST,
265
+ PM_ERR_PATTERN_TERM_BRACE,
266
+ PM_ERR_PATTERN_TERM_BRACKET,
267
+ PM_ERR_PATTERN_TERM_PAREN,
268
+ PM_ERR_PIPEPIPEEQ_MULTI_ASSIGN,
269
+ PM_ERR_REGEXP_ENCODING_OPTION_MISMATCH,
270
+ PM_ERR_REGEXP_ESCAPED_NON_ASCII_IN_UTF8,
271
+ PM_ERR_REGEXP_INCOMPAT_CHAR_ENCODING,
272
+ PM_ERR_REGEXP_INVALID_CHAR_PROPERTY,
273
+ PM_ERR_REGEXP_INVALID_UNICODE_RANGE,
274
+ PM_ERR_REGEXP_NON_ESCAPED_MBC,
275
+ PM_ERR_REGEXP_PARSE_ERROR,
276
+ PM_ERR_REGEXP_TERM,
277
+ PM_ERR_REGEXP_UNKNOWN_OPTIONS,
278
+ PM_ERR_REGEXP_UTF8_CHAR_NON_UTF8_REGEXP,
279
+ PM_ERR_RESCUE_EXPRESSION,
280
+ PM_ERR_RESCUE_MODIFIER_VALUE,
281
+ PM_ERR_RESCUE_TERM,
282
+ PM_ERR_RESCUE_VARIABLE,
283
+ PM_ERR_RETURN_INVALID,
284
+ PM_ERR_SCRIPT_NOT_FOUND,
285
+ PM_ERR_SINGLETON_FOR_LITERALS,
286
+ PM_ERR_STATEMENT_ALIAS,
287
+ PM_ERR_STATEMENT_POSTEXE_END,
288
+ PM_ERR_STATEMENT_PREEXE_BEGIN,
289
+ PM_ERR_STATEMENT_UNDEF,
290
+ PM_ERR_STRING_CONCATENATION,
291
+ PM_ERR_STRING_INTERPOLATED_TERM,
292
+ PM_ERR_STRING_LITERAL_EOF,
293
+ PM_ERR_STRING_LITERAL_TERM,
294
+ PM_ERR_SYMBOL_INVALID,
295
+ PM_ERR_SYMBOL_TERM_DYNAMIC,
296
+ PM_ERR_SYMBOL_TERM_INTERPOLATED,
297
+ PM_ERR_TERNARY_COLON,
298
+ PM_ERR_TERNARY_EXPRESSION_FALSE,
299
+ PM_ERR_TERNARY_EXPRESSION_TRUE,
300
+ PM_ERR_UNARY_DISALLOWED,
301
+ PM_ERR_UNARY_RECEIVER,
302
+ PM_ERR_UNDEF_ARGUMENT,
303
+ PM_ERR_UNEXPECTED_BLOCK_ARGUMENT,
304
+ PM_ERR_UNEXPECTED_INDEX_BLOCK,
305
+ PM_ERR_UNEXPECTED_INDEX_KEYWORDS,
306
+ PM_ERR_UNEXPECTED_LABEL,
307
+ PM_ERR_UNEXPECTED_MULTI_WRITE,
308
+ PM_ERR_UNEXPECTED_PARAMETER_DEFAULT_VALUE,
309
+ PM_ERR_UNEXPECTED_RANGE_OPERATOR,
310
+ PM_ERR_UNEXPECTED_SAFE_NAVIGATION,
311
+ PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT,
312
+ PM_ERR_UNEXPECTED_TOKEN_IGNORE,
313
+ PM_ERR_UNTIL_TERM,
314
+ PM_ERR_VOID_EXPRESSION,
315
+ PM_ERR_WHILE_TERM,
316
+ PM_ERR_WRITE_TARGET_IN_METHOD,
317
+ PM_ERR_WRITE_TARGET_READONLY,
318
+ PM_ERR_WRITE_TARGET_UNEXPECTED,
319
+ PM_ERR_XSTRING_TERM,
320
+
321
+ /* These are the warning diagnostics. */
322
+ PM_WARN_AMBIGUOUS_BINARY_OPERATOR,
323
+ PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
324
+ PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
325
+ PM_WARN_AMBIGUOUS_PREFIX_AMPERSAND,
326
+ PM_WARN_AMBIGUOUS_PREFIX_STAR,
327
+ PM_WARN_AMBIGUOUS_PREFIX_STAR_STAR,
328
+ PM_WARN_AMBIGUOUS_SLASH,
329
+ PM_WARN_COMPARISON_AFTER_COMPARISON,
330
+ PM_WARN_DOT_DOT_DOT_EOL,
331
+ PM_WARN_EQUAL_IN_CONDITIONAL,
332
+ PM_WARN_EQUAL_IN_CONDITIONAL_3_3,
333
+ PM_WARN_END_IN_METHOD,
334
+ PM_WARN_DUPLICATED_HASH_KEY,
335
+ PM_WARN_DUPLICATED_WHEN_CLAUSE,
336
+ PM_WARN_FLOAT_OUT_OF_RANGE,
337
+ PM_WARN_IGNORED_FROZEN_STRING_LITERAL,
338
+ PM_WARN_INDENTATION_MISMATCH,
339
+ PM_WARN_INTEGER_IN_FLIP_FLOP,
340
+ PM_WARN_INVALID_CHARACTER,
341
+ PM_WARN_INVALID_MAGIC_COMMENT_VALUE,
342
+ PM_WARN_INVALID_NUMBERED_REFERENCE,
343
+ PM_WARN_KEYWORD_EOL,
344
+ PM_WARN_LITERAL_IN_CONDITION_DEFAULT,
345
+ PM_WARN_LITERAL_IN_CONDITION_VERBOSE,
346
+ PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE,
347
+ PM_WARN_SHEBANG_CARRIAGE_RETURN,
348
+ PM_WARN_UNEXPECTED_CARRIAGE_RETURN,
349
+ PM_WARN_UNREACHABLE_STATEMENT,
350
+ PM_WARN_UNUSED_LOCAL_VARIABLE,
351
+ PM_WARN_VOID_STATEMENT,
352
+ } pm_diagnostic_id_t;
353
+
354
+ /*
355
+ * This struct represents a diagnostic generated during parsing.
356
+ */
357
+ struct pm_diagnostic_t {
358
+ /* The embedded base node. */
359
+ pm_list_node_t node;
360
+
361
+ /* The location of the diagnostic in the source. */
362
+ pm_location_t location;
363
+
364
+ /* The ID of the diagnostic. */
365
+ pm_diagnostic_id_t diag_id;
366
+
367
+ /* The message associated with the diagnostic. */
368
+ const char *message;
369
+
370
+ /*
371
+ * The level of the diagnostic, see `pm_error_level_t` and
372
+ * `pm_warning_level_t` for possible values.
373
+ */
374
+ uint8_t level;
375
+ };
376
+
377
+ /*
378
+ * Append a diagnostic to the given list of diagnostics that is using shared
379
+ * memory for its message.
380
+ */
381
+ void pm_diagnostic_list_append(pm_arena_t *arena, pm_list_t *list, uint32_t start, uint32_t length, pm_diagnostic_id_t diag_id);
382
+
383
+ /*
384
+ * Append a diagnostic to the given list of diagnostics that is using a format
385
+ * string for its message.
386
+ */
387
+ void pm_diagnostic_list_append_format(pm_arena_t *arena, pm_list_t *list, uint32_t start, uint32_t length, pm_diagnostic_id_t diag_id, ...);
388
+
389
+ #endif
@@ -1,128 +1,95 @@
1
- /**
2
- * @file encoding.h
3
- *
4
- * The encoding interface and implementations used by the parser.
5
- */
6
- #ifndef PRISM_ENCODING_H
7
- #define PRISM_ENCODING_H
8
-
9
- #include "prism/defines.h"
10
- #include "prism/util/pm_strncasecmp.h"
1
+ #ifndef PRISM_INTERNAL_ENCODING_H
2
+ #define PRISM_INTERNAL_ENCODING_H
11
3
 
12
- #include <assert.h>
13
4
  #include <stdbool.h>
14
5
  #include <stddef.h>
15
6
  #include <stdint.h>
16
7
 
17
- /**
8
+ /*
18
9
  * This struct defines the functions necessary to implement the encoding
19
10
  * interface so we can determine how many bytes the subsequent character takes.
20
11
  * Each callback should return the number of bytes, or 0 if the next bytes are
21
12
  * invalid for the encoding and type.
22
13
  */
23
14
  typedef struct {
24
- /**
15
+ /*
25
16
  * Return the number of bytes that the next character takes if it is valid
26
17
  * in the encoding. Does not read more than n bytes. It is assumed that n is
27
18
  * at least 1.
28
19
  */
29
20
  size_t (*char_width)(const uint8_t *b, ptrdiff_t n);
30
21
 
31
- /**
22
+ /*
32
23
  * Return the number of bytes that the next character takes if it is valid
33
24
  * in the encoding and is alphabetical. Does not read more than n bytes. It
34
25
  * is assumed that n is at least 1.
35
26
  */
36
27
  size_t (*alpha_char)(const uint8_t *b, ptrdiff_t n);
37
28
 
38
- /**
29
+ /*
39
30
  * Return the number of bytes that the next character takes if it is valid
40
31
  * in the encoding and is alphanumeric. Does not read more than n bytes. It
41
32
  * is assumed that n is at least 1.
42
33
  */
43
34
  size_t (*alnum_char)(const uint8_t *b, ptrdiff_t n);
44
35
 
45
- /**
36
+ /*
46
37
  * Return true if the next character is valid in the encoding and is an
47
38
  * uppercase character. Does not read more than n bytes. It is assumed that
48
39
  * n is at least 1.
49
40
  */
50
41
  bool (*isupper_char)(const uint8_t *b, ptrdiff_t n);
51
42
 
52
- /**
43
+ /*
53
44
  * The name of the encoding. This should correspond to a value that can be
54
45
  * passed to Encoding.find in Ruby.
55
46
  */
56
47
  const char *name;
57
48
 
58
- /**
59
- * Return true if the encoding is a multibyte encoding.
60
- */
49
+ /* Return true if the encoding is a multibyte encoding. */
61
50
  bool multibyte;
62
51
  } pm_encoding_t;
63
52
 
64
- /**
53
+ /*
65
54
  * All of the lookup tables use the first bit of each embedded byte to indicate
66
55
  * whether the codepoint is alphabetical.
67
56
  */
68
57
  #define PRISM_ENCODING_ALPHABETIC_BIT 1 << 0
69
58
 
70
- /**
59
+ /*
71
60
  * All of the lookup tables use the second bit of each embedded byte to indicate
72
61
  * whether the codepoint is alphanumeric.
73
62
  */
74
63
  #define PRISM_ENCODING_ALPHANUMERIC_BIT 1 << 1
75
64
 
76
- /**
65
+ /*
77
66
  * All of the lookup tables use the third bit of each embedded byte to indicate
78
67
  * whether the codepoint is uppercase.
79
68
  */
80
69
  #define PRISM_ENCODING_UPPERCASE_BIT 1 << 2
81
70
 
82
- /**
83
- * Return the size of the next character in the UTF-8 encoding.
84
- *
85
- * @param b The bytes to read.
86
- * @param n The number of bytes that can be read.
87
- * @returns The number of bytes that the next character takes if it is valid in
88
- * the encoding, or 0 if it is not.
89
- */
71
+ /* Return the size of the next character in the UTF-8 encoding. */
90
72
  size_t pm_encoding_utf_8_char_width(const uint8_t *b, ptrdiff_t n);
91
73
 
92
- /**
74
+ /*
93
75
  * Return the size of the next character in the UTF-8 encoding if it is an
94
76
  * alphabetical character.
95
- *
96
- * @param b The bytes to read.
97
- * @param n The number of bytes that can be read.
98
- * @returns The number of bytes that the next character takes if it is valid in
99
- * the encoding, or 0 if it is not.
100
77
  */
101
78
  size_t pm_encoding_utf_8_alpha_char(const uint8_t *b, ptrdiff_t n);
102
79
 
103
- /**
80
+ /*
104
81
  * Return the size of the next character in the UTF-8 encoding if it is an
105
82
  * alphanumeric character.
106
- *
107
- * @param b The bytes to read.
108
- * @param n The number of bytes that can be read.
109
- * @returns The number of bytes that the next character takes if it is valid in
110
- * the encoding, or 0 if it is not.
111
83
  */
112
84
  size_t pm_encoding_utf_8_alnum_char(const uint8_t *b, ptrdiff_t n);
113
85
 
114
- /**
86
+ /*
115
87
  * Return true if the next character in the UTF-8 encoding if it is an uppercase
116
88
  * character.
117
- *
118
- * @param b The bytes to read.
119
- * @param n The number of bytes that can be read.
120
- * @returns True if the next character is valid in the encoding and is an
121
- * uppercase character, or false if it is not.
122
89
  */
123
90
  bool pm_encoding_utf_8_isupper_char(const uint8_t *b, ptrdiff_t n);
124
91
 
125
- /**
92
+ /*
126
93
  * This lookup table is referenced in both the UTF-8 encoding file and the
127
94
  * parser directly in order to speed up the default encoding processing. It is
128
95
  * used to indicate whether a character is alphabetical, alphanumeric, or
@@ -130,9 +97,7 @@ bool pm_encoding_utf_8_isupper_char(const uint8_t *b, ptrdiff_t n);
130
97
  */
131
98
  extern const uint8_t pm_encoding_unicode_table[256];
132
99
 
133
- /**
134
- * These are all of the encodings that prism supports.
135
- */
100
+ /* These are all of the encodings that prism supports. */
136
101
  typedef enum {
137
102
  PM_ENCODING_UTF_8 = 0,
138
103
  PM_ENCODING_US_ASCII,
@@ -140,8 +105,8 @@ typedef enum {
140
105
  PM_ENCODING_EUC_JP,
141
106
  PM_ENCODING_WINDOWS_31J,
142
107
 
143
- // We optionally support excluding the full set of encodings to only support the
144
- // minimum necessary to process Ruby code without encoding comments.
108
+ /* We optionally support excluding the full set of encodings to only support the
109
+ * minimum necessary to process Ruby code without encoding comments. */
145
110
  #ifndef PRISM_ENCODING_EXCLUDE_FULL
146
111
  PM_ENCODING_BIG5,
147
112
  PM_ENCODING_BIG5_HKSCS,
@@ -233,50 +198,44 @@ typedef enum {
233
198
  PM_ENCODING_MAXIMUM
234
199
  } pm_encoding_type_t;
235
200
 
236
- /**
237
- * This is the table of all of the encodings that prism supports.
238
- */
201
+ /* This is the table of all of the encodings that prism supports. */
239
202
  extern const pm_encoding_t pm_encodings[PM_ENCODING_MAXIMUM];
240
203
 
241
- /**
204
+ /*
242
205
  * This is the default UTF-8 encoding. We need a reference to it to quickly
243
206
  * create parsers.
244
207
  */
245
208
  #define PM_ENCODING_UTF_8_ENTRY (&pm_encodings[PM_ENCODING_UTF_8])
246
209
 
247
- /**
210
+ /*
248
211
  * This is the US-ASCII encoding. We need a reference to it to be able to
249
212
  * compare against it when a string is being created because it could possibly
250
213
  * need to fall back to ASCII-8BIT.
251
214
  */
252
215
  #define PM_ENCODING_US_ASCII_ENTRY (&pm_encodings[PM_ENCODING_US_ASCII])
253
216
 
254
- /**
217
+ /*
255
218
  * This is the ASCII-8BIT encoding. We need a reference to it so that pm_strpbrk
256
219
  * can compare against it because invalid multibyte characters are not a thing
257
220
  * in this encoding. It is also needed for handling Regexp encoding flags.
258
221
  */
259
222
  #define PM_ENCODING_ASCII_8BIT_ENTRY (&pm_encodings[PM_ENCODING_ASCII_8BIT])
260
223
 
261
- /**
224
+ /*
262
225
  * This is the EUC-JP encoding. We need a reference to it to quickly process
263
226
  * regular expression modifiers.
264
227
  */
265
228
  #define PM_ENCODING_EUC_JP_ENTRY (&pm_encodings[PM_ENCODING_EUC_JP])
266
229
 
267
- /**
230
+ /*
268
231
  * This is the Windows-31J encoding. We need a reference to it to quickly
269
232
  * process regular expression modifiers.
270
233
  */
271
234
  #define PM_ENCODING_WINDOWS_31J_ENTRY (&pm_encodings[PM_ENCODING_WINDOWS_31J])
272
235
 
273
- /**
236
+ /*
274
237
  * Parse the given name of an encoding and return a pointer to the corresponding
275
238
  * encoding struct if one can be found, otherwise return NULL.
276
- *
277
- * @param start A pointer to the first byte of the name.
278
- * @param end A pointer to the last byte of the name.
279
- * @returns A pointer to the encoding struct if one is found, otherwise NULL.
280
239
  */
281
240
  const pm_encoding_t * pm_encoding_find(const uint8_t *start, const uint8_t *end);
282
241
 
@@ -0,0 +1,68 @@
1
+ /*
2
+ * This module provides functions for working with arbitrary-sized integers.
3
+ */
4
+ #ifndef PRISM_INTERNAL_INTEGER_H
5
+ #define PRISM_INTERNAL_INTEGER_H
6
+
7
+ #include "prism/buffer.h"
8
+ #include "prism/integer.h"
9
+
10
+ #include <stdint.h>
11
+
12
+ /*
13
+ * An enum controlling the base of an integer. It is expected that the base is
14
+ * already known before parsing the integer, even though it could be derived
15
+ * from the string itself.
16
+ */
17
+ typedef enum {
18
+ /* The default decimal base, with no prefix. Leading 0s will be ignored. */
19
+ PM_INTEGER_BASE_DEFAULT,
20
+
21
+ /* The binary base, indicated by a 0b or 0B prefix. */
22
+ PM_INTEGER_BASE_BINARY,
23
+
24
+ /* The octal base, indicated by a 0, 0o, or 0O prefix. */
25
+ PM_INTEGER_BASE_OCTAL,
26
+
27
+ /* The decimal base, indicated by a 0d, 0D, or empty prefix. */
28
+ PM_INTEGER_BASE_DECIMAL,
29
+
30
+ /* The hexadecimal base, indicated by a 0x or 0X prefix. */
31
+ PM_INTEGER_BASE_HEXADECIMAL,
32
+
33
+ /*
34
+ * An unknown base, in which case pm_integer_parse will derive it based on
35
+ * the content of the string. This is less efficient and does more
36
+ * comparisons, so if callers know the base ahead of time, they should use
37
+ * that instead.
38
+ */
39
+ PM_INTEGER_BASE_UNKNOWN
40
+ } pm_integer_base_t;
41
+
42
+ /*
43
+ * Parse an integer from a string. This assumes that the format of the integer
44
+ * has already been validated, as internal validation checks are not performed
45
+ * here.
46
+ */
47
+ void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
48
+
49
+ /*
50
+ * Compare two integers. This function returns -1 if the left integer is less
51
+ * than the right integer, 0 if they are equal, and 1 if the left integer is
52
+ * greater than the right integer.
53
+ */
54
+ int pm_integer_compare(const pm_integer_t *left, const pm_integer_t *right);
55
+
56
+ /*
57
+ * Reduce a ratio of integers to its simplest form.
58
+ *
59
+ * If either the numerator or denominator do not fit into a 32-bit integer, then
60
+ * this function is a no-op. In the future, we may consider reducing even the
61
+ * larger numbers, but for now we're going to keep it simple.
62
+ */
63
+ void pm_integers_reduce(pm_integer_t *numerator, pm_integer_t *denominator);
64
+
65
+ /* Convert an integer to a decimal string. */
66
+ void pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer);
67
+
68
+ #endif
@@ -0,0 +1,16 @@
1
+ #ifndef PRISM_INTERNAL_ISINF_H
2
+ #define PRISM_INTERNAL_ISINF_H
3
+
4
+ /*
5
+ * isinf on POSIX systems accepts a float, a double, or a long double. But mingw
6
+ * didn't provide an isinf macro, only an isinf function that only accepts
7
+ * floats, so we need to use _finite instead.
8
+ */
9
+ #ifdef __MINGW64__
10
+ #include <float.h>
11
+ #define PRISM_ISINF(x) (!_finite(x))
12
+ #else
13
+ #define PRISM_ISINF(x) isinf(x)
14
+ #endif
15
+
16
+ #endif