herb 0.11.1 → 0.11.2

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 (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -2
  3. data/config.yml +6 -0
  4. data/ext/herb/extconf.rb +8 -31
  5. data/ext/herb/nodes.c +75 -75
  6. data/ext/herb/parser_options_helpers.c +26 -0
  7. data/lib/herb/analysis/partial_index.rb +1 -1
  8. data/lib/herb/analysis/partial_resolution.rb +27 -0
  9. data/lib/herb/ast/helpers.rb +1 -1
  10. data/lib/herb/configuration.rb +11 -1
  11. data/lib/herb/dev/classifier.rb +1 -1
  12. data/lib/herb/engine/compiler.rb +5 -8
  13. data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
  14. data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
  15. data/lib/herb/engine/slots/visitor.rb +32 -4
  16. data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
  17. data/lib/herb/parser_options.rb +6 -3
  18. data/lib/herb/project.rb +19 -8
  19. data/lib/herb/version.rb +1 -1
  20. data/lib/herb.rb +1 -1
  21. data/sig/herb/analysis/partial_resolution.rbs +8 -0
  22. data/sig/herb/configuration.rbs +3 -0
  23. data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
  24. data/sig/herb/engine/slots/visitor.rbs +14 -0
  25. data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
  26. data/sig/herb/parser_options.rbs +6 -4
  27. data/sig/herb.rbs +2 -2
  28. data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
  29. data/src/analyze/action_view/generated_handlers.c +36 -36
  30. data/src/analyze/action_view/image_tag.c +7 -3
  31. data/src/analyze/action_view/javascript_include_tag.c +6 -3
  32. data/src/analyze/action_view/link_to.c +23 -23
  33. data/src/analyze/action_view/registry.c +7 -3
  34. data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
  35. data/src/analyze/action_view/tag_helpers.c +139 -90
  36. data/src/analyze/action_view/turbo_frame_tag.c +5 -4
  37. data/src/analyze/analyze.c +35 -19
  38. data/src/analyze/analyze_helpers.c +161 -188
  39. data/src/analyze/analyzed_ruby.c +8 -7
  40. data/src/analyze/control_type.c +29 -22
  41. data/src/analyze/herb_directives.c +16 -20
  42. data/src/analyze/iteration_nodes.c +69 -24
  43. data/src/analyze/parse_errors.c +32 -22
  44. data/src/analyze/postfix_conditionals.c +23 -13
  45. data/src/analyze/prism_annotate.c +29 -28
  46. data/src/analyze/render_nodes.c +51 -41
  47. data/src/analyze/strict_locals.c +14 -15
  48. data/src/analyze/ternary_conditionals.c +14 -10
  49. data/src/herb.c +10 -8
  50. data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
  51. data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
  52. data/src/include/analyze/action_view/tag_helpers.h +1 -1
  53. data/src/include/analyze/analyze.h +3 -2
  54. data/src/include/analyze/analyzed_ruby.h +4 -2
  55. data/src/include/analyze/helpers.h +6 -6
  56. data/src/include/herb.h +3 -2
  57. data/src/include/parser/parser_options.h +5 -0
  58. data/src/include/prism/prism_context.h +12 -12
  59. data/src/include/prism/prism_helpers.h +30 -0
  60. data/src/include/prism_version.h +11 -0
  61. data/src/include/version.h +1 -1
  62. data/src/parser/parser_helpers.c +1 -2
  63. data/src/parser.c +6 -7
  64. data/src/parser_options_defaults.c +1 -0
  65. data/src/prism/prism_helpers.c +84 -50
  66. data/src/prism/ruby_parser.c +20 -20
  67. data/templates/ext/herb/nodes.c.erb +5 -5
  68. data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
  69. data/templates/java/nodes.c.erb +6 -6
  70. data/templates/java/parser_options_helpers.c.erb +41 -2
  71. data/templates/java/parser_options_helpers.h.erb +2 -1
  72. data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
  73. data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
  74. data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
  75. data/templates/lib/herb/parser_options.rb.erb +1 -1
  76. data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
  77. data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
  78. data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
  79. data/templates/src/include/parser/parser_options.h.erb +10 -0
  80. data/templates/src/include/prism_version.h.erb +17 -0
  81. data/templates/src/parser_options_defaults.c.erb +1 -1
  82. data/templates/template.rb +17 -2
  83. data/templates/wasm/nodes.cpp.erb +5 -5
  84. data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
  85. data/vendor/prism/Rakefile +76 -7
  86. data/vendor/prism/config.yml +174 -161
  87. data/vendor/prism/include/prism/arena.h +45 -0
  88. data/vendor/prism/include/prism/arena.hpp +42 -0
  89. data/vendor/prism/include/prism/ast.h +2738 -611
  90. data/vendor/prism/include/prism/ast.hpp +641 -0
  91. data/vendor/prism/include/prism/buffer.h +60 -0
  92. data/vendor/prism/include/prism/buffer.hpp +55 -0
  93. data/vendor/prism/include/prism/comments.h +72 -0
  94. data/vendor/prism/include/prism/compiler/accel.h +26 -0
  95. data/vendor/prism/include/prism/compiler/align.h +36 -0
  96. data/vendor/prism/include/prism/compiler/assume.h +25 -0
  97. data/vendor/prism/include/prism/compiler/branch.h +26 -0
  98. data/vendor/prism/include/prism/compiler/bswap.h +46 -0
  99. data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
  100. data/vendor/prism/include/prism/compiler/endianness.h +34 -0
  101. data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
  102. data/vendor/prism/include/prism/compiler/exported.h +24 -0
  103. data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
  104. data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
  105. data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
  106. data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
  107. data/vendor/prism/include/prism/compiler/format.h +27 -0
  108. data/vendor/prism/include/prism/compiler/inline.h +17 -0
  109. data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
  110. data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
  111. data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
  112. data/vendor/prism/include/prism/compiler/unused.h +18 -0
  113. data/vendor/prism/include/prism/constant_pool.h +106 -0
  114. data/vendor/prism/include/prism/diagnostic.h +55 -402
  115. data/vendor/prism/include/prism/errors_format.h +61 -0
  116. data/vendor/prism/include/prism/excludes.h +29 -0
  117. data/vendor/prism/include/prism/integer.h +41 -0
  118. data/vendor/prism/include/prism/internal/allocator.h +68 -0
  119. data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
  120. data/vendor/prism/include/prism/internal/arena.h +108 -0
  121. data/vendor/prism/include/prism/internal/bit.h +42 -0
  122. data/vendor/prism/include/prism/internal/buffer.h +94 -0
  123. data/vendor/prism/include/prism/internal/char.h +145 -0
  124. data/vendor/prism/include/prism/internal/comments.h +54 -0
  125. data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
  126. data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
  127. data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
  128. data/vendor/prism/include/prism/internal/integer.h +68 -0
  129. data/vendor/prism/include/prism/internal/isinf.h +16 -0
  130. data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
  131. data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  132. data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
  133. data/vendor/prism/include/prism/internal/memchr.h +15 -0
  134. data/vendor/prism/include/prism/internal/node.h +42 -0
  135. data/vendor/prism/include/prism/internal/options.h +232 -0
  136. data/vendor/prism/include/prism/internal/parser.h +1015 -0
  137. data/vendor/prism/include/prism/internal/regexp.h +26 -0
  138. data/vendor/prism/include/prism/internal/serialize.h +39 -0
  139. data/vendor/prism/include/prism/internal/source.h +72 -0
  140. data/vendor/prism/include/prism/internal/static_literals.h +60 -0
  141. data/vendor/prism/include/prism/internal/stringy.h +30 -0
  142. data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  143. data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  144. data/vendor/prism/include/prism/internal/tokens.h +11 -0
  145. data/vendor/prism/include/prism/internal/xxh3.h +16 -0
  146. data/vendor/prism/include/prism/json.h +40 -0
  147. data/vendor/prism/include/prism/line_offset_list.h +69 -0
  148. data/vendor/prism/include/prism/magic_comments.h +53 -0
  149. data/vendor/prism/include/prism/node.h +59 -49
  150. data/vendor/prism/include/prism/node.hpp +272 -0
  151. data/vendor/prism/include/prism/node_type.hpp +38 -0
  152. data/vendor/prism/include/prism/options.h +154 -279
  153. data/vendor/prism/include/prism/options.hpp +43 -0
  154. data/vendor/prism/include/prism/parser.h +367 -870
  155. data/vendor/prism/include/prism/parser.hpp +274 -0
  156. data/vendor/prism/include/prism/prettyprint.h +14 -9
  157. data/vendor/prism/include/prism/serialize.h +123 -0
  158. data/vendor/prism/include/prism/source.h +163 -0
  159. data/vendor/prism/include/prism/stream.h +36 -0
  160. data/vendor/prism/include/prism/string_query.h +82 -0
  161. data/vendor/prism/include/prism/stringy.h +61 -0
  162. data/vendor/prism/include/prism/stringy.hpp +31 -0
  163. data/vendor/prism/include/prism/version.h +20 -3
  164. data/vendor/prism/include/prism.h +35 -320
  165. data/vendor/prism/include/prism.hpp +24 -0
  166. data/vendor/prism/src/arena.c +122 -0
  167. data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
  168. data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
  169. data/vendor/prism/src/comments.c +455 -0
  170. data/vendor/prism/src/constant_pool.c +406 -0
  171. data/vendor/prism/src/diagnostic.c +120 -68
  172. data/vendor/prism/src/encoding.c +8 -3
  173. data/vendor/prism/src/errors_format.c +519 -0
  174. data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
  175. data/vendor/prism/src/json.c +5733 -0
  176. data/vendor/prism/src/line_offset_list.c +100 -0
  177. data/vendor/prism/src/list.c +24 -0
  178. data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
  179. data/vendor/prism/src/node.c +3465 -7787
  180. data/vendor/prism/src/options.c +161 -54
  181. data/vendor/prism/src/parser.c +371 -0
  182. data/vendor/prism/src/prettyprint.c +421 -354
  183. data/vendor/prism/src/prism.c +8522 -7280
  184. data/vendor/prism/src/regexp.c +960 -45
  185. data/vendor/prism/src/serialize.c +2434 -2048
  186. data/vendor/prism/src/source.c +524 -0
  187. data/vendor/prism/src/static_literals.c +303 -360
  188. data/vendor/prism/src/string_query.c +180 -0
  189. data/vendor/prism/src/stringy.c +61 -0
  190. data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  191. data/vendor/prism/src/strpbrk.c +447 -0
  192. data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
  193. data/vendor/prism/src/xxh3.c +292 -0
  194. data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
  195. data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
  196. data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
  197. data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
  198. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
  199. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
  200. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
  201. data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
  202. data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
  203. data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
  204. data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
  205. data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
  206. data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
  207. data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
  208. data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
  209. data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
  210. data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
  211. data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
  212. data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
  213. data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
  214. data/vendor/prism/templates/src/json.c.erb +130 -0
  215. data/vendor/prism/templates/src/node.c.erb +79 -236
  216. data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
  217. data/vendor/prism/templates/src/serialize.c.erb +369 -183
  218. data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
  219. data/vendor/prism/templates/template.rb +193 -91
  220. metadata +100 -42
  221. data/vendor/prism/include/prism/defines.h +0 -260
  222. data/vendor/prism/include/prism/pack.h +0 -163
  223. data/vendor/prism/include/prism/regexp.h +0 -43
  224. data/vendor/prism/include/prism/static_literals.h +0 -121
  225. data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
  226. data/vendor/prism/include/prism/util/pm_char.h +0 -204
  227. data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
  228. data/vendor/prism/include/prism/util/pm_integer.h +0 -130
  229. data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
  230. data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
  231. data/vendor/prism/include/prism/util/pm_string.h +0 -200
  232. data/vendor/prism/src/pack.c +0 -509
  233. data/vendor/prism/src/util/pm_constant_pool.c +0 -342
  234. data/vendor/prism/src/util/pm_list.c +0 -49
  235. data/vendor/prism/src/util/pm_newline_list.c +0 -125
  236. data/vendor/prism/src/util/pm_string.c +0 -381
  237. data/vendor/prism/src/util/pm_strpbrk.c +0 -206
  238. data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
  239. data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
  240. data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
  241. data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
  242. data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
  243. data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
  244. data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
  245. data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
  246. data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
  247. data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @file constant_pool.h
3
+ *
4
+ * A data structure that stores a set of strings.
5
+ *
6
+ * Each string is assigned a unique id, which can be used to compare strings for
7
+ * equality. This comparison ends up being much faster than strcmp, since it
8
+ * only requires a single integer comparison.
9
+ */
10
+ #ifndef PRISM_CONSTANT_POOL_H
11
+ #define PRISM_CONSTANT_POOL_H
12
+
13
+ #include "prism/compiler/exported.h"
14
+ #include "prism/compiler/inline.h"
15
+ #include "prism/compiler/nodiscard.h"
16
+ #include "prism/compiler/nonnull.h"
17
+
18
+ #include "prism/arena.h"
19
+
20
+ #include <stddef.h>
21
+ #include <stdint.h>
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ /**
28
+ * A constant id is a unique identifier for a constant in the constant pool.
29
+ */
30
+ typedef uint32_t pm_constant_id_t;
31
+
32
+ /**
33
+ * Returns the index of the constant with the given id among the constants of
34
+ * the parser that produced it. The indices run from 0 to one less than
35
+ * pm_parser_constants_size, so they can index a cache with one entry per
36
+ * constant that was filled using pm_parser_constant_at.
37
+ *
38
+ * @param constant_id the id of the constant. Optional constant fields on nodes
39
+ * hold 0 when they are absent, which is not a valid id, so check for it
40
+ * before calling this function.
41
+ * @returns the index of the constant
42
+ */
43
+ static PRISM_INLINE size_t
44
+ pm_constant_id_index(pm_constant_id_t constant_id) {
45
+ return (size_t) constant_id - 1;
46
+ }
47
+
48
+ /**
49
+ * A list of constant IDs. Usually used to represent a set of locals.
50
+ */
51
+ typedef struct {
52
+ /** The number of constant ids in the list. */
53
+ size_t size;
54
+
55
+ /** The number of constant ids that have been allocated in the list. */
56
+ size_t capacity;
57
+
58
+ /** The constant ids in the list. */
59
+ pm_constant_id_t *ids;
60
+ } pm_constant_id_list_t;
61
+
62
+ /** A constant in the pool which effectively stores a string. */
63
+ typedef struct pm_constant_t pm_constant_t;
64
+
65
+ /**
66
+ * The overall constant pool, which stores constants found while parsing.
67
+ */
68
+ typedef struct pm_constant_pool_t pm_constant_pool_t;
69
+
70
+ /**
71
+ * Return a raw pointer to the start of a constant.
72
+ *
73
+ * @param constant The constant to get the start of.
74
+ * @returns A raw pointer to the start of the constant.
75
+ */
76
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_constant_start(const pm_constant_t *constant) PRISM_NONNULL(1);
77
+
78
+ /**
79
+ * Return the length of a constant.
80
+ *
81
+ * @param constant The constant to get the length of.
82
+ * @returns The length of the constant.
83
+ */
84
+ PRISM_EXPORTED_FUNCTION size_t pm_constant_length(const pm_constant_t *constant) PRISM_NONNULL(1);
85
+
86
+ /**
87
+ * Initialize a list of constant ids.
88
+ *
89
+ * @param list The list to initialize.
90
+ */
91
+ PRISM_EXPORTED_FUNCTION void pm_constant_id_list_init(pm_constant_id_list_t *list) PRISM_NONNULL(1);
92
+
93
+ /**
94
+ * Append a constant id to a list of constant ids.
95
+ *
96
+ * @param arena The arena to use for allocations.
97
+ * @param list The list to append to.
98
+ * @param id The constant id to append.
99
+ */
100
+ PRISM_EXPORTED_FUNCTION void pm_constant_id_list_append(pm_arena_t *arena, pm_constant_id_list_t *list, pm_constant_id_t id) PRISM_NONNULL(1, 2);
101
+
102
+ #ifdef __cplusplus
103
+ }
104
+ #endif
105
+
106
+ #endif
@@ -1,13 +1,3 @@
1
- /* :markup: markdown */
2
-
3
- /*----------------------------------------------------------------------------*/
4
- /* This file is generated by the templates/template.rb script and should not */
5
- /* be modified manually. See */
6
- /* templates/include/prism/diagnostic.h.erb */
7
- /* if you are looking to modify the */
8
- /* template */
9
- /*----------------------------------------------------------------------------*/
10
-
11
1
  /**
12
2
  * @file diagnostic.h
13
3
  *
@@ -16,379 +6,20 @@
16
6
  #ifndef PRISM_DIAGNOSTIC_H
17
7
  #define PRISM_DIAGNOSTIC_H
18
8
 
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
19
13
  #include "prism/ast.h"
20
- #include "prism/defines.h"
21
- #include "prism/util/pm_list.h"
22
14
 
23
- #include <stdbool.h>
24
- #include <stdlib.h>
25
- #include <assert.h>
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
26
18
 
27
19
  /**
28
- * The diagnostic IDs of all of the diagnostics, used to communicate the types
29
- * of errors between the parser and the user.
20
+ * An opaque pointer to a diagnostic generated during parsing.
30
21
  */
