From 68f434e3568bfe108b2b0bee22a6f56c42dbffdb Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:34:57 +0200 Subject: [PATCH] Use `partial_script` for the parser translators Followup to https://github.com/ruby/prism/pull/3079 --- lib/prism/translation/parser.rb | 6 +++--- lib/prism/translation/ripper.rb | 6 +----- lib/prism/translation/ruby_parser.rb | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/prism/translation/parser.rb b/lib/prism/translation/parser.rb index 8c7eb3aa752..969f2b95b0e 100644 --- a/lib/prism/translation/parser.rb +++ b/lib/prism/translation/parser.rb @@ -51,7 +51,7 @@ def parse(source_buffer) source = source_buffer.source offset_cache = build_offset_cache(source) - result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), scopes: [[]], encoding: false), offset_cache) + result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), partial_script: true, encoding: false), offset_cache) build_ast(result.value, offset_cache) ensure @@ -64,7 +64,7 @@ def parse_with_comments(source_buffer) source = source_buffer.source offset_cache = build_offset_cache(source) - result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), scopes: [[]], encoding: false), offset_cache) + result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version), partial_script: true, encoding: false), offset_cache) [ build_ast(result.value, offset_cache), @@ -83,7 +83,7 @@ def tokenize(source_buffer, recover = false) offset_cache = build_offset_cache(source) result = begin - unwrap(Prism.parse_lex(source, filepath: source_buffer.name, version: convert_for_prism(version), scopes: [[]], encoding: false), offset_cache) + unwrap(Prism.parse_lex(source, filepath: source_buffer.name, version: convert_for_prism(version), partial_script: true, encoding: false), offset_cache) rescue ::Parser::SyntaxError raise if !recover end diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index cafe8c3f633..018842715b0 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -3269,11 +3269,7 @@ def visit_yield_node(node) # Lazily initialize the parse result. def result - @result ||= - begin - scopes = RUBY_VERSION >= "3.3.0" ? [] : [[]] - Prism.parse(source, scopes: scopes) - end + @result ||= Prism.parse(source, partial_script: true) end ########################################################################## diff --git a/lib/prism/translation/ruby_parser.rb b/lib/prism/translation/ruby_parser.rb index 4ccff0b600e..189038d008d 100644 --- a/lib/prism/translation/ruby_parser.rb +++ b/lib/prism/translation/ruby_parser.rb @@ -1596,13 +1596,13 @@ def visit_write_value(node) # Parse the given source and translate it into the seattlerb/ruby_parser # gem's Sexp format. def parse(source, filepath = "(string)") - translate(Prism.parse(source, filepath: filepath, scopes: [[]]), filepath) + translate(Prism.parse(source, filepath: filepath, partial_script: true), filepath) end # Parse the given file and translate it into the seattlerb/ruby_parser # gem's Sexp format. def parse_file(filepath) - translate(Prism.parse_file(filepath, scopes: [[]]), filepath) + translate(Prism.parse_file(filepath, partial_script: true), filepath) end class << self