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,34 @@
1
+ #ifndef PRISM_INTERNAL_LINE_OFFSET_LIST_H
2
+ #define PRISM_INTERNAL_LINE_OFFSET_LIST_H
3
+
4
+ #include "prism/compiler/force_inline.h"
5
+
6
+ #include "prism/arena.h"
7
+ #include "prism/line_offset_list.h"
8
+
9
+ /* Initialize a new line offset list with the given capacity. */
10
+ void pm_line_offset_list_init(pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity);
11
+
12
+ /* Clear out the offsets that have been appended to the list. */
13
+ void pm_line_offset_list_clear(pm_line_offset_list_t *list);
14
+
15
+ /* Append a new offset to the list (slow path with resize). */
16
+ void pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor);
17
+
18
+ /* Append a new offset to the list. */
19
+ static PRISM_FORCE_INLINE void
20
+ pm_line_offset_list_append(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) {
21
+ if (list->size < list->capacity) {
22
+ list->offsets[list->size++] = cursor;
23
+ } else {
24
+ pm_line_offset_list_append_slow(arena, list, cursor);
25
+ }
26
+ }
27
+
28
+ /*
29
+ * Returns the line of the given offset. If the offset is not in the list, the
30
+ * line of the closest offset less than the given offset is returned.
31
+ */
32
+ int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line);
33
+
34
+ #endif
@@ -1,19 +1,9 @@
1
- /**
2
- * @file pm_list.h
3
- *
4
- * An abstract linked list.
5
- */
6
- #ifndef PRISM_LIST_H
7
- #define PRISM_LIST_H
1
+ #ifndef PRISM_INTERNAL_LIST_H
2
+ #define PRISM_INTERNAL_LIST_H
8
3
 
9
- #include "prism/defines.h"
10
-
11
- #include <stdbool.h>
12
4
  #include <stddef.h>
13
- #include <stdint.h>
14
- #include <stdlib.h>
15
5
 
16
- /**
6
+ /*
17
7
  * This struct represents an abstract linked list that provides common
18
8
  * functionality. It is meant to be used any time a linked list is necessary to
19
9
  * store data.
@@ -44,60 +34,29 @@
44
34
  * iteration and appending of new nodes.
45
35
  */
46
36
  typedef struct pm_list_node {
47
- /** A pointer to the next node in the list. */
37
+ /* A pointer to the next node in the list. */
48
38
  struct pm_list_node *next;
49
39
  } pm_list_node_t;
50
40
 
51
- /**
41
+ /*
52
42
  * This represents the overall linked list. It keeps a pointer to the head and
53
43
  * tail so that iteration is easy and pushing new nodes is easy.
54
44
  */
55
45
  typedef struct {
56
- /** The size of the list. */
46
+ /* The size of the list. */
57
47
  size_t size;
58
48
 
59
- /** A pointer to the head of the list. */
49
+ /* A pointer to the head of the list. */
60
50
  pm_list_node_t *head;
61
51
 
62
- /** A pointer to the tail of the list. */
52
+ /* A pointer to the tail of the list. */
63
53
  pm_list_node_t *tail;
64
54
  } pm_list_t;
65
55
 
66
- /**
67
- * Returns true if the given list is empty.
68
- *
69
- * @param list The list to check.
70
- * @return True if the given list is empty, otherwise false.
71
- *
72
- * \public \memberof pm_list_t
73
- */
74
- PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
75
-
76
- /**
77
- * Returns the size of the list.
78
- *
79
- * @param list The list to check.
80
- * @return The size of the list.
81
- *
82
- * \public \memberof pm_list_t
83
- */
84
- PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
56
+ /* Returns the size of the list. */
57
+ size_t pm_list_size(pm_list_t *list);
85
58
 
86
- /**
87
- * Append a node to the given list.
88
- *
89
- * @param list The list to append to.
90
- * @param node The node to append.
91
- */
59
+ /* Append a node to the given list. */
92
60
  void pm_list_append(pm_list_t *list, pm_list_node_t *node);
93
61
 
