prism 2.0.0-aarch64-mingw-ucrt

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 (232) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +881 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +145 -0
  8. data/README.md +81 -0
  9. data/config.yml +4752 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +69 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +81 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +133 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +147 -0
  23. data/docs/relocation.md +32 -0
  24. data/docs/ripper_translation.md +63 -0
  25. data/docs/ruby_api.md +45 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +244 -0
  28. data/docs/testing.md +72 -0
  29. data/ext/prism/api_node.c +7005 -0
  30. data/ext/prism/extconf.rb +126 -0
  31. data/ext/prism/extension.c +1768 -0
  32. data/ext/prism/extension.h +19 -0
  33. data/include/prism/arena.h +45 -0
  34. data/include/prism/arena.hpp +42 -0
  35. data/include/prism/ast.h +10381 -0
  36. data/include/prism/ast.hpp +641 -0
  37. data/include/prism/buffer.h +60 -0
  38. data/include/prism/buffer.hpp +55 -0
  39. data/include/prism/comments.h +72 -0
  40. data/include/prism/compiler/accel.h +26 -0
  41. data/include/prism/compiler/align.h +36 -0
  42. data/include/prism/compiler/assume.h +25 -0
  43. data/include/prism/compiler/branch.h +26 -0
  44. data/include/prism/compiler/bswap.h +46 -0
  45. data/include/prism/compiler/cplusplus.hpp +16 -0
  46. data/include/prism/compiler/endianness.h +34 -0
  47. data/include/prism/compiler/exceptions.hpp +17 -0
  48. data/include/prism/compiler/exported.h +24 -0
  49. data/include/prism/compiler/fallthrough.h +22 -0
  50. data/include/prism/compiler/filesystem.h +32 -0
  51. data/include/prism/compiler/flex_array.h +19 -0
  52. data/include/prism/compiler/force_inline.h +21 -0
  53. data/include/prism/compiler/format.h +27 -0
  54. data/include/prism/compiler/inline.h +17 -0
  55. data/include/prism/compiler/lifetimebound.hpp +25 -0
  56. data/include/prism/compiler/nodiscard.h +22 -0
  57. data/include/prism/compiler/nonnull.h +18 -0
  58. data/include/prism/compiler/unused.h +18 -0
  59. data/include/prism/constant_pool.h +106 -0
  60. data/include/prism/diagnostic.h +111 -0
  61. data/include/prism/errors_format.h +61 -0
  62. data/include/prism/excludes.h +29 -0
  63. data/include/prism/integer.h +41 -0
  64. data/include/prism/internal/allocator.h +68 -0
  65. data/include/prism/internal/allocator_debug.h +88 -0
  66. data/include/prism/internal/arena.h +108 -0
  67. data/include/prism/internal/bit.h +42 -0
  68. data/include/prism/internal/buffer.h +94 -0
  69. data/include/prism/internal/char.h +145 -0
  70. data/include/prism/internal/comments.h +53 -0
  71. data/include/prism/internal/constant_pool.h +152 -0
  72. data/include/prism/internal/diagnostic.h +389 -0
  73. data/include/prism/internal/encoding.h +242 -0
  74. data/include/prism/internal/integer.h +68 -0
  75. data/include/prism/internal/isinf.h +16 -0
  76. data/include/prism/internal/line_offset_list.h +34 -0
  77. data/include/prism/internal/list.h +62 -0
  78. data/include/prism/internal/magic_comments.h +23 -0
  79. data/include/prism/internal/memchr.h +15 -0
  80. data/include/prism/internal/node.h +42 -0
  81. data/include/prism/internal/options.h +232 -0
  82. data/include/prism/internal/parser.h +1004 -0
  83. data/include/prism/internal/regexp.h +26 -0
  84. data/include/prism/internal/serialize.h +39 -0
  85. data/include/prism/internal/source.h +72 -0
  86. data/include/prism/internal/static_literals.h +100 -0
  87. data/include/prism/internal/stringy.h +30 -0
  88. data/include/prism/internal/strncasecmp.h +18 -0
  89. data/include/prism/internal/strpbrk.h +33 -0
  90. data/include/prism/internal/tokens.h +11 -0
  91. data/include/prism/internal/xxh3.h +16 -0
  92. data/include/prism/json.h +40 -0
  93. data/include/prism/line_offset_list.h +69 -0
  94. data/include/prism/magic_comments.h +53 -0
  95. data/include/prism/node.h +139 -0
  96. data/include/prism/node.hpp +272 -0
  97. data/include/prism/node_type.hpp +38 -0
  98. data/include/prism/options.h +363 -0
  99. data/include/prism/options.hpp +43 -0
  100. data/include/prism/parser.h +433 -0
  101. data/include/prism/parser.hpp +274 -0
  102. data/include/prism/prettyprint.h +39 -0
  103. data/include/prism/serialize.h +123 -0
  104. data/include/prism/source.h +163 -0
  105. data/include/prism/stream.h +36 -0
  106. data/include/prism/string_query.h +82 -0
  107. data/include/prism/stringy.h +61 -0
  108. data/include/prism/stringy.hpp +31 -0
  109. data/include/prism/version.h +46 -0
  110. data/include/prism.h +123 -0
  111. data/include/prism.hpp +24 -0
  112. data/lib/prism/3.4/prism.so +0 -0
  113. data/lib/prism/4.0/prism.so +0 -0
  114. data/lib/prism/compiler.rb +815 -0
  115. data/lib/prism/desugar_compiler.rb +463 -0
  116. data/lib/prism/dispatcher.rb +2383 -0
  117. data/lib/prism/dot_visitor.rb +4848 -0
  118. data/lib/prism/dsl.rb +1369 -0
  119. data/lib/prism/ffi.rb +746 -0
  120. data/lib/prism/inspect_visitor.rb +2425 -0
  121. data/lib/prism/lex_compat.rb +953 -0
  122. data/lib/prism/mutation_compiler.rb +780 -0
  123. data/lib/prism/node.rb +33940 -0
  124. data/lib/prism/node_ext.rb +504 -0
  125. data/lib/prism/node_find.rb +215 -0
  126. data/lib/prism/parse_result/errors.rb +72 -0
  127. data/lib/prism/parse_result/newlines.rb +423 -0
  128. data/lib/prism/parse_result.rb +1236 -0
  129. data/lib/prism/pattern.rb +314 -0
  130. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  131. data/lib/prism/polyfill/byteindex.rb +13 -0
  132. data/lib/prism/polyfill/scan_byte.rb +14 -0
  133. data/lib/prism/polyfill/unpack1.rb +14 -0
  134. data/lib/prism/polyfill/warn.rb +36 -0
  135. data/lib/prism/reflection.rb +427 -0
  136. data/lib/prism/relocation.rb +567 -0
  137. data/lib/prism/serialize.rb +4589 -0
  138. data/lib/prism/string_query.rb +54 -0
  139. data/lib/prism/translation/parser/builder.rb +70 -0
  140. data/lib/prism/translation/parser/compiler.rb +2226 -0
  141. data/lib/prism/translation/parser/lexer.rb +769 -0
  142. data/lib/prism/translation/parser.rb +376 -0
  143. data/lib/prism/translation/parser_current.rb +26 -0
  144. data/lib/prism/translation/parser_versions.rb +36 -0
  145. data/lib/prism/translation/ripper/filter.rb +53 -0
  146. data/lib/prism/translation/ripper/lexer.rb +133 -0
  147. data/lib/prism/translation/ripper/sexp.rb +118 -0
  148. data/lib/prism/translation/ripper/shim.rb +7 -0
  149. data/lib/prism/translation/ripper.rb +4278 -0
  150. data/lib/prism/translation/ruby_parser.rb +1721 -0
  151. data/lib/prism/translation.rb +20 -0
  152. data/lib/prism/visitor.rb +1440 -0
  153. data/lib/prism.rb +168 -0
  154. data/prism.gemspec +251 -0
  155. data/rbi/generated/prism/compiler.rbi +489 -0
  156. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  157. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  158. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  159. data/rbi/generated/prism/dsl.rbi +751 -0
  160. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  161. data/rbi/generated/prism/lex_compat.rbi +162 -0
  162. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  163. data/rbi/generated/prism/node.rbi +15143 -0
  164. data/rbi/generated/prism/node_ext.rbi +259 -0
  165. data/rbi/generated/prism/node_find.rbi +79 -0
  166. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  167. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  168. data/rbi/generated/prism/parse_result.rbi +776 -0
  169. data/rbi/generated/prism/pattern.rbi +134 -0
  170. data/rbi/generated/prism/reflection.rbi +89 -0
  171. data/rbi/generated/prism/relocation.rbi +329 -0
  172. data/rbi/generated/prism/serialize.rbi +185 -0
  173. data/rbi/generated/prism/string_query.rbi +43 -0
  174. data/rbi/generated/prism/translation.rbi +7 -0
  175. data/rbi/generated/prism/visitor.rbi +650 -0
  176. data/rbi/generated/prism.rbi +86 -0
  177. data/rbi/prism/translation/parser.rbi +11 -0
  178. data/rbi/prism/translation/parser_versions.rbi +28 -0
  179. data/rbi/prism/translation/ripper.rbi +15 -0
  180. data/rbi/rubyvm/node_find.rbi +14 -0
  181. data/sig/generated/prism/compiler.rbs +492 -0
  182. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  183. data/sig/generated/prism/dispatcher.rbs +1292 -0
  184. data/sig/generated/prism/dot_visitor.rbs +635 -0
  185. data/sig/generated/prism/dsl.rbs +928 -0
  186. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  187. data/sig/generated/prism/lex_compat.rbs +166 -0
  188. data/sig/generated/prism/mutation_compiler.rbs +464 -0
  189. data/sig/generated/prism/node.rbs +21632 -0
  190. data/sig/generated/prism/node_ext.rbs +290 -0
  191. data/sig/generated/prism/node_find.rbs +90 -0
  192. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  193. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  194. data/sig/generated/prism/parse_result.rbs +871 -0
  195. data/sig/generated/prism/pattern.rbs +156 -0
  196. data/sig/generated/prism/reflection.rbs +101 -0
  197. data/sig/generated/prism/relocation.rbs +428 -0
  198. data/sig/generated/prism/serialize.rbs +200 -0
  199. data/sig/generated/prism/string_query.rbs +43 -0
  200. data/sig/generated/prism/translation.rbs +8 -0
  201. data/sig/generated/prism/visitor.rbs +1111 -0
  202. data/sig/generated/prism.rbs +84 -0
  203. data/sig/manifest.yaml +2 -0
  204. data/src/arena.c +117 -0
  205. data/src/buffer.c +389 -0
  206. data/src/char.c +289 -0
  207. data/src/comments.c +454 -0
  208. data/src/constant_pool.c +406 -0
  209. data/src/diagnostic.c +894 -0
  210. data/src/encoding.c +5345 -0
  211. data/src/errors_format.c +519 -0
  212. data/src/integer.c +681 -0
  213. data/src/json.c +5733 -0
  214. data/src/line_offset_list.c +100 -0
  215. data/src/list.c +24 -0
  216. data/src/memchr.c +37 -0
  217. data/src/node.c +4363 -0
  218. data/src/options.c +445 -0
  219. data/src/parser.c +371 -0
  220. data/src/prettyprint.c +9024 -0
  221. data/src/prism.c +23901 -0
  222. data/src/regexp.c +1705 -0
  223. data/src/serialize.c +2660 -0
  224. data/src/source.c +524 -0
  225. data/src/static_literals.c +685 -0
  226. data/src/string_query.c +180 -0
  227. data/src/stringy.c +61 -0
  228. data/src/strncasecmp.c +37 -0
  229. data/src/strpbrk.c +447 -0
  230. data/src/tokens.c +724 -0
  231. data/src/xxh3.c +292 -0
  232. metadata +275 -0
