Ruby: prism/diagnostic.h Source File

Ruby 3.3.7p123 (2025-01-15 revision be31f993d7fa0219d85f7b3c694d454da4ecc10b)

diagnostic.h
Go to the documentation of this file.
1
6#ifndef PRISM_DIAGNOSTIC_H
7#define PRISM_DIAGNOSTIC_H
8
9#include "prism/ast.h"
10#include "prism/defines.h"
11#include "prism/util/pm_list.h"
12
13#include <stdbool.h>
14#include <stdlib.h>
15#include <assert.h>
16
22 typedef struct {
24 pm_list_node_t node;
25
27 pm_location_t location;
28
30 const char *message;
31
37 bool owned;
38} pm_diagnostic_t;
39
44 typedef enum {
45 PM_ERR_ALIAS_ARGUMENT,
46 PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
47 PM_ERR_ARGUMENT_AFTER_BLOCK,
48 PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
49 PM_ERR_ARGUMENT_BARE_HASH,
50 PM_ERR_ARGUMENT_BLOCK_MULTI,
51 PM_ERR_ARGUMENT_FORMAL_CLASS,
52 PM_ERR_ARGUMENT_FORMAL_CONSTANT,
53 PM_ERR_ARGUMENT_FORMAL_GLOBAL,
54 PM_ERR_ARGUMENT_FORMAL_IVAR,
55 PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
56 PM_ERR_ARGUMENT_NO_FORWARDING_AMP,
57 PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
58 PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
59 PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT,
60 PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT,
61 PM_ERR_ARGUMENT_TERM_PAREN,
62 PM_ERR_ARGUMENT_UNEXPECTED_BLOCK,
63 PM_ERR_ARRAY_ELEMENT,
64 PM_ERR_ARRAY_EXPRESSION,
65 PM_ERR_ARRAY_EXPRESSION_AFTER_STAR,
66 PM_ERR_ARRAY_SEPARATOR,
67 PM_ERR_ARRAY_TERM,
68 PM_ERR_BEGIN_LONELY_ELSE,
69 PM_ERR_BEGIN_TERM,
70 PM_ERR_BEGIN_UPCASE_BRACE,
71 PM_ERR_BEGIN_UPCASE_TERM,
72 PM_ERR_BEGIN_UPCASE_TOPLEVEL,
73 PM_ERR_BLOCK_PARAM_LOCAL_VARIABLE,
74 PM_ERR_BLOCK_PARAM_PIPE_TERM,
75 PM_ERR_BLOCK_TERM_BRACE,
76 PM_ERR_BLOCK_TERM_END,
77 PM_ERR_CANNOT_PARSE_EXPRESSION,
78 PM_ERR_CANNOT_PARSE_STRING_PART,
79 PM_ERR_CASE_EXPRESSION_AFTER_CASE,
80 PM_ERR_CASE_EXPRESSION_AFTER_WHEN,
81 PM_ERR_CASE_MATCH_MISSING_PREDICATE,
82 PM_ERR_CASE_MISSING_CONDITIONS,
83 PM_ERR_CASE_TERM,
84 PM_ERR_CLASS_IN_METHOD,
85 PM_ERR_CLASS_NAME,
86 PM_ERR_CLASS_SUPERCLASS,
87 PM_ERR_CLASS_TERM,
88 PM_ERR_CLASS_UNEXPECTED_END,
89 PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
90 PM_ERR_CONDITIONAL_IF_PREDICATE,
91 PM_ERR_CONDITIONAL_PREDICATE_TERM,
92 PM_ERR_CONDITIONAL_TERM,
93 PM_ERR_CONDITIONAL_TERM_ELSE,
94 PM_ERR_CONDITIONAL_UNLESS_PREDICATE,
95 PM_ERR_CONDITIONAL_UNTIL_PREDICATE,
96 PM_ERR_CONDITIONAL_WHILE_PREDICATE,
97 PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT,
98 PM_ERR_DEF_ENDLESS,
99 PM_ERR_DEF_ENDLESS_SETTER,
100 PM_ERR_DEF_NAME,
101 PM_ERR_DEF_NAME_AFTER_RECEIVER,
102 PM_ERR_DEF_PARAMS_TERM,
103 PM_ERR_DEF_PARAMS_TERM_PAREN,
104 PM_ERR_DEF_RECEIVER,
105 PM_ERR_DEF_RECEIVER_TERM,
106 PM_ERR_DEF_TERM,
107 PM_ERR_DEFINED_EXPRESSION,
108 PM_ERR_EMBDOC_TERM,
109 PM_ERR_EMBEXPR_END,
110 PM_ERR_EMBVAR_INVALID,
111 PM_ERR_END_UPCASE_BRACE,
112 PM_ERR_END_UPCASE_TERM,
113 PM_ERR_ESCAPE_INVALID_CONTROL,
114 PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT,
115 PM_ERR_ESCAPE_INVALID_HEXADECIMAL,
116 PM_ERR_ESCAPE_INVALID_META,
117 PM_ERR_ESCAPE_INVALID_META_REPEAT,
118 PM_ERR_ESCAPE_INVALID_UNICODE,
119 PM_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS,
120 PM_ERR_ESCAPE_INVALID_UNICODE_LITERAL,
121 PM_ERR_ESCAPE_INVALID_UNICODE_LONG,
122 PM_ERR_ESCAPE_INVALID_UNICODE_TERM,
123 PM_ERR_EXPECT_ARGUMENT,
124 PM_ERR_EXPECT_EOL_AFTER_STATEMENT,
125 PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ,
126 PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
127 PM_ERR_EXPECT_EXPRESSION_AFTER_COMMA,
128 PM_ERR_EXPECT_EXPRESSION_AFTER_EQUAL,
129 PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS,
130 PM_ERR_EXPECT_EXPRESSION_AFTER_LPAREN,
131 PM_ERR_EXPECT_EXPRESSION_AFTER_QUESTION,
132 PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR,
133 PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT,
134 PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
135 PM_ERR_EXPECT_EXPRESSION_AFTER_STAR,
136 PM_ERR_EXPECT_IDENT_REQ_PARAMETER,
137 PM_ERR_EXPECT_LPAREN_REQ_PARAMETER,
138 PM_ERR_EXPECT_RBRACKET,
139 PM_ERR_EXPECT_RPAREN,
140 PM_ERR_EXPECT_RPAREN_AFTER_MULTI,
141 PM_ERR_EXPECT_RPAREN_REQ_PARAMETER,
142 PM_ERR_EXPECT_STRING_CONTENT,
143 PM_ERR_EXPECT_WHEN_DELIMITER,
144 PM_ERR_EXPRESSION_BARE_HASH,
145 PM_ERR_FOR_COLLECTION,
146 PM_ERR_FOR_IN,
147 PM_ERR_FOR_INDEX,
148 PM_ERR_FOR_TERM,
149 PM_ERR_HASH_EXPRESSION_AFTER_LABEL,
150 PM_ERR_HASH_KEY,
151 PM_ERR_HASH_ROCKET,
152 PM_ERR_HASH_TERM,
153 PM_ERR_HASH_VALUE,
154 PM_ERR_HEREDOC_TERM,
155 PM_ERR_INCOMPLETE_QUESTION_MARK,
156 PM_ERR_INCOMPLETE_VARIABLE_CLASS,
157 PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
158 PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
159 PM_ERR_INVALID_FLOAT_EXPONENT,
160 PM_ERR_INVALID_NUMBER_BINARY,
161 PM_ERR_INVALID_NUMBER_DECIMAL,
162 PM_ERR_INVALID_NUMBER_HEXADECIMAL,
163 PM_ERR_INVALID_NUMBER_OCTAL,
164 PM_ERR_INVALID_NUMBER_UNDERSCORE,
165 PM_ERR_INVALID_PERCENT,
166 PM_ERR_INVALID_TOKEN,
167 PM_ERR_INVALID_VARIABLE_GLOBAL,
168 PM_ERR_LAMBDA_OPEN,
169 PM_ERR_LAMBDA_TERM_BRACE,
170 PM_ERR_LAMBDA_TERM_END,
171 PM_ERR_LIST_I_LOWER_ELEMENT,
172 PM_ERR_LIST_I_LOWER_TERM,
173 PM_ERR_LIST_I_UPPER_ELEMENT,
174 PM_ERR_LIST_I_UPPER_TERM,
175 PM_ERR_LIST_W_LOWER_ELEMENT,
176 PM_ERR_LIST_W_LOWER_TERM,
177 PM_ERR_LIST_W_UPPER_ELEMENT,
178 PM_ERR_LIST_W_UPPER_TERM,
179 PM_ERR_MALLOC_FAILED,
180 PM_ERR_MIXED_ENCODING,
181 PM_ERR_MODULE_IN_METHOD,
182 PM_ERR_MODULE_NAME,
183 PM_ERR_MODULE_TERM,
184 PM_ERR_MULTI_ASSIGN_MULTI_SPLATS,
185 PM_ERR_NOT_EXPRESSION,
186 PM_ERR_NUMBER_LITERAL_UNDERSCORE,
187 PM_ERR_NUMBERED_PARAMETER_NOT_ALLOWED,
188 PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE,
189 PM_ERR_OPERATOR_MULTI_ASSIGN,
190 PM_ERR_OPERATOR_WRITE_ARGUMENTS,
191 PM_ERR_OPERATOR_WRITE_BLOCK,
192 PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
193 PM_ERR_PARAMETER_BLOCK_MULTI,
194 PM_ERR_PARAMETER_CIRCULAR,
195 PM_ERR_PARAMETER_METHOD_NAME,
196 PM_ERR_PARAMETER_NAME_REPEAT,
197 PM_ERR_PARAMETER_NO_DEFAULT,
198 PM_ERR_PARAMETER_NO_DEFAULT_KW,
199 PM_ERR_PARAMETER_NUMBERED_RESERVED,
200 PM_ERR_PARAMETER_ORDER,
201 PM_ERR_PARAMETER_SPLAT_MULTI,
202 PM_ERR_PARAMETER_STAR,
203 PM_ERR_PARAMETER_UNEXPECTED_FWD,
204 PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
205 PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
206 PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
207 PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
208 PM_ERR_PATTERN_EXPRESSION_AFTER_IN,
209 PM_ERR_PATTERN_EXPRESSION_AFTER_KEY,
210 PM_ERR_PATTERN_EXPRESSION_AFTER_PAREN,
211 PM_ERR_PATTERN_EXPRESSION_AFTER_PIN,
212 PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
213 PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
214 PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
215 PM_ERR_PATTERN_HASH_KEY,
216 PM_ERR_PATTERN_HASH_KEY_LABEL,
217 PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
218 PM_ERR_PATTERN_LABEL_AFTER_COMMA,
219 PM_ERR_PATTERN_REST,
220 PM_ERR_PATTERN_TERM_BRACE,
221 PM_ERR_PATTERN_TERM_BRACKET,
222 PM_ERR_PATTERN_TERM_PAREN,
223 PM_ERR_PIPEPIPEEQ_MULTI_ASSIGN,
224 PM_ERR_REGEXP_TERM,
225 PM_ERR_RESCUE_EXPRESSION,
226 PM_ERR_RESCUE_MODIFIER_VALUE,
227 PM_ERR_RESCUE_TERM,
228 PM_ERR_RESCUE_VARIABLE,
229 PM_ERR_RETURN_INVALID,
230 PM_ERR_STATEMENT_ALIAS,
231 PM_ERR_STATEMENT_POSTEXE_END,
232 PM_ERR_STATEMENT_PREEXE_BEGIN,
233 PM_ERR_STATEMENT_UNDEF,
234 PM_ERR_STRING_CONCATENATION,
235 PM_ERR_STRING_INTERPOLATED_TERM,
236 PM_ERR_STRING_LITERAL_TERM,
237 PM_ERR_SYMBOL_INVALID,
238 PM_ERR_SYMBOL_TERM_DYNAMIC,
239 PM_ERR_SYMBOL_TERM_INTERPOLATED,
240 PM_ERR_TERNARY_COLON,
241 PM_ERR_TERNARY_EXPRESSION_FALSE,
242 PM_ERR_TERNARY_EXPRESSION_TRUE,
243 PM_ERR_UNARY_RECEIVER_BANG,
244 PM_ERR_UNARY_RECEIVER_MINUS,
245 PM_ERR_UNARY_RECEIVER_PLUS,
246 PM_ERR_UNARY_RECEIVER_TILDE,
247 PM_ERR_UNDEF_ARGUMENT,
248 PM_ERR_UNTIL_TERM,
249 PM_ERR_VOID_EXPRESSION,
250 PM_ERR_WHILE_TERM,
251 PM_ERR_WRITE_TARGET_IN_METHOD,
252 PM_ERR_WRITE_TARGET_READONLY,
253 PM_ERR_WRITE_TARGET_UNEXPECTED,
254 PM_ERR_XSTRING_TERM,
255 PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
256 PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
257 PM_WARN_AMBIGUOUS_PREFIX_STAR,
258 PM_WARN_AMBIGUOUS_SLASH,
259 PM_WARN_END_IN_METHOD,
260
261 /* This must be the last member. */
262 PM_DIAGNOSTIC_ID_LEN,
263} pm_diagnostic_id_t;
264
275bool pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id);
276
288bool pm_diagnostic_list_append_format(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id, ...);
289
295void pm_diagnostic_list_free(pm_list_t *list);
296
297#endif
assert.h
ast.h
The abstract syntax tree.
pm_diagnostic_list_free
void pm_diagnostic_list_free(pm_list_t *list)
Deallocate the internal state of the given diagnostic list.
Definition diagnostic.c:345
pm_diagnostic_list_append_format
bool pm_diagnostic_list_append_format(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id,...)
Append a diagnostic to the given list of diagnostics that is using a format string for its message.
Definition diagnostic.c:303
pm_diagnostic_id_t
pm_diagnostic_id_t
The diagnostic IDs of all of the diagnostics, used to communicate the types of errors between the par...
Definition diagnostic.h:44
pm_diagnostic_list_append
bool pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id)
Append a diagnostic to the given list of diagnostics that is using shared memory for its message.
Definition diagnostic.c:284
pm_list.h
An abstract linked list.
pm_list_node_t
struct pm_list_node pm_list_node_t
This struct represents an abstract linked list that provides common functionality.
defines.h
Macro definitions used throughout the prism library.
stdbool.h
C99 shim for <stdbool.h>
pm_diagnostic_t
This struct represents a diagnostic generated during parsing.
Definition diagnostic.h:22
pm_diagnostic_t::location
pm_location_t location
The location of the diagnostic in the source.
Definition diagnostic.h:27
pm_diagnostic_t::message
const char * message
The message associated with the diagnostic.
Definition diagnostic.h:30
pm_diagnostic_t::node
pm_list_node_t node
The embedded base node.
Definition diagnostic.h:24
pm_diagnostic_t::owned
bool owned
Whether or not the memory related to the message of this diagnostic is owned by this diagnostic.
Definition diagnostic.h:37
pm_list_t
This represents the overall linked list.
Definition pm_list.h:55
pm_location_t
This represents a range of bytes in the source string to which a node or token corresponds.
Definition ast.h:543