[ruby/prism] Rename Ruby 3.5 to Ruby 4.0

See 6d81969b47

It leaves the old variant around. RuboCop for examples accesses `Prism::Translation::Parser35`
to test against ruby-head. For now I left these simply as an alias

https://github.com/ruby/prism/commit/d0a823f045
This commit is contained in:
Earlopain 2025-11-07 13:14:07 +01:00 committed by git
parent a7c23b9a9f
commit 7037d8f89e
21 changed files with 54 additions and 50 deletions

View File

@ -432,10 +432,8 @@ module Prism
1
when /\A3\.4(\.\d+)?\z/
2
when /\A3\.5(\.\d+)?\z/
when /\A3\.5(\.\d+)?\z/, /\A4\.0(\.\d+)?\z/
3
when /\A4\.0(\.\d+)?\z/
4
else
if current
raise CurrentVersionError, RUBY_VERSION

View File

@ -101,6 +101,7 @@ Gem::Specification.new do |spec|
"lib/prism/translation/parser33.rb",
"lib/prism/translation/parser34.rb",
"lib/prism/translation/parser35.rb",
"lib/prism/translation/parser40.rb",
"lib/prism/translation/parser/builder.rb",
"lib/prism/translation/parser/compiler.rb",
"lib/prism/translation/parser/lexer.rb",
@ -123,6 +124,7 @@ Gem::Specification.new do |spec|
"rbi/prism/translation/parser33.rbi",
"rbi/prism/translation/parser34.rbi",
"rbi/prism/translation/parser35.rbi",
"rbi/prism/translation/parser40.rbi",
"rbi/prism/translation/ripper.rbi",
"rbi/prism/visitor.rbi",
"sig/prism.rbs",

View File

@ -10,6 +10,7 @@ module Prism
autoload :Parser33, "prism/translation/parser33"
autoload :Parser34, "prism/translation/parser34"
autoload :Parser35, "prism/translation/parser35"
autoload :Parser40, "prism/translation/parser40"
autoload :Ripper, "prism/translation/ripper"
autoload :RubyParser, "prism/translation/ruby_parser"
end

View File

@ -84,7 +84,7 @@ module Prism
end
def version # :nodoc:
35
40
end
# The default encoding for Ruby files is UTF-8.
@ -356,8 +356,8 @@ module Prism
"3.3.1"
when 34
"3.4.0"
when 35
"3.5.0"
when 35, 40
"4.0.0"
else
"latest"
end

View File

@ -3,11 +3,6 @@
module Prism
module Translation
# This class is the entry-point for Ruby 3.5 of `Prism::Translation::Parser`.
class Parser35 < Parser
def version # :nodoc:
35
end
end
Parser35 = Parser40 # :nodoc:
end
end

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
# :markup: markdown
module Prism
module Translation
# This class is the entry-point for Ruby 4.0 of `Prism::Translation::Parser`.
class Parser40 < Parser
def version # :nodoc:
40
end
end
end
end

View File

@ -10,8 +10,8 @@ module Prism
ParserCurrent = Parser33
when /^3\.4\./
ParserCurrent = Parser34
when /^3\.5\./
ParserCurrent = Parser35
when /^3\.5\./, /^4\.0\./
ParserCurrent = Parser40
else
# Keep this in sync with released Ruby.
parser = Parser34

View File

