Skip to content

Commit 68a16e8

Browse files
Earlopainkddnewton
authored andcommitted
[ruby/prism] Add Ruby 4.1 as a version specifier
ruby/prism@138db9ccc4
1 parent f133ebb commit 68a16e8

10 files changed

Lines changed: 41 additions & 3 deletions

File tree

lib/prism/ffi.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ def dump_options_version(version)
434434
2
435435
when /\A3\.5(\.\d+)?\z/, /\A4\.0(\.\d+)?\z/
436436
3
437+
when /\A4\.1(\.\d+)?\z/
438+
4
437439
else
438440
if current
439441
raise CurrentVersionError, RUBY_VERSION

lib/prism/prism.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Gem::Specification.new do |spec|
102102
"lib/prism/translation/parser34.rb",
103103
"lib/prism/translation/parser35.rb",
104104
"lib/prism/translation/parser40.rb",
105+
"lib/prism/translation/parser41.rb",
105106
"lib/prism/translation/parser/builder.rb",
106107
"lib/prism/translation/parser/compiler.rb",
107108
"lib/prism/translation/parser/lexer.rb",
@@ -125,6 +126,7 @@ Gem::Specification.new do |spec|
125126
"rbi/prism/translation/parser34.rbi",
126127
"rbi/prism/translation/parser35.rbi",
127128
"rbi/prism/translation/parser40.rbi",
129+
"rbi/prism/translation/parser41.rbi",
128130
"rbi/prism/translation/ripper.rbi",
129131
"rbi/prism/visitor.rbi",
130132
"sig/prism.rbs",

lib/prism/translation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Translation # steep:ignore
1111
autoload :Parser34, "prism/translation/parser34"
1212
autoload :Parser35, "prism/translation/parser35"
1313
autoload :Parser40, "prism/translation/parser40"
14+
autoload :Parser41, "prism/translation/parser41"
1415
autoload :Ripper, "prism/translation/ripper"
1516
autoload :RubyParser, "prism/translation/ruby_parser"
1617
end

lib/prism/translation/parser.rb

Lines changed: 3 additions & 1 deletion
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-
40
87+
41
8888
end
8989

9090
# The default encoding for Ruby files is UTF-8.
@@ -358,6 +358,8 @@ def convert_for_prism(version)
358358
"3.4.0"
359359
when 35, 40
360360
"4.0.0"
361+
when 41
362+
"4.1.0"
361363
else
362364
"latest"
363365
end

lib/prism/translation/parser41.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.1 of `Prism::Translation::Parser`.
7+
class Parser41 < Parser
8+
def version # :nodoc:
9+
41
10+
end
11+
end
12+
end
13+
end

lib/prism/translation/parser_current.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module Translation
1212
ParserCurrent = Parser34
1313
when /^3\.5\./, /^4\.0\./
1414
ParserCurrent = Parser40
15+
when /^4\.1\./
16+
ParserCurrent = Parser41
1517
else
1618
# Keep this in sync with released Ruby.
1719
parser = Parser34

prism/options.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
9393
return true;
9494
}
9595

96+
if (strncmp(version, "4.1", 3) == 0) {
97+
options->version = PM_OPTIONS_VERSION_CRUBY_4_1;
98+
return true;
99+
}
100+
96101
return false;
97102
}
98103

@@ -111,6 +116,11 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
111116
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
112117
return true;
113118
}
119+
120+
if (strncmp(version, "4.1.", 4) == 0) {
121+
options->version = PM_OPTIONS_VERSION_CRUBY_4_1;
122+
return true;
123+
}
114124
}
115125

116126
if (length >= 6) {

prism/options.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ typedef enum {
9797
/** The vendored version of prism in CRuby 4.0.x. */
9898
PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
9999

100+
/** The vendored version of prism in CRuby 4.1.x. */
101+
PM_OPTIONS_VERSION_CRUBY_4_1 = 4,
102+
100103
/** The current version of prism. */
101-
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_0
104+
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_1
102105
} pm_options_version_t;
103106

104107
/**

test/prism/api/parse_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def test_version
122122
assert Prism.parse_success?("1 + 1", version: "4.0")
123123
assert Prism.parse_success?("1 + 1", version: "4.0.0")
124124

125+
assert Prism.parse_success?("1 + 1", version: "4.1")
126+
assert Prism.parse_success?("1 + 1", version: "4.1.0")
127+
125128
assert Prism.parse_success?("1 + 1", version: "latest")
126129

127130
# Test edge case

test/prism/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def self.windows?
241241
end
242242

243243
# All versions that prism can parse
244-
SYNTAX_VERSIONS = %w[3.3 3.4 4.0]
244+
SYNTAX_VERSIONS = %w[3.3 3.4 4.0 4.1]
245245

246246
# `RUBY_VERSION` with the patch version excluded
247247
CURRENT_MAJOR_MINOR = RUBY_VERSION.split(".")[0, 2].join(".")

0 commit comments

Comments
 (0)