forked from jasder/antlr
Serialized ATN generation changed.
Originally the serialized ATN was coded as a wide string literal with embeded Unicode escapes (where necessary). This might fail on Windows however, as VS is very strict when checking Unicode code points and rejects compilation if it finds undefined code points. Hence this generation has been changed to hex numbers instead of that string literal.
This commit is contained in:
parent
b2daab9477
commit
77d0a6c32a
|
@ -9,8 +9,8 @@ set -o errexit
|
|||
# There are 2 ways of running the ANTLR generator here.
|
||||
|
||||
# 1) Running from jar. Use the given jar (or replace it by another one you built or downloaded) for generation.
|
||||
LOCATION=antlr-4.1.1-dev-complete.jar
|
||||
java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
#LOCATION=antlr-4.1.1-dev-complete.jar
|
||||
#java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
#java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
|
||||
#java -jar $LOCATION -Dlanguage=Java -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
|
||||
|
@ -23,7 +23,7 @@ java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package ant
|
|||
# antlr jar over and over again.
|
||||
CLASSPATH=../../../tool/resources/:ST-4.0.8.jar:../../../tool/target/classes:../../../runtime/Java/target/classes:../../../../antlr3/runtime/Java/target/classes
|
||||
|
||||
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
|
||||
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Java -listener -visitor -o generated/ TLexer.g4 TParser.g4
|
||||
|
||||
|
|
|
@ -354,15 +354,17 @@ static std::wstring _serializedATN;
|
|||
// Constructs the serialized ATN and writes init code for static member vars.
|
||||
SerializedATN(model) ::= <<
|
||||
<if (rest(model.segments))>
|
||||
<model.segments: {segment | static std::wstring _serializedATNSegment<i0> =
|
||||
L"<segment; wrap={"<\n> "}>";}; separator="\n">
|
||||
<model.segments: {segment | static std::wstring _serializedATNSegment<i0> = {
|
||||
<segment; wrap={<\n> }>
|
||||
\};}; separator="\n">
|
||||
_serializedATN =
|
||||
<model.segments: {segment | _serializedATNSegment<i0>}; separator=" +\n">;
|
||||
|
||||
<else>
|
||||
<! only one segment, can be inlined !>
|
||||
_serializedATN =
|
||||
L"<model.serialized; wrap = {"<\n> "}>";
|
||||
_serializedATN = {
|
||||
<model.serialized; wrap = {<\n> }>
|
||||
};
|
||||
<endif>
|
||||
|
||||
atn::ATNDeserializer deserializer;
|
||||
|
|
|
@ -154,10 +154,10 @@ class <file.grammarName>BaseListener : public <file.grammarName>Listener {
|
|||
void exit<lname; format="cap">(<file.parserName>::<lname; format = "cap">Context *ctx) { \}
|
||||
}; separator="\n">
|
||||
|
||||
void enterEveryRule(ParserRuleContext ctx) { }
|
||||
void exitEveryRule(ParserRuleContext ctx) { }
|
||||
void visitTerminal(tree::TerminalNode node) { }
|
||||
void visitErrorNode(tree::ErrorNode node) { }
|
||||
void enterEveryRule(ParserRuleContext::Ref ctx) { }
|
||||
void exitEveryRule(ParserRuleContext::Ref ctx) { }
|
||||
void visitTerminal(std::shared_ptr\<tree::TerminalNode> node) { }
|
||||
void visitErrorNode(std::shared_ptr\<tree::ErrorNode> node) { }
|
||||
};
|
||||
|
||||
<if (file.genPackage)>
|
||||
|
@ -239,10 +239,11 @@ namespace <file.genPackage> {
|
|||
template \<typename T>
|
||||
class <file.grammarName>BaseVisitor : public tree::AbstractParseTreeVisitor\<T>, public <file.grammarName>Visitor\<T> {
|
||||
public:
|
||||
<file.visitorNames: {
|
||||
lname | virtual T* visit<lname; format = "cap">(<file.parserName>::<lname; format = "cap">Context *ctx) <\\>
|
||||
override { return tree::AbstractParseTreeVisitor\<T>::visitChildren(ctx); \}
|
||||
}; separator="\n">
|
||||
<file.visitorNames: { lname |
|
||||
virtual T* visit<lname; format = "cap">(<file.parserName>::<lname; format = "cap">Context *ctx) override {
|
||||
return tree::AbstractParseTreeVisitor\<T>::visitChildren(ctx);
|
||||
\}
|
||||
}; separator="\n">
|
||||
};
|
||||
|
||||
<if(file.genPackage)>
|
||||
|
|
|
@ -176,7 +176,7 @@ public class CppTarget extends Target {
|
|||
if (v < Character.MIN_VALUE || v > Character.MAX_VALUE) {
|
||||
throw new IllegalArgumentException(String.format("Cannot encode the specified value: %d", v));
|
||||
}
|
||||
|
||||
/*
|
||||
if (v >= 0 && v < targetCharValueEscape.length && targetCharValueEscape[v] != null) {
|
||||
return targetCharValueEscape[v];
|
||||
}
|
||||
|
@ -192,6 +192,8 @@ public class CppTarget extends Target {
|
|||
|
||||
String hex = Integer.toHexString(v | 0x10000).substring(1, 5);
|
||||
return "\\u" + hex;
|
||||
*/
|
||||
return "0x" + Integer.toHexString(v) + ", ";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue