[ruby/prism] Use partial_script for the parser translators

Followup to https://github.com/ruby/prism/pull/3079

https://github.com/ruby/prism/commit/68f434e356
This commit is contained in:
Earlopain 2024-10-03 13:34:57 +02:00 committed by git
parent cd96af2cb8
commit 66124cdb17
3 changed files with 6 additions and 10 deletions

View File

@ -51,7 +51,7 @@ module Prism
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 @@ module Prism
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 @@ module Prism
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

View File

@ -3269,11 +3269,7 @@ module Prism
# 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
##########################################################################

View File

@ -1596,13 +1596,13 @@ module Prism
# 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