prism 1.9.0 → 2.1.0

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 (258) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +144 -40
  3. data/CODE_OF_CONDUCT.md +1 -1
  4. data/LICENSE.md +1 -1
  5. data/Makefile +49 -20
  6. data/README.md +38 -98
  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 +9 -16
  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 +39 -28
  17. data/docs/testing.md +46 -29
  18. data/ext/prism/api_node.c +1527 -1467
  19. data/ext/prism/extconf.rb +3 -4
  20. data/ext/prism/extension.c +759 -418
  21. data/ext/prism/extension.h +3 -3
  22. data/include/prism/arena.h +45 -0
  23. data/include/prism/arena.hpp +42 -0
  24. data/include/prism/ast.h +2738 -611
  25. data/include/prism/ast.hpp +641 -0
  26. data/include/prism/buffer.h +60 -0
  27. data/include/prism/buffer.hpp +55 -0
  28. data/include/prism/comments.h +72 -0
  29. data/include/prism/compiler/accel.h +26 -0
  30. data/include/prism/compiler/align.h +36 -0
  31. data/include/prism/compiler/assume.h +25 -0
  32. data/include/prism/compiler/branch.h +26 -0
  33. data/include/prism/compiler/bswap.h +46 -0
  34. data/include/prism/compiler/cplusplus.hpp +16 -0
  35. data/include/prism/compiler/endianness.h +34 -0
  36. data/include/prism/compiler/exceptions.hpp +17 -0
  37. data/include/prism/compiler/exported.h +24 -0
  38. data/include/prism/compiler/fallthrough.h +22 -0
  39. data/include/prism/compiler/filesystem.h +32 -0
  40. data/include/prism/compiler/flex_array.h +19 -0
  41. data/include/prism/compiler/force_inline.h +21 -0
  42. data/include/prism/compiler/format.h +27 -0
  43. data/include/prism/compiler/inline.h +17 -0
  44. data/include/prism/compiler/lifetimebound.hpp +25 -0
  45. data/include/prism/compiler/nodiscard.h +22 -0
  46. data/include/prism/compiler/nonnull.h +18 -0
  47. data/include/prism/compiler/unused.h +18 -0
  48. data/include/prism/constant_pool.h +106 -0
  49. data/include/prism/diagnostic.h +55 -402
  50. data/include/prism/errors_format.h +61 -0
  51. data/include/prism/excludes.h +29 -0
  52. data/include/prism/integer.h +41 -0
  53. data/include/prism/internal/allocator.h +68 -0
  54. data/include/prism/internal/allocator_debug.h +88 -0
  55. data/include/prism/internal/arena.h +108 -0
  56. data/include/prism/internal/bit.h +42 -0
  57. data/include/prism/internal/buffer.h +94 -0
  58. data/include/prism/internal/char.h +145 -0
  59. data/include/prism/internal/comments.h +54 -0
  60. data/include/prism/internal/constant_pool.h +152 -0
  61. data/include/prism/internal/diagnostic.h +389 -0
  62. data/include/prism/{encoding.h → internal/encoding.h} +27 -68
  63. data/include/prism/internal/integer.h +68 -0
  64. data/include/prism/internal/isinf.h +16 -0
  65. data/include/prism/internal/line_offset_list.h +34 -0
  66. data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  67. data/include/prism/internal/magic_comments.h +23 -0
  68. data/include/prism/internal/memchr.h +15 -0
  69. data/include/prism/internal/node.h +42 -0
  70. data/include/prism/internal/options.h +232 -0
  71. data/include/prism/internal/parser.h +1015 -0
  72. data/include/prism/internal/regexp.h +26 -0
  73. data/include/prism/internal/serialize.h +39 -0
  74. data/include/prism/internal/source.h +72 -0
  75. data/include/prism/internal/static_literals.h +60 -0
  76. data/include/prism/internal/stringy.h +30 -0
  77. data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  78. data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  79. data/include/prism/internal/tokens.h +11 -0
  80. data/include/prism/internal/xxh3.h +16 -0
  81. data/include/prism/json.h +40 -0
  82. data/include/prism/line_offset_list.h +69 -0
  83. data/include/prism/magic_comments.h +53 -0
  84. data/include/prism/node.h +59 -49
  85. data/include/prism/node.hpp +272 -0
  86. data/include/prism/node_type.hpp +38 -0
  87. data/include/prism/options.h +154 -279
  88. data/include/prism/options.hpp +43 -0
  89. data/include/prism/parser.h +367 -870
  90. data/include/prism/parser.hpp +274 -0
  91. data/include/prism/prettyprint.h +14 -9
  92. data/include/prism/serialize.h +123 -0
  93. data/include/prism/source.h +163 -0
  94. data/include/prism/stream.h +36 -0
  95. data/include/prism/string_query.h +82 -0
  96. data/include/prism/stringy.h +61 -0
  97. data/include/prism/stringy.hpp +31 -0
  98. data/include/prism/version.h +20 -3
  99. data/include/prism.h +35 -320
  100. data/include/prism.hpp +24 -0
  101. data/lib/prism/compiler.rb +319 -305
  102. data/lib/prism/desugar_compiler.rb +105 -34
  103. data/lib/prism/dispatcher.rb +646 -473
  104. data/lib/prism/dot_visitor.rb +592 -511
  105. data/lib/prism/dsl.rb +391 -25
  106. data/lib/prism/ffi.rb +258 -90
  107. data/lib/prism/inspect_visitor.rb +357 -325
  108. data/lib/prism/lex_compat.rb +254 -212
  109. data/lib/prism/mutation_compiler.rb +313 -305
  110. data/lib/prism/node.rb +20966 -6992
  111. data/lib/prism/node_ext.rb +180 -187
  112. data/lib/prism/node_find.rb +215 -0
  113. data/lib/prism/parse_result/errors.rb +7 -1
  114. data/lib/prism/parse_result/newlines.rb +276 -8
  115. data/lib/prism/parse_result.rb +468 -139
  116. data/lib/prism/pattern.rb +65 -20
  117. data/lib/prism/reflection.rb +23 -12
  118. data/lib/prism/relocation.rb +149 -87
  119. data/lib/prism/serialize.rb +2889 -700
  120. data/lib/prism/string_query.rb +24 -1
  121. data/lib/prism/translation/parser/builder.rb +10 -2
  122. data/lib/prism/translation/parser/compiler.rb +44 -52
  123. data/lib/prism/translation/parser/lexer.rb +41 -92
  124. data/lib/prism/translation/parser.rb +1 -1
  125. data/lib/prism/translation/parser_current.rb +1 -1
  126. data/lib/prism/translation/ripper/lexer.rb +8 -10
  127. data/lib/prism/translation/ripper/sexp.rb +2 -10
  128. data/lib/prism/translation/ripper/shim.rb +2 -0
  129. data/lib/prism/translation/ripper.rb +967 -209
  130. data/lib/prism/translation/ruby_parser.rb +73 -316
  131. data/lib/prism/translation.rb +2 -0
  132. data/lib/prism/visitor.rb +632 -5
  133. data/lib/prism.rb +79 -9
  134. data/prism.gemspec +141 -62
  135. data/rbi/generated/prism/compiler.rbi +489 -0
  136. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  137. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  138. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  139. data/rbi/generated/prism/dsl.rbi +751 -0
  140. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  141. data/rbi/generated/prism/lex_compat.rbi +162 -0
  142. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  143. data/rbi/generated/prism/node.rbi +15143 -0
  144. data/rbi/generated/prism/node_ext.rbi +259 -0
  145. data/rbi/generated/prism/node_find.rbi +79 -0
  146. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  147. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  148. data/rbi/generated/prism/parse_result.rbi +776 -0
  149. data/rbi/generated/prism/pattern.rbi +134 -0
  150. data/rbi/generated/prism/reflection.rbi +89 -0
  151. data/rbi/generated/prism/relocation.rbi +329 -0
  152. data/rbi/generated/prism/serialize.rbi +185 -0
  153. data/rbi/generated/prism/string_query.rbi +43 -0
  154. data/rbi/generated/prism/translation.rbi +7 -0
  155. data/rbi/generated/prism/visitor.rbi +650 -0
  156. data/rbi/generated/prism.rbi +86 -0
  157. data/rbi/prism/translation/parser_versions.rbi +5 -0
  158. data/rbi/rubyvm/node_find.rbi +14 -0
  159. data/sig/generated/prism/compiler.rbs +492 -0
  160. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  161. data/sig/generated/prism/dispatcher.rbs +1292 -0
  162. data/sig/generated/prism/dot_visitor.rbs +635 -0
  163. data/sig/generated/prism/dsl.rbs +928 -0
  164. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  165. data/sig/generated/prism/lex_compat.rbs +166 -0
  166. data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
  167. data/sig/generated/prism/node.rbs +21632 -0
  168. data/sig/generated/prism/node_ext.rbs +290 -0
  169. data/sig/generated/prism/node_find.rbs +90 -0
  170. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  171. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  172. data/sig/generated/prism/parse_result.rbs +871 -0
  173. data/sig/generated/prism/pattern.rbs +156 -0
  174. data/sig/generated/prism/reflection.rbs +101 -0
  175. data/sig/generated/prism/relocation.rbs +428 -0
  176. data/sig/generated/prism/serialize.rbs +200 -0
  177. data/sig/generated/prism/string_query.rbs +43 -0
  178. data/sig/generated/prism/translation.rbs +8 -0
  179. data/sig/generated/prism/visitor.rbs +1111 -0
  180. data/sig/generated/prism.rbs +84 -0
  181. data/sig/manifest.yaml +2 -0
  182. data/src/arena.c +122 -0
  183. data/src/{util/pm_buffer.c → buffer.c} +53 -21
  184. data/src/{util/pm_char.c → char.c} +28 -57
  185. data/src/comments.c +455 -0
  186. data/src/constant_pool.c +406 -0
  187. data/src/diagnostic.c +120 -68
  188. data/src/encoding.c +8 -3
  189. data/src/errors_format.c +519 -0
  190. data/src/{util/pm_integer.c → integer.c} +38 -22
  191. data/src/json.c +5733 -0
  192. data/src/line_offset_list.c +100 -0
  193. data/src/list.c +24 -0
  194. data/src/{util/pm_memchr.c → memchr.c} +8 -6
  195. data/src/node.c +3465 -7787
  196. data/src/options.c +161 -54
  197. data/src/parser.c +371 -0
  198. data/src/prettyprint.c +421 -354
  199. data/src/prism.c +8503 -7280
  200. data/src/regexp.c +960 -45
  201. data/src/serialize.c +2434 -2048
  202. data/src/source.c +524 -0
  203. data/src/static_literals.c +303 -360
  204. data/src/string_query.c +180 -0
  205. data/src/stringy.c +61 -0
  206. data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  207. data/src/strpbrk.c +447 -0
  208. data/src/{token_type.c → tokens.c} +39 -18
  209. data/src/xxh3.c +292 -0
  210. metadata +141 -63
  211. data/ext/prism/api_pack.c +0 -276
  212. data/include/prism/defines.h +0 -260
  213. data/include/prism/pack.h +0 -163
  214. data/include/prism/regexp.h +0 -43
  215. data/include/prism/static_literals.h +0 -121
  216. data/include/prism/util/pm_buffer.h +0 -236
  217. data/include/prism/util/pm_char.h +0 -204
  218. data/include/prism/util/pm_constant_pool.h +0 -218
  219. data/include/prism/util/pm_integer.h +0 -130
  220. data/include/prism/util/pm_memchr.h +0 -29
  221. data/include/prism/util/pm_newline_list.h +0 -113
  222. data/include/prism/util/pm_string.h +0 -200
  223. data/lib/prism/pack.rb +0 -230
  224. data/lib/prism/parse_result/comments.rb +0 -188
  225. data/rbi/prism/compiler.rbi +0 -12
  226. data/rbi/prism/dsl.rbi +0 -524
  227. data/rbi/prism/inspect_visitor.rbi +0 -12
  228. data/rbi/prism/node.rbi +0 -8750
  229. data/rbi/prism/node_ext.rbi +0 -107
  230. data/rbi/prism/parse_result.rbi +0 -404
  231. data/rbi/prism/reflection.rbi +0 -58
  232. data/rbi/prism/string_query.rbi +0 -12
  233. data/rbi/prism/visitor.rbi +0 -473
  234. data/rbi/prism.rbi +0 -63
  235. data/sig/prism/compiler.rbs +0 -9
  236. data/sig/prism/dispatcher.rbs +0 -19
  237. data/sig/prism/dot_visitor.rbs +0 -6
  238. data/sig/prism/dsl.rbs +0 -351
  239. data/sig/prism/inspect_visitor.rbs +0 -22
  240. data/sig/prism/lex_compat.rbs +0 -10
  241. data/sig/prism/node.rbs +0 -4042
  242. data/sig/prism/node_ext.rbs +0 -149
  243. data/sig/prism/pack.rbs +0 -43
  244. data/sig/prism/parse_result/comments.rbs +0 -38
  245. data/sig/prism/parse_result.rbs +0 -197
  246. data/sig/prism/pattern.rbs +0 -13
  247. data/sig/prism/reflection.rbs +0 -50
  248. data/sig/prism/relocation.rbs +0 -185
  249. data/sig/prism/serialize.rbs +0 -8
  250. data/sig/prism/string_query.rbs +0 -11
  251. data/sig/prism/visitor.rbs +0 -169
  252. data/sig/prism.rbs +0 -272
  253. data/src/pack.c +0 -509
  254. data/src/util/pm_constant_pool.c +0 -342
  255. data/src/util/pm_list.c +0 -49
  256. data/src/util/pm_newline_list.c +0 -125
  257. data/src/util/pm_string.c +0 -381
  258. data/src/util/pm_strpbrk.c +0 -206
