@@ -2673,16 +2673,22 @@ yp_else_node_end_keyword_loc_set(yp_else_node_t *node, const yp_token_t *keyword
2673
2673
2674
2674
// Allocate and initialize a new IntegerNode node.
2675
2675
static yp_integer_node_t *
2676
- yp_integer_node_create(yp_parser_t *parser, const yp_token_t *token) {
2676
+ yp_integer_node_create(yp_parser_t *parser, yp_node_flags_t base, const yp_token_t *token) {
2677
2677
assert(token->type == YP_TOKEN_INTEGER);
2678
2678
yp_integer_node_t *node = YP_ALLOC_NODE(parser, yp_integer_node_t);
2679
- *node = (yp_integer_node_t) {{ .type = YP_INTEGER_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }};
2679
+
2680
+ *node = (yp_integer_node_t) {{
2681
+ .type = YP_INTEGER_NODE,
2682
+ .flags = base,
2683
+ .location = YP_LOCATION_TOKEN_VALUE(token)
2684
+ }};
2685
+
2680
2686
return node;
2681
2687
}
2682
2688
2683
2689
// Allocate and initialize a new IntegerNode node from an INTEGER_IMAGINARY token.
2684
2690
static yp_imaginary_node_t *
2685
- yp_integer_node_imaginary_create(yp_parser_t *parser, const yp_token_t *token) {
2691
+ yp_integer_node_imaginary_create(yp_parser_t *parser, yp_node_flags_t base, const yp_token_t *token) {
2686
2692
assert(token->type == YP_TOKEN_INTEGER_IMAGINARY);
2687
2693
2688
2694
yp_imaginary_node_t *node = YP_ALLOC_NODE(parser, yp_imaginary_node_t);
@@ -2691,7 +2697,7 @@ yp_integer_node_imaginary_create(yp_parser_t *parser, const yp_token_t *token) {
2691
2697
.type = YP_IMAGINARY_NODE,
2692
2698
.location = YP_LOCATION_TOKEN_VALUE(token)
2693
2699
},
2694
- .numeric = (yp_node_t *) yp_integer_node_create(parser, &((yp_token_t) {
2700
+ .numeric = (yp_node_t *) yp_integer_node_create(parser, base, &((yp_token_t) {
2695
2701
.type = YP_TOKEN_INTEGER,
2696
2702
.start = token->start,
2697
2703
.end = token->end - 1
@@ -2703,7 +2709,7 @@ yp_integer_node_imaginary_create(yp_parser_t *parser, const yp_token_t *token) {
2703
2709
2704
2710
// Allocate and initialize a new IntegerNode node from an INTEGER_RATIONAL token.
2705
2711
static yp_rational_node_t *
2706
- yp_integer_node_rational_create(yp_parser_t *parser, const yp_token_t *token) {
2712
+ yp_integer_node_rational_create(yp_parser_t *parser, yp_node_flags_t base, const yp_token_t *token) {
2707
2713
assert(token->type == YP_TOKEN_INTEGER_RATIONAL);
2708
2714
2709
2715
yp_rational_node_t *node = YP_ALLOC_NODE(parser, yp_rational_node_t);
@@ -2712,7 +2718,7 @@ yp_integer_node_rational_create(yp_parser_t *parser, const yp_token_t *token) {
2712
2718
.type = YP_RATIONAL_NODE,
2713
2719
.location = YP_LOCATION_TOKEN_VALUE(token)
2714
2720
},
2715
- .numeric = (yp_node_t *) yp_integer_node_create(parser, &((yp_token_t) {
2721
+ .numeric = (yp_node_t *) yp_integer_node_create(parser, base, &((yp_token_t) {
2716
2722
.type = YP_TOKEN_INTEGER,
2717
2723
.start = token->start,
2718
2724
.end = token->end - 1
@@ -2724,7 +2730,7 @@ yp_integer_node_rational_create(yp_parser_t *parser, const yp_token_t *token) {
2724
2730
2725
2731
// Allocate and initialize a new IntegerNode node from an INTEGER_RATIONAL_IMAGINARY token.
2726
2732
static yp_imaginary_node_t *
2727
- yp_integer_node_rational_imaginary_create(yp_parser_t *parser, const yp_token_t *token) {
2733
+ yp_integer_node_rational_imaginary_create(yp_parser_t *parser, yp_node_flags_t base, const yp_token_t *token) {
2728
2734
assert(token->type == YP_TOKEN_INTEGER_RATIONAL_IMAGINARY);
2729
2735
2730
2736
yp_imaginary_node_t *node = YP_ALLOC_NODE(parser, yp_imaginary_node_t);
@@ -2733,7 +2739,7 @@ yp_integer_node_rational_imaginary_create(yp_parser_t *parser, const yp_token_t
2733
2739
.type = YP_IMAGINARY_NODE,
2734
2740
.location = YP_LOCATION_TOKEN_VALUE(token)
2735
2741
},
2736
- .numeric = (yp_node_t *) yp_integer_node_rational_create(parser, &((yp_token_t) {
2742
+ .numeric = (yp_node_t *) yp_integer_node_rational_create(parser, base, &((yp_token_t) {
2737
2743
.type = YP_TOKEN_INTEGER_RATIONAL,
2738
2744
.start = token->start,
2739
2745
.end = token->end - 1
@@ -5193,6 +5199,7 @@ lex_numeric_prefix(yp_parser_t *parser) {
5193
5199
yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_INVALID_NUMBER_BINARY);
5194
5200
}
5195
5201
5202
+ parser->integer_base = YP_INTEGER_BASE_FLAGS_BINARY;
5196
5203
break;
5197
5204
5198
5205
// 0o1111 is an octal number
@@ -5205,6 +5212,7 @@ lex_numeric_prefix(yp_parser_t *parser) {
5205
5212
yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_INVALID_NUMBER_OCTAL);
5206
5213
}
5207
5214
5215
+ parser->integer_base = YP_INTEGER_BASE_FLAGS_OCTAL;
5208
5216
break;
5209
5217
5210
5218
// 01111 is an octal number
@@ -5218,6 +5226,7 @@ lex_numeric_prefix(yp_parser_t *parser) {
5218
5226
case '6':
5219
5227
case '7':
5220
5228
parser->current.end += yp_strspn_octal_number(parser->current.end, parser->end - parser->current.end);
5229
+ parser->integer_base = YP_INTEGER_BASE_FLAGS_OCTAL;
5221
5230
break;
5222
5231
5223
5232
// 0x1111 is a hexadecimal number
@@ -5230,6 +5239,7 @@ lex_numeric_prefix(yp_parser_t *parser) {
5230
5239
yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_INVALID_NUMBER_HEXADECIMAL);
5231
5240
}
5232
5241
5242
+ parser->integer_base = YP_INTEGER_BASE_FLAGS_HEXADECIMAL;
5233
5243
break;
5234
5244
5235
5245
// 0.xxx is a float
@@ -5266,6 +5276,7 @@ lex_numeric_prefix(yp_parser_t *parser) {
5266
5276
static yp_token_type_t
5267
5277
lex_numeric(yp_parser_t *parser) {
5268
5278
yp_token_type_t type = YP_TOKEN_INTEGER;
5279
+ parser->integer_base = YP_INTEGER_BASE_FLAGS_DECIMAL;
5269
5280
5270
5281
if (parser->current.end < parser->end) {
5271
5282
type = lex_numeric_prefix(parser);
@@ -11272,18 +11283,26 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
11272
11283
11273
11284
return node;
11274
11285
}
11275
- case YP_TOKEN_INTEGER:
11286
+ case YP_TOKEN_INTEGER: {
11287
+ yp_node_flags_t base = parser->integer_base;
11276
11288
parser_lex(parser);
11277
- return (yp_node_t *) yp_integer_node_create(parser, &parser->previous);
11278
- case YP_TOKEN_INTEGER_IMAGINARY:
11289
+ return (yp_node_t *) yp_integer_node_create(parser, base, &parser->previous);
11290
+ }
11291
+ case YP_TOKEN_INTEGER_IMAGINARY: {
11292
+ yp_node_flags_t base = parser->integer_base;
11279
11293
parser_lex(parser);
11280
- return (yp_node_t *) yp_integer_node_imaginary_create(parser, &parser->previous);
11281
- case YP_TOKEN_INTEGER_RATIONAL:
11294
+ return (yp_node_t *) yp_integer_node_imaginary_create(parser, base, &parser->previous);
11295
+ }
11296
+ case YP_TOKEN_INTEGER_RATIONAL: {
11297
+ yp_node_flags_t base = parser->integer_base;
11282
11298
parser_lex(parser);
11283
- return (yp_node_t *) yp_integer_node_rational_create(parser, &parser->previous);
11284
- case YP_TOKEN_INTEGER_RATIONAL_IMAGINARY:
11299
+ return (yp_node_t *) yp_integer_node_rational_create(parser, base, &parser->previous);
11300
+ }
11301
+ case YP_TOKEN_INTEGER_RATIONAL_IMAGINARY: {
11302
+ yp_node_flags_t base = parser->integer_base;
11285
11303
parser_lex(parser);
11286
- return (yp_node_t *) yp_integer_node_rational_imaginary_create(parser, &parser->previous);
11304
+ return (yp_node_t *) yp_integer_node_rational_imaginary_create(parser, base, &parser->previous);
11305
+ }
11287
11306
case YP_TOKEN_KEYWORD___ENCODING__:
11288
11307
parser_lex(parser);
11289
11308
return (yp_node_t *) yp_source_encoding_node_create(parser, &parser->previous);
@@ -13816,7 +13835,8 @@ yp_parser_init(yp_parser_t *parser, const uint8_t *source, size_t size, const ch
13816
13835
.in_keyword_arg = false,
13817
13836
.filepath_string = filepath_string,
13818
13837
.constant_pool = YP_CONSTANT_POOL_EMPTY,
13819
- .newline_list = YP_NEWLINE_LIST_EMPTY
13838
+ .newline_list = YP_NEWLINE_LIST_EMPTY,
13839
+ .integer_base = 0
13820
13840
};
13821
13841
13822
13842
yp_accepts_block_stack_push(parser, true);
0 commit comments