├── .gitignore ├── rule_engine.hpp ├── antlr ├── runtime │ ├── misc │ │ ├── Predicate.cpp │ │ ├── Predicate.h │ │ └── InterpreterDataReader.h │ ├── tree │ │ ├── xpath │ │ │ ├── XPathLexer.tokens │ │ │ ├── XPathLexerErrorListener.cpp │ │ │ ├── XPathWildcardElement.h │ │ │ ├── XPathWildcardAnywhereElement.h │ │ │ ├── XPathWildcardElement.cpp │ │ │ ├── XPathLexerErrorListener.h │ │ │ ├── XPathRuleElement.h │ │ │ ├── XPathTokenElement.h │ │ │ ├── XPathRuleAnywhereElement.cpp │ │ │ ├── XPathTokenAnywhereElement.cpp │ │ │ ├── XPathTokenAnywhereElement.h │ │ │ ├── XPathWildcardAnywhereElement.cpp │ │ │ ├── XPathRuleAnywhereElement.h │ │ │ ├── XPathElement.cpp │ │ │ ├── XPathRuleElement.cpp │ │ │ ├── XPathTokenElement.cpp │ │ │ ├── XPathElement.h │ │ │ ├── XPathLexer.g4 │ │ │ └── XPathLexer.h │ │ ├── ErrorNode.cpp │ │ ├── pattern │ │ │ ├── Chunk.cpp │ │ │ ├── TextChunk.cpp │ │ │ ├── TagChunk.cpp │ │ │ ├── TokenTagToken.cpp │ │ │ ├── Chunk.h │ │ │ ├── TextChunk.h │ │ │ ├── ParseTreePattern.cpp │ │ │ ├── RuleTagToken.cpp │ │ │ └── ParseTreeMatch.cpp │ │ ├── TerminalNode.cpp │ │ ├── ParseTreeVisitor.cpp │ │ ├── ParseTreeListener.cpp │ │ ├── ParseTree.cpp │ │ ├── ErrorNode.h │ │ ├── ErrorNodeImpl.cpp │ │ ├── TerminalNode.h │ │ ├── TerminalNodeImpl.h │ │ ├── ErrorNodeImpl.h │ │ ├── ParseTreeListener.h │ │ ├── TerminalNodeImpl.cpp │ │ ├── ParseTreeProperty.h │ │ └── ParseTreeWalker.cpp │ ├── Token.cpp │ ├── TokenSource.cpp │ ├── WritableToken.cpp │ ├── atn │ │ ├── LexerAction.cpp │ │ ├── BlockStartState.cpp │ │ ├── BasicState.cpp │ │ ├── LoopEndState.cpp │ │ ├── RuleStopState.cpp │ │ ├── TokensStartState.cpp │ │ ├── PlusLoopbackState.cpp │ │ ├── BasicBlockStartState.cpp │ │ ├── PlusBlockStartState.cpp │ │ ├── StarBlockStartState.cpp │ │ ├── OrderedATNConfigSet.cpp │ │ ├── BlockEndState.cpp │ │ ├── RuleStartState.cpp │ │ ├── StarLoopEntryState.cpp │ │ ├── AbstractPredicateTransition.cpp │ │ ├── ATNType.h │ │ ├── DecisionState.cpp │ │ ├── BasicState.h │ │ ├── OrderedATNConfigSet.h │ │ ├── ContextSensitivityInfo.cpp │ │ ├── ErrorInfo.cpp │ │ ├── StarLoopbackState.h │ │ ├── BasicBlockStartState.h │ │ ├── StarBlockStartState.h │ │ ├── BlockStartState.h │ │ ├── LoopEndState.h │ │ ├── StarLoopbackState.cpp │ │ ├── DecisionEventInfo.cpp │ │ ├── TokensStartState.h │ │ ├── AbstractPredicateTransition.h │ │ ├── LookaheadEventInfo.cpp │ │ ├── RuleStartState.h │ │ ├── BlockEndState.h │ │ ├── AmbiguityInfo.cpp │ │ ├── PlusLoopbackState.h │ │ ├── DecisionState.h │ │ ├── PredicateEvalInfo.cpp │ │ ├── WildcardTransition.h │ │ ├── RuleStopState.h │ │ ├── NotSetTransition.h │ │ ├── WildcardTransition.cpp │ │ ├── PlusBlockStartState.h │ │ ├── RangeTransition.h │ │ ├── EmptyPredictionContext.h │ │ ├── SetTransition.h │ │ ├── AtomTransition.h │ │ ├── DecisionInfo.cpp │ │ ├── AtomTransition.cpp │ │ ├── EmptyPredictionContext.cpp │ │ ├── PrecedencePredicateTransition.h │ │ ├── NotSetTransition.cpp │ │ ├── SetTransition.cpp │ │ ├── StarLoopEntryState.h │ │ ├── ActionTransition.h │ │ ├── RangeTransition.cpp │ │ ├── EpsilonTransition.cpp │ │ ├── Transition.cpp │ │ ├── PrecedencePredicateTransition.cpp │ │ ├── LexerMoreAction.cpp │ │ ├── LexerSkipAction.cpp │ │ ├── RuleTransition.cpp │ │ ├── EpsilonTransition.h │ │ ├── LexerPopModeAction.cpp │ │ ├── ActionTransition.cpp │ │ ├── PredicateTransition.cpp │ │ ├── ATNDeserializationOptions.h │ │ ├── RuleTransition.h │ │ ├── PredicateTransition.h │ │ ├── LexerModeAction.cpp │ │ ├── LexerTypeAction.cpp │ │ ├── LexerChannelAction.cpp │ │ ├── LexerPushModeAction.cpp │ │ ├── LexerActionType.h │ │ ├── SingletonPredictionContext.h │ │ ├── ArrayPredictionContext.h │ │ ├── LexerATNConfig.h │ │ ├── Makefile │ │ ├── LexerCustomAction.cpp │ │ ├── ATNDeserializationOptions.cpp │ │ ├── LexerIndexedCustomAction.cpp │ │ ├── LexerSkipAction.h │ │ ├── ErrorInfo.h │ │ ├── LexerMoreAction.h │ │ ├── LexerPopModeAction.h │ │ ├── LookaheadEventInfo.h │ │ ├── LexerTypeAction.h │ │ └── LexerModeAction.h │ ├── CharStream.cpp │ ├── TokenStream.cpp │ ├── ANTLRErrorListener.cpp │ ├── ANTLRErrorStrategy.cpp │ ├── support │ │ ├── Any.cpp │ │ ├── Arrays.cpp │ │ ├── StringUtils.cpp │ │ └── BitSet.h │ ├── IntStream.cpp │ ├── InputMismatchException.cpp │ ├── ConsoleErrorListener.cpp │ ├── dfa │ │ ├── LexerDFASerializer.cpp │ │ ├── LexerDFASerializer.h │ │ └── DFASerializer.h │ ├── InterpreterRuleContext.cpp │ ├── WritableToken.h │ ├── RuleContextWithAltNum.cpp │ ├── InputMismatchException.h │ ├── ANTLRFileStream.cpp │ ├── ANTLRFileStream.h │ ├── LexerNoViableAltException.h │ ├── RuleContextWithAltNum.h │ ├── ConsoleErrorListener.h │ ├── FailedPredicateException.h │ ├── BaseErrorListener.cpp │ ├── TokenFactory.h │ ├── LexerNoViableAltException.cpp │ ├── CommonTokenFactory.cpp │ ├── BaseErrorListener.h │ ├── CharStream.h │ ├── NoViableAltException.cpp │ ├── InterpreterRuleContext.h │ ├── ProxyErrorListener.h │ ├── NoViableAltException.h │ ├── FailedPredicateException.cpp │ ├── BailErrorStrategy.cpp │ ├── CommonTokenStream.cpp │ └── ProxyErrorListener.cpp └── grammar │ ├── generated │ ├── cruleVisitor.cpp │ ├── cruleListener.cpp │ ├── cruleBaseListener.cpp │ ├── cruleBaseVisitor.cpp │ ├── crule.tokens │ └── cruleLexer.tokens │ └── .antlr │ ├── crule.tokens │ └── cruleLexer.tokens ├── ast_processor ├── constants.hpp ├── array_map_selector.hpp ├── literal.hpp ├── then_scope.hpp ├── crl.hpp ├── then_expressions.hpp ├── arguments.hpp ├── assignment.hpp ├── then_expression.hpp ├── function.hpp ├── if_scope.hpp └── rule_entry.hpp ├── engine ├── knowledge_base.hpp ├── data_context.hpp └── engine.hpp ├── LICENSE ├── log └── logger.hpp └── examples └── map_vector.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.o 3 | build 4 | -------------------------------------------------------------------------------- /rule_engine.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include "engine/engine.hpp" 3 | #include "engine/data_context.hpp" -------------------------------------------------------------------------------- /antlr/runtime/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /antlr/grammar/generated/cruleVisitor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from crule.g4 by ANTLR 4.9 3 | 4 | 5 | #include "cruleVisitor.h" 6 | 7 | 8 | using namespace rule_engine; 9 | 10 | -------------------------------------------------------------------------------- /antlr/grammar/generated/cruleListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from crule.g4 by ANTLR 4.9 3 | 4 | 5 | #include "cruleListener.h" 6 | 7 | 8 | using namespace rule_engine; 9 | 10 | -------------------------------------------------------------------------------- /antlr/grammar/generated/cruleBaseListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from crule.g4 by ANTLR 4.9 3 | 4 | 5 | #include "cruleBaseListener.h" 6 | 7 | 8 | using namespace rule_engine; 9 | 10 | -------------------------------------------------------------------------------- /antlr/grammar/generated/cruleBaseVisitor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from crule.g4 by ANTLR 4.9 3 | 4 | 5 | #include "cruleBaseVisitor.h" 6 | 7 | 8 | using namespace rule_engine; 9 | 10 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathLexer.tokens: -------------------------------------------------------------------------------- 1 | TOKEN_REF=1 2 | RULE_REF=2 3 | ANYWHERE=3 4 | ROOT=4 5 | WILDCARD=5 6 | BANG=6 7 | ID=7 8 | STRING=8 9 | '//'=3 10 | '/'=4 11 | '*'=5 12 | '!'=6 13 | -------------------------------------------------------------------------------- /antlr/runtime/Token.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | antlr4::Token::~Token() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/TokenSource.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenSource.h" 7 | 8 | antlr4::TokenSource::~TokenSource() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/WritableToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "WritableToken.h" 7 | 8 | antlr4::WritableToken::~WritableToken() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "LexerAction.h" 7 | 8 | antlr4::atn::LexerAction::~LexerAction() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ErrorNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | 8 | antlr4::tree::ErrorNode::~ErrorNode() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/Chunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/Chunk.h" 7 | 8 | antlr4::tree::pattern::Chunk::~Chunk() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/CharStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "CharStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | CharStream::~CharStream() { 11 | } 12 | -------------------------------------------------------------------------------- /antlr/runtime/tree/TerminalNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/TerminalNode.h" 7 | 8 | antlr4::tree::TerminalNode::~TerminalNode() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/TokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | TokenStream::~TokenStream() { 11 | } 12 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BlockStartState.h" 7 | 8 | antlr4::atn::BlockStartState::~BlockStartState() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/ANTLRErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorListener.h" 7 | 8 | antlr4::ANTLRErrorListener::~ANTLRErrorListener() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /antlr/runtime/ANTLRErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorStrategy.h" 7 | 8 | antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /antlr/runtime/support/Any.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Any.h" 7 | 8 | using namespace antlrcpp; 9 | 10 | Any::~Any() 11 | { 12 | delete _ptr; 13 | } 14 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ParseTreeVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeVisitor.h" 7 | 8 | antlr4::tree::ParseTreeVisitor::~ParseTreeVisitor() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ParseTreeListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeListener.h" 7 | 8 | antlr4::tree::ParseTreeListener::~ParseTreeListener() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BasicState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicState::getStateType() { 11 | return BASIC; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LoopEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LoopEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t LoopEndState::getStateType() { 11 | return LOOP_END; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RuleStopState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStopState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t RuleStopState::getStateType() { 11 | return RULE_STOP; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/TokensStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/TokensStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t TokensStartState::getStateType() { 11 | return TOKEN_START; 12 | } 13 | -------------------------------------------------------------------------------- /ast_processor/constants.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_CONSTANTS_ 2 | #define _RULE_ENGINE_CONSTANTS_ 3 | 4 | #include 5 | 6 | #include "node.hpp" 7 | #include "log/logger.hpp" 8 | #include "constant.hpp" 9 | 10 | namespace rule_engine { 11 | 12 | class Constants: public Node { 13 | public: 14 | Constants() {} 15 | private: 16 | std::vector constants_; 17 | }; 18 | 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /antlr/runtime/IntStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "IntStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | const std::string IntStream::UNKNOWN_SOURCE_NAME = ""; 11 | 12 | IntStream::~IntStream() = default; 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PlusLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusLoopbackState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusLoopbackState::getStateType() { 11 | return PLUS_LOOP_BACK; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BasicBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicBlockStartState::getStateType() { 11 | return BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PlusBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusBlockStartState::getStateType() { 11 | return PLUS_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/StarBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t StarBlockStartState::getStateType() { 11 | return STAR_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/OrderedATNConfigSet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/OrderedATNConfigSet.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t OrderedATNConfigSet::getHash(ATNConfig *c) { 11 | return c->hashCode(); 12 | } 13 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BlockEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BlockEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | BlockEndState::BlockEndState() : startState(nullptr) { 11 | } 12 | 13 | size_t BlockEndState::getStateType() { 14 | return BLOCK_END; 15 | } 16 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ParseTree.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | 8 | using namespace antlr4::tree; 9 | 10 | ParseTree::ParseTree() : parent(nullptr) { 11 | } 12 | 13 | bool ParseTree::operator == (const ParseTree &other) const { 14 | return &other == this; 15 | } 16 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RuleStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | RuleStartState::RuleStartState() { 11 | isLeftRecursiveRule = false; 12 | } 13 | 14 | size_t RuleStartState::getStateType() { 15 | return RULE_START; 16 | } 17 | -------------------------------------------------------------------------------- /antlr/runtime/atn/StarLoopEntryState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | StarLoopEntryState::StarLoopEntryState() : DecisionState(), isPrecedenceDecision(false) { 11 | } 12 | 13 | size_t StarLoopEntryState::getStateType() { 14 | return STAR_LOOP_ENTRY; 15 | } 16 | -------------------------------------------------------------------------------- /antlr/runtime/atn/AbstractPredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AbstractPredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | AbstractPredicateTransition::AbstractPredicateTransition(ATNState *target) : Transition(target) { 11 | } 12 | 13 | AbstractPredicateTransition::~AbstractPredicateTransition() { 14 | } 15 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ErrorNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ErrorNode : public virtual TerminalNode { 14 | public: 15 | ~ErrorNode() override; 16 | }; 17 | 18 | } // namespace tree 19 | } // namespace antlr4 20 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ATNType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Represents the type of recognizer an ATN applies to. 14 | enum class ATNType { 15 | LEXER = 0, 16 | PARSER = 1, 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /antlr/runtime/atn/DecisionState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | void DecisionState::InitializeInstanceFields() { 11 | decision = -1; 12 | nonGreedy = false; 13 | } 14 | 15 | std::string DecisionState::toString() const { 16 | return "DECISION " + ATNState::toString(); 17 | } 18 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BasicState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC BasicState final : public ATNState { 14 | 15 | public: 16 | virtual size_t getStateType() override; 17 | 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr/runtime/misc/Predicate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | class ANTLR4CPP_PUBLIC Predicate { 14 | public: 15 | virtual ~Predicate(); 16 | 17 | virtual bool test(tree::ParseTree *t) = 0; 18 | }; 19 | 20 | } // namespace tree 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr/runtime/atn/OrderedATNConfigSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfigSet.h" 9 | #include "atn/ATNConfig.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC OrderedATNConfigSet : public ATNConfigSet { 15 | protected: 16 | virtual size_t getHash(ATNConfig *c) override; 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathLexerErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPathLexerErrorListener.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::tree::xpath; 10 | 11 | void XPathLexerErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 12 | size_t /*line*/, size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ContextSensitivityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ContextSensitivityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | ContextSensitivityInfo::ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, 12 | size_t startIndex, size_t stopIndex) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, true) { 14 | } 15 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ErrorInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNConfigSet.h" 7 | 8 | #include "atn/ErrorInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | ErrorInfo::ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 14 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 15 | } 16 | -------------------------------------------------------------------------------- /antlr/runtime/atn/StarLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopbackState final : public ATNState { 14 | public: 15 | StarLoopEntryState *getLoopEntryState(); 16 | 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BasicBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | #include "atn/BlockStartState.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC BasicBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /engine/knowledge_base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_KB_ 2 | #define _RULE_ENGINE_KB_ 3 | 4 | #include 5 | #include 6 | #include "ast_processor/crl.hpp" 7 | namespace rule_engine { 8 | 9 | // DataContext holds the data to be manipulated by crule, usually structs. 10 | class KnowledgeBase { 11 | public: 12 | KnowledgeBase() { 13 | // TODO: 14 | } 15 | void set_crl(std::shared_ptr crl) { 16 | crl_ = crl; 17 | } 18 | std::shared_ptr get_crl() { 19 | return crl_; 20 | } 21 | private: 22 | std::shared_ptr crl_; 23 | }; 24 | 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/StarBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The block that begins a closure loop. 14 | class ANTLR4CPP_PUBLIC StarBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr/runtime/atn/BlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The start of a regular {@code (...)} block. 14 | class ANTLR4CPP_PUBLIC BlockStartState : public DecisionState { 15 | public: 16 | ~BlockStartState(); 17 | BlockEndState *endState = nullptr; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /ast_processor/array_map_selector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_SELECTOR_ 2 | #define _RULE_ENGINE_SELECTOR_ 3 | 4 | #include "node.hpp" 5 | 6 | namespace rule_engine { 7 | class ArrayMapSelector: public Node, public IExpressionAcceptor { 8 | public: 9 | ArrayMapSelector() {} 10 | void accept_expression(std::shared_ptr expr) { 11 | expression_ = std::dynamic_pointer_cast(expr); 12 | } 13 | 14 | rttr::variant evaluate(IDataContext* dctx) { 15 | return expression_->evaluate(dctx); 16 | } 17 | private: 18 | std::shared_ptr expression_; 19 | }; 20 | 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/LoopEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Mark the end of a * or + loop. 14 | class ANTLR4CPP_PUBLIC LoopEndState final : public ATNState { 15 | public: 16 | ATNState *loopBackState = nullptr; 17 | 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr/runtime/atn/StarLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/StarLoopbackState.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | StarLoopEntryState *StarLoopbackState::getLoopEntryState() { 14 | return dynamic_cast(transitions[0]->target); 15 | } 16 | 17 | size_t StarLoopbackState::getStateType() { 18 | return STAR_LOOP_BACK; 19 | } 20 | -------------------------------------------------------------------------------- /antlr/runtime/atn/DecisionEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | DecisionEventInfo::DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, 12 | size_t stopIndex, bool fullCtx) 13 | : decision(decision), configs(configs), input(input), startIndex(startIndex), stopIndex(stopIndex), fullCtx(fullCtx) { 14 | } 15 | -------------------------------------------------------------------------------- /antlr/runtime/atn/TokensStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The Tokens rule start state linking to each lexer rule start state. 14 | class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr/runtime/InputMismatchException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "InputMismatchException.h" 9 | 10 | using namespace antlr4; 11 | 12 | InputMismatchException::InputMismatchException(Parser *recognizer) 13 | : RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(), 14 | recognizer->getCurrentToken()) { 15 | } 16 | 17 | InputMismatchException::~InputMismatchException() { 18 | } 19 | -------------------------------------------------------------------------------- /antlr/runtime/atn/AbstractPredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTState; 14 | 15 | class ANTLR4CPP_PUBLIC AbstractPredicateTransition : public Transition { 16 | 17 | public: 18 | AbstractPredicateTransition(ATNState *target); 19 | ~AbstractPredicateTransition(); 20 | 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /ast_processor/literal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_LITERAL_ 2 | #define _RULE_ENGINE_LITERAL_ 3 | 4 | #include "node.hpp" 5 | 6 | namespace rule_engine { 7 | 8 | class StringLiteral: public Node { 9 | public: 10 | std::string string_; 11 | virtual ~StringLiteral() {} 12 | }; 13 | 14 | class IntegerLiteral: public Node { 15 | public: 16 | int int_; 17 | virtual ~IntegerLiteral() {} 18 | }; 19 | 20 | class FloatLiteral: public Node { 21 | public: 22 | float float_; 23 | virtual ~FloatLiteral() {} 24 | }; 25 | 26 | class BooleanLiteral: public Node { 27 | public: 28 | bool bool_; 29 | virtual ~BooleanLiteral() {} 30 | }; 31 | 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /ast_processor/then_scope.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_THEN_SCOPE_ 2 | #define _RULE_ENGINE_THEN_SCOPE_ 3 | 4 | #include 5 | 6 | #include "then_expressions.hpp" 7 | #include "node.hpp" 8 | 9 | namespace rule_engine { 10 | 11 | class ThenScope: public Node, public IThenExpressionsAcceptor { 12 | public: 13 | ThenScope() {} 14 | virtual void accept_then_expressions(std::shared_ptr exprs) { 15 | then_expressions_ = exprs; 16 | } 17 | void execute(IDataContext* dctx) { 18 | then_expressions_->execute(dctx); 19 | } 20 | private: 21 | std::shared_ptr then_expressions_; 22 | }; 23 | 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /antlr/runtime/ConsoleErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ConsoleErrorListener.h" 7 | 8 | using namespace antlr4; 9 | 10 | ConsoleErrorListener ConsoleErrorListener::INSTANCE; 11 | 12 | void ConsoleErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 13 | size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) { 14 | std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LookaheadEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LookaheadEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | LookaheadEventInfo::LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->predictedAlt = predictedAlt; 16 | } 17 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RuleStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleStartState final : public ATNState { 14 | public: 15 | RuleStartState(); 16 | 17 | RuleStopState *stopState = nullptr; 18 | bool isLeftRecursiveRule = false; 19 | 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr/runtime/dfa/LexerDFASerializer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Vocabulary.h" 7 | 8 | #include "dfa/LexerDFASerializer.h" 9 | 10 | using namespace antlr4::dfa; 11 | 12 | LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, Vocabulary::EMPTY_VOCABULARY) { 13 | } 14 | 15 | LexerDFASerializer::~LexerDFASerializer() { 16 | } 17 | 18 | std::string LexerDFASerializer::getEdgeLabel(size_t i) const { 19 | return std::string("'") + static_cast(i) + "'"; 20 | } 21 | -------------------------------------------------------------------------------- /antlr/runtime/dfa/LexerDFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "dfa/DFASerializer.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | class ANTLR4CPP_PUBLIC LexerDFASerializer : public DFASerializer { 14 | public: 15 | LexerDFASerializer(DFA *dfa); 16 | virtual ~LexerDFASerializer(); 17 | 18 | protected: 19 | virtual std::string getEdgeLabel(size_t i) const override; 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathWildcardElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardElement : public XPathElement { 15 | public: 16 | XPathWildcardElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /ast_processor/crl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_CRL_ 2 | #define _RULE_ENGINE_CRL_ 3 | 4 | #include 5 | 6 | #include "node.hpp" 7 | #include "rule_entry.hpp" 8 | 9 | namespace rule_engine { 10 | 11 | class Crl: public Node, public IRuleEntryAcceptor { 12 | public: 13 | Crl() {} 14 | std::unordered_map>& get_rule_entries() { 15 | return rule_enties_; 16 | } 17 | virtual void accept_rule_entry(std::shared_ptr entry) { 18 | rule_enties_[entry->get_name()] = entry; 19 | } 20 | private: 21 | std::unordered_map> rule_enties_; 22 | }; 23 | 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/BlockEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Terminal node of a simple {@code (a|b|c)} block. 14 | class ANTLR4CPP_PUBLIC BlockEndState final : public ATNState { 15 | public: 16 | BlockStartState *startState = nullptr; 17 | 18 | BlockEndState(); 19 | 20 | virtual size_t getStateType() override; 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /antlr/runtime/atn/AmbiguityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AmbiguityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | AmbiguityInfo::AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->ambigAlts = ambigAlts; 16 | } 17 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathWildcardAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardAnywhereElement : public XPathElement { 15 | public: 16 | XPathWildcardAnywhereElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /antlr/runtime/InterpreterRuleContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "InterpreterRuleContext.h" 7 | 8 | using namespace antlr4; 9 | 10 | InterpreterRuleContext::InterpreterRuleContext() : ParserRuleContext() { 11 | } 12 | 13 | InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex) 14 | : ParserRuleContext(parent, invokingStateNumber), _ruleIndex(ruleIndex) { 15 | } 16 | 17 | size_t InterpreterRuleContext::getRuleIndex() const { 18 | return _ruleIndex; 19 | } 20 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ErrorNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "tree/ParseTreeVisitor.h" 8 | 9 | #include "tree/ErrorNodeImpl.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::misc; 13 | using namespace antlr4::tree; 14 | 15 | ErrorNodeImpl::ErrorNodeImpl(Token *token) : TerminalNodeImpl(token) { 16 | } 17 | 18 | ErrorNodeImpl::~ErrorNodeImpl() { 19 | } 20 | 21 | antlrcpp::Any ErrorNodeImpl::accept(ParseTreeVisitor *visitor) { 22 | return visitor->visitErrorNode(this); 23 | } 24 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PlusLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions: 14 | /// one to the loop back to start of the block and one to exit. 15 | class ANTLR4CPP_PUBLIC PlusLoopbackState final : public DecisionState { 16 | 17 | public: 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr/runtime/atn/DecisionState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC DecisionState : public ATNState { 14 | public: 15 | int decision; 16 | bool nonGreedy; 17 | 18 | private: 19 | void InitializeInstanceFields(); 20 | 21 | public: 22 | DecisionState() { 23 | InitializeInstanceFields(); 24 | } 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathWildcardElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardElement::XPathWildcardElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | 23 | return t->children; 24 | } 25 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathLexerErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathLexerErrorListener : public BaseErrorListener { 15 | public: 16 | virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, 17 | size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override; 18 | }; 19 | 20 | } // namespace xpath 21 | } // namespace tree 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathRuleElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathRuleElement : public XPathElement { 15 | public: 16 | XPathRuleElement(const std::string &ruleName, size_t ruleIndex); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _ruleIndex = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathTokenElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenElement : public XPathElement { 15 | public: 16 | XPathTokenElement(const std::string &tokenName, size_t tokenType); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _tokenType = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PredicateEvalInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "SemanticContext.h" 7 | 8 | #include "atn/PredicateEvalInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, 14 | Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx) 15 | : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), 16 | semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) { 17 | } 18 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/TextChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TextChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TextChunk::TextChunk(const std::string &text) : text(text) { 13 | if (text == "") { 14 | throw IllegalArgumentException("text cannot be nul"); 15 | } 16 | 17 | } 18 | 19 | TextChunk::~TextChunk() { 20 | } 21 | 22 | std::string TextChunk::getText() { 23 | return text; 24 | } 25 | 26 | std::string TextChunk::toString() { 27 | return std::string("'") + text + std::string("'"); 28 | } 29 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathRuleAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "tree/xpath/XPathRuleAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleAnywhereElement::XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllRuleNodes(t, _ruleIndex); 20 | } 21 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathTokenAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathTokenAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathTokenAnywhereElement::XPathTokenAnywhereElement(const std::string &tokenName, int tokenType) : XPathElement(tokenName) { 15 | this->tokenType = tokenType; 16 | } 17 | 18 | std::vector XPathTokenAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllTokenNodes(t, tokenType); 20 | } 21 | -------------------------------------------------------------------------------- /ast_processor/then_expressions.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_THEN_EXPRESSIONS_ 2 | #define _RULE_ENGINE_THEN_EXPRESSIONS_ 3 | 4 | #include 5 | #include 6 | 7 | #include "then_expression.hpp" 8 | #include "node.hpp" 9 | 10 | namespace rule_engine { 11 | 12 | class ThenExpressions: public Node, public IThenExpressionAcceptor { 13 | public: 14 | ThenExpressions() {} 15 | virtual void accept_then_expression(std::shared_ptr expr) { 16 | expressions_.push_back(expr); 17 | } 18 | void execute(IDataContext* dctx) { 19 | for(auto expr:expressions_) { 20 | expr->execute(dctx); 21 | } 22 | } 23 | private: 24 | std::vector> expressions_; 25 | }; 26 | 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathTokenAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenAnywhereElement : public XPathElement { 15 | protected: 16 | int tokenType = 0; 17 | public: 18 | XPathTokenAnywhereElement(const std::string &tokenName, int tokenType); 19 | 20 | virtual std::vector evaluate(ParseTree *t) override; 21 | }; 22 | 23 | } // namespace xpath 24 | } // namespace tree 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr/runtime/WritableToken.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Token.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC WritableToken : public Token { 13 | public: 14 | virtual ~WritableToken(); 15 | virtual void setText(const std::string &text) = 0; 16 | virtual void setType(size_t ttype) = 0; 17 | virtual void setLine(size_t line) = 0; 18 | virtual void setCharPositionInLine(size_t pos) = 0; 19 | virtual void setChannel(size_t channel) = 0; 20 | virtual void setTokenIndex(size_t index) = 0; 21 | }; 22 | 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /antlr/runtime/atn/WildcardTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC WildcardTransition final : public Transition { 14 | public: 15 | WildcardTransition(ATNState *target); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathWildcardAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardAnywhereElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardAnywhereElement::XPathWildcardAnywhereElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardAnywhereElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | return Trees::getDescendants(t); 23 | } 24 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RuleStopState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The last node in the ATN for a rule, unless that rule is the start symbol. 14 | /// In that case, there is one transition to EOF. Later, we might encode 15 | /// references to all calls to this rule to compute FOLLOW sets for 16 | /// error handling. 17 | class ANTLR4CPP_PUBLIC RuleStopState final : public ATNState { 18 | 19 | public: 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /engine/data_context.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_DATA_CTX_ 2 | #define _RULE_ENGINE_DATA_CTX_ 3 | 4 | #include 5 | #include 6 | 7 | #include "ast_processor/rule_entry.hpp" 8 | 9 | namespace rule_engine { 10 | 11 | // DataContext holds the data to be manipulated by crule, usually structs. 12 | class DataContext: public IDataContext { 13 | public: 14 | DataContext() {} 15 | 16 | void add(const std::string& name, rttr::instance obj) { 17 | map_.insert(std::make_pair(name, obj)); 18 | } 19 | void remove(const std::string& name) { 20 | map_.erase(name); 21 | } 22 | 23 | rttr::instance get(const std::string& name) { 24 | return map_[name]; 25 | } 26 | private: 27 | std::unordered_map map_; 28 | }; 29 | 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/NotSetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SetTransition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC NotSetTransition final : public SetTransition { 14 | public: 15 | NotSetTransition(ATNState *target, const misc::IntervalSet &set); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathRuleAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | /// Either {@code ID} at start of path or {@code ...//ID} in middle of path. 15 | class ANTLR4CPP_PUBLIC XPathRuleAnywhereElement : public XPathElement { 16 | public: 17 | XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex); 18 | 19 | virtual std::vector evaluate(ParseTree *t) override; 20 | 21 | protected: 22 | int _ruleIndex = 0; 23 | }; 24 | 25 | } // namespace xpath 26 | } // namespace tree 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /antlr/runtime/RuleContextWithAltNum.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATN.h" 7 | 8 | #include "RuleContextWithAltNum.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() { 14 | altNum = ATN::INVALID_ALT_NUMBER; 15 | } 16 | 17 | RuleContextWithAltNum::RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber) 18 | : ParserRuleContext(parent, invokingStateNumber) { 19 | } 20 | 21 | size_t RuleContextWithAltNum::getAltNumber() const { 22 | return altNum; 23 | } 24 | 25 | void RuleContextWithAltNum::setAltNumber(size_t number) { 26 | altNum = number; 27 | } 28 | -------------------------------------------------------------------------------- /antlr/runtime/atn/WildcardTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNState.h" 7 | 8 | #include "atn/WildcardTransition.h" 9 | 10 | using namespace antlr4::atn; 11 | 12 | WildcardTransition::WildcardTransition(ATNState *target) : Transition(target) { 13 | } 14 | 15 | Transition::SerializationType WildcardTransition::getSerializationType() const { 16 | return WILDCARD; 17 | } 18 | 19 | bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 20 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol; 21 | } 22 | 23 | std::string WildcardTransition::toString() const { 24 | return "WILDCARD " + Transition::toString() + " {}"; 25 | } 26 | -------------------------------------------------------------------------------- /antlr/runtime/InputMismatchException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// 13 | /// This signifies any kind of mismatched input exceptions such as 14 | /// when the current input does not match the expected token. 15 | /// 16 | class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException { 17 | public: 18 | InputMismatchException(Parser *recognizer); 19 | InputMismatchException(InputMismatchException const&) = default; 20 | ~InputMismatchException(); 21 | InputMismatchException& operator=(InputMismatchException const&) = default; 22 | }; 23 | 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/CPPUtils.h" 7 | 8 | #include "XPathElement.h" 9 | 10 | using namespace antlr4::tree; 11 | using namespace antlr4::tree::xpath; 12 | 13 | XPathElement::XPathElement(const std::string &nodeName) { 14 | _nodeName = nodeName; 15 | } 16 | 17 | XPathElement::~XPathElement() { 18 | } 19 | 20 | std::vector XPathElement::evaluate(ParseTree * /*t*/) { 21 | return {}; 22 | } 23 | 24 | std::string XPathElement::toString() const { 25 | std::string inv = _invert ? "!" : ""; 26 | return antlrcpp::toString(*this) + "[" + inv + _nodeName + "]"; 27 | } 28 | 29 | void XPathElement::setInvert(bool value) { 30 | _invert = value; 31 | } 32 | -------------------------------------------------------------------------------- /ast_processor/arguments.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_ARGS_ 2 | #define _RULE_ENGINE_ARGS_ 3 | 4 | #include 5 | #include 6 | 7 | #include "node.hpp" 8 | 9 | namespace rule_engine { 10 | 11 | class Expression; 12 | class Arguments: public Node, public IExpressionAcceptor { 13 | public: 14 | Arguments() {} 15 | virtual void accept_expression(std::shared_ptr expr) { 16 | args_.push_back(std::dynamic_pointer_cast(expr)); 17 | } 18 | std::shared_ptr> evaluate(IDataContext* dctx) { 19 | auto ans = std::make_shared>(); 20 | if(args_.empty()) return ans; 21 | for(auto& arg:args_) { 22 | ans->push_back(arg->evaluate(dctx)); 23 | } 24 | return ans; 25 | } 26 | private: 27 | std::vector> args_; 28 | }; 29 | 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/PlusBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Start of {@code (A|B|...)+} loop. Technically a decision state, but 14 | /// we don't use for code generation; somebody might need it, so I'm defining 15 | /// it for completeness. In reality, the node is the 16 | /// real decision-making note for {@code A+}. 17 | class ANTLR4CPP_PUBLIC PlusBlockStartState final : public BlockStartState { 18 | public: 19 | PlusLoopbackState *loopBackState = nullptr; 20 | 21 | virtual size_t getStateType() override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RangeTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RangeTransition final : public Transition { 14 | public: 15 | const size_t from; 16 | const size_t to; 17 | 18 | RangeTransition(ATNState *target, size_t from, size_t to); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | 22 | virtual misc::IntervalSet label() const override; 23 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 24 | 25 | virtual std::string toString() const override; 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /antlr/runtime/atn/EmptyPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SingletonPredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EmptyPredictionContext : public SingletonPredictionContext { 14 | public: 15 | EmptyPredictionContext(); 16 | 17 | virtual bool isEmpty() const override; 18 | virtual size_t size() const override; 19 | virtual Ref getParent(size_t index) const override; 20 | virtual size_t getReturnState(size_t index) const override; 21 | virtual std::string toString() const override; 22 | 23 | virtual bool operator == (const PredictionContext &o) const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /antlr/runtime/ANTLRFileStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | #include "ANTLRFileStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | ANTLRFileStream::ANTLRFileStream(const std::string &fileName) { 13 | _fileName = fileName; 14 | loadFromFile(fileName); 15 | } 16 | 17 | void ANTLRFileStream::loadFromFile(const std::string &fileName) { 18 | _fileName = fileName; 19 | if (_fileName.empty()) { 20 | return; 21 | } 22 | 23 | #ifdef _MSC_VER 24 | std::ifstream stream(antlrcpp::s2ws(fileName), std::ios::binary); 25 | #else 26 | std::ifstream stream(fileName, std::ios::binary); 27 | #endif 28 | 29 | ANTLRInputStream::load(stream); 30 | } 31 | 32 | std::string ANTLRFileStream::getSourceName() const { 33 | return _fileName; 34 | } 35 | -------------------------------------------------------------------------------- /antlr/runtime/tree/TerminalNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ParseTree.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNode : public ParseTree { 14 | public: 15 | ~TerminalNode() override; 16 | 17 | virtual Token* getSymbol() = 0; 18 | 19 | /** Set the parent for this leaf node. 20 | * 21 | * Technically, this is not backward compatible as it changes 22 | * the interface but no one was able to create custom 23 | * TerminalNodes anyway so I'm adding as it improves internal 24 | * code quality. 25 | * 26 | * @since 4.7 27 | */ 28 | virtual void setParent(RuleContext *parent) = 0; 29 | }; 30 | 31 | } // namespace tree 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr/runtime/atn/SetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// A transition containing a set of values. 15 | class ANTLR4CPP_PUBLIC SetTransition : public Transition { 16 | public: 17 | const misc::IntervalSet set; 18 | 19 | SetTransition(ATNState *target, const misc::IntervalSet &set); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr/runtime/ANTLRFileStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRInputStream.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// This is an ANTLRInputStream that is loaded from a file all at once 13 | /// when you construct the object (or call load()). 14 | // TODO: this class needs testing. 15 | class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { 16 | protected: 17 | std::string _fileName; // UTF-8 encoded file name. 18 | 19 | public: 20 | // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). 21 | ANTLRFileStream(const std::string &fileName); 22 | 23 | virtual void loadFromFile(const std::string &fileName); 24 | virtual std::string getSourceName() const override; 25 | }; 26 | 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /antlr/runtime/dfa/DFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Vocabulary.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | /// A DFA walker that knows how to dump them to serialized strings. 14 | class ANTLR4CPP_PUBLIC DFASerializer { 15 | public: 16 | DFASerializer(const DFA *dfa, const std::vector& tnames); 17 | DFASerializer(const DFA *dfa, const Vocabulary &vocabulary); 18 | virtual ~DFASerializer(); 19 | 20 | virtual std::string toString() const; 21 | 22 | protected: 23 | virtual std::string getEdgeLabel(size_t i) const; 24 | virtual std::string getStateString(DFAState *s) const; 25 | 26 | private: 27 | const DFA *_dfa; 28 | const Vocabulary &_vocabulary; 29 | }; 30 | 31 | } // namespace atn 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/TagChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TagChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TagChunk::TagChunk(const std::string &tag) : TagChunk("", tag) { 13 | } 14 | 15 | TagChunk::TagChunk(const std::string &label, const std::string &tag) : _tag(tag), _label(label) { 16 | if (tag.empty()) { 17 | throw IllegalArgumentException("tag cannot be null or empty"); 18 | } 19 | 20 | } 21 | 22 | TagChunk::~TagChunk() { 23 | } 24 | 25 | std::string TagChunk::getTag() { 26 | return _tag; 27 | } 28 | 29 | std::string TagChunk::getLabel() { 30 | return _label; 31 | } 32 | 33 | std::string TagChunk::toString() { 34 | if (!_label.empty()) { 35 | return _label + ":" + _tag; 36 | } 37 | 38 | return _tag; 39 | } 40 | -------------------------------------------------------------------------------- /ast_processor/assignment.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_ASSIGNMENT_ 2 | #define _RULE_ENGINE_ASSIGNMENT_ 3 | 4 | #include 5 | 6 | #include "node.hpp" 7 | #include "variable.hpp" 8 | #include "expression.hpp" 9 | 10 | namespace rule_engine { 11 | 12 | class Assignment: public Node, public IExpressionAcceptor, public IVariableAcceptor { 13 | public: 14 | Assignment() {} 15 | void accept_expression(std::shared_ptr expr) { 16 | expression_ = expr; 17 | } 18 | virtual void accept_variable(std::shared_ptr var) { 19 | var->set_top_level(); 20 | variable_ = var; 21 | } 22 | 23 | void execute(IDataContext* dctx) { 24 | auto right = expression_->evaluate(dctx); 25 | variable_->assign(dctx, right, type_); 26 | } 27 | 28 | void set_type(ASSIGN_TYPE t) {type_ = t;} 29 | private: 30 | std::shared_ptr variable_; 31 | std::shared_ptr expression_; 32 | ASSIGN_TYPE type_; 33 | }; 34 | 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /ast_processor/then_expression.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_THEN_EXPRESSION_ 2 | #define _RULE_ENGINE_THEN_EXPRESSION_ 3 | 4 | #include 5 | 6 | #include "assignment.hpp" 7 | #include "expression_atom.hpp" 8 | #include "node.hpp" 9 | 10 | namespace rule_engine { 11 | 12 | class ThenExpression: public Node, 13 | public IExpressionAtomAcceptor, public IAssignmentAcceptor { 14 | public: 15 | ThenExpression() {} 16 | virtual void accept_expression_atom(std::shared_ptr atom) { 17 | atom_ = atom; 18 | } 19 | 20 | virtual void accept_assignment(std::shared_ptr assignment) { 21 | assignment_ = assignment; 22 | } 23 | 24 | void execute(IDataContext* dctx) { 25 | if(assignment_) { 26 | assignment_->execute(dctx); 27 | } else if(atom_) { 28 | atom_->execute(dctx); 29 | } 30 | } 31 | private: 32 | std::shared_ptr assignment_; 33 | std::shared_ptr atom_; 34 | }; 35 | 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/AtomTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// TODO: make all transitions sets? no, should remove set edges. 14 | class ANTLR4CPP_PUBLIC AtomTransition final : public Transition { 15 | public: 16 | /// The token type or character value; or, signifies special label. 17 | const size_t _label; 18 | 19 | AtomTransition(ATNState *target, size_t label); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr/runtime/atn/DecisionInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ErrorInfo.h" 7 | #include "atn/LookaheadEventInfo.h" 8 | 9 | #include "atn/DecisionInfo.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | DecisionInfo::DecisionInfo(size_t decision) : decision(decision) { 14 | } 15 | 16 | std::string DecisionInfo::toString() const { 17 | std::stringstream ss; 18 | 19 | ss << "{decision=" << decision << ", contextSensitivities=" << contextSensitivities.size() << ", errors="; 20 | ss << errors.size() << ", ambiguities=" << ambiguities.size() << ", SLL_lookahead=" << SLL_TotalLook; 21 | ss << ", SLL_ATNTransitions=" << SLL_ATNTransitions << ", SLL_DFATransitions=" << SLL_DFATransitions; 22 | ss << ", LL_Fallback=" << LL_Fallback << ", LL_lookahead=" << LL_TotalLook << ", LL_ATNTransitions=" << LL_ATNTransitions << '}'; 23 | 24 | return ss.str(); 25 | } 26 | -------------------------------------------------------------------------------- /antlr/runtime/atn/AtomTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/AtomTransition.h" 10 | 11 | using namespace antlr4::misc; 12 | using namespace antlr4::atn; 13 | 14 | AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) { 15 | } 16 | 17 | Transition::SerializationType AtomTransition::getSerializationType() const { 18 | return ATOM; 19 | } 20 | 21 | IntervalSet AtomTransition::label() const { 22 | return IntervalSet::of((int)_label); 23 | } 24 | 25 | bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 26 | return _label == symbol; 27 | } 28 | 29 | std::string AtomTransition::toString() const { 30 | return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }"; 31 | } 32 | -------------------------------------------------------------------------------- /antlr/runtime/atn/EmptyPredictionContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EmptyPredictionContext.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) { 11 | } 12 | 13 | bool EmptyPredictionContext::isEmpty() const { 14 | return true; 15 | } 16 | 17 | size_t EmptyPredictionContext::size() const { 18 | return 1; 19 | } 20 | 21 | Ref EmptyPredictionContext::getParent(size_t /*index*/) const { 22 | return nullptr; 23 | } 24 | 25 | size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const { 26 | return returnState; 27 | } 28 | 29 | bool EmptyPredictionContext::operator == (const PredictionContext &o) const { 30 | return this == &o; 31 | } 32 | 33 | std::string EmptyPredictionContext::toString() const { 34 | return "$"; 35 | } 36 | -------------------------------------------------------------------------------- /ast_processor/function.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_FUNCTION_ 2 | #define _RULE_ENGINE_FUNCTION_ 3 | 4 | #include 5 | 6 | #include "node.hpp" 7 | #include "arguments.hpp" 8 | 9 | namespace rule_engine { 10 | 11 | class Function: public Node, public IArgumentsAcceptor { 12 | public: 13 | Function() {} 14 | 15 | virtual void accept_arguments(std::shared_ptr args) { 16 | args_ = args; 17 | } 18 | void set_name(const std::string& name) {name_ = name;} 19 | std::string get_name() {return name_;} 20 | std::shared_ptr> evaluate_args(IDataContext* dctx) { 21 | if(!args_) return std::make_shared>(); 22 | return args_->evaluate(dctx); 23 | } 24 | void execute(IDataContext* dctx) { 25 | 26 | } 27 | 28 | rttr::variant evaluate(IDataContext* dctx) { 29 | // TODO: 30 | return rttr::variant(); 31 | } 32 | private: 33 | std::string name_; 34 | std::shared_ptr args_; 35 | }; 36 | 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/PrecedencePredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC PrecedencePredicateTransition final : public AbstractPredicateTransition { 15 | public: 16 | const int precedence; 17 | 18 | PrecedencePredicateTransition(ATNState *target, int precedence); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | virtual bool isEpsilon() const override; 22 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 23 | Ref getPredicate() const; 24 | virtual std::string toString() const override; 25 | 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /antlr/runtime/LexerNoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "atn/ATNConfigSet.h" 10 | 11 | namespace antlr4 { 12 | 13 | class ANTLR4CPP_PUBLIC LexerNoViableAltException : public RecognitionException { 14 | public: 15 | LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs); 17 | 18 | virtual size_t getStartIndex(); 19 | virtual atn::ATNConfigSet* getDeadEndConfigs(); 20 | virtual std::string toString(); 21 | 22 | private: 23 | /// Matching attempted at what input index? 24 | const size_t _startIndex; 25 | 26 | /// Which configurations did we try at input.index() that couldn't match input.LA(1)? 27 | atn::ATNConfigSet *_deadEndConfigs; 28 | 29 | }; 30 | 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /antlr/runtime/atn/NotSetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/NotSetTransition.h" 7 | #include "atn/ATNState.h" 8 | #include "misc/IntervalSet.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) { 14 | } 15 | 16 | Transition::SerializationType NotSetTransition::getSerializationType() const { 17 | return NOT_SET; 18 | } 19 | 20 | bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 21 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 22 | && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol); 23 | } 24 | 25 | std::string NotSetTransition::toString() const { 26 | return "NOT_SET " + Transition::toString() + " { " + SetTransition::toString() + " }"; 27 | } 28 | -------------------------------------------------------------------------------- /antlr/runtime/misc/InterpreterDataReader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | struct InterpreterData { 14 | atn::ATN atn; 15 | dfa::Vocabulary vocabulary; 16 | std::vector ruleNames; 17 | std::vector channels; // Only valid for lexer grammars. 18 | std::vector modes; // ditto 19 | 20 | InterpreterData() {}; // For invalid content. 21 | InterpreterData(std::vector const& literalNames, std::vector const& symbolicNames); 22 | }; 23 | 24 | // A class to read plain text interpreter data produced by ANTLR. 25 | class ANTLR4CPP_PUBLIC InterpreterDataReader { 26 | public: 27 | static InterpreterData parseFile(std::string const& fileName); 28 | }; 29 | 30 | } // namespace atn 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /ast_processor/if_scope.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_IF_SCOPE_ 2 | #define _RULE_ENGINE_IF_SCOPE_ 3 | 4 | #include 5 | 6 | #include "node.hpp" 7 | #include "expression.hpp" 8 | 9 | namespace rule_engine { 10 | 11 | class IfScope: public Node, public IExpressionAcceptor { 12 | public: 13 | IfScope() {} 14 | bool evaluate(IDataContext* dctx) { 15 | rttr::variant result = expression_->evaluate(dctx); 16 | if(!result.is_valid()) { 17 | error("unresolved IfScope"); 18 | } 19 | if(result.get_type() != rttr::type::get()) { 20 | error("invalid IfScope: not a boolean expression"); 21 | } 22 | // info("IfScope evaluated: " + result.to_string()); 23 | return result.to_bool(); 24 | } 25 | void accept_expression(std::shared_ptr expr) { 26 | expression_ = expr; 27 | } 28 | private: 29 | std::shared_ptr expression_; 30 | }; 31 | 32 | struct IIfScopeAcceptor { 33 | virtual void accept_if_scope(std::shared_ptr) = 0; 34 | }; 35 | 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /ast_processor/rule_entry.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_RULE_ENTRY_ 2 | #define _RULE_ENGINE_RULE_ENTRY_ 3 | 4 | #include 5 | 6 | #include "node.hpp" 7 | #include "if_scope.hpp" 8 | #include "then_scope.hpp" 9 | 10 | namespace rule_engine { 11 | 12 | class RuleEntry: public Node, 13 | public IIfScopeAcceptor, public IThenScopeAcceptor { 14 | public: 15 | RuleEntry() {} 16 | bool evaluate(IDataContext* dctx) { 17 | return if_scope_->evaluate(dctx); 18 | } 19 | void execute(IDataContext* dctx) { 20 | then_scope_->execute(dctx); 21 | } 22 | 23 | virtual void accept_if_scope(std::shared_ptr node) { 24 | if_scope_ = node; 25 | } 26 | virtual void accept_then_scope(std::shared_ptr node) { 27 | then_scope_ = node; 28 | } 29 | const std::string& get_name() {return name_;} 30 | private: 31 | std::string name_; 32 | std::string description_; 33 | int salience_; 34 | 35 | std::shared_ptr if_scope_; 36 | std::shared_ptr then_scope_; 37 | }; 38 | 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/SetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | #include "misc/IntervalSet.h" 8 | 9 | #include "atn/SetTransition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | SetTransition::SetTransition(ATNState *target, const misc::IntervalSet &aSet) 15 | : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : aSet) { 16 | } 17 | 18 | Transition::SerializationType SetTransition::getSerializationType() const { 19 | return SET; 20 | } 21 | 22 | misc::IntervalSet SetTransition::label() const { 23 | return set; 24 | } 25 | 26 | bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return set.contains(symbol); 28 | } 29 | 30 | std::string SetTransition::toString() const { 31 | return "SET " + Transition::toString() + " { set: " + set.toString() + "}"; 32 | } 33 | -------------------------------------------------------------------------------- /antlr/runtime/atn/StarLoopEntryState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopEntryState final : public DecisionState { 14 | public: 15 | StarLoopEntryState(); 16 | 17 | /** 18 | * Indicates whether this state can benefit from a precedence DFA during SLL 19 | * decision making. 20 | * 21 | *