@@ -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
@@ -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
@@ -0,0 +1,62 @@
1
+ #ifndef PRISM_INTERNAL_LIST_H
2
+ #define PRISM_INTERNAL_LIST_H
3
+
4
+ #include <stddef.h>
5
+
6
+ /*
7
+ * This struct represents an abstract linked list that provides common
8
+ * functionality. It is meant to be used any time a linked list is necessary to
9
+ * store data.
10
+ *
11
+ * The linked list itself operates off a set of pointers. Because the pointers
12
+ * are not necessarily sequential, they can be of any size. We use this fact to
13
+ * allow the consumer of this linked list to extend the node struct to include
14
+ * any data they want. This is done by using the pm_list_node_t as the first
15
+ * member of the struct.
16
+ *
17
+ * For example, if we want to store a list of integers, we can do the following:
18
+ *
19
+ * ```c
20
+ * typedef struct {
21
+ * pm_list_node_t node;
22
+ * int value;
23
+ * } pm_int_node_t;
24
+ *
25
+ * pm_list_t list = { 0 };
26
+ * pm_int_node_t *node = xmalloc(sizeof(pm_int_node_t));
27
+ * node->value = 5;
28
+ *
29
+ * pm_list_append(&list, &node->node);
30
+ * ```
31
+ *
32
+ * The pm_list_t struct is used to represent the overall linked list. It
33
+ * contains a pointer to the head and tail of the list. This allows for easy
34
+ * iteration and appending of new nodes.
35
+ */
36
+ typedef struct pm_list_node {
37
+ /* A pointer to the next node in the list. */
38
+ struct pm_list_node *next;
39
+ } pm_list_node_t;
40
+
41
+ /*
42
+ * This represents the overall linked list. It keeps a pointer to the head and
43
+ * tail so that iteration is easy and pushing new nodes is easy.
44
+ */
45
+ typedef struct {
46
+ /* The size of the list. */
47
+ size_t size;
48
+
49
+ /* A pointer to the head of the list. */
50
+ pm_list_node_t *head;
51
+
52
+ /* A pointer to the tail of the list. */
53
+ pm_list_node_t *tail;
54
+ } pm_list_t;
55
+
56
+ /* Returns the size of the list. */
57
+ size_t pm_list_size(pm_list_t *list);
58
+
59
+ /* Append a node to the given list. */
60
+ void pm_list_append(pm_list_t *list, pm_list_node_t *node);
61
+
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,42 @@
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_inline: grow the list and append the node.
18
+ * Do not call directly — use pm_node_list_append_inline instead.
19
+ */
20
+ void pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
21
+
22
+ /*
23
+ * Append a new node onto the end of the node list, handling the common case
24
+ * inline and growing the list through pm_node_list_append_slow. This is the
25
+ * version for prism's own code; others call the exported pm_node_list_append.
26
+ */
27
+ static PRISM_FORCE_INLINE void
28
+ pm_node_list_append_inline(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
29
+ if (list->size < list->capacity) {
30
+ list->nodes[list->size++] = node;
31
+ } else {
32
+ pm_node_list_append_slow(arena, list, node);
33
+ }
34
+ }
35
+
36
+ /* Prepend a new node onto the beginning of the node list. */
37
+ void pm_node_list_prepend(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
38
+
39
+ /* Concatenate the given node list onto the end of the other node list. */
40
+ void pm_node_list_concat(pm_arena_t *arena, pm_node_list_t *list, pm_node_list_t *other);
41
+
42
+ #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