Skip to content

Commit d6465e9

Browse files
committed
Add enum for Prism syntax versions
1 parent cd64acb commit d6465e9

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/main/java/org/truffleruby/parser/YARPTranslatorDriver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,7 @@ public static org.prism.ParseResult parseToYARPAST(RubyContext context, RubyLang
421421
byte[] encoding = StringOperations.encodeAsciiBytes(rubySource.getEncoding().toString()); // encoding name is supposed to contain only ASCII characters
422422
boolean frozenStringLiteral = language.options.FROZEN_STRING_LITERALS;
423423
boolean verbose = true;
424-
// The vendored version of prism in CRuby 3.3.0
425-
// See pm_options_version_t in c/yarp/include/prism/options.h
426-
byte version = (byte) 1;
424+
var version = ParsingOptions.SyntaxVersion.V3_3_0;
427425
byte[][][] scopes;
428426

429427
// intern() to improve footprint

src/yarp/java/org/prism/ParsingOptions.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66

77
// @formatter:off
88
public abstract class ParsingOptions {
9+
/** The version of Ruby syntax that we should be parsing with.
10+
* See pm_options_version_t in c/yarp/include/prism/options.h */
11+
public enum SyntaxVersion {
12+
LATEST(0),
13+
V3_3_0(1);
14+
15+
private final int value;
16+
17+
SyntaxVersion(int value) {
18+
this.value = value;
19+
}
20+
21+
public byte getValue() {
22+
return (byte) value;
23+
}
24+
}
25+
926
/** Serialize parsing options into byte array.
1027
*
1128
* @param filepath the name of the file that is currently being parsed
@@ -17,7 +34,7 @@ public abstract class ParsingOptions {
1734
* @param scopes scopes surrounding the code that is being parsed with local variable names defined in every scope
1835
* ordered from the outermost scope to the innermost one */
1936
public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boolean frozenStringLiteral,
20-
boolean verbose, byte version, byte[][][] scopes) {
37+
boolean verbose, SyntaxVersion version, byte[][][] scopes) {
2138
final ByteArrayOutputStream output = new ByteArrayOutputStream();
2239

2340
// filepath
@@ -47,7 +64,7 @@ public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boole
4764
}
4865

4966
// version
50-
output.write(version);
67+
output.write(version.getValue());
5168

5269
// scopes
5370

0 commit comments

Comments
 (0)