Skip to content

Commit

Permalink
Merge pull request #3336 from ruby/support-3-5-version
Browse files Browse the repository at this point in the history
Support 3.5 for version option
  • Loading branch information
kddnewton authored Dec 21, 2024
2 parents c009746 + 6b6aa05 commit a08cde8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion include/prism/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ typedef enum {
PM_OPTIONS_VERSION_LATEST = 0,

/** The vendored version of prism in CRuby 3.3.x. */
PM_OPTIONS_VERSION_CRUBY_3_3 = 1
PM_OPTIONS_VERSION_CRUBY_3_3 = 1,

/** The vendored version of prism in CRuby 3.4.x. */
PM_OPTIONS_VERSION_CRUBY_3_4 = 2
} 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 @@ -13,7 +13,8 @@ public abstract class ParsingOptions {
*/
public enum SyntaxVersion {
LATEST(0),
V3_3(1);
V3_3(1),
V3_4(2);

private final int value;

Expand Down
4 changes: 3 additions & 1 deletion javascript/src/parsePrism.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ function dumpOptions(options) {
values.push(dumpCommandLineOptions(options));

template.push("C");
if (!options.version || options.version === "latest" || options.version.match(/^3\.4(\.\d+)?$/)) {
if (!options.version || options.version === "latest" || options.version.match(/^3\.5(\.\d+)?$/)) {
values.push(0);
} else if (options.version.match(/^3\.3(\.\d+)?$/)) {
values.push(1);
} else if (options.version.match(/^3\.4(\.\d+)?$/)) {
values.push(2);
} 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 @@ -431,6 +431,8 @@ def dump_options_version(version)
when /\A3\.3(\.\d+)?\z/
1
when /\A3\.4(\.\d+)?\z/
2
when /\A3\.5(\.\d+)?\z/
0
else
raise ArgumentError, "invalid version: #{version}"
Expand Down
10 changes: 10 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
}

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

if (strncmp(version, "3.5", 3) == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}
Expand All @@ -98,6 +103,11 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
}

if (strncmp(version, "3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
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_LATEST;
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion test/prism/api/parse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def test_version
assert Prism.parse_success?("1 + 1", version: "3.4.9")
assert Prism.parse_success?("1 + 1", version: "3.4.10")

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: "latest")

# Test edge case
Expand All @@ -133,7 +136,7 @@ def test_version

# Not supported version (too new)
assert_raise ArgumentError do
Prism.parse("1 + 1", version: "3.5.0")
Prism.parse("1 + 1", version: "3.6.0")
end
end

Expand Down

0 comments on commit a08cde8

Please sign in to comment.