Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/prism/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ 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 = 3,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use a different number here than for "3.5". They are the same after all.


/** The current version of prism. */
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_3_5
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_0
} pm_options_version_t;

/**
Expand Down
3 changes: 2 additions & 1 deletion java/org/prism/ParsingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum SyntaxVersion {
LATEST(0), // Handled in pm_parser_init
V3_3(1),
V3_4(2),
V3_5(3);
V3_5(3),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a use-case for keeping the 3.5 parser translator. While I can't say the same for the other places, I'd keep them all around for now.

In a year or two I'd simply remove them.

V4_0(3);

private final int value;

Expand Down
2 changes: 1 addition & 1 deletion javascript/src/parsePrism.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function dumpOptions(options) {
values.push(1);
} else if (options.version.match(/^3\.4(\.\d+)?$/)) {
values.push(2);
} else if (options.version.match(/^3\.5(\.\d+)?$/)) {
} else if (options.version.match(/^3\.5(\.\d+)?$/) || options.version.match(/^4\.0(\.\d+)?$/)) {
values.push(3);
} else {
throw new Error(`Unsupported version '${options.version}' in compiler options`);
Expand Down
2 changes: 1 addition & 1 deletion lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def dump_options_version(version)
1
when /\A3\.4(\.\d+)?\z/
2
when /\A3\.5(\.\d+)?\z/
when /\A3\.5(\.\d+)?\z/, /\A4\.0(\.\d+)?\z/
3
else
if current
Expand Down
1 change: 1 addition & 0 deletions lib/prism/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Translation # steep:ignore
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
Expand Down
6 changes: 3 additions & 3 deletions lib/prism/translation/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def initialize(builder = Prism::Translation::Parser::Builder.new, parser: Prism)
end

def version # :nodoc:
35
40
end

# The default encoding for Ruby files is UTF-8.
Expand Down Expand Up @@ -356,8 +356,8 @@ def convert_for_prism(version)
"3.3.1"
when 34
"3.4.0"
when 35
"3.5.0"
when 35, 40
"4.0.0"
else
"latest"
end
Expand Down
7 changes: 1 addition & 6 deletions lib/prism/translation/parser35.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions lib/prism/translation/parser40.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/prism/translation/parser_current.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Translation
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
Expand Down
2 changes: 2 additions & 0 deletions prism.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions rbi/prism/translation/parser35.rbi
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# typed: strict

class Prism::Translation::Parser35 < Prism::Translation::Parser
sig { override.returns(Integer) }
def version; end
end
6 changes: 6 additions & 0 deletions rbi/prism/translation/parser40.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# typed: strict

class Prism::Translation::Parser40 < Prism::Translation::Parser
sig { override.returns(Integer) }
def version; end
end
File renamed without changes.
14 changes: 7 additions & 7 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,27 @@ 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;
if (strncmp(version, "3.5", 3) == 0 || strncmp(version, "4.0", 3) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
return true;
}

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;
if (strncmp(version, "3.5.", 4) == 0 || strncmp(version, "4.0.", 4) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) == '|') ||
Expand Down Expand Up @@ -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) == '&') {
Expand Down Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions test/prism/api/parse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def test_version
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
Expand Down
4 changes: 2 additions & 2 deletions test/prism/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class FixturesTest < TestCase
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"

Expand Down
4 changes: 2 additions & 2 deletions test/prism/lex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class LexTest < TestCase
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"
Expand Down
4 changes: 2 additions & 2 deletions test/prism/locals_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class LocalsTest < TestCase
"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"
]

Expand Down
2 changes: 1 addition & 1 deletion test/prism/ractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def with_ractor(*arguments, &block)
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
Expand Down
7 changes: 4 additions & 3 deletions test/prism/ruby/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class ParserTest < TestCase
"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",
Expand Down Expand Up @@ -172,6 +172,7 @@ def test_non_prism_builder_class_deprecated
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)
Expand Down
4 changes: 2 additions & 2 deletions test/prism/ruby/ripper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RipperTest < TestCase
# 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",
Expand Down Expand Up @@ -40,7 +40,7 @@ class RipperTest < TestCase
"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",
Expand Down
4 changes: 2 additions & 2 deletions test/prism/ruby/ruby_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class RubyParserTest < TestCase

"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",
Expand Down
3 changes: 2 additions & 1 deletion test/prism/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def self.windows?
end

# All versions that prism can parse
SYNTAX_VERSIONS = %w[3.3 3.4 3.5]
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
Expand All @@ -256,6 +256,7 @@ def current_major_minor

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
Expand Down