@@ -0,0 +1,152 @@
1
+ #ifndef PRISM_INTERNAL_CONSTANT_POOL_H
2
+ #define PRISM_INTERNAL_CONSTANT_POOL_H
3
+
4
+ #include "prism/constant_pool.h"
5
+
6
+ #include "prism/arena.h"
7
+ #include "prism/compiler/inline.h"
8
+
9
+ #include <stdbool.h>
10
+
11
+ /* A constant in the pool which effectively stores a string. */
12
+ struct pm_constant_t {
13
+ /* A pointer to the start of the string. */
14
+ const uint8_t *start;
15
+
16
+ /* The length of the string. */
17
+ size_t length;
18
+ };
19
+
20
+ /*
21
+ * The type of bucket in the constant pool hash map. This determines how the
22
+ * bucket should be freed.
23
+ */
24
+ typedef unsigned int pm_constant_pool_bucket_type_t;
25
+
26
+ /* By default, each constant is a slice of the source. */
27
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_DEFAULT = 0;
28
+
29
+ /* An owned constant is one for which memory has been allocated. */
30
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_OWNED = 1;
31
+
32
+ /* A constant constant is known at compile time. */
33
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_CONSTANT = 2;
34
+
35
+ /* A bucket in the hash map. */
36
+ typedef struct {
37
+ /* The incremental ID used for indexing back into the pool. */
38
+ unsigned int id: 30;
39
+
40
+ /* The type of the bucket, which determines how to free it. */
41
+ pm_constant_pool_bucket_type_t type: 2;
42
+
43
+ /* The hash of the bucket. */
44
+ uint32_t hash;
45
+
46
+ /*
47
+ * A pointer to the start of the string, stored directly in the bucket to
48
+ * avoid a pointer chase to the constants array during probing.
49
+ */
50
+ const uint8_t *start;
51
+
52
+ /* The length of the string. */
53
+ size_t length;
54
+ } pm_constant_pool_bucket_t;
55
+
56
+ /* The overall constant pool, which stores constants found while parsing. */
57
+ struct pm_constant_pool_t {
58
+ /* The buckets in the hash map. */
59
+ pm_constant_pool_bucket_t *buckets;
60
+
61
+ /* The constants that are stored in the buckets. */
62
+ pm_constant_t *constants;
63
+
64
+ /* The number of buckets in the hash map. */
65
+ uint32_t size;
66
+
67
+ /* The number of buckets that have been allocated in the hash map. */
68
+ uint32_t capacity;
69
+ };
70
+
71
+ /*
72
+ * When we allocate constants into the pool, we reserve 0 to mean that the slot
73
+ * is not yet filled. This constant is reused in other places to indicate the
74
+ * lack of a constant id.
75
+ */
76
+ #define PM_CONSTANT_ID_UNSET 0
77
+
78
+ /* Initialize a list of constant ids with a given capacity. */
79
+ void pm_constant_id_list_init_capacity(pm_arena_t *arena, pm_constant_id_list_t *list, size_t capacity);
80
+
81
+ /* Insert a constant id into a list of constant ids at the specified index. */
82
+ void pm_constant_id_list_insert(pm_constant_id_list_t *list, size_t index, pm_constant_id_t id);
83
+
84
+ /*
85
+ * Mix the bits of a constant id so that ids which are close together, as
86
+ * sequentially assigned ids are, land in unrelated slots of a hash table.
87
+ */
88
+ static PRISM_INLINE uint32_t
89
+ pm_constant_id_hash(pm_constant_id_t id) {
90
+ id = ((id >> 16) ^ id) * 0x45d9f3b;
91
+ id = ((id >> 16) ^ id) * 0x45d9f3b;
92
+ id = (id >> 16) ^ id;
93
+ return id;
94
+ }
95
+
96
+ /*
97
+ * A set of constant ids, for where the parser only needs to know whether it has
98
+ * already seen a name, as with the variables a pattern captures or the named
99
+ * capture groups of a regular expression.
100
+ */
101
+ typedef struct {
102
+ /* The number of ids in the set. */
103
+ size_t size;
104
+
105
+ /* The number of slots in `ids`, either zero or a power of two. */
106
+ size_t capacity;
107
+
108
+ /*
109
+ * An open-addressed table of the ids in the set, where PM_CONSTANT_ID_UNSET
110
+ * marks an empty slot. It is NULL until the first id is added.
111
+ */
112
+ pm_constant_id_t *ids;
113
+ } pm_constant_id_set_t;
114
+
115
+ /*
116
+ * Add a constant id, which must not be PM_CONSTANT_ID_UNSET, to the set.
117
+ * Returns whether the set did not already contain it.
118
+ */
119
+ bool pm_constant_id_set_insert(pm_arena_t *arena, pm_constant_id_set_t *set, pm_constant_id_t id);
120
+
121
+ /* Initialize a new constant pool with a given capacity. */
122
+ void pm_constant_pool_init(pm_arena_t *arena, pm_constant_pool_t *pool, uint32_t capacity);
123
+
124
+ /* Return a pointer to the constant indicated by the given constant id. */
125
+ pm_constant_t * pm_constant_pool_id_to_constant(const pm_constant_pool_t *pool, pm_constant_id_t constant_id);
126
+
127
+ /*
128
+ * Find a constant in a constant pool. Returns the id of the constant, or 0 if
129
+ * the constant is not found.
130
+ */
131
+ pm_constant_id_t pm_constant_pool_find(const pm_constant_pool_t *pool, const uint8_t *start, size_t length);
132
+
133
+ /*
134
+ * Insert a constant into a constant pool that is a slice of a source string.
135
+ * Returns the id of the constant, or 0 if any potential calls to resize fail.
136
+ */
137
+ pm_constant_id_t pm_constant_pool_insert_shared(pm_arena_t *arena, pm_constant_pool_t *pool, const uint8_t *start, size_t length);
138
+
139
+ /*
140
+ * Insert a constant into a constant pool from memory that is now owned by the
141
+ * constant pool. Returns the id of the constant, or 0 if any potential calls to
142
+ * resize fail.
143
+ */
144
+ pm_constant_id_t pm_constant_pool_insert_owned(pm_arena_t *arena, pm_constant_pool_t *pool, uint8_t *start, size_t length);
145
+
146
+ /*
147
+ * Insert a constant into a constant pool from memory that is constant. Returns
148
+ * the id of the constant, or 0 if any potential calls to resize fail.
149
+ */
150
+ pm_constant_id_t pm_constant_pool_insert_constant(pm_arena_t *arena, pm_constant_pool_t *pool, const uint8_t *start, size_t length);
151
+
152
+ #endif
@@ -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