Skip to content

Commit

Permalink
[C++] Use camel case name in generated lexers and parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
jcking committed Mar 4, 2022
1 parent 58b802e commit 59dc1cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
26 changes: 13 additions & 13 deletions runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ struct XPathLexerStaticData final {
std::unique_ptr<antlr4::atn::ATN> atn;
};

std::once_flag XPathLexer_onceFlag;
XPathLexerStaticData *XPathLexerstaticData = nullptr;
std::once_flag xpathLexerOnceFlag;
XPathLexerStaticData *xpathLexerStaticData = nullptr;

void XPathLexer_initialize() {
assert(XPathLexerstaticData == nullptr);
void xpathLexerInitialize() {
assert(xpathLexerStaticData == nullptr);
auto staticData = std::make_unique<XPathLexerStaticData>(
std::vector<std::string>{
"ANYWHERE", "ROOT", "WILDCARD", "BANG", "ID", "NameChar", "NameStartChar",
Expand Down Expand Up @@ -117,14 +117,14 @@ void XPathLexer_initialize() {
for (size_t i = 0; i < count; i++) {
staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i);
}
XPathLexerstaticData = staticData.release();
xpathLexerStaticData = staticData.release();
}

}

XPathLexer::XPathLexer(CharStream *input) : Lexer(input) {
XPathLexer::initialize();
_interpreter = new atn::LexerATNSimulator(this, *XPathLexerstaticData->atn, XPathLexerstaticData->decisionToDFA, XPathLexerstaticData->sharedContextCache);
_interpreter = new atn::LexerATNSimulator(this, *xpathLexerStaticData->atn, xpathLexerStaticData->decisionToDFA, xpathLexerStaticData->sharedContextCache);
}

XPathLexer::~XPathLexer() {
Expand All @@ -136,27 +136,27 @@ std::string XPathLexer::getGrammarFileName() const {
}

const std::vector<std::string>& XPathLexer::getRuleNames() const {
return XPathLexerstaticData->ruleNames;
return xpathLexerStaticData->ruleNames;
}

const std::vector<std::string>& XPathLexer::getChannelNames() const {
return XPathLexerstaticData->channelNames;
return xpathLexerStaticData->channelNames;
}

const std::vector<std::string>& XPathLexer::getModeNames() const {
return XPathLexerstaticData->modeNames;
return xpathLexerStaticData->modeNames;
}

const dfa::Vocabulary& XPathLexer::getVocabulary() const {
return XPathLexerstaticData->vocabulary;
return xpathLexerStaticData->vocabulary;
}

const std::vector<uint16_t>& XPathLexer::getSerializedATN() const {
return XPathLexerstaticData->serializedATN;
return xpathLexerStaticData->serializedATN;
}

const atn::ATN& XPathLexer::getATN() const {
return *XPathLexerstaticData->atn;
return *xpathLexerStaticData->atn;
}

void XPathLexer::action(RuleContext *context, size_t ruleIndex, size_t actionIndex) {
Expand All @@ -183,5 +183,5 @@ void XPathLexer::IDAction(antlr4::RuleContext *context, size_t actionIndex) {
}

void XPathLexer::initialize() {
std::call_once(XPathLexer_onceFlag, XPathLexer_initialize);
std::call_once(xpathLexerOnceFlag, xpathLexerInitialize);
}
48 changes: 24 additions & 24 deletions tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ struct <lexer.name>StaticData final {
std::unique_ptr\<antlr4::atn::ATN> atn;
};

std::once_flag <lexer.name>_onceFlag;
<lexer.name>StaticData *<lexer.name>staticData = nullptr;
std::once_flag <lexer.grammarName; format = "lower">LexerOnceFlag;
<lexer.name>StaticData *<lexer.grammarName; format = "lower">LexerStaticData = nullptr;

void <lexer.name>_initialize() {
assert(<lexer.name>staticData == nullptr);
void <lexer.grammarName; format = "lower">LexerInitialize() {
assert(<lexer.grammarName; format = "lower">LexerStaticData == nullptr);
auto staticData = std::make_unique\<<lexer.name>StaticData>(
std::vector\<std::string>{
<lexer.ruleNames: {r | "<r>"}; separator = ", ", wrap, anchor>
Expand All @@ -165,14 +165,14 @@ void <lexer.name>_initialize() {
}
);
<atn>
<lexer.name>staticData = staticData.release();
<lexer.grammarName; format = "lower">LexerStaticData = staticData.release();
}

}

<lexer.name>::<lexer.name>(CharStream *input) : <superClass>(input) {
<lexer.name>::initialize();
_interpreter = new atn::LexerATNSimulator(this, *<lexer.name>staticData->atn, <lexer.name>staticData->decisionToDFA, <lexer.name>staticData->sharedContextCache);
_interpreter = new atn::LexerATNSimulator(this, *<lexer.grammarName; format = "lower">LexerStaticData->atn, <lexer.grammarName; format = "lower">LexerStaticData->decisionToDFA, <lexer.grammarName; format = "lower">LexerStaticData->sharedContextCache);
}

<lexer.name>::~<lexer.name>() {
Expand All @@ -184,27 +184,27 @@ std::string <lexer.name>::getGrammarFileName() const {
}

const std::vector\<std::string>& <lexer.name>::getRuleNames() const {
return <lexer.name>staticData->ruleNames;
return <lexer.grammarName; format = "lower">LexerStaticData->ruleNames;
}

const std::vector\<std::string>& <lexer.name>::getChannelNames() const {
return <lexer.name>staticData->channelNames;
return <lexer.grammarName; format = "lower">LexerStaticData->channelNames;
}

const std::vector\<std::string>& <lexer.name>::getModeNames() const {
return <lexer.name>staticData->modeNames;
return <lexer.grammarName; format = "lower">LexerStaticData->modeNames;
}

const dfa::Vocabulary& <lexer.name>::getVocabulary() const {
return <lexer.name>staticData->vocabulary;
return <lexer.grammarName; format = "lower">LexerStaticData->vocabulary;
}

const std::vector\<uint16_t>& <lexer.name>::getSerializedATN() const {
return <lexer.name>staticData->serializedATN;
return <lexer.grammarName; format = "lower">LexerStaticData->serializedATN;
}

const atn::ATN& <lexer.name>::getATN() const {
return *<lexer.name>staticData->atn;
return *<lexer.grammarName; format = "lower">LexerStaticData->atn;
}

<namedActions.definitions>
Expand Down Expand Up @@ -237,7 +237,7 @@ bool <lexer.name>::sempred(RuleContext *context, size_t ruleIndex, size_t predic
<sempredFuncs.values; separator="\n">

void <lexer.name>::initialize() {
std::call_once(<lexer.name>_onceFlag, <lexer.name>_initialize);
std::call_once(<lexer.grammarName; format = "lower">LexerOnceFlag, <lexer.grammarName; format = "lower">LexerInitialize);
}
>>

Expand Down Expand Up @@ -360,11 +360,11 @@ struct <parser.name>StaticData final {
std::unique_ptr\<antlr4::atn::ATN> atn;
};

std::once_flag <parser.name>_onceFlag;
<parser.name>StaticData *<parser.name>staticData = nullptr;
std::once_flag <parser.grammarName; format = "lower">ParserOnceFlag;
<parser.name>StaticData *<parser.grammarName; format = "lower">ParserStaticData = nullptr;

void <parser.name>_initialize() {
assert(<parser.name>staticData == nullptr);
void <parser.grammarName; format = "lower">ParserInitialize() {
assert(<parser.grammarName; format = "lower">ParserStaticData == nullptr);
auto staticData = std::make_unique\<<parser.name>StaticData>(
std::vector\<std::string>{
<parser.ruleNames: {r | "<r>"}; separator = ", ", wrap, anchor>
Expand All @@ -377,38 +377,38 @@ void <parser.name>_initialize() {
}
);
<atn>
<parser.name>staticData = staticData.release();
<parser.grammarName; format = "lower">ParserStaticData = staticData.release();
}

}

<parser.name>::<parser.name>(TokenStream *input) : <superClass>(input) {
<parser.name>::initialize();
_interpreter = new atn::ParserATNSimulator(this, *<parser.name>staticData->atn, <parser.name>staticData->decisionToDFA, <parser.name>staticData->sharedContextCache);
_interpreter = new atn::ParserATNSimulator(this, *<parser.grammarName; format = "lower">ParserStaticData->atn, <parser.grammarName; format = "lower">ParserStaticData->decisionToDFA, <parser.grammarName; format = "lower">ParserStaticData->sharedContextCache);
}

<parser.name>::~<parser.name>() {
delete _interpreter;
}

const atn::ATN& <parser.name>::getATN() const {
return *<parser.name>staticData->atn;
return *<parser.grammarName; format = "lower">ParserStaticData->atn;
}

std::string <parser.name>::getGrammarFileName() const {
return "<parser.grammarFileName>";
}

const std::vector\<std::string>& <parser.name>::getRuleNames() const {
return <parser.name>staticData->ruleNames;
return <parser.grammarName; format = "lower">ParserStaticData->ruleNames;
}

const dfa::Vocabulary& <parser.name>::getVocabulary() const {
return <parser.name>staticData->vocabulary;
return <parser.grammarName; format = "lower">ParserStaticData->vocabulary;
}

const std::vector\<uint16_t>& <parser.name>::getSerializedATN() const {
return <parser.name>staticData->serializedATN;
return <parser.grammarName; format = "lower">ParserStaticData->serializedATN;
}

<namedActions.definitions>
Expand All @@ -430,7 +430,7 @@ bool <parser.name>::sempred(RuleContext *context, size_t ruleIndex, size_t predi
<sempredFuncs.values; separator="\n"><endif>

void <parser.name>::initialize() {
std::call_once(<parser.name>_onceFlag, <parser.name>_initialize);
std::call_once(<parser.grammarName; format = "lower">ParserOnceFlag, <parser.grammarName; format = "lower">ParserInitialize);
}
>>

Expand Down

0 comments on commit 59dc1cf

Please sign in to comment.