├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── common ├── CMakeLists.txt ├── antlr │ ├── CMakeLists.txt │ ├── grammar │ │ ├── Dotenv.g4 │ │ ├── Line.g4 │ │ └── Makefile │ └── parser │ │ ├── CMakeLists.txt │ │ ├── dotenv │ │ ├── CMakeLists.txt │ │ ├── Dotenv.interp │ │ ├── Dotenv.tokens │ │ ├── DotenvBaseListener.cpp │ │ ├── DotenvBaseListener.h │ │ ├── DotenvLexer.cpp │ │ ├── DotenvLexer.h │ │ ├── DotenvLexer.interp │ │ ├── DotenvLexer.tokens │ │ ├── DotenvListener.cpp │ │ ├── DotenvListener.h │ │ ├── DotenvParser.cpp │ │ └── DotenvParser.h │ │ └── line │ │ ├── CMakeLists.txt │ │ ├── Line.interp │ │ ├── Line.tokens │ │ ├── LineBaseListener.cpp │ │ ├── LineBaseListener.h │ │ ├── LineLexer.cpp │ │ ├── LineLexer.h │ │ ├── LineLexer.interp │ │ ├── LineLexer.tokens │ │ ├── LineListener.cpp │ │ ├── LineListener.h │ │ ├── LineParser.cpp │ │ └── LineParser.h └── libs │ ├── CMakeLists.txt │ └── antlr4-cpp-runtime │ ├── .gitignore │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ └── runtime │ ├── CMakeLists.txt │ └── src │ ├── ANTLRErrorListener.cpp │ ├── ANTLRErrorListener.h │ ├── ANTLRErrorStrategy.cpp │ ├── ANTLRErrorStrategy.h │ ├── ANTLRFileStream.cpp │ ├── ANTLRFileStream.h │ ├── ANTLRInputStream.cpp │ ├── ANTLRInputStream.h │ ├── BailErrorStrategy.cpp │ ├── BailErrorStrategy.h │ ├── BaseErrorListener.cpp │ ├── BaseErrorListener.h │ ├── BufferedTokenStream.cpp │ ├── BufferedTokenStream.h │ ├── CharStream.cpp │ ├── CharStream.h │ ├── CommonToken.cpp │ ├── CommonToken.h │ ├── CommonTokenFactory.cpp │ ├── CommonTokenFactory.h │ ├── CommonTokenStream.cpp │ ├── CommonTokenStream.h │ ├── ConsoleErrorListener.cpp │ ├── ConsoleErrorListener.h │ ├── DefaultErrorStrategy.cpp │ ├── DefaultErrorStrategy.h │ ├── DiagnosticErrorListener.cpp │ ├── DiagnosticErrorListener.h │ ├── Exceptions.cpp │ ├── Exceptions.h │ ├── FailedPredicateException.cpp │ ├── FailedPredicateException.h │ ├── InputMismatchException.cpp │ ├── InputMismatchException.h │ ├── IntStream.cpp │ ├── IntStream.h │ ├── InterpreterRuleContext.cpp │ ├── InterpreterRuleContext.h │ ├── Lexer.cpp │ ├── Lexer.h │ ├── LexerInterpreter.cpp │ ├── LexerInterpreter.h │ ├── LexerNoViableAltException.cpp │ ├── LexerNoViableAltException.h │ ├── ListTokenSource.cpp │ ├── ListTokenSource.h │ ├── NoViableAltException.cpp │ ├── NoViableAltException.h │ ├── Parser.cpp │ ├── Parser.h │ ├── ParserInterpreter.cpp │ ├── ParserInterpreter.h │ ├── ParserRuleContext.cpp │ ├── ParserRuleContext.h │ ├── ProxyErrorListener.cpp │ ├── ProxyErrorListener.h │ ├── RecognitionException.cpp │ ├── RecognitionException.h │ ├── Recognizer.cpp │ ├── Recognizer.h │ ├── RuleContext.cpp │ ├── RuleContext.h │ ├── RuleContextWithAltNum.cpp │ ├── RuleContextWithAltNum.h │ ├── RuntimeMetaData.cpp │ ├── RuntimeMetaData.h │ ├── Token.cpp │ ├── Token.h │ ├── TokenFactory.h │ ├── TokenSource.cpp │ ├── TokenSource.h │ ├── TokenStream.cpp │ ├── TokenStream.h │ ├── TokenStreamRewriter.cpp │ ├── TokenStreamRewriter.h │ ├── UnbufferedCharStream.cpp │ ├── UnbufferedCharStream.h │ ├── UnbufferedTokenStream.cpp │ ├── UnbufferedTokenStream.h │ ├── Vocabulary.cpp │ ├── Vocabulary.h │ ├── WritableToken.cpp │ ├── WritableToken.h │ ├── antlr4-common.h │ ├── antlr4-runtime.h │ ├── atn │ ├── ATN.cpp │ ├── ATN.h │ ├── ATNConfig.cpp │ ├── ATNConfig.h │ ├── ATNConfigSet.cpp │ ├── ATNConfigSet.h │ ├── ATNDeserializationOptions.cpp │ ├── ATNDeserializationOptions.h │ ├── ATNDeserializer.cpp │ ├── ATNDeserializer.h │ ├── ATNSerializer.cpp │ ├── ATNSerializer.h │ ├── ATNSimulator.cpp │ ├── ATNSimulator.h │ ├── ATNState.cpp │ ├── ATNState.h │ ├── ATNType.h │ ├── AbstractPredicateTransition.cpp │ ├── AbstractPredicateTransition.h │ ├── ActionTransition.cpp │ ├── ActionTransition.h │ ├── AmbiguityInfo.cpp │ ├── AmbiguityInfo.h │ ├── ArrayPredictionContext.cpp │ ├── ArrayPredictionContext.h │ ├── AtomTransition.cpp │ ├── AtomTransition.h │ ├── BasicBlockStartState.cpp │ ├── BasicBlockStartState.h │ ├── BasicState.cpp │ ├── BasicState.h │ ├── BlockEndState.cpp │ ├── BlockEndState.h │ ├── BlockStartState.cpp │ ├── BlockStartState.h │ ├── ContextSensitivityInfo.cpp │ ├── ContextSensitivityInfo.h │ ├── DecisionEventInfo.cpp │ ├── DecisionEventInfo.h │ ├── DecisionInfo.cpp │ ├── DecisionInfo.h │ ├── DecisionState.cpp │ ├── DecisionState.h │ ├── EmptyPredictionContext.cpp │ ├── EmptyPredictionContext.h │ ├── EpsilonTransition.cpp │ ├── EpsilonTransition.h │ ├── ErrorInfo.cpp │ ├── ErrorInfo.h │ ├── LL1Analyzer.cpp │ ├── LL1Analyzer.h │ ├── LexerATNConfig.cpp │ ├── LexerATNConfig.h │ ├── LexerATNSimulator.cpp │ ├── LexerATNSimulator.h │ ├── LexerAction.cpp │ ├── LexerAction.h │ ├── LexerActionExecutor.cpp │ ├── LexerActionExecutor.h │ ├── LexerActionType.h │ ├── LexerChannelAction.cpp │ ├── LexerChannelAction.h │ ├── LexerCustomAction.cpp │ ├── LexerCustomAction.h │ ├── LexerIndexedCustomAction.cpp │ ├── LexerIndexedCustomAction.h │ ├── LexerModeAction.cpp │ ├── LexerModeAction.h │ ├── LexerMoreAction.cpp │ ├── LexerMoreAction.h │ ├── LexerPopModeAction.cpp │ ├── LexerPopModeAction.h │ ├── LexerPushModeAction.cpp │ ├── LexerPushModeAction.h │ ├── LexerSkipAction.cpp │ ├── LexerSkipAction.h │ ├── LexerTypeAction.cpp │ ├── LexerTypeAction.h │ ├── LookaheadEventInfo.cpp │ ├── LookaheadEventInfo.h │ ├── LoopEndState.cpp │ ├── LoopEndState.h │ ├── Makefile │ ├── NotSetTransition.cpp │ ├── NotSetTransition.h │ ├── OrderedATNConfigSet.cpp │ ├── OrderedATNConfigSet.h │ ├── ParseInfo.cpp │ ├── ParseInfo.h │ ├── ParserATNSimulator.cpp │ ├── ParserATNSimulator.h │ ├── PlusBlockStartState.cpp │ ├── PlusBlockStartState.h │ ├── PlusLoopbackState.cpp │ ├── PlusLoopbackState.h │ ├── PrecedencePredicateTransition.cpp │ ├── PrecedencePredicateTransition.h │ ├── PredicateEvalInfo.cpp │ ├── PredicateEvalInfo.h │ ├── PredicateTransition.cpp │ ├── PredicateTransition.h │ ├── PredictionContext.cpp │ ├── PredictionContext.h │ ├── PredictionMode.cpp │ ├── PredictionMode.h │ ├── ProfilingATNSimulator.cpp │ ├── ProfilingATNSimulator.h │ ├── RangeTransition.cpp │ ├── RangeTransition.h │ ├── RuleStartState.cpp │ ├── RuleStartState.h │ ├── RuleStopState.cpp │ ├── RuleStopState.h │ ├── RuleTransition.cpp │ ├── RuleTransition.h │ ├── SemanticContext.cpp │ ├── SemanticContext.h │ ├── SetTransition.cpp │ ├── SetTransition.h │ ├── SingletonPredictionContext.cpp │ ├── SingletonPredictionContext.h │ ├── StarBlockStartState.cpp │ ├── StarBlockStartState.h │ ├── StarLoopEntryState.cpp │ ├── StarLoopEntryState.h │ ├── StarLoopbackState.cpp │ ├── StarLoopbackState.h │ ├── TokensStartState.cpp │ ├── TokensStartState.h │ ├── Transition.cpp │ ├── Transition.h │ ├── WildcardTransition.cpp │ └── WildcardTransition.h │ ├── dfa │ ├── DFA.cpp │ ├── DFA.h │ ├── DFASerializer.cpp │ ├── DFASerializer.h │ ├── DFAState.cpp │ ├── DFAState.h │ ├── LexerDFASerializer.cpp │ └── LexerDFASerializer.h │ ├── misc │ ├── InterpreterDataReader.cpp │ ├── InterpreterDataReader.h │ ├── Interval.cpp │ ├── Interval.h │ ├── IntervalSet.cpp │ ├── IntervalSet.h │ ├── MurmurHash.cpp │ ├── MurmurHash.h │ ├── Predicate.cpp │ └── Predicate.h │ ├── support │ ├── Any.cpp │ ├── Any.h │ ├── Arrays.cpp │ ├── Arrays.h │ ├── BitSet.h │ ├── CPPUtils.cpp │ ├── CPPUtils.h │ ├── Declarations.h │ ├── StringUtils.cpp │ ├── StringUtils.h │ ├── guid.cpp │ └── guid.h │ └── tree │ ├── AbstractParseTreeVisitor.h │ ├── ErrorNode.cpp │ ├── ErrorNode.h │ ├── ErrorNodeImpl.cpp │ ├── ErrorNodeImpl.h │ ├── IterativeParseTreeWalker.cpp │ ├── IterativeParseTreeWalker.h │ ├── ParseTree.cpp │ ├── ParseTree.h │ ├── ParseTreeListener.cpp │ ├── ParseTreeListener.h │ ├── ParseTreeProperty.h │ ├── ParseTreeVisitor.cpp │ ├── ParseTreeVisitor.h │ ├── ParseTreeWalker.cpp │ ├── ParseTreeWalker.h │ ├── TerminalNode.cpp │ ├── TerminalNode.h │ ├── TerminalNodeImpl.cpp │ ├── TerminalNodeImpl.h │ ├── Trees.cpp │ ├── Trees.h │ ├── pattern │ ├── Chunk.cpp │ ├── Chunk.h │ ├── ParseTreeMatch.cpp │ ├── ParseTreeMatch.h │ ├── ParseTreePattern.cpp │ ├── ParseTreePattern.h │ ├── ParseTreePatternMatcher.cpp │ ├── ParseTreePatternMatcher.h │ ├── RuleTagToken.cpp │ ├── RuleTagToken.h │ ├── TagChunk.cpp │ ├── TagChunk.h │ ├── TextChunk.cpp │ ├── TextChunk.h │ ├── TokenTagToken.cpp │ └── TokenTagToken.h │ └── xpath │ ├── XPath.cpp │ ├── XPath.h │ ├── XPathElement.cpp │ ├── XPathElement.h │ ├── XPathLexer.cpp │ ├── XPathLexer.g4 │ ├── XPathLexer.h │ ├── XPathLexer.tokens │ ├── XPathLexerErrorListener.cpp │ ├── XPathLexerErrorListener.h │ ├── XPathRuleAnywhereElement.cpp │ ├── XPathRuleAnywhereElement.h │ ├── XPathRuleElement.cpp │ ├── XPathRuleElement.h │ ├── XPathTokenAnywhereElement.cpp │ ├── XPathTokenAnywhereElement.h │ ├── XPathTokenElement.cpp │ ├── XPathTokenElement.h │ ├── XPathWildcardAnywhereElement.cpp │ ├── XPathWildcardAnywhereElement.h │ ├── XPathWildcardElement.cpp │ └── XPathWildcardElement.h ├── cpp-dotenv.png ├── include └── dotenv.h └── src ├── CMakeLists.txt ├── Parser.cpp ├── Parser.h ├── common ├── CMakeLists.txt ├── environ.cpp ├── environ.h ├── errors.cpp ├── errors.h ├── escape.cpp ├── escape.h ├── logger.cpp └── logger.h ├── dotenv.cpp ├── listeners ├── CMakeLists.txt ├── dotenv │ ├── CMakeLists.txt │ ├── CheckerListener.cpp │ ├── CheckerListener.h │ ├── SymbolsListener.cpp │ └── SymbolsListener.h └── line │ ├── CMakeLists.txt │ ├── ExpanderListener.cpp │ ├── ExpanderListener.h │ ├── ExternalResolverListener.cpp │ ├── ExternalResolverListener.h │ ├── LocalResolverListener.cpp │ ├── LocalResolverListener.h │ ├── ReferencesListener.cpp │ ├── ReferencesListener.h │ ├── UndefinedListener.cpp │ ├── UndefinedListener.h │ ├── UnresolvableListener.cpp │ └── UnresolvableListener.h └── structures ├── CMakeLists.txt ├── ReferencesTable.cpp ├── ReferencesTable.h ├── ReplaceStack.cpp ├── ReplaceStack.h ├── SymbolsTable.cpp ├── SymbolsTable.h ├── TreeDecorations.cpp └── TreeDecorations.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # ANTLR 35 | .antlr/ 36 | 37 | # Project specifics 38 | *.env 39 | 40 | # VSCode specifics 41 | .vscode/ 42 | 43 | # CMake specifics 44 | build/ 45 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #----------------------- PROJECT CONFIGURATION -------------------------------- 2 | cmake_minimum_required(VERSION 3.10) 3 | project(cpp-dotenv VERSION 1.0.0) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") 9 | set(CMAKE_BUILD_TYPE RELEASE) 10 | else() 11 | string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) 12 | endif() 13 | message(STATUS "Building CPP-DOTENV in ${CMAKE_BUILD_TYPE} mode") 14 | 15 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 16 | 17 | add_subdirectory(common) 18 | add_subdirectory(src) 19 | 20 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 21 | 22 | set(CPP_DOTENV cpp_dotenv CACHE INTERNAL "") 23 | set(CPP_DOTENV_SRC 24 | src/dotenv.cpp 25 | include/dotenv.h 26 | ) 27 | 28 | add_library(${CPP_DOTENV} ${CPP_DOTENV_SRC}) 29 | 30 | target_link_libraries(${CPP_DOTENV} 31 | ${ENVIRON_LIB} 32 | ${PARSER_LIB} 33 | ) 34 | 35 | target_include_directories(${CPP_DOTENV} PUBLIC 36 | ${CMAKE_CURRENT_SOURCE_DIR}/include 37 | ) 38 | 39 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 40 | target_compile_options(${CPP_DOTENV} PRIVATE 41 | -g -Wall -O0 42 | ) 43 | else() 44 | target_compile_options(${CPP_DOTENV} PRIVATE 45 | -O3 46 | ) 47 | endif() 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Alejandro de Haro 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 2 | 3 | add_subdirectory(libs) 4 | add_subdirectory(antlr) 5 | -------------------------------------------------------------------------------- /common/antlr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 2 | 3 | add_subdirectory(parser) 4 | -------------------------------------------------------------------------------- /common/antlr/grammar/Dotenv.g4: -------------------------------------------------------------------------------- 1 | grammar Dotenv; 2 | 3 | ////////////////// 4 | // Parser rules // 5 | ////////////////// 6 | 7 | dotenv 8 | : line (NL line)* EOF 9 | ; 10 | 11 | line 12 | : WS? pair WS? # lineContent 13 | | WS? # emptyLine 14 | ; 15 | 16 | pair 17 | : key WS? EQ WS? value 18 | ; 19 | 20 | key 21 | : (export_token=UNQUOTED_STRING WS)? key_unquoted=UNQUOTED_STRING 22 | | (export_token=UNQUOTED_STRING WS)? key_string=STRING 23 | ; 24 | 25 | value 26 | : UNQUOTED_STRING (WS UNQUOTED_STRING)* 27 | | STRING 28 | | 29 | ; 30 | 31 | ///////////////// 32 | // Lexer rules // 33 | ///////////////// 34 | 35 | EQ: '='; 36 | NL: '\r'? '\n'; 37 | WS: [ \t]+; 38 | 39 | COMMENT 40 | : '#' COMMENT_STRING? -> skip 41 | ; 42 | 43 | STRING 44 | : '\'' SINGLE_UNQUOTED_STRING '\'' 45 | | '"' DOUBLE_UNQUOTED_STRING '"' 46 | ; 47 | 48 | UNQUOTED_STRING: (ESC_SEQ | ~[#="' \t\r\n\\])+; 49 | 50 | fragment COMMENT_STRING: ~[\r\n]+; 51 | 52 | fragment SINGLE_UNQUOTED_STRING: (ESC_SEQ | ~['\\])*; 53 | fragment DOUBLE_UNQUOTED_STRING: (ESC_SEQ | ~["\\])*; 54 | 55 | fragment ESC_SEQ 56 | : '\\' ('\''|'"'|'='|'$'|'#'|'\\'|'a'|'b'|'f'|'n'|'r'|'t'|'v') 57 | | UNICODE_ESC 58 | | OCTAL_ESC 59 | ; 60 | fragment OCTAL_ESC 61 | : '\\' ('0'..'3') ('0'..'7') ('0'..'7') 62 | | '\\' ('0'..'7') ('0'..'7') 63 | | '\\' ('0'..'7') 64 | ; 65 | fragment UNICODE_ESC 66 | : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 67 | ; 68 | fragment HEX_DIGIT: ('0'..'9'|'a'..'f'|'A'..'F'); 69 | -------------------------------------------------------------------------------- /common/antlr/grammar/Line.g4: -------------------------------------------------------------------------------- 1 | grammar Line; 2 | 3 | ////////////////// 4 | // Parser rules // 5 | ////////////////// 6 | 7 | line 8 | : content? EOF 9 | ; 10 | 11 | content 12 | : (STRING_CHAR | ESC_SEQ | variable)+ 13 | ; 14 | 15 | variable 16 | : BOUNDED_VARIABLE 17 | | UNBOUNDED_VARIABLE 18 | ; 19 | 20 | ///////////////// 21 | // Lexer rules // 22 | ///////////////// 23 | 24 | ESC_SEQ 25 | : '\\' ('\''|'"'|'='|'$'|'#'|'\\'|'a'|'b'|'f'|'n'|'r'|'t'|'v') 26 | | UNICODE_ESC 27 | | OCTAL_ESC 28 | ; 29 | 30 | BOUNDED_VARIABLE: '$' '{' UNBOUNDED_STRING '}'; 31 | UNBOUNDED_VARIABLE: '$' LIMITED_UNBOUNDED_STRING; 32 | 33 | STRING_CHAR: .; 34 | 35 | fragment UNICODE_ESC 36 | : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 37 | ; 38 | fragment OCTAL_ESC 39 | : '\\' ('0'..'3') ('0'..'7') ('0'..'7') 40 | | '\\' ('0'..'7') ('0'..'7') 41 | | '\\' ('0'..'7') 42 | ; 43 | fragment UNBOUNDED_STRING: ~[{}]+; 44 | fragment LIMITED_UNBOUNDED_STRING: ('_' | LETTER) ('_' | LETTER | DIGIT)*; 45 | fragment LETTER: 'a'..'z' | 'A'..'Z'; 46 | fragment DIGIT: '0'..'9'; 47 | fragment HEX_DIGIT: ('0'..'9'|'a'..'f'|'A'..'F'); 48 | -------------------------------------------------------------------------------- /common/antlr/parser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 2 | 3 | add_subdirectory(dotenv) 4 | add_subdirectory(line) 5 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 2 | 3 | set(DOTENV_GENERATED_LIB dotenv_generated CACHE INTERNAL "") 4 | set(DOTENV_GENERATED_SRC 5 | DotenvBaseListener.cpp 6 | DotenvBaseListener.h 7 | DotenvLexer.cpp 8 | DotenvLexer.h 9 | DotenvListener.cpp 10 | DotenvListener.h 11 | DotenvParser.cpp 12 | DotenvParser.h 13 | ) 14 | 15 | add_library(${DOTENV_GENERATED_LIB} ${DOTENV_GENERATED_SRC}) 16 | 17 | target_link_libraries(${DOTENV_GENERATED_LIB} 18 | ${ANTLR4_CPP_RUNTIME} 19 | ) 20 | 21 | target_include_directories(${DOTENV_GENERATED_LIB} PUBLIC 22 | ${CMAKE_CURRENT_SOURCE_DIR} 23 | ) 24 | 25 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 26 | target_compile_options(${DOTENV_GENERATED_LIB} PRIVATE 27 | -g -Wall -O0 28 | ) 29 | else() 30 | target_compile_options(${DOTENV_GENERATED_LIB} PRIVATE 31 | -w -O3 32 | ) 33 | endif() 34 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/Dotenv.tokens: -------------------------------------------------------------------------------- 1 | EQ=1 2 | NL=2 3 | WS=3 4 | COMMENT=4 5 | STRING=5 6 | UNQUOTED_STRING=6 7 | '='=1 8 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/DotenvBaseListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Dotenv.g4 by ANTLR 4.8 3 | 4 | 5 | #include "DotenvBaseListener.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/DotenvBaseListener.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Dotenv.g4 by ANTLR 4.8 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | #include "DotenvListener.h" 9 | 10 | 11 | /** 12 | * This class provides an empty implementation of DotenvListener, 13 | * which can be extended to create a listener which only needs to handle a subset 14 | * of the available methods. 15 | */ 16 | class DotenvBaseListener : public DotenvListener { 17 | public: 18 | 19 | virtual void enterDotenv(DotenvParser::DotenvContext * /*ctx*/) override { } 20 | virtual void exitDotenv(DotenvParser::DotenvContext * /*ctx*/) override { } 21 | 22 | virtual void enterLineContent(DotenvParser::LineContentContext * /*ctx*/) override { } 23 | virtual void exitLineContent(DotenvParser::LineContentContext * /*ctx*/) override { } 24 | 25 | virtual void enterEmptyLine(DotenvParser::EmptyLineContext * /*ctx*/) override { } 26 | virtual void exitEmptyLine(DotenvParser::EmptyLineContext * /*ctx*/) override { } 27 | 28 | virtual void enterPair(DotenvParser::PairContext * /*ctx*/) override { } 29 | virtual void exitPair(DotenvParser::PairContext * /*ctx*/) override { } 30 | 31 | virtual void enterKey(DotenvParser::KeyContext * /*ctx*/) override { } 32 | virtual void exitKey(DotenvParser::KeyContext * /*ctx*/) override { } 33 | 34 | virtual void enterValue(DotenvParser::ValueContext * /*ctx*/) override { } 35 | virtual void exitValue(DotenvParser::ValueContext * /*ctx*/) override { } 36 | 37 | 38 | virtual void enterEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { } 39 | virtual void exitEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { } 40 | virtual void visitTerminal(antlr4::tree::TerminalNode * /*node*/) override { } 41 | virtual void visitErrorNode(antlr4::tree::ErrorNode * /*node*/) override { } 42 | 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/DotenvLexer.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Dotenv.g4 by ANTLR 4.8 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | 9 | 10 | 11 | 12 | class DotenvLexer : public antlr4::Lexer { 13 | public: 14 | enum { 15 | EQ = 1, NL = 2, WS = 3, COMMENT = 4, STRING = 5, UNQUOTED_STRING = 6 16 | }; 17 | 18 | DotenvLexer(antlr4::CharStream *input); 19 | ~DotenvLexer(); 20 | 21 | virtual std::string getGrammarFileName() const override; 22 | virtual const std::vector& getRuleNames() const override; 23 | 24 | virtual const std::vector& getChannelNames() const override; 25 | virtual const std::vector& getModeNames() const override; 26 | virtual const std::vector& getTokenNames() const override; // deprecated, use vocabulary instead 27 | virtual antlr4::dfa::Vocabulary& getVocabulary() const override; 28 | 29 | virtual const std::vector getSerializedATN() const override; 30 | virtual const antlr4::atn::ATN& getATN() const override; 31 | 32 | private: 33 | static std::vector _decisionToDFA; 34 | static antlr4::atn::PredictionContextCache _sharedContextCache; 35 | static std::vector _ruleNames; 36 | static std::vector _tokenNames; 37 | static std::vector _channelNames; 38 | static std::vector _modeNames; 39 | 40 | static std::vector _literalNames; 41 | static std::vector _symbolicNames; 42 | static antlr4::dfa::Vocabulary _vocabulary; 43 | static antlr4::atn::ATN _atn; 44 | static std::vector _serializedATN; 45 | 46 | 47 | // Individual action functions triggered by action() above. 48 | 49 | // Individual semantic predicate functions triggered by sempred() above. 50 | 51 | struct Initializer { 52 | Initializer(); 53 | }; 54 | static Initializer _init; 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/DotenvLexer.tokens: -------------------------------------------------------------------------------- 1 | EQ=1 2 | NL=2 3 | WS=3 4 | COMMENT=4 5 | STRING=5 6 | UNQUOTED_STRING=6 7 | '='=1 8 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/DotenvListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Dotenv.g4 by ANTLR 4.8 3 | 4 | 5 | #include "DotenvListener.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /common/antlr/parser/dotenv/DotenvListener.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Dotenv.g4 by ANTLR 4.8 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | #include "DotenvParser.h" 9 | 10 | 11 | /** 12 | * This interface defines an abstract listener for a parse tree produced by DotenvParser. 13 | */ 14 | class DotenvListener : public antlr4::tree::ParseTreeListener { 15 | public: 16 | 17 | virtual void enterDotenv(DotenvParser::DotenvContext *ctx) = 0; 18 | virtual void exitDotenv(DotenvParser::DotenvContext *ctx) = 0; 19 | 20 | virtual void enterLineContent(DotenvParser::LineContentContext *ctx) = 0; 21 | virtual void exitLineContent(DotenvParser::LineContentContext *ctx) = 0; 22 | 23 | virtual void enterEmptyLine(DotenvParser::EmptyLineContext *ctx) = 0; 24 | virtual void exitEmptyLine(DotenvParser::EmptyLineContext *ctx) = 0; 25 | 26 | virtual void enterPair(DotenvParser::PairContext *ctx) = 0; 27 | virtual void exitPair(DotenvParser::PairContext *ctx) = 0; 28 | 29 | virtual void enterKey(DotenvParser::KeyContext *ctx) = 0; 30 | virtual void exitKey(DotenvParser::KeyContext *ctx) = 0; 31 | 32 | virtual void enterValue(DotenvParser::ValueContext *ctx) = 0; 33 | virtual void exitValue(DotenvParser::ValueContext *ctx) = 0; 34 | 35 | 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /common/antlr/parser/line/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 2 | 3 | set(LINE_GENERATED_LIB line_generated CACHE INTERNAL "") 4 | set(LINE_GENERATED_SRC 5 | LineBaseListener.cpp 6 | LineBaseListener.h 7 | LineLexer.cpp 8 | LineLexer.h 9 | LineListener.cpp 10 | LineListener.h 11 | LineParser.cpp 12 | LineParser.h 13 | ) 14 | 15 | add_library(${LINE_GENERATED_LIB} ${LINE_GENERATED_SRC}) 16 | 17 | target_link_libraries(${LINE_GENERATED_LIB} 18 | ${ANTLR4_CPP_RUNTIME} 19 | ) 20 | 21 | target_include_directories(${LINE_GENERATED_LIB} PUBLIC 22 | ${CMAKE_CURRENT_SOURCE_DIR} 23 | ) 24 | 25 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 26 | target_compile_options(${LINE_GENERATED_LIB} PRIVATE 27 | -g -Wall -O0 28 | ) 29 | else() 30 | target_compile_options(${LINE_GENERATED_LIB} PRIVATE 31 | -w -O3 32 | ) 33 | endif() 34 | -------------------------------------------------------------------------------- /common/antlr/parser/line/Line.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | null 4 | null 5 | null 6 | null 7 | 8 | token symbolic names: 9 | null 10 | ESC_SEQ 11 | BOUNDED_VARIABLE 12 | UNBOUNDED_VARIABLE 13 | STRING_CHAR 14 | 15 | rule names: 16 | line 17 | content 18 | variable 19 | 20 | 21 | atn: 22 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 6, 23, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 5, 2, 10, 10, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 6, 3, 17, 10, 3, 13, 3, 14, 3, 18, 3, 4, 3, 4, 3, 4, 2, 2, 5, 2, 4, 6, 2, 3, 3, 2, 4, 5, 2, 23, 2, 9, 3, 2, 2, 2, 4, 16, 3, 2, 2, 2, 6, 20, 3, 2, 2, 2, 8, 10, 5, 4, 3, 2, 9, 8, 3, 2, 2, 2, 9, 10, 3, 2, 2, 2, 10, 11, 3, 2, 2, 2, 11, 12, 7, 2, 2, 3, 12, 3, 3, 2, 2, 2, 13, 17, 7, 6, 2, 2, 14, 17, 7, 3, 2, 2, 15, 17, 5, 6, 4, 2, 16, 13, 3, 2, 2, 2, 16, 14, 3, 2, 2, 2, 16, 15, 3, 2, 2, 2, 17, 18, 3, 2, 2, 2, 18, 16, 3, 2, 2, 2, 18, 19, 3, 2, 2, 2, 19, 5, 3, 2, 2, 2, 20, 21, 9, 2, 2, 2, 21, 7, 3, 2, 2, 2, 5, 9, 16, 18] -------------------------------------------------------------------------------- /common/antlr/parser/line/Line.tokens: -------------------------------------------------------------------------------- 1 | ESC_SEQ=1 2 | BOUNDED_VARIABLE=2 3 | UNBOUNDED_VARIABLE=3 4 | STRING_CHAR=4 5 | -------------------------------------------------------------------------------- /common/antlr/parser/line/LineBaseListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Line.g4 by ANTLR 4.8 3 | 4 | 5 | #include "LineBaseListener.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /common/antlr/parser/line/LineBaseListener.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Line.g4 by ANTLR 4.8 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | #include "LineListener.h" 9 | 10 | 11 | /** 12 | * This class provides an empty implementation of LineListener, 13 | * which can be extended to create a listener which only needs to handle a subset 14 | * of the available methods. 15 | */ 16 | class LineBaseListener : public LineListener { 17 | public: 18 | 19 | virtual void enterLine(LineParser::LineContext * /*ctx*/) override { } 20 | virtual void exitLine(LineParser::LineContext * /*ctx*/) override { } 21 | 22 | virtual void enterContent(LineParser::ContentContext * /*ctx*/) override { } 23 | virtual void exitContent(LineParser::ContentContext * /*ctx*/) override { } 24 | 25 | virtual void enterVariable(LineParser::VariableContext * /*ctx*/) override { } 26 | virtual void exitVariable(LineParser::VariableContext * /*ctx*/) override { } 27 | 28 | 29 | virtual void enterEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { } 30 | virtual void exitEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { } 31 | virtual void visitTerminal(antlr4::tree::TerminalNode * /*node*/) override { } 32 | virtual void visitErrorNode(antlr4::tree::ErrorNode * /*node*/) override { } 33 | 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /common/antlr/parser/line/LineLexer.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Line.g4 by ANTLR 4.8 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | 9 | 10 | 11 | 12 | class LineLexer : public antlr4::Lexer { 13 | public: 14 | enum { 15 | ESC_SEQ = 1, BOUNDED_VARIABLE = 2, UNBOUNDED_VARIABLE = 3, STRING_CHAR = 4 16 | }; 17 | 18 | LineLexer(antlr4::CharStream *input); 19 | ~LineLexer(); 20 | 21 | virtual std::string getGrammarFileName() const override; 22 | virtual const std::vector& getRuleNames() const override; 23 | 24 | virtual const std::vector& getChannelNames() const override; 25 | virtual const std::vector& getModeNames() const override; 26 | virtual const std::vector& getTokenNames() const override; // deprecated, use vocabulary instead 27 | virtual antlr4::dfa::Vocabulary& getVocabulary() const override; 28 | 29 | virtual const std::vector getSerializedATN() const override; 30 | virtual const antlr4::atn::ATN& getATN() const override; 31 | 32 | private: 33 | static std::vector _decisionToDFA; 34 | static antlr4::atn::PredictionContextCache _sharedContextCache; 35 | static std::vector _ruleNames; 36 | static std::vector _tokenNames; 37 | static std::vector _channelNames; 38 | static std::vector _modeNames; 39 | 40 | static std::vector _literalNames; 41 | static std::vector _symbolicNames; 42 | static antlr4::dfa::Vocabulary _vocabulary; 43 | static antlr4::atn::ATN _atn; 44 | static std::vector _serializedATN; 45 | 46 | 47 | // Individual action functions triggered by action() above. 48 | 49 | // Individual semantic predicate functions triggered by sempred() above. 50 | 51 | struct Initializer { 52 | Initializer(); 53 | }; 54 | static Initializer _init; 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /common/antlr/parser/line/LineLexer.tokens: -------------------------------------------------------------------------------- 1 | ESC_SEQ=1 2 | BOUNDED_VARIABLE=2 3 | UNBOUNDED_VARIABLE=3 4 | STRING_CHAR=4 5 | -------------------------------------------------------------------------------- /common/antlr/parser/line/LineListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Line.g4 by ANTLR 4.8 3 | 4 | 5 | #include "LineListener.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /common/antlr/parser/line/LineListener.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from Line.g4 by ANTLR 4.8 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | #include "LineParser.h" 9 | 10 | 11 | /** 12 | * This interface defines an abstract listener for a parse tree produced by LineParser. 13 | */ 14 | class LineListener : public antlr4::tree::ParseTreeListener { 15 | public: 16 | 17 | virtual void enterLine(LineParser::LineContext *ctx) = 0; 18 | virtual void exitLine(LineParser::LineContext *ctx) = 0; 19 | 20 | virtual void enterContent(LineParser::ContentContext *ctx) = 0; 21 | virtual void exitContent(LineParser::ContentContext *ctx) = 0; 22 | 23 | virtual void enterVariable(LineParser::VariableContext *ctx) = 0; 24 | virtual void exitVariable(LineParser::VariableContext *ctx) = 0; 25 | 26 | 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /common/libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 2 | 3 | add_subdirectory(antlr4-cpp-runtime) 4 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # VSCode specifics 35 | .vscode/ 36 | 37 | # CMake specifics 38 | build/ 39 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.2) 2 | project(antlr4-cpp-runtime VERSION 4.8) 3 | 4 | set(CMAKE_CXX_STANDARD 11) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | 7 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") 8 | set(CMAKE_BUILD_TYPE RELEASE) 9 | else() 10 | string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) 11 | endif() 12 | message(STATUS "Building ANTLR4-CPP-RUNTIME in ${CMAKE_BUILD_TYPE} mode") 13 | 14 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 15 | 16 | add_subdirectory(runtime) 17 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 Ref> CommonTokenFactory::DEFAULT = std::make_shared(); 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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 (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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | std::wstring_convert> converter; 24 | std::string narrow = converter.to_bytes(wstr); 25 | 26 | return narrow; 27 | } 28 | 29 | std::wstring s2ws(const std::string &str) { 30 | std::wstring_convert> converter; 31 | std::wstring wide = converter.from_bytes(str); 32 | 33 | return wide; 34 | } 35 | 36 | } // namespace antrlcpp 37 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/tree/ParseTreeWalker.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 | class ANTLR4CPP_PUBLIC ParseTreeWalker { 14 | public: 15 | static ParseTreeWalker &DEFAULT; 16 | 17 | virtual ~ParseTreeWalker(); 18 | 19 | virtual void walk(ParseTreeListener *listener, ParseTree *t) const; 20 | 21 | protected: 22 | /// The discovery of a rule node, involves sending two events: the generic 23 | /// and a 24 | /// -specific event. First we trigger the generic and then 25 | /// the rule specific. We do them in reverse order upon finishing the node. 26 | virtual void enterRule(ParseTreeListener *listener, ParseTree *r) const; 27 | virtual void exitRule(ParseTreeListener *listener, ParseTree *r) const; 28 | }; 29 | 30 | } // namespace tree 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /common/libs/antlr4-cpp-runtime/runtime/src/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 | -------------------------------------------------------------------------------- /cpp-dotenv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adeharo9/cpp-dotenv/8ed6f82dd5fdd437f6c2820b37ef88103b4e8360/cpp-dotenv.png -------------------------------------------------------------------------------- /include/dotenv.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | 6 | 7 | namespace dotenv 8 | { 9 | class dotenv 10 | { 11 | public: 12 | 13 | using key_type = std::string; 14 | using value_type = std::string; 15 | 16 | public: 17 | 18 | dotenv& load_dotenv(const std::string& dotenv_path = env_filename, 19 | const bool overwrite = false, 20 | const bool interpolate = true); 21 | 22 | const value_type operator[](const key_type& k) const; 23 | 24 | public: 25 | 26 | virtual ~dotenv() = default; 27 | dotenv(const dotenv&) = delete; 28 | void operator=(const dotenv&) = delete; 29 | 30 | static dotenv& instance(); 31 | 32 | private: 33 | 34 | dotenv() = default; 35 | 36 | private: 37 | 38 | static const std::string env_filename; 39 | static dotenv _instance; 40 | 41 | }; 42 | 43 | 44 | extern dotenv& env; 45 | } 46 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 2 | 3 | add_subdirectory(common) 4 | add_subdirectory(structures) 5 | add_subdirectory(listeners) 6 | 7 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 8 | 9 | set(PARSER_LIB parser CACHE INTERNAL "") 10 | set(PARSER_SRC 11 | Parser.cpp 12 | Parser.h 13 | ) 14 | 15 | add_library(${PARSER_LIB} ${PARSER_SRC}) 16 | 17 | target_link_libraries(${PARSER_LIB} 18 | ${ANTLR4_CPP_RUNTIME} 19 | ${DOTENV_GENERATED_LIB} 20 | ${DOTENV_LISTENERS_LIB} 21 | ${ENVIRON_LIB} 22 | ${ERRORS_LIB} 23 | ${LINE_GENERATED_LIB} 24 | ${LINE_LISTENERS_LIB} 25 | ${STRUCTURES_LIB} 26 | ) 27 | 28 | target_include_directories(${PARSER_LIB} PUBLIC 29 | ${CMAKE_CURRENT_SOURCE_DIR} 30 | ) 31 | 32 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 33 | target_compile_options(${PARSER_LIB} PRIVATE 34 | -g -Wall -O0 35 | ) 36 | else() 37 | target_compile_options(${PARSER_LIB} PRIVATE 38 | -O3 39 | ) 40 | endif() 41 | -------------------------------------------------------------------------------- /src/Parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReferencesTable.h" 5 | #include "SymbolsTable.h" 6 | 7 | #include "antlr4-runtime.h" 8 | 9 | #include 10 | #include 11 | 12 | 13 | namespace dotenv 14 | { 15 | class Parser 16 | { 17 | public: 18 | 19 | Parser(); 20 | Parser(const Parser& parser) = default; 21 | virtual ~Parser() = default; 22 | 23 | void parse(std::istream& is, const bool overwrite = false, const bool interpolate = true); 24 | 25 | private: 26 | 27 | void parse_dotenv(std::istream& is, const bool overwrite); 28 | void parse_line(); 29 | void resolve_vars(); 30 | void expand_escape(); 31 | void register_env(const bool interpolate) const; 32 | 33 | void resolve_local_vars(); 34 | void resolve_external_vars(); 35 | void resolve_undefined_vars(); 36 | void resolve_unresolvable_vars(); 37 | 38 | void report_undefined_vars(); 39 | void report_unresolvable_vars(); 40 | 41 | void walk_line(const std::string& line, antlr4::tree::ParseTreeListener& listener); 42 | 43 | private: 44 | 45 | size_t unresolved; 46 | ReferencesTable references_table; 47 | SymbolsTable symbols_table; 48 | 49 | antlr4::tree::ParseTreeWalker walker; 50 | 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /src/common/environ.cpp: -------------------------------------------------------------------------------- 1 | #include "environ.h" 2 | 3 | 4 | #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || defined(WIN32) 5 | #define OS_WIN 6 | #endif 7 | 8 | 9 | using namespace std; 10 | using namespace dotenv; 11 | 12 | 13 | #ifdef OS_WIN 14 | int setenv(const char *name, const char *value, int overwrite) 15 | { 16 | int errcode = 0; 17 | 18 | if (overwrite == 0) 19 | { 20 | size_t envsize = 0; 21 | errcode = getenv_s(&envsize, nullptr, 0, name); 22 | 23 | if (errcode != 0 or envsize != 0) 24 | { 25 | return errcode; 26 | } 27 | } 28 | 29 | return _putenv_s(name, value); 30 | } 31 | #endif 32 | 33 | 34 | pair dotenv::getenv(const string& name) 35 | { 36 | const char* value = ::getenv(name.c_str()); 37 | const bool success = value != nullptr; 38 | 39 | if (not success) 40 | { 41 | value = ""; 42 | } 43 | 44 | return {success, value}; 45 | } 46 | 47 | 48 | int dotenv::setenv(const string& name, const string& value, bool overwrite) 49 | { 50 | return ::setenv(name.c_str(), value.c_str(), overwrite ? 1 : 0); 51 | } 52 | 53 | 54 | #undef OS_WIN 55 | -------------------------------------------------------------------------------- /src/common/environ.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* This header file provides access to all the environment-handling 4 | * functions through the cstdlib header. 5 | * 6 | * In case they don't exist for a specific system, it declares and 7 | * defines them with the standard specification for the existing systems 8 | * for the sake of portability. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || defined(WIN32) 17 | #define OS_WIN 18 | #endif 19 | 20 | 21 | #ifdef OS_WIN 22 | int setenv(const char *name, const char *value, int overwrite); 23 | #endif 24 | 25 | 26 | namespace dotenv 27 | { 28 | std::pair getenv(const std::string& name); 29 | 30 | int setenv(const std::string& name, const std::string& value, bool overwrite); 31 | } 32 | 33 | 34 | #undef OS_WIN 35 | -------------------------------------------------------------------------------- /src/common/errors.cpp: -------------------------------------------------------------------------------- 1 | #include "errors.h" 2 | 3 | 4 | using namespace antlr4; 5 | using namespace dotenv; 6 | using namespace std; 7 | 8 | 9 | void errors::extraneous_input_error(Token* token, const vector& expected) 10 | { 11 | size_t line = token->getLine(); 12 | size_t pos = token->getCharPositionInLine(); 13 | string msg = "line " + to_string(line) + ":" + to_string(pos) + " extraneous input '" + token->getText() + "'"; 14 | 15 | if (not expected.empty()) 16 | { 17 | msg += " expecting {"; 18 | for (const string& s: expected) 19 | { 20 | msg += s; 21 | msg += ", "; 22 | } 23 | msg.erase(msg.size() - 2, 2); 24 | msg += "}"; 25 | } 26 | 27 | _log.error(msg, line, pos); 28 | } 29 | 30 | 31 | void errors::undefined_reference_error(const string& reference, const size_t line, const size_t pos) 32 | { 33 | string msg = "line " + to_string(line) + ":" + to_string(pos) + " undefined reference to '" + reference + "'"; 34 | 35 | _log.warn(msg, line, pos); 36 | } 37 | 38 | 39 | void errors::circular_reference_error(const string& reference, const size_t line, const size_t pos) 40 | { 41 | string msg = "line " + to_string(line) + ":" + to_string(pos) + " unresolvable reference to '" + reference + "'"; 42 | 43 | _log.error(msg, line, pos); 44 | } 45 | 46 | 47 | void errors::flush() 48 | { 49 | _log.flush(); 50 | } 51 | 52 | 53 | void errors::clear() 54 | { 55 | _log.clear(); 56 | } 57 | 58 | 59 | logger errors::_log; 60 | -------------------------------------------------------------------------------- /src/common/errors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "logger.h" 5 | 6 | #include "antlr4-runtime.h" 7 | 8 | #include 9 | #include 10 | 11 | 12 | namespace dotenv 13 | { 14 | class errors 15 | { 16 | public: 17 | 18 | static void extraneous_input_error(antlr4::Token* token, const std::vector& expected = {}); 19 | static void undefined_reference_error(const std::string& reference, const size_t line, const size_t pos); 20 | static void circular_reference_error(const std::string& reference, const size_t line, const size_t pos); 21 | 22 | static void flush(); 23 | static void clear(); 24 | 25 | private: 26 | 27 | static logger _log; 28 | 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /src/common/escape.cpp: -------------------------------------------------------------------------------- 1 | #include "escape.h" 2 | 3 | 4 | using namespace dotenv; 5 | using namespace std; 6 | 7 | 8 | pair escape::encode_escape(const char sequence) 9 | { 10 | return escape::encode_escape(string(1, sequence)); 11 | } 12 | 13 | 14 | pair escape::encode_escape(const std::string& sequence) 15 | { 16 | bool success = ENC_ESC_EQ.find(sequence) != ENC_ESC_EQ.end(); 17 | string encoded; 18 | 19 | if (success) 20 | { 21 | encoded = ENC_ESC_EQ.at(sequence); 22 | } 23 | 24 | return {success, encoded}; 25 | } 26 | 27 | 28 | pair escape::decode_escape(const std::string& sequence) 29 | { 30 | bool success = DEC_ESC_EQ.find(sequence) != DEC_ESC_EQ.end(); 31 | string decoded; 32 | 33 | if (success) 34 | { 35 | decoded = DEC_ESC_EQ.at(sequence); 36 | } 37 | 38 | return {success, decoded}; 39 | } 40 | 41 | 42 | const unordered_map escape::ENC_ESC_EQ 43 | { 44 | { "'" , "\\'" }, 45 | { "\"", "\\\""}, 46 | { "=" , "\\=" }, 47 | { "$" , "\\$" }, 48 | { "#" , "\\#" }, 49 | { "\\", "\\\\"}, 50 | { "\a", "\\a" }, 51 | { "\b", "\\b" }, 52 | { "\f", "\\f" }, 53 | { "\n", "\\n" }, 54 | { "\r", "\\r" }, 55 | { "\t", "\\t" }, 56 | { "\v", "\\v" } 57 | }; 58 | 59 | 60 | const unordered_map escape::DEC_ESC_EQ 61 | { 62 | { "\\'" , "'" }, 63 | { "\\\"", "\"" }, 64 | { "\\=" , "=" }, 65 | { "\\$" , "$" }, 66 | { "\\#" , "#" }, 67 | { "\\\\", "\\" }, 68 | { "\\a" , "\a" }, 69 | { "\\b" , "\b" }, 70 | { "\\f" , "\f" }, 71 | { "\\n" , "\n" }, 72 | { "\\r" , "\r" }, 73 | { "\\t" , "\t" }, 74 | { "\\v" , "\v" } 75 | }; 76 | -------------------------------------------------------------------------------- /src/common/escape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | namespace dotenv 10 | { 11 | class escape 12 | { 13 | public: 14 | 15 | static std::pair encode_escape(const char sequence); 16 | static std::pair encode_escape(const std::string& sequence); 17 | static std::pair decode_escape(const std::string& sequence); 18 | 19 | private: 20 | 21 | static const std::unordered_map ENC_ESC_EQ; 22 | static const std::unordered_map DEC_ESC_EQ; 23 | 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /src/dotenv.cpp: -------------------------------------------------------------------------------- 1 | #include "dotenv.h" 2 | 3 | #include "environ.h" 4 | #include "Parser.h" 5 | 6 | #include 7 | #include 8 | 9 | 10 | using namespace std; 11 | using namespace dotenv; 12 | 13 | 14 | dotenv::dotenv& dotenv::dotenv::load_dotenv(const string& dotenv_path, const bool overwrite, const bool interpolate) 15 | { 16 | ifstream env_file; 17 | env_file.open(dotenv_path); 18 | 19 | if (env_file.good()) 20 | { 21 | Parser parser; 22 | parser.parse(env_file, overwrite, interpolate); 23 | env_file.close(); 24 | } 25 | 26 | return *this; 27 | } 28 | 29 | 30 | const dotenv::dotenv::value_type dotenv::dotenv::operator[](const key_type& k) const 31 | { 32 | return getenv(k).second; 33 | } 34 | 35 | 36 | dotenv::dotenv& dotenv::dotenv::instance() 37 | { 38 | return _instance; 39 | } 40 | 41 | 42 | const string dotenv::dotenv::env_filename = ".env"; 43 | dotenv::dotenv dotenv::dotenv::_instance; 44 | 45 | dotenv::dotenv& dotenv::env = dotenv::instance(); 46 | -------------------------------------------------------------------------------- /src/listeners/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------- SUBDIRECTORY ADDITION ------------------------------------ 2 | 3 | add_subdirectory(dotenv) 4 | add_subdirectory(line) 5 | -------------------------------------------------------------------------------- /src/listeners/dotenv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 2 | 3 | set(DOTENV_LISTENERS_LIB dotenv_listeners CACHE INTERNAL "") 4 | set(DOTENV_LISTENERS_SRC 5 | CheckerListener.cpp 6 | CheckerListener.h 7 | SymbolsListener.cpp 8 | SymbolsListener.h 9 | ) 10 | 11 | add_library(${DOTENV_LISTENERS_LIB} ${DOTENV_LISTENERS_SRC}) 12 | 13 | target_link_libraries(${DOTENV_LISTENERS_LIB} 14 | ${DOTENV_GENERATED_LIB} 15 | ${ENVIRON_LIB} 16 | ${ERRORS_LIB} 17 | ${STRUCTURES_LIB} 18 | ) 19 | 20 | target_include_directories(${DOTENV_LISTENERS_LIB} PUBLIC 21 | ${CMAKE_CURRENT_SOURCE_DIR} 22 | ) 23 | 24 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 25 | target_compile_options(${DOTENV_LISTENERS_LIB} PRIVATE 26 | -g -Wall -O0 27 | ) 28 | else() 29 | target_compile_options(${DOTENV_LISTENERS_LIB} PRIVATE 30 | -O3 31 | ) 32 | endif() 33 | -------------------------------------------------------------------------------- /src/listeners/dotenv/CheckerListener.cpp: -------------------------------------------------------------------------------- 1 | #include "CheckerListener.h" 2 | 3 | #include "errors.h" 4 | 5 | 6 | using namespace dotenv; 7 | using namespace std; 8 | 9 | 10 | CheckerListener::CheckerListener(TreeDecorations& decorations): 11 | _errored(false), 12 | decorations(decorations) 13 | { 14 | 15 | } 16 | 17 | 18 | void CheckerListener::enterPair(DotenvParser::PairContext* ctx) 19 | { 20 | _errored = false; 21 | } 22 | 23 | 24 | void CheckerListener::exitPair(DotenvParser::PairContext* ctx) 25 | { 26 | decorations.put_errored(ctx, _errored); 27 | } 28 | 29 | 30 | void CheckerListener::exitKey(DotenvParser::KeyContext* ctx) 31 | { 32 | _errored = ctx->export_token != nullptr and ctx->export_token->getText() != EXPORT_TOKEN; 33 | 34 | if (_errored) 35 | { 36 | errors::extraneous_input_error(ctx->export_token, {EXPORT_TOKEN}); 37 | } 38 | 39 | decorations.put_errored(ctx, _errored); 40 | } 41 | 42 | 43 | void CheckerListener::exitValue(DotenvParser::ValueContext* ctx) 44 | { 45 | decorations.put_errored(ctx, _errored); 46 | } 47 | 48 | 49 | const string CheckerListener::EXPORT_TOKEN = "export"; 50 | -------------------------------------------------------------------------------- /src/listeners/dotenv/CheckerListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "TreeDecorations.h" 5 | #include "DotenvBaseListener.h" 6 | #include "DotenvParser.h" 7 | 8 | #include 9 | 10 | 11 | namespace dotenv 12 | { 13 | class CheckerListener final: public DotenvBaseListener 14 | { 15 | public: 16 | 17 | CheckerListener(TreeDecorations& decorations); 18 | CheckerListener(const CheckerListener& checker_listener) = default; 19 | virtual ~CheckerListener() = default; 20 | 21 | virtual void enterPair(DotenvParser::PairContext* ctx) override; 22 | virtual void exitPair(DotenvParser::PairContext* ctx) override; 23 | 24 | virtual void exitKey(DotenvParser::KeyContext* ctx) override; 25 | 26 | virtual void exitValue(DotenvParser::ValueContext* ctx) override; 27 | 28 | private: 29 | 30 | bool _errored; 31 | TreeDecorations& decorations; 32 | 33 | static const std::string EXPORT_TOKEN; 34 | 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /src/listeners/dotenv/SymbolsListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReferencesTable.h" 5 | #include "SymbolsTable.h" 6 | #include "TreeDecorations.h" 7 | #include "DotenvBaseListener.h" 8 | #include "DotenvParser.h" 9 | 10 | #include 11 | 12 | 13 | namespace dotenv 14 | { 15 | class SymbolsListener final: public DotenvBaseListener 16 | { 17 | public: 18 | 19 | SymbolsListener(const bool overwrite, SymbolsTable& symbols_table, TreeDecorations& decorations); 20 | SymbolsListener(const SymbolsListener& pairs_listener) = default; 21 | virtual ~SymbolsListener() = default; 22 | 23 | virtual void enterPair(DotenvParser::PairContext* ctx) override; 24 | virtual void exitPair(DotenvParser::PairContext* ctx) override; 25 | 26 | virtual void exitKey(DotenvParser::KeyContext* ctx) override; 27 | 28 | virtual void exitValue(DotenvParser::ValueContext* ctx) override; 29 | 30 | private: 31 | 32 | size_t _line; 33 | size_t _offset; 34 | std::string _key; 35 | std::string _value; 36 | 37 | bool overwrite; 38 | SymbolsTable& symbols_table; 39 | TreeDecorations& decorations; 40 | 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/listeners/line/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 2 | 3 | set(LINE_LISTENERS_LIB line_listeners CACHE INTERNAL "") 4 | set(LINE_LISTENERS_SRC 5 | ExpanderListener.cpp 6 | ExpanderListener.h 7 | ExternalResolverListener.cpp 8 | ExternalResolverListener.h 9 | ReferencesListener.cpp 10 | ReferencesListener.h 11 | LocalResolverListener.cpp 12 | LocalResolverListener.h 13 | UndefinedListener.cpp 14 | UndefinedListener.h 15 | UnresolvableListener.cpp 16 | UnresolvableListener.h 17 | ) 18 | 19 | add_library(${LINE_LISTENERS_LIB} ${LINE_LISTENERS_SRC}) 20 | 21 | target_link_libraries(${LINE_LISTENERS_LIB} 22 | ${ENVIRON_LIB} 23 | ${ERRORS_LIB} 24 | ${ESCAPE_LIB} 25 | ${LINE_GENERATED_LIB} 26 | ${STRUCTURES_LIB} 27 | ) 28 | 29 | target_include_directories(${LINE_LISTENERS_LIB} PUBLIC 30 | ${CMAKE_CURRENT_SOURCE_DIR} 31 | ) 32 | 33 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 34 | target_compile_options(${LINE_LISTENERS_LIB} PRIVATE 35 | -g -Wall -O0 36 | ) 37 | else() 38 | target_compile_options(${LINE_LISTENERS_LIB} PRIVATE 39 | -O3 40 | ) 41 | endif() 42 | -------------------------------------------------------------------------------- /src/listeners/line/ExpanderListener.cpp: -------------------------------------------------------------------------------- 1 | #include "ExpanderListener.h" 2 | 3 | #include "escape.h" 4 | 5 | 6 | using namespace antlr4; 7 | using namespace dotenv; 8 | using namespace std; 9 | 10 | 11 | ExpanderListener::ExpanderListener(const string& key, SymbolsTable& symbols_table): 12 | key(key), 13 | symbols_table(symbols_table) 14 | { 15 | 16 | } 17 | 18 | 19 | void ExpanderListener::enterLine(LineParser::LineContext* ctx) 20 | { 21 | // Clear the stack in case the listener is reused 22 | expand_stack.clear(); 23 | } 24 | 25 | 26 | void ExpanderListener::exitLine(LineParser::LineContext* ctx) 27 | { 28 | // At this point all the expand operations have been registered 29 | expand_stack.run(); 30 | } 31 | 32 | 33 | void ExpanderListener::exitContent(LineParser::ContentContext* ctx) 34 | { 35 | for (tree::TerminalNode* ESC_SEQ: ctx->ESC_SEQ()) 36 | { 37 | string sequence = ESC_SEQ->getText(); 38 | size_t pos = ESC_SEQ->getSymbol()->getCharPositionInLine(); 39 | size_t size = sequence.size(); 40 | 41 | pair expanded = escape::decode_escape(sequence); 42 | 43 | if (expanded.first) 44 | { 45 | SymbolRecord& record = symbols_table.at(key); 46 | expand_stack.emplace(record.value(), expanded.second, pos, size); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/listeners/line/ExpanderListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReplaceStack.h" 5 | #include "SymbolsTable.h" 6 | #include "LineBaseListener.h" 7 | #include "LineParser.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | namespace dotenv 15 | { 16 | class ExpanderListener final: public LineBaseListener 17 | { 18 | public: 19 | 20 | ExpanderListener(const std::string& key, SymbolsTable& symbols_table); 21 | ExpanderListener(const ExpanderListener& expander_listener) = default; 22 | virtual ~ExpanderListener() = default; 23 | 24 | virtual void enterLine(LineParser::LineContext* ctx) override; 25 | virtual void exitLine(LineParser::LineContext* ctx) override; 26 | 27 | virtual void exitContent(LineParser::ContentContext* ctx) override; 28 | 29 | private: 30 | 31 | const std::string& key; 32 | SymbolsTable& symbols_table; 33 | ReplaceStack expand_stack; 34 | 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /src/listeners/line/ExternalResolverListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReplaceStack.h" 5 | #include "SymbolsTable.h" 6 | #include "LineBaseListener.h" 7 | #include "LineParser.h" 8 | 9 | #include 10 | 11 | 12 | namespace dotenv 13 | { 14 | class ExternalResolverListener final: public LineBaseListener 15 | { 16 | public: 17 | 18 | ExternalResolverListener(const std::string& key, SymbolsTable& symbols_table); 19 | ExternalResolverListener(const ExternalResolverListener& resovler_listener) = default; 20 | virtual ~ExternalResolverListener() = default; 21 | 22 | virtual void enterLine(LineParser::LineContext* ctx) override; 23 | virtual void exitLine(LineParser::LineContext* ctx) override; 24 | 25 | virtual void exitVariable(LineParser::VariableContext* ctx) override; 26 | 27 | private: 28 | 29 | const std::string& key; 30 | SymbolsTable& symbols_table; 31 | ReplaceStack resolve_stack; 32 | 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/listeners/line/LocalResolverListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReplaceStack.h" 5 | #include "SymbolsTable.h" 6 | #include "LineBaseListener.h" 7 | #include "LineParser.h" 8 | 9 | #include 10 | 11 | 12 | namespace dotenv 13 | { 14 | class LocalResolverListener final: public LineBaseListener 15 | { 16 | public: 17 | 18 | LocalResolverListener(const std::string& key, SymbolsTable& symbols_table); 19 | LocalResolverListener(const LocalResolverListener& resovler_listener) = default; 20 | virtual ~LocalResolverListener() = default; 21 | 22 | virtual void enterLine(LineParser::LineContext* ctx) override; 23 | virtual void exitLine(LineParser::LineContext* ctx) override; 24 | 25 | virtual void exitVariable(LineParser::VariableContext* ctx) override; 26 | 27 | private: 28 | 29 | const std::string& key; 30 | SymbolsTable& symbols_table; 31 | ReplaceStack resolve_stack; 32 | 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/listeners/line/ReferencesListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReferencesTable.h" 5 | #include "SymbolsTable.h" 6 | #include "LineBaseListener.h" 7 | #include "LineParser.h" 8 | 9 | #include 10 | 11 | 12 | namespace dotenv 13 | { 14 | class ReferencesListener final: public LineBaseListener 15 | { 16 | public: 17 | 18 | ReferencesListener(const std::string& key, ReferencesTable& references_table, SymbolsTable& symbols_table); 19 | ReferencesListener(const ReferencesListener& symbols_listener) = default; 20 | virtual ~ReferencesListener() = default; 21 | 22 | virtual void exitVariable(LineParser::VariableContext* ctx) override; 23 | 24 | private: 25 | 26 | static std::string encode_string(const std::string& decoded); 27 | 28 | private: 29 | 30 | const std::string& key; 31 | ReferencesTable& references_table; 32 | SymbolsTable& symbols_table; 33 | 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /src/listeners/line/UndefinedListener.cpp: -------------------------------------------------------------------------------- 1 | #include "UndefinedListener.h" 2 | 3 | 4 | using namespace dotenv; 5 | using namespace std; 6 | 7 | 8 | UndefinedListener::UndefinedListener(const string& key, SymbolsTable& symbols_table): 9 | key(key), 10 | symbols_table(symbols_table) 11 | { 12 | 13 | } 14 | 15 | 16 | void UndefinedListener::enterLine(LineParser::LineContext* ctx) 17 | { 18 | // Clear the stack in case the listener is reused 19 | resolve_stack.clear(); 20 | } 21 | 22 | 23 | void UndefinedListener::exitLine(LineParser::LineContext* ctx) 24 | { 25 | // At this point all the resolve operations have been registered 26 | resolve_stack.run(); 27 | } 28 | 29 | 30 | void UndefinedListener::exitVariable(LineParser::VariableContext* ctx) 31 | { 32 | string var_name = ctx->getText(); 33 | size_t pos = ctx->getStart()->getCharPositionInLine(); 34 | size_t size = var_name.size(); 35 | 36 | // Format variable name 37 | if (ctx->BOUNDED_VARIABLE() != nullptr) 38 | { 39 | var_name = var_name.substr(2, var_name.size() - 3); 40 | } 41 | else if (ctx->UNBOUNDED_VARIABLE() != nullptr) 42 | { 43 | var_name = var_name.substr(1, var_name.size() - 1); 44 | } 45 | 46 | SymbolRecord& var = symbols_table.at(var_name); 47 | 48 | // If there is more than one substitution operation, they must be performed 49 | // from end to beginning so position and size indices are maintained 50 | // constant throughout the different operations 51 | if (not var.local() and not var.complete()) 52 | { 53 | SymbolRecord& record = symbols_table.at(key); 54 | resolve_stack.emplace(record.value(), "", pos, size); 55 | record.dependency_resolve_one(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/listeners/line/UndefinedListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReplaceStack.h" 5 | #include "SymbolsTable.h" 6 | #include "LineBaseListener.h" 7 | #include "LineParser.h" 8 | 9 | #include 10 | 11 | 12 | namespace dotenv 13 | { 14 | class UndefinedListener final: public LineBaseListener 15 | { 16 | public: 17 | 18 | UndefinedListener(const std::string& key, SymbolsTable& symbols_table); 19 | UndefinedListener(const UndefinedListener& undefined_listener) = default; 20 | virtual ~UndefinedListener() = default; 21 | 22 | virtual void enterLine(LineParser::LineContext* ctx) override; 23 | virtual void exitLine(LineParser::LineContext* ctx) override; 24 | 25 | virtual void exitVariable(LineParser::VariableContext* ctx) override; 26 | 27 | private: 28 | 29 | const std::string& key; 30 | SymbolsTable& symbols_table; 31 | ReplaceStack resolve_stack; 32 | 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/listeners/line/UnresolvableListener.cpp: -------------------------------------------------------------------------------- 1 | #include "UnresolvableListener.h" 2 | 3 | 4 | using namespace dotenv; 5 | using namespace std; 6 | 7 | 8 | UnresolvableListener::UnresolvableListener(const string& key, SymbolsTable& symbols_table): 9 | key(key), 10 | symbols_table(symbols_table) 11 | { 12 | 13 | } 14 | 15 | 16 | void UnresolvableListener::enterLine(LineParser::LineContext* ctx) 17 | { 18 | // Clear the stack in case the listener is reused 19 | resolve_stack.clear(); 20 | } 21 | 22 | 23 | void UnresolvableListener::exitLine(LineParser::LineContext* ctx) 24 | { 25 | // At this point all the resolve operations have been registered 26 | resolve_stack.run(); 27 | } 28 | 29 | 30 | void UnresolvableListener::exitVariable(LineParser::VariableContext* ctx) 31 | { 32 | string var_name = ctx->getText(); 33 | size_t pos = ctx->getStart()->getCharPositionInLine(); 34 | size_t size = var_name.size(); 35 | 36 | // Format variable name 37 | if (ctx->BOUNDED_VARIABLE() != nullptr) 38 | { 39 | var_name = var_name.substr(2, var_name.size() - 3); 40 | } 41 | else if (ctx->UNBOUNDED_VARIABLE() != nullptr) 42 | { 43 | var_name = var_name.substr(1, var_name.size() - 1); 44 | } 45 | 46 | SymbolRecord& var = symbols_table.at(var_name); 47 | 48 | // If there is more than one substitution operation, they must be performed 49 | // from end to beginning so position and size indices are maintained 50 | // constant throughout the different operations 51 | // Do not mark variables as solved at this point since that would mess with 52 | // the resolution system by making it think that they are not unresolvable 53 | if (var.local() and not var.complete()) 54 | { 55 | SymbolRecord& record = symbols_table.at(key); 56 | resolve_stack.emplace(record.value(), "", pos, size); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/listeners/line/UnresolvableListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ReplaceStack.h" 5 | #include "SymbolsTable.h" 6 | #include "LineBaseListener.h" 7 | #include "LineParser.h" 8 | 9 | #include 10 | 11 | 12 | namespace dotenv 13 | { 14 | class UnresolvableListener final: public LineBaseListener 15 | { 16 | public: 17 | 18 | UnresolvableListener(const std::string& key, SymbolsTable& symbols_table); 19 | UnresolvableListener(const UnresolvableListener& unresolvable_listener) = default; 20 | virtual ~UnresolvableListener() = default; 21 | 22 | virtual void enterLine(LineParser::LineContext* ctx) override; 23 | virtual void exitLine(LineParser::LineContext* ctx) override; 24 | 25 | virtual void exitVariable(LineParser::VariableContext* ctx) override; 26 | 27 | private: 28 | 29 | const std::string& key; 30 | SymbolsTable& symbols_table; 31 | ReplaceStack resolve_stack; 32 | 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/structures/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #----------------------- LIBRARY CONFIGURATION -------------------------------- 2 | 3 | set(STRUCTURES_LIB structures CACHE INTERNAL "") 4 | set(STRUCTURES_SRC 5 | ReferencesTable.cpp 6 | ReferencesTable.h 7 | ReplaceStack.cpp 8 | ReplaceStack.h 9 | SymbolsTable.cpp 10 | SymbolsTable.h 11 | TreeDecorations.cpp 12 | TreeDecorations.h 13 | ) 14 | 15 | add_library(${STRUCTURES_LIB} ${STRUCTURES_SRC}) 16 | 17 | target_link_libraries(${STRUCTURES_LIB} 18 | ${ANTLR4_CPP_RUNTIME} 19 | ) 20 | 21 | target_include_directories(${STRUCTURES_LIB} PUBLIC 22 | ${CMAKE_CURRENT_SOURCE_DIR} 23 | ) 24 | 25 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") 26 | target_compile_options(${STRUCTURES_LIB} PRIVATE 27 | -g -Wall -O0 28 | ) 29 | else() 30 | target_compile_options(${STRUCTURES_LIB} PRIVATE 31 | -O3 32 | ) 33 | endif() 34 | -------------------------------------------------------------------------------- /src/structures/ReferencesTable.cpp: -------------------------------------------------------------------------------- 1 | #include "ReferencesTable.h" 2 | 3 | 4 | using namespace dotenv; 5 | 6 | 7 | ReferenceRecord::ReferenceRecord(const size_t line, const size_t pos): 8 | _line(line), 9 | _pos(pos) 10 | { 11 | 12 | } 13 | 14 | 15 | size_t ReferenceRecord::line() const 16 | { 17 | return _line; 18 | } 19 | 20 | 21 | size_t ReferenceRecord::pos() const 22 | { 23 | return _pos; 24 | } 25 | -------------------------------------------------------------------------------- /src/structures/ReferencesTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include 6 | 7 | 8 | namespace dotenv 9 | { 10 | class ReferenceRecord 11 | { 12 | public: 13 | 14 | ReferenceRecord(const size_t line, 15 | const size_t pos); 16 | ReferenceRecord(const ReferenceRecord& reference_record) = default; 17 | virtual ~ReferenceRecord() = default; 18 | 19 | size_t line() const; 20 | size_t pos() const; 21 | 22 | private: 23 | 24 | size_t _line; 25 | size_t _pos; 26 | 27 | }; 28 | 29 | 30 | class ReferencesTable: public std::unordered_multimap 31 | { 32 | 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/structures/ReplaceStack.cpp: -------------------------------------------------------------------------------- 1 | #include "ReplaceStack.h" 2 | 3 | 4 | using namespace dotenv; 5 | using namespace std; 6 | 7 | 8 | ReplaceOperation::ReplaceOperation(std::string& original, const string& replace, size_t pos, size_t size): 9 | original(original), 10 | replace(replace), 11 | pos(pos), 12 | size(size) 13 | { 14 | 15 | } 16 | 17 | 18 | void ReplaceOperation::run() 19 | { 20 | original.erase(pos, size).insert(pos, replace); 21 | } 22 | 23 | 24 | void ReplaceStack::clear() 25 | { 26 | while (not this->empty()) 27 | { 28 | this->pop(); 29 | } 30 | } 31 | 32 | 33 | void ReplaceStack::run() 34 | { 35 | while (not this->empty()) 36 | { 37 | ReplaceOperation& operation = this->top(); 38 | operation.run(); 39 | this->pop(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/structures/ReplaceStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include 6 | 7 | 8 | namespace dotenv 9 | { 10 | class ReplaceOperation 11 | { 12 | public: 13 | 14 | ReplaceOperation(std::string& original, const std::string& replace, size_t pos, size_t size); 15 | ReplaceOperation(const ReplaceOperation& replace_operation) = default; 16 | virtual ~ReplaceOperation() = default; 17 | 18 | void run(); 19 | 20 | private: 21 | 22 | std::string& original; 23 | const std::string replace; 24 | size_t pos; 25 | size_t size; 26 | }; 27 | 28 | class ReplaceStack: public std::stack 29 | { 30 | public: 31 | 32 | void clear(); 33 | void run(); 34 | 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /src/structures/SymbolsTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include 6 | 7 | 8 | namespace dotenv 9 | { 10 | class SymbolRecord 11 | { 12 | public: 13 | 14 | SymbolRecord(const bool declared = false, 15 | const bool defined = false, 16 | const size_t num_depends = 0, 17 | const bool local = true); 18 | SymbolRecord(const SymbolRecord& symbol_record) = default; 19 | ~SymbolRecord() = default; 20 | 21 | bool complete() const; 22 | 23 | bool declared() const; 24 | bool defined() const; 25 | bool resolved() const; 26 | bool local() const; 27 | size_t line() const; 28 | size_t offset() const; 29 | std::string& value(); 30 | const std::string& value() const; 31 | 32 | void set_declared(); 33 | void set_defined(); 34 | void set_line(const size_t line); 35 | void set_offset(const size_t offset); 36 | void set_value(const std::string& value); 37 | 38 | void dependency_add_one(); 39 | void dependency_resolve_one(); 40 | 41 | private: 42 | 43 | bool _declared; 44 | bool _defined; 45 | bool _local; 46 | 47 | size_t _line; 48 | size_t _offset; 49 | size_t _num_depends; 50 | std::string _value; 51 | 52 | }; 53 | 54 | 55 | class SymbolsTable: public std::unordered_map 56 | { 57 | 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/structures/TreeDecorations.cpp: -------------------------------------------------------------------------------- 1 | #include "TreeDecorations.h" 2 | 3 | 4 | using namespace dotenv; 5 | 6 | 7 | bool TreeDecorations::get_errored(antlr4::ParserRuleContext* ctx) 8 | { 9 | return _errored.get(ctx); 10 | } 11 | 12 | 13 | void TreeDecorations::put_errored(antlr4::ParserRuleContext* ctx, bool errored) 14 | { 15 | _errored.put(ctx, errored); 16 | } 17 | -------------------------------------------------------------------------------- /src/structures/TreeDecorations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "antlr4-runtime.h" 5 | 6 | 7 | namespace dotenv 8 | { 9 | class TreeDecorations 10 | { 11 | public: 12 | 13 | TreeDecorations() = default; 14 | TreeDecorations(const TreeDecorations& tree_decorations) = default; 15 | virtual ~TreeDecorations() = default; 16 | 17 | bool get_errored(antlr4::ParserRuleContext* ctx); 18 | void put_errored(antlr4::ParserRuleContext* ctx, bool errored); 19 | 20 | private: 21 | 22 | antlr4::tree::ParseTreeProperty _errored; 23 | 24 | }; 25 | } 26 | --------------------------------------------------------------------------------