Skip to content

Commit 7932e62

Browse files
committed
1 parent b3d5b54 commit 7932e62

File tree

15 files changed

+829
-502
lines changed

15 files changed

+829
-502
lines changed

src/main/c/yarp/include/prism.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <assert.h>
2828
#include <errno.h>
29+
#include <locale.h>
2930
#include <math.h>
3031
#include <stdarg.h>
3132
#include <stdbool.h>
@@ -222,10 +223,12 @@ const char * pm_token_type_human(pm_token_type_t token_type);
222223
* Format the errors on the parser into the given buffer.
223224
*
224225
* @param parser The parser to format the errors for.
226+
* @param error_list The list of errors to format.
225227
* @param buffer The buffer to format the errors into.
226228
* @param colorize Whether or not to colorize the errors with ANSI escape sequences.
229+
* @param inline_messages Whether or not to inline the messages with the source.
227230
*/
228-
PRISM_EXPORTED_FUNCTION void pm_parser_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, bool colorize);
231+
PRISM_EXPORTED_FUNCTION void pm_parser_errors_format(const pm_parser_t *parser, const pm_list_t *error_list, pm_buffer_t *buffer, bool colorize, bool inline_messages);
229232

230233
// We optionally support dumping to JSON. For systems that don't want or need
231234
// this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.

