Skip to content

Commit 47bbccc

Browse files
committed
[GR-45043] Import Prism v1.4.0
PullRequest: truffleruby/4508
2 parents f230fa9 + 4ef81aa commit 47bbccc

File tree

321 files changed

+20357
-3407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

321 files changed

+20357
-3407
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug fixes:
88
* Fix `Range#cover?` on begin-less ranges and non-integer values (@nirvdrum, @rwstauner).
99
* Fix `Time.new` with String argument and handle nanoseconds correctly (#3836, @andrykonchin).
1010
* Fix a possible case of infinite recursion when implementing `frozen?` in a native extension (@nirvdrum).
11+
* Fix parameters forwarding to a method call executed with `Kernel#eval` (@andrykonchin).
1112

1213
Compatibility:
1314

lib/gems/specifications/default/prism-1.1.0.gemspec

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- encoding: utf-8 -*-
2+
# stub: prism 1.4.0 ruby lib
3+
# stub: ext/prism/extconf.rb
4+
5+
Gem::Specification.new do |s|
6+
s.name = "prism".freeze
7+
s.version = "1.4.0".freeze
8+
9+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
10+
s.metadata = { "allowed_push_host" => "https://rubygems.org", "changelog_uri" => "https://github.com/ruby/prism/blob/main/CHANGELOG.md", "source_code_uri" => "https://github.com/ruby/prism" } if s.respond_to? :metadata=
11+
s.require_paths = ["lib".freeze]
12+
s.authors = ["Shopify".freeze]
13+
s.date = "2025-04-01"
14+
s.email = ["ruby@shopify.com".freeze]
15+
s.extensions = ["ext/prism/extconf.rb".freeze]
16+
s.files = ["BSDmakefile".freeze, "CHANGELOG.md".freeze, "CODE_OF_CONDUCT.md".freeze, "CONTRIBUTING.md".freeze, "LICENSE.md".freeze, "Makefile".freeze, "README.md".freeze, "config.yml".freeze, "docs/build_system.md".freeze, "docs/configuration.md".freeze, "docs/cruby_compilation.md".freeze, "docs/design.md".freeze, "docs/encoding.md".freeze, "docs/fuzzing.md".freeze, "docs/heredocs.md".freeze, "docs/javascript.md".freeze, "docs/local_variable_depth.md".freeze, "docs/mapping.md".freeze, "docs/parser_translation.md".freeze, "docs/parsing_rules.md".freeze, "docs/releasing.md".freeze, "docs/relocation.md".freeze, "docs/ripper_translation.md".freeze, "docs/ruby_api.md".freeze, "docs/ruby_parser_translation.md".freeze, "docs/serialization.md".freeze, "docs/testing.md".freeze, "ext/prism/api_node.c".freeze, "ext/prism/api_pack.c".freeze, "ext/prism/extconf.rb".freeze, "ext/prism/extension.c".freeze, "ext/prism/extension.h".freeze, "include/prism.h".freeze, "include/prism/ast.h".freeze, "include/prism/defines.h".freeze, "include/prism/diagnostic.h".freeze, "include/prism/encoding.h".freeze, "include/prism/node.h".freeze, "include/prism/options.h".freeze, "include/prism/pack.h".freeze, "include/prism/parser.h".freeze, "include/prism/prettyprint.h".freeze, "include/prism/regexp.h".freeze, "include/prism/static_literals.h".freeze, "include/prism/util/pm_buffer.h".freeze, "include/prism/util/pm_char.h".freeze, "include/prism/util/pm_constant_pool.h".freeze, "include/prism/util/pm_integer.h".freeze, "include/prism/util/pm_list.h".freeze, "include/prism/util/pm_memchr.h".freeze, "include/prism/util/pm_newline_list.h".freeze, "include/prism/util/pm_string.h".freeze, "include/prism/util/pm_strncasecmp.h".freeze, "include/prism/util/pm_strpbrk.h".freeze, "include/prism/version.h".freeze, "lib/prism.rb".freeze, "lib/prism/compiler.rb".freeze, "lib/prism/desugar_compiler.rb".freeze, "lib/prism/dispatcher.rb".freeze, "lib/prism/dot_visitor.rb".freeze, "lib/prism/dsl.rb".freeze, "lib/prism/ffi.rb".freeze, "lib/prism/inspect_visitor.rb".freeze, "lib/prism/lex_compat.rb".freeze, "lib/prism/mutation_compiler.rb".freeze, "lib/prism/node.rb".freeze, "lib/prism/node_ext.rb".freeze, "lib/prism/pack.rb".freeze, "lib/prism/parse_result.rb".freeze, "lib/prism/parse_result/comments.rb".freeze, "lib/prism/parse_result/errors.rb".freeze, "lib/prism/parse_result/newlines.rb".freeze, "lib/prism/pattern.rb".freeze, "lib/prism/polyfill/append_as_bytes.rb".freeze, "lib/prism/polyfill/byteindex.rb".freeze, "lib/prism/polyfill/unpack1.rb".freeze, "lib/prism/reflection.rb".freeze, "lib/prism/relocation.rb".freeze, "lib/prism/serialize.rb".freeze, "lib/prism/string_query.rb".freeze, "lib/prism/translation.rb".freeze, "lib/prism/translation/parser.rb".freeze, "lib/prism/translation/parser/builder.rb".freeze, "lib/prism/translation/parser/compiler.rb".freeze, "lib/prism/translation/parser/lexer.rb".freeze, "lib/prism/translation/parser33.rb".freeze, "lib/prism/translation/parser34.rb".freeze, "lib/prism/translation/parser35.rb".freeze, "lib/prism/translation/ripper.rb".freeze, "lib/prism/translation/ripper/sexp.rb".freeze, "lib/prism/translation/ripper/shim.rb".freeze, "lib/prism/translation/ruby_parser.rb".freeze, "lib/prism/visitor.rb".freeze, "prism.gemspec".freeze, "rbi/prism.rbi".freeze, "rbi/prism/compiler.rbi".freeze, "rbi/prism/dsl.rbi".freeze, "rbi/prism/inspect_visitor.rbi".freeze, "rbi/prism/node.rbi".freeze, "rbi/prism/node_ext.rbi".freeze, "rbi/prism/parse_result.rbi".freeze, "rbi/prism/reflection.rbi".freeze, "rbi/prism/string_query.rbi".freeze, "rbi/prism/translation/parser.rbi".freeze, "rbi/prism/translation/parser33.rbi".freeze, "rbi/prism/translation/parser34.rbi".freeze, "rbi/prism/translation/parser35.rbi".freeze, "rbi/prism/translation/ripper.rbi".freeze, "rbi/prism/visitor.rbi".freeze, "sig/prism.rbs".freeze, "sig/prism/compiler.rbs".freeze, "sig/prism/dispatcher.rbs".freeze, "sig/prism/dot_visitor.rbs".freeze, "sig/prism/dsl.rbs".freeze, "sig/prism/inspect_visitor.rbs".freeze, "sig/prism/lex_compat.rbs".freeze, "sig/prism/mutation_compiler.rbs".freeze, "sig/prism/node.rbs".freeze, "sig/prism/node_ext.rbs".freeze, "sig/prism/pack.rbs".freeze, "sig/prism/parse_result.rbs".freeze, "sig/prism/pattern.rbs".freeze, "sig/prism/reflection.rbs".freeze, "sig/prism/relocation.rbs".freeze, "sig/prism/serialize.rbs".freeze, "sig/prism/string_query.rbs".freeze, "sig/prism/visitor.rbs".freeze, "src/diagnostic.c".freeze, "src/encoding.c".freeze, "src/node.c".freeze, "src/options.c".freeze, "src/pack.c".freeze, "src/prettyprint.c".freeze, "src/prism.c".freeze, "src/regexp.c".freeze, "src/serialize.c".freeze, "src/static_literals.c".freeze, "src/token_type.c".freeze, "src/util/pm_buffer.c".freeze, "src/util/pm_char.c".freeze, "src/util/pm_constant_pool.c".freeze, "src/util/pm_integer.c".freeze, "src/util/pm_list.c".freeze, "src/util/pm_memchr.c".freeze, "src/util/pm_newline_list.c".freeze, "src/util/pm_string.c".freeze, "src/util/pm_strncasecmp.c".freeze, "src/util/pm_strpbrk.c".freeze]
17+
s.homepage = "https://github.com/ruby/prism".freeze
18+
s.licenses = ["MIT".freeze]
19+
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0".freeze)
20+
s.rubygems_version = "3.5.16".freeze
21+
s.summary = "Prism Ruby parser".freeze
22+
end
23+

lib/mri/prism.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ module Prism
2424
autoload :Pack, "prism/pack"
2525
autoload :Pattern, "prism/pattern"
2626
autoload :Reflection, "prism/reflection"
27+
autoload :Relocation, "prism/relocation"
2728
autoload :Serialize, "prism/serialize"
29+
autoload :StringQuery, "prism/string_query"
2830
autoload :Translation, "prism/translation"
2931
autoload :Visitor, "prism/visitor"
3032

@@ -57,11 +59,11 @@ def self.lex_ripper(source)
5759
end
5860

5961
# :call-seq:
60-
# Prism::load(source, serialized) -> ParseResult
62+
# Prism::load(source, serialized, freeze) -> ParseResult
6163
#
6264
# Load the serialized AST using the source as a reference into a tree.
63-
def self.load(source, serialized)
64-
Serialize.load(source, serialized)
65+
def self.load(source, serialized, freeze = false)
66+
Serialize.load_parse(source, serialized, freeze)
6567
end
6668
end
6769

@@ -75,13 +77,13 @@ def self.load(source, serialized)
7577
# it's going to require the built library. Otherwise, it's going to require a
7678
# module that uses FFI to call into the library.
7779
if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
78-
require "prism/prism"
79-
8080
# The C extension is the default backend on CRuby.
8181
Prism::BACKEND = :CEXT
82-
else
83-
require_relative "prism/ffi"
8482

83+
require "prism/prism"
84+
else
8585
# The FFI backend is used on other Ruby implementations.
8686
Prism::BACKEND = :FFI
87+
88+
require_relative "prism/ffi"
8789
end

lib/mri/prism/dot_visitor.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,6 +3608,9 @@ def visit_parentheses_node(node)
36083608
table = Table.new("ParenthesesNode")
36093609
id = node_id(node)
36103610

3611+
# flags
3612+
table.field("flags", parentheses_node_flags_inspect(node))
3613+
36113614
# body
36123615
unless (body = node.body).nil?
36133616
table.field("body", port: true)
@@ -3954,6 +3957,11 @@ def visit_rescue_node(node)
39543957
digraph.edge("#{id}:reference -> #{node_id(reference)};")
39553958
end
39563959

3960+
# then_keyword_loc
3961+
unless (then_keyword_loc = node.then_keyword_loc).nil?
3962+
table.field("then_keyword_loc", location_inspect(then_keyword_loc))
3963+
end
3964+
39573965
# statements
39583966
unless (statements = node.statements).nil?
39593967
table.field("statements", port: true)
@@ -4414,6 +4422,11 @@ def visit_until_node(node)
44144422
# keyword_loc
44154423
table.field("keyword_loc", location_inspect(node.keyword_loc))
44164424

4425+
# do_keyword_loc
4426+
unless (do_keyword_loc = node.do_keyword_loc).nil?
4427+
table.field("do_keyword_loc", location_inspect(do_keyword_loc))
4428+
end
4429+
44174430
# closing_loc
44184431
unless (closing_loc = node.closing_loc).nil?
44194432
table.field("closing_loc", location_inspect(closing_loc))
@@ -4490,6 +4503,11 @@ def visit_while_node(node)
44904503
# keyword_loc
44914504
table.field("keyword_loc", location_inspect(node.keyword_loc))
44924505

4506+
# do_keyword_loc
4507+
unless (do_keyword_loc = node.do_keyword_loc).nil?
4508+
table.field("do_keyword_loc", location_inspect(do_keyword_loc))
4509+
end
4510+
44934511
# closing_loc
44944512
unless (closing_loc = node.closing_loc).nil?
44954513
table.field("closing_loc", location_inspect(closing_loc))
@@ -4672,6 +4690,14 @@ def parameter_flags_inspect(node)
46724690
flags.join(", ")
46734691
end
46744692

4693+
# Inspect a node that has parentheses_node_flags flags to display the flags as a
4694+
# comma-separated list.
4695+
def parentheses_node_flags_inspect(node)
4696+
flags = [] #: Array[String]
4697+
flags << "multiple_statements" if node.multiple_statements?
4698+
flags.join(", ")
4699+
end
4700+
46754701
# Inspect a node that has range_flags flags to display the flags as a
46764702
# comma-separated list.
46774703
def range_flags_inspect(node)

lib/mri/prism/dsl.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ def rescue_modifier_node(source: default_source, node_id: 0, location: default_l
714714
end
715715

716716
# Create a new RescueNode node.
717-
def rescue_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, exceptions: [], operator_loc: nil, reference: nil, statements: nil, subsequent: nil)
718-
RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent)
717+
def rescue_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, exceptions: [], operator_loc: nil, reference: nil, then_keyword_loc: nil, statements: nil, subsequent: nil)
718+
RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
719719
end
720720