This is a computed property that is calculated during ATN deserialization 22 | * and stored for use in {@link ParserATNSimulator} and 23 | * {@link ParserInterpreter}.

24 | * 25 | * @see DFA#isPrecedenceDfa() 26 | */ 27 | bool isPrecedenceDecision = false; 28 | 29 | StarLoopbackState *loopBackState = nullptr; 30 | 31 | virtual size_t getStateType() override; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /antlr/runtime/tree/TerminalNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNodeImpl : public virtual TerminalNode { 14 | public: 15 | Token *symbol; 16 | 17 | TerminalNodeImpl(Token *symbol); 18 | 19 | virtual Token* getSymbol() override; 20 | virtual void setParent(RuleContext *parent) override; 21 | virtual misc::Interval getSourceInterval() override; 22 | 23 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 24 | 25 | virtual std::string getText() override; 26 | virtual std::string toStringTree(Parser *parser, bool pretty = false) override; 27 | virtual std::string toString() override; 28 | virtual std::string toStringTree(bool pretty = false) override; 29 | 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ActionTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ActionTransition final : public Transition { 14 | public: 15 | const size_t ruleIndex; 16 | const size_t actionIndex; 17 | const bool isCtxDependent; // e.g., $i ref in action 18 | 19 | ActionTransition(ATNState *target, size_t ruleIndex); 20 | 21 | ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent); 22 | 23 | virtual SerializationType getSerializationType() const override; 24 | 25 | virtual bool isEpsilon() const override; 26 | 27 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 28 | 29 | virtual std::string toString() const override; 30 | }; 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RangeTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | 8 | #include "atn/RangeTransition.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RangeTransition::RangeTransition(ATNState *target, size_t from, size_t to) : Transition(target), from(from), to(to) { 14 | } 15 | 16 | Transition::SerializationType RangeTransition::getSerializationType() const { 17 | return RANGE; 18 | } 19 | 20 | misc::IntervalSet RangeTransition::label() const { 21 | return misc::IntervalSet::of((int)from, (int)to); 22 | } 23 | 24 | bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 25 | return symbol >= from && symbol <= to; 26 | } 27 | 28 | std::string RangeTransition::toString() const { 29 | return "RANGE " + Transition::toString() + " { from: " + std::to_string(from) + ", to: " + std::to_string(to) + " }"; 30 | } 31 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathRuleElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathRuleElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleElement::XPathRuleElement(const std::string &ruleName, size_t ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleElement::evaluate(ParseTree *t) { 19 | // return all children of t that match nodeName 20 | std::vector nodes; 21 | for (auto *c : t->children) { 22 | if (antlrcpp::is(c)) { 23 | ParserRuleContext *ctx = dynamic_cast(c); 24 | if ((ctx->getRuleIndex() == _ruleIndex && !_invert) || (ctx->getRuleIndex() != _ruleIndex && _invert)) { 25 | nodes.push_back(ctx); 26 | } 27 | } 28 | } 29 | return nodes; 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 jesse 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /antlr/runtime/RuleContextWithAltNum.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A handy class for use with 13 | /// 14 | /// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} 15 | /// 16 | /// that provides a backing field / impl for the outer alternative number 17 | /// matched for an internal parse tree node. 18 | /// 19 | /// I'm only putting into Java runtime as I'm certain I'm the only one that 20 | /// will really every use this. 21 | class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext { 22 | public: 23 | size_t altNum = 0; 24 | 25 | RuleContextWithAltNum(); 26 | RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber); 27 | 28 | virtual size_t getAltNumber() const override; 29 | virtual void setAltNumber(size_t altNum) override; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/TokenTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/TokenTagToken.h" 7 | 8 | using namespace antlr4::tree::pattern; 9 | 10 | TokenTagToken::TokenTagToken(const std::string &/*tokenName*/, int type) 11 | : CommonToken(type), tokenName(""), label("") { 12 | } 13 | 14 | TokenTagToken::TokenTagToken(const std::string &tokenName, int type, const std::string &label) 15 | : CommonToken(type), tokenName(tokenName), label(label) { 16 | } 17 | 18 | std::string TokenTagToken::getTokenName() const { 19 | return tokenName; 20 | } 21 | 22 | std::string TokenTagToken::getLabel() const { 23 | return label; 24 | } 25 | 26 | std::string TokenTagToken::getText() const { 27 | if (!label.empty()) { 28 | return "<" + label + ":" + tokenName + ">"; 29 | } 30 | 31 | return "<" + tokenName + ">"; 32 | } 33 | 34 | std::string TokenTagToken::toString() const { 35 | return tokenName + ":" + std::to_string(_type); 36 | } 37 | -------------------------------------------------------------------------------- /antlr/runtime/support/Arrays.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "Exceptions.h" 8 | 9 | #include "support/Arrays.h" 10 | 11 | using namespace antlrcpp; 12 | 13 | std::string Arrays::listToString(const std::vector &list, const std::string &separator) 14 | { 15 | std::stringstream ss; 16 | bool firstEntry = true; 17 | 18 | ss << '['; 19 | for (const auto &entry : list) { 20 | ss << entry; 21 | if (firstEntry) { 22 | ss << separator; 23 | firstEntry = false; 24 | } 25 | } 26 | 27 | ss << ']'; 28 | return ss.str(); 29 | } 30 | 31 | template <> 32 | std::string Arrays::toString(const std::vector &source) { 33 | std::string result = "["; 34 | bool firstEntry = true; 35 | for (auto *value : source) { 36 | result += value->toStringTree(); 37 | if (firstEntry) { 38 | result += ", "; 39 | firstEntry = false; 40 | } 41 | } 42 | return result + "]"; 43 | } 44 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ErrorNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ErrorNode.h" 9 | #include "tree/TerminalNodeImpl.h" 10 | #include "misc/Interval.h" 11 | 12 | #include "support/Any.h" 13 | 14 | namespace antlr4 { 15 | namespace tree { 16 | 17 | /// 18 | /// Represents a token that was consumed during resynchronization 19 | /// rather than during a valid match operation. For example, 20 | /// we will create this kind of a node during single token insertion 21 | /// and deletion as well as during "consume until error recovery set" 22 | /// upon no viable alternative exceptions. 23 | /// 24 | class ANTLR4CPP_PUBLIC ErrorNodeImpl : public virtual TerminalNodeImpl, public virtual ErrorNode { 25 | public: 26 | ErrorNodeImpl(Token *token); 27 | ~ErrorNodeImpl() override; 28 | 29 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /antlr/grammar/.antlr/crule.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | PLUS=2 3 | MINUS=3 4 | DIV=4 5 | MUL=5 6 | MOD=6 7 | DOT=7 8 | SEMICOLON=8 9 | LR_BRACE=9 10 | RR_BRACE=10 11 | LR_BRACKET=11 12 | RR_BRACKET=12 13 | LS_BRACKET=13 14 | RS_BRACKET=14 15 | RULE=15 16 | IF=16 17 | IN=17 18 | THEN=18 19 | AND=19 20 | OR=20 21 | TRUE=21 22 | FALSE=22 23 | NIL_LITERAL=23 24 | NEGATION=24 25 | SALIENCE=25 26 | EQUALS=26 27 | ASSIGN=27 28 | PLUS_ASIGN=28 29 | MINUS_ASIGN=29 30 | DIV_ASIGN=30 31 | MUL_ASIGN=31 32 | MOD_ASIGN=32 33 | GT=33 34 | LT=34 35 | GTE=35 36 | LTE=36 37 | NOTEQUALS=37 38 | BITAND=38 39 | BITOR=39 40 | SIMPLENAME=40 41 | DQUOTA_STRING=41 42 | SQUOTA_STRING=42 43 | DECIMAL_FLOAT_LIT=43 44 | DECIMAL_EXPONENT=44 45 | HEX_FLOAT_LIT=45 46 | HEX_EXPONENT=46 47 | DEC_LIT=47 48 | HEX_LIT=48 49 | OCT_LIT=49 50 | SPACE=50 51 | COMMENT=51 52 | LINE_COMMENT=52 53 | ','=1 54 | '+'=2 55 | '-'=3 56 | '/'=4 57 | '*'=5 58 | '%'=6 59 | '.'=7 60 | ';'=8 61 | '{'=9 62 | '}'=10 63 | '('=11 64 | ')'=12 65 | '['=13 66 | ']'=14 67 | '&&'=19 68 | '||'=20 69 | '!'=24 70 | '=='=26 71 | '='=27 72 | '+='=28 73 | '-='=29 74 | '/='=30 75 | '*='=31 76 | '%='=32 77 | '>'=33 78 | '<'=34 79 | '>='=35 80 | '<='=36 81 | '!='=37 82 | '&'=38 83 | '|'=39 84 | -------------------------------------------------------------------------------- /antlr/grammar/generated/crule.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | PLUS=2 3 | MINUS=3 4 | DIV=4 5 | MUL=5 6 | MOD=6 7 | DOT=7 8 | SEMICOLON=8 9 | LR_BRACE=9 10 | RR_BRACE=10 11 | LR_BRACKET=11 12 | RR_BRACKET=12 13 | LS_BRACKET=13 14 | RS_BRACKET=14 15 | RULE=15 16 | IF=16 17 | IN=17 18 | THEN=18 19 | AND=19 20 | OR=20 21 | TRUE=21 22 | FALSE=22 23 | NIL_LITERAL=23 24 | NEGATION=24 25 | SALIENCE=25 26 | EQUALS=26 27 | ASSIGN=27 28 | PLUS_ASIGN=28 29 | MINUS_ASIGN=29 30 | DIV_ASIGN=30 31 | MUL_ASIGN=31 32 | MOD_ASIGN=32 33 | GT=33 34 | LT=34 35 | GTE=35 36 | LTE=36 37 | NOTEQUALS=37 38 | BITAND=38 39 | BITOR=39 40 | SIMPLENAME=40 41 | DQUOTA_STRING=41 42 | SQUOTA_STRING=42 43 | DECIMAL_FLOAT_LIT=43 44 | DECIMAL_EXPONENT=44 45 | HEX_FLOAT_LIT=45 46 | HEX_EXPONENT=46 47 | DEC_LIT=47 48 | HEX_LIT=48 49 | OCT_LIT=49 50 | SPACE=50 51 | COMMENT=51 52 | LINE_COMMENT=52 53 | ','=1 54 | '+'=2 55 | '-'=3 56 | '/'=4 57 | '*'=5 58 | '%'=6 59 | '.'=7 60 | ';'=8 61 | '{'=9 62 | '}'=10 63 | '('=11 64 | ')'=12 65 | '['=13 66 | ']'=14 67 | '&&'=19 68 | '||'=20 69 | '!'=24 70 | '=='=26 71 | '='=27 72 | '+='=28 73 | '-='=29 74 | '/='=30 75 | '*='=31 76 | '%='=32 77 | '>'=33 78 | '<'=34 79 | '>='=35 80 | '<='=36 81 | '!='=37 82 | '&'=38 83 | '|'=39 84 | -------------------------------------------------------------------------------- /antlr/grammar/.antlr/cruleLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | PLUS=2 3 | MINUS=3 4 | DIV=4 5 | MUL=5 6 | MOD=6 7 | DOT=7 8 | SEMICOLON=8 9 | LR_BRACE=9 10 | RR_BRACE=10 11 | LR_BRACKET=11 12 | RR_BRACKET=12 13 | LS_BRACKET=13 14 | RS_BRACKET=14 15 | RULE=15 16 | IF=16 17 | IN=17 18 | THEN=18 19 | AND=19 20 | OR=20 21 | TRUE=21 22 | FALSE=22 23 | NIL_LITERAL=23 24 | NEGATION=24 25 | SALIENCE=25 26 | EQUALS=26 27 | ASSIGN=27 28 | PLUS_ASIGN=28 29 | MINUS_ASIGN=29 30 | DIV_ASIGN=30 31 | MUL_ASIGN=31 32 | MOD_ASIGN=32 33 | GT=33 34 | LT=34 35 | GTE=35 36 | LTE=36 37 | NOTEQUALS=37 38 | BITAND=38 39 | BITOR=39 40 | SIMPLENAME=40 41 | DQUOTA_STRING=41 42 | SQUOTA_STRING=42 43 | DECIMAL_FLOAT_LIT=43 44 | DECIMAL_EXPONENT=44 45 | HEX_FLOAT_LIT=45 46 | HEX_EXPONENT=46 47 | DEC_LIT=47 48 | HEX_LIT=48 49 | OCT_LIT=49 50 | SPACE=50 51 | COMMENT=51 52 | LINE_COMMENT=52 53 | ','=1 54 | '+'=2 55 | '-'=3 56 | '/'=4 57 | '*'=5 58 | '%'=6 59 | '.'=7 60 | ';'=8 61 | '{'=9 62 | '}'=10 63 | '('=11 64 | ')'=12 65 | '['=13 66 | ']'=14 67 | '&&'=19 68 | '||'=20 69 | '!'=24 70 | '=='=26 71 | '='=27 72 | '+='=28 73 | '-='=29 74 | '/='=30 75 | '*='=31 76 | '%='=32 77 | '>'=33 78 | '<'=34 79 | '>='=35 80 | '<='=36 81 | '!='=37 82 | '&'=38 83 | '|'=39 84 | -------------------------------------------------------------------------------- /antlr/grammar/generated/cruleLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | PLUS=2 3 | MINUS=3 4 | DIV=4 5 | MUL=5 6 | MOD=6 7 | DOT=7 8 | SEMICOLON=8 9 | LR_BRACE=9 10 | RR_BRACE=10 11 | LR_BRACKET=11 12 | RR_BRACKET=12 13 | LS_BRACKET=13 14 | RS_BRACKET=14 15 | RULE=15 16 | IF=16 17 | IN=17 18 | THEN=18 19 | AND=19 20 | OR=20 21 | TRUE=21 22 | FALSE=22 23 | NIL_LITERAL=23 24 | NEGATION=24 25 | SALIENCE=25 26 | EQUALS=26 27 | ASSIGN=27 28 | PLUS_ASIGN=28 29 | MINUS_ASIGN=29 30 | DIV_ASIGN=30 31 | MUL_ASIGN=31 32 | MOD_ASIGN=32 33 | GT=33 34 | LT=34 35 | GTE=35 36 | LTE=36 37 | NOTEQUALS=37 38 | BITAND=38 39 | BITOR=39 40 | SIMPLENAME=40 41 | DQUOTA_STRING=41 42 | SQUOTA_STRING=42 43 | DECIMAL_FLOAT_LIT=43 44 | DECIMAL_EXPONENT=44 45 | HEX_FLOAT_LIT=45 46 | HEX_EXPONENT=46 47 | DEC_LIT=47 48 | HEX_LIT=48 49 | OCT_LIT=49 50 | SPACE=50 51 | COMMENT=51 52 | LINE_COMMENT=52 53 | ','=1 54 | '+'=2 55 | '-'=3 56 | '/'=4 57 | '*'=5 58 | '%'=6 59 | '.'=7 60 | ';'=8 61 | '{'=9 62 | '}'=10 63 | '('=11 64 | ')'=12 65 | '['=13 66 | ']'=14 67 | '&&'=19 68 | '||'=20 69 | '!'=24 70 | '=='=26 71 | '='=27 72 | '+='=28 73 | '-='=29 74 | '/='=30 75 | '*='=31 76 | '%='=32 77 | '>'=33 78 | '<'=34 79 | '>='=35 80 | '<='=36 81 | '!='=37 82 | '&'=38 83 | '|'=39 84 | -------------------------------------------------------------------------------- /antlr/runtime/atn/EpsilonTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EpsilonTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EpsilonTransition::EpsilonTransition(ATNState *target) : EpsilonTransition(target, INVALID_INDEX) { 11 | } 12 | 13 | EpsilonTransition::EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn) 14 | : Transition(target), _outermostPrecedenceReturn(outermostPrecedenceReturn) { 15 | } 16 | 17 | size_t EpsilonTransition::outermostPrecedenceReturn() { 18 | return _outermostPrecedenceReturn; 19 | } 20 | 21 | Transition::SerializationType EpsilonTransition::getSerializationType() const { 22 | return EPSILON; 23 | } 24 | 25 | bool EpsilonTransition::isEpsilon() const { 26 | return true; 27 | } 28 | 29 | bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 30 | return false; 31 | } 32 | 33 | std::string EpsilonTransition::toString() const { 34 | return "EPSILON " + Transition::toString() + " {}"; 35 | } 36 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathTokenElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | #include "support/CPPUtils.h" 9 | #include "Token.h" 10 | 11 | #include "XPathTokenElement.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | using namespace antlr4::tree::xpath; 16 | 17 | XPathTokenElement::XPathTokenElement(const std::string &tokenName, size_t tokenType) : XPathElement(tokenName) { 18 | _tokenType = tokenType; 19 | } 20 | 21 | std::vector XPathTokenElement::evaluate(ParseTree *t) { 22 | // return all children of t that match nodeName 23 | std::vector nodes; 24 | for (auto *c : t->children) { 25 | if (antlrcpp::is(c)) { 26 | TerminalNode *tnode = dynamic_cast(c); 27 | if ((tnode->getSymbol()->getType() == _tokenType && !_invert) || (tnode->getSymbol()->getType() != _tokenType && _invert)) { 28 | nodes.push_back(tnode); 29 | } 30 | } 31 | } 32 | return nodes; 33 | } 34 | -------------------------------------------------------------------------------- /antlr/runtime/ConsoleErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC ConsoleErrorListener : public BaseErrorListener { 13 | public: 14 | /** 15 | * Provides a default instance of {@link ConsoleErrorListener}. 16 | */ 17 | static ConsoleErrorListener INSTANCE; 18 | 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

