prism 0.27.0 → 0.29.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -1
- data/config.yml +68 -44
- data/docs/configuration.md +1 -0
- data/ext/prism/api_node.c +854 -847
- data/ext/prism/extconf.rb +27 -23
- data/ext/prism/extension.c +5 -3
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +70 -48
- data/include/prism/diagnostic.h +23 -6
- data/include/prism/options.h +2 -2
- data/include/prism/parser.h +10 -0
- data/include/prism/static_literals.h +8 -6
- data/include/prism/version.h +2 -2
- data/lib/prism/desugar_compiler.rb +4 -4
- data/lib/prism/dot_visitor.rb +54 -38
- data/lib/prism/dsl.rb +24 -24
- data/lib/prism/ffi.rb +4 -4
- data/lib/prism/inspect_visitor.rb +2156 -0
- data/lib/prism/lex_compat.rb +1 -1
- data/lib/prism/mutation_compiler.rb +2 -2
- data/lib/prism/node.rb +737 -1863
- data/lib/prism/node_ext.rb +176 -5
- data/lib/prism/parse_result/comments.rb +1 -1
- data/lib/prism/parse_result/newlines.rb +1 -1
- data/lib/prism/parse_result.rb +78 -0
- data/lib/prism/pattern.rb +12 -6
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/reflection.rb +20 -20
- data/lib/prism/serialize.rb +32 -15
- data/lib/prism/translation/parser/compiler.rb +156 -26
- data/lib/prism/translation/parser.rb +7 -7
- data/lib/prism/translation/ripper.rb +29 -25
- data/lib/prism/translation/ruby_parser.rb +13 -13
- data/lib/prism.rb +2 -1
- data/prism.gemspec +37 -38
- data/rbi/prism/compiler.rbi +3 -5
- data/rbi/prism/inspect_visitor.rbi +12 -0
- data/rbi/prism/node.rbi +405 -370
- data/rbi/prism/node_ext.rbi +5 -0
- data/rbi/prism/parse_result.rbi +23 -0
- data/rbi/prism/translation/ripper.rbi +1 -11
- data/sig/prism/dsl.rbs +12 -12
- data/sig/prism/inspect_visitor.rbs +22 -0
- data/sig/prism/lex_compat.rbs +10 -0
- data/sig/prism/node.rbs +108 -91
- data/sig/prism/node_ext.rbs +4 -0
- data/sig/prism/parse_result.rbs +12 -0
- data/src/diagnostic.c +66 -33
- data/src/node.c +89 -64
- data/src/options.c +2 -2
- data/src/prettyprint.c +109 -66
- data/src/prism.c +862 -317
- data/src/serialize.c +21 -18
- data/src/static_literals.c +120 -34
- data/src/token_type.c +6 -6
- metadata +8 -9
- data/lib/prism/node_inspector.rb +0 -68
- data/lib/prism/polyfill/string.rb +0 -12
- data/rbi/prism/desugar_compiler.rbi +0 -5
- data/rbi/prism/mutation_compiler.rbi +0 -5
- data/rbi/prism/translation/parser/compiler.rbi +0 -13
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +0 -5
- data/rbi/prism/translation/ruby_parser.rbi +0 -11
data/ext/prism/extconf.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rbconfig"
|
4
|
+
|
3
5
|
if ARGV.delete("--help")
|
4
6
|
print(<<~TEXT)
|
5
7
|
USAGE: ruby #{$PROGRAM_NAME} [options]
|
@@ -40,26 +42,6 @@ def generate_templates
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
# We're going to need to run `make` using prism's `Makefile`. We want to match
|
44
|
-
# up as much of the configuration to the configuration that built the current
|
45
|
-
# version of Ruby as possible.
|
46
|
-
require "rbconfig"
|
47
|
-
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
|
48
|
-
|
49
|
-
# It's possible that the Ruby that is being run wasn't actually compiled on this
|
50
|
-
# machine, in which case the configuration might be incorrect. In this case
|
51
|
-
# we'll need to do some additional checks and potentially fall back to defaults.
|
52
|
-
if env.key?("CC") && !File.exist?(env["CC"])
|
53
|
-
env.delete("CC")
|
54
|
-
env.delete("CFLAGS")
|
55
|
-
env.delete("CPPFLAGS")
|
56
|
-
end
|
57
|
-
|
58
|
-
if env.key?("AR") && !File.exist?(env["AR"])
|
59
|
-
env.delete("AR")
|
60
|
-
env.delete("ARFLAGS")
|
61
|
-
end
|
62
|
-
|
63
45
|
# Runs `make` in the root directory of the project. Note that this is the
|
64
46
|
# `Makefile` for the overall project, not the `Makefile` that is being generated
|
65
47
|
# by this script.`
|
@@ -77,15 +59,37 @@ end
|
|
77
59
|
|
78
60
|
# On non-CRuby we only need the shared library since we'll interface with it
|
79
61
|
# through FFI, so we'll build only that and not the C extension. We also avoid
|
80
|
-
# `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby,
|
81
|
-
# but we want to use the
|
62
|
+
# `require "mkmf"` as that prepends the GraalVM LLVM toolchain to PATH on TruffleRuby < 24.0,
|
63
|
+
# but we want to use the system toolchain here since libprism is run natively.
|
82
64
|
if RUBY_ENGINE != "ruby"
|
83
65
|
generate_templates
|
84
|
-
|
66
|
+
soext = RbConfig::CONFIG["SOEXT"]
|
67
|
+
# Pass SOEXT to avoid an extra subprocess just to query that
|
68
|
+
make({ "SOEXT" => soext }, "build/libprism.#{soext}")
|
85
69
|
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
|
86
70
|
return
|
87
71
|
end
|
88
72
|
|
73
|
+
# We're going to need to run `make` using prism's `Makefile`.
|
74
|
+
# We want to use the same toolchain (compiler, flags, etc) to compile libprism.a and
|
75
|
+
# the C extension since they will be linked together.
|
76
|
+
# The C extension uses RbConfig, which contains values from the toolchain that built the running Ruby.
|
77
|
+
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
|
78
|
+
|
79
|
+
# It's possible that the Ruby that is being run wasn't actually compiled on this
|
80
|
+
# machine, in which case parts of RbConfig might be incorrect. In this case
|
81
|
+
# we'll need to do some additional checks and potentially fall back to defaults.
|
82
|
+
if env.key?("CC") && !File.exist?(env["CC"])
|
83
|
+
env.delete("CC")
|
84
|
+
env.delete("CFLAGS")
|
85
|
+
env.delete("CPPFLAGS")
|
86
|
+
end
|
87
|
+
|
88
|
+
if env.key?("AR") && !File.exist?(env["AR"])
|
89
|
+
env.delete("AR")
|
90
|
+
env.delete("ARFLAGS")
|
91
|
+
end
|
92
|
+
|
89
93
|
require "mkmf"
|
90
94
|
|
91
95
|
# First, ensure that we can find the header for the prism library.
|
data/ext/prism/extension.c
CHANGED
@@ -32,6 +32,7 @@ ID rb_option_id_frozen_string_literal;
|
|
32
32
|
ID rb_option_id_line;
|
33
33
|
ID rb_option_id_scopes;
|
34
34
|
ID rb_option_id_version;
|
35
|
+
ID rb_prism_source_id_for;
|
35
36
|
|
36
37
|
/******************************************************************************/
|
37
38
|
/* IO of Ruby code */
|
@@ -599,8 +600,7 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod
|
|
599
600
|
|
600
601
|
VALUE source_string = rb_str_new((const char *) pm_string_source(input), pm_string_length(input));
|
601
602
|
VALUE offsets = rb_ary_new();
|
602
|
-
VALUE
|
603
|
-
VALUE source = rb_class_new_instance(3, source_argv, rb_cPrismSource);
|
603
|
+
VALUE source = rb_funcall(rb_cPrismSource, rb_prism_source_id_for, 3, source_string, LONG2NUM(parser.start_line), offsets);
|
604
604
|
|
605
605
|
parse_lex_data_t parse_lex_data = {
|
606
606
|
.source = source,
|
@@ -1243,7 +1243,7 @@ static_inspect(int argc, VALUE *argv, VALUE self) {
|
|
1243
1243
|
pm_node_t *node = ((pm_program_node_t *) program)->statements->body.nodes[0];
|
1244
1244
|
|
1245
1245
|
pm_buffer_t buffer = { 0 };
|
1246
|
-
pm_static_literal_inspect(&buffer, &parser, node);
|
1246
|
+
pm_static_literal_inspect(&buffer, &parser.newline_list, parser.start_line, parser.encoding->name, node);
|
1247
1247
|
|
1248
1248
|
rb_encoding *encoding = rb_enc_find(parser.encoding->name);
|
1249
1249
|
VALUE result = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), encoding);
|
@@ -1379,6 +1379,8 @@ Init_prism(void) {
|
|
1379
1379
|
rb_option_id_scopes = rb_intern_const("scopes");
|
1380
1380
|
rb_option_id_version = rb_intern_const("version");
|
1381
1381
|
|
1382
|
+
rb_prism_source_id_for = rb_intern("for");
|
1383
|
+
|
1382
1384
|
/**
|
1383
1385
|
* The version of the prism library.
|
1384
1386
|
*/
|
data/ext/prism/extension.h
CHANGED
data/include/prism/ast.h
CHANGED
@@ -1235,6 +1235,7 @@ typedef struct pm_and_node {
|
|
1235
1235
|
*
|
1236
1236
|
* Type: PM_ARGUMENTS_NODE
|
1237
1237
|
* Flags:
|
1238
|
+
* PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORDS
|
1238
1239
|
* PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT
|
1239
1240
|
*
|
1240
1241
|
* @extends pm_node_t
|
@@ -1817,14 +1818,14 @@ typedef struct pm_call_operator_write_node {
|
|
1817
1818
|
pm_constant_id_t write_name;
|
1818
1819
|
|
1819
1820
|
/**
|
1820
|
-
* CallOperatorWriteNode#
|
1821
|
+
* CallOperatorWriteNode#binary_operator
|
1821
1822
|
*/
|
1822
|
-
pm_constant_id_t
|
1823
|
+
pm_constant_id_t binary_operator;
|
1823
1824
|
|
1824
1825
|
/**
|
1825
|
-
* CallOperatorWriteNode#
|
1826
|
+
* CallOperatorWriteNode#binary_operator_loc
|
1826
1827
|
*/
|
1827
|
-
pm_location_t
|
1828
|
+
pm_location_t binary_operator_loc;
|
1828
1829
|
|
1829
1830
|
/**
|
1830
1831
|
* CallOperatorWriteNode#value
|
@@ -2128,9 +2129,9 @@ typedef struct pm_class_variable_operator_write_node {
|
|
2128
2129
|
pm_location_t name_loc;
|
2129
2130
|
|
2130
2131
|
/**
|
2131
|
-
* ClassVariableOperatorWriteNode#
|
2132
|
+
* ClassVariableOperatorWriteNode#binary_operator_loc
|
2132
2133
|
*/
|
2133
|
-
pm_location_t
|
2134
|
+
pm_location_t binary_operator_loc;
|
2134
2135
|
|
2135
2136
|
/**
|
2136
2137
|
* ClassVariableOperatorWriteNode#value
|
@@ -2138,9 +2139,9 @@ typedef struct pm_class_variable_operator_write_node {
|
|
2138
2139
|
struct pm_node *value;
|
2139
2140
|
|
2140
2141
|
/**
|
2141
|
-
* ClassVariableOperatorWriteNode#
|
2142
|
+
* ClassVariableOperatorWriteNode#binary_operator
|
2142
2143
|
*/
|
2143
|
-
pm_constant_id_t
|
2144
|
+
pm_constant_id_t binary_operator;
|
2144
2145
|
} pm_class_variable_operator_write_node_t;
|
2145
2146
|
|
2146
2147
|
/**
|
@@ -2325,9 +2326,9 @@ typedef struct pm_constant_operator_write_node {
|
|
2325
2326
|
pm_location_t name_loc;
|
2326
2327
|
|
2327
2328
|
/**
|
2328
|
-
* ConstantOperatorWriteNode#
|
2329
|
+
* ConstantOperatorWriteNode#binary_operator_loc
|
2329
2330
|
*/
|
2330
|
-
pm_location_t
|
2331
|
+
pm_location_t binary_operator_loc;
|
2331
2332
|
|
2332
2333
|
/**
|
2333
2334
|
* ConstantOperatorWriteNode#value
|
@@ -2335,9 +2336,9 @@ typedef struct pm_constant_operator_write_node {
|
|
2335
2336
|
struct pm_node *value;
|
2336
2337
|
|
2337
2338
|
/**
|
2338
|
-
* ConstantOperatorWriteNode#
|
2339
|
+
* ConstantOperatorWriteNode#binary_operator
|
2339
2340
|
*/
|
2340
|
-
pm_constant_id_t
|
2341
|
+
pm_constant_id_t binary_operator;
|
2341
2342
|
} pm_constant_operator_write_node_t;
|
2342
2343
|
|
2343
2344
|
/**
|
@@ -2427,21 +2428,11 @@ typedef struct pm_constant_path_node {
|
|
2427
2428
|
struct pm_node *parent;
|
2428
2429
|
|
2429
2430
|
/**
|
2430
|
-
* ConstantPathNode#
|
2431
|
-
*
|
2432
|
-
* The right-hand node of the path. Always a `ConstantReadNode` in a
|
2433
|
-
* valid Ruby syntax tree.
|
2434
|
-
*
|
2435
|
-
* ::Foo
|
2436
|
-
* ^^^
|
2437
|
-
*
|
2438
|
-
* self::Test
|
2439
|
-
* ^^^^
|
2431
|
+
* ConstantPathNode#name
|
2440
2432
|
*
|
2441
|
-
*
|
2442
|
-
* ^
|
2433
|
+
* The name of the constant being accessed. This could be `nil` in the event of a syntax error.
|
2443
2434
|
*/
|
2444
|
-
|
2435
|
+
pm_constant_id_t name;
|
2445
2436
|
|
2446
2437
|
/**
|
2447
2438
|
* ConstantPathNode#delimiter_loc
|
@@ -2455,6 +2446,19 @@ typedef struct pm_constant_path_node {
|
|
2455
2446
|
* ^^
|
2456
2447
|
*/
|
2457
2448
|
pm_location_t delimiter_loc;
|
2449
|
+
|
2450
|
+
/**
|
2451
|
+
* ConstantPathNode#name_loc
|
2452
|
+
*
|
2453
|
+
* The location of the name of the constant.
|
2454
|
+
*
|
2455
|
+
* ::Foo
|
2456
|
+
* ^^^
|
2457
|
+
*
|
2458
|
+
* One::Two
|
2459
|
+
* ^^^
|
2460
|
+
*/
|
2461
|
+
pm_location_t name_loc;
|
2458
2462
|
} pm_constant_path_node_t;
|
2459
2463
|
|
2460
2464
|
/**
|
@@ -2474,9 +2478,9 @@ typedef struct pm_constant_path_operator_write_node {
|
|
2474
2478
|
struct pm_constant_path_node *target;
|
2475
2479
|
|
2476
2480
|
/**
|
2477
|
-
* ConstantPathOperatorWriteNode#
|
2481
|
+
* ConstantPathOperatorWriteNode#binary_operator_loc
|
2478
2482
|
*/
|
2479
|
-
pm_location_t
|
2483
|
+
pm_location_t binary_operator_loc;
|
2480
2484
|
|
2481
2485
|
/**
|
2482
2486
|
* ConstantPathOperatorWriteNode#value
|
@@ -2484,9 +2488,9 @@ typedef struct pm_constant_path_operator_write_node {
|
|
2484
2488
|
struct pm_node *value;
|
2485
2489
|
|
2486
2490
|
/**
|
2487
|
-
* ConstantPathOperatorWriteNode#
|
2491
|
+
* ConstantPathOperatorWriteNode#binary_operator
|
2488
2492
|
*/
|
2489
|
-
pm_constant_id_t
|
2493
|
+
pm_constant_id_t binary_operator;
|
2490
2494
|
} pm_constant_path_operator_write_node_t;
|
2491
2495
|
|
2492
2496
|
/**
|
@@ -2533,14 +2537,19 @@ typedef struct pm_constant_path_target_node {
|
|
2533
2537
|
struct pm_node *parent;
|
2534
2538
|
|
2535
2539
|
/**
|
2536
|
-
* ConstantPathTargetNode#
|
2540
|
+
* ConstantPathTargetNode#name
|
2537
2541
|
*/
|
2538
|
-
|
2542
|
+
pm_constant_id_t name;
|
2539
2543
|
|
2540
2544
|
/**
|
2541
2545
|
* ConstantPathTargetNode#delimiter_loc
|
2542
2546
|
*/
|
2543
2547
|
pm_location_t delimiter_loc;
|
2548
|
+
|
2549
|
+
/**
|
2550
|
+
* ConstantPathTargetNode#name_loc
|
2551
|
+
*/
|
2552
|
+
pm_location_t name_loc;
|
2544
2553
|
} pm_constant_path_target_node_t;
|
2545
2554
|
|
2546
2555
|
/**
|
@@ -3135,9 +3144,9 @@ typedef struct pm_global_variable_operator_write_node {
|
|
3135
3144
|
pm_location_t name_loc;
|
3136
3145
|
|
3137
3146
|
/**
|
3138
|
-
* GlobalVariableOperatorWriteNode#
|
3147
|
+
* GlobalVariableOperatorWriteNode#binary_operator_loc
|
3139
3148
|
*/
|
3140
|
-
pm_location_t
|
3149
|
+
pm_location_t binary_operator_loc;
|
3141
3150
|
|
3142
3151
|
/**
|
3143
3152
|
* GlobalVariableOperatorWriteNode#value
|
@@ -3145,9 +3154,9 @@ typedef struct pm_global_variable_operator_write_node {
|
|
3145
3154
|
struct pm_node *value;
|
3146
3155
|
|
3147
3156
|
/**
|
3148
|
-
* GlobalVariableOperatorWriteNode#
|
3157
|
+
* GlobalVariableOperatorWriteNode#binary_operator
|
3149
3158
|
*/
|
3150
|
-
pm_constant_id_t
|
3159
|
+
pm_constant_id_t binary_operator;
|
3151
3160
|
} pm_global_variable_operator_write_node_t;
|
3152
3161
|
|
3153
3162
|
/**
|
@@ -3642,14 +3651,14 @@ typedef struct pm_index_operator_write_node {
|
|
3642
3651
|
struct pm_node *block;
|
3643
3652
|
|
3644
3653
|
/**
|
3645
|
-
* IndexOperatorWriteNode#
|
3654
|
+
* IndexOperatorWriteNode#binary_operator
|
3646
3655
|
*/
|
3647
|
-
pm_constant_id_t
|
3656
|
+
pm_constant_id_t binary_operator;
|
3648
3657
|
|
3649
3658
|
/**
|
3650
|
-
* IndexOperatorWriteNode#
|
3659
|
+
* IndexOperatorWriteNode#binary_operator_loc
|
3651
3660
|
*/
|
3652
|
-
pm_location_t
|
3661
|
+
pm_location_t binary_operator_loc;
|
3653
3662
|
|
3654
3663
|
/**
|
3655
3664
|
* IndexOperatorWriteNode#value
|
@@ -3810,9 +3819,9 @@ typedef struct pm_instance_variable_operator_write_node {
|
|
3810
3819
|
pm_location_t name_loc;
|
3811
3820
|
|
3812
3821
|
/**
|
3813
|
-
* InstanceVariableOperatorWriteNode#
|
3822
|
+
* InstanceVariableOperatorWriteNode#binary_operator_loc
|
3814
3823
|
*/
|
3815
|
-
pm_location_t
|
3824
|
+
pm_location_t binary_operator_loc;
|
3816
3825
|
|
3817
3826
|
/**
|
3818
3827
|
* InstanceVariableOperatorWriteNode#value
|
@@ -3820,9 +3829,9 @@ typedef struct pm_instance_variable_operator_write_node {
|
|
3820
3829
|
struct pm_node *value;
|
3821
3830
|
|
3822
3831
|
/**
|
3823
|
-
* InstanceVariableOperatorWriteNode#
|
3832
|
+
* InstanceVariableOperatorWriteNode#binary_operator
|
3824
3833
|
*/
|
3825
|
-
pm_constant_id_t
|
3834
|
+
pm_constant_id_t binary_operator;
|
3826
3835
|
} pm_instance_variable_operator_write_node_t;
|
3827
3836
|
|
3828
3837
|
/**
|
@@ -4295,9 +4304,9 @@ typedef struct pm_local_variable_operator_write_node {
|
|
4295
4304
|
pm_location_t name_loc;
|
4296
4305
|
|
4297
4306
|
/**
|
4298
|
-
* LocalVariableOperatorWriteNode#
|
4307
|
+
* LocalVariableOperatorWriteNode#binary_operator_loc
|
4299
4308
|
*/
|
4300
|
-
pm_location_t
|
4309
|
+
pm_location_t binary_operator_loc;
|
4301
4310
|
|
4302
4311
|
/**
|
4303
4312
|
* LocalVariableOperatorWriteNode#value
|
@@ -4310,9 +4319,9 @@ typedef struct pm_local_variable_operator_write_node {
|
|
4310
4319
|
pm_constant_id_t name;
|
4311
4320
|
|
4312
4321
|
/**
|
4313
|
-
* LocalVariableOperatorWriteNode#
|
4322
|
+
* LocalVariableOperatorWriteNode#binary_operator
|
4314
4323
|
*/
|
4315
|
-
pm_constant_id_t
|
4324
|
+
pm_constant_id_t binary_operator;
|
4316
4325
|
|
4317
4326
|
/**
|
4318
4327
|
* LocalVariableOperatorWriteNode#depth
|
@@ -5455,6 +5464,8 @@ typedef struct pm_retry_node {
|
|
5455
5464
|
* ReturnNode
|
5456
5465
|
*
|
5457
5466
|
* Type: PM_RETURN_NODE
|
5467
|
+
* Flags:
|
5468
|
+
* PM_RETURN_NODE_FLAGS_REDUNDANT
|
5458
5469
|
*
|
5459
5470
|
* @extends pm_node_t
|
5460
5471
|
*/
|
@@ -6029,8 +6040,11 @@ typedef struct pm_yield_node {
|
|
6029
6040
|
* Flags for arguments nodes.
|
6030
6041
|
*/
|
6031
6042
|
typedef enum pm_arguments_node_flags {
|
6043
|
+
/** if arguments contain keywords */
|
6044
|
+
PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORDS = 1,
|
6045
|
+
|
6032
6046
|
/** if arguments contain keyword splat */
|
6033
|
-
PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT =
|
6047
|
+
PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT = 2,
|
6034
6048
|
} pm_arguments_node_flags_t;
|
6035
6049
|
|
6036
6050
|
/**
|
@@ -6167,6 +6181,14 @@ typedef enum pm_regular_expression_flags {
|
|
6167
6181
|
PM_REGULAR_EXPRESSION_FLAGS_FORCED_US_ASCII_ENCODING = 1024,
|
6168
6182
|
} pm_regular_expression_flags_t;
|
6169
6183
|
|
6184
|
+
/**
|
6185
|
+
* Flags for return nodes.
|
6186
|
+
*/
|
6187
|
+
typedef enum pm_return_node_flags {
|
6188
|
+
/** a return statement that is redundant because it is the last statement in a method */
|
6189
|
+
PM_RETURN_NODE_FLAGS_REDUNDANT = 1,
|
6190
|
+
} pm_return_node_flags_t;
|
6191
|
+
|
6170
6192
|
/**
|
6171
6193
|
* Flags for shareable constant nodes.
|
6172
6194
|
*/
|
data/include/prism/diagnostic.h
CHANGED
@@ -36,13 +36,16 @@ typedef enum {
|
|
36
36
|
PM_ERR_ARGUMENT_BARE_HASH,
|
37
37
|
PM_ERR_ARGUMENT_BLOCK_FORWARDING,
|
38
38
|
PM_ERR_ARGUMENT_BLOCK_MULTI,
|
39
|
+
PM_ERR_ARGUMENT_CONFLICT_AMPERSAND,
|
40
|
+
PM_ERR_ARGUMENT_CONFLICT_STAR,
|
41
|
+
PM_ERR_ARGUMENT_CONFLICT_STAR_STAR,
|
39
42
|
PM_ERR_ARGUMENT_FORMAL_CLASS,
|
40
43
|
PM_ERR_ARGUMENT_FORMAL_CONSTANT,
|
41
44
|
PM_ERR_ARGUMENT_FORMAL_GLOBAL,
|
42
45
|
PM_ERR_ARGUMENT_FORMAL_IVAR,
|
43
46
|
PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
|
44
47
|
PM_ERR_ARGUMENT_IN,
|
45
|
-
|
48
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND,
|
46
49
|
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
|
47
50
|
PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
|
48
51
|
PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR,
|
@@ -124,6 +127,7 @@ typedef enum {
|
|
124
127
|
PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
|
125
128
|
PM_ERR_EXPECT_EXPRESSION_AFTER_STAR,
|
126
129
|
PM_ERR_EXPECT_IDENT_REQ_PARAMETER,
|
130
|
+
PM_ERR_EXPECT_IN_DELIMITER,
|
127
131
|
PM_ERR_EXPECT_LPAREN_REQ_PARAMETER,
|
128
132
|
PM_ERR_EXPECT_MESSAGE,
|
129
133
|
PM_ERR_EXPECT_RBRACKET,
|
@@ -152,16 +156,18 @@ typedef enum {
|
|
152
156
|
PM_ERR_HASH_ROCKET,
|
153
157
|
PM_ERR_HASH_TERM,
|
154
158
|
PM_ERR_HASH_VALUE,
|
159
|
+
PM_ERR_HEREDOC_IDENTIFIER,
|
155
160
|
PM_ERR_HEREDOC_TERM,
|
156
161
|
PM_ERR_INCOMPLETE_QUESTION_MARK,
|
157
162
|
PM_ERR_INCOMPLETE_VARIABLE_CLASS,
|
158
|
-
|
163
|
+
PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3,
|
159
164
|
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
|
160
|
-
|
165
|
+
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3,
|
161
166
|
PM_ERR_INSTANCE_VARIABLE_BARE,
|
162
167
|
PM_ERR_INVALID_BLOCK_EXIT,
|
163
168
|
PM_ERR_INVALID_CHARACTER,
|
164
169
|
PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
|
170
|
+
PM_ERR_INVALID_ESCAPE_CHARACTER,
|
165
171
|
PM_ERR_INVALID_FLOAT_EXPONENT,
|
166
172
|
PM_ERR_INVALID_LOCAL_VARIABLE_READ,
|
167
173
|
PM_ERR_INVALID_LOCAL_VARIABLE_WRITE,
|
@@ -170,16 +176,19 @@ typedef enum {
|
|
170
176
|
PM_ERR_INVALID_MULTIBYTE_ESCAPE,
|
171
177
|
PM_ERR_INVALID_NUMBER_BINARY,
|
172
178
|
PM_ERR_INVALID_NUMBER_DECIMAL,
|
179
|
+
PM_ERR_INVALID_NUMBER_FRACTION,
|
173
180
|
PM_ERR_INVALID_NUMBER_HEXADECIMAL,
|
174
181
|
PM_ERR_INVALID_NUMBER_OCTAL,
|
175
|
-
|
182
|
+
PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER,
|
183
|
+
PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING,
|
176
184
|
PM_ERR_INVALID_PERCENT,
|
177
185
|
PM_ERR_INVALID_PRINTABLE_CHARACTER,
|
178
186
|
PM_ERR_INVALID_RETRY_AFTER_ELSE,
|
179
187
|
PM_ERR_INVALID_RETRY_AFTER_ENSURE,
|
180
188
|
PM_ERR_INVALID_RETRY_WITHOUT_RESCUE,
|
189
|
+
PM_ERR_INVALID_SYMBOL,
|
181
190
|
PM_ERR_INVALID_VARIABLE_GLOBAL,
|
182
|
-
|
191
|
+
PM_ERR_INVALID_VARIABLE_GLOBAL_3_3,
|
183
192
|
PM_ERR_INVALID_YIELD,
|
184
193
|
PM_ERR_IT_NOT_ALLOWED_NUMBERED,
|
185
194
|
PM_ERR_IT_NOT_ALLOWED_ORDINARY,
|
@@ -213,6 +222,7 @@ typedef enum {
|
|
213
222
|
PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
|
214
223
|
PM_ERR_PARAMETER_BLOCK_MULTI,
|
215
224
|
PM_ERR_PARAMETER_CIRCULAR,
|
225
|
+
PM_ERR_PARAMETER_FORWARDING_AFTER_REST,
|
216
226
|
PM_ERR_PARAMETER_METHOD_NAME,
|
217
227
|
PM_ERR_PARAMETER_NAME_DUPLICATED,
|
218
228
|
PM_ERR_PARAMETER_NO_DEFAULT,
|
@@ -223,6 +233,7 @@ typedef enum {
|
|
223
233
|
PM_ERR_PARAMETER_STAR,
|
224
234
|
PM_ERR_PARAMETER_UNEXPECTED_FWD,
|
225
235
|
PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
|
236
|
+
PM_ERR_PARAMETER_UNEXPECTED_NO_KW,
|
226
237
|
PM_ERR_PATTERN_CAPTURE_DUPLICATE,
|
227
238
|
PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
|
228
239
|
PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
|
@@ -234,8 +245,10 @@ typedef enum {
|
|
234
245
|
PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
|
235
246
|
PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
|
236
247
|
PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
|
248
|
+
PM_ERR_PATTERN_HASH_IMPLICIT,
|
237
249
|
PM_ERR_PATTERN_HASH_KEY,
|
238
250
|
PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
|
251
|
+
PM_ERR_PATTERN_HASH_KEY_INTERPOLATED,
|
239
252
|
PM_ERR_PATTERN_HASH_KEY_LABEL,
|
240
253
|
PM_ERR_PATTERN_HASH_KEY_LOCALS,
|
241
254
|
PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
|
@@ -276,6 +289,9 @@ typedef enum {
|
|
276
289
|
PM_ERR_UNARY_RECEIVER,
|
277
290
|
PM_ERR_UNDEF_ARGUMENT,
|
278
291
|
PM_ERR_UNEXPECTED_BLOCK_ARGUMENT,
|
292
|
+
PM_ERR_UNEXPECTED_INDEX_BLOCK,
|
293
|
+
PM_ERR_UNEXPECTED_INDEX_KEYWORDS,
|
294
|
+
PM_ERR_UNEXPECTED_SAFE_NAVIGATION,
|
279
295
|
PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT,
|
280
296
|
PM_ERR_UNEXPECTED_TOKEN_IGNORE,
|
281
297
|
PM_ERR_UNTIL_TERM,
|
@@ -296,7 +312,7 @@ typedef enum {
|
|
296
312
|
PM_WARN_COMPARISON_AFTER_COMPARISON,
|
297
313
|
PM_WARN_DOT_DOT_DOT_EOL,
|
298
314
|
PM_WARN_EQUAL_IN_CONDITIONAL,
|
299
|
-
|
315
|
+
PM_WARN_EQUAL_IN_CONDITIONAL_3_3,
|
300
316
|
PM_WARN_END_IN_METHOD,
|
301
317
|
PM_WARN_DUPLICATED_HASH_KEY,
|
302
318
|
PM_WARN_DUPLICATED_WHEN_CLAUSE,
|
@@ -309,6 +325,7 @@ typedef enum {
|
|
309
325
|
PM_WARN_KEYWORD_EOL,
|
310
326
|
PM_WARN_LITERAL_IN_CONDITION_DEFAULT,
|
311
327
|
PM_WARN_LITERAL_IN_CONDITION_VERBOSE,
|
328
|
+
PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE,
|
312
329
|
PM_WARN_SHEBANG_CARRIAGE_RETURN,
|
313
330
|
PM_WARN_UNEXPECTED_CARRIAGE_RETURN,
|
314
331
|
PM_WARN_UNREACHABLE_STATEMENT,
|
data/include/prism/options.h
CHANGED
@@ -49,8 +49,8 @@ typedef enum {
|
|
49
49
|
/** The current version of prism. */
|
50
50
|
PM_OPTIONS_VERSION_LATEST = 0,
|
51
51
|
|
52
|
-
/** The vendored version of prism in CRuby 3.3.
|
53
|
-
|
52
|
+
/** The vendored version of prism in CRuby 3.3.x. */
|
53
|
+
PM_OPTIONS_VERSION_CRUBY_3_3 = 1
|
54
54
|
} pm_options_version_t;
|
55
55
|
|
56
56
|
/**
|
data/include/prism/parser.h
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
#include "prism/ast.h"
|
11
11
|
#include "prism/encoding.h"
|
12
12
|
#include "prism/options.h"
|
13
|
+
#include "prism/static_literals.h"
|
13
14
|
#include "prism/util/pm_constant_pool.h"
|
14
15
|
#include "prism/util/pm_list.h"
|
15
16
|
#include "prism/util/pm_newline_list.h"
|
@@ -717,6 +718,15 @@ struct pm_parser {
|
|
717
718
|
/** The current parsing context. */
|
718
719
|
pm_context_node_t *current_context;
|
719
720
|
|
721
|
+
/**
|
722
|
+
* The hash keys for the hash that is currently being parsed. This is not
|
723
|
+
* usually necessary because it can pass it down the various call chains,
|
724
|
+
* but in the event that you're parsing a hash that is being directly
|
725
|
+
* pushed into another hash with **, we need to share the hash keys so that
|
726
|
+
* we can warn for the nested hash as well.
|
727
|
+
*/
|
728
|
+
pm_static_literals_t *current_hash_keys;
|
729
|
+
|
720
730
|
/**
|
721
731
|
* The encoding functions for the current file is attached to the parser as
|
722
732
|
* it's parsing so that it can change with a magic comment.
|
@@ -8,8 +8,7 @@
|
|
8
8
|
|
9
9
|
#include "prism/defines.h"
|
10
10
|
#include "prism/ast.h"
|
11
|
-
#include "prism/
|
12
|
-
#include "prism/parser.h"
|
11
|
+
#include "prism/util/pm_newline_list.h"
|
13
12
|
|
14
13
|
#include <assert.h>
|
15
14
|
#include <stdbool.h>
|
@@ -92,12 +91,13 @@ typedef struct {
|
|
92
91
|
/**
|
93
92
|
* Add a node to the set of static literals.
|
94
93
|
*
|
95
|
-
* @param
|
94
|
+
* @param newline_list The list of newline offsets to use to calculate lines.
|
95
|
+
* @param start_line The line number that the parser starts on.
|
96
96
|
* @param literals The set of static literals to add the node to.
|
97
97
|
* @param node The node to add to the set.
|
98
98
|
* @return A pointer to the node that is being overwritten, if there is one.
|
99
99
|
*/
|
100
|
-
pm_node_t * pm_static_literals_add(const
|
100
|
+
pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node);
|
101
101
|
|
102
102
|
/**
|
103
103
|
* Free the internal memory associated with the given static literals set.
|
@@ -110,9 +110,11 @@ void pm_static_literals_free(pm_static_literals_t *literals);
|
|
110
110
|
* Create a string-based representation of the given static literal.
|
111
111
|
*
|
112
112
|
* @param buffer The buffer to write the string to.
|
113
|
-
* @param
|
113
|
+
* @param newline_list The list of newline offsets to use to calculate lines.
|
114
|
+
* @param start_line The line number that the parser starts on.
|
115
|
+
* @param encoding_name The name of the encoding of the source being parsed.
|
114
116
|
* @param node The node to create a string representation of.
|
115
117
|
*/
|
116
|
-
PRISM_EXPORTED_FUNCTION void pm_static_literal_inspect(pm_buffer_t *buffer, const
|
118
|
+
PRISM_EXPORTED_FUNCTION void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
|
117
119
|
|
118
120
|
#endif
|
data/include/prism/version.h
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
/**
|
15
15
|
* The minor version of the Prism library as an int.
|
16
16
|
*/
|
17
|
-
#define PRISM_VERSION_MINOR
|
17
|
+
#define PRISM_VERSION_MINOR 29
|
18
18
|
|
19
19
|
/**
|
20
20
|
* The patch version of the Prism library as an int.
|
@@ -24,6 +24,6 @@
|
|
24
24
|
/**
|
25
25
|
* The version of the Prism library as a constant string.
|
26
26
|
*/
|
27
|
-
#define PRISM_VERSION "0.
|
27
|
+
#define PRISM_VERSION "0.29.0"
|
28
28
|
|
29
29
|
#endif
|
@@ -73,7 +73,7 @@ module Prism
|
|
73
73
|
|
74
74
|
# Desugar `x += y` to `x = x + y`
|
75
75
|
def compile
|
76
|
-
|
76
|
+
binary_operator_loc = node.binary_operator_loc.chop
|
77
77
|
|
78
78
|
write_class.new(
|
79
79
|
source,
|
@@ -84,15 +84,15 @@ module Prism
|
|
84
84
|
0,
|
85
85
|
read_class.new(source, *arguments, node.name_loc),
|
86
86
|
nil,
|
87
|
-
|
88
|
-
|
87
|
+
binary_operator_loc.slice.to_sym,
|
88
|
+
binary_operator_loc,
|
89
89
|
nil,
|
90
90
|
ArgumentsNode.new(source, 0, [node.value], node.value.location),
|
91
91
|
nil,
|
92
92
|
nil,
|
93
93
|
node.location
|
94
94
|
),
|
95
|
-
node.
|
95
|
+
node.binary_operator_loc.copy(start_offset: node.binary_operator_loc.end_offset - 1, length: 1),
|
96
96
|
node.location
|
97
97
|
)
|
98
98
|
end
|