721721
# Create a new RestParameterNode node.
@@ -804,8 +804,8 @@ def unless_node(source: default_source, node_id: 0, location: default_location,
804804
end
805805

806806
# Create a new UntilNode node.
807-
def until_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, closing_loc: nil, predicate: default_node(source, location), statements: nil)
808-
UntilNode.new(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements)
807+
def until_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, do_keyword_loc: nil, closing_loc: nil, predicate: default_node(source, location), statements: nil)
808+
UntilNode.new(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements)
809809
end
810810

811811
# Create a new WhenNode node.
@@ -814,8 +814,8 @@ def when_node(source: default_source, node_id: 0, location: default_location, fl
814814
end
815815

816816
# Create a new WhileNode node.
817-
def while_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, closing_loc: nil, predicate: default_node(source, location), statements: nil)
818-
WhileNode.new(source, node_id, location, flags, keyword_loc, closing_loc, predicate, statements)
817+
def while_node(source: default_source, node_id: 0, location: default_location, flags: 0, keyword_loc: location, do_keyword_loc: nil, closing_loc: nil, predicate: default_node(source, location), statements: nil)
818+
WhileNode.new(source, node_id, location, flags, keyword_loc, do_keyword_loc, closing_loc, predicate, statements)
819819
end
820820

821821
# Create a new XStringNode node.
@@ -912,6 +912,14 @@ def parameter_flag(name)
912912
end
913913
end
914914

915+
# Retrieve the value of one of the ParenthesesNodeFlags flags.
916+
def parentheses_node_flag(name)
917+
case name
918+
when :multiple_statements then ParenthesesNodeFlags::MULTIPLE_STATEMENTS
919+
else Kernel.raise ArgumentError, "invalid ParenthesesNodeFlags flag: #{name.inspect}"
920+
end
921+
end
922+
915923
# Retrieve the value of one of the RangeFlags flags.
916924
def range_flag(name)
917925
case name

0 commit comments

Comments
 (0)