prism 2.0.0-arm-linux-musl

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 (233) 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.3/prism.so +0 -0
  113. data/lib/prism/3.4/prism.so +0 -0
  114. data/lib/prism/4.0/prism.so +0 -0
  115. data/lib/prism/compiler.rb +815 -0
  116. data/lib/prism/desugar_compiler.rb +463 -0
  117. data/lib/prism/dispatcher.rb +2383 -0
  118. data/lib/prism/dot_visitor.rb +4848 -0
  119. data/lib/prism/dsl.rb +1369 -0
  120. data/lib/prism/ffi.rb +746 -0
  121. data/lib/prism/inspect_visitor.rb +2425 -0
  122. data/lib/prism/lex_compat.rb +953 -0
  123. data/lib/prism/mutation_compiler.rb +780 -0
  124. data/lib/prism/node.rb +33940 -0
  125. data/lib/prism/node_ext.rb +504 -0
  126. data/lib/prism/node_find.rb +215 -0
  127. data/lib/prism/parse_result/errors.rb +72 -0
  128. data/lib/prism/parse_result/newlines.rb +423 -0
  129. data/lib/prism/parse_result.rb +1236 -0
  130. data/lib/prism/pattern.rb +314 -0
  131. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  132. data/lib/prism/polyfill/byteindex.rb +13 -0
  133. data/lib/prism/polyfill/scan_byte.rb +14 -0
  134. data/lib/prism/polyfill/unpack1.rb +14 -0
  135. data/lib/prism/polyfill/warn.rb +36 -0
  136. data/lib/prism/reflection.rb +427 -0
  137. data/lib/prism/relocation.rb +567 -0
  138. data/lib/prism/serialize.rb +4589 -0
  139. data/lib/prism/string_query.rb +54 -0
  140. data/lib/prism/translation/parser/builder.rb +70 -0
  141. data/lib/prism/translation/parser/compiler.rb +2226 -0
  142. data/lib/prism/translation/parser/lexer.rb +769 -0
  143. data/lib/prism/translation/parser.rb +376 -0
  144. data/lib/prism/translation/parser_current.rb +26 -0
  145. data/lib/prism/translation/parser_versions.rb +36 -0
  146. data/lib/prism/translation/ripper/filter.rb +53 -0
  147. data/lib/prism/translation/ripper/lexer.rb +133 -0
  148. data/lib/prism/translation/ripper/sexp.rb +118 -0
  149. data/lib/prism/translation/ripper/shim.rb +7 -0
  150. data/lib/prism/translation/ripper.rb +4278 -0
  151. data/lib/prism/translation/ruby_parser.rb +1721 -0
  152. data/lib/prism/translation.rb +20 -0
  153. data/lib/prism/visitor.rb +1440 -0
  154. data/lib/prism.rb +168 -0
  155. data/prism.gemspec +251 -0
  156. data/rbi/generated/prism/compiler.rbi +489 -0
  157. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  158. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  159. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  160. data/rbi/generated/prism/dsl.rbi +751 -0
  161. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  162. data/rbi/generated/prism/lex_compat.rbi +162 -0
  163. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  164. data/rbi/generated/prism/node.rbi +15143 -0
  165. data/rbi/generated/prism/node_ext.rbi +259 -0
  166. data/rbi/generated/prism/node_find.rbi +79 -0
  167. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  168. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  169. data/rbi/generated/prism/parse_result.rbi +776 -0
  170. data/rbi/generated/prism/pattern.rbi +134 -0
  171. data/rbi/generated/prism/reflection.rbi +89 -0
  172. data/rbi/generated/prism/relocation.rbi +329 -0
  173. data/rbi/generated/prism/serialize.rbi +185 -0
  174. data/rbi/generated/prism/string_query.rbi +43 -0
  175. data/rbi/generated/prism/translation.rbi +7 -0
  176. data/rbi/generated/prism/visitor.rbi +650 -0
  177. data/rbi/generated/prism.rbi +86 -0
  178. data/rbi/prism/translation/parser.rbi +11 -0
  179. data/rbi/prism/translation/parser_versions.rbi +28 -0
  180. data/rbi/prism/translation/ripper.rbi +15 -0
  181. data/rbi/rubyvm/node_find.rbi +14 -0
  182. data/sig/generated/prism/compiler.rbs +492 -0
  183. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  184. data/sig/generated/prism/dispatcher.rbs +1292 -0
  185. data/sig/generated/prism/dot_visitor.rbs +635 -0
  186. data/sig/generated/prism/dsl.rbs +928 -0
  187. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  188. data/sig/generated/prism/lex_compat.rbs +166 -0
  189. data/sig/generated/prism/mutation_compiler.rbs +464 -0
  190. data/sig/generated/prism/node.rbs +21632 -0
  191. data/sig/generated/prism/node_ext.rbs +290 -0
  192. data/sig/generated/prism/node_find.rbs +90 -0
  193. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  194. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  195. data/sig/generated/prism/parse_result.rbs +871 -0
  196. data/sig/generated/prism/pattern.rbs +156 -0
  197. data/sig/generated/prism/reflection.rbs +101 -0
  198. data/sig/generated/prism/relocation.rbs +428 -0
  199. data/sig/generated/prism/serialize.rbs +200 -0
  200. data/sig/generated/prism/string_query.rbs +43 -0
  201. data/sig/generated/prism/translation.rbs +8 -0
  202. data/sig/generated/prism/visitor.rbs +1111 -0
  203. data/sig/generated/prism.rbs +84 -0
  204. data/sig/manifest.yaml +2 -0
  205. data/src/arena.c +117 -0
  206. data/src/buffer.c +389 -0
  207. data/src/char.c +289 -0
  208. data/src/comments.c +454 -0
  209. data/src/constant_pool.c +406 -0
  210. data/src/diagnostic.c +894 -0
  211. data/src/encoding.c +5345 -0
  212. data/src/errors_format.c +519 -0
  213. data/src/integer.c +681 -0
  214. data/src/json.c +5733 -0
  215. data/src/line_offset_list.c +100 -0
  216. data/src/list.c +24 -0
  217. data/src/memchr.c +37 -0
  218. data/src/node.c +4363 -0
  219. data/src/options.c +445 -0
  220. data/src/parser.c +371 -0
  221. data/src/prettyprint.c +9024 -0
  222. data/src/prism.c +23901 -0
  223. data/src/regexp.c +1705 -0
  224. data/src/serialize.c +2660 -0
  225. data/src/source.c +524 -0
  226. data/src/static_literals.c +685 -0
  227. data/src/string_query.c +180 -0
  228. data/src/stringy.c +61 -0
  229. data/src/strncasecmp.c +37 -0
  230. data/src/strpbrk.c +447 -0
  231. data/src/tokens.c +724 -0
  232. data/src/xxh3.c +292 -0
  233. metadata +276 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file options.hpp