31
- typedef enum {
32
- // These are the error diagnostics.
33
- PM_ERR_ALIAS_ARGUMENT,
34
- PM_ERR_ALIAS_ARGUMENT_NUMBERED_REFERENCE,
35
- PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
36
- PM_ERR_ARGUMENT_AFTER_BLOCK,
37
- PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
38
- PM_ERR_ARGUMENT_BARE_HASH,
39
- PM_ERR_ARGUMENT_BLOCK_FORWARDING,
40
- PM_ERR_ARGUMENT_BLOCK_MULTI,
41
- PM_ERR_ARGUMENT_CONFLICT_AMPERSAND,
42
- PM_ERR_ARGUMENT_CONFLICT_STAR,
43
- PM_ERR_ARGUMENT_CONFLICT_STAR_STAR,
44
- PM_ERR_ARGUMENT_FORMAL_CLASS,
45
- PM_ERR_ARGUMENT_FORMAL_CONSTANT,
46
- PM_ERR_ARGUMENT_FORMAL_GLOBAL,
47
- PM_ERR_ARGUMENT_FORMAL_IVAR,
48
- PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
49
- PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND,
50
- PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
51
- PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
52
- PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR,
53
- PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT,
54
- PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT,
55
- PM_ERR_ARGUMENT_TERM_PAREN,
56
- PM_ERR_ARGUMENT_UNEXPECTED_BLOCK,
57
- PM_ERR_ARRAY_ELEMENT,
58
- PM_ERR_ARRAY_EXPRESSION,
59
- PM_ERR_ARRAY_EXPRESSION_AFTER_STAR,
60
- PM_ERR_ARRAY_SEPARATOR,
61
- PM_ERR_ARRAY_TERM,
62
- PM_ERR_BEGIN_LONELY_ELSE,
63
- PM_ERR_BEGIN_TERM,
64
- PM_ERR_BEGIN_UPCASE_BRACE,
65
- PM_ERR_BEGIN_UPCASE_TERM,
66
- PM_ERR_BEGIN_UPCASE_TOPLEVEL,
67
- PM_ERR_BLOCK_PARAM_LOCAL_VARIABLE,
68
- PM_ERR_BLOCK_PARAM_PIPE_TERM,
69
- PM_ERR_BLOCK_TERM_BRACE,
70
- PM_ERR_BLOCK_TERM_END,
71
- PM_ERR_CANNOT_PARSE_EXPRESSION,
72
- PM_ERR_CANNOT_PARSE_STRING_PART,
73
- PM_ERR_CASE_EXPRESSION_AFTER_CASE,
74
- PM_ERR_CASE_EXPRESSION_AFTER_WHEN,
75
- PM_ERR_CASE_MATCH_MISSING_PREDICATE,
76
- PM_ERR_CASE_MISSING_CONDITIONS,
77
- PM_ERR_CASE_TERM,
78
- PM_ERR_CLASS_IN_METHOD,
79
- PM_ERR_CLASS_NAME,
80
- PM_ERR_CLASS_SUPERCLASS,
81
- PM_ERR_CLASS_TERM,
82
- PM_ERR_CLASS_UNEXPECTED_END,
83
- PM_ERR_CLASS_VARIABLE_BARE,
84
- PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
85
- PM_ERR_CONDITIONAL_IF_PREDICATE,
86
- PM_ERR_CONDITIONAL_PREDICATE_TERM,
87
- PM_ERR_CONDITIONAL_TERM,
88
- PM_ERR_CONDITIONAL_TERM_ELSE,
89
- PM_ERR_CONDITIONAL_UNLESS_PREDICATE,
90
- PM_ERR_CONDITIONAL_UNTIL_PREDICATE,
91
- PM_ERR_CONDITIONAL_WHILE_PREDICATE,
92
- PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT,
93
- PM_ERR_DEF_ENDLESS,
94
- PM_ERR_DEF_ENDLESS_PARAMETERS,
95
- PM_ERR_DEF_ENDLESS_SETTER,
96
- PM_ERR_DEF_NAME,
97
- PM_ERR_DEF_PARAMS_TERM,
98
- PM_ERR_DEF_PARAMS_TERM_PAREN,
99
- PM_ERR_DEF_RECEIVER,
100
- PM_ERR_DEF_RECEIVER_TERM,
101
- PM_ERR_DEF_TERM,
102
- PM_ERR_DEFINED_EXPRESSION,
103
- PM_ERR_EMBDOC_TERM,
104
- PM_ERR_EMBEXPR_END,
105
- PM_ERR_EMBVAR_INVALID,
106
- PM_ERR_END_UPCASE_BRACE,
107
- PM_ERR_END_UPCASE_TERM,
108
- PM_ERR_ESCAPE_INVALID_CONTROL,
109
- PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT,
110
- PM_ERR_ESCAPE_INVALID_HEXADECIMAL,
111
- PM_ERR_ESCAPE_INVALID_META,
112
- PM_ERR_ESCAPE_INVALID_META_REPEAT,
113
- PM_ERR_ESCAPE_INVALID_UNICODE,
114
- PM_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS,
115
- PM_ERR_ESCAPE_INVALID_UNICODE_LIST,
116
- PM_ERR_ESCAPE_INVALID_UNICODE_LITERAL,
117
- PM_ERR_ESCAPE_INVALID_UNICODE_LONG,
118
- PM_ERR_ESCAPE_INVALID_UNICODE_SHORT,
119
- PM_ERR_ESCAPE_INVALID_UNICODE_TERM,
120
- PM_ERR_EXPECT_ARGUMENT,
121
- PM_ERR_EXPECT_EOL_AFTER_STATEMENT,
122
- PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ,
123
- PM_ERR_EXPECT_EXPRESSION_AFTER_COMMA,
124
- PM_ERR_EXPECT_EXPRESSION_AFTER_EQUAL,
125
- PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS,
126
- PM_ERR_EXPECT_EXPRESSION_AFTER_LPAREN,
127
- PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR,
128
- PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
129
- PM_ERR_EXPECT_EXPRESSION_AFTER_QUESTION,
130
- PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT,
131
- PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
132
- PM_ERR_EXPECT_EXPRESSION_AFTER_STAR,
133
- PM_ERR_EXPECT_FOR_DELIMITER,
134
- PM_ERR_EXPECT_IDENT_REQ_PARAMETER,
135
- PM_ERR_EXPECT_IN_DELIMITER,
136
- PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN,
137
- PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER,
138
- PM_ERR_EXPECT_LPAREN_REQ_PARAMETER,
139
- PM_ERR_EXPECT_MESSAGE,
140
- PM_ERR_EXPECT_RBRACKET,
141
- PM_ERR_EXPECT_RPAREN,
142
- PM_ERR_EXPECT_RPAREN_AFTER_MULTI,
143
- PM_ERR_EXPECT_RPAREN_REQ_PARAMETER,
144
- PM_ERR_EXPECT_SINGLETON_CLASS_DELIMITER,
145
- PM_ERR_EXPECT_STRING_CONTENT,
146
- PM_ERR_EXPECT_WHEN_DELIMITER,
147
- PM_ERR_EXPRESSION_BARE_HASH,
148
- PM_ERR_EXPRESSION_NOT_WRITABLE,
149
- PM_ERR_EXPRESSION_NOT_WRITABLE_ENCODING,
150
- PM_ERR_EXPRESSION_NOT_WRITABLE_FALSE,
151
- PM_ERR_EXPRESSION_NOT_WRITABLE_FILE,
152
- PM_ERR_EXPRESSION_NOT_WRITABLE_LINE,
153
- PM_ERR_EXPRESSION_NOT_WRITABLE_NIL,
154
- PM_ERR_EXPRESSION_NOT_WRITABLE_NUMBERED,
155
- PM_ERR_EXPRESSION_NOT_WRITABLE_SELF,
156
- PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE,
157
- PM_ERR_FLOAT_PARSE,
158
- PM_ERR_FOR_COLLECTION,
159
- PM_ERR_FOR_IN,
160
- PM_ERR_FOR_INDEX,
161
- PM_ERR_FOR_TERM,
162
- PM_ERR_GLOBAL_VARIABLE_BARE,
163
- PM_ERR_HASH_EXPRESSION_AFTER_LABEL,
164
- PM_ERR_HASH_KEY,
165
- PM_ERR_HASH_ROCKET,
166
- PM_ERR_HASH_TERM,
167
- PM_ERR_HASH_VALUE,
168
- PM_ERR_HEREDOC_IDENTIFIER,
169
- PM_ERR_HEREDOC_TERM,
170
- PM_ERR_INCOMPLETE_QUESTION_MARK,
171
- PM_ERR_INCOMPLETE_VARIABLE_CLASS,
172
- PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3,
173
- PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
174
- PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3,
175
- PM_ERR_INSTANCE_VARIABLE_BARE,
176
- PM_ERR_INVALID_BLOCK_EXIT,
177
- PM_ERR_INVALID_CHARACTER,
178
- PM_ERR_INVALID_COMMA,
179
- PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
180
- PM_ERR_INVALID_ESCAPE_CHARACTER,
181
- PM_ERR_INVALID_FLOAT_EXPONENT,
182
- PM_ERR_INVALID_LOCAL_VARIABLE_READ,
183
- PM_ERR_INVALID_LOCAL_VARIABLE_WRITE,
184
- PM_ERR_INVALID_MULTIBYTE_CHAR,
185
- PM_ERR_INVALID_MULTIBYTE_CHARACTER,
186
- PM_ERR_INVALID_MULTIBYTE_ESCAPE,
187
- PM_ERR_INVALID_NUMBER_BINARY,
188
- PM_ERR_INVALID_NUMBER_DECIMAL,
189
- PM_ERR_INVALID_NUMBER_FRACTION,
190
- PM_ERR_INVALID_NUMBER_HEXADECIMAL,
191
- PM_ERR_INVALID_NUMBER_OCTAL,
192
- PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER,
193
- PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING,
194
- PM_ERR_INVALID_PERCENT,
195
- PM_ERR_INVALID_PERCENT_EOF,
196
- PM_ERR_INVALID_PRINTABLE_CHARACTER,
197
- PM_ERR_INVALID_RETRY_AFTER_ELSE,
198
- PM_ERR_INVALID_RETRY_AFTER_ENSURE,
199
- PM_ERR_INVALID_RETRY_WITHOUT_RESCUE,
200
- PM_ERR_INVALID_SYMBOL,
201
- PM_ERR_INVALID_VARIABLE_GLOBAL,
202
- PM_ERR_INVALID_VARIABLE_GLOBAL_3_3,
203
- PM_ERR_INVALID_YIELD,
204
- PM_ERR_IT_NOT_ALLOWED_NUMBERED,
205
- PM_ERR_IT_NOT_ALLOWED_ORDINARY,
206
- PM_ERR_LAMBDA_OPEN,
207
- PM_ERR_LAMBDA_TERM_BRACE,
208
- PM_ERR_LAMBDA_TERM_END,
209
- PM_ERR_LIST_I_LOWER_ELEMENT,
210
- PM_ERR_LIST_I_LOWER_TERM,
211
- PM_ERR_LIST_I_UPPER_ELEMENT,
212
- PM_ERR_LIST_I_UPPER_TERM,
213
- PM_ERR_LIST_W_LOWER_ELEMENT,
214
- PM_ERR_LIST_W_LOWER_TERM,
215
- PM_ERR_LIST_W_UPPER_ELEMENT,
216
- PM_ERR_LIST_W_UPPER_TERM,
217
- PM_ERR_MALLOC_FAILED,
218
- PM_ERR_MIXED_ENCODING,
219
- PM_ERR_MODULE_IN_METHOD,
220
- PM_ERR_MODULE_NAME,
221
- PM_ERR_MODULE_TERM,
222
- PM_ERR_MULTI_ASSIGN_MULTI_SPLATS,
223
- PM_ERR_MULTI_ASSIGN_UNEXPECTED_REST,
224
- PM_ERR_NESTING_TOO_DEEP,
225
- PM_ERR_NO_LOCAL_VARIABLE,
226
- PM_ERR_NON_ASSOCIATIVE_OPERATOR,
227
- PM_ERR_NOT_EXPRESSION,
228
- PM_ERR_NUMBER_LITERAL_UNDERSCORE,
229
- PM_ERR_NUMBERED_PARAMETER_INNER_BLOCK,
230
- PM_ERR_NUMBERED_PARAMETER_IT,
231
- PM_ERR_NUMBERED_PARAMETER_ORDINARY,
232
- PM_ERR_NUMBERED_PARAMETER_OUTER_BLOCK,
233
- PM_ERR_OPERATOR_MULTI_ASSIGN,
234
- PM_ERR_OPERATOR_WRITE_ARGUMENTS,
235
- PM_ERR_OPERATOR_WRITE_BLOCK,
236
- PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
237
- PM_ERR_PARAMETER_BLOCK_MULTI,
238
- PM_ERR_PARAMETER_CIRCULAR,
239
- PM_ERR_PARAMETER_FORWARDING_AFTER_REST,
240
- PM_ERR_PARAMETER_METHOD_NAME,
241
- PM_ERR_PARAMETER_NAME_DUPLICATED,
242
- PM_ERR_PARAMETER_NO_DEFAULT,
243
- PM_ERR_PARAMETER_NO_DEFAULT_KW,
244
- PM_ERR_PARAMETER_NUMBERED_RESERVED,
245
- PM_ERR_PARAMETER_ORDER,
246
- PM_ERR_PARAMETER_SPLAT_MULTI,
247
- PM_ERR_PARAMETER_STAR,
248
- PM_ERR_PARAMETER_UNEXPECTED_FWD,
249
- PM_ERR_PARAMETER_UNEXPECTED_NO_KW,
250
- PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
251
- PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS,
252
- PM_ERR_PATTERN_CAPTURE_DUPLICATE,
253
- PM_ERR_PATTERN_CAPTURE_IN_ALTERNATIVE,
254
- PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
255
- PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
256
- PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
257
- PM_ERR_PATTERN_EXPRESSION_AFTER_IN,
258
- PM_ERR_PATTERN_EXPRESSION_AFTER_KEY,
259
- PM_ERR_PATTERN_EXPRESSION_AFTER_PAREN,
260
- PM_ERR_PATTERN_EXPRESSION_AFTER_PIN,
261
- PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
262
- PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
263
- PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
264
- PM_ERR_PATTERN_FIND_MISSING_INNER,
265
- PM_ERR_PATTERN_HASH_IMPLICIT,
266
- PM_ERR_PATTERN_HASH_KEY,
267
- PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
268
- PM_ERR_PATTERN_HASH_KEY_INTERPOLATED,
269
- PM_ERR_PATTERN_HASH_KEY_LABEL,
270
- PM_ERR_PATTERN_HASH_KEY_LOCALS,
271
- PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
272
- PM_ERR_PATTERN_LABEL_AFTER_COMMA,
273
- PM_ERR_PATTERN_REST,
274
- PM_ERR_PATTERN_TERM_BRACE,
275
- PM_ERR_PATTERN_TERM_BRACKET,
276
- PM_ERR_PATTERN_TERM_PAREN,
277
- PM_ERR_PIPEPIPEEQ_MULTI_ASSIGN,
278
- PM_ERR_REGEXP_ENCODING_OPTION_MISMATCH,
279
- PM_ERR_REGEXP_INCOMPAT_CHAR_ENCODING,
280
- PM_ERR_REGEXP_INVALID_UNICODE_RANGE,
281
- PM_ERR_REGEXP_NON_ESCAPED_MBC,
282
- PM_ERR_REGEXP_PARSE_ERROR,
283
- PM_ERR_REGEXP_TERM,
284
- PM_ERR_REGEXP_UNKNOWN_OPTIONS,
285
- PM_ERR_REGEXP_UTF8_CHAR_NON_UTF8_REGEXP,
286
- PM_ERR_RESCUE_EXPRESSION,
287
- PM_ERR_RESCUE_MODIFIER_VALUE,
288
- PM_ERR_RESCUE_TERM,
289
- PM_ERR_RESCUE_VARIABLE,
290
- PM_ERR_RETURN_INVALID,
291
- PM_ERR_SCRIPT_NOT_FOUND,
292
- PM_ERR_SINGLETON_FOR_LITERALS,
293
- PM_ERR_STATEMENT_ALIAS,
294
- PM_ERR_STATEMENT_POSTEXE_END,
295
- PM_ERR_STATEMENT_PREEXE_BEGIN,
296
- PM_ERR_STATEMENT_UNDEF,
297
- PM_ERR_STRING_CONCATENATION,
298
- PM_ERR_STRING_INTERPOLATED_TERM,
299
- PM_ERR_STRING_LITERAL_EOF,
300
- PM_ERR_STRING_LITERAL_TERM,
301
- PM_ERR_SYMBOL_INVALID,
302
- PM_ERR_SYMBOL_TERM_DYNAMIC,
303
- PM_ERR_SYMBOL_TERM_INTERPOLATED,
304
- PM_ERR_TERNARY_COLON,
305
- PM_ERR_TERNARY_EXPRESSION_FALSE,
306
- PM_ERR_TERNARY_EXPRESSION_TRUE,
307
- PM_ERR_UNARY_DISALLOWED,
308
- PM_ERR_UNARY_RECEIVER,
309
- PM_ERR_UNDEF_ARGUMENT,
310
- PM_ERR_UNEXPECTED_BLOCK_ARGUMENT,
311
- PM_ERR_UNEXPECTED_INDEX_BLOCK,
312
- PM_ERR_UNEXPECTED_INDEX_KEYWORDS,
313
- PM_ERR_UNEXPECTED_LABEL,
314
- PM_ERR_UNEXPECTED_MULTI_WRITE,
315
- PM_ERR_UNEXPECTED_PARAMETER_DEFAULT_VALUE,
316
- PM_ERR_UNEXPECTED_RANGE_OPERATOR,
317
- PM_ERR_UNEXPECTED_SAFE_NAVIGATION,
318
- PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT,
319
- PM_ERR_UNEXPECTED_TOKEN_IGNORE,
320
- PM_ERR_UNTIL_TERM,
321
- PM_ERR_VOID_EXPRESSION,
322
- PM_ERR_WHILE_TERM,
323
- PM_ERR_WRITE_TARGET_IN_METHOD,
324
- PM_ERR_WRITE_TARGET_READONLY,
325
- PM_ERR_WRITE_TARGET_UNEXPECTED,
326
- PM_ERR_XSTRING_TERM,
327
-
328
- // These are the warning diagnostics.
329
- PM_WARN_AMBIGUOUS_BINARY_OPERATOR,
330
- PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
331
- PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
332
- PM_WARN_AMBIGUOUS_PREFIX_AMPERSAND,
333
- PM_WARN_AMBIGUOUS_PREFIX_STAR,
334
- PM_WARN_AMBIGUOUS_PREFIX_STAR_STAR,
335
- PM_WARN_AMBIGUOUS_SLASH,
336
- PM_WARN_COMPARISON_AFTER_COMPARISON,
337
- PM_WARN_DOT_DOT_DOT_EOL,
338
- PM_WARN_EQUAL_IN_CONDITIONAL,
339
- PM_WARN_EQUAL_IN_CONDITIONAL_3_3,
340
- PM_WARN_END_IN_METHOD,
341
- PM_WARN_DUPLICATED_HASH_KEY,
342
- PM_WARN_DUPLICATED_WHEN_CLAUSE,
343
- PM_WARN_FLOAT_OUT_OF_RANGE,
344
- PM_WARN_IGNORED_FROZEN_STRING_LITERAL,
345
- PM_WARN_INDENTATION_MISMATCH,
346
- PM_WARN_INTEGER_IN_FLIP_FLOP,
347
- PM_WARN_INVALID_CHARACTER,
348
- PM_WARN_INVALID_MAGIC_COMMENT_VALUE,
349
- PM_WARN_INVALID_NUMBERED_REFERENCE,
350
- PM_WARN_KEYWORD_EOL,
351
- PM_WARN_LITERAL_IN_CONDITION_DEFAULT,
352
- PM_WARN_LITERAL_IN_CONDITION_VERBOSE,
353
- PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE,
354
- PM_WARN_SHEBANG_CARRIAGE_RETURN,
355
- PM_WARN_UNEXPECTED_CARRIAGE_RETURN,
356
- PM_WARN_UNREACHABLE_STATEMENT,
357
- PM_WARN_UNUSED_LOCAL_VARIABLE,
358
- PM_WARN_VOID_STATEMENT,
359
- } pm_diagnostic_id_t;
360
-
361
- /**
362
- * This struct represents a diagnostic generated during parsing.
363
- *
364
- * @extends pm_list_node_t
365
- */
366
- typedef struct {
367
- /** The embedded base node. */
368
- pm_list_node_t node;
369
-
370
- /** The location of the diagnostic in the source. */
371
- pm_location_t location;
372
-
373
- /** The ID of the diagnostic. */
374
- pm_diagnostic_id_t diag_id;
375
-
376
- /** The message associated with the diagnostic. */
377
- const char *message;
378
-
379
- /**
380
- * Whether or not the memory related to the message of this diagnostic is
381
- * owned by this diagnostic. If it is, it needs to be freed when the
382
- * diagnostic is freed.
383
- */
384
- bool owned;
385
-
386
- /**
387
- * The level of the diagnostic, see `pm_error_level_t` and
388
- * `pm_warning_level_t` for possible values.
389
- */
390
- uint8_t level;
391
- } pm_diagnostic_t;
22
+ typedef struct pm_diagnostic_t pm_diagnostic_t;
392
23
 
