@@ -62,6 +62,9 @@ typedef enum yp_token_type {
62
62
YP_TOKEN_EQUAL_GREATER , // =>
63
63
YP_TOKEN_EQUAL_TILDE , // =~
64
64
YP_TOKEN_FLOAT , // a floating point number
65
+ YP_TOKEN_FLOAT_IMAGINARY , // a floating pointer number with an imaginary suffix
66
+ YP_TOKEN_FLOAT_RATIONAL , // a floating pointer number with a rational suffix
67
+ YP_TOKEN_FLOAT_RATIONAL_IMAGINARY , // a floating pointer number with a rational and imaginary suffix
65
68
YP_TOKEN_GLOBAL_VARIABLE , // a global variable
66
69
YP_TOKEN_GREATER , // >
67
70
YP_TOKEN_GREATER_EQUAL , // >=
@@ -71,9 +74,11 @@ typedef enum yp_token_type {
71
74
YP_TOKEN_HEREDOC_START , // the start of a heredoc
72
75
YP_TOKEN_IDENTIFIER , // an identifier
73
76
YP_TOKEN_IGNORED_NEWLINE , // an ignored newline
74
- YP_TOKEN_IMAGINARY_NUMBER , // an imaginary number literal
75
77
YP_TOKEN_INSTANCE_VARIABLE , // an instance variable
76
78
YP_TOKEN_INTEGER , // an integer (any base)
79
+ YP_TOKEN_INTEGER_IMAGINARY , // an integer with an imaginary suffix
80
+ YP_TOKEN_INTEGER_RATIONAL , // an integer with a rational suffix
81
+ YP_TOKEN_INTEGER_RATIONAL_IMAGINARY , // an integer with a rational and imaginary suffix
77
82
YP_TOKEN_KEYWORD_ALIAS , // alias
78
83
YP_TOKEN_KEYWORD_AND , // and
79
84
YP_TOKEN_KEYWORD_BEGIN , // begin
@@ -151,7 +156,6 @@ typedef enum yp_token_type {
151
156
YP_TOKEN_PLUS , // +
152
157
YP_TOKEN_PLUS_EQUAL , // +=
153
158
YP_TOKEN_QUESTION_MARK , // ?
154
- YP_TOKEN_RATIONAL_NUMBER , // a rational number literal
155
159
YP_TOKEN_REGEXP_BEGIN , // the beginning of a regular expression
156
160
YP_TOKEN_REGEXP_END , // the end of a regular expression
157
161
YP_TOKEN_SEMICOLON , // ;
@@ -166,6 +170,7 @@ typedef enum yp_token_type {
166
170
YP_TOKEN_STRING_END , // the end of a string
167
171
YP_TOKEN_SYMBOL_BEGIN , // the beginning of a symbol
168
172
YP_TOKEN_TILDE , // ~ or ~@
173
+ YP_TOKEN_UAMPERSAND , // unary &
169
174
YP_TOKEN_UCOLON_COLON , // unary ::
170
175
YP_TOKEN_UDOT_DOT , // unary ..
171
176
YP_TOKEN_UDOT_DOT_DOT , // unary ...
@@ -245,98 +250,111 @@ typedef enum {
245
250
YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE = 34 ,
246
251
YP_NODE_CONSTANT_PATH_WRITE_NODE = 35 ,
247
252
YP_NODE_CONSTANT_READ_NODE = 36 ,
248
- YP_NODE_DEF_NODE = 37 ,
249
- YP_NODE_DEFINED_NODE = 38 ,
250
- YP_NODE_ELSE_NODE = 39 ,
251
- YP_NODE_EMBEDDED_STATEMENTS_NODE = 40 ,
252
- YP_NODE_EMBEDDED_VARIABLE_NODE = 41 ,
253
- YP_NODE_ENSURE_NODE = 42 ,
254
- YP_NODE_FALSE_NODE = 43 ,
255
- YP_NODE_FIND_PATTERN_NODE = 44 ,
256
- YP_NODE_FLOAT_NODE = 45 ,
257
- YP_NODE_FOR_NODE = 46 ,
258
- YP_NODE_FORWARDING_ARGUMENTS_NODE = 47 ,
259
- YP_NODE_FORWARDING_PARAMETER_NODE = 48 ,
260
- YP_NODE_FORWARDING_SUPER_NODE = 49 ,
261
- YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 50 ,
262
- YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 51 ,
263
- YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE = 52 ,
264
- YP_NODE_GLOBAL_VARIABLE_READ_NODE = 53 ,
265
- YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 54 ,
266
- YP_NODE_HASH_NODE = 55 ,
267
- YP_NODE_HASH_PATTERN_NODE = 56 ,
268
- YP_NODE_IF_NODE = 57 ,
269
- YP_NODE_IMAGINARY_NODE = 58 ,
270
- YP_NODE_IN_NODE = 59 ,
271
- YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE = 60 ,
272
- YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE = 61 ,
273
- YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE = 62 ,
274
- YP_NODE_INSTANCE_VARIABLE_READ_NODE = 63 ,
275
- YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 64 ,
276
- YP_NODE_INTEGER_NODE = 65 ,
277
- YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 66 ,
278
- YP_NODE_INTERPOLATED_STRING_NODE = 67 ,
279
- YP_NODE_INTERPOLATED_SYMBOL_NODE = 68 ,
280
- YP_NODE_INTERPOLATED_X_STRING_NODE = 69 ,
281
- YP_NODE_KEYWORD_HASH_NODE = 70 ,
282
- YP_NODE_KEYWORD_PARAMETER_NODE = 71 ,
283
- YP_NODE_KEYWORD_REST_PARAMETER_NODE = 72 ,
284
- YP_NODE_LAMBDA_NODE = 73 ,
285
- YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 74 ,
286
- YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 75 ,
287
- YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 76 ,
288
- YP_NODE_LOCAL_VARIABLE_READ_NODE = 77 ,
289
- YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 78 ,
290
- YP_NODE_MATCH_PREDICATE_NODE = 79 ,
291
- YP_NODE_MATCH_REQUIRED_NODE = 80 ,
292
- YP_NODE_MISSING_NODE = 81 ,
293
- YP_NODE_MODULE_NODE = 82 ,
294
- YP_NODE_MULTI_WRITE_NODE = 83 ,
295
- YP_NODE_NEXT_NODE = 84 ,
296
- YP_NODE_NIL_NODE = 85 ,
297
- YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 86 ,
298
- YP_NODE_NUMBERED_REFERENCE_READ_NODE = 87 ,
299
- YP_NODE_OPTIONAL_PARAMETER_NODE = 88 ,
300
- YP_NODE_OR_NODE = 89 ,
301
- YP_NODE_PARAMETERS_NODE = 90 ,
302
- YP_NODE_PARENTHESES_NODE = 91 ,
303
- YP_NODE_PINNED_EXPRESSION_NODE = 92 ,
304
- YP_NODE_PINNED_VARIABLE_NODE = 93 ,
305
- YP_NODE_POST_EXECUTION_NODE = 94 ,
306
- YP_NODE_PRE_EXECUTION_NODE = 95 ,
307
- YP_NODE_PROGRAM_NODE = 96 ,
308
- YP_NODE_RANGE_NODE = 97 ,
309
- YP_NODE_RATIONAL_NODE = 98 ,
310
- YP_NODE_REDO_NODE = 99 ,
311
- YP_NODE_REGULAR_EXPRESSION_NODE = 100 ,
312
- YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 101 ,
313
- YP_NODE_REQUIRED_PARAMETER_NODE = 102 ,
314
- YP_NODE_RESCUE_MODIFIER_NODE = 103 ,
315
- YP_NODE_RESCUE_NODE = 104 ,
316
- YP_NODE_REST_PARAMETER_NODE = 105 ,
317
- YP_NODE_RETRY_NODE = 106 ,
318
- YP_NODE_RETURN_NODE = 107 ,
319
- YP_NODE_SELF_NODE = 108 ,
320
- YP_NODE_SINGLETON_CLASS_NODE = 109 ,
321
- YP_NODE_SOURCE_ENCODING_NODE = 110 ,
322
- YP_NODE_SOURCE_FILE_NODE = 111 ,
323
- YP_NODE_SOURCE_LINE_NODE = 112 ,
324
- YP_NODE_SPLAT_NODE = 113 ,
325
- YP_NODE_STATEMENTS_NODE = 114 ,
326
- YP_NODE_STRING_CONCAT_NODE = 115 ,
327
- YP_NODE_STRING_NODE = 116 ,
328
- YP_NODE_SUPER_NODE = 117 ,
329
- YP_NODE_SYMBOL_NODE = 118 ,
330
- YP_NODE_TRUE_NODE = 119 ,
331
- YP_NODE_UNDEF_NODE = 120 ,
332
- YP_NODE_UNLESS_NODE = 121 ,
333
- YP_NODE_UNTIL_NODE = 122 ,
334
- YP_NODE_WHEN_NODE = 123 ,
335
- YP_NODE_WHILE_NODE = 124 ,
336
- YP_NODE_X_STRING_NODE = 125 ,
337
- YP_NODE_YIELD_NODE = 126 ,
253
+ YP_NODE_CONSTANT_WRITE_NODE = 37 ,
254
+ YP_NODE_DEF_NODE = 38 ,
255
+ YP_NODE_DEFINED_NODE = 39 ,
256
+ YP_NODE_ELSE_NODE = 40 ,
257
+ YP_NODE_EMBEDDED_STATEMENTS_NODE = 41 ,
258
+ YP_NODE_EMBEDDED_VARIABLE_NODE = 42 ,
259
+ YP_NODE_ENSURE_NODE = 43 ,
260
+ YP_NODE_FALSE_NODE = 44 ,
261
+ YP_NODE_FIND_PATTERN_NODE = 45 ,
262
+ YP_NODE_FLOAT_NODE = 46 ,
263
+ YP_NODE_FOR_NODE = 47 ,
264
+ YP_NODE_FORWARDING_ARGUMENTS_NODE = 48 ,
265
+ YP_NODE_FORWARDING_PARAMETER_NODE = 49 ,
266
+ YP_NODE_FORWARDING_SUPER_NODE = 50 ,
267
+ YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 51 ,
268
+ YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 52 ,
269
+ YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE = 53 ,
270
+ YP_NODE_GLOBAL_VARIABLE_READ_NODE = 54 ,
271
+ YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 55 ,
272
+ YP_NODE_HASH_NODE = 56 ,
273
+ YP_NODE_HASH_PATTERN_NODE = 57 ,
274
+ YP_NODE_IF_NODE = 58 ,
275
+ YP_NODE_IMAGINARY_NODE = 59 ,
276
+ YP_NODE_IN_NODE = 60 ,
277
+ YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE = 61 ,
278
+ YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE = 62 ,
279
+ YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE = 63 ,
280
+ YP_NODE_INSTANCE_VARIABLE_READ_NODE = 64 ,
281
+ YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 65 ,
282
+ YP_NODE_INTEGER_NODE = 66 ,
283
+ YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 67 ,
284
+ YP_NODE_INTERPOLATED_STRING_NODE = 68 ,
285
+ YP_NODE_INTERPOLATED_SYMBOL_NODE = 69 ,
286
+ YP_NODE_INTERPOLATED_X_STRING_NODE = 70 ,
287
+ YP_NODE_KEYWORD_HASH_NODE = 71 ,
288
+ YP_NODE_KEYWORD_PARAMETER_NODE = 72 ,
289
+ YP_NODE_KEYWORD_REST_PARAMETER_NODE = 73 ,
290
+ YP_NODE_LAMBDA_NODE = 74 ,
291
+ YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 75 ,
292
+ YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 76 ,
293
+ YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 77 ,
294
+ YP_NODE_LOCAL_VARIABLE_READ_NODE = 78 ,
295
+ YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 79 ,
296
+ YP_NODE_MATCH_PREDICATE_NODE = 80 ,
297
+ YP_NODE_MATCH_REQUIRED_NODE = 81 ,
298
+ YP_NODE_MISSING_NODE = 82 ,
299
+ YP_NODE_MODULE_NODE = 83 ,
300
+ YP_NODE_MULTI_WRITE_NODE = 84 ,
301
+ YP_NODE_NEXT_NODE = 85 ,
302
+ YP_NODE_NIL_NODE = 86 ,
303
+ YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 87 ,
304
+ YP_NODE_NUMBERED_REFERENCE_READ_NODE = 88 ,
305
+ YP_NODE_OPTIONAL_PARAMETER_NODE = 89 ,
306
+ YP_NODE_OR_NODE = 90 ,
307
+ YP_NODE_PARAMETERS_NODE = 91 ,
308
+ YP_NODE_PARENTHESES_NODE = 92 ,
309
+ YP_NODE_PINNED_EXPRESSION_NODE = 93 ,
310
+ YP_NODE_PINNED_VARIABLE_NODE = 94 ,
311
+ YP_NODE_POST_EXECUTION_NODE = 95 ,
312
+ YP_NODE_PRE_EXECUTION_NODE = 96 ,
313
+ YP_NODE_PROGRAM_NODE = 97 ,
314
+ YP_NODE_RANGE_NODE = 98 ,
315
+ YP_NODE_RATIONAL_NODE = 99 ,
316
+ YP_NODE_REDO_NODE = 100 ,
317
+ YP_NODE_REGULAR_EXPRESSION_NODE = 101 ,
318
+ YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 102 ,
319
+ YP_NODE_REQUIRED_PARAMETER_NODE = 103 ,
320
+ YP_NODE_RESCUE_MODIFIER_NODE = 104 ,
321
+ YP_NODE_RESCUE_NODE = 105 ,
322
+ YP_NODE_REST_PARAMETER_NODE = 106 ,
323
+ YP_NODE_RETRY_NODE = 107 ,
324
+ YP_NODE_RETURN_NODE = 108 ,
325
+ YP_NODE_SELF_NODE = 109 ,
326
+ YP_NODE_SINGLETON_CLASS_NODE = 110 ,
327
+ YP_NODE_SOURCE_ENCODING_NODE = 111 ,
328
+ YP_NODE_SOURCE_FILE_NODE = 112 ,
329
+ YP_NODE_SOURCE_LINE_NODE = 113 ,
330
+ YP_NODE_SPLAT_NODE = 114 ,
331
+ YP_NODE_STATEMENTS_NODE = 115 ,
332
+ YP_NODE_STRING_CONCAT_NODE = 116 ,
333
+ YP_NODE_STRING_NODE = 117 ,
334
+ YP_NODE_SUPER_NODE = 118 ,
335
+ YP_NODE_SYMBOL_NODE = 119 ,
336
+ YP_NODE_TRUE_NODE = 120 ,
337
+ YP_NODE_UNDEF_NODE = 121 ,
338
+ YP_NODE_UNLESS_NODE = 122 ,
339
+ YP_NODE_UNTIL_NODE = 123 ,
340
+ YP_NODE_WHEN_NODE = 124 ,
341
+ YP_NODE_WHILE_NODE = 125 ,
342
+ YP_NODE_X_STRING_NODE = 126 ,
343
+ YP_NODE_YIELD_NODE = 127 ,
338
344
} yp_node_type_t ;
339
345
346
+ // We store the node type enum in every node in the tree. We don't have nearly
347
+ // as many node types as we do bits in an enum, so we're going to use the top
348
+ // half of the enum to store flags about the node.
349
+ static const unsigned int YP_NODE_FLAGS_SHIFT = sizeof (yp_node_type_t ) * 8 / 2 ;
350
+ static const unsigned int YP_NODE_FLAG_NEWLINE = 1 << YP_NODE_FLAGS_SHIFT ;
351
+
352
+ // For easy access, we define some macros that manipulate only the bottom half
353
+ // of the node type enum.
354
+ static const unsigned int YP_NODE_TYPE_MASK = ((1 << (sizeof (yp_node_type_t ) * 8 / 2 )) - 1 );
355
+ #define YP_NODE_TYPE (node ) ((node)->type & YP_NODE_TYPE_MASK)
356
+ #define YP_NODE_TYPE_P (node , type ) (YP_NODE_TYPE(node) == (type))
357
+
340
358
// This is the overall tagged union representing a node in the syntax tree.
341
359
typedef struct yp_node {
342
360
// This represents the type of the node. It somewhat maps to the nodes that
@@ -646,6 +664,14 @@ typedef struct yp_constant_read_node {
646
664
yp_node_t base ;
647
665
} yp_constant_read_node_t ;
648
666
667
+ // ConstantWriteNode
668
+ typedef struct yp_constant_write_node {
669
+ yp_node_t base ;
670
+ yp_location_t name_loc ;
671
+ struct yp_node * value ;
672
+ yp_location_t operator_loc ;
673
+ } yp_constant_write_node_t ;
674
+
649
675
// DefNode
650
676
typedef struct yp_def_node {
651
677
yp_node_t base ;
@@ -1183,7 +1209,7 @@ typedef struct yp_rescue_node {
1183
1209
yp_location_t keyword_loc ;
1184
1210
struct yp_node_list exceptions ;
1185
1211
yp_location_t operator_loc ;
1186
- struct yp_node * exception ;
1212
+ struct yp_node * reference ;
1187
1213
struct yp_statements_node * statements ;
1188
1214
struct yp_rescue_node * consequent ;
1189
1215
} yp_rescue_node_t ;
@@ -1315,6 +1341,7 @@ typedef struct yp_until_node {
1315
1341
yp_location_t keyword_loc ;
1316
1342
struct yp_node * predicate ;
1317
1343
struct yp_statements_node * statements ;
1344
+ uint32_t flags ;
1318
1345
} yp_until_node_t ;
1319
1346
1320
1347
// WhenNode
@@ -1331,6 +1358,7 @@ typedef struct yp_while_node {
1331
1358
yp_location_t keyword_loc ;
1332
1359
struct yp_node * predicate ;
1333
1360
struct yp_statements_node * statements ;
1361
+ uint32_t flags ;
1334
1362
} yp_while_node_t ;
1335
1363
1336
1364
// XStringNode
@@ -1354,8 +1382,14 @@ typedef struct yp_yield_node {
1354
1382
// CallNodeFlags
1355
1383
typedef enum {
1356
1384
YP_CALL_NODE_FLAGS_SAFE_NAVIGATION = 1 << 0 ,
1385
+ YP_CALL_NODE_FLAGS_VARIABLE_CALL = 1 << 1 ,
1357
1386
} yp_call_node_flags_t ;
1358
1387
1388
+ // LoopFlags
1389
+ typedef enum {
1390
+ YP_LOOP_FLAGS_BEGIN_MODIFIER = 1 << 0 ,
1391
+ } yp_loop_flags_t ;
1392
+
1359
1393
// RangeNodeFlags
1360
1394
typedef enum {
1361
1395
YP_RANGE_NODE_FLAGS_EXCLUDE_END = 1 << 0 ,
0 commit comments