23 | * This implementation prints messages to {@link System#err} containing the 24 | * values of {@code line}, {@code charPositionInLine}, and {@code msg} using 25 | * the following format.

26 | * 27 | *
28 |      * line line:charPositionInLine msg
29 |      * 
30 | */ 31 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 32 | const std::string &msg, std::exception_ptr e) override; 33 | }; 34 | 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | class ParseTree; 13 | 14 | namespace xpath { 15 | 16 | class ANTLR4CPP_PUBLIC XPathElement { 17 | public: 18 | /// Construct element like {@code /ID} or {@code ID} or {@code /*} etc... 19 | /// op is null if just node 20 | XPathElement(const std::string &nodeName); 21 | XPathElement(XPathElement const&) = default; 22 | virtual ~XPathElement(); 23 | 24 | XPathElement& operator=(XPathElement const&) = default; 25 | 26 | /// Given tree rooted at {@code t} return all nodes matched by this path 27 | /// element. 28 | virtual std::vector evaluate(ParseTree *t); 29 | virtual std::string toString() const; 30 | 31 | void setInvert(bool value); 32 | 33 | protected: 34 | std::string _nodeName; 35 | bool _invert = false; 36 | }; 37 | 38 | } // namespace xpath 39 | } // namespace tree 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /antlr/runtime/FailedPredicateException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A semantic predicate failed during validation. Validation of predicates 13 | /// occurs when normally parsing the alternative just like matching a token. 14 | /// Disambiguating predicate evaluation occurs when we test a predicate during 15 | /// prediction. 16 | class ANTLR4CPP_PUBLIC FailedPredicateException : public RecognitionException { 17 | public: 18 | FailedPredicateException(Parser *recognizer); 19 | FailedPredicateException(Parser *recognizer, const std::string &predicate); 20 | FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message); 21 | 22 | virtual size_t getRuleIndex(); 23 | virtual size_t getPredIndex(); 24 | virtual std::string getPredicate(); 25 | 26 | private: 27 | size_t _ruleIndex; 28 | size_t _predicateIndex; 29 | std::string _predicate; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr/runtime/atn/Transition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "support/Arrays.h" 8 | 9 | #include "atn/Transition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | using namespace antlrcpp; 15 | 16 | const std::vector Transition::serializationNames = { 17 | "INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION", "SET", "NOT_SET", "WILDCARD", "PRECEDENCE" 18 | }; 19 | 20 | Transition::Transition(ATNState *target) { 21 | if (target == nullptr) { 22 | throw NullPointerException("target cannot be null."); 23 | } 24 | 25 | this->target = target; 26 | } 27 | 28 | Transition::~Transition() { 29 | } 30 | 31 | bool Transition::isEpsilon() const { 32 | return false; 33 | } 34 | 35 | misc::IntervalSet Transition::label() const { 36 | return misc::IntervalSet::EMPTY_SET; 37 | } 38 | 39 | std::string Transition::toString() const { 40 | std::stringstream ss; 41 | ss << "(Transition " << std::hex << this << ", target: " << std::hex << target << ')'; 42 | 43 | return ss.str(); 44 | } 45 | -------------------------------------------------------------------------------- /antlr/runtime/BaseErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BaseErrorListener.h" 7 | #include "RecognitionException.h" 8 | 9 | using namespace antlr4; 10 | 11 | void BaseErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, size_t /*line*/, 12 | size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | 15 | void BaseErrorListener::reportAmbiguity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 16 | size_t /*stopIndex*/, bool /*exact*/, const antlrcpp::BitSet &/*ambigAlts*/, atn::ATNConfigSet * /*configs*/) { 17 | } 18 | 19 | void BaseErrorListener::reportAttemptingFullContext(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 20 | size_t /*stopIndex*/, const antlrcpp::BitSet &/*conflictingAlts*/, atn::ATNConfigSet * /*configs*/) { 21 | } 22 | 23 | void BaseErrorListener::reportContextSensitivity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 24 | size_t /*stopIndex*/, size_t /*prediction*/, atn::ATNConfigSet * /*configs*/) { 25 | } 26 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PrecedencePredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PrecedencePredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, int precedence) 11 | : AbstractPredicateTransition(target), precedence(precedence) { 12 | } 13 | 14 | Transition::SerializationType PrecedencePredicateTransition::getSerializationType() const { 15 | return PRECEDENCE; 16 | } 17 | 18 | bool PrecedencePredicateTransition::isEpsilon() const { 19 | return true; 20 | } 21 | 22 | bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 23 | return false; 24 | } 25 | 26 | Ref PrecedencePredicateTransition::getPredicate() const { 27 | return std::make_shared(precedence); 28 | } 29 | 30 | std::string PrecedencePredicateTransition::toString() const { 31 | return "PRECEDENCE " + Transition::toString() + " { precedence: " + std::to_string(precedence) + " }"; 32 | } 33 | -------------------------------------------------------------------------------- /log/logger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_LOG_ 2 | #define _RULE_ENGINE_LOG_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | namespace rule_engine { 10 | 11 | void info(const std::string& s) { 12 | std::cout << s << std::endl; 13 | } 14 | 15 | void warn(const std::string& s) { 16 | 17 | } 18 | 19 | void error(const std::string& s) { 20 | std::cout << s << std::endl; 21 | } 22 | 23 | void semantic_error(const std::string& s) { 24 | std::cout << s << std::endl; 25 | } 26 | 27 | void syntax_error(const std::string& s) { 28 | std::cout << s << std::endl; 29 | } 30 | 31 | void runtime_error(const std::string& s) { 32 | std::cout << s << std::endl; 33 | } 34 | 35 | template 36 | void assert_type_semantic(std::shared_ptr ptr, const std::string& s) { 37 | if(dynamic_cast(ptr.get()) == nullptr) { 38 | error(s); 39 | } 40 | } 41 | 42 | template 43 | void assert_type(std::shared_ptr ptr, const std::string& s) { 44 | if(dynamic_cast(ptr.get()) == nullptr) { 45 | error(s); 46 | } 47 | } 48 | 49 | template 50 | void assert_type(std::unique_ptr& ptr, const std::string& s) { 51 | if(dynamic_cast(ptr.get()) == nullptr) { 52 | error(s); 53 | } 54 | } 55 | 56 | } 57 | #endif -------------------------------------------------------------------------------- /antlr/runtime/TokenFactory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// The default mechanism for creating tokens. It's used by default in Lexer and 13 | /// the error handling strategy (to create missing tokens). Notifying the parser 14 | /// of a new factory means that it notifies it's token source and error strategy. 15 | template 16 | class ANTLR4CPP_PUBLIC TokenFactory { 17 | public: 18 | virtual ~TokenFactory() {} 19 | 20 | /// This is the method used to create tokens in the lexer and in the 21 | /// error handling strategy. If text!=null, than the start and stop positions 22 | /// are wiped to -1 in the text override is set in the CommonToken. 23 | virtual std::unique_ptr create(std::pair source, size_t type, const std::string &text, 24 | size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) = 0; 25 | 26 | /// Generically useful 27 | virtual std::unique_ptr create(size_t type, const std::string &text) = 0; 28 | }; 29 | 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerMoreAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerMoreAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerMoreAction::getInstance() { 16 | static Ref instance(new LexerMoreAction()); 17 | return instance; 18 | } 19 | 20 | LexerMoreAction::LexerMoreAction() { 21 | } 22 | 23 | LexerActionType LexerMoreAction::getActionType() const { 24 | return LexerActionType::MORE; 25 | } 26 | 27 | bool LexerMoreAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerMoreAction::execute(Lexer *lexer) { 32 | lexer->more(); 33 | } 34 | 35 | size_t LexerMoreAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerMoreAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerMoreAction::toString() const { 46 | return "more"; 47 | } 48 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerSkipAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerSkipAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerSkipAction::getInstance() { 16 | static Ref instance(new LexerSkipAction()); 17 | return instance; 18 | } 19 | 20 | LexerSkipAction::LexerSkipAction() { 21 | } 22 | 23 | LexerActionType LexerSkipAction::getActionType() const { 24 | return LexerActionType::SKIP; 25 | } 26 | 27 | bool LexerSkipAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerSkipAction::execute(Lexer *lexer) { 32 | lexer->skip(); 33 | } 34 | 35 | size_t LexerSkipAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerSkipAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerSkipAction::toString() const { 46 | return "skip"; 47 | } 48 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RuleTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | #include "atn/RuleTransition.h" 8 | 9 | using namespace antlr4::atn; 10 | 11 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState) 12 | : RuleTransition(ruleStart, ruleIndex, 0, followState) { 13 | } 14 | 15 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState) 16 | : Transition(ruleStart), ruleIndex(ruleIndex), precedence(precedence) { 17 | this->followState = followState; 18 | } 19 | 20 | Transition::SerializationType RuleTransition::getSerializationType() const { 21 | return RULE; 22 | } 23 | 24 | bool RuleTransition::isEpsilon() const { 25 | return true; 26 | } 27 | 28 | bool RuleTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 29 | return false; 30 | } 31 | 32 | std::string RuleTransition::toString() const { 33 | std::stringstream ss; 34 | ss << "RULE " << Transition::toString() << " { ruleIndex: " << ruleIndex << ", precedence: " << precedence << 35 | ", followState: " << std::hex << followState << " }"; 36 | return ss.str(); 37 | } 38 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ParseTreeListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /** This interface describes the minimal core of methods triggered 14 | * by {@link ParseTreeWalker}. E.g., 15 | * 16 | * ParseTreeWalker walker = new ParseTreeWalker(); 17 | * walker.walk(myParseTreeListener, myParseTree); <-- triggers events in your listener 18 | * 19 | * If you want to trigger events in multiple listeners during a single 20 | * tree walk, you can use the ParseTreeDispatcher object available at 21 | * 22 | * https://github.com/antlr/antlr4/issues/841 23 | */ 24 | class ANTLR4CPP_PUBLIC ParseTreeListener { 25 | public: 26 | virtual ~ParseTreeListener(); 27 | 28 | virtual void visitTerminal(TerminalNode *node) = 0; 29 | virtual void visitErrorNode(ErrorNode *node) = 0; 30 | virtual void enterEveryRule(ParserRuleContext *ctx) = 0; 31 | virtual void exitEveryRule(ParserRuleContext *ctx) = 0; 32 | 33 | bool operator == (const ParseTreeListener &other) { 34 | return this == &other; 35 | } 36 | }; 37 | 38 | } // namespace tree 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /antlr/runtime/LexerNoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "support/CPPUtils.h" 8 | #include "CharStream.h" 9 | #include "Lexer.h" 10 | 11 | #include "LexerNoViableAltException.h" 12 | 13 | using namespace antlr4; 14 | 15 | LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs) 17 | : RecognitionException(lexer, input, nullptr, nullptr), _startIndex(startIndex), _deadEndConfigs(deadEndConfigs) { 18 | } 19 | 20 | size_t LexerNoViableAltException::getStartIndex() { 21 | return _startIndex; 22 | } 23 | 24 | atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() { 25 | return _deadEndConfigs; 26 | } 27 | 28 | std::string LexerNoViableAltException::toString() { 29 | std::string symbol; 30 | if (_startIndex < getInputStream()->size()) { 31 | symbol = static_cast(getInputStream())->getText(misc::Interval(_startIndex, _startIndex)); 32 | symbol = antlrcpp::escapeWhitespace(symbol, false); 33 | } 34 | std::string format = "LexerNoViableAltException('" + symbol + "')"; 35 | return format; 36 | } 37 | -------------------------------------------------------------------------------- /examples/map_vector.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "rule_engine.hpp" 5 | 6 | struct Family { 7 | std::map members; 8 | std::unordered_map ages; 9 | }; 10 | 11 | 12 | RTTR_REGISTRATION { 13 | rttr::registration::class_("Family") 14 | .property("members", &Family::members) 15 | .property("ages", &Family::ages) 16 | ; 17 | } 18 | 19 | 20 | int main() { 21 | const char* rule = R"( 22 | rule family "this is a description" { 23 | if 24 | Family.members["mother"] == "judith harper" 25 | then 26 | Family.members["step mother"] = "candy"; 27 | Family.members["mother"] = "judith melnick"; 28 | } 29 | )"; 30 | 31 | Family family; 32 | family.members["uncle"] = "charlie harper"; 33 | family.members["dad"] = "alan harper"; 34 | family.members["grandma"] = "evalyn harper"; 35 | family.members["mother"] = "judith harper"; 36 | 37 | family.ages["jake"] = 13; 38 | 39 | rule_engine::Engine e; 40 | e.load_rules(rule); 41 | rule_engine::DataContext dctx; 42 | dctx.add("Family", family); 43 | e.execute(&dctx); 44 | 45 | assert(family.members["mother"] == "judith melnick"); 46 | assert(family.members["step mother"] == "candy"); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /antlr/runtime/atn/EpsilonTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EpsilonTransition final : public Transition { 14 | public: 15 | EpsilonTransition(ATNState *target); 16 | EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn); 17 | 18 | /** 19 | * @return the rule index of a precedence rule for which this transition is 20 | * returning from, where the precedence value is 0; otherwise, INVALID_INDEX. 21 | * 22 | * @see ATNConfig#isPrecedenceFilterSuppressed() 23 | * @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet) 24 | * @since 4.4.1 25 | */ 26 | size_t outermostPrecedenceReturn(); 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | virtual std::string toString() const override; 33 | 34 | private: 35 | const size_t _outermostPrecedenceReturn; // A rule index. 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerPopModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPopModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerPopModeAction::getInstance() { 16 | static Ref instance(new LexerPopModeAction()); 17 | return instance; 18 | } 19 | 20 | LexerPopModeAction::LexerPopModeAction() { 21 | } 22 | 23 | LexerActionType LexerPopModeAction::getActionType() const { 24 | return LexerActionType::POP_MODE; 25 | } 26 | 27 | bool LexerPopModeAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerPopModeAction::execute(Lexer *lexer) { 32 | lexer->popMode(); 33 | } 34 | 35 | size_t LexerPopModeAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerPopModeAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerPopModeAction::toString() const { 46 | return "popMode"; 47 | } 48 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ActionTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ActionTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex) 11 | : Transition(target), ruleIndex(ruleIndex), actionIndex(INVALID_INDEX), isCtxDependent(false) { 12 | } 13 | 14 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent) 15 | : Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) { 16 | } 17 | 18 | Transition::SerializationType ActionTransition::getSerializationType() const { 19 | return ACTION; 20 | } 21 | 22 | bool ActionTransition::isEpsilon() const { 23 | return true; // we are to be ignored by analysis 'cept for predicates 24 | } 25 | 26 | bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return false; 28 | } 29 | 30 | std::string ActionTransition::toString() const { 31 | return " ACTION " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + ", actionIndex: " + 32 | std::to_string(actionIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 33 | } 34 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PredicateTransition::PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent) : AbstractPredicateTransition(target), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) { 11 | } 12 | 13 | Transition::SerializationType PredicateTransition::getSerializationType() const { 14 | return PREDICATE; 15 | } 16 | 17 | bool PredicateTransition::isEpsilon() const { 18 | return true; 19 | } 20 | 21 | bool PredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 22 | return false; 23 | } 24 | 25 | Ref PredicateTransition::getPredicate() const { 26 | return std::make_shared(ruleIndex, predIndex, isCtxDependent); 27 | } 28 | 29 | std::string PredicateTransition::toString() const { 30 | return "PREDICATE " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + 31 | ", predIndex: " + std::to_string(predIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 32 | 33 | // Generate and add a predicate context here? 34 | } 35 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ATNDeserializationOptions.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ATNDeserializationOptions { 14 | private: 15 | static ATNDeserializationOptions defaultOptions; 16 | 17 | bool readOnly; 18 | bool verifyATN; 19 | bool generateRuleBypassTransitions; 20 | 21 | public: 22 | ATNDeserializationOptions(); 23 | ATNDeserializationOptions(ATNDeserializationOptions *options); 24 | ATNDeserializationOptions(ATNDeserializationOptions const&) = default; 25 | virtual ~ATNDeserializationOptions(); 26 | ATNDeserializationOptions& operator=(ATNDeserializationOptions const&) = default; 27 | 28 | static const ATNDeserializationOptions& getDefaultOptions(); 29 | 30 | bool isReadOnly(); 31 | 32 | void makeReadOnly(); 33 | 34 | bool isVerifyATN(); 35 | 36 | void setVerifyATN(bool verify); 37 | 38 | bool isGenerateRuleBypassTransitions(); 39 | 40 | void setGenerateRuleBypassTransitions(bool generate); 41 | 42 | protected: 43 | virtual void throwIfReadOnly(); 44 | 45 | private: 46 | void InitializeInstanceFields(); 47 | }; 48 | 49 | } // namespace atn 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar XPathLexer; 2 | 3 | tokens { TOKEN_REF, RULE_REF } 4 | 5 | /* 6 | path : separator? word (separator word)* EOF ; 7 | 8 | separator 9 | : '/' '!' 10 | | '//' '!' 11 | | '/' 12 | | '//' 13 | ; 14 | 15 | word: TOKEN_REF 16 | | RULE_REF 17 | | STRING 18 | | '*' 19 | ; 20 | */ 21 | 22 | ANYWHERE : '//' ; 23 | ROOT : '/' ; 24 | WILDCARD : '*' ; 25 | BANG : '!' ; 26 | 27 | ID : NameStartChar NameChar* 28 | { 29 | if (isupper(getText()[0])) 30 | setType(TOKEN_REF); 31 | else 32 | setType(RULE_REF); 33 | } 34 | ; 35 | 36 | fragment 37 | NameChar : NameStartChar 38 | | '0'..'9' 39 | | '_' 40 | | '\u00B7' 41 | | '\u0300'..'\u036F' 42 | | '\u203F'..'\u2040' 43 | ; 44 | 45 | fragment 46 | NameStartChar 47 | : 'A'..'Z' | 'a'..'z' 48 | | '\u00C0'..'\u00D6' 49 | | '\u00D8'..'\u00F6' 50 | | '\u00F8'..'\u02FF' 51 | | '\u0370'..'\u037D' 52 | | '\u037F'..'\u1FFF' 53 | | '\u200C'..'\u200D' 54 | | '\u2070'..'\u218F' 55 | | '\u2C00'..'\u2FEF' 56 | | '\u3001'..'\uD7FF' 57 | | '\uF900'..'\uFDCF' 58 | | '\uFDF0'..'\uFFFF' // implicitly includes ['\u10000-'\uEFFFF] 59 | ; 60 | 61 | STRING : '\'' .*? '\''; 62 | 63 | //WS : [ \t\r\n]+ -> skip ; 64 | 65 | -------------------------------------------------------------------------------- /antlr/runtime/support/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | namespace antlrcpp { 9 | 10 | void replaceAll(std::string& str, std::string const& from, std::string const& to) 11 | { 12 | if (from.empty()) 13 | return; 14 | 15 | size_t start_pos = 0; 16 | while ((start_pos = str.find(from, start_pos)) != std::string::npos) { 17 | str.replace(start_pos, from.length(), to); 18 | start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'. 19 | } 20 | } 21 | 22 | std::string ws2s(std::wstring const& wstr) { 23 | #ifndef USE_UTF8_INSTEAD_OF_CODECVT 24 | std::wstring_convert> converter; 25 | std::string narrow = converter.to_bytes(wstr); 26 | #else 27 | std::string narrow; 28 | utf8::utf32to8(wstr.begin(), wstr.end(), std::back_inserter(narrow)); 29 | #endif 30 | 31 | return narrow; 32 | } 33 | 34 | std::wstring s2ws(const std::string &str) { 35 | #ifndef USE_UTF8_INSTEAD_OF_CODECVT 36 | std::wstring_convert> converter; 37 | std::wstring wide = converter.from_bytes(str); 38 | #else 39 | std::wstring wide; 40 | utf8::utf8to32(str.begin(), str.end(), std::back_inserter(wide)); 41 | #endif 42 | 43 | return wide; 44 | } 45 | 46 | } // namespace antrlcpp 47 | -------------------------------------------------------------------------------- /antlr/runtime/CommonTokenFactory.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "CommonToken.h" 8 | #include "CharStream.h" 9 | 10 | #include "CommonTokenFactory.h" 11 | 12 | using namespace antlr4; 13 | 14 | const std::unique_ptr> CommonTokenFactory::DEFAULT(new CommonTokenFactory); 15 | 16 | CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) { 17 | } 18 | 19 | CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) { 20 | } 21 | 22 | std::unique_ptr CommonTokenFactory::create(std::pair source, size_t type, 23 | const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) { 24 | 25 | std::unique_ptr t(new CommonToken(source, type, channel, start, stop)); 26 | t->setLine(line); 27 | t->setCharPositionInLine(charPositionInLine); 28 | if (text != "") { 29 | t->setText(text); 30 | } else if (copyText && source.second != nullptr) { 31 | t->setText(source.second->getText(misc::Interval(start, stop))); 32 | } 33 | 34 | return t; 35 | } 36 | 37 | std::unique_ptr CommonTokenFactory::create(size_t type, const std::string &text) { 38 | return std::unique_ptr(new CommonToken(type, text)); 39 | } 40 | -------------------------------------------------------------------------------- /antlr/runtime/atn/RuleTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleTransition : public Transition { 14 | public: 15 | /// Ptr to the rule definition object for this rule ref. 16 | const size_t ruleIndex; // no Rule object at runtime 17 | 18 | const int precedence; 19 | 20 | /// What node to begin computations following ref to rule. 21 | ATNState *followState; 22 | 23 | /// @deprecated Use 24 | /// instead. 25 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState); 26 | 27 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState); 28 | RuleTransition(RuleTransition const&) = delete; 29 | RuleTransition& operator=(RuleTransition const&) = delete; 30 | 31 | virtual SerializationType getSerializationType() const override; 32 | 33 | virtual bool isEpsilon() const override; 34 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 35 | 36 | virtual std::string toString() const override; 37 | }; 38 | 39 | } // namespace atn 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /antlr/runtime/atn/PredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// TODO: this is old comment: 15 | /// A tree of semantic predicates from the grammar AST if label==SEMPRED. 16 | /// In the ATN, labels will always be exactly one predicate, but the DFA 17 | /// may have to combine a bunch of them as it collects predicates from 18 | /// multiple ATN configurations into a single DFA state. 19 | class ANTLR4CPP_PUBLIC PredicateTransition final : public AbstractPredicateTransition { 20 | public: 21 | const size_t ruleIndex; 22 | const size_t predIndex; 23 | const bool isCtxDependent; // e.g., $i ref in pred 24 | 25 | PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent); 26 | 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | Ref getPredicate() const; 33 | 34 | virtual std::string toString() const override; 35 | 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /antlr/runtime/BaseErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | 10 | namespace antlrcpp { 11 | class BitSet; 12 | } 13 | 14 | namespace antlr4 { 15 | 16 | /** 17 | * Provides an empty default implementation of {@link ANTLRErrorListener}. The 18 | * default implementation of each method does nothing, but can be overridden as 19 | * necessary. 20 | */ 21 | class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener { 22 | 23 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 24 | const std::string &msg, std::exception_ptr e) override; 25 | 26 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 27 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 28 | 29 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 30 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 31 | 32 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 33 | size_t prediction, atn::ATNConfigSet *configs) override; 34 | }; 35 | 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerModeAction::LexerModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerModeAction::getMode() { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerModeAction::getActionType() const { 23 | return LexerActionType::MODE; 24 | } 25 | 26 | bool LexerModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerModeAction::execute(Lexer *lexer) { 31 | lexer->setMode(_mode); 32 | } 33 | 34 | size_t LexerModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerModeAction::toString() const { 55 | return "mode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerTypeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerTypeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerTypeAction::LexerTypeAction(int type) : _type(type) { 16 | } 17 | 18 | int LexerTypeAction::getType() const { 19 | return _type; 20 | } 21 | 22 | LexerActionType LexerTypeAction::getActionType() const { 23 | return LexerActionType::TYPE; 24 | } 25 | 26 | bool LexerTypeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerTypeAction::execute(Lexer *lexer) { 31 | lexer->setType(_type); 32 | } 33 | 34 | size_t LexerTypeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _type); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerTypeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerTypeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _type == action->_type; 52 | } 53 | 54 | std::string LexerTypeAction::toString() const { 55 | return "type(" + std::to_string(_type) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /antlr/runtime/tree/TerminalNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "Token.h" 8 | #include "RuleContext.h" 9 | #include "tree/ParseTreeVisitor.h" 10 | 11 | #include "tree/TerminalNodeImpl.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | 16 | TerminalNodeImpl::TerminalNodeImpl(Token *symbol_) : symbol(symbol_) { 17 | } 18 | 19 | Token* TerminalNodeImpl::getSymbol() { 20 | return symbol; 21 | } 22 | 23 | void TerminalNodeImpl::setParent(RuleContext *parent_) { 24 | this->parent = parent_; 25 | } 26 | 27 | misc::Interval TerminalNodeImpl::getSourceInterval() { 28 | if (symbol == nullptr) { 29 | return misc::Interval::INVALID; 30 | } 31 | 32 | size_t tokenIndex = symbol->getTokenIndex(); 33 | return misc::Interval(tokenIndex, tokenIndex); 34 | } 35 | 36 | antlrcpp::Any TerminalNodeImpl::accept(ParseTreeVisitor *visitor) { 37 | return visitor->visitTerminal(this); 38 | } 39 | 40 | std::string TerminalNodeImpl::getText() { 41 | return symbol->getText(); 42 | } 43 | 44 | std::string TerminalNodeImpl::toStringTree(Parser * /*parser*/, bool /*pretty*/) { 45 | return toString(); 46 | } 47 | 48 | std::string TerminalNodeImpl::toString() { 49 | if (symbol->getType() == Token::EOF) { 50 | return ""; 51 | } 52 | return symbol->getText(); 53 | } 54 | 55 | std::string TerminalNodeImpl::toStringTree(bool /*pretty*/) { 56 | return toString(); 57 | } 58 | -------------------------------------------------------------------------------- /antlr/runtime/CharStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "IntStream.h" 9 | #include "misc/Interval.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// A source of characters for an ANTLR lexer. 14 | class ANTLR4CPP_PUBLIC CharStream : public IntStream { 15 | public: 16 | virtual ~CharStream(); 17 | 18 | /// This method returns the text for a range of characters within this input 19 | /// stream. This method is guaranteed to not throw an exception if the 20 | /// specified interval lies entirely within a marked range. For more 21 | /// information about marked ranges, see IntStream::mark. 22 | /// 23 | /// an interval within the stream 24 | /// the text of the specified interval 25 | /// 26 | /// if {@code interval} is {@code null} 27 | /// if {@code interval.a < 0}, or if 28 | /// {@code interval.b < interval.a - 1}, or if {@code interval.b} lies at or 29 | /// past the end of the stream 30 | /// if the stream does not support 31 | /// getting the text of the specified interval 32 | virtual std::string getText(const misc::Interval &interval) = 0; 33 | 34 | virtual std::string toString() const = 0; 35 | }; 36 | 37 | } // namespace antlr4 38 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerChannelAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerChannelAction.h" 10 | 11 | using namespace antlr4::atn; 12 | using namespace antlr4::misc; 13 | 14 | LexerChannelAction::LexerChannelAction(int channel) : _channel(channel) { 15 | } 16 | 17 | int LexerChannelAction::getChannel() const { 18 | return _channel; 19 | } 20 | 21 | LexerActionType LexerChannelAction::getActionType() const { 22 | return LexerActionType::CHANNEL; 23 | } 24 | 25 | bool LexerChannelAction::isPositionDependent() const { 26 | return false; 27 | } 28 | 29 | void LexerChannelAction::execute(Lexer *lexer) { 30 | lexer->setChannel(_channel); 31 | } 32 | 33 | size_t LexerChannelAction::hashCode() const { 34 | size_t hash = MurmurHash::initialize(); 35 | hash = MurmurHash::update(hash, static_cast(getActionType())); 36 | hash = MurmurHash::update(hash, _channel); 37 | return MurmurHash::finish(hash, 2); 38 | } 39 | 40 | bool LexerChannelAction::operator == (const LexerAction &obj) const { 41 | if (&obj == this) { 42 | return true; 43 | } 44 | 45 | const LexerChannelAction *action = dynamic_cast(&obj); 46 | if (action == nullptr) { 47 | return false; 48 | } 49 | 50 | return _channel == action->_channel; 51 | } 52 | 53 | std::string LexerChannelAction::toString() const { 54 | return "channel(" + std::to_string(_channel) + ")"; 55 | } 56 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/Chunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// A chunk is either a token tag, a rule tag, or a span of literal text within a 16 | /// tree pattern. 17 | ///

18 | /// The method returns a list of 19 | /// chunks in preparation for creating a token stream by 20 | /// . From there, we get a parse 21 | /// tree from with . These 22 | /// chunks are converted to , , or the 23 | /// regular tokens of the text surrounding the tags. 24 | ///

25 | class ANTLR4CPP_PUBLIC Chunk { 26 | public: 27 | Chunk() = default; 28 | Chunk(Chunk const&) = default; 29 | virtual ~Chunk(); 30 | 31 | Chunk& operator=(Chunk const&) = default; 32 | 33 | /// This method returns a text representation of the tag chunk. Labeled tags 34 | /// are returned in the form {@code label:tag}, and unlabeled tags are 35 | /// returned as just the tag name. 36 | virtual std::string toString() { 37 | std::string str; 38 | return str; 39 | } 40 | }; 41 | 42 | } // namespace pattern 43 | } // namespace tree 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerPushModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPushModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerPushModeAction::LexerPushModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerPushModeAction::getMode() const { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerPushModeAction::getActionType() const { 23 | return LexerActionType::PUSH_MODE; 24 | } 25 | 26 | bool LexerPushModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerPushModeAction::execute(Lexer *lexer) { 31 | lexer->pushMode(_mode); 32 | } 33 | 34 | size_t LexerPushModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerPushModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerPushModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerPushModeAction::toString() const { 55 | return "pushMode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ParseTreeProperty.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /// 14 | /// Associate a property with a parse tree node. Useful with parse tree listeners 15 | /// that need to associate values with particular tree nodes, kind of like 16 | /// specifying a return value for the listener event method that visited a 17 | /// particular node. Example: 18 | /// 19 | ///
20 |   /// ParseTreeProperty<Integer> values = new ParseTreeProperty<Integer>();
21 |   /// values.put(tree, 36);
22 |   /// int x = values.get(tree);
23 |   /// values.removeFrom(tree);
24 |   /// 
25 | /// 26 | /// You would make one decl (values here) in the listener and use lots of times 27 | /// in your event methods. 28 | ///
29 | template 30 | class ANTLR4CPP_PUBLIC ParseTreeProperty { 31 | public: 32 | virtual ~ParseTreeProperty() {} 33 | virtual V get(ParseTree *node) { 34 | return _annotations[node]; 35 | } 36 | virtual void put(ParseTree *node, V value) { 37 | _annotations[node] = value; 38 | } 39 | virtual V removeFrom(ParseTree *node) { 40 | auto value = _annotations[node]; 41 | _annotations.erase(node); 42 | return value; 43 | } 44 | 45 | protected: 46 | std::map _annotations; 47 | }; 48 | 49 | } // namespace tree 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /antlr/runtime/tree/ParseTreeWalker.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | #include "ParserRuleContext.h" 8 | #include "tree/ParseTreeListener.h" 9 | #include "support/CPPUtils.h" 10 | 11 | #include "tree/IterativeParseTreeWalker.h" 12 | #include "tree/ParseTreeWalker.h" 13 | 14 | using namespace antlr4::tree; 15 | using namespace antlrcpp; 16 | 17 | static IterativeParseTreeWalker defaultWalker; 18 | ParseTreeWalker &ParseTreeWalker::DEFAULT = defaultWalker; 19 | 20 | ParseTreeWalker::~ParseTreeWalker() { 21 | } 22 | 23 | void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const { 24 | if (is(t)) { 25 | listener->visitErrorNode(dynamic_cast(t)); 26 | return; 27 | } else if (is(t)) { 28 | listener->visitTerminal(dynamic_cast(t)); 29 | return; 30 | } 31 | 32 | enterRule(listener, t); 33 | for (auto &child : t->children) { 34 | walk(listener, child); 35 | } 36 | exitRule(listener, t); 37 | } 38 | 39 | void ParseTreeWalker::enterRule(ParseTreeListener *listener, ParseTree *r) const { 40 | ParserRuleContext *ctx = dynamic_cast(r); 41 | listener->enterEveryRule(ctx); 42 | ctx->enterRule(listener); 43 | } 44 | 45 | void ParseTreeWalker::exitRule(ParseTreeListener *listener, ParseTree *r) const { 46 | ParserRuleContext *ctx = dynamic_cast(r); 47 | ctx->exitRule(listener); 48 | listener->exitEveryRule(ctx); 49 | } 50 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerActionType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// Represents the serialization type of a . 15 | /// 16 | /// @author Sam Harwell 17 | /// @since 4.2 18 | /// 19 | enum class LexerActionType : size_t { 20 | /// 21 | /// The type of a action. 22 | /// 23 | CHANNEL, 24 | /// 25 | /// The type of a action. 26 | /// 27 | CUSTOM, 28 | /// 29 | /// The type of a action. 30 | /// 31 | MODE, 32 | /// 33 | /// The type of a action. 34 | /// 35 | MORE, 36 | /// 37 | /// The type of a action. 38 | /// 39 | POP_MODE, 40 | /// 41 | /// The type of a action. 42 | /// 43 | PUSH_MODE, 44 | /// 45 | /// The type of a action. 46 | /// 47 | SKIP, 48 | /// 49 | /// The type of a action. 50 | /// 51 | TYPE, 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /antlr/runtime/atn/SingletonPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/PredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC SingletonPredictionContext : public PredictionContext { 14 | public: 15 | // Usually a parent is linked via a weak ptr. Not so here as we have kinda reverse reference chain. 16 | // There are no child contexts stored here and often the parent context is left dangling when it's 17 | // owning ATNState is released. In order to avoid having this context released as well (leaving all other contexts 18 | // which got this one as parent with a null reference) we use a shared_ptr here instead, to keep those left alone 19 | // parent contexts alive. 20 | const Ref parent; 21 | const size_t returnState; 22 | 23 | SingletonPredictionContext(Ref const& parent, size_t returnState); 24 | virtual ~SingletonPredictionContext(); 25 | 26 | static Ref create(Ref const& parent, size_t returnState); 27 | 28 | virtual size_t size() const override; 29 | virtual Ref getParent(size_t index) const override; 30 | virtual size_t getReturnState(size_t index) const override; 31 | virtual bool operator == (const PredictionContext &o) const override; 32 | virtual std::string toString() const override; 33 | }; 34 | 35 | } // namespace atn 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/TextChunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Chunk.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// Represents a span of raw text (concrete syntax) between tags in a tree 16 | /// pattern string. 17 | /// 18 | class ANTLR4CPP_PUBLIC TextChunk : public Chunk { 19 | private: 20 | /// 21 | /// This is the backing field for . 22 | /// 23 | const std::string text; 24 | 25 | /// 26 | /// Constructs a new instance of with the specified text. 27 | /// 28 | /// The text of this chunk. 29 | /// if {@code text} is {@code null}. 30 | public: 31 | TextChunk(const std::string &text); 32 | virtual ~TextChunk(); 33 | 34 | /// 35 | /// Gets the raw text of this chunk. 36 | /// 37 | /// The text of the chunk. 38 | std::string getText(); 39 | 40 | /// 41 | /// {@inheritDoc} 42 | ///

43 | /// The implementation for returns the result of 44 | /// in single quotes. 45 | ///

46 | virtual std::string toString() override; 47 | }; 48 | 49 | } // namespace pattern 50 | } // namespace tree 51 | } // namespace antlr4 52 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ArrayPredictionContext.h: -------------------------------------------------------------------------------- 1 | 2 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | * Use of this file is governed by the BSD 3-clause license that 4 | * can be found in the LICENSE.txt file in the project root. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "atn/PredictionContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class SingletonPredictionContext; 15 | 16 | class ANTLR4CPP_PUBLIC ArrayPredictionContext : public PredictionContext { 17 | public: 18 | /// Parent can be empty only if full ctx mode and we make an array 19 | /// from EMPTY and non-empty. We merge EMPTY by using null parent and 20 | /// returnState == EMPTY_RETURN_STATE. 21 | // Also here: we use a strong reference to our parents to avoid having them freed prematurely. 22 | // See also SinglePredictionContext. 23 | const std::vector> parents; 24 | 25 | /// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last. 26 | const std::vector returnStates; 27 | 28 | ArrayPredictionContext(Ref const& a); 29 | ArrayPredictionContext(std::vector> const& parents_, std::vector const& returnStates); 30 | virtual ~ArrayPredictionContext(); 31 | 32 | virtual bool isEmpty() const override; 33 | virtual size_t size() const override; 34 | virtual Ref getParent(size_t index) const override; 35 | virtual size_t getReturnState(size_t index) const override; 36 | bool operator == (const PredictionContext &o) const override; 37 | 38 | virtual std::string toString() const override; 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | 44 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerATNConfig.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfig.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC LexerATNConfig : public ATNConfig { 14 | public: 15 | LexerATNConfig(ATNState *state, int alt, Ref const& context); 16 | LexerATNConfig(ATNState *state, int alt, Ref const& context, Ref const& lexerActionExecutor); 17 | 18 | LexerATNConfig(Ref const& c, ATNState *state); 19 | LexerATNConfig(Ref const& c, ATNState *state, Ref const& lexerActionExecutor); 20 | LexerATNConfig(Ref const& c, ATNState *state, Ref const& context); 21 | 22 | /** 23 | * Gets the {@link LexerActionExecutor} capable of executing the embedded 24 | * action(s) for the current configuration. 25 | */ 26 | Ref getLexerActionExecutor() const; 27 | bool hasPassedThroughNonGreedyDecision(); 28 | 29 | virtual size_t hashCode() const override; 30 | 31 | bool operator == (const LexerATNConfig& other) const; 32 | 33 | private: 34 | /** 35 | * This is the backing field for {@link #getLexerActionExecutor}. 36 | */ 37 | const Ref _lexerActionExecutor; 38 | const bool _passedThroughNonGreedyDecision; 39 | 40 | static bool checkNonGreedyDecision(Ref const& source, ATNState *target); 41 | }; 42 | 43 | } // namespace atn 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /antlr/runtime/NoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "NoViableAltException.h" 9 | 10 | using namespace antlr4; 11 | 12 | namespace { 13 | 14 | // Create a normal shared pointer if the configurations are to be deleted. If not, then 15 | // the shared pointer is created with a deleter that does nothing. 16 | Ref buildConfigsRef(atn::ATNConfigSet *configs, bool deleteConfigs) { 17 | if (deleteConfigs) { 18 | return Ref(configs); 19 | } else { 20 | return Ref(configs, [](atn::ATNConfigSet *){}); 21 | } 22 | } 23 | 24 | } 25 | 26 | NoViableAltException::NoViableAltException(Parser *recognizer) 27 | : NoViableAltException(recognizer, recognizer->getTokenStream(), recognizer->getCurrentToken(), 28 | recognizer->getCurrentToken(), nullptr, recognizer->getContext(), false) { 29 | } 30 | 31 | NoViableAltException::NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 32 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs) 33 | : RecognitionException("No viable alternative", recognizer, input, ctx, offendingToken), 34 | _deadEndConfigs(buildConfigsRef(deadEndConfigs, deleteConfigs)), _startToken(startToken) { 35 | } 36 | 37 | NoViableAltException::~NoViableAltException() { 38 | } 39 | 40 | Token* NoViableAltException::getStartToken() const { 41 | return _startToken; 42 | } 43 | 44 | atn::ATNConfigSet* NoViableAltException::getDeadEndConfigs() const { 45 | return _deadEndConfigs.get(); 46 | } 47 | -------------------------------------------------------------------------------- /antlr/runtime/InterpreterRuleContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /** 13 | * This class extends {@link ParserRuleContext} by allowing the value of 14 | * {@link #getRuleIndex} to be explicitly set for the context. 15 | * 16 | *