src/main/c/yarp/include/prism/ast.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5823,10 +5823,10 @@ typedef enum pm_integer_base_flags {
58235823
* Flags for interpolated string nodes that indicated mutability if they are also marked as literals.
58245824
*/
58255825
typedef enum pm_interpolated_string_node_flags {
5826-
/** frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal` */
5826+
/** frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` */
58275827
PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN = 1,
58285828

5829-
/** mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal` */
5829+
/** mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` */
58305830
PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE = 2,
58315831
} pm_interpolated_string_node_flags_t;
58325832

src/main/c/yarp/include/prism/diagnostic.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
typedef enum {
3030
// These are the error diagnostics.
3131
PM_ERR_ALIAS_ARGUMENT,
32+
PM_ERR_ALIAS_ARGUMENT_NUMBERED_REFERENCE,
3233
PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
3334
PM_ERR_ARGUMENT_AFTER_BLOCK,
3435
PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
@@ -75,6 +76,7 @@ typedef enum {
7576
PM_ERR_CLASS_SUPERCLASS,
7677
PM_ERR_CLASS_TERM,
7778
PM_ERR_CLASS_UNEXPECTED_END,
79+
PM_ERR_CLASS_VARIABLE_BARE,
7880
PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
7981
PM_ERR_CONDITIONAL_IF_PREDICATE,
8082
PM_ERR_CONDITIONAL_PREDICATE_TERM,
@@ -136,6 +138,7 @@ typedef enum {
136138
PM_ERR_FOR_IN,
137139
PM_ERR_FOR_INDEX,
138140
PM_ERR_FOR_TERM,
141+
PM_ERR_GLOBAL_VARIABLE_BARE,
139142
PM_ERR_HASH_EXPRESSION_AFTER_LABEL,
140143
PM_ERR_HASH_KEY,
141144
PM_ERR_HASH_ROCKET,
@@ -147,6 +150,7 @@ typedef enum {
147150
PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3_0,
148151
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
149152
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3_0,
153+
PM_ERR_INSTANCE_VARIABLE_BARE,
150154
PM_ERR_INVALID_CHARACTER,
151155
PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
152156
PM_ERR_INVALID_FLOAT_EXPONENT,
@@ -195,7 +199,7 @@ typedef enum {
195199
PM_ERR_PARAMETER_BLOCK_MULTI,
196200
PM_ERR_PARAMETER_CIRCULAR,
197201
PM_ERR_PARAMETER_METHOD_NAME,
198-
PM_ERR_PARAMETER_NAME_REPEAT,
202+
PM_ERR_PARAMETER_NAME_DUPLICATED,
199203
PM_ERR_PARAMETER_NO_DEFAULT,
200204
PM_ERR_PARAMETER_NO_DEFAULT_KW,
201205
PM_ERR_PARAMETER_NUMBERED_RESERVED,
@@ -204,6 +208,7 @@ typedef enum {
204208
PM_ERR_PARAMETER_STAR,
205209
PM_ERR_PARAMETER_UNEXPECTED_FWD,
206210
PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
211+
PM_ERR_PATTERN_CAPTURE_DUPLICATE,
207212
PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
208213
PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
209214
PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
@@ -215,6 +220,7 @@ typedef enum {
215220
PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
216221
PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
217222
PM_ERR_PATTERN_HASH_KEY,
223+
PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
218224
PM_ERR_PATTERN_HASH_KEY_LABEL,
219225
PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
220226
PM_ERR_PATTERN_LABEL_AFTER_COMMA,
@@ -235,6 +241,7 @@ typedef enum {
235241
PM_ERR_RESCUE_TERM,
236242
PM_ERR_RESCUE_VARIABLE,
237243
PM_ERR_RETURN_INVALID,
244+
PM_ERR_SCRIPT_NOT_FOUND,
238245
PM_ERR_SINGLETON_FOR_LITERALS,
239246
PM_ERR_STATEMENT_ALIAS,
240247
PM_ERR_STATEMENT_POSTEXE_END,
@@ -285,6 +292,7 @@ typedef enum {
285292
PM_WARN_KEYWORD_EOL,
286293
PM_WARN_LITERAL_IN_CONDITION_DEFAULT,
287294
PM_WARN_LITERAL_IN_CONDITION_VERBOSE,
295+
PM_WARN_SHEBANG_CARRIAGE_RETURN,
288296
PM_WARN_UNEXPECTED_CARRIAGE_RETURN,
289297
} pm_diagnostic_id_t;
290298

@@ -324,11 +332,14 @@ typedef struct {
324332
* The levels of errors generated during parsing.
325333
*/
326334
typedef enum {
327-
/** For errors that cannot be recovered from. */
328-
PM_ERROR_LEVEL_FATAL = 0,
335+
/** For errors that should raise a syntax error. */
336+
PM_ERROR_LEVEL_SYNTAX = 0,
329337

330338
/** For errors that should raise an argument error. */
331-
PM_ERROR_LEVEL_ARGUMENT = 1
339+
PM_ERROR_LEVEL_ARGUMENT = 1,
340+
341+
/** For errors that should raise a load error. */
342+
PM_ERROR_LEVEL_LOAD = 2
332343
} pm_error_level_t;
333344

334345
/**

src/main/c/yarp/include/prism/options.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ typedef struct {
6666
*/
6767
int32_t line;
6868

69-
/**
70-
* The offset within the file that the parse starts on. This value is
71-
* 0-indexed.
72-
*/
73-
uint32_t offset;
74-
7569
/**
7670
* The name of the encoding that the source file is in. Note that this must
7771
* correspond to a name that can be found with Encoding.find in Ruby.
@@ -164,14 +158,6 @@ PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, cons
164158
*/
165159
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
166160

167-
/**
168-
* Set the offset option on the given options struct.
169-
*
170-
* @param options The options struct to set the offset on.
171-
* @param offset The offset to set.
172-
*/
173-
PRISM_EXPORTED_FUNCTION void pm_options_offset_set(pm_options_t *options, uint32_t offset);
174-
175161
/**
176162
* Set the encoding option on the given options struct.
177163
*
@@ -267,7 +253,6 @@ PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
267253
* | `4` | the length of the filepath |
268254
* | ... | the filepath bytes |
269255
* | `4` | the line number |
270-
* | `4` | the offset |
271256
* | `4` | the length the encoding |
272257
* | ... | the encoding bytes |
273258
* | `1` | frozen string literal |

src/main/c/yarp/include/prism/util/pm_newline_list.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ typedef struct {
6161
*/
6262
bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
6363

64+
/**
65+
* Clear out the newlines that have been appended to the list.
66+
*
67+
* @param list The list to clear.
68+
*/
69+
void
70+
pm_newline_list_clear(pm_newline_list_t *list);
71+
6472
/**
6573
* Append a new offset to the newline list. Returns true if the reallocation of
6674
* the offsets succeeds (if one was necessary), otherwise returns false.

0 commit comments

Comments
 (0)