3
+ *
4
+ * Ownership of parse options from C++.
5
+ */
6
+ #ifndef PRISM_OPTIONS_HPP
7
+ #define PRISM_OPTIONS_HPP
8
+
9
+ #include "prism/compiler/cplusplus.hpp"
10
+
11
+ #include "prism/options.h"
12
+
13
+ #include <memory>
14
+
15
+ namespace prism {
16
+
17
+ /** Frees options with pm_options_free. */
18
+ struct options_deleter {
19
+ /**
20
+ * Free the given options.
21
+ *
22
+ * @param options The options to free.
23
+ */
24
+ void operator()(pm_options_t *options) const noexcept { pm_options_free(options); }
25
+ };
26
+
27
+ /** An owned set of options. */
28
+ using unique_options = std::unique_ptr<pm_options_t, options_deleter>;
29
+
30
+ /**
31
+ * Allocate a new set of options with every option at its default. Allocation
32
+ * failure aborts, so this never throws.
33
+ *
34
+ * @return A unique_options owning the newly allocated options.
35
+ */
36
+ [[nodiscard]] inline unique_options
37
+ make_options() noexcept {
38
+ return unique_options(pm_options_new());
39
+ }
40
+
41
+ }
42
+
43
+ #endif
@@ -0,0 +1,433 @@
1
+ /**
2
+ * @file parser.h
3
+ *
4
+ * The parser used to parse Ruby source.
5
+ */
6
+ #ifndef PRISM_PARSER_H
7
+ #define PRISM_PARSER_H
8
+
9
+ #include "prism/compiler/nodiscard.h"
10
+ #include "prism/compiler/nonnull.h"
11
+
12
+ #include "prism/ast.h"
13
+ #include "prism/comments.h"
14
+ #include "prism/diagnostic.h"
15
+ #include "prism/line_offset_list.h"
16
+ #include "prism/magic_comments.h"
17
+ #include "prism/options.h"
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+ /**
24
+ * The parser used to parse Ruby source.
25
+ */
26
+ typedef struct pm_parser_t pm_parser_t;
27
+
28
+ /**
29
+ * Allocate and initialize a parser with the given start and end pointers.
30
+ *
31
+ * @param arena The arena to use for all AST-lifetime allocations. It is caller-
32
+ * owned and must outlive the parser.
33
+ * @param source The source to parse.
34
+ * @param size The size of the source.
35
+ * @param options The optional options to use when parsing. These options must
36
+ * live for the whole lifetime of this parser.
37
+ * @returns The initialized parser. It is the responsibility of the caller to
38
+ * free the parser with `pm_parser_free()`.
39
+ */
40
+ PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1);
41
+
42
+ /**
43
+ * Free both the memory held by the given parser and the parser itself.
44
+ *
45
+ * @param parser The parser to free.
46
+ */
47
+ PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1);
48
+
49
+ /**
50
+ * When the encoding that is being used to parse the source is changed by prism,
51
+ * we provide the ability here to call out to a user-defined function.
52
+ */
53
+ typedef void (*pm_encoding_changed_callback_t)(pm_parser_t *parser);
54
+
55
+ /**
56
+ * This is the callback that is called when a token is lexed. It is passed
57
+ * the opaque data pointer, the parser, and the token that was lexed.
58
+ */
59
+ typedef void (*pm_lex_callback_t)(pm_parser_t *parser, pm_token_t *token, void *data);
60
+
61
+ /**
62
+ * Register a callback that will be called whenever prism changes the encoding
63
+ * it is using to parse based on the magic comment.
64
+ *
65
+ * @param parser The parser to register the callback with.
66
+ * @param callback The callback to register.
67
+ */
68
+ PRISM_EXPORTED_FUNCTION void pm_parser_encoding_changed_callback_set(pm_parser_t *parser, pm_encoding_changed_callback_t callback) PRISM_NONNULL(1);
69
+
70
+ /**
71
+ * Register a callback that will be called whenever a token is lexed.
72
+ *
73
+ * @param parser The parser to register the callback with.
74
+ * @param data The opaque data to pass to the callback when it is called.
75
+ * @param callback The callback to register.
76
+ */
77
+ PRISM_EXPORTED_FUNCTION void pm_parser_lex_callback_set(pm_parser_t *parser, pm_lex_callback_t callback, void *data) PRISM_NONNULL(1);
78
+
79
+ /**
80
+ * Returns the opaque data that is passed to the lex callback when it is called.
81
+ *
82
+ * @param parser The parser whose lex callback data we want to get.
83
+ * @returns The opaque data that is passed to the lex callback when it is called.
84
+ */
85
+ PRISM_EXPORTED_FUNCTION void * pm_parser_lex_callback_data(const pm_parser_t *parser) PRISM_NONNULL(1);
86
+
87
+ /**
88
+ * Returns the raw pointer to the start of the source that is being parsed.
89
+ *
90
+ * @param parser the parser whose start pointer we want to get
91
+ * @returns the raw pointer to the start of the source that is being parsed
92
+ */
93
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_parser_start(const pm_parser_t *parser) PRISM_NONNULL(1);
94
+
95
+ /**
96
+ * Returns the raw pointer to the end of the source that is being parsed.
97
+ *
98
+ * @param parser the parser whose end pointer we want to get
99
+ * @returns the raw pointer to the end of the source that is being parsed
100
+ */
101
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_parser_end(const pm_parser_t *parser) PRISM_NONNULL(1);
102
+
103
+ /**
104
+ * Returns the line that the parser was considered to have started on.
105
+ *
106
+ * @param parser the parser whose start line we want to get
107
+ * @returns the line that the parser was considered to have started on
108
+ */
109
+ PRISM_EXPORTED_FUNCTION int32_t pm_parser_start_line(const pm_parser_t *parser) PRISM_NONNULL(1);
110
+
111
+ /**
112
+ * Returns the name of the encoding that is being used to parse the source.
113
+ *
114
+ * @param parser the parser whose encoding name we want to get
115
+ * @returns the name of the encoding that is being used to parse the source
116
+ */
117
+ PRISM_EXPORTED_FUNCTION const char * pm_parser_encoding_name(const pm_parser_t *parser) PRISM_NONNULL(1);
118
+
119
+ /**
120
+ * Returns the width of the character at the given pointer in the encoding that
121
+ * is being used to parse the source.
122
+ *
123
+ * @param parser the parser whose encoding we want to use
124
+ * @param start a pointer to the start of the character
125
+ * @param remaining the number of bytes remaining in the source
126
+ * @returns the width of the character in bytes
127
+ */
128
+ PRISM_EXPORTED_FUNCTION size_t pm_parser_encoding_char_width(const pm_parser_t *parser, const uint8_t *start, ptrdiff_t remaining) PRISM_NONNULL(1, 2);
129
+
130
+ /**
131
+ * Returns whether or not the parser is using the US-ASCII encoding.
132
+ *
133
+ * @param parser the parser to check
134
+ * @returns true if the parser is using US-ASCII encoding, false otherwise
135
+ */
136
+ PRISM_EXPORTED_FUNCTION bool pm_parser_encoding_us_ascii(const pm_parser_t *parser) PRISM_NONNULL(1);
137
+
138
+ /**
139
+ * Returns the filepath that is being used to parse the source.
140
+ *
141
+ * @param parser the parser whose filepath we want to get
142
+ * @returns a pointer to the filepath string
143
+ */
144
+ PRISM_EXPORTED_FUNCTION const pm_string_t * pm_parser_filepath(const pm_parser_t *parser) PRISM_NONNULL(1);
145
+
146
+ /**
147
+ * Find a constant in the parser's constant pool. Returns the id of the
148
+ * constant, or 0 if the constant is not found.
149
+ *
150
+ * @param parser the parser whose constant pool we want to search
151
+ * @param start a pointer to the start of the string to search for
152
+ * @param length the length of the string to search for
153
+ * @returns the id of the constant, or 0 if the constant is not found
154
+ */
155
+ PRISM_EXPORTED_FUNCTION pm_constant_id_t pm_parser_constant_find(const pm_parser_t *parser, const uint8_t *start, size_t length) PRISM_NONNULL(1, 2);
156
+
157
+ /**
158
+ * Add a constant to the parser's constant pool, for naming a node that was not
159
+ * parsed from the source. If the constant is already in the pool, its existing
160
+ * id is returned. Otherwise the parser copies the bytes, so they only need to
161
+ * remain valid for the duration of the call.
162
+ *
163
+ * Adding a constant makes the pool larger, so a cache with one entry per
164
+ * constant built beforehand from pm_parser_constants_size and
165
+ * pm_parser_constant_at does not cover it. Build such caches after adding any
166
+ * constants.
167
+ *
168
+ * @param parser the parser whose constant pool we want to add to
169
+ * @param start a pointer to the start of the string to add
170
+ * @param length the length of the string to add
171
+ * @returns the id of the constant
172
+ */
173
+ PRISM_EXPORTED_FUNCTION pm_constant_id_t pm_parser_constant_insert(pm_parser_t *parser, const uint8_t *start, size_t length) PRISM_NONNULL(1, 2);
174
+
175
+ /**
176
+ * Returns the frozen string literal value of the parser, as determined by the
177
+ * frozen_string_literal magic comment or the option set on the parser.
178
+ *
179
+ * @param parser the parser whose frozen string literal value we want to get
180
+ * @returns -1 if disabled, 0 if unset, 1 if enabled
181
+ */
182
+ PRISM_EXPORTED_FUNCTION int8_t pm_parser_frozen_string_literal(const pm_parser_t *parser) PRISM_NONNULL(1);
183
+
184
+ /**
185
+ * Returns the line offsets that are associated with the given parser.
186
+ *
187
+ * @param parser the parser whose line offsets we want to get
188
+ * @returns the line offsets that are associated with the given parser
189
+ */
190
+ PRISM_EXPORTED_FUNCTION const pm_line_offset_list_t * pm_parser_line_offsets(const pm_parser_t *parser) PRISM_NONNULL(1);
191
+
192
+ /**
193
+ * Returns the location of the __DATA__ section that is associated with the
194
+ * given parser.
195
+ *
196
+ * @param parser the parser whose data location we want to get
197
+ * @returns the location of the __DATA__ section that is associated with the
198
+ * given parser. If it is unset, then the length will be set to 0.
199
+ */
200
+ PRISM_EXPORTED_FUNCTION const pm_location_t * pm_parser_data_loc(const pm_parser_t *parser) PRISM_NONNULL(1);
201
+
202
+ /**
203
+ * Returns the checksum of the source code that was parsed. The data section
204
+ * after an __END__ marker is not code, so the hash covers the source only up to
205
+ * and including the newline that ends the __END__ line. The __END__ marker is
206
+ * only found by parsing, so this must be called after pm_parse.
207
+ *
208
+ * The hash is computed from the source on each call rather than during
209
+ * parsing, so that parses that never ask for it do not pay for it. This
210
+ * requires the source to still be alive, and callers that need the value more
211
+ * than once should keep it.
212
+ *
213
+ * The hash is currently the 64-bit variant of XXH3 with a seed of 0. It is not
214
+ * cryptographic, and the algorithm may change between versions of prism, so
215
+ * hashes should only be compared against other hashes computed by the same
216
+ * version of prism.
217
+ *
218
+ * @param parser the parser whose checksum we want to get
219
+ * @returns the checksum of the source code that was parsed
220
+ */
221
+ PRISM_EXPORTED_FUNCTION uint64_t pm_parser_checksum(const pm_parser_t *parser) PRISM_NONNULL(1);
222
+
223
+ /**
224
+ * Returns whether the given parser is continuable, meaning that it could become
225
+ * valid if more input were appended, as opposed to being definitively invalid.
226
+ *
227
+ * @param parser the parser whose continuable status we want to get
228
+ * @returns whether the given parser is continuable
229
+ */
230
+ PRISM_EXPORTED_FUNCTION bool pm_parser_continuable(const pm_parser_t *parser) PRISM_NONNULL(1);
231
+
232
+ /**
233
+ * Returns the lex state of the parser. Note that this is an internal detail,
234
+ * and we are purposefully not returning an instance of the internal enum that
235
+ * we use to track this. This is only exposed because we need it for some very
236
+ * niche use cases. Most consumers should avoid this function.
237
+ *
238
+ * @param parser the parser whose lex state we want to get
239
+ * @returns the lex state of the parser
240
+ */
241
+ PRISM_EXPORTED_FUNCTION int pm_parser_lex_state(const pm_parser_t *parser) PRISM_NONNULL(1);
242
+
243
+ /**
244
+ * Returns the number of comments associated with the given parser.
245
+ *
246
+ * @param parser the parser whose comments we want to get the size of
247
+ * @returns the number of comments associated with the given parser
248
+ */
249
+ PRISM_EXPORTED_FUNCTION size_t pm_parser_comments_size(const pm_parser_t *parser) PRISM_NONNULL(1);
250
+
251
+ /**
252
+ * Returns the first comment associated with the given parser. Iterate over the
253
+ * rest with pm_comment_next, as in:
254
+ *
255
+ * ```c
256
+ * for (const pm_comment_t *comment = pm_parser_comments_first(parser); comment != NULL; comment = pm_comment_next(comment)) {
257
+ * pm_location_t location = pm_comment_location(comment);
258
+ * }
259
+ * ```
260
+ *
261
+ * @param parser the parser whose comments we want to iterate over
262
+ * @returns the first comment, or NULL if there are no comments
263
+ */
264
+ PRISM_EXPORTED_FUNCTION const pm_comment_t * pm_parser_comments_first(const pm_parser_t *parser) PRISM_NONNULL(1);
265
+
266
+ /**
267
+ * Returns the number of comments owned by the given node. This is 0 if the
268
+ * node owns no comments or if the attach_comments option was not set.
269
+ *
270
+ * @param parser the parser that produced the node
271
+ * @param node the node whose comments we want to count
272
+ * @returns the number of comments owned by the given node
273
+ */
274
+ PRISM_EXPORTED_FUNCTION uint32_t pm_node_comments_size(const pm_parser_t *parser, const pm_node_t *node) PRISM_NONNULL(1, 2);
275
+
276
+ /**
277
+ * Returns the comment at the given index among the comments owned by the given
278
+ * node, which are ordered by start offset.
279
+ *
280
+ * @param parser the parser that produced the node
281
+ * @param node the node whose comment we want to get
282
+ * @param index the index of the comment among those owned by the node
283
+ * @returns the comment at the given index, or NULL if the index is out of range
284
+ */
285
+ PRISM_EXPORTED_FUNCTION const pm_comment_t * pm_node_comment(const pm_parser_t *parser, const pm_node_t *node, uint32_t index) PRISM_NONNULL(1, 2);
286
+
287
+ /**
288
+ * Returns the index, among the comments associated with the given parser, of
289
+ * the comment at the given index among the comment attachments. The attachments
290
+ * are every comment, grouped by owning node in order of node id and ordered by
291
+ * start offset within each node, so there are as many attachments as there are
292
+ * comments when the attach_comments option is set.
293
+ *
294
+ * @param parser the parser whose comment attachments we want to read
295
+ * @param index the index of the attachment
296
+ * @returns the index of the comment, or UINT32_MAX if the index is out of range
297
+ * or the attach_comments option was not set
298
+ */
299
+ PRISM_EXPORTED_FUNCTION uint32_t pm_parser_comment_attachment(const pm_parser_t *parser, uint32_t index) PRISM_NONNULL(1);
300
+
301
+ /**
302
+ * Returns the number of node ids that have a comment range, which is one more
303
+ * than the largest id of a node that owns a comment, or 0 if the
304
+ * attach_comments option was not set or there are no comments.
305
+ *
306
+ * @param parser the parser whose comment ranges we want to count
307
+ * @returns the number of comment ranges
308
+ */
309
+ PRISM_EXPORTED_FUNCTION uint32_t pm_parser_comment_ranges_size(const pm_parser_t *parser) PRISM_NONNULL(1);
310
+
311
+ /**
312
+ * Returns the range of comment attachments owned by the node with the given id.
313
+ *
314
+ * @param parser the parser that produced the node
315
+ * @param node_id the id of the node
316
+ * @returns the range of attachments owned by the node, whose length is 0 if the
317
+ * node owns no comments, the node id is out of range, or the
318
+ * attach_comments option was not set
319
+ */
320
+ PRISM_EXPORTED_FUNCTION pm_comment_range_t pm_parser_comment_range(const pm_parser_t *parser, uint32_t node_id) PRISM_NONNULL(1);
321
+
322
+ /**
323
+ * Returns the number of magic comments associated with the given parser.
324
+ *
325
+ * @param parser the parser whose magic comments we want to get the size of
326
+ * @returns the number of magic comments associated with the given parser
327
+ */
328
+ PRISM_EXPORTED_FUNCTION size_t pm_parser_magic_comments_size(const pm_parser_t *parser) PRISM_NONNULL(1);
329
+
330
+ /**
331
+ * Returns the first magic comment associated with the given parser. Iterate
332
+ * over the rest with pm_magic_comment_next.
333
+ *
334
+ * @param parser the parser whose magic comments we want to iterate over
335
+ * @returns the first magic comment, or NULL if there are no magic comments
336
+ */
337
+ PRISM_EXPORTED_FUNCTION const pm_magic_comment_t * pm_parser_magic_comments_first(const pm_parser_t *parser) PRISM_NONNULL(1);
338
+
339
+ /**
340
+ * Returns the number of errors associated with the given parser.
341
+ *
342
+ * @param parser the parser whose errors we want to get the size of
343
+ * @returns the number of errors associated with the given parser
344
+ */
345
+ PRISM_EXPORTED_FUNCTION size_t pm_parser_errors_size(const pm_parser_t *parser) PRISM_NONNULL(1);
346
+
347
+ /**
348
+ * Returns the number of warnings associated with the given parser.
349
+ *
350
+ * @param parser the parser whose warnings we want to get the size of
351
+ * @returns the number of warnings associated with the given parser
352
+ */
353
+ PRISM_EXPORTED_FUNCTION size_t pm_parser_warnings_size(const pm_parser_t *parser) PRISM_NONNULL(1);
354
+
355
+ /**
356
+ * Returns the first error associated with the given parser. Iterate over the
357
+ * rest with pm_diagnostic_next.
358
+ *
359
+ * @param parser the parser whose errors we want to iterate over
360
+ * @returns the first error, or NULL if there are no errors
361
+ */
362
+ PRISM_EXPORTED_FUNCTION const pm_diagnostic_t * pm_parser_errors_first(const pm_parser_t *parser) PRISM_NONNULL(1);
363
+
364
+ /**
365
+ * Returns the first warning associated with the given parser. Iterate over the
366
+ * rest with pm_diagnostic_next.
367
+ *
368
+ * @param parser the parser whose warnings we want to iterate over
369
+ * @returns the first warning, or NULL if there are no warnings
370
+ */
371
+ PRISM_EXPORTED_FUNCTION const pm_diagnostic_t * pm_parser_warnings_first(const pm_parser_t *parser) PRISM_NONNULL(1);
372
+
373
+ /**
374
+ * Returns the number of constants in the constant pool associated with the
375
+ * given parser.
376
+ *
377
+ * @param parser the parser whose constant pool constants we want to get the
378
+ * size of
379
+ * @returns the number of constants in the constant pool associated with the
380
+ * given parser
381
+ */
382
+ PRISM_EXPORTED_FUNCTION size_t pm_parser_constants_size(const pm_parser_t *parser) PRISM_NONNULL(1);
383
+
384
+ /**
385
+ * Returns the constant at the given index in the constant pool associated with
386
+ * the given parser. Together with pm_constant_id_index, this lets a caller
387
+ * build a cache with one entry per constant and then find the entry for any
388
+ * constant id, as in:
389
+ *
390
+ * ```c
391
+ * size_t size = pm_parser_constants_size(parser);
392
+ * for (size_t index = 0; index < size; index++) {
393
+ * cache[index] = convert(pm_parser_constant_at(parser, index));
394
+ * }
395
+ *
396
+ * value = cache[pm_constant_id_index(constant_id)];
397
+ * ```
398
+ *
399
+ * For any constant id, pm_parser_constant_at(parser,
400
+ * pm_constant_id_index(constant_id)) is pm_parser_constant(parser,
401
+ * constant_id).
402
+ *
403
+ * @param parser the parser whose constant pool we want to look up from
404
+ * @param index the index of the constant, which must be less than
405
+ * pm_parser_constants_size(parser)
406
+ * @returns a pointer to the constant at the given index
407
+ */
408
+ PRISM_EXPORTED_FUNCTION const pm_constant_t * pm_parser_constant_at(const pm_parser_t *parser, size_t index) PRISM_NONNULL(1);
409
+
410
+ /**
411
+ * Returns a pointer to the constant at the given id in the constant pool
412
+ * associated with the given parser.
413
+ *
414
+ * @param parser the parser whose constant pool we want to look up from
415
+ * @param constant_id the id of the constant to look up. Optional constant
416
+ * fields on nodes hold 0 when they are absent, which is not a valid id.
417
+ * @returns a pointer to the constant at the given id
418
+ */
419
+ PRISM_EXPORTED_FUNCTION const pm_constant_t * pm_parser_constant(const pm_parser_t *parser, pm_constant_id_t constant_id) PRISM_NONNULL(1);
420
+
421
+ /**
422
+ * Initiate the parser with the given parser.
423
+ *
424
+ * @param parser The parser to use.
425
+ * @returns The AST representing the source.
426
+ */
427
+ PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser) PRISM_NONNULL(1);
428
+
429
+ #ifdef __cplusplus
430
+ }
431
+ #endif
432
+
433
+ #endif