Skip to content

Commit 7037d8f

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Rename Ruby 3.5 to Ruby 4.0
See ruby@6d81969 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 ruby/prism@d0a823f045
1 parent a7c23b9 commit 7037d8f

21 files changed

+54
-50
lines changed

lib/prism/ffi.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,8 @@ def dump_options_version(version)
432432
1
433433
when /\A3\.4(\.\d+)?\z/
434434
2
435-
when /\A3\.5(\.\d+)?\z/
435+
when /\A3\.5(\.\d+)?\z/, /\A4\.0(\.\d+)?\z/
436436
3
437-
when /\A4\.0(\.\d+)?\z/
438-
4
439437
else
440438
if current
441439
raise CurrentVersionError, RUBY_VERSION

lib/prism/prism.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Gem::Specification.new do |spec|
101101
"lib/prism/translation/parser33.rb",
102102
"lib/prism/translation/parser34.rb",
103103
"lib/prism/translation/parser35.rb",
104+
"lib/prism/translation/parser40.rb",
104105
"lib/prism/translation/parser/builder.rb",
105106
"lib/prism/translation/parser/compiler.rb",
106107
"lib/prism/translation/parser/lexer.rb",
@@ -123,6 +124,7 @@ Gem::Specification.new do |spec|
123124
"rbi/prism/translation/parser33.rbi",
124125
"rbi/prism/translation/parser34.rbi",
125126
"rbi/prism/translation/parser35.rbi",
127+
"rbi/prism/translation/parser40.rbi",
126128
"rbi/prism/translation/ripper.rbi",
127129
"rbi/prism/visitor.rbi",
128130
"sig/prism.rbs",

lib/prism/translation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Translation # steep:ignore
1010
autoload :Parser33, "prism/translation/parser33"
1111
autoload :Parser34, "prism/translation/parser34"
1212
autoload :Parser35, "prism/translation/parser35"
13+
autoload :Parser40, "prism/translation/parser40"
1314
autoload :Ripper, "prism/translation/ripper"
1415
autoload :RubyParser, "prism/translation/ruby_parser"
1516
end

lib/prism/translation/parser.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def initialize(builder = Prism::Translation::Parser::Builder.new, parser: Prism)
8484
end
8585

8686
def version # :nodoc:
87-
35
87+
40
8888
end
8989

9090
# The default encoding for Ruby files is UTF-8.
@@ -356,8 +356,8 @@ def convert_for_prism(version)
356356
"3.3.1"
357357
when 34
358358
"3.4.0"
359-
when 35
360-
"3.5.0"
359+
when 35, 40
360+
"4.0.0"
361361
else
362362
"latest"
363363
end

lib/prism/translation/parser35.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33

44
module Prism
55
module Translation
6-
# This class is the entry-point for Ruby 3.5 of `Prism::Translation::Parser`.
7-
class Parser35 < Parser
8-
def version # :nodoc:
9-
35
10-
end
11-
end
6+
Parser35 = Parser40 # :nodoc:
127
end
138
end

lib/prism/translation/parser40.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
# :markup: markdown
3+
4+
module Prism
5+
module Translation
6+
# This class is the entry-point for Ruby 4.0 of `Prism::Translation::Parser`.
7+
class Parser40 < Parser
8+
def version # :nodoc:
9+
40
10+
end
11+
end
12+
end
13+
end

lib/prism/translation/parser_current.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module Translation
1010
ParserCurrent = Parser33
1111
when /^3\.4\./
1212
ParserCurrent = Parser34
13-
when /^3\.5\./
14-
ParserCurrent = Parser35
13+
when /^3\.5\./, /^4\.0\./
14+
ParserCurrent = Parser40
1515
else
1616
# Keep this in sync with released Ruby.
1717
parser = Parser34

prism/options.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,26 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
8888
return true;
8989
}
9090

91-
if (strncmp(version, "3.5", 3) == 0) {
92-
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
93-
return true;
94-
}
95-
96-
if (strncmp(version, "4.0", 3) == 0) {
91+
if (strncmp(version, "3.5", 3) == 0 || strncmp(version, "4.0", 3) == 0) {
9792
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
9893
return true;
9994
}
10095

10196
return false;
10297
}
10398

104-
if (length >= 4) {
105-
if (strncmp(version, "3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
99+
if (length >= 4 && is_number(version + 4, length - 4)) {
100+
if (strncmp(version, "3.3.", 4) == 0) {
106101
options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
107102
return true;
108103
}
109104

110-
if (strncmp(version, "3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
105+
if (strncmp(version, "3.4.", 4) == 0) {
111106
options->version = PM_OPTIONS_VERSION_CRUBY_3_4;
112107
return true;
113108
}
114109

115-
if (strncmp(version, "3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
116-
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
117-
return true;
118-
}
119-
120-
if (strncmp(version, "4.0.", 4) == 0 && is_number(version + 4, length - 4)) {
110+
if (strncmp(version, "3.5.", 4) == 0 || strncmp(version, "4.0.", 4) == 0) {
121111
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
122112
return true;
123113
}

prism/options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ typedef enum {
9191
/** The vendored version of prism in CRuby 3.4.x. */
9292
PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
9393

94-
/** The vendored version of prism in CRuby 3.5.x. */
94+
/** The vendored version of prism in CRuby 4.0.x. */
9595
PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
9696

9797
/** The vendored version of prism in CRuby 4.0.x. */
98-
PM_OPTIONS_VERSION_CRUBY_4_0 = 4,
98+
PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
9999

100100
/** The current version of prism. */
101101
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_0

prism/prism.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10864,11 +10864,11 @@ parser_lex(pm_parser_t *parser) {
1086410864
}
1086510865

1086610866

10867-
// If we are parsing as CRuby 3.5 or later and we
10867+
// If we are parsing as CRuby 4.0 or later and we
1086810868
// hit a '&&' or a '||' then we will lex the ignored
1086910869
// newline.
1087010870
if (
10871-
(parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) &&
10871+
(parser->version >= PM_OPTIONS_VERSION_CRUBY_4_0) &&
1087210872
following && (
1087310873
(peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '&') ||
1087410874
(peek_at(parser, following) == '|' && peek_at(parser, following + 1) == '|') ||
@@ -10915,7 +10915,7 @@ parser_lex(pm_parser_t *parser) {
1091510915
LEX(PM_TOKEN_AMPERSAND_DOT);
1091610916
}
1091710917

10918-
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) {
10918+
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_4_0) {
1091910919
// If we hit an && then we are in a logical chain
1092010920
// and we need to return the logical operator.
1092110921
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
1962519625
statements = (pm_node_t *) pm_statements_node_create(parser);
1962619626

1962719627
bool allow_command_call;
19628-
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) {
19628+
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_4_0) {
1962919629
allow_command_call = accepts_command_call;
1963019630
} else {
1963119631
// Allow `def foo = puts "Hello"` but not `private def foo = puts "Hello"`

0 commit comments

Comments
 (0)