94
- /**
95
- * Deallocate the internal state of the given list.
96
- *
97
- * @param list The list to free.
98
- *
99
- * \public \memberof pm_list_t
100
- */
101
- PRISM_EXPORTED_FUNCTION void pm_list_free(pm_list_t *list);
102
-
103
62
  #endif
@@ -0,0 +1,23 @@
1
+ #ifndef PRISM_INTERNAL_MAGIC_COMMENTS_H
2
+ #define PRISM_INTERNAL_MAGIC_COMMENTS_H
3
+
4
+ #include "prism/magic_comments.h"
5
+
6
+ #include "prism/internal/list.h"
7
+
8
+ /*
9
+ * This is a node in the linked list of magic comments that we've found while
10
+ * parsing.
11
+ */
12
+ struct pm_magic_comment_t {
13
+ /* The embedded base node. */
14
+ pm_list_node_t node;
15
+
16
+ /* The key of the magic comment. */
17
+ pm_location_t key;
18
+
19
+ /* The value of the magic comment. */
20
+ pm_location_t value;
21
+ };
22
+
23
+ #endif
@@ -0,0 +1,15 @@
1
+ #ifndef PRISM_INTERNAL_MEMCHR_H
2
+ #define PRISM_INTERNAL_MEMCHR_H
3
+
4
+ #include "prism/internal/encoding.h"
5
+
6
+ #include <stddef.h>
7
+
8
+ /*
9
+ * We need to roll our own memchr to handle cases where the encoding changes and
10
+ * we need to search for a character in a buffer that could be the trailing byte
11
+ * of a multibyte character.
12
+ */
13
+ const void * pm_memchr(const void *source, int character, size_t number, bool encoding_changed, const pm_encoding_t *encoding);
14
+
15
+ #endif
@@ -0,0 +1,38 @@
1
+ #ifndef PRISM_INTERNAL_NODE_H
2
+ #define PRISM_INTERNAL_NODE_H
3
+
4
+ #include "prism/node.h"
5
+
6
+ #include "prism/compiler/force_inline.h"
7
+
8
+ #include "prism/arena.h"
9
+
10
+ /* The offset of the start of the given location. */
11
+ #define PM_LOCATION_START(location_) ((location_)->start)
12
+
13
+ /* The offset just past the end of the given location. */
14
+ #define PM_LOCATION_END(location_) ((location_)->start + (location_)->length)
15
+
16
+ /*
17
+ * Slow path for pm_node_list_append: grow the list and append the node.
18
+ * Do not call directly — use pm_node_list_append instead.
19
+ */
20
+ void pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
21
+
22
+ /* Append a new node onto the end of the node list. */
23
+ static PRISM_FORCE_INLINE void
24
+ pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
25
+ if (list->size < list->capacity) {
26
+ list->nodes[list->size++] = node;
27
+ } else {
28
+ pm_node_list_append_slow(arena, list, node);
29
+ }
30
+ }
31
+
32
+ /* Prepend a new node onto the beginning of the node list. */
33
+ void pm_node_list_prepend(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
34
+
35
+ /* Concatenate the given node list onto the end of the other node list. */
36
+ void pm_node_list_concat(pm_arena_t *arena, pm_node_list_t *list, pm_node_list_t *other);
37
+
38
+ #endif
@@ -0,0 +1,232 @@
1
+ #ifndef PRISM_INTERNAL_OPTIONS_H
2
+ #define PRISM_INTERNAL_OPTIONS_H
3
+
4
+ #include "prism/options.h"
5
+
6
+ /* A scope of locals surrounding the code that is being parsed. */
7
+ struct pm_options_scope_t {
8
+ /* The number of locals in the scope. */
9
+ size_t locals_count;
10
+
11
+ /* The names of the locals in the scope. */
12
+ pm_string_t *locals;
13
+
14
+ /* Flags for the set of forwarding parameters in this scope. */
15
+ uint8_t forwarding;
16
+ };
17
+
18
+ /*
19
+ * The version of Ruby syntax that we should be parsing with. This is used to
20
+ * allow consumers to specify which behavior they want in case they need to
21
+ * parse in the same way as a specific version of CRuby would have.
22
+ */
23
+ typedef enum {
24
+ /*
25
+ * If an explicit version is not provided, the current version of prism will
26
+ * be used.
27
+ */
28
+ PM_OPTIONS_VERSION_UNSET = 0,
29
+
30
+ /* The vendored version of prism in CRuby 3.3.x. */
31
+ PM_OPTIONS_VERSION_CRUBY_3_3 = 1,
32
+
33
+ /* The vendored version of prism in CRuby 3.4.x. */
34
+ PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
35
+
36
+ /* The vendored version of prism in CRuby 4.0.x. */
37
+ PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
38
+
39
+ /* The vendored version of prism in CRuby 4.0.x. */
40
+ PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
41
+
42
+ /* The vendored version of prism in CRuby 4.1.x. */
43
+ PM_OPTIONS_VERSION_CRUBY_4_1 = 4,
44
+
45
+ /* The current version of prism. */
46
+ PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_1
47
+ } pm_options_version_t;
48
+
49
+ /* The options that can be passed to the parser. */
50
+ struct pm_options_t {
51
+ /*
52
+ * The callback to call when additional switches are found in a shebang
53
+ * comment.
54
+ */
55
+ pm_options_shebang_callback_t shebang_callback;
56
+
57
+ /*
58
+ * Any additional data that should be passed along to the shebang callback
59
+ * if one was set.
60
+ */
61
+ void *shebang_callback_data;
62
+
63
+ /* The name of the file that is currently being parsed. */
64
+ pm_string_t filepath;
65
+
66
+ /*
67
+ * The line within the file that the parse starts on. This value is
68
+ * 1-indexed.
69
+ */
70
+ int32_t line;
71
+
72
+ /*
73
+ * The name of the encoding that the source file is in. Note that this must
74
+ * correspond to a name that can be found with Encoding.find in Ruby.
75
+ */
76
+ pm_string_t encoding;
77
+
78
+ /* The number of scopes surrounding the code that is being parsed. */
79
+ size_t scopes_count;
80
+
81
+ /*
82
+ * The scopes surrounding the code that is being parsed. For most parses
83
+ * this will be NULL, but for evals it will be the locals that are in scope
84
+ * surrounding the eval. Scopes are ordered from the outermost scope to the
85
+ * innermost one.
86
+ */
87
+ pm_options_scope_t *scopes;
88
+
89
+ /*
90
+ * The version of prism that we should be parsing with. This is used to
91
+ * allow consumers to specify which behavior they want in case they need to
92
+ * parse exactly as a specific version of CRuby.
93
+ */
94
+ pm_options_version_t version;
95
+
96
+ /* A bitset of the various options that were set on the command line. */
97
+ uint8_t command_line;
98
+
99
+ /*
100
+ * Whether or not the frozen string literal option has been set.
101
+ * May be:
102
+ * - PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED
103
+ * - PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED
104
+ * - PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET
105
+ */
106
+ int8_t frozen_string_literal;
107
+
108
+ /*
109
+ * Whether or not the parser should raise an error when it encounters an
110
+ * error. By default this is off, but can be turned on in the case that you
111
+ * want nicely formatted syntax errors. The values that this can be set to
112
+ * are:
113
+ * - 0 - do not raise an error, just return the errors in the result
114
+ * - PM_ERRORS_FORMAT_PLAIN - raise a plain error with no formatting
115
+ * - PM_ERRORS_FORMAT_STYLE - raise an error with bold formatting
116
+ * - PM_ERRORS_FORMAT_COLOR - raise an error with color formatting
117
+ */
118
+ uint8_t raise_error;
119
+
120
+ /*
121
+ * Whether or not the encoding magic comments should be respected. This is a
122
+ * niche use-case where you want to parse a file with a specific encoding
123
+ * but ignore any encoding magic comments at the top of the file.
124
+ */
125
+ bool encoding_locked;
126
+
127
+ /*
128
+ * When the file being parsed is the main script, the shebang will be
129
+ * considered for command-line flags (or for implicit -x). The caller needs
130
+ * to pass this information to the parser so that it can behave correctly.
131
+ */
132
+ bool main_script;
133
+
134
+ /*
135
+ * When the file being parsed is considered a "partial" script, jumps will
136
+ * not be marked as errors if they are not contained within loops/blocks.
137
+ * This is used in the case that you're parsing a script that you know will
138
+ * be embedded inside another script later, but you do not have that context
139
+ * yet. For example, when parsing an ERB template that will be evaluated
140
+ * inside another script.
141
+ */
142
+ bool partial_script;
143
+
144
+ /*
145
+ * Whether or not the parser should freeze the nodes that it creates. This
146
+ * makes it possible to have a deeply frozen AST that is safe to share
147
+ * between concurrency primitives.
148
+ */
149
+ bool freeze;
150
+
151
+ /*
152
+ * Whether or not the parser should attach comments to the nodes that own
153
+ * them after parsing. When this is set, the parser's comment list is
154
+ * sorted by start offset and every comment is assigned an owning node.
155
+ */
156
+ bool attach_comments;
157
+ };
158
+
159
+ /* Free the internal memory associated with the options. */
160
+ void pm_options_cleanup(pm_options_t *options);
161
+
162
+ /*
163
+ * Deserialize an options struct from the given binary string. This is used to
164
+ * pass options to the parser from an FFI call so that consumers of the library
165
+ * from an FFI perspective don't have to worry about the structure of our
166
+ * options structs. Since the source of these calls will be from Ruby
167
+ * implementation internals we assume it is from a trusted source.
168
+ *
169
+ * `data` is assumed to be a valid pointer pointing to well-formed data. The
170
+ * layout of this data should be the same every time, and is described below:
171
+ *
172
+ * | # bytes | field |
173
+ * | ------- | -------------------------- |
174
+ * | `4` | the length of the filepath |
175
+ * | ... | the filepath bytes |
176
+ * | `4` | the line number |
177
+ * | `4` | the length the encoding |
178
+ * | ... | the encoding bytes |
179
+ * | `1` | frozen string literal |
180
+ * | `1` | -p command line option |
181
+ * | `1` | -n command line option |
182
+ * | `1` | -l command line option |
183
+ * | `1` | -a command line option |
184
+ * | `1` | the version |
185
+ * | `1` | encoding locked |
186
+ * | `1` | main script |
187
+ * | `1` | partial script |
188
+ * | `1` | freeze |
189
+ * | `1` | attach comments |
190
+ * | `4` | the number of scopes |
191
+ * | ... | the scopes |
192
+ *
193
+ * The version field is an enum, so it should be one of the following values:
194
+ *
195
+ * | value | version |
196
+ * | ----- | ------------------------- |
197
+ * | `0` | use the latest version of prism |
198
+ * | `1` | use the version of prism that is vendored in CRuby 3.3.0 |
199
+ * | `2` | use the version of prism that is vendored in CRuby 3.4.0 |
200
+ * | `3` | use the version of prism that is vendored in CRuby 4.0.0 |
201
+ * | `4` | use the version of prism that is vendored in CRuby 4.1.0 |
202
+ *
203
+ * Each scope is laid out as follows:
204
+ *
205
+ * | # bytes | field |
206
+ * | ------- | -------------------------- |
207
+ * | `4` | the number of locals |
208
+ * | `1` | the forwarding flags |
209
+ * | ... | the locals |
210
+ *
211
+ * Each local is laid out as follows:
212
+ *
213
+ * | # bytes | field |
214
+ * | ------- | -------------------------- |
215
+ * | `4` | the length of the local |
216
+ * | ... | the local bytes |
217
+ *
218
+ * Some additional things to note about this layout:
219
+ *
220
+ * * The filepath can have a length of 0, in which case we'll consider it an
221
+ * empty string.
222
+ * * The line number should be 0-indexed.
223
+ * * The encoding can have a length of 0, in which case we'll use the default
224
+ * encoding (UTF-8). If it's not 0, it should correspond to a name of an
225
+ * encoding that can be passed to `Encoding.find` in Ruby.
226
+ * * The frozen string literal, encoding locked, main script, and partial script
227
+ * fields are booleans, so their values should be either 0 or 1.
228
+ * * The number of scopes can be 0.
229
+ */
230
+ void pm_options_read(pm_options_t *options, const char *data);
231
+
232
+ #endif