prism 0.29.0 → 1.3.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 +115 -1
- data/CONTRIBUTING.md +0 -4
- data/Makefile +1 -1
- data/README.md +4 -0
- data/config.yml +920 -148
- data/docs/build_system.md +8 -11
- data/docs/fuzzing.md +1 -1
- data/docs/parsing_rules.md +4 -1
- data/docs/relocation.md +34 -0
- data/docs/ripper_translation.md +22 -0
- data/docs/serialization.md +3 -0
- data/ext/prism/api_node.c +2863 -2079
- data/ext/prism/extconf.rb +14 -37
- data/ext/prism/extension.c +241 -391
- data/ext/prism/extension.h +2 -2
- data/include/prism/ast.h +2156 -453
- data/include/prism/defines.h +58 -7
- data/include/prism/diagnostic.h +24 -6
- data/include/prism/node.h +0 -21
- data/include/prism/options.h +94 -3
- data/include/prism/parser.h +82 -40
- data/include/prism/regexp.h +18 -8
- data/include/prism/static_literals.h +3 -2
- data/include/prism/util/pm_char.h +1 -2
- data/include/prism/util/pm_constant_pool.h +0 -8
- data/include/prism/util/pm_integer.h +22 -15
- data/include/prism/util/pm_newline_list.h +11 -0
- data/include/prism/util/pm_string.h +28 -12
- data/include/prism/version.h +3 -3
- data/include/prism.h +47 -11
- data/lib/prism/compiler.rb +3 -0
- data/lib/prism/desugar_compiler.rb +111 -74
- data/lib/prism/dispatcher.rb +16 -1
- data/lib/prism/dot_visitor.rb +55 -34
- data/lib/prism/dsl.rb +660 -468
- data/lib/prism/ffi.rb +113 -8
- data/lib/prism/inspect_visitor.rb +296 -64
- data/lib/prism/lex_compat.rb +1 -1
- data/lib/prism/mutation_compiler.rb +11 -6
- data/lib/prism/node.rb +4262 -5023
- data/lib/prism/node_ext.rb +91 -14
- data/lib/prism/parse_result/comments.rb +0 -7
- data/lib/prism/parse_result/errors.rb +65 -0
- data/lib/prism/parse_result/newlines.rb +101 -11
- data/lib/prism/parse_result.rb +183 -6
- data/lib/prism/reflection.rb +12 -10
- data/lib/prism/relocation.rb +504 -0
- data/lib/prism/serialize.rb +496 -609
- data/lib/prism/string_query.rb +30 -0
- data/lib/prism/translation/parser/compiler.rb +185 -155
- data/lib/prism/translation/parser/lexer.rb +26 -4
- data/lib/prism/translation/parser.rb +9 -4
- data/lib/prism/translation/ripper.rb +23 -25
- data/lib/prism/translation/ruby_parser.rb +86 -17
- data/lib/prism/visitor.rb +3 -0
- data/lib/prism.rb +6 -8
- data/prism.gemspec +9 -5
- data/rbi/prism/dsl.rbi +521 -0
- data/rbi/prism/node.rbi +1115 -1120
- data/rbi/prism/parse_result.rbi +29 -0
- data/rbi/prism/string_query.rbi +12 -0
- data/rbi/prism/visitor.rbi +3 -0
- data/rbi/prism.rbi +36 -30
- data/sig/prism/dsl.rbs +190 -303
- data/sig/prism/mutation_compiler.rbs +1 -0
- data/sig/prism/node.rbs +678 -632
- data/sig/prism/parse_result.rbs +22 -0
- data/sig/prism/relocation.rbs +185 -0
- data/sig/prism/string_query.rbs +11 -0
- data/sig/prism/visitor.rbs +1 -0
- data/sig/prism.rbs +103 -64
- data/src/diagnostic.c +64 -28
- data/src/node.c +502 -1739
- data/src/options.c +76 -27
- data/src/prettyprint.c +188 -112
- data/src/prism.c +3376 -2293
- data/src/regexp.c +208 -71
- data/src/serialize.c +182 -50
- data/src/static_literals.c +64 -85
- data/src/token_type.c +4 -4
- data/src/util/pm_char.c +1 -1
- data/src/util/pm_constant_pool.c +0 -8
- data/src/util/pm_integer.c +53 -25
- data/src/util/pm_newline_list.c +29 -0
- data/src/util/pm_string.c +131 -80
- data/src/util/pm_strpbrk.c +32 -6
- metadata +11 -7
- data/include/prism/util/pm_string_list.h +0 -44
- data/lib/prism/debug.rb +0 -249
- data/lib/prism/translation/parser/rubocop.rb +0 -73
- data/src/util/pm_string_list.c +0 -28
data/lib/prism/dispatcher.rb
CHANGED
@@ -22,7 +22,8 @@ module Prism
|
|
22
22
|
# end
|
23
23
|
# end
|
24
24
|
#
|
25
|
-
#
|
25
|
+
# listener = OctalListener.new
|
26
|
+
# dispatcher = Prism::Dispatcher.new
|
26
27
|
# dispatcher.register(listener, :on_integer_node_enter)
|
27
28
|
#
|
28
29
|
# Then, you can walk any number of trees and dispatch events to the listeners:
|
@@ -762,6 +763,14 @@ module Prism
|
|
762
763
|
listeners[:on_interpolated_x_string_node_leave]&.each { |listener| listener.on_interpolated_x_string_node_leave(node) }
|
763
764
|
end
|
764
765
|
|
766
|
+
# Dispatch enter and leave events for ItLocalVariableReadNode nodes and continue
|
767
|
+
# walking the tree.
|
768
|
+
def visit_it_local_variable_read_node(node)
|
769
|
+
listeners[:on_it_local_variable_read_node_enter]&.each { |listener| listener.on_it_local_variable_read_node_enter(node) }
|
770
|
+
super
|
771
|
+
listeners[:on_it_local_variable_read_node_leave]&.each { |listener| listener.on_it_local_variable_read_node_leave(node) }
|
772
|
+
end
|
773
|
+
|
765
774
|
# Dispatch enter and leave events for ItParametersNode nodes and continue
|
766
775
|
# walking the tree.
|
767
776
|
def visit_it_parameters_node(node)
|
@@ -1795,6 +1804,12 @@ module Prism
|
|
1795
1804
|
listeners[:on_interpolated_x_string_node_leave]&.each { |listener| listener.on_interpolated_x_string_node_leave(node) }
|
1796
1805
|
end
|
1797
1806
|
|
1807
|
+
# Dispatch enter and leave events for ItLocalVariableReadNode nodes.
|
1808
|
+
def visit_it_local_variable_read_node(node)
|
1809
|
+
listeners[:on_it_local_variable_read_node_enter]&.each { |listener| listener.on_it_local_variable_read_node_enter(node) }
|
1810
|
+
listeners[:on_it_local_variable_read_node_leave]&.each { |listener| listener.on_it_local_variable_read_node_leave(node) }
|
1811
|
+
end
|
1812
|
+
|
1798
1813
|
# Dispatch enter and leave events for ItParametersNode nodes.
|
1799
1814
|
def visit_it_parameters_node(node)
|
1800
1815
|
listeners[:on_it_parameters_node_enter]&.each { |listener| listener.on_it_parameters_node_enter(node) }
|
data/lib/prism/dot_visitor.rb
CHANGED
@@ -909,10 +909,10 @@ module Prism
|
|
909
909
|
table.field("conditions", "[]")
|
910
910
|
end
|
911
911
|
|
912
|
-
#
|
913
|
-
unless (
|
914
|
-
table.field("
|
915
|
-
digraph.edge("#{id}:
|
912
|
+
# else_clause
|
913
|
+
unless (else_clause = node.else_clause).nil?
|
914
|
+
table.field("else_clause", port: true)
|
915
|
+
digraph.edge("#{id}:else_clause -> #{node_id(else_clause)};")
|
916
916
|
end
|
917
917
|
|
918
918
|
# case_keyword_loc
|
@@ -954,10 +954,10 @@ module Prism
|
|
954
954
|
table.field("conditions", "[]")
|
955
955
|
end
|
956
956
|
|
957
|
-
#
|
958
|
-
unless (
|
959
|
-
table.field("
|
960
|
-
digraph.edge("#{id}:
|
957
|
+
# else_clause
|
958
|
+
unless (else_clause = node.else_clause).nil?
|
959
|
+
table.field("else_clause", port: true)
|
960
|
+
digraph.edge("#{id}:else_clause -> #{node_id(else_clause)};")
|
961
961
|
end
|
962
962
|
|
963
963
|
# case_keyword_loc
|
@@ -2130,10 +2130,10 @@ module Prism
|
|
2130
2130
|
digraph.edge("#{id}:statements -> #{node_id(statements)};")
|
2131
2131
|
end
|
2132
2132
|
|
2133
|
-
#
|
2134
|
-
unless (
|
2135
|
-
table.field("
|
2136
|
-
digraph.edge("#{id}:
|
2133
|
+
# subsequent
|
2134
|
+
unless (subsequent = node.subsequent).nil?
|
2135
|
+
table.field("subsequent", port: true)
|
2136
|
+
digraph.edge("#{id}:subsequent -> #{node_id(subsequent)};")
|
2137
2137
|
end
|
2138
2138
|
|
2139
2139
|
# end_keyword_loc
|
@@ -2780,6 +2780,20 @@ module Prism
|
|
2780
2780
|
super
|
2781
2781
|
end
|
2782
2782
|
|
2783
|
+
# Visit a ItLocalVariableReadNode node.
|
2784
|
+
def visit_it_local_variable_read_node(node)
|
2785
|
+
table = Table.new("ItLocalVariableReadNode")
|
2786
|
+
id = node_id(node)
|
2787
|
+
|
2788
|
+
digraph.nodes << <<~DOT
|
2789
|
+
#{id} [
|
2790
|
+
label=<#{table.to_dot.gsub(/\n/, "\n ")}>
|
2791
|
+
];
|
2792
|
+
DOT
|
2793
|
+
|
2794
|
+
super
|
2795
|
+
end
|
2796
|
+
|
2783
2797
|
# Visit a ItParametersNode node.
|
2784
2798
|
def visit_it_parameters_node(node)
|
2785
2799
|
table = Table.new("ItParametersNode")
|
@@ -3779,9 +3793,14 @@ module Prism
|
|
3779
3793
|
table = Table.new("RationalNode")
|
3780
3794
|
id = node_id(node)
|
3781
3795
|
|
3782
|
-
#
|
3783
|
-
table.field("
|
3784
|
-
|
3796
|
+
# flags
|
3797
|
+
table.field("flags", integer_base_flags_inspect(node))
|
3798
|
+
|
3799
|
+
# numerator
|
3800
|
+
table.field("numerator", node.numerator.inspect)
|
3801
|
+
|
3802
|
+
# denominator
|
3803
|
+
table.field("denominator", node.denominator.inspect)
|
3785
3804
|
|
3786
3805
|
digraph.nodes << <<~DOT
|
3787
3806
|
#{id} [
|
@@ -3941,10 +3960,10 @@ module Prism
|
|
3941
3960
|
digraph.edge("#{id}:statements -> #{node_id(statements)};")
|
3942
3961
|
end
|
3943
3962
|
|
3944
|
-
#
|
3945
|
-
unless (
|
3946
|
-
table.field("
|
3947
|
-
digraph.edge("#{id}:
|
3963
|
+
# subsequent
|
3964
|
+
unless (subsequent = node.subsequent).nil?
|
3965
|
+
table.field("subsequent", port: true)
|
3966
|
+
digraph.edge("#{id}:subsequent -> #{node_id(subsequent)};")
|
3948
3967
|
end
|
3949
3968
|
|
3950
3969
|
digraph.nodes << <<~DOT
|
@@ -4003,9 +4022,6 @@ module Prism
|
|
4003
4022
|
table = Table.new("ReturnNode")
|
4004
4023
|
id = node_id(node)
|
4005
4024
|
|
4006
|
-
# flags
|
4007
|
-
table.field("flags", return_node_flags_inspect(node))
|
4008
|
-
|
4009
4025
|
# keyword_loc
|
4010
4026
|
table.field("keyword_loc", location_inspect(node.keyword_loc))
|
4011
4027
|
|
@@ -4367,10 +4383,10 @@ module Prism
|
|
4367
4383
|
digraph.edge("#{id}:statements -> #{node_id(statements)};")
|
4368
4384
|
end
|
4369
4385
|
|
4370
|
-
#
|
4371
|
-
unless (
|
4372
|
-
table.field("
|
4373
|
-
digraph.edge("#{id}:
|
4386
|
+
# else_clause
|
4387
|
+
unless (else_clause = node.else_clause).nil?
|
4388
|
+
table.field("else_clause", port: true)
|
4389
|
+
digraph.edge("#{id}:else_clause -> #{node_id(else_clause)};")
|
4374
4390
|
end
|
4375
4391
|
|
4376
4392
|
# end_keyword_loc
|
@@ -4398,6 +4414,11 @@ module Prism
|
|
4398
4414
|
# keyword_loc
|
4399
4415
|
table.field("keyword_loc", location_inspect(node.keyword_loc))
|
4400
4416
|
|
4417
|
+
# do_keyword_loc
|
4418
|
+
unless (do_keyword_loc = node.do_keyword_loc).nil?
|
4419
|
+
table.field("do_keyword_loc", location_inspect(do_keyword_loc))
|
4420
|
+
end
|
4421
|
+
|
4401
4422
|
# closing_loc
|
4402
4423
|
unless (closing_loc = node.closing_loc).nil?
|
4403
4424
|
table.field("closing_loc", location_inspect(closing_loc))
|
@@ -4474,6 +4495,11 @@ module Prism
|
|
4474
4495
|
# keyword_loc
|
4475
4496
|
table.field("keyword_loc", location_inspect(node.keyword_loc))
|
4476
4497
|
|
4498
|
+
# do_keyword_loc
|
4499
|
+
unless (do_keyword_loc = node.do_keyword_loc).nil?
|
4500
|
+
table.field("do_keyword_loc", location_inspect(do_keyword_loc))
|
4501
|
+
end
|
4502
|
+
|
4477
4503
|
# closing_loc
|
4478
4504
|
unless (closing_loc = node.closing_loc).nil?
|
4479
4505
|
table.field("closing_loc", location_inspect(closing_loc))
|
@@ -4576,8 +4602,11 @@ module Prism
|
|
4576
4602
|
# comma-separated list.
|
4577
4603
|
def arguments_node_flags_inspect(node)
|
4578
4604
|
flags = [] #: Array[String]
|
4605
|
+
flags << "contains_forwarding" if node.contains_forwarding?
|
4579
4606
|
flags << "contains_keywords" if node.contains_keywords?
|
4580
4607
|
flags << "contains_keyword_splat" if node.contains_keyword_splat?
|
4608
|
+
flags << "contains_splat" if node.contains_splat?
|
4609
|
+
flags << "contains_multiple_splats" if node.contains_multiple_splats?
|
4581
4610
|
flags.join(", ")
|
4582
4611
|
end
|
4583
4612
|
|
@@ -4679,14 +4708,6 @@ module Prism
|
|
4679
4708
|
flags.join(", ")
|
4680
4709
|
end
|
4681
4710
|
|
4682
|
-
# Inspect a node that has return_node_flags flags to display the flags as a
|
4683
|
-
# comma-separated list.
|
4684
|
-
def return_node_flags_inspect(node)
|
4685
|
-
flags = [] #: Array[String]
|
4686
|
-
flags << "redundant" if node.redundant?
|
4687
|
-
flags.join(", ")
|
4688
|
-
end
|
4689
|
-
|
4690
4711
|
# Inspect a node that has shareable_constant_node_flags flags to display the flags as a
|
4691
4712
|
# comma-separated list.
|
4692
4713
|
def shareable_constant_node_flags_inspect(node)
|