393
24
  /**
394
25
  * The levels of errors generated during parsing.
@@ -416,43 +47,65 @@ typedef enum {
416
47
  } pm_warning_level_t;
417
48
 
418
49
  /**
419
- * Get the human-readable name of the given diagnostic ID.
50
+ * Get the type of the given diagnostic.
51
+ *
52
+ * @param diagnostic The diagnostic to get the type of.
53
+ * @returns The type of the given diagnostic. Note that this is a string
54
+ * representation of an internal ID, and is not meant to be relied upon as a
55
+ * stable identifier for the diagnostic. We do not guarantee that these will
56
+ * not change in the future. This is meant to be used for debugging and
57
+ * error reporting purposes, and not for programmatic checks.
58
+ */
59
+ PRISM_EXPORTED_FUNCTION const char * pm_diagnostic_type(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
60
+
61
+ /**
62
+ * Get the location of the given diagnostic.
420
63
  *
421
- * @param diag_id The diagnostic ID.
422
- * @return The human-readable name of the diagnostic ID.
64
+ * @param diagnostic The diagnostic to get the location of.
65
+ * @returns The location of the given diagnostic.
423
66
  */
424
- const char * pm_diagnostic_id_human(pm_diagnostic_id_t diag_id);
67
+ PRISM_EXPORTED_FUNCTION pm_location_t pm_diagnostic_location(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
425
68
 
426
69
  /**
427
- * Append a diagnostic to the given list of diagnostics that is using shared
428
- * memory for its message.
70
+ * Get the message of the given diagnostic.
429
71
  *
430
- * @param list The list to append to.
431
- * @param start The start of the diagnostic.
432
- * @param end The end of the diagnostic.
433
- * @param diag_id The diagnostic ID.
434
- * @return Whether the diagnostic was successfully appended.
72
+ * @param diagnostic The diagnostic to get the message of.
73
+ * @returns The message of the given diagnostic.
435
74
  */
436
- bool pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id);
75
+ PRISM_EXPORTED_FUNCTION const char * pm_diagnostic_message(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
437
76
 
438
77
  /**
439
- * Append a diagnostic to the given list of diagnostics that is using a format
440
- * string for its message.
78
+ * Get the error level associated with the given diagnostic.
441
79
  *
442
- * @param list The list to append to.
443
- * @param start The start of the diagnostic.
444
- * @param end The end of the diagnostic.
445
- * @param diag_id The diagnostic ID.
446
- * @param ... The arguments to the format string for the message.
447
- * @return Whether the diagnostic was successfully appended.
80
+ * @param diagnostic The diagnostic to get the error level of.
81
+ * @returns The error level of the given diagnostic. If the diagnostic was a
82
+ * warning, or is in any way not an error, then the return value is
83
+ * undefined and should not be relied upon.
448
84
  */
449
- bool pm_diagnostic_list_append_format(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id, ...);
85
+ PRISM_EXPORTED_FUNCTION pm_error_level_t pm_diagnostic_error_level(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
450
86
 
451
87
  /**
452
- * Deallocate the internal state of the given diagnostic list.
88
+ * Get the warning level associated with the given diagnostic.
453
89
  *
454
- * @param list The list to deallocate.
90
+ * @param diagnostic The diagnostic to get the warning level of.
91
+ * @returns The warning level of the given diagnostic. If the diagnostic was an
92
+ * error, or is in any way not a warning, then the return value is
93
+ * undefined and should not be relied upon.
455
94
  */
456
- void pm_diagnostic_list_free(pm_list_t *list);
95
+ PRISM_EXPORTED_FUNCTION pm_warning_level_t pm_diagnostic_warning_level(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
96
+
97
+ /**
98
+ * Get the diagnostic that follows the given diagnostic among the errors or the
99
+ * warnings of the parser that produced it.
100
+ *
101
+ * @param diagnostic The diagnostic to get the successor of.
102
+ * @returns The next diagnostic of the same kind, or NULL if the given
103
+ * diagnostic is the last one.
104
+ */
105
+ PRISM_EXPORTED_FUNCTION const pm_diagnostic_t * pm_diagnostic_next(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
106
+
107
+ #ifdef __cplusplus
108
+ }
109
+ #endif
457
110
 
458
111
  #endif
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @file errors_format.h
3
+ *
4
+ * A function for formatting the errors in a parser into a buffer.
5
+ */
6
+ #ifndef PRISM_ERRORS_FORMAT_H
7
+ #define PRISM_ERRORS_FORMAT_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include "prism/buffer.h"
14
+ #include "prism/diagnostic.h"
15
+ #include "prism/parser.h"
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ /** The type of formatting to use when formatting errors. */
22
+ typedef enum {
23
+ /** Format errors in a plain format with no colors or styles. Typically
24
+ * used when outputting to a file or when the output is not a terminal.
25
+ */
26
+ PM_ERRORS_FORMAT_PLAIN = 1,
27
+
28
+ /** Format errors in a style format with bold only. Typically used when
29
+ * outputting to a terminal where you do not want colors.
30
+ */
31
+ PM_ERRORS_FORMAT_STYLE = 2,
32
+
33
+ /** Format errors in a color format with bold and colors. The default case
34
+ * when outputting on the terminal.
35
+ */
36
+ PM_ERRORS_FORMAT_COLOR = 3
37
+ } pm_errors_format_type_t;
38
+
39
+ /**
40
+ * Format the errors in a parser into a buffer. After return, the buffer will
41
+ * contain the formatted errors and any relevant source snippets if available
42
+ * and possible.
43
+ *
44
+ * @param parser The parser containing the errors to format. Note that the
45
+ * parser does not need to be fully initialized, but it will need to have
46
+ * start, end, start_line, encoding, line_offsets, filepath, and error_list
47
+ * initialized.
48
+ * @param buffer The buffer to format the errors into.
49
+ * @param format_type The type of formatting to use when formatting the errors.
50
+ * @returns The error level of the error with the highest precedence that was
51
+ * formatted. In practice this means it will be the argument or load error
52
+ * level if any were found, otherwise it will be the syntax error level.
53
+ * Callers should raise appropriate error types based on the returned level.
54
+ */
55
+ PRISM_EXPORTED_FUNCTION pm_error_level_t pm_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type) PRISM_NONNULL(1, 2);
56
+
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
61
+ #endif
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @file excludes.h
3
+ *
4
+ * A header file that defines macros to exclude certain features of the prism
5
+ * library. This is useful for reducing the size of the library when certain
6
+ * features are not needed.
7
+ */
8
+ #ifndef PRISM_EXCLUDES_H
9
+ #define PRISM_EXCLUDES_H
10
+
11
+ /**
12
+ * If PRISM_BUILD_MINIMAL is defined, then we're going to define every possible
13
+ * switch that will turn off certain features of prism.
14
+ */
15
+ #ifdef PRISM_BUILD_MINIMAL
16
+ /** Exclude the serialization API. */
17
+ #define PRISM_EXCLUDE_SERIALIZATION
18
+
19
+ /** Exclude the JSON serialization API. */
20
+ #define PRISM_EXCLUDE_JSON
21
+
22
+ /** Exclude the prettyprint API. */
23
+ #define PRISM_EXCLUDE_PRETTYPRINT
24
+
25
+ /** Exclude the full set of encodings, using the minimal only. */
26
+ #define PRISM_ENCODING_EXCLUDE_FULL
27
+ #endif
28
+
29
+ #endif