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
2 changes: 1 addition & 1 deletion runtime/Python2/src/antlr4/atn/ATNDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, options = None):
self.actionFactories = None

def deserialize(self, data):
self.data = [ ord(c) for c in data ]
self.data = data
self.pos = 0
self.checkVersion()
atn = self.readATN()
Expand Down
4 changes: 2 additions & 2 deletions runtime/Python3/src/antlr4/atn/ATNDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, options : ATNDeserializationOptions = None):
options = ATNDeserializationOptions.defaultOptions
self.deserializationOptions = options

def deserialize(self, data : str):
self.data = [ ord(c) for c in data ]
def deserialize(self, data : int):
self.data = data
self.pos = 0
self.checkVersion()
atn = self.readATN()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,10 @@ class <lexer.name>(<if(superClass)><superClass><else>Lexer<endif>):
>>

SerializedATN(model) ::= <<
<! only one segment, can be inlined !>

def serializedATN():
with StringIO() as buf:
buf.write(u"<model.serialized; wrap={")<\n> buf.write(u"}>")
return buf.getvalue()

return [
<model.serialized: {s | <s>}; separator=",", wrap>
]
>>

/** Using a type to init value map, try to init a type; if not in table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,10 @@ class <lexer.name>(<if(superClass)><superClass><else>Lexer<endif>):
>>

SerializedATN(model) ::= <<
<! only one segment, can be inlined !>

def serializedATN():
with StringIO() as buf:
buf.write("<model.serialized; wrap={")<\n> buf.write("}>")
return buf.getvalue()

return [
<model.serialized: {s | <s>}; separator=",", wrap>
]
>>

/** Using a type to init value map, try to init a type; if not in table
Expand Down
8 changes: 6 additions & 2 deletions tool/src/org/antlr/v4/codegen/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ public String encodeIntAsCharEscape(int v) {
throw new IllegalArgumentException(String.format("Cannot encode the specified value: %d", v));
}

String language = getLanguage();
if (language.equals("Go") || language.equals("Cpp")) {
if ( isATNSerializedAsInts() ) {
return Integer.toString(v);
}

Expand All @@ -367,6 +366,7 @@ public String encodeIntAsCharEscape(int v) {
}

if (isPreviousOctal) {
String language = getLanguage();
char upperBound = language.equals("PHP") ? '9' : '7';
if (c >= '0' && c <= upperBound) {
return escapeChar(v);
Expand Down Expand Up @@ -689,6 +689,10 @@ public boolean supportsOverloadedMethods() {
return true;
}

public boolean isATNSerializedAsInts() {
return true;
}

/** @since 4.6 */
public boolean needsHeader() { return false; } // Override in targets that need header files.
}
5 changes: 5 additions & 0 deletions tool/src/org/antlr/v4/codegen/target/CSharpTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ private void reportError(STMessage msg) {

return result;
}

@Override
public boolean isATNSerializedAsInts() {
return false;
}
}
5 changes: 5 additions & 0 deletions tool/src/org/antlr/v4/codegen/target/DartTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ protected STGroup loadTemplates() {

return result;
}

@Override
public boolean isATNSerializedAsInts() {
return false;
}
}
2 changes: 0 additions & 2 deletions tool/src/org/antlr/v4/codegen/target/GoTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public String getBaseVisitorFileName(boolean header) {
}

protected static class JavaStringRenderer extends StringRenderer {

@Override
public String toString(Object o, String formatString, Locale locale) {

Expand All @@ -177,6 +176,5 @@ public String toString(Object o, String formatString, Locale locale) {

return super.toString(o, formatString, locale);
}

}
}
5 changes: 5 additions & 0 deletions tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ public boolean wantsBaseVisitor() {
public boolean supportsOverloadedMethods() {
return false;
}

@Override
public boolean isATNSerializedAsInts() {
return false;
}
}
5 changes: 5 additions & 0 deletions tool/src/org/antlr/v4/codegen/target/JavaTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ public String toString(Object o, String formatString, Locale locale) {
return super.toString(o, formatString, locale);
}
}

@Override
public boolean isATNSerializedAsInts() {
return false;
}
}
1 change: 1 addition & 0 deletions tool/src/org/antlr/v4/codegen/target/Python2Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ public boolean supportsOverloadedMethods() {
return false;
}
}

5 changes: 5 additions & 0 deletions tool/src/org/antlr/v4/codegen/target/SwiftTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public String toString(Object o, String formatString, Locale locale) {
return super.toString(o, formatString, locale);
}
}

@Override
public boolean isATNSerializedAsInts() {
return false;
}
}