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 3f77695
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
20 changes: 10 additions & 10 deletions runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ struct XPathLexerStaticData final {
};

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

void XPathLexer_initialize() {
assert(XPathLexerstaticData == nullptr);
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 Down
36 changes: 18 additions & 18 deletions tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ struct <lexer.name>StaticData final {
};

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

void <lexer.name>_initialize() {
assert(<lexer.name>staticData == nullptr);
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 @@ -361,10 +361,10 @@ struct <parser.name>StaticData final {
};

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

void <parser.name>_initialize() {
assert(<parser.name>staticData == nullptr);
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 Down

0 comments on commit 3f77695

Please sign in to comment.