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
5 changes: 4 additions & 1 deletion include/prism/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ typedef enum {
/** The vendored version of prism in CRuby 4.0.x. */
PM_OPTIONS_VERSION_CRUBY_4_0 = 3,

/** The vendored version of prism in CRuby 4.1.x. */
PM_OPTIONS_VERSION_CRUBY_4_1 = 4,

/** The current version of prism. */
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_0
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_1
} 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 @@ -16,7 +16,8 @@ public enum SyntaxVersion {
V3_3(1),
V3_4(2),
V3_5(3),
V4_0(3);
V4_0(3),
V4_1(4);

private final int value;

Expand Down
2 changes: 2 additions & 0 deletions javascript/src/parsePrism.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ function dumpOptions(options) {
values.push(2);
} else if (options.version.match(/^3\.5(\.\d+)?$/) || options.version.match(/^4\.0(\.\d+)?$/)) {
values.push(3);
} else if (options.version.match(/^4\.1(\.\d+)?$/)) {
values.push(4);
} else {
throw new Error(`Unsupported version '${options.version}' in compiler options`);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ def dump_options_version(version)
2
when /\A3\.5(\.\d+)?\z/, /\A4\.0(\.\d+)?\z/
3
when /\A4\.1(\.\d+)?\z/
4
else
if current
raise CurrentVersionError, RUBY_VERSION
Expand Down
1 change: 1 addition & 0 deletions lib/prism/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Translation # steep:ignore
autoload :Parser34, "prism/translation/parser34"
autoload :Parser35, "prism/translation/parser35"
autoload :Parser40, "prism/translation/parser40"
autoload :Parser41, "prism/translation/parser41"
autoload :Ripper, "prism/translation/ripper"
autoload :RubyParser, "prism/translation/ruby_parser"
end
Expand Down
4 changes: 3 additions & 1 deletion 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:
40
41
end

# The default encoding for Ruby files is UTF-8.
Expand Down Expand Up @@ -358,6 +358,8 @@ def convert_for_prism(version)
"3.4.0"
when 35, 40
"4.0.0"
when 41
"4.1.0"
else
"latest"
end
Expand Down
13 changes: 13 additions & 0 deletions lib/prism/translation/parser41.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.1 of `Prism::Translation::Parser`.
class Parser41 < Parser
def version # :nodoc:
41
end
end
end
end
2 changes: 2 additions & 0 deletions lib/prism/translation/parser_current.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Translation
ParserCurrent = Parser34
when /^3\.5\./, /^4\.0\./
ParserCurrent = Parser40
when /^4\.1\./
ParserCurrent = Parser41
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 @@ -102,6 +102,7 @@ Gem::Specification.new do |spec|
"lib/prism/translation/parser34.rb",
"lib/prism/translation/parser35.rb",
"lib/prism/translation/parser40.rb",
"lib/prism/translation/parser41.rb",
"lib/prism/translation/parser/builder.rb",
"lib/prism/translation/parser/compiler.rb",
"lib/prism/translation/parser/lexer.rb",
Expand All @@ -125,6 +126,7 @@ Gem::Specification.new do |spec|
"rbi/prism/translation/parser34.rbi",
"rbi/prism/translation/parser35.rbi",
"rbi/prism/translation/parser40.rbi",
"rbi/prism/translation/parser41.rbi",
"rbi/prism/translation/ripper.rbi",
"rbi/prism/visitor.rbi",
"sig/prism.rbs",
Expand Down
6 changes: 6 additions & 0 deletions rbi/prism/translation/parser41.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
10 changes: 10 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
return true;
}

if (strncmp(version, "4.1", 3) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_4_1;
return true;
}

return false;
}

Expand All @@ -111,6 +116,11 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
options->version = PM_OPTIONS_VERSION_CRUBY_4_0;
return true;
}

if (strncmp(version, "4.1.", 4) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_4_1;
return true;
}
}

if (length >= 6) {
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 @@ -122,6 +122,9 @@ def test_version
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: "4.1")
assert Prism.parse_success?("1 + 1", version: "4.1.0")

assert Prism.parse_success?("1 + 1", version: "latest")

# Test edge case
Expand Down
2 changes: 1 addition & 1 deletion test/prism/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def self.windows?
end

# All versions that prism can parse
SYNTAX_VERSIONS = %w[3.3 3.4 4.0]
SYNTAX_VERSIONS = %w[3.3 3.4 4.0 4.1]

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