@ -88,12 +88,7 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
return true;
}
if (strncmp(version, "3.5", 3) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
return true;
}
if (strncmp(version, "4.0", 3) == 0) {
if (strncmp(version, "3.5", 3) == 0 || strncmp(version, "4.0", 3) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
return true;
}
@ -101,23 +96,18 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
return false;
}
if (length >= 4) {
if (strncmp(version, "3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
if (length >= 4 && is_number(version + 4, length - 4)) {
if (strncmp(version, "3.3.", 4) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
return true;
}
if (strncmp(version, "3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
if (strncmp(version, "3.4.", 4) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_3_4;
return true;
}
if (strncmp(version, "3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
return true;
}
if (strncmp(version, "4.0.", 4) == 0 && is_number(version + 4, length - 4)) {
if (strncmp(version, "3.5.", 4) == 0 || strncmp(version, "4.0.", 4) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
return true;
}

View File

@ -91,11 +91,11 @@ typedef enum {
/** The vendored version of prism in CRuby 3.4.x. */
PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
/** The vendored version of prism in CRuby 3.5.x. */
/** The vendored version of prism in CRuby 4.0.x. */
PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
/** The vendored version of prism in CRuby 4.0.x. */
PM_OPTIONS_VERSION_CRUBY_4_0 = 4,
PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
/** The current version of prism. */
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_0

View File

@ -10864,11 +10864,11 @@ parser_lex(pm_parser_t *parser) {
}
// If we are parsing as CRuby 3.5 or later and we
// If we are parsing as CRuby 4.0 or later and we
// hit a '&&' or a '||' then we will lex the ignored
// newline.
if (
(parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) &&
(parser->version >= PM_OPTIONS_VERSION_CRUBY_4_0) &&
following && (
(peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '&') ||
(peek_at(parser, following) == '|' && peek_at(parser, following + 1) == '|') ||
@ -10915,7 +10915,7 @@ parser_lex(pm_parser_t *parser) {
LEX(PM_TOKEN_AMPERSAND_DOT);
}
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) {
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_4_0) {
// If we hit an && then we are in a logical chain
// and we need to return the logical operator.
if (peek_at(parser, next_content) == '&' && peek_at(parser, next_content + 1) == '&') {
@ -19625,7 +19625,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
statements = (pm_node_t *) pm_statements_node_create(parser);
bool allow_command_call;
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) {
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_4_0) {
allow_command_call = accepts_command_call;
} else {
// Allow `def foo = puts "Hello"` but not `private def foo = puts "Hello"`

View File

@ -119,6 +119,9 @@ module Prism
assert Prism.parse_success?("1 + 1", version: "3.5")
assert Prism.parse_success?("1 + 1", version: "3.5.0")
assert Prism.parse_success?("1 + 1", version: "4.0")
assert Prism.parse_success?("1 + 1", version: "4.0.0")
assert Prism.parse_success?("1 + 1", version: "latest")
# Test edge case

View File

@ -35,8 +35,8 @@ module Prism
except << "3.3-3.3/return_in_sclass.txt"
# Leaving these out until they are supported by parse.y.
except << "3.5/leading_logical.txt"
except << "3.5/endless_methods_command_call.txt"
except << "4.0/leading_logical.txt"
except << "4.0/endless_methods_command_call.txt"
# https://bugs.ruby-lang.org/issues/21168#note-5
except << "command_method_call_2.txt"

View File

@ -43,10 +43,10 @@ module Prism
end
# https://bugs.ruby-lang.org/issues/20925
except << "3.5/leading_logical.txt"
except << "4.0/leading_logical.txt"
# https://bugs.ruby-lang.org/issues/17398#note-12
except << "3.5/endless_methods_command_call.txt"
except << "4.0/endless_methods_command_call.txt"
# https://bugs.ruby-lang.org/issues/21168#note-5
except << "command_method_call_2.txt"

View File

@ -38,8 +38,8 @@ module Prism
"3.3-3.3/return_in_sclass.txt",
# Leaving these out until they are supported by parse.y.
"3.5/leading_logical.txt",
"3.5/endless_methods_command_call.txt",
"4.0/leading_logical.txt",
"4.0/endless_methods_command_call.txt",
"command_method_call_2.txt"
]

View File

@ -64,7 +64,7 @@ module Prism
else
ractor = ignore_warnings { Ractor.new(*arguments, &block) }
# Somewhere in the Ruby 3.5.* series, Ractor#take was removed and
# Somewhere in the Ruby 4.0.* series, Ractor#take was removed and
# Ractor#value was added.
puts(ractor.respond_to?(:value) ? ractor.value : ractor.take)
end

View File

@ -69,10 +69,10 @@ module Prism
"3.4/circular_parameters.txt",
# Cannot yet handling leading logical operators.
"3.5/leading_logical.txt",
"4.0/leading_logical.txt",
# Ruby >= 3.5 specific syntax
"3.5/endless_methods_command_call.txt",
# Ruby >= 4.0 specific syntax
"4.0/endless_methods_command_call.txt",
# https://bugs.ruby-lang.org/issues/21168#note-5
"command_method_call_2.txt",
@ -172,6 +172,7 @@ module Prism
if RUBY_VERSION >= "3.3"
def test_current_parser_for_current_ruby
major, minor = current_major_minor.split(".")
return if major == "3" && minor == "5" # TODO: Remove once ruby-dev becomes 4.0
# Let's just hope there never is a Ruby 3.10 or similar
expected = major.to_i * 10 + minor.to_i
assert_equal(expected, Translation::ParserCurrent.new.version)

View File

@ -9,7 +9,7 @@ module Prism
# Skip these tests that Ripper is reporting the wrong results for.
incorrect = [
# Not yet supported.
"3.5/leading_logical.txt",
"4.0/leading_logical.txt",
# Ripper incorrectly attributes the block to the keyword.
"seattlerb/block_break.txt",
@ -40,7 +40,7 @@ module Prism
"3.4/circular_parameters.txt",
# https://bugs.ruby-lang.org/issues/17398#note-12
"3.5/endless_methods_command_call.txt",
"4.0/endless_methods_command_call.txt",
# https://bugs.ruby-lang.org/issues/21168#note-5
"command_method_call_2.txt",

View File

@ -84,8 +84,8 @@ module Prism
"3.4/circular_parameters.txt",
"3.5/endless_methods_command_call.txt",
"3.5/leading_logical.txt",
"4.0/endless_methods_command_call.txt",
"4.0/leading_logical.txt",
# https://bugs.ruby-lang.org/issues/21168#note-5
"command_method_call_2.txt",

View File

@ -230,7 +230,7 @@ module Prism
end
# All versions that prism can parse
SYNTAX_VERSIONS = %w[3.3 3.4 3.5 4.0]
SYNTAX_VERSIONS = %w[3.3 3.4 4.0]
# Returns an array of ruby versions that a given filepath should test against:
# test.txt # => all available versions
@ -256,6 +256,7 @@ module Prism
if RUBY_VERSION >= "3.3.0"
def test_all_syntax_versions_present
return if RUBY_VERSION.start_with?("3.5") # TODO: Remove once ruby-dev becomes 4.0
assert_include(SYNTAX_VERSIONS, current_major_minor)
end
end