From 6b6aa05bfb3f5620c537678f822b6a9269ab77cf Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Sat, 21 Dec 2024 15:15:32 -0500 Subject: [PATCH] Support 3.5 for version option --- include/prism/options.h | 5 ++++- java/org/prism/ParsingOptions.java | 3 ++- javascript/src/parsePrism.js | 4 +++- lib/prism/ffi.rb | 2 ++ src/options.c | 10 ++++++++++ test/prism/api/parse_test.rb | 5 ++++- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/prism/options.h b/include/prism/options.h index c96fa684ac..c40b4d828a 100644 --- a/include/prism/options.h +++ b/include/prism/options.h @@ -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; /** diff --git a/java/org/prism/ParsingOptions.java b/java/org/prism/ParsingOptions.java index 35a6a7b0c9..379d0d2202 100644 --- a/java/org/prism/ParsingOptions.java +++ b/java/org/prism/ParsingOptions.java @@ -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; diff --git a/javascript/src/parsePrism.js b/javascript/src/parsePrism.js index ea200105bd..8a613767ed 100644 --- a/javascript/src/parsePrism.js +++ b/javascript/src/parsePrism.js @@ -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`); } diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb index 29f312e479..9ab1557838 100644 --- a/lib/prism/ffi.rb +++ b/lib/prism/ffi.rb @@ -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}" diff --git a/src/options.c b/src/options.c index 6b52b2f296..31ceeb200e 100644 --- a/src/options.c +++ b/src/options.c @@ -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; } @@ -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; } diff --git a/test/prism/api/parse_test.rb b/test/prism/api/parse_test.rb index ee8061c98c..55b2731225 100644 --- a/test/prism/api/parse_test.rb +++ b/test/prism/api/parse_test.rb @@ -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 @@ -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