17 | * {@link ParserRuleContext} does not include field storage for the rule index 18 | * since the context classes created by the code generator override the 19 | * {@link #getRuleIndex} method to return the correct value for that context. 20 | * Since the parser interpreter does not use the context classes generated for a 21 | * parser, this class (with slightly more memory overhead per node) is used to 22 | * provide equivalent functionality.

23 | */ 24 | class ANTLR4CPP_PUBLIC InterpreterRuleContext : public ParserRuleContext { 25 | public: 26 | InterpreterRuleContext(); 27 | 28 | /** 29 | * Constructs a new {@link InterpreterRuleContext} with the specified 30 | * parent, invoking state, and rule index. 31 | * 32 | * @param parent The parent context. 33 | * @param invokingStateNumber The invoking state number. 34 | * @param ruleIndex The rule index for the current context. 35 | */ 36 | InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex); 37 | 38 | virtual size_t getRuleIndex() const override; 39 | 40 | protected: 41 | /** This is the backing field for {@link #getRuleIndex}. */ 42 | const size_t _ruleIndex = INVALID_INDEX; 43 | }; 44 | 45 | } // namespace antlr4 46 | -------------------------------------------------------------------------------- /antlr/runtime/atn/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CXXFLAGS += -g -std=c++0x -Wall #-Wextra 3 | CXXFLAGS += -I. -I../ -I../misc/ -I../tree/ -I../dfa/ \ 4 | -I../../../../../antlrcpp/ 5 | 6 | #TODO LDFLAGS += ? 7 | 8 | ALL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) 9 | ALL_LDFLAGS = $(LDFLAGS) 10 | 11 | # Escote's files 12 | SRCS = \ 13 | AbstractPredicateTransition.cpp \ 14 | ActionTransition.cpp \ 15 | ArrayPredictionContext.cpp \ 16 | ATNDeserializationOptions.cpp \ 17 | ATNDeserializer.cpp \ 18 | ATNState.cpp \ 19 | ATNType.cpp \ 20 | AtomTransition.cpp \ 21 | BasicBlockStartState.cpp \ 22 | BasicState.cpp \ 23 | BlockEndState.cpp \ 24 | BlockStartState.cpp \ 25 | DecisionState.cpp \ 26 | EmptyPredictionContext.cpp \ 27 | EpsilonTransition.cpp \ 28 | LexerATNConfig.cpp \ 29 | LoopEndState.cpp 30 | # Escote's TODO: LL1Analyzer.cpp LexerATNSimulator.cpp ATNSimulator.cpp \ 31 | ATNSerializer.cpp ATNConfigSet.cpp ATNConfig.cpp \ 32 | ATN.cpp 33 | 34 | # Alejandro's files 35 | SRCS += \ 36 | NotSetTransition.cpp \ 37 | OrderedATNConfigSet.cpp \ 38 | PlusBlockStartState.cpp \ 39 | PlusLoopbackState.cpp \ 40 | PredicateTransition.cpp \ 41 | PredictionMode.cpp \ 42 | RangeTransition.cpp \ 43 | RuleStartState.cpp \ 44 | RuleStopState.cpp \ 45 | RuleTransition.cpp \ 46 | SemanticContext.cpp \ 47 | SetTransition.cpp \ 48 | SingletonPredictionContext.cpp \ 49 | StarBlockStartState.cpp \ 50 | StarLoopbackState.cpp \ 51 | StarLoopEntryState.cpp \ 52 | TokensStartState.cpp \ 53 | Transition.cpp \ 54 | WildcardTransition.cpp 55 | # Alejandro's TODO: PredictionContext.cpp PredictionContextCache.cpp \ 56 | PrecedencePredicateTransition.cpp ParserATNSimulator.cpp 57 | 58 | OBJS = $(SRCS:.cpp=.o) 59 | 60 | all: $(OBJS) 61 | 62 | %.o: %.cpp 63 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 64 | 65 | clean: 66 | $(RM) $(OBJS) 67 | 68 | -------------------------------------------------------------------------------- /antlr/runtime/ProxyErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | #include "Exceptions.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// This implementation of ANTLRErrorListener dispatches all calls to a 14 | /// collection of delegate listeners. This reduces the effort required to support multiple 15 | /// listeners. 16 | class ANTLR4CPP_PUBLIC ProxyErrorListener : public ANTLRErrorListener { 17 | private: 18 | std::set _delegates; // Not owned. 19 | 20 | public: 21 | void addErrorListener(ANTLRErrorListener *listener); 22 | void removeErrorListener(ANTLRErrorListener *listener); 23 | void removeErrorListeners(); 24 | 25 | void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, size_t charPositionInLine, 26 | const std::string &msg, std::exception_ptr e) override; 27 | 28 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 29 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 30 | 31 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 32 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 33 | 34 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 35 | size_t prediction, atn::ATNConfigSet *configs) override; 36 | }; 37 | 38 | } // namespace antlr4 39 | -------------------------------------------------------------------------------- /antlr/runtime/NoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "Token.h" 10 | #include "atn/ATNConfigSet.h" 11 | 12 | namespace antlr4 { 13 | 14 | /// Indicates that the parser could not decide which of two or more paths 15 | /// to take based upon the remaining input. It tracks the starting token 16 | /// of the offending input and also knows where the parser was 17 | /// in the various paths when the error. Reported by reportNoViableAlternative() 18 | class ANTLR4CPP_PUBLIC NoViableAltException : public RecognitionException { 19 | public: 20 | NoViableAltException(Parser *recognizer); // LL(1) error 21 | NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 22 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs); 23 | ~NoViableAltException(); 24 | 25 | virtual Token* getStartToken() const; 26 | virtual atn::ATNConfigSet* getDeadEndConfigs() const; 27 | 28 | private: 29 | /// Which configurations did we try at input.index() that couldn't match input.LT(1)? 30 | /// Shared pointer that conditionally deletes the configurations (based on flag 31 | /// passed during construction) 32 | Ref _deadEndConfigs; 33 | 34 | /// The token object at the start index; the input stream might 35 | /// not be buffering tokens so get a reference to it. (At the 36 | /// time the error occurred, of course the stream needs to keep a 37 | /// buffer all of the tokens but later we might not have access to those.) 38 | Token *_startToken; 39 | 40 | }; 41 | 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /engine/engine.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RULE_ENGINE_ENGINE_ 2 | #define _RULE_ENGINE_ENGINE_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antlr/grammar/crule_listener.hpp" 10 | #include "antlr/grammar/generated/cruleLexer.h" 11 | #include "antlr/grammar/generated/cruleParser.h" 12 | #include "ast_processor/crl.hpp" 13 | #include "antlr4-runtime.h" 14 | 15 | #include "data_context.hpp" 16 | #include "knowledge_base.hpp" 17 | 18 | namespace rule_engine { 19 | 20 | class Engine { 21 | public: 22 | Engine() {} 23 | 24 | void load_rules(const std::string& rules) { 25 | antlr4::ANTLRInputStream inputStream(rules.c_str(), rules.size()); 26 | cruleLexer lexer(&inputStream); 27 | antlr4::CommonTokenStream tokens(&lexer); 28 | cruleParser parser(&tokens); 29 | CruleListener listener; 30 | antlr4::tree::ParseTreeWalker::DEFAULT.walk(&listener, parser.crl()); 31 | 32 | std::unique_lock lock(mtx_); 33 | rules_ = rules; 34 | auto crl = listener.get_crl(); 35 | kb_.set_crl(crl); 36 | } 37 | void execute(DataContext* dctx) { 38 | std::shared_ptr crl; 39 | { 40 | std::shared_lock lock(mtx_); 41 | crl = kb_.get_crl(); 42 | } 43 | 44 | for(auto& rule_entry:crl->get_rule_entries()) { 45 | if(rule_entry.second->evaluate(dctx)) { 46 | rule_entry.second->execute(dctx); 47 | } 48 | } 49 | } 50 | // void set_data_ctx(std::shared_ptr d) { 51 | // dctx_ = d; 52 | // } 53 | // std::shared_ptr get_data_ctx() { 54 | // return dctx_; 55 | // } 56 | private: 57 | // std::shared_ptr dctx_; 58 | KnowledgeBase kb_; 59 | std::string rules_; 60 | mutable std::shared_mutex mtx_; 61 | }; 62 | 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "support/CPPUtils.h" 8 | #include "Lexer.h" 9 | 10 | #include "atn/LexerCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | 16 | LexerCustomAction::LexerCustomAction(size_t ruleIndex, size_t actionIndex) : _ruleIndex(ruleIndex), _actionIndex(actionIndex) { 17 | } 18 | 19 | size_t LexerCustomAction::getRuleIndex() const { 20 | return _ruleIndex; 21 | } 22 | 23 | size_t LexerCustomAction::getActionIndex() const { 24 | return _actionIndex; 25 | } 26 | 27 | LexerActionType LexerCustomAction::getActionType() const { 28 | return LexerActionType::CUSTOM; 29 | } 30 | 31 | bool LexerCustomAction::isPositionDependent() const { 32 | return true; 33 | } 34 | 35 | void LexerCustomAction::execute(Lexer *lexer) { 36 | lexer->action(nullptr, _ruleIndex, _actionIndex); 37 | } 38 | 39 | size_t LexerCustomAction::hashCode() const { 40 | size_t hash = MurmurHash::initialize(); 41 | hash = MurmurHash::update(hash, static_cast(getActionType())); 42 | hash = MurmurHash::update(hash, _ruleIndex); 43 | hash = MurmurHash::update(hash, _actionIndex); 44 | return MurmurHash::finish(hash, 3); 45 | } 46 | 47 | bool LexerCustomAction::operator == (const LexerAction &obj) const { 48 | if (&obj == this) { 49 | return true; 50 | } 51 | 52 | const LexerCustomAction *action = dynamic_cast(&obj); 53 | if (action == nullptr) { 54 | return false; 55 | } 56 | 57 | return _ruleIndex == action->_ruleIndex && _actionIndex == action->_actionIndex; 58 | } 59 | 60 | std::string LexerCustomAction::toString() const { 61 | return antlrcpp::toString(this); 62 | } 63 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ATNDeserializationOptions.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNDeserializationOptions.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ATNDeserializationOptions ATNDeserializationOptions::defaultOptions; 11 | 12 | ATNDeserializationOptions::ATNDeserializationOptions() { 13 | InitializeInstanceFields(); 14 | } 15 | 16 | ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options) : ATNDeserializationOptions() { 17 | this->verifyATN = options->verifyATN; 18 | this->generateRuleBypassTransitions = options->generateRuleBypassTransitions; 19 | } 20 | 21 | ATNDeserializationOptions::~ATNDeserializationOptions() { 22 | } 23 | 24 | const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() { 25 | return defaultOptions; 26 | } 27 | 28 | bool ATNDeserializationOptions::isReadOnly() { 29 | return readOnly; 30 | } 31 | 32 | void ATNDeserializationOptions::makeReadOnly() { 33 | readOnly = true; 34 | } 35 | 36 | bool ATNDeserializationOptions::isVerifyATN() { 37 | return verifyATN; 38 | } 39 | 40 | void ATNDeserializationOptions::setVerifyATN(bool verify) { 41 | throwIfReadOnly(); 42 | verifyATN = verify; 43 | } 44 | 45 | bool ATNDeserializationOptions::isGenerateRuleBypassTransitions() { 46 | return generateRuleBypassTransitions; 47 | } 48 | 49 | void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) { 50 | throwIfReadOnly(); 51 | generateRuleBypassTransitions = generate; 52 | } 53 | 54 | void ATNDeserializationOptions::throwIfReadOnly() { 55 | if (isReadOnly()) { 56 | throw "The object is read only."; 57 | } 58 | } 59 | 60 | void ATNDeserializationOptions::InitializeInstanceFields() { 61 | readOnly = false; 62 | verifyATN = true; 63 | generateRuleBypassTransitions = false; 64 | } 65 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerIndexedCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | #include "support/CPPUtils.h" 9 | 10 | #include "atn/LexerIndexedCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | 16 | LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref const& action) 17 | : _offset(offset), _action(action) { 18 | } 19 | 20 | int LexerIndexedCustomAction::getOffset() const { 21 | return _offset; 22 | } 23 | 24 | Ref LexerIndexedCustomAction::getAction() const { 25 | return _action; 26 | } 27 | 28 | LexerActionType LexerIndexedCustomAction::getActionType() const { 29 | return _action->getActionType(); 30 | } 31 | 32 | bool LexerIndexedCustomAction::isPositionDependent() const { 33 | return true; 34 | } 35 | 36 | void LexerIndexedCustomAction::execute(Lexer *lexer) { 37 | // assume the input stream position was properly set by the calling code 38 | _action->execute(lexer); 39 | } 40 | 41 | size_t LexerIndexedCustomAction::hashCode() const { 42 | size_t hash = MurmurHash::initialize(); 43 | hash = MurmurHash::update(hash, _offset); 44 | hash = MurmurHash::update(hash, _action); 45 | return MurmurHash::finish(hash, 2); 46 | } 47 | 48 | bool LexerIndexedCustomAction::operator == (const LexerAction &obj) const { 49 | if (&obj == this) { 50 | return true; 51 | } 52 | 53 | const LexerIndexedCustomAction *action = dynamic_cast(&obj); 54 | if (action == nullptr) { 55 | return false; 56 | } 57 | 58 | return _offset == action->_offset && *_action == *action->_action; 59 | } 60 | 61 | std::string LexerIndexedCustomAction::toString() const { 62 | return antlrcpp::toString(this); 63 | } 64 | -------------------------------------------------------------------------------- /antlr/runtime/FailedPredicateException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ParserATNSimulator.h" 7 | #include "Parser.h" 8 | #include "atn/PredicateTransition.h" 9 | #include "atn/ATN.h" 10 | #include "atn/ATNState.h" 11 | #include "support/CPPUtils.h" 12 | 13 | #include "FailedPredicateException.h" 14 | 15 | using namespace antlr4; 16 | using namespace antlrcpp; 17 | 18 | FailedPredicateException::FailedPredicateException(Parser *recognizer) : FailedPredicateException(recognizer, "", "") { 19 | } 20 | 21 | FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::string &predicate): FailedPredicateException(recognizer, predicate, "") { 22 | } 23 | 24 | FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message) 25 | : RecognitionException(!message.empty() ? message : "failed predicate: " + predicate + "?", recognizer, 26 | recognizer->getInputStream(), recognizer->getContext(), recognizer->getCurrentToken()) { 27 | 28 | atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()]; 29 | atn::Transition *transition = s->transitions[0]; 30 | if (is(transition)) { 31 | _ruleIndex = static_cast(transition)->ruleIndex; 32 | _predicateIndex = static_cast(transition)->predIndex; 33 | } else { 34 | _ruleIndex = 0; 35 | _predicateIndex = 0; 36 | } 37 | 38 | _predicate = predicate; 39 | } 40 | 41 | size_t FailedPredicateException::getRuleIndex() { 42 | return _ruleIndex; 43 | } 44 | 45 | size_t FailedPredicateException::getPredIndex() { 46 | return _predicateIndex; 47 | } 48 | 49 | std::string FailedPredicateException::getPredicate() { 50 | return _predicate; 51 | } 52 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerSkipAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code skip} lexer action by calling . 16 | /// 17 | /// The {@code skip} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction { 24 | public: 25 | /// Provides a singleton instance of this parameterless lexer action. 26 | static const Ref getInstance(); 27 | 28 | /// 29 | /// {@inheritDoc} 30 | /// This method returns . 31 | virtual LexerActionType getActionType() const override; 32 | 33 | /// 34 | /// {@inheritDoc} 35 | /// This method returns {@code false}. 36 | virtual bool isPositionDependent() const override; 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling . 42 | /// 43 | virtual void execute(Lexer *lexer) override; 44 | 45 | virtual size_t hashCode() const override; 46 | virtual bool operator == (const LexerAction &obj) const override; 47 | virtual std::string toString() const override; 48 | 49 | private: 50 | /// Constructs the singleton instance of the lexer {@code skip} command. 51 | LexerSkipAction(); 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /antlr/runtime/atn/ErrorInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// This class represents profiling event information for a syntax error 15 | /// identified during prediction. Syntax errors occur when the prediction 16 | /// algorithm is unable to identify an alternative which would lead to a 17 | /// successful parse. 18 | /// 19 | /// 20 | /// 23 | class ANTLR4CPP_PUBLIC ErrorInfo : public DecisionEventInfo { 24 | public: 25 | /// 26 | /// Constructs a new instance of the class with the 27 | /// specified detailed syntax error information. 28 | /// 29 | /// The decision number 30 | /// The final configuration set reached during prediction 31 | /// prior to reaching the state 32 | /// The input token stream 33 | /// The start index for the current prediction 34 | /// The index at which the syntax error was identified 35 | /// {@code true} if the syntax error was identified during LL 36 | /// prediction; otherwise, {@code false} if the syntax error was identified 37 | /// during SLL prediction 38 | ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, 39 | bool fullCtx); 40 | }; 41 | 42 | } // namespace atn 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /antlr/runtime/tree/xpath/XPathLexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "antlr4-runtime.h" 5 | 6 | 7 | 8 | 9 | class XPathLexer : public antlr4::Lexer { 10 | public: 11 | enum { 12 | TOKEN_REF = 1, RULE_REF = 2, ANYWHERE = 3, ROOT = 4, WILDCARD = 5, BANG = 6, 13 | ID = 7, STRING = 8 14 | }; 15 | 16 | XPathLexer(antlr4::CharStream *input); 17 | ~XPathLexer(); 18 | 19 | virtual std::string getGrammarFileName() const override; 20 | virtual const std::vector& getRuleNames() const override; 21 | 22 | virtual const std::vector& getChannelNames() const override; 23 | virtual const std::vector& getModeNames() const override; 24 | virtual const std::vector& getTokenNames() const override; // deprecated, use vocabulary instead 25 | virtual antlr4::dfa::Vocabulary& getVocabulary() const override; 26 | 27 | virtual const std::vector getSerializedATN() const override; 28 | virtual const antlr4::atn::ATN& getATN() const override; 29 | 30 | virtual void action(antlr4::RuleContext *context, size_t ruleIndex, size_t actionIndex) override; 31 | private: 32 | static std::vector _decisionToDFA; 33 | static antlr4::atn::PredictionContextCache _sharedContextCache; 34 | static std::vector _ruleNames; 35 | static std::vector _tokenNames; 36 | static std::vector _channelNames; 37 | static std::vector _modeNames; 38 | 39 | static std::vector _literalNames; 40 | static std::vector _symbolicNames; 41 | static antlr4::dfa::Vocabulary _vocabulary; 42 | static antlr4::atn::ATN _atn; 43 | static std::vector _serializedATN; 44 | 45 | 46 | // Individual action functions triggered by action() above. 47 | void IDAction(antlr4::RuleContext *context, size_t actionIndex); 48 | 49 | // Individual semantic predicate functions triggered by sempred() above. 50 | 51 | struct Initializer { 52 | Initializer(); 53 | }; 54 | static Initializer _init; 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerMoreAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code more} lexer action by calling . 16 | /// 17 | /// The {@code more} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerMoreAction final : public LexerAction { 24 | public: 25 | /// 26 | /// Provides a singleton instance of this parameterless lexer action. 27 | /// 28 | static const Ref getInstance(); 29 | 30 | /// 31 | /// {@inheritDoc} 32 | /// This method returns . 33 | virtual LexerActionType getActionType() const override; 34 | 35 | /// 36 | /// {@inheritDoc} 37 | /// This method returns {@code false}. 38 | virtual bool isPositionDependent() const override; 39 | 40 | /// 41 | /// {@inheritDoc} 42 | /// 43 | /// This action is implemented by calling . 44 | /// 45 | virtual void execute(Lexer *lexer) override; 46 | 47 | virtual size_t hashCode() const override; 48 | virtual bool operator == (const LexerAction &obj) const override; 49 | virtual std::string toString() const override; 50 | 51 | private: 52 | /// Constructs the singleton instance of the lexer {@code more} command. 53 | LexerMoreAction(); 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /antlr/runtime/BailErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "ParserRuleContext.h" 8 | #include "InputMismatchException.h" 9 | #include "Parser.h" 10 | 11 | #include "BailErrorStrategy.h" 12 | 13 | using namespace antlr4; 14 | 15 | void BailErrorStrategy::recover(Parser *recognizer, std::exception_ptr e) { 16 | ParserRuleContext *context = recognizer->getContext(); 17 | do { 18 | context->exception = e; 19 | if (context->parent == nullptr) 20 | break; 21 | context = static_cast(context->parent); 22 | } while (true); 23 | 24 | try { 25 | std::rethrow_exception(e); // Throw the exception to be able to catch and rethrow nested. 26 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026 27 | } catch (RecognitionException &inner) { 28 | throw ParseCancellationException(inner.what()); 29 | #else 30 | } catch (RecognitionException & /*inner*/) { 31 | std::throw_with_nested(ParseCancellationException()); 32 | #endif 33 | } 34 | } 35 | 36 | Token* BailErrorStrategy::recoverInline(Parser *recognizer) { 37 | InputMismatchException e(recognizer); 38 | std::exception_ptr exception = std::make_exception_ptr(e); 39 | 40 | ParserRuleContext *context = recognizer->getContext(); 41 | do { 42 | context->exception = exception; 43 | if (context->parent == nullptr) 44 | break; 45 | context = static_cast(context->parent); 46 | } while (true); 47 | 48 | try { 49 | throw e; 50 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026 51 | } catch (InputMismatchException &inner) { 52 | throw ParseCancellationException(inner.what()); 53 | #else 54 | } catch (InputMismatchException & /*inner*/) { 55 | std::throw_with_nested(ParseCancellationException()); 56 | #endif 57 | } 58 | } 59 | 60 | void BailErrorStrategy::sync(Parser * /*recognizer*/) { 61 | } 62 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerPopModeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code popMode} lexer action by calling . 16 | /// 17 | /// The {@code popMode} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerPopModeAction final : public LexerAction { 24 | public: 25 | /// 26 | /// Provides a singleton instance of this parameterless lexer action. 27 | /// 28 | static const Ref getInstance(); 29 | 30 | /// 31 | /// {@inheritDoc} 32 | /// This method returns . 33 | virtual LexerActionType getActionType() const override; 34 | 35 | /// 36 | /// {@inheritDoc} 37 | /// This method returns {@code false}. 38 | virtual bool isPositionDependent() const override; 39 | 40 | /// 41 | /// {@inheritDoc} 42 | /// 43 | /// This action is implemented by calling . 44 | /// 45 | virtual void execute(Lexer *lexer) override; 46 | 47 | virtual size_t hashCode() const override; 48 | virtual bool operator == (const LexerAction &obj) const override; 49 | virtual std::string toString() const override; 50 | 51 | private: 52 | /// Constructs the singleton instance of the lexer {@code popMode} command. 53 | LexerPopModeAction(); 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LookaheadEventInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// This class represents profiling event information for tracking the lookahead 14 | /// depth required in order to make a prediction. 15 | class ANTLR4CPP_PUBLIC LookaheadEventInfo : public DecisionEventInfo { 16 | public: 17 | /// The alternative chosen by adaptivePredict(), not necessarily 18 | /// the outermost alt shown for a rule; left-recursive rules have 19 | /// user-level alts that differ from the rewritten rule with a (...) block 20 | /// and a (..)* loop. 21 | size_t predictedAlt = 0; 22 | 23 | /// 24 | /// Constructs a new instance of the class with 25 | /// the specified detailed lookahead information. 26 | /// 27 | /// The decision number 28 | /// The final configuration set containing the necessary 29 | /// information to determine the result of a prediction, or {@code null} if 30 | /// the final configuration set is not available 31 | /// The input token stream 32 | /// The start index for the current prediction 33 | /// The index at which the prediction was finally made 34 | /// {@code true} if the current lookahead is part of an LL 35 | /// prediction; otherwise, {@code false} if the current lookahead is part of 36 | /// an SLL prediction 37 | LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, TokenStream *input, size_t startIndex, 38 | size_t stopIndex, bool fullCtx); 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerTypeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerActionType.h" 9 | #include "atn/LexerAction.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// Implements the {@code type} lexer action by calling 15 | /// with the assigned type. 16 | class ANTLR4CPP_PUBLIC LexerTypeAction : public LexerAction { 17 | public: 18 | /// 19 | /// Constructs a new {@code type} action with the specified token type value. 20 | /// The type to assign to the token using . 21 | LexerTypeAction(int type); 22 | 23 | /// 24 | /// Gets the type to assign to a token created by the lexer. 25 | /// The type to assign to a token created by the lexer. 26 | virtual int getType() const; 27 | 28 | /// 29 | /// {@inheritDoc} 30 | /// This method returns . 31 | virtual LexerActionType getActionType() const override; 32 | 33 | /// 34 | /// {@inheritDoc} 35 | /// This method returns {@code false}. 36 | virtual bool isPositionDependent() const override; 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling with the 42 | /// value provided by . 43 | /// 44 | virtual void execute(Lexer *lexer) override; 45 | 46 | virtual size_t hashCode() const override; 47 | virtual bool operator == (const LexerAction &obj) const override; 48 | virtual std::string toString() const override; 49 | 50 | private: 51 | const int _type; 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/ParseTreePattern.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/pattern/ParseTreePatternMatcher.h" 8 | #include "tree/pattern/ParseTreeMatch.h" 9 | 10 | #include "tree/xpath/XPath.h" 11 | #include "tree/xpath/XPathElement.h" 12 | 13 | #include "tree/pattern/ParseTreePattern.h" 14 | 15 | using namespace antlr4::tree; 16 | using namespace antlr4::tree::pattern; 17 | 18 | using namespace antlrcpp; 19 | 20 | ParseTreePattern::ParseTreePattern(ParseTreePatternMatcher *matcher, const std::string &pattern, int patternRuleIndex_, 21 | ParseTree *patternTree) 22 | : patternRuleIndex(patternRuleIndex_), _pattern(pattern), _patternTree(patternTree), _matcher(matcher) { 23 | } 24 | 25 | ParseTreePattern::~ParseTreePattern() { 26 | } 27 | 28 | ParseTreeMatch ParseTreePattern::match(ParseTree *tree) { 29 | return _matcher->match(tree, *this); 30 | } 31 | 32 | bool ParseTreePattern::matches(ParseTree *tree) { 33 | return _matcher->match(tree, *this).succeeded(); 34 | } 35 | 36 | std::vector ParseTreePattern::findAll(ParseTree *tree, const std::string &xpath) { 37 | xpath::XPath finder(_matcher->getParser(), xpath); 38 | std::vector subtrees = finder.evaluate(tree); 39 | std::vector matches; 40 | for (auto *t : subtrees) { 41 | ParseTreeMatch aMatch = match(t); 42 | if (aMatch.succeeded()) { 43 | matches.push_back(aMatch); 44 | } 45 | } 46 | return matches; 47 | } 48 | 49 | 50 | ParseTreePatternMatcher *ParseTreePattern::getMatcher() const { 51 | return _matcher; 52 | } 53 | 54 | std::string ParseTreePattern::getPattern() const { 55 | return _pattern; 56 | } 57 | 58 | int ParseTreePattern::getPatternRuleIndex() const { 59 | return patternRuleIndex; 60 | } 61 | 62 | ParseTree* ParseTreePattern::getPatternTree() const { 63 | return _patternTree; 64 | } 65 | -------------------------------------------------------------------------------- /antlr/runtime/CommonTokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | #include "CommonTokenStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : CommonTokenStream(tokenSource, Token::DEFAULT_CHANNEL) { 13 | } 14 | 15 | CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, size_t channel_) 16 | : BufferedTokenStream(tokenSource), channel(channel_) { 17 | } 18 | 19 | ssize_t CommonTokenStream::adjustSeekIndex(size_t i) { 20 | return nextTokenOnChannel(i, channel); 21 | } 22 | 23 | Token* CommonTokenStream::LB(size_t k) { 24 | if (k == 0 || k > _p) { 25 | return nullptr; 26 | } 27 | 28 | ssize_t i = static_cast(_p); 29 | size_t n = 1; 30 | // find k good tokens looking backwards 31 | while (n <= k) { 32 | // skip off-channel tokens 33 | i = previousTokenOnChannel(i - 1, channel); 34 | n++; 35 | } 36 | if (i < 0) { 37 | return nullptr; 38 | } 39 | 40 | return _tokens[i].get(); 41 | } 42 | 43 | Token* CommonTokenStream::LT(ssize_t k) { 44 | lazyInit(); 45 | if (k == 0) { 46 | return nullptr; 47 | } 48 | if (k < 0) { 49 | return LB(static_cast(-k)); 50 | } 51 | size_t i = _p; 52 | ssize_t n = 1; // we know tokens[p] is a good one 53 | // find k good tokens 54 | while (n < k) { 55 | // skip off-channel tokens, but make sure to not look past EOF 56 | if (sync(i + 1)) { 57 | i = nextTokenOnChannel(i + 1, channel); 58 | } 59 | n++; 60 | } 61 | 62 | return _tokens[i].get(); 63 | } 64 | 65 | int CommonTokenStream::getNumberOfOnChannelTokens() { 66 | int n = 0; 67 | fill(); 68 | for (size_t i = 0; i < _tokens.size(); i++) { 69 | Token *t = _tokens[i].get(); 70 | if (t->getChannel() == channel) { 71 | n++; 72 | } 73 | if (t->getType() == Token::EOF) { 74 | break; 75 | } 76 | } 77 | return n; 78 | } 79 | -------------------------------------------------------------------------------- /antlr/runtime/support/BitSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | class ANTLR4CPP_PUBLIC BitSet : public std::bitset<2048> { 13 | public: 14 | size_t nextSetBit(size_t pos) const { 15 | for (size_t i = pos; i < size(); i++){ 16 | if (test(i)) { 17 | return i; 18 | } 19 | } 20 | 21 | return INVALID_INDEX; 22 | } 23 | 24 | // Prints a list of every index for which the bitset contains a bit in true. 25 | friend std::wostream& operator << (std::wostream& os, const BitSet& obj) 26 | { 27 | os << "{"; 28 | size_t total = obj.count(); 29 | for (size_t i = 0; i < obj.size(); i++){ 30 | if (obj.test(i)){ 31 | os << i; 32 | --total; 33 | if (total > 1){ 34 | os << ", "; 35 | } 36 | } 37 | } 38 | 39 | os << "}"; 40 | return os; 41 | } 42 | 43 | static std::string subStringRepresentation(const std::vector::iterator &begin, 44 | const std::vector::iterator &end) { 45 | std::string result; 46 | std::vector::iterator vectorIterator; 47 | 48 | for (vectorIterator = begin; vectorIterator != end; vectorIterator++) { 49 | result += vectorIterator->toString(); 50 | } 51 | // Grab the end 52 | result += end->toString(); 53 | 54 | return result; 55 | } 56 | 57 | std::string toString(){ 58 | std::stringstream stream; 59 | stream << "{"; 60 | bool valueAdded = false; 61 | for (size_t i = 0; i < size(); ++i){ 62 | if (test(i)){ 63 | if (valueAdded) { 64 | stream << ", "; 65 | } 66 | stream << i; 67 | valueAdded = true; 68 | } 69 | } 70 | 71 | stream << "}"; 72 | return stream.str(); 73 | } 74 | 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/RuleTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/RuleTagToken.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | RuleTagToken::RuleTagToken(const std::string &/*ruleName*/, int _bypassTokenType) : bypassTokenType(_bypassTokenType) { 13 | } 14 | 15 | RuleTagToken::RuleTagToken(const std::string &ruleName, size_t bypassTokenType, const std::string &label) 16 | : ruleName(ruleName), bypassTokenType(bypassTokenType), label(label) { 17 | if (ruleName.empty()) { 18 | throw IllegalArgumentException("ruleName cannot be null or empty."); 19 | } 20 | 21 | } 22 | 23 | std::string RuleTagToken::getRuleName() const { 24 | return ruleName; 25 | } 26 | 27 | std::string RuleTagToken::getLabel() const { 28 | return label; 29 | } 30 | 31 | size_t RuleTagToken::getChannel() const { 32 | return DEFAULT_CHANNEL; 33 | } 34 | 35 | std::string RuleTagToken::getText() const { 36 | if (label != "") { 37 | return std::string("<") + label + std::string(":") + ruleName + std::string(">"); 38 | } 39 | 40 | return std::string("<") + ruleName + std::string(">"); 41 | } 42 | 43 | size_t RuleTagToken::getType() const { 44 | return bypassTokenType; 45 | } 46 | 47 | size_t RuleTagToken::getLine() const { 48 | return 0; 49 | } 50 | 51 | size_t RuleTagToken::getCharPositionInLine() const { 52 | return INVALID_INDEX; 53 | } 54 | 55 | size_t RuleTagToken::getTokenIndex() const { 56 | return INVALID_INDEX; 57 | } 58 | 59 | size_t RuleTagToken::getStartIndex() const { 60 | return INVALID_INDEX; 61 | } 62 | 63 | size_t RuleTagToken::getStopIndex() const { 64 | return INVALID_INDEX; 65 | } 66 | 67 | antlr4::TokenSource *RuleTagToken::getTokenSource() const { 68 | return nullptr; 69 | } 70 | 71 | antlr4::CharStream *RuleTagToken::getInputStream() const { 72 | return nullptr; 73 | } 74 | 75 | std::string RuleTagToken::toString() const { 76 | return ruleName + ":" + std::to_string(bypassTokenType); 77 | } 78 | -------------------------------------------------------------------------------- /antlr/runtime/atn/LexerModeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code mode} lexer action by calling with 16 | /// the assigned mode. 17 | /// 18 | /// @author Sam Harwell 19 | /// @since 4.2 20 | /// 21 | class ANTLR4CPP_PUBLIC LexerModeAction final : public LexerAction { 22 | public: 23 | /// 24 | /// Constructs a new {@code mode} action with the specified mode value. 25 | /// The mode value to pass to . 26 | LexerModeAction(int mode); 27 | 28 | /// 29 | /// Get the lexer mode this action should transition the lexer to. 30 | /// 31 | /// The lexer mode for this {@code mode} command. 32 | int getMode(); 33 | 34 | /// 35 | /// {@inheritDoc} 36 | /// This method returns . 37 | virtual LexerActionType getActionType() const override; 38 | 39 | /// 40 | /// {@inheritDoc} 41 | /// This method returns {@code false}. 42 | virtual bool isPositionDependent() const override; 43 | 44 | /// 45 | /// {@inheritDoc} 46 | /// 47 | /// This action is implemented by calling with the 48 | /// value provided by . 49 | /// 50 | virtual void execute(Lexer *lexer) override; 51 | 52 | virtual size_t hashCode() const override; 53 | virtual bool operator == (const LexerAction &obj) const override; 54 | virtual std::string toString() const override; 55 | 56 | private: 57 | const int _mode; 58 | }; 59 | 60 | } // namespace atn 61 | } // namespace antlr4 62 | -------------------------------------------------------------------------------- /antlr/runtime/ProxyErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ProxyErrorListener.h" 7 | 8 | using namespace antlr4; 9 | 10 | void ProxyErrorListener::addErrorListener(ANTLRErrorListener *listener) { 11 | if (listener == nullptr) { 12 | throw "listener cannot be null."; 13 | } 14 | 15 | _delegates.insert(listener); 16 | } 17 | 18 | void ProxyErrorListener::removeErrorListener(ANTLRErrorListener *listener) { 19 | _delegates.erase(listener); 20 | } 21 | 22 | void ProxyErrorListener::removeErrorListeners() { 23 | _delegates.clear(); 24 | } 25 | 26 | void ProxyErrorListener::syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, 27 | size_t charPositionInLine, const std::string &msg, std::exception_ptr e) { 28 | 29 | for (auto *listener : _delegates) { 30 | listener->syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e); 31 | } 32 | } 33 | 34 | void ProxyErrorListener::reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 35 | bool exact, const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) { 36 | for (auto *listener : _delegates) { 37 | listener->reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs); 38 | } 39 | } 40 | 41 | void ProxyErrorListener::reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, 42 | size_t stopIndex, const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) { 43 | for (auto *listener : _delegates) { 44 | listener->reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs); 45 | } 46 | } 47 | 48 | void ProxyErrorListener::reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 49 | size_t prediction, atn::ATNConfigSet *configs) { 50 | for (auto *listener : _delegates) { 51 | listener->reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /antlr/runtime/tree/pattern/ParseTreeMatch.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/ParseTreeMatch.h" 9 | 10 | using namespace antlr4::tree; 11 | using namespace antlr4::tree::pattern; 12 | 13 | ParseTreeMatch::ParseTreeMatch(ParseTree *tree, const ParseTreePattern &pattern, 14 | const std::map> &labels, 15 | ParseTree *mismatchedNode) 16 | : _tree(tree), _pattern(pattern), _labels(labels), _mismatchedNode(mismatchedNode) { 17 | if (tree == nullptr) { 18 | throw IllegalArgumentException("tree cannot be nul"); 19 | } 20 | } 21 | 22 | ParseTreeMatch::~ParseTreeMatch() { 23 | } 24 | 25 | ParseTree* ParseTreeMatch::get(const std::string &label) { 26 | auto iterator = _labels.find(label); 27 | if (iterator == _labels.end() || iterator->second.empty()) { 28 | return nullptr; 29 | } 30 | 31 | return iterator->second.back(); // return last if multiple 32 | } 33 | 34 | std::vector ParseTreeMatch::getAll(const std::string &label) { 35 | auto iterator = _labels.find(label); 36 | if (iterator == _labels.end()) { 37 | return {}; 38 | } 39 | 40 | return iterator->second; 41 | } 42 | 43 | std::map>& ParseTreeMatch::getLabels() { 44 | return _labels; 45 | } 46 | 47 | ParseTree *ParseTreeMatch::getMismatchedNode() { 48 | return _mismatchedNode; 49 | } 50 | 51 | bool ParseTreeMatch::succeeded() { 52 | return _mismatchedNode == nullptr; 53 | } 54 | 55 | const ParseTreePattern& ParseTreeMatch::getPattern() { 56 | return _pattern; 57 | } 58 | 59 | ParseTree * ParseTreeMatch::getTree() { 60 | return _tree; 61 | } 62 | 63 | std::string ParseTreeMatch::toString() { 64 | if (succeeded()) { 65 | return "Match succeeded; found " + std::to_string(_labels.size()) + " labels"; 66 | } else { 67 | return "Match failed; found " + std::to_string(_labels.size()) + " labels"; 68 | } 69 | } 70 | --------------------------------------------------------------------------------