-
Notifications
You must be signed in to change notification settings - Fork 9
feat(tdl): Add support to generate an ANTLR parser from the TaskDefLang's grammar. #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
133a2f1
Add parser generation.
LinZhihao-723 e372bd5
Add Java setup.
LinZhihao-723 28d814e
Update cmake to build the generated code.
LinZhihao-723 622c777
Add antlr jar back.
LinZhihao-723 7f0196c
Minor...
LinZhihao-723 8136e3f
Simpify workflow check command.g
LinZhihao-723 2a8b063
Making an intentially mismatch.
LinZhihao-723 de03b01
Fix...
LinZhihao-723 7b460a0
Undo the modification.
LinZhihao-723 7d6c85e
Address Rabit's comment.
LinZhihao-723 e1a3ab0
Merge branch 'main' into parser-gen
LinZhihao-723 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| name: "tdl-generated-code-checks" | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| schedule: | ||
| # Run daily at 00:15 UTC (the 15 is to avoid periods of high load) | ||
| - cron: "15 0 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: "${{github.workflow}}-${{github.ref}}" | ||
| # Cancel in-progress jobs for efficiency | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| antlr-code-committed: | ||
| name: "antlr-code-committed" | ||
| runs-on: "ubuntu-latest" | ||
| steps: | ||
| - uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" | ||
| with: | ||
| submodules: "recursive" | ||
|
|
||
| - name: "Set up Java" | ||
| uses: "actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00" | ||
| with: | ||
| distribution: "temurin" | ||
| java-version: "11" | ||
|
|
||
| - name: "Install task" | ||
| shell: "bash" | ||
| run: "npm install -g @go-task/cli" | ||
|
|
||
| - name: "Generate parsers" | ||
| shell: "bash" | ||
| run: "task build:tdl-generate-parsers" | ||
|
|
||
| - name: "Check if the generated parsers are the latest" | ||
| shell: "bash" | ||
| run: | ||
| | | ||
| git status --porcelain \ | ||
| src/spider/tdl/parser/antlr_generated \ | ||
| | grep . > /dev/null \ | ||
| && exit 1 \ | ||
| || exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| grammar TaskDefLang; | ||
|
|
||
| start: EOF ; | ||
|
|
||
| SPACE: [ \t\r\n] -> skip ; |
9 changes: 9 additions & 0 deletions
9
src/spider/tdl/parser/antlr_generated/TaskDefLangBaseVisitor.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| // Generated from tdl/parser/TaskDefLang.g4 by ANTLR 4.13.2 | ||
|
|
||
|
|
||
| #include "TaskDefLangBaseVisitor.h" | ||
|
|
||
|
|
||
| using namespace spider::tdl::parser::antlr_generated; | ||
|
|
27 changes: 27 additions & 0 deletions
27
src/spider/tdl/parser/antlr_generated/TaskDefLangBaseVisitor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
|
|
||
| // Generated from tdl/parser/TaskDefLang.g4 by ANTLR 4.13.2 | ||
|
|
||
| #pragma once | ||
|
|
||
|
|
||
| #include "antlr4-runtime.h" | ||
| #include "TaskDefLangVisitor.h" | ||
|
|
||
|
|
||
| namespace spider::tdl::parser::antlr_generated { | ||
|
|
||
| /** | ||
| * This class provides an empty implementation of TaskDefLangVisitor, which can be | ||
| * extended to create a visitor which only needs to handle a subset of the available methods. | ||
| */ | ||
| class TaskDefLangBaseVisitor : public TaskDefLangVisitor { | ||
| public: | ||
|
|
||
| virtual std::any visitStart(TaskDefLangParser::StartContext *ctx) override { | ||
| return visitChildren(ctx); | ||
| } | ||
|
|
||
|
|
||
| }; | ||
|
|
||
| } // namespace spider::tdl::parser::antlr_generated |
141 changes: 141 additions & 0 deletions
141
src/spider/tdl/parser/antlr_generated/TaskDefLangLexer.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
|
|
||
| // Generated from tdl/parser/TaskDefLang.g4 by ANTLR 4.13.2 | ||
|
|
||
|
|
||
| #include "TaskDefLangLexer.h" | ||
|
|
||
|
|
||
| using namespace antlr4; | ||
|
|
||
| using namespace spider::tdl::parser::antlr_generated; | ||
|
|
||
|
|
||
| using namespace antlr4; | ||
|
|
||
| namespace { | ||
|
|
||
| struct TaskDefLangLexerStaticData final { | ||
| TaskDefLangLexerStaticData(std::vector<std::string> ruleNames, | ||
| std::vector<std::string> channelNames, | ||
| std::vector<std::string> modeNames, | ||
| std::vector<std::string> literalNames, | ||
| std::vector<std::string> symbolicNames) | ||
| : ruleNames(std::move(ruleNames)), channelNames(std::move(channelNames)), | ||
| modeNames(std::move(modeNames)), literalNames(std::move(literalNames)), | ||
| symbolicNames(std::move(symbolicNames)), | ||
| vocabulary(this->literalNames, this->symbolicNames) {} | ||
|
|
||
| TaskDefLangLexerStaticData(const TaskDefLangLexerStaticData&) = delete; | ||
| TaskDefLangLexerStaticData(TaskDefLangLexerStaticData&&) = delete; | ||
| TaskDefLangLexerStaticData& operator=(const TaskDefLangLexerStaticData&) = delete; | ||
| TaskDefLangLexerStaticData& operator=(TaskDefLangLexerStaticData&&) = delete; | ||
|
|
||
| std::vector<antlr4::dfa::DFA> decisionToDFA; | ||
| antlr4::atn::PredictionContextCache sharedContextCache; | ||
| const std::vector<std::string> ruleNames; | ||
| const std::vector<std::string> channelNames; | ||
| const std::vector<std::string> modeNames; | ||
| const std::vector<std::string> literalNames; | ||
| const std::vector<std::string> symbolicNames; | ||
| const antlr4::dfa::Vocabulary vocabulary; | ||
| antlr4::atn::SerializedATNView serializedATN; | ||
| std::unique_ptr<antlr4::atn::ATN> atn; | ||
| }; | ||
|
|
||
| ::antlr4::internal::OnceFlag taskdeflanglexerLexerOnceFlag; | ||
| #if ANTLR4_USE_THREAD_LOCAL_CACHE | ||
| static thread_local | ||
| #endif | ||
| std::unique_ptr<TaskDefLangLexerStaticData> taskdeflanglexerLexerStaticData = nullptr; | ||
|
|
||
| void taskdeflanglexerLexerInitialize() { | ||
| #if ANTLR4_USE_THREAD_LOCAL_CACHE | ||
| if (taskdeflanglexerLexerStaticData != nullptr) { | ||
| return; | ||
| } | ||
| #else | ||
| assert(taskdeflanglexerLexerStaticData == nullptr); | ||
| #endif | ||
| auto staticData = std::make_unique<TaskDefLangLexerStaticData>( | ||
| std::vector<std::string>{ | ||
| "SPACE" | ||
| }, | ||
| std::vector<std::string>{ | ||
| "DEFAULT_TOKEN_CHANNEL", "HIDDEN" | ||
| }, | ||
| std::vector<std::string>{ | ||
| "DEFAULT_MODE" | ||
| }, | ||
| std::vector<std::string>{ | ||
| }, | ||
| std::vector<std::string>{ | ||
| "", "SPACE" | ||
| } | ||
| ); | ||
| static const int32_t serializedATNSegment[] = { | ||
| 4,0,1,7,6,-1,2,0,7,0,1,0,1,0,1,0,1,0,0,0,1,1,1,1,0,1,3,0,9,10,13,13,32, | ||
| 32,6,0,1,1,0,0,0,1,3,1,0,0,0,3,4,7,0,0,0,4,5,1,0,0,0,5,6,6,0,0,0,6,2, | ||
| 1,0,0,0,1,0,1,6,0,0 | ||
| }; | ||
| staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); | ||
|
|
||
| antlr4::atn::ATNDeserializer deserializer; | ||
| staticData->atn = deserializer.deserialize(staticData->serializedATN); | ||
|
|
||
| const size_t count = staticData->atn->getNumberOfDecisions(); | ||
| staticData->decisionToDFA.reserve(count); | ||
| for (size_t i = 0; i < count; i++) { | ||
| staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); | ||
| } | ||
| taskdeflanglexerLexerStaticData = std::move(staticData); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| TaskDefLangLexer::TaskDefLangLexer(CharStream *input) : Lexer(input) { | ||
| TaskDefLangLexer::initialize(); | ||
| _interpreter = new atn::LexerATNSimulator(this, *taskdeflanglexerLexerStaticData->atn, taskdeflanglexerLexerStaticData->decisionToDFA, taskdeflanglexerLexerStaticData->sharedContextCache); | ||
| } | ||
|
|
||
| TaskDefLangLexer::~TaskDefLangLexer() { | ||
| delete _interpreter; | ||
| } | ||
|
|
||
| std::string TaskDefLangLexer::getGrammarFileName() const { | ||
| return "TaskDefLang.g4"; | ||
| } | ||
|
|
||
| const std::vector<std::string>& TaskDefLangLexer::getRuleNames() const { | ||
| return taskdeflanglexerLexerStaticData->ruleNames; | ||
| } | ||
|
|
||
| const std::vector<std::string>& TaskDefLangLexer::getChannelNames() const { | ||
| return taskdeflanglexerLexerStaticData->channelNames; | ||
| } | ||
|
|
||
| const std::vector<std::string>& TaskDefLangLexer::getModeNames() const { | ||
| return taskdeflanglexerLexerStaticData->modeNames; | ||
| } | ||
|
|
||
| const dfa::Vocabulary& TaskDefLangLexer::getVocabulary() const { | ||
| return taskdeflanglexerLexerStaticData->vocabulary; | ||
| } | ||
|
|
||
| antlr4::atn::SerializedATNView TaskDefLangLexer::getSerializedATN() const { | ||
| return taskdeflanglexerLexerStaticData->serializedATN; | ||
| } | ||
|
|
||
| const atn::ATN& TaskDefLangLexer::getATN() const { | ||
| return *taskdeflanglexerLexerStaticData->atn; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| void TaskDefLangLexer::initialize() { | ||
| #if ANTLR4_USE_THREAD_LOCAL_CACHE | ||
| taskdeflanglexerLexerInitialize(); | ||
| #else | ||
| ::antlr4::internal::call_once(taskdeflanglexerLexerOnceFlag, taskdeflanglexerLexerInitialize); | ||
| #endif | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
|
|
||
| // Generated from tdl/parser/TaskDefLang.g4 by ANTLR 4.13.2 | ||
|
|
||
| #pragma once | ||
|
|
||
|
|
||
| #include "antlr4-runtime.h" | ||
|
|
||
|
|
||
| namespace spider::tdl::parser::antlr_generated { | ||
|
|
||
|
|
||
| class TaskDefLangLexer : public antlr4::Lexer { | ||
| public: | ||
| enum { | ||
| SPACE = 1 | ||
| }; | ||
|
|
||
| explicit TaskDefLangLexer(antlr4::CharStream *input); | ||
|
|
||
| ~TaskDefLangLexer() override; | ||
|
|
||
|
|
||
| std::string getGrammarFileName() const override; | ||
|
|
||
| const std::vector<std::string>& getRuleNames() const override; | ||
|
|
||
| const std::vector<std::string>& getChannelNames() const override; | ||
|
|
||
| const std::vector<std::string>& getModeNames() const override; | ||
|
|
||
| const antlr4::dfa::Vocabulary& getVocabulary() const override; | ||
|
|
||
| antlr4::atn::SerializedATNView getSerializedATN() const override; | ||
|
|
||
| const antlr4::atn::ATN& getATN() const override; | ||
|
|
||
| // By default the static state used to implement the lexer is lazily initialized during the first | ||
| // call to the constructor. You can call this function if you wish to initialize the static state | ||
| // ahead of time. | ||
| static void initialize(); | ||
|
|
||
| private: | ||
|
|
||
| // Individual action functions triggered by action() above. | ||
|
|
||
| // Individual semantic predicate functions triggered by sempred() above. | ||
|
|
||
| }; | ||
|
|
||
| } // namespace spider::tdl::parser::antlr_generated |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.