├── .clang-format ├── .clang-tidy ├── .editorconfig ├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── Lua.g4 ├── README.md ├── SCsub ├── config.py ├── constants.h ├── debug.cpp ├── debug.h ├── doc_classes └── LuaScript.xml ├── editor ├── SCsub ├── luascript_editor_syntax_highlighter.cpp └── luascript_editor_syntax_highlighter.h ├── icons └── LuaScript.svg ├── lib ├── antlr4 │ ├── .gitignore │ ├── 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 │ ├── FlatHashMap.h │ ├── FlatHashSet.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 │ ├── SCsub │ ├── 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 │ ├── Version.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 │ │ ├── ATNSimulator.cpp │ │ ├── ATNSimulator.h │ │ ├── ATNState.cpp │ │ ├── ATNState.h │ │ ├── ATNStateType.cpp │ │ ├── ATNStateType.h │ │ ├── ATNType.h │ │ ├── ActionTransition.cpp │ │ ├── ActionTransition.h │ │ ├── AmbiguityInfo.cpp │ │ ├── AmbiguityInfo.h │ │ ├── ArrayPredictionContext.cpp │ │ ├── ArrayPredictionContext.h │ │ ├── AtomTransition.cpp │ │ ├── AtomTransition.h │ │ ├── BasicBlockStartState.h │ │ ├── BasicState.h │ │ ├── BlockEndState.h │ │ ├── BlockStartState.h │ │ ├── ContextSensitivityInfo.cpp │ │ ├── ContextSensitivityInfo.h │ │ ├── DecisionEventInfo.cpp │ │ ├── DecisionEventInfo.h │ │ ├── DecisionInfo.cpp │ │ ├── DecisionInfo.h │ │ ├── DecisionState.cpp │ │ ├── DecisionState.h │ │ ├── EpsilonTransition.cpp │ │ ├── EpsilonTransition.h │ │ ├── ErrorInfo.cpp │ │ ├── ErrorInfo.h │ │ ├── HashUtils.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.h │ │ ├── NotSetTransition.cpp │ │ ├── NotSetTransition.h │ │ ├── OrderedATNConfigSet.cpp │ │ ├── OrderedATNConfigSet.h │ │ ├── ParseInfo.cpp │ │ ├── ParseInfo.h │ │ ├── ParserATNSimulator.cpp │ │ ├── ParserATNSimulator.h │ │ ├── ParserATNSimulatorOptions.h │ │ ├── PlusBlockStartState.h │ │ ├── PlusLoopbackState.h │ │ ├── PrecedencePredicateTransition.cpp │ │ ├── PrecedencePredicateTransition.h │ │ ├── PredicateEvalInfo.cpp │ │ ├── PredicateEvalInfo.h │ │ ├── PredicateTransition.cpp │ │ ├── PredicateTransition.h │ │ ├── PredictionContext.cpp │ │ ├── PredictionContext.h │ │ ├── PredictionContextCache.cpp │ │ ├── PredictionContextCache.h │ │ ├── PredictionContextMergeCache.cpp │ │ ├── PredictionContextMergeCache.h │ │ ├── PredictionContextMergeCacheOptions.h │ │ ├── PredictionContextType.h │ │ ├── PredictionMode.cpp │ │ ├── PredictionMode.h │ │ ├── ProfilingATNSimulator.cpp │ │ ├── ProfilingATNSimulator.h │ │ ├── RangeTransition.cpp │ │ ├── RangeTransition.h │ │ ├── RuleStartState.h │ │ ├── RuleStopState.h │ │ ├── RuleTransition.cpp │ │ ├── RuleTransition.h │ │ ├── SemanticContext.cpp │ │ ├── SemanticContext.h │ │ ├── SemanticContextType.h │ │ ├── SerializedATNView.h │ │ ├── SetTransition.cpp │ │ ├── SetTransition.h │ │ ├── SingletonPredictionContext.cpp │ │ ├── SingletonPredictionContext.h │ │ ├── StarBlockStartState.h │ │ ├── StarLoopEntryState.h │ │ ├── StarLoopbackState.cpp │ │ ├── StarLoopbackState.h │ │ ├── TokensStartState.h │ │ ├── Transition.cpp │ │ ├── Transition.h │ │ ├── TransitionType.cpp │ │ ├── TransitionType.h │ │ ├── WildcardTransition.cpp │ │ └── WildcardTransition.h │ ├── dfa │ │ ├── DFA.cpp │ │ ├── DFA.h │ │ ├── DFASerializer.cpp │ │ ├── DFASerializer.h │ │ ├── DFAState.cpp │ │ ├── DFAState.h │ │ ├── LexerDFASerializer.cpp │ │ └── LexerDFASerializer.h │ ├── internal │ │ ├── Synchronization.cpp │ │ └── Synchronization.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 │ │ ├── Casts.h │ │ ├── Declarations.h │ │ ├── StringUtils.cpp │ │ ├── StringUtils.h │ │ ├── Unicode.h │ │ ├── Utf8.cpp │ │ └── Utf8.h │ └── tree │ │ ├── AbstractParseTreeVisitor.h │ │ ├── ErrorNode.h │ │ ├── ErrorNodeImpl.cpp │ │ ├── ErrorNodeImpl.h │ │ ├── IterativeParseTreeWalker.cpp │ │ ├── IterativeParseTreeWalker.h │ │ ├── ParseTree.cpp │ │ ├── ParseTree.h │ │ ├── ParseTreeListener.cpp │ │ ├── ParseTreeListener.h │ │ ├── ParseTreeProperty.h │ │ ├── ParseTreeType.h │ │ ├── ParseTreeVisitor.cpp │ │ ├── ParseTreeVisitor.h │ │ ├── ParseTreeWalker.cpp │ │ ├── ParseTreeWalker.h │ │ ├── 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 └── lua │ ├── .gitignore │ ├── SCsub │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── ljumptab.h │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── lopnames.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.h │ ├── lua.hpp │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── lua_script.cpp ├── lua_script.h ├── lua_script_instance.cpp ├── lua_script_instance.h ├── lua_script_language.cpp ├── lua_script_language.h ├── lua_script_resource_formate_loader.cpp ├── lua_script_resource_formate_loader.h ├── lua_script_resource_formate_saver.cpp ├── lua_script_resource_formate_saver.h ├── parser ├── SCsub ├── ast │ ├── abstract_syntax_tree.cpp │ ├── abstract_syntax_tree.h │ ├── antlr_tree_walker.cpp │ ├── antlr_tree_walker.h │ └── tree_walker.h ├── generated │ ├── .clang-format │ ├── LuaBaseListener.cpp │ ├── LuaBaseListener.h │ ├── LuaLexer.cpp │ ├── LuaLexer.h │ ├── LuaListener.cpp │ ├── LuaListener.h │ ├── LuaParser.cpp │ └── LuaParser.h ├── parser.cpp └── parser.h ├── register_types.cpp └── register_types.h /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = tab 7 | insert_final_newline = true 8 | 9 | [*.{cpp,hpp,c,h,mm}] 10 | trim_trailing_whitespace = true 11 | 12 | [{*.gradle,AndroidManifest.xml}] 13 | indent_style = space 14 | indent_size = 4 15 | 16 | [{*.py,SConstruct,SCsub}] 17 | indent_style = space 18 | indent_size = 4 19 | 20 | # YAML requires indentation with spaces instead of tabs. 21 | [*.{yml,yaml}] 22 | indent_style = space 23 | indent_size = 2 24 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Properly detect languages on Github 2 | *.h linguist-language=cpp 3 | *.inc linguist-language=cpp 4 | thirdparty/* linguist-vendored 5 | 6 | # Normalize EOL for all files that Git considers text files 7 | * text=auto eol=lf 8 | # Except for bat files, which are Windows only files 9 | *.bat eol=crlf 10 | 11 | # The above only works properly for Git 2.10+, so for older versions 12 | # we need to manually list the binary files we don't want modified. 13 | *.icns binary 14 | *.ico binary 15 | *.jar binary 16 | *.png binary 17 | *.ttf binary 18 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: perbone 2 | -------------------------------------------------------------------------------- /SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | Import("env") 4 | Import('env_modules') 5 | 6 | env_luascript = env_modules.Clone() 7 | 8 | if env.msvc: 9 | env_luascript.Append(CCFLAGS=["/std:c++17","/Zc:__cplusplus"]) 10 | env_luascript.Append(CCFLAGS=["/Zi", "/FS"]) 11 | env_luascript.Append(LINKFLAGS=["/DEBUG:FULL"]) 12 | env_luascript.Append(CPPDEFINES=['ANTLR4CPP_STATIC']) 13 | elif env["platform"] == "macos": 14 | env_luascript.Append(ASFLAGS=["-mmacosx-version-min=10.13"]) 15 | env_luascript.Append(CCFLAGS=["-mmacosx-version-min=10.13"]) 16 | env_luascript.Append(LINKFLAGS=["-mmacosx-version-min=10.13"]) 17 | else: 18 | env_luascript['CXXFLAGS'] = ['-std=c++17'] 19 | 20 | Export('env_luascript') 21 | 22 | SConscript('lib/lua/SCsub') 23 | SConscript('lib/antlr4/SCsub') 24 | SConscript('parser/SCsub') 25 | if env.editor_build: 26 | SConscript('editor/SCsub') 27 | 28 | env_luascript.add_source_files(env.modules_sources,'*.cpp') 29 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | def is_enabled(): 2 | # The module is disabled by default. Use module_luascript_enabled=yes to enable it. 3 | return False 4 | 5 | def can_build(env, platform): 6 | return True 7 | 8 | def configure(env): 9 | pass 10 | 11 | def get_doc_classes(): 12 | return ["LuaScript"] 13 | 14 | def get_doc_path(): 15 | return "doc_classes" 16 | -------------------------------------------------------------------------------- /constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "core/string/ustring.h" 23 | 24 | const String EMPTY_STRING = ""; 25 | const String SCRIPT_TYPE = "Script"; 26 | const String LUA_NAME = "Lua"; 27 | const String LUA_SCRIPT_TYPE = "LuaScript"; 28 | const String LUA_EXTENSION = "lua"; 29 | const int LUA_PIL_IDENTATION_SIZE = 2; // Following PiL indenting often uses two spaces 30 | const String LUA_PIL_IDENTATION = " "; // Keep it in sync with LUA_PIL_IDENTATION_SIZE constant 31 | -------------------------------------------------------------------------------- /debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #ifdef DEBUG_ENABLED 23 | 24 | #include 25 | 26 | #include "core/string/ustring.h" 27 | 28 | std::string get_notification_name(const int constant_value); 29 | //void print_debug(const String fmt, ...); 30 | #define print_debug(fmt, ...) print_line(vformat(fmt, __VA_ARGS__)) 31 | 32 | #else 33 | 34 | #define print_debug(fmt, ...) 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /doc_classes/LuaScript.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Lua language script. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /editor/SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | Import('env') 4 | Import('env_luascript') 5 | 6 | env_editor = env_luascript.Clone() 7 | 8 | env_editor.add_source_files(env.modules_sources,'*.cpp') 9 | -------------------------------------------------------------------------------- /editor/luascript_editor_syntax_highlighter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #ifdef TOOLS_ENABLED 23 | 24 | #include "editor/plugins/script_editor_plugin.h" 25 | 26 | class LuaScriptEditorSyntaxHighlighter : public EditorSyntaxHighlighter { 27 | GDCLASS(LuaScriptEditorSyntaxHighlighter, EditorSyntaxHighlighter) 28 | 29 | public: 30 | LuaScriptEditorSyntaxHighlighter(); 31 | ~LuaScriptEditorSyntaxHighlighter(); 32 | 33 | // Overrides from SyntaxHighlighter 34 | Dictionary _get_line_syntax_highlighting_impl(int p_line) override; 35 | void _clear_highlighting_cache() override; 36 | void _update_cache() override; 37 | 38 | // Overrides from EditorSyntaxHighlighter 39 | String _get_name() const override; 40 | PackedStringArray _get_supported_languages() const override; 41 | Ref _create() const override; 42 | }; 43 | 44 | #endif // TOOLS_ENABLED 45 | -------------------------------------------------------------------------------- /lib/antlr4/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 "ANTLRFileStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | void ANTLRFileStream::loadFromFile(const std::string &fileName) { 11 | _fileName = fileName; 12 | if (_fileName.empty()) { 13 | return; 14 | } 15 | 16 | std::ifstream stream(fileName, std::ios::binary); 17 | 18 | ANTLRInputStream::load(stream); 19 | } 20 | 21 | std::string ANTLRFileStream::getSourceName() const { 22 | return _fileName; 23 | } 24 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 17 | ANTLRFileStream() = default; 18 | ANTLRFileStream(const std::string &) = delete; 19 | ANTLRFileStream(const char *data, size_t length) = delete; 20 | ANTLRFileStream(std::istream &stream) = delete; 21 | 22 | // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). 23 | virtual void loadFromFile(const std::string &fileName); 24 | virtual std::string getSourceName() const override; 25 | 26 | private: 27 | std::string _fileName; // UTF-8 encoded file name. 28 | }; 29 | 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/CommonTokenFactory.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "CommonToken.h" 8 | #include "CharStream.h" 9 | 10 | #include "CommonTokenFactory.h" 11 | 12 | using namespace antlr4; 13 | 14 | const std::unique_ptr> CommonTokenFactory::DEFAULT(new CommonTokenFactory); 15 | 16 | CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) { 17 | } 18 | 19 | CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) { 20 | } 21 | 22 | std::unique_ptr CommonTokenFactory::create(std::pair source, size_t type, 23 | const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) { 24 | 25 | std::unique_ptr t(new CommonToken(source, type, channel, start, stop)); 26 | t->setLine(line); 27 | t->setCharPositionInLine(charPositionInLine); 28 | if (text != "") { 29 | t->setText(text); 30 | } else if (copyText && source.second != nullptr) { 31 | t->setText(source.second->getText(misc::Interval(start, stop))); 32 | } 33 | 34 | return t; 35 | } 36 | 37 | std::unique_ptr CommonTokenFactory::create(size_t type, const std::string &text) { 38 | return std::unique_ptr(new CommonToken(type, text)); 39 | } 40 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | explicit 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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/LexerInterpreter.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 "Lexer.h" 9 | #include "atn/PredictionContext.h" 10 | #include "atn/PredictionContextCache.h" 11 | #include "Vocabulary.h" 12 | 13 | namespace antlr4 { 14 | 15 | class ANTLR4CPP_PUBLIC LexerInterpreter : public Lexer { 16 | public: 17 | LexerInterpreter(const std::string &grammarFileName, const dfa::Vocabulary &vocabulary, 18 | const std::vector &ruleNames, const std::vector &channelNames, 19 | const std::vector &modeNames, const atn::ATN &atn, CharStream *input); 20 | 21 | ~LexerInterpreter(); 22 | 23 | virtual const atn::ATN& getATN() const override; 24 | virtual std::string getGrammarFileName() const override; 25 | virtual const std::vector& getRuleNames() const override; 26 | virtual const std::vector& getChannelNames() const override; 27 | virtual const std::vector& getModeNames() const override; 28 | 29 | virtual const dfa::Vocabulary& getVocabulary() const override; 30 | 31 | protected: 32 | const std::string _grammarFileName; 33 | const atn::ATN &_atn; 34 | 35 | const std::vector &_ruleNames; 36 | const std::vector &_channelNames; 37 | const std::vector &_modeNames; 38 | std::vector _decisionToDFA; 39 | 40 | atn::PredictionContextCache _sharedContextCache; 41 | 42 | private: 43 | dfa::Vocabulary _vocabulary; 44 | }; 45 | 46 | } // namespace antlr4 47 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | Import('env') 4 | Import('env_luascript') 5 | 6 | env_antlr4 = env_luascript.Clone() 7 | 8 | env_antlr4.Append(CPPPATH=['.']) 9 | 10 | # Enable exceptions for ANTLR4 11 | if env_antlr4.msvc: 12 | env_antlr4.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 1)]) 13 | else: 14 | env_antlr4.Append(CCFLAGS=["-fexceptions"]) 15 | 16 | env_antlr4.add_source_files(env.modules_sources,'*.cpp') 17 | env_antlr4.add_source_files(env.modules_sources,'atn/*.cpp') 18 | env_antlr4.add_source_files(env.modules_sources,'dfa/*.cpp') 19 | env_antlr4.add_source_files(env.modules_sources,'internal/*.cpp') 20 | env_antlr4.add_source_files(env.modules_sources,'misc/*.cpp') 21 | env_antlr4.add_source_files(env.modules_sources,'support/*.cpp') 22 | env_antlr4.add_source_files(env.modules_sources,'tree/*.cpp') 23 | env_antlr4.add_source_files(env.modules_sources,'tree/pattern/*.cpp') 24 | env_antlr4.add_source_files(env.modules_sources,'tree/xpath/*.cpp') 25 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ATNDeserializationOptions.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNDeserializationOptions.h" 7 | #include "Exceptions.h" 8 | 9 | using namespace antlr4; 10 | using namespace antlr4::atn; 11 | 12 | ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options) 13 | : _readOnly(false), _verifyATN(options->_verifyATN), 14 | _generateRuleBypassTransitions(options->_generateRuleBypassTransitions) {} 15 | 16 | const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() { 17 | static const std::unique_ptr defaultOptions = std::make_unique(); 18 | return *defaultOptions; 19 | } 20 | 21 | void ATNDeserializationOptions::makeReadOnly() { 22 | _readOnly = true; 23 | } 24 | 25 | void ATNDeserializationOptions::setVerifyATN(bool verify) { 26 | throwIfReadOnly(); 27 | _verifyATN = verify; 28 | } 29 | 30 | void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) { 31 | throwIfReadOnly(); 32 | _generateRuleBypassTransitions = generate; 33 | } 34 | 35 | void ATNDeserializationOptions::throwIfReadOnly() const { 36 | if (isReadOnly()) { 37 | throw IllegalStateException("ATNDeserializationOptions is read only."); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/antlr4/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 final { 14 | public: 15 | ATNDeserializationOptions() 16 | : _readOnly(false), _verifyATN(true), _generateRuleBypassTransitions(false) {} 17 | 18 | // TODO: Is this useful? If so we should mark it as explicit, otherwise remove it. 19 | ATNDeserializationOptions(ATNDeserializationOptions *options); 20 | 21 | ATNDeserializationOptions(const ATNDeserializationOptions&) = default; 22 | 23 | ATNDeserializationOptions& operator=(const ATNDeserializationOptions&) = default; 24 | 25 | static const ATNDeserializationOptions& getDefaultOptions(); 26 | 27 | bool isReadOnly() const { return _readOnly; } 28 | 29 | void makeReadOnly(); 30 | 31 | bool isVerifyATN() const { return _verifyATN; } 32 | 33 | void setVerifyATN(bool verify); 34 | 35 | bool isGenerateRuleBypassTransitions() const { return _generateRuleBypassTransitions; } 36 | 37 | void setGenerateRuleBypassTransitions(bool generate); 38 | 39 | private: 40 | void throwIfReadOnly() const; 41 | 42 | bool _readOnly; 43 | bool _verifyATN; 44 | bool _generateRuleBypassTransitions; 45 | }; 46 | 47 | } // namespace atn 48 | } // namespace antlr4 49 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ATNDeserializer.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/ATNDeserializationOptions.h" 9 | #include "atn/SerializedATNView.h" 10 | #include "atn/LexerAction.h" 11 | #include "atn/Transition.h" 12 | 13 | namespace antlr4 { 14 | namespace atn { 15 | 16 | class ANTLR4CPP_PUBLIC ATNDeserializer final { 17 | public: 18 | static constexpr size_t SERIALIZED_VERSION = 4; 19 | 20 | ATNDeserializer(); 21 | 22 | explicit ATNDeserializer(ATNDeserializationOptions deserializationOptions); 23 | 24 | std::unique_ptr deserialize(SerializedATNView input) const; 25 | void verifyATN(const ATN &atn) const; 26 | 27 | private: 28 | const ATNDeserializationOptions _deserializationOptions; 29 | }; 30 | 31 | } // namespace atn 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ATNSimulator.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/ATNSimulator.h" 7 | 8 | #include "atn/ATNConfigSet.h" 9 | #include "atn/ATNDeserializer.h" 10 | #include "atn/ATNType.h" 11 | #include "dfa/DFAState.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::dfa; 15 | using namespace antlr4::atn; 16 | 17 | const Ref ATNSimulator::ERROR = std::make_shared(std::numeric_limits::max()); 18 | 19 | ATNSimulator::ATNSimulator(const ATN &atn, PredictionContextCache &sharedContextCache) 20 | : atn(atn), _sharedContextCache(sharedContextCache) {} 21 | 22 | void ATNSimulator::clearDFA() { 23 | throw UnsupportedOperationException("This ATN simulator does not support clearing the DFA."); 24 | } 25 | 26 | PredictionContextCache& ATNSimulator::getSharedContextCache() const { 27 | return _sharedContextCache; 28 | } 29 | 30 | Ref ATNSimulator::getCachedContext(const Ref &context) { 31 | // This function must only be called with an active state lock, as we are going to change a shared structure. 32 | return PredictionContext::getCachedContext(context, getSharedContextCache()); 33 | } 34 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ATNState.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 | #include "atn/Transition.h" 8 | #include "misc/IntervalSet.h" 9 | #include "support/CPPUtils.h" 10 | 11 | #include "atn/ATNState.h" 12 | 13 | using namespace antlr4::atn; 14 | using namespace antlrcpp; 15 | 16 | size_t ATNState::hashCode() const { 17 | return stateNumber; 18 | } 19 | 20 | bool ATNState::equals(const ATNState &other) const { 21 | return stateNumber == other.stateNumber; 22 | } 23 | 24 | bool ATNState::isNonGreedyExitState() const { 25 | return false; 26 | } 27 | 28 | std::string ATNState::toString() const { 29 | return std::to_string(stateNumber); 30 | } 31 | 32 | void ATNState::addTransition(ConstTransitionPtr e) { 33 | addTransition(transitions.size(), std::move(e)); 34 | } 35 | 36 | void ATNState::addTransition(size_t index, ConstTransitionPtr e) { 37 | for (const auto &transition : transitions) 38 | if (transition->target->stateNumber == e->target->stateNumber) { 39 | return; 40 | } 41 | 42 | if (transitions.empty()) { 43 | epsilonOnlyTransitions = e->isEpsilon(); 44 | } else if (epsilonOnlyTransitions != e->isEpsilon()) { 45 | std::cerr << "ATN state %d has both epsilon and non-epsilon transitions.\n" << stateNumber; 46 | epsilonOnlyTransitions = false; 47 | } 48 | 49 | transitions.insert(transitions.begin() + index, std::move(e)); 50 | } 51 | 52 | ConstTransitionPtr ATNState::removeTransition(size_t index) { 53 | ConstTransitionPtr result = std::move(transitions[index]); 54 | transitions.erase(transitions.begin() + index); 55 | return result; 56 | } 57 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ATNStateType.cpp: -------------------------------------------------------------------------------- 1 | #include "atn/ATNStateType.h" 2 | 3 | std::string antlr4::atn::atnStateTypeName(ATNStateType atnStateType) { 4 | switch (atnStateType) { 5 | case ATNStateType::INVALID: 6 | return "INVALID"; 7 | case ATNStateType::BASIC: 8 | return "BASIC"; 9 | case ATNStateType::RULE_START: 10 | return "RULE_START"; 11 | case ATNStateType::BLOCK_START: 12 | return "BLOCK_START"; 13 | case ATNStateType::PLUS_BLOCK_START: 14 | return "PLUS_BLOCK_START"; 15 | case ATNStateType::STAR_BLOCK_START: 16 | return "STAR_BLOCK_START"; 17 | case ATNStateType::TOKEN_START: 18 | return "TOKEN_START"; 19 | case ATNStateType::RULE_STOP: 20 | return "RULE_STOP"; 21 | case ATNStateType::BLOCK_END: 22 | return "BLOCK_END"; 23 | case ATNStateType::STAR_LOOP_BACK: 24 | return "STAR_LOOP_BACK"; 25 | case ATNStateType::STAR_LOOP_ENTRY: 26 | return "STAR_LOOP_ENTRY"; 27 | case ATNStateType::PLUS_LOOP_BACK: 28 | return "PLUS_LOOP_BACK"; 29 | case ATNStateType::LOOP_END: 30 | return "LOOP_END"; 31 | } 32 | return "UNKNOWN"; 33 | } 34 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ATNStateType.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 9 | #include 10 | 11 | #include "antlr4-common.h" 12 | 13 | namespace antlr4 { 14 | namespace atn { 15 | 16 | // Constants for ATNState serialization. 17 | enum class ATNStateType : size_t { 18 | INVALID = 0, 19 | BASIC = 1, 20 | RULE_START = 2, 21 | BLOCK_START = 3, 22 | PLUS_BLOCK_START = 4, 23 | STAR_BLOCK_START = 5, 24 | TOKEN_START = 6, 25 | RULE_STOP = 7, 26 | BLOCK_END = 8, 27 | STAR_LOOP_BACK = 9, 28 | STAR_LOOP_ENTRY = 10, 29 | PLUS_LOOP_BACK = 11, 30 | LOOP_END = 12, 31 | }; 32 | 33 | ANTLR4CPP_PUBLIC std::string atnStateTypeName(ATNStateType atnStateType); 34 | 35 | } // namespace atn 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType::ACTION, 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(TransitionType::ACTION, target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) { 16 | } 17 | 18 | bool ActionTransition::isEpsilon() const { 19 | return true; // we are to be ignored by analysis 'cept for predicates 20 | } 21 | 22 | bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 23 | return false; 24 | } 25 | 26 | std::string ActionTransition::toString() const { 27 | return " ACTION " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + ", actionIndex: " + 28 | std::to_string(actionIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 29 | } 30 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::ACTION; } 16 | 17 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 18 | 19 | const size_t ruleIndex; 20 | const size_t actionIndex; 21 | const bool isCtxDependent; // e.g., $i ref in action 22 | 23 | ActionTransition(ATNState *target, size_t ruleIndex); 24 | 25 | ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent); 26 | 27 | virtual bool isEpsilon() const override; 28 | 29 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 30 | 31 | virtual std::string toString() const override; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType::ATOM, target), _label(label) { 15 | } 16 | 17 | IntervalSet AtomTransition::label() const { 18 | return IntervalSet::of((int)_label); 19 | } 20 | 21 | bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 22 | return _label == symbol; 23 | } 24 | 25 | std::string AtomTransition::toString() const { 26 | return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }"; 27 | } 28 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::ATOM; } 17 | 18 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 19 | 20 | /// The token type or character value; or, signifies special label. 21 | /// TODO: rename this to label 22 | const size_t _label; 23 | 24 | AtomTransition(ATNState *target, size_t label); 25 | 26 | virtual misc::IntervalSet label() const override; 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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 16 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::BLOCK_START; } 17 | 18 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 19 | 20 | BasicBlockStartState() : BlockStartState(ATNStateType::BLOCK_START) {} 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 15 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::BASIC; } 16 | 17 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 18 | 19 | BasicState() : ATNState(ATNStateType::BASIC) {} 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::BLOCK_END; } 17 | 18 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 19 | 20 | BlockStartState *startState = nullptr; 21 | 22 | BlockEndState() : ATNState(ATNStateType::BLOCK_END) {} 23 | }; 24 | 25 | } // namespace atn 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { 17 | const auto stateType = atnState.getStateType(); 18 | return stateType >= ATNStateType::BLOCK_START && stateType <= ATNStateType::STAR_BLOCK_START; 19 | } 20 | 21 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 22 | 23 | BlockEndState *endState = nullptr; 24 | 25 | protected: 26 | using DecisionState::DecisionState; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | std::string DecisionState::toString() const { 11 | return ATNState::toString(); 12 | } 13 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { 16 | const auto stateType = atnState.getStateType(); 17 | return (stateType >= ATNStateType::BLOCK_START && stateType <= ATNStateType::TOKEN_START) || 18 | stateType == ATNStateType::PLUS_LOOP_BACK || 19 | stateType == ATNStateType::STAR_LOOP_ENTRY; 20 | } 21 | 22 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 23 | 24 | int decision = -1; 25 | bool nonGreedy = false; 26 | 27 | virtual std::string toString() const override; 28 | 29 | protected: 30 | using ATNState::ATNState; 31 | }; 32 | 33 | } // namespace atn 34 | } // namespace antlr4 35 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType::EPSILON, target), _outermostPrecedenceReturn(outermostPrecedenceReturn) { 15 | } 16 | 17 | size_t EpsilonTransition::outermostPrecedenceReturn() const { 18 | return _outermostPrecedenceReturn; 19 | } 20 | 21 | bool EpsilonTransition::isEpsilon() const { 22 | return true; 23 | } 24 | 25 | bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 26 | return false; 27 | } 28 | 29 | std::string EpsilonTransition::toString() const { 30 | return "EPSILON " + Transition::toString() + " {}"; 31 | } 32 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::EPSILON; } 16 | 17 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 18 | 19 | explicit EpsilonTransition(ATNState *target); 20 | EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn); 21 | 22 | /** 23 | * @return the rule index of a precedence rule for which this transition is 24 | * returning from, where the precedence value is 0; otherwise, INVALID_INDEX. 25 | * 26 | * @see ATNConfig#isPrecedenceFilterSuppressed() 27 | * @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet) 28 | * @since 4.4.1 29 | */ 30 | size_t outermostPrecedenceReturn() const; 31 | 32 | virtual bool isEpsilon() const override; 33 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 34 | 35 | virtual std::string toString() const override; 36 | 37 | private: 38 | const size_t _outermostPrecedenceReturn; // A rule index. 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/atn/ErrorInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// This class represents profiling event information for a syntax error 15 | /// identified during prediction. Syntax errors occur when the prediction 16 | /// algorithm is unable to identify an alternative which would lead to a 17 | /// successful parse. 18 | /// 19 | /// 20 | /// 23 | class ANTLR4CPP_PUBLIC ErrorInfo : public DecisionEventInfo { 24 | public: 25 | /// 26 | /// Constructs a new instance of the class with the 27 | /// specified detailed syntax error information. 28 | /// 29 | /// The decision number 30 | /// The final configuration set reached during prediction 31 | /// prior to reaching the state 32 | /// The input token stream 33 | /// The start index for the current prediction 34 | /// The index at which the syntax error was identified 35 | /// {@code true} if the syntax error was identified during LL 36 | /// prediction; otherwise, {@code false} if the syntax error was identified 37 | /// during SLL prediction 38 | ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, 39 | bool fullCtx); 40 | }; 41 | 42 | } // namespace atn 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /lib/antlr4/atn/HashUtils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2022 The ANTLR Project. All rights reserved. 2 | * Use of this file is 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 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | inline bool cachedHashCodeEqual(size_t lhs, size_t rhs) { 14 | return lhs == rhs || lhs == 0 || rhs == 0; 15 | } 16 | 17 | } // namespace atn 18 | } // namespace antlr4 19 | -------------------------------------------------------------------------------- /lib/antlr4/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 final : public ATNConfig { 14 | public: 15 | LexerATNConfig(ATNState *state, int alt, Ref context); 16 | LexerATNConfig(ATNState *state, int alt, Ref context, Ref lexerActionExecutor); 17 | 18 | LexerATNConfig(LexerATNConfig const& other, ATNState *state); 19 | LexerATNConfig(LexerATNConfig const& other, ATNState *state, Ref lexerActionExecutor); 20 | LexerATNConfig(LexerATNConfig const& other, ATNState *state, Ref context); 21 | 22 | /** 23 | * Gets the {@link LexerActionExecutor} capable of executing the embedded 24 | * action(s) for the current configuration. 25 | */ 26 | const Ref& getLexerActionExecutor() const { return _lexerActionExecutor; } 27 | bool hasPassedThroughNonGreedyDecision() const { return _passedThroughNonGreedyDecision; } 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 = false; 39 | 40 | static bool checkNonGreedyDecision(LexerATNConfig const& source, ATNState *target); 41 | }; 42 | 43 | } // namespace atn 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerAction.cpp: -------------------------------------------------------------------------------- 1 | #include "LexerAction.h" 2 | 3 | using namespace antlr4::atn; 4 | 5 | size_t LexerAction::hashCode() const { 6 | auto hash = cachedHashCode(); 7 | if (hash == 0) { 8 | hash = hashCodeImpl(); 9 | if (hash == 0) { 10 | hash = std::numeric_limits::max(); 11 | } 12 | _hashCode.store(hash, std::memory_order_relaxed); 13 | } 14 | return hash; 15 | } 16 | -------------------------------------------------------------------------------- /lib/antlr4/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 = 0, 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 | INDEXED_CUSTOM, 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "support/Casts.h" 9 | 10 | #include "atn/LexerChannelAction.h" 11 | 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | using namespace antlrcpp; 15 | 16 | LexerChannelAction::LexerChannelAction(int channel) 17 | : LexerAction(LexerActionType::CHANNEL, false), _channel(channel) {} 18 | 19 | void LexerChannelAction::execute(Lexer *lexer) const { 20 | lexer->setChannel(getChannel()); 21 | } 22 | 23 | size_t LexerChannelAction::hashCodeImpl() const { 24 | size_t hash = MurmurHash::initialize(); 25 | hash = MurmurHash::update(hash, static_cast(getActionType())); 26 | hash = MurmurHash::update(hash, getChannel()); 27 | return MurmurHash::finish(hash, 2); 28 | } 29 | 30 | bool LexerChannelAction::equals(const LexerAction &other) const { 31 | if (this == std::addressof(other)) { 32 | return true; 33 | } 34 | if (getActionType() != other.getActionType()) { 35 | return false; 36 | } 37 | const auto &lexerAction = downCast(other); 38 | return getChannel() == lexerAction.getChannel(); 39 | } 40 | 41 | std::string LexerChannelAction::toString() const { 42 | return "channel(" + std::to_string(getChannel()) + ")"; 43 | } 44 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | #include "support/Casts.h" 9 | 10 | #include "atn/LexerCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | using namespace antlrcpp; 16 | 17 | LexerCustomAction::LexerCustomAction(size_t ruleIndex, size_t actionIndex) 18 | : LexerAction(LexerActionType::CUSTOM, true), _ruleIndex(ruleIndex), _actionIndex(actionIndex) {} 19 | 20 | void LexerCustomAction::execute(Lexer *lexer) const { 21 | lexer->action(nullptr, getRuleIndex(), getActionIndex()); 22 | } 23 | 24 | size_t LexerCustomAction::hashCodeImpl() const { 25 | size_t hash = MurmurHash::initialize(); 26 | hash = MurmurHash::update(hash, static_cast(getActionType())); 27 | hash = MurmurHash::update(hash, getRuleIndex()); 28 | hash = MurmurHash::update(hash, getActionIndex()); 29 | return MurmurHash::finish(hash, 3); 30 | } 31 | 32 | bool LexerCustomAction::equals(const LexerAction &other) const { 33 | if (this == std::addressof(other)) { 34 | return true; 35 | } 36 | if (getActionType() != other.getActionType()) { 37 | return false; 38 | } 39 | const auto &lexerAction = downCast(other); 40 | return getRuleIndex() == lexerAction.getRuleIndex() && getActionIndex() == lexerAction.getActionIndex(); 41 | } 42 | 43 | std::string LexerCustomAction::toString() const { 44 | return "custom(" + std::to_string(getRuleIndex()) + ", " + std::to_string(getActionIndex()) + ")"; 45 | } 46 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerIndexedCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/HashUtils.h" 7 | #include "misc/MurmurHash.h" 8 | #include "Lexer.h" 9 | #include "support/CPPUtils.h" 10 | #include "support/Casts.h" 11 | 12 | #include "atn/LexerIndexedCustomAction.h" 13 | 14 | using namespace antlr4; 15 | using namespace antlr4::atn; 16 | using namespace antlr4::misc; 17 | using namespace antlrcpp; 18 | 19 | LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref action) 20 | : LexerAction(LexerActionType::INDEXED_CUSTOM, true), _action(std::move(action)), _offset(offset) {} 21 | 22 | void LexerIndexedCustomAction::execute(Lexer *lexer) const { 23 | // assume the input stream position was properly set by the calling code 24 | getAction()->execute(lexer); 25 | } 26 | 27 | size_t LexerIndexedCustomAction::hashCodeImpl() const { 28 | size_t hash = MurmurHash::initialize(); 29 | hash = MurmurHash::update(hash, static_cast(getActionType())); 30 | hash = MurmurHash::update(hash, getOffset()); 31 | hash = MurmurHash::update(hash, getAction()); 32 | return MurmurHash::finish(hash, 3); 33 | } 34 | 35 | bool LexerIndexedCustomAction::equals(const LexerAction &other) const { 36 | if (this == std::addressof(other)) { 37 | return true; 38 | } 39 | if (getActionType() != other.getActionType()) { 40 | return false; 41 | } 42 | const auto &lexerAction = downCast(other); 43 | return getOffset() == lexerAction.getOffset() && 44 | cachedHashCodeEqual(cachedHashCode(), lexerAction.cachedHashCode()) && 45 | *getAction() == *lexerAction.getAction(); 46 | } 47 | 48 | std::string LexerIndexedCustomAction::toString() const { 49 | return "indexedCustom(" + std::to_string(getOffset()) + ", " + getAction()->toString() + ")"; 50 | } 51 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "support/Casts.h" 9 | 10 | #include "atn/LexerModeAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | using namespace antlrcpp; 16 | 17 | LexerModeAction::LexerModeAction(int mode) : LexerAction(LexerActionType::MODE, false), _mode(mode) {} 18 | 19 | void LexerModeAction::execute(Lexer *lexer) const { 20 | lexer->setMode(getMode()); 21 | } 22 | 23 | size_t LexerModeAction::hashCodeImpl() const { 24 | size_t hash = MurmurHash::initialize(); 25 | hash = MurmurHash::update(hash, static_cast(getActionType())); 26 | hash = MurmurHash::update(hash, getMode()); 27 | return MurmurHash::finish(hash, 2); 28 | } 29 | 30 | bool LexerModeAction::equals(const LexerAction &other) const { 31 | if (this == std::addressof(other)) { 32 | return true; 33 | } 34 | if (getActionType() != other.getActionType()) { 35 | return false; 36 | } 37 | const auto &lexerAction = downCast(other); 38 | return getMode() == lexerAction.getMode(); 39 | } 40 | 41 | std::string LexerModeAction::toString() const { 42 | return "mode(" + std::to_string(getMode()) + ")"; 43 | } 44 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerModeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code mode} lexer action by calling with 16 | /// the assigned mode. 17 | /// 18 | /// @author Sam Harwell 19 | /// @since 4.2 20 | /// 21 | class ANTLR4CPP_PUBLIC LexerModeAction final : public LexerAction { 22 | public: 23 | static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::MODE; } 24 | 25 | static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); } 26 | 27 | /// 28 | /// Constructs a new {@code mode} action with the specified mode value. 29 | /// The mode value to pass to . 30 | explicit LexerModeAction(int mode); 31 | 32 | /// 33 | /// Get the lexer mode this action should transition the lexer to. 34 | /// 35 | /// The lexer mode for this {@code mode} command. 36 | int getMode() const { return _mode; } 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling with the 42 | /// value provided by . 43 | /// 44 | void execute(Lexer *lexer) const override; 45 | 46 | bool equals(const LexerAction &obj) const override; 47 | std::string toString() const override; 48 | 49 | protected: 50 | size_t hashCodeImpl() const override; 51 | 52 | private: 53 | const int _mode; 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /lib/antlr4/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 const Ref instance(new LexerMoreAction()); 17 | return instance; 18 | } 19 | 20 | void LexerMoreAction::execute(Lexer *lexer) const { 21 | lexer->more(); 22 | } 23 | 24 | size_t LexerMoreAction::hashCodeImpl() const { 25 | size_t hash = MurmurHash::initialize(); 26 | hash = MurmurHash::update(hash, static_cast(getActionType())); 27 | return MurmurHash::finish(hash, 1); 28 | } 29 | 30 | bool LexerMoreAction::equals(const LexerAction &other) const { 31 | return this == std::addressof(other); 32 | } 33 | 34 | std::string LexerMoreAction::toString() const { 35 | return "more"; 36 | } 37 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerMoreAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code more} lexer action by calling . 16 | /// 17 | /// The {@code more} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerMoreAction final : public LexerAction { 24 | public: 25 | static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::MORE; } 26 | 27 | static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); } 28 | 29 | /// 30 | /// Provides a singleton instance of this parameterless lexer action. 31 | /// 32 | static const Ref& getInstance(); 33 | 34 | /// 35 | /// {@inheritDoc} 36 | /// 37 | /// This action is implemented by calling . 38 | /// 39 | void execute(Lexer *lexer) const override; 40 | 41 | bool equals(const LexerAction &obj) const override; 42 | std::string toString() const override; 43 | 44 | protected: 45 | size_t hashCodeImpl() const override; 46 | 47 | private: 48 | /// Constructs the singleton instance of the lexer {@code more} command. 49 | LexerMoreAction() : LexerAction(LexerActionType::MORE, false) {} 50 | }; 51 | 52 | } // namespace atn 53 | } // namespace antlr4 54 | -------------------------------------------------------------------------------- /lib/antlr4/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 const Ref instance(new LexerPopModeAction()); 17 | return instance; 18 | } 19 | 20 | void LexerPopModeAction::execute(Lexer *lexer) const { 21 | lexer->popMode(); 22 | } 23 | 24 | size_t LexerPopModeAction::hashCodeImpl() const { 25 | size_t hash = MurmurHash::initialize(); 26 | hash = MurmurHash::update(hash, static_cast(getActionType())); 27 | return MurmurHash::finish(hash, 1); 28 | } 29 | 30 | bool LexerPopModeAction::equals(const LexerAction &other) const { 31 | return this == std::addressof(other); 32 | } 33 | 34 | std::string LexerPopModeAction::toString() const { 35 | return "popMode"; 36 | } 37 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerPopModeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code popMode} lexer action by calling . 16 | /// 17 | /// The {@code popMode} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerPopModeAction final : public LexerAction { 24 | public: 25 | static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::POP_MODE; } 26 | 27 | static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); } 28 | 29 | /// 30 | /// Provides a singleton instance of this parameterless lexer action. 31 | /// 32 | static const Ref& getInstance(); 33 | 34 | /// 35 | /// {@inheritDoc} 36 | /// 37 | /// This action is implemented by calling . 38 | /// 39 | void execute(Lexer *lexer) const override; 40 | 41 | bool equals(const LexerAction &other) const override; 42 | std::string toString() const override; 43 | 44 | protected: 45 | size_t hashCodeImpl() const override; 46 | 47 | private: 48 | /// Constructs the singleton instance of the lexer {@code popMode} command. 49 | LexerPopModeAction() : LexerAction(LexerActionType::POP_MODE, false) {} 50 | }; 51 | 52 | } // namespace atn 53 | } // namespace antlr4 54 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "support/Casts.h" 9 | 10 | #include "atn/LexerPushModeAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | using namespace antlrcpp; 16 | 17 | LexerPushModeAction::LexerPushModeAction(int mode) : LexerAction(LexerActionType::PUSH_MODE, false), _mode(mode) {} 18 | 19 | void LexerPushModeAction::execute(Lexer *lexer) const { 20 | lexer->pushMode(getMode()); 21 | } 22 | 23 | size_t LexerPushModeAction::hashCodeImpl() const { 24 | size_t hash = MurmurHash::initialize(); 25 | hash = MurmurHash::update(hash, static_cast(getActionType())); 26 | hash = MurmurHash::update(hash, getMode()); 27 | return MurmurHash::finish(hash, 2); 28 | } 29 | 30 | bool LexerPushModeAction::equals(const LexerAction &other) const { 31 | if (this == std::addressof(other)) { 32 | return true; 33 | } 34 | if (getActionType() != other.getActionType()) { 35 | return false; 36 | } 37 | const auto &lexerAction = downCast(other); 38 | return getMode() == lexerAction.getMode(); 39 | } 40 | 41 | std::string LexerPushModeAction::toString() const { 42 | return "pushMode(" + std::to_string(getMode()) + ")"; 43 | } 44 | -------------------------------------------------------------------------------- /lib/antlr4/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 const Ref instance(new LexerSkipAction()); 17 | return instance; 18 | } 19 | 20 | void LexerSkipAction::execute(Lexer *lexer) const { 21 | lexer->skip(); 22 | } 23 | 24 | size_t LexerSkipAction::hashCodeImpl() const { 25 | size_t hash = MurmurHash::initialize(); 26 | hash = MurmurHash::update(hash, static_cast(getActionType())); 27 | return MurmurHash::finish(hash, 1); 28 | } 29 | 30 | bool LexerSkipAction::equals(const LexerAction &other) const { 31 | return this == std::addressof(other); 32 | } 33 | 34 | std::string LexerSkipAction::toString() const { 35 | return "skip"; 36 | } 37 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerSkipAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code skip} lexer action by calling . 16 | /// 17 | /// The {@code skip} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction { 24 | public: 25 | static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::SKIP; } 26 | 27 | static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); } 28 | 29 | /// Provides a singleton instance of this parameterless lexer action. 30 | static const Ref& getInstance(); 31 | 32 | /// 33 | /// {@inheritDoc} 34 | /// 35 | /// This action is implemented by calling . 36 | /// 37 | void execute(Lexer *lexer) const override; 38 | 39 | bool equals(const LexerAction &obj) const override; 40 | std::string toString() const override; 41 | 42 | protected: 43 | size_t hashCodeImpl() const override; 44 | 45 | private: 46 | /// Constructs the singleton instance of the lexer {@code skip} command. 47 | LexerSkipAction() : LexerAction(LexerActionType::SKIP, false) {} 48 | }; 49 | 50 | } // namespace atn 51 | } // namespace antlr4 52 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "support/Casts.h" 9 | 10 | #include "atn/LexerTypeAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | using namespace antlrcpp; 16 | 17 | LexerTypeAction::LexerTypeAction(int type) : LexerAction(LexerActionType::TYPE, false), _type(type) {} 18 | 19 | void LexerTypeAction::execute(Lexer *lexer) const { 20 | lexer->setType(getType()); 21 | } 22 | 23 | size_t LexerTypeAction::hashCodeImpl() const { 24 | size_t hash = MurmurHash::initialize(); 25 | hash = MurmurHash::update(hash, static_cast(getActionType())); 26 | hash = MurmurHash::update(hash, getType()); 27 | return MurmurHash::finish(hash, 2); 28 | } 29 | 30 | bool LexerTypeAction::equals(const LexerAction &other) const { 31 | if (this == std::addressof(other)) { 32 | return true; 33 | } 34 | if (getActionType() != other.getActionType()) { 35 | return false; 36 | } 37 | const auto &lexerAction = downCast(other); 38 | return getType() == lexerAction.getType(); 39 | } 40 | 41 | std::string LexerTypeAction::toString() const { 42 | return "type(" + std::to_string(getType()) + ")"; 43 | } 44 | -------------------------------------------------------------------------------- /lib/antlr4/atn/LexerTypeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerActionType.h" 9 | #include "atn/LexerAction.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// Implements the {@code type} lexer action by calling 15 | /// with the assigned type. 16 | class ANTLR4CPP_PUBLIC LexerTypeAction final : public LexerAction { 17 | public: 18 | static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::TYPE; } 19 | 20 | static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); } 21 | 22 | /// 23 | /// Constructs a new {@code type} action with the specified token type value. 24 | /// The type to assign to the token using . 25 | explicit LexerTypeAction(int type); 26 | 27 | /// 28 | /// Gets the type to assign to a token created by the lexer. 29 | /// The type to assign to a token created by the lexer. 30 | int getType() const { return _type; } 31 | 32 | /// 33 | /// {@inheritDoc} 34 | /// 35 | /// This action is implemented by calling with the 36 | /// value provided by . 37 | /// 38 | void execute(Lexer *lexer) const override; 39 | 40 | bool equals(const LexerAction &obj) const override; 41 | std::string toString() const override; 42 | 43 | protected: 44 | size_t hashCodeImpl() const override; 45 | 46 | private: 47 | const int _type; 48 | }; 49 | 50 | } // namespace atn 51 | } // namespace antlr4 52 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::LOOP_END; } 17 | 18 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 19 | 20 | ATNState *loopBackState = nullptr; 21 | 22 | LoopEndState() : ATNState(ATNStateType::LOOP_END) {} 23 | }; 24 | 25 | } // namespace atn 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /lib/antlr4/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, misc::IntervalSet set) : SetTransition(TransitionType::NOT_SET, target, std::move(set)) {} 14 | 15 | bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 16 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 17 | && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol); 18 | } 19 | 20 | std::string NotSetTransition::toString() const { 21 | return "NOT_SET " + Transition::toString() + " { " + SetTransition::toString() + " }"; 22 | } 23 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::NOT_SET; } 16 | 17 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 18 | 19 | NotSetTransition(ATNState *target, misc::IntervalSet set); 20 | 21 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 22 | 23 | virtual std::string toString() const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /lib/antlr4/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::hashCode(const ATNConfig &atnConfig) const { 11 | return atnConfig.hashCode(); 12 | } 13 | 14 | bool OrderedATNConfigSet::equals(const ATNConfig &lhs, const ATNConfig &rhs) const { 15 | return lhs == rhs; 16 | } 17 | -------------------------------------------------------------------------------- /lib/antlr4/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 final : public ATNConfigSet { 15 | public: 16 | OrderedATNConfigSet() = default; 17 | 18 | private: 19 | size_t hashCode(const ATNConfig &atnConfig) const override; 20 | 21 | bool equals(const ATNConfig &lhs, const ATNConfig &rhs) const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::PLUS_BLOCK_START; } 20 | 21 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 22 | 23 | PlusLoopbackState *loopBackState = nullptr; 24 | 25 | PlusBlockStartState() : BlockStartState(ATNStateType::PLUS_BLOCK_START) {} 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 17 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::PLUS_LOOP_BACK; } 18 | 19 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 20 | 21 | PlusLoopbackState() : DecisionState(ATNStateType::PLUS_LOOP_BACK) {} 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /lib/antlr4/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 | : Transition(TransitionType::PRECEDENCE, target), _predicate(std::make_shared(precedence)) {} 12 | 13 | bool PrecedencePredicateTransition::isEpsilon() const { 14 | return true; 15 | } 16 | 17 | bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 18 | return false; 19 | } 20 | 21 | std::string PrecedencePredicateTransition::toString() const { 22 | return "PRECEDENCE " + Transition::toString() + " { precedence: " + std::to_string(getPrecedence()) + " }"; 23 | } 24 | -------------------------------------------------------------------------------- /lib/antlr4/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/Transition.h" 9 | #include "atn/SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC PrecedencePredicateTransition final : public Transition { 15 | public: 16 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::PRECEDENCE; } 17 | 18 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 19 | 20 | PrecedencePredicateTransition(ATNState *target, int precedence); 21 | 22 | int getPrecedence() const { return _predicate->precedence; } 23 | 24 | bool isEpsilon() const override; 25 | bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 26 | std::string toString() const override; 27 | 28 | const Ref& getPredicate() const { return _predicate; } 29 | 30 | private: 31 | const std::shared_ptr _predicate; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /lib/antlr4/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 semctx, bool evalResult, size_t predictedAlt, bool fullCtx) 15 | : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), 16 | semctx(std::move(semctx)), predictedAlt(predictedAlt), evalResult(evalResult) { 17 | } 18 | -------------------------------------------------------------------------------- /lib/antlr4/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) 11 | : Transition(TransitionType::PREDICATE, target), _predicate(std::make_shared(ruleIndex, predIndex, isCtxDependent)) {} 12 | 13 | bool PredicateTransition::isEpsilon() const { 14 | return true; 15 | } 16 | 17 | bool PredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 18 | return false; 19 | } 20 | 21 | std::string PredicateTransition::toString() const { 22 | return "PREDICATE " + Transition::toString() + " { ruleIndex: " + std::to_string(getRuleIndex()) + 23 | ", predIndex: " + std::to_string(getPredIndex()) + ", isCtxDependent: " + std::to_string(isCtxDependent()) + " }"; 24 | } 25 | -------------------------------------------------------------------------------- /lib/antlr4/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/Transition.h" 9 | #include "atn/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 Transition { 20 | public: 21 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::PREDICATE; } 22 | 23 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 24 | 25 | PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent); 26 | 27 | size_t getRuleIndex() const { 28 | return _predicate->ruleIndex; 29 | } 30 | 31 | size_t getPredIndex() const { 32 | return _predicate->predIndex; 33 | } 34 | 35 | bool isCtxDependent() const { 36 | return _predicate->isCtxDependent; 37 | } 38 | 39 | bool isEpsilon() const override; 40 | bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 41 | std::string toString() const override; 42 | 43 | const Ref& getPredicate() const { return _predicate; } 44 | 45 | private: 46 | const std::shared_ptr _predicate; 47 | }; 48 | 49 | } // namespace atn 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /lib/antlr4/atn/PredictionContextType.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 9 | 10 | #include "antlr4-common.h" 11 | 12 | namespace antlr4 { 13 | namespace atn { 14 | 15 | enum class PredictionContextType : size_t { 16 | SINGLETON = 1, 17 | ARRAY = 2, 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType::RANGE, target), from(from), to(to) { 14 | } 15 | 16 | misc::IntervalSet RangeTransition::label() const { 17 | return misc::IntervalSet::of((int)from, (int)to); 18 | } 19 | 20 | bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 21 | return symbol >= from && symbol <= to; 22 | } 23 | 24 | std::string RangeTransition::toString() const { 25 | return "RANGE " + Transition::toString() + " { from: " + std::to_string(from) + ", to: " + std::to_string(to) + " }"; 26 | } 27 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::RANGE; } 16 | 17 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 18 | 19 | const size_t from; 20 | const size_t to; 21 | 22 | RangeTransition(ATNState *target, size_t from, size_t to); 23 | 24 | virtual misc::IntervalSet label() const override; 25 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 26 | 27 | virtual std::string toString() const override; 28 | }; 29 | 30 | } // namespace atn 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::RULE_START; } 16 | 17 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 18 | 19 | RuleStopState *stopState = nullptr; 20 | bool isLeftRecursiveRule = false; 21 | 22 | RuleStartState() : ATNState(ATNStateType::RULE_START) {} 23 | }; 24 | 25 | } // namespace atn 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 19 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::RULE_STOP; } 20 | 21 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 22 | 23 | RuleStopState() : ATNState(ATNStateType::RULE_STOP) {} 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType::RULE, ruleStart), ruleIndex(ruleIndex), precedence(precedence) { 17 | this->followState = followState; 18 | } 19 | 20 | bool RuleTransition::isEpsilon() const { 21 | return true; 22 | } 23 | 24 | bool RuleTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 25 | return false; 26 | } 27 | 28 | std::string RuleTransition::toString() const { 29 | std::stringstream ss; 30 | ss << "RULE " << Transition::toString() << " { ruleIndex: " << ruleIndex << ", precedence: " << precedence << 31 | ", followState: " << std::hex << followState << " }"; 32 | return ss.str(); 33 | } 34 | -------------------------------------------------------------------------------- /lib/antlr4/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 final : public Transition { 14 | public: 15 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::RULE; } 16 | 17 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 18 | 19 | /// Ptr to the rule definition object for this rule ref. 20 | const size_t ruleIndex; // no Rule object at runtime 21 | 22 | const int precedence; 23 | 24 | /// What node to begin computations following ref to rule. 25 | ATNState *followState; 26 | 27 | /// @deprecated Use 28 | /// instead. 29 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState); 30 | 31 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState); 32 | RuleTransition(RuleTransition const&) = delete; 33 | RuleTransition& operator=(RuleTransition const&) = delete; 34 | 35 | virtual bool isEpsilon() const override; 36 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 37 | 38 | virtual std::string toString() const override; 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /lib/antlr4/atn/SemanticContextType.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 9 | 10 | #include "antlr4-common.h" 11 | 12 | namespace antlr4 { 13 | namespace atn { 14 | 15 | enum class SemanticContextType : size_t { 16 | PREDICATE = 1, 17 | PRECEDENCE = 2, 18 | AND = 3, 19 | OR = 4, 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType transitionType, ATNState *target, misc::IntervalSet aSet) 15 | : Transition(transitionType, target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : std::move(aSet)) { 16 | } 17 | 18 | misc::IntervalSet SetTransition::label() const { 19 | return set; 20 | } 21 | 22 | bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 23 | return set.contains(symbol); 24 | } 25 | 26 | std::string SetTransition::toString() const { 27 | return "SET " + Transition::toString() + " { set: " + set.toString() + "}"; 28 | } 29 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { 18 | const auto transitionType = transition.getTransitionType(); 19 | return transitionType == TransitionType::SET || transitionType == TransitionType::NOT_SET; 20 | } 21 | 22 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 23 | 24 | const misc::IntervalSet set; 25 | 26 | SetTransition(ATNState *target, misc::IntervalSet set) : SetTransition(TransitionType::SET, target, std::move(set)) {} 27 | 28 | virtual misc::IntervalSet label() const override; 29 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 30 | 31 | virtual std::string toString() const override; 32 | 33 | protected: 34 | SetTransition(TransitionType transitionType, ATNState *target, misc::IntervalSet set); 35 | }; 36 | 37 | } // namespace atn 38 | } // namespace antlr4 39 | -------------------------------------------------------------------------------- /lib/antlr4/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 final : public PredictionContext { 14 | public: 15 | static bool is(const PredictionContext &predictionContext) { return predictionContext.getContextType() == PredictionContextType::SINGLETON; } 16 | 17 | static bool is(const PredictionContext *predictionContext) { return predictionContext != nullptr && is(*predictionContext); } 18 | 19 | static Ref create(Ref parent, size_t returnState); 20 | 21 | // Usually a parent is linked via a weak ptr. Not so here as we have kinda reverse reference chain. 22 | // There are no child contexts stored here and often the parent context is left dangling when it's 23 | // owning ATNState is released. In order to avoid having this context released as well (leaving all other contexts 24 | // which got this one as parent with a null reference) we use a shared_ptr here instead, to keep those left alone 25 | // parent contexts alive. 26 | const Ref parent; 27 | const size_t returnState; 28 | 29 | SingletonPredictionContext(Ref parent, size_t returnState); 30 | 31 | bool isEmpty() const override; 32 | size_t size() const override; 33 | const Ref& getParent(size_t index) const override; 34 | size_t getReturnState(size_t index) const override; 35 | bool equals(const PredictionContext &other) const override; 36 | std::string toString() const override; 37 | 38 | protected: 39 | size_t hashCodeImpl() const override; 40 | }; 41 | 42 | } // namespace atn 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 16 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::STAR_BLOCK_START; } 17 | 18 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 19 | 20 | StarBlockStartState() : BlockStartState(ATNStateType::STAR_BLOCK_START) {} 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::STAR_LOOP_ENTRY; } 16 | 17 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 18 | 19 | /** 20 | * Indicates whether this state can benefit from a precedence DFA during SLL 21 | * decision making. 22 | * 23 | *

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

26 | * 27 | * @see DFA#isPrecedenceDfa() 28 | */ 29 | bool isPrecedenceDecision = false; 30 | 31 | StarLoopbackState *loopBackState = nullptr; 32 | 33 | StarLoopEntryState() : DecisionState(ATNStateType::STAR_LOOP_ENTRY) {} 34 | }; 35 | 36 | } // namespace atn 37 | } // namespace antlr4 38 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "support/Casts.h" 9 | 10 | #include "atn/StarLoopbackState.h" 11 | 12 | using namespace antlr4::atn; 13 | 14 | StarLoopEntryState *StarLoopbackState::getLoopEntryState() const { 15 | if (transitions[0]->target != nullptr && transitions[0]->target->getStateType() == ATNStateType::STAR_LOOP_ENTRY) { 16 | return antlrcpp::downCast(transitions[0]->target); 17 | } 18 | return nullptr; 19 | } 20 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::STAR_LOOP_BACK; } 16 | 17 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 18 | 19 | StarLoopbackState() : ATNState(ATNStateType::STAR_LOOP_BACK) {} 20 | 21 | StarLoopEntryState *getLoopEntryState() const; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /lib/antlr4/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 | public: 16 | static bool is(const ATNState &atnState) { return atnState.getStateType() == ATNStateType::TOKEN_START; } 17 | 18 | static bool is(const ATNState *atnState) { return atnState != nullptr && is(*atnState); } 19 | 20 | TokensStartState() : DecisionState(ATNStateType::TOKEN_START) {} 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /lib/antlr4/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 | using namespace antlrcpp; 14 | 15 | Transition::Transition(TransitionType transitionType, ATNState *target) : _transitionType(transitionType) { 16 | if (target == nullptr) { 17 | throw NullPointerException("target cannot be null."); 18 | } 19 | 20 | this->target = target; 21 | } 22 | 23 | bool Transition::isEpsilon() const { 24 | return false; 25 | } 26 | 27 | misc::IntervalSet Transition::label() const { 28 | return misc::IntervalSet::EMPTY_SET; 29 | } 30 | 31 | std::string Transition::toString() const { 32 | std::stringstream ss; 33 | ss << "(Transition " << std::hex << this << ", target: " << std::hex << target << ')'; 34 | 35 | return ss.str(); 36 | } 37 | -------------------------------------------------------------------------------- /lib/antlr4/atn/TransitionType.cpp: -------------------------------------------------------------------------------- 1 | #include "atn/TransitionType.h" 2 | 3 | std::string antlr4::atn::transitionTypeName(TransitionType transitionType) { 4 | switch (transitionType) { 5 | case TransitionType::EPSILON: 6 | return "EPSILON"; 7 | case TransitionType::RANGE: 8 | return "RANGE"; 9 | case TransitionType::RULE: 10 | return "RULE"; 11 | case TransitionType::PREDICATE: 12 | return "PREDICATE"; 13 | case TransitionType::ATOM: 14 | return "ATOM"; 15 | case TransitionType::ACTION: 16 | return "ACTION"; 17 | case TransitionType::SET: 18 | return "SET"; 19 | case TransitionType::NOT_SET: 20 | return "NOT_SET"; 21 | case TransitionType::WILDCARD: 22 | return "WILDCARD"; 23 | case TransitionType::PRECEDENCE: 24 | return "PRECEDENCE"; 25 | } 26 | return "UNKNOWN"; 27 | } 28 | -------------------------------------------------------------------------------- /lib/antlr4/atn/TransitionType.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 9 | #include 10 | 11 | #include "antlr4-common.h" 12 | 13 | namespace antlr4 { 14 | namespace atn { 15 | 16 | // Constants for transition serialization. 17 | enum class TransitionType : size_t { 18 | EPSILON = 1, 19 | RANGE = 2, 20 | RULE = 3, 21 | PREDICATE = 4, // e.g., {isType(input.LT(1))}? 22 | ATOM = 5, 23 | ACTION = 6, 24 | SET = 7, // ~(A|B) or ~atom, wildcard, which convert to next 2 25 | NOT_SET = 8, 26 | WILDCARD = 9, 27 | PRECEDENCE = 10, 28 | }; 29 | 30 | ANTLR4CPP_PUBLIC std::string transitionTypeName(TransitionType transitionType); 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /lib/antlr4/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(TransitionType::WILDCARD, target) { 13 | } 14 | 15 | bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 16 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol; 17 | } 18 | 19 | std::string WildcardTransition::toString() const { 20 | return "WILDCARD " + Transition::toString() + " {}"; 21 | } 22 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const Transition &transition) { return transition.getTransitionType() == TransitionType::WILDCARD; } 16 | 17 | static bool is(const Transition *transition) { return transition != nullptr && is(*transition); } 18 | 19 | explicit WildcardTransition(ATNState *target); 20 | 21 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 22 | 23 | virtual std::string toString() const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /lib/antlr4/dfa/DFASerializer.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 "dfa/DFA.h" 7 | #include "Vocabulary.h" 8 | 9 | #include "dfa/DFASerializer.h" 10 | 11 | using namespace antlr4::dfa; 12 | 13 | DFASerializer::DFASerializer(const DFA *dfa, const Vocabulary &vocabulary) : _dfa(dfa), _vocabulary(vocabulary) { 14 | } 15 | 16 | std::string DFASerializer::toString() const { 17 | if (_dfa->s0 == nullptr) { 18 | return ""; 19 | } 20 | 21 | std::stringstream ss; 22 | std::vector states = _dfa->getStates(); 23 | for (auto *s : states) { 24 | for (size_t i = 0; i < s->edges.size(); i++) { 25 | DFAState *t = s->edges[i]; 26 | if (t != nullptr && t->stateNumber != INT32_MAX) { 27 | ss << getStateString(s); 28 | std::string label = getEdgeLabel(i); 29 | ss << "-" << label << "->" << getStateString(t) << "\n"; 30 | } 31 | } 32 | } 33 | 34 | return ss.str(); 35 | } 36 | 37 | std::string DFASerializer::getEdgeLabel(size_t i) const { 38 | return _vocabulary.getDisplayName(i); // ml: no longer needed -1 as we use a map for edges, without offset. 39 | } 40 | 41 | std::string DFASerializer::getStateString(DFAState *s) const { 42 | size_t n = s->stateNumber; 43 | 44 | const std::string baseStateStr = std::string(s->isAcceptState ? ":" : "") + "s" + std::to_string(n) + 45 | (s->requiresFullContext ? "^" : ""); 46 | 47 | if (s->isAcceptState) { 48 | if (!s->predicates.empty()) { 49 | std::string buf; 50 | for (size_t i = 0; i < s->predicates.size(); i++) { 51 | buf.append(s->predicates[i].toString()); 52 | } 53 | return baseStateStr + "=>" + buf; 54 | } else { 55 | return baseStateStr + "=>" + std::to_string(s->prediction); 56 | } 57 | } else { 58 | return baseStateStr; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/antlr4/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 Vocabulary &vocabulary); 17 | 18 | virtual ~DFASerializer() = default; 19 | 20 | std::string toString() const; 21 | 22 | protected: 23 | virtual std::string getEdgeLabel(size_t i) const; 24 | 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 | -------------------------------------------------------------------------------- /lib/antlr4/dfa/DFAState.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 | #include "atn/SemanticContext.h" 8 | #include "atn/ATNConfig.h" 9 | #include "misc/MurmurHash.h" 10 | 11 | #include "dfa/DFAState.h" 12 | 13 | using namespace antlr4::dfa; 14 | using namespace antlr4::atn; 15 | 16 | std::string DFAState::PredPrediction::toString() const { 17 | return std::string("(") + pred->toString() + ", " + std::to_string(alt) + ")"; 18 | } 19 | 20 | std::set DFAState::getAltSet() const { 21 | std::set alts; 22 | if (configs != nullptr) { 23 | for (size_t i = 0; i < configs->size(); i++) { 24 | alts.insert(configs->get(i)->alt); 25 | } 26 | } 27 | return alts; 28 | } 29 | 30 | size_t DFAState::hashCode() const { 31 | return configs != nullptr ? configs->hashCode() : 0; 32 | } 33 | 34 | bool DFAState::equals(const DFAState &other) const { 35 | if (this == std::addressof(other)) { 36 | return true; 37 | } 38 | return configs == other.configs || 39 | (configs != nullptr && other.configs != nullptr && *configs == *other.configs); 40 | } 41 | 42 | std::string DFAState::toString() const { 43 | std::stringstream ss; 44 | ss << stateNumber; 45 | if (configs) { 46 | ss << ":" << configs->toString(); 47 | } 48 | if (isAcceptState) { 49 | ss << "=>"; 50 | if (!predicates.empty()) { 51 | for (size_t i = 0; i < predicates.size(); i++) { 52 | ss << predicates[i].toString(); 53 | } 54 | } else { 55 | ss << prediction; 56 | } 57 | } 58 | return ss.str(); 59 | } 60 | -------------------------------------------------------------------------------- /lib/antlr4/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(const DFA *dfa) : DFASerializer(dfa, Vocabulary()) { 13 | } 14 | 15 | std::string LexerDFASerializer::getEdgeLabel(size_t i) const { 16 | return std::string("'") + static_cast(i) + "'"; 17 | } 18 | -------------------------------------------------------------------------------- /lib/antlr4/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 final : public DFASerializer { 14 | public: 15 | explicit LexerDFASerializer(const DFA *dfa); 16 | 17 | protected: 18 | std::string getEdgeLabel(size_t i) const override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "atn/ATN.h" 10 | #include "Vocabulary.h" 11 | 12 | namespace antlr4 { 13 | namespace misc { 14 | 15 | struct InterpreterData { 16 | std::unique_ptr atn; 17 | dfa::Vocabulary vocabulary; 18 | std::vector ruleNames; 19 | std::vector channels; // Only valid for lexer grammars. 20 | std::vector modes; // ditto 21 | 22 | InterpreterData() {}; // For invalid content. 23 | InterpreterData(std::vector const& literalNames, std::vector const& symbolicNames); 24 | }; 25 | 26 | // A class to read plain text interpreter data produced by ANTLR. 27 | class ANTLR4CPP_PUBLIC InterpreterDataReader { 28 | public: 29 | static InterpreterData parseFile(std::string const& fileName); 30 | }; 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /lib/antlr4/misc/Interval.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 | 8 | using namespace antlr4::misc; 9 | 10 | const Interval Interval::INVALID; 11 | 12 | size_t Interval::hashCode() const { 13 | size_t hash = 23; 14 | hash = hash * 31 + static_cast(a); 15 | hash = hash * 31 + static_cast(b); 16 | return hash; 17 | } 18 | 19 | bool Interval::startsBeforeDisjoint(const Interval &other) const { 20 | return a < other.a && b < other.a; 21 | } 22 | 23 | bool Interval::startsBeforeNonDisjoint(const Interval &other) const { 24 | return a <= other.a && b >= other.a; 25 | } 26 | 27 | bool Interval::startsAfter(const Interval &other) const { 28 | return a > other.a; 29 | } 30 | 31 | bool Interval::startsAfterDisjoint(const Interval &other) const { 32 | return a > other.b; 33 | } 34 | 35 | bool Interval::startsAfterNonDisjoint(const Interval &other) const { 36 | return a > other.a && a <= other.b; // b >= other.b implied 37 | } 38 | 39 | bool Interval::disjoint(const Interval &other) const { 40 | return startsBeforeDisjoint(other) || startsAfterDisjoint(other); 41 | } 42 | 43 | bool Interval::adjacent(const Interval &other) const { 44 | return a == other.b + 1 || b == other.a - 1; 45 | } 46 | 47 | bool Interval::properlyContains(const Interval &other) const { 48 | return other.a >= a && other.b <= b; 49 | } 50 | 51 | Interval Interval::Union(const Interval &other) const { 52 | return Interval(std::min(a, other.a), std::max(b, other.b)); 53 | } 54 | 55 | Interval Interval::intersection(const Interval &other) const { 56 | return Interval(std::max(a, other.a), std::min(b, other.b)); 57 | } 58 | 59 | std::string Interval::toString() const { 60 | return std::to_string(a) + ".." + std::to_string(b); 61 | } 62 | -------------------------------------------------------------------------------- /lib/antlr4/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/support/Any.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 | // A standard C++ class loosely modeled after boost::Any. 7 | 8 | #pragma once 9 | 10 | #include "antlr4-common.h" 11 | 12 | namespace antlrcpp { 13 | 14 | using Any = std::any; 15 | 16 | } // namespace antlrcpp 17 | -------------------------------------------------------------------------------- /lib/antlr4/support/Arrays.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "Exceptions.h" 8 | 9 | #include "support/Arrays.h" 10 | 11 | using namespace antlrcpp; 12 | 13 | std::string Arrays::listToString(const std::vector &list, const std::string &separator) 14 | { 15 | std::stringstream ss; 16 | bool firstEntry = true; 17 | 18 | ss << '['; 19 | for (const auto &entry : list) { 20 | ss << entry; 21 | if (firstEntry) { 22 | ss << separator; 23 | firstEntry = false; 24 | } 25 | } 26 | 27 | ss << ']'; 28 | return ss.str(); 29 | } 30 | 31 | template <> 32 | std::string Arrays::toString(const std::vector &source) { 33 | std::string result = "["; 34 | bool firstEntry = true; 35 | for (auto *value : source) { 36 | result += value->toStringTree(); 37 | if (firstEntry) { 38 | result += ", "; 39 | firstEntry = false; 40 | } 41 | } 42 | return result + "]"; 43 | } 44 | -------------------------------------------------------------------------------- /lib/antlr4/support/Casts.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2021 The ANTLR Project. All rights reserved. 2 | * Use of this file is 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 9 | #include 10 | #include 11 | 12 | namespace antlrcpp { 13 | 14 | template 15 | To downCast(From* from) { 16 | static_assert(std::is_pointer_v, "Target type not a pointer."); 17 | static_assert(std::is_base_of_v>, "Target type not derived from source type."); 18 | #if !defined(__GNUC__) || defined(__GXX_RTTI) 19 | assert(from == nullptr || dynamic_cast(from) != nullptr); 20 | #endif 21 | return static_cast(from); 22 | } 23 | 24 | template 25 | To downCast(From& from) { 26 | static_assert(std::is_lvalue_reference_v, "Target type not a lvalue reference."); 27 | static_assert(std::is_base_of_v>, "Target type not derived from source type."); 28 | #if !defined(__GNUC__) || defined(__GXX_RTTI) 29 | assert(dynamic_cast>>(std::addressof(from)) != nullptr); 30 | #endif 31 | return static_cast(from); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /lib/antlr4/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 | std::string escapeWhitespace(std::string_view in) { 11 | std::string out; 12 | escapeWhitespace(out, in); 13 | out.shrink_to_fit(); 14 | return out; 15 | } 16 | 17 | std::string& escapeWhitespace(std::string& out, std::string_view in) { 18 | out.reserve(in.size()); // Best case, no escaping. 19 | for (const auto &c : in) { 20 | switch (c) { 21 | case '\t': 22 | out.append("\\t"); 23 | break; 24 | case '\r': 25 | out.append("\\r"); 26 | break; 27 | case '\n': 28 | out.append("\\n"); 29 | break; 30 | default: 31 | out.push_back(c); 32 | break; 33 | } 34 | } 35 | return out; 36 | } 37 | 38 | } // namespace antrlcpp 39 | -------------------------------------------------------------------------------- /lib/antlr4/support/StringUtils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | ANTLR4CPP_PUBLIC std::string escapeWhitespace(std::string_view in); 13 | 14 | ANTLR4CPP_PUBLIC std::string& escapeWhitespace(std::string& out, std::string_view in); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /lib/antlr4/support/Unicode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | class ANTLR4CPP_PUBLIC Unicode final { 13 | public: 14 | static constexpr char32_t REPLACEMENT_CHARACTER = 0xfffd; 15 | 16 | static constexpr bool isValid(char32_t codePoint) { 17 | return codePoint < 0xd800 || (codePoint > 0xdfff && codePoint <= 0x10ffff); 18 | } 19 | 20 | private: 21 | Unicode() = delete; 22 | Unicode(const Unicode&) = delete; 23 | Unicode(Unicode&&) = delete; 24 | Unicode& operator=(const Unicode&) = delete; 25 | Unicode& operator=(Unicode&&) = delete; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /lib/antlr4/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 TerminalNode { 14 | public: 15 | static bool is(const tree::ParseTree &parseTree) { return parseTree.getTreeType() == tree::ParseTreeType::ERROR; } 16 | 17 | static bool is(const tree::ParseTree *parseTree) { return parseTree != nullptr && is(*parseTree); } 18 | 19 | protected: 20 | using TerminalNode::TerminalNode; 21 | }; 22 | 23 | } // namespace tree 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /lib/antlr4/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 "misc/Interval.h" 7 | #include "Token.h" 8 | #include "RuleContext.h" 9 | #include "tree/ParseTreeVisitor.h" 10 | 11 | #include "tree/ErrorNodeImpl.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | 16 | Token* ErrorNodeImpl::getSymbol() const { 17 | return symbol; 18 | } 19 | 20 | void ErrorNodeImpl::setParent(RuleContext *parent_) { 21 | this->parent = parent_; 22 | } 23 | 24 | misc::Interval ErrorNodeImpl::getSourceInterval() { 25 | if (symbol == nullptr) { 26 | return misc::Interval::INVALID; 27 | } 28 | 29 | size_t tokenIndex = symbol->getTokenIndex(); 30 | return misc::Interval(tokenIndex, tokenIndex); 31 | } 32 | 33 | std::any ErrorNodeImpl::accept(ParseTreeVisitor *visitor) { 34 | return visitor->visitErrorNode(this); 35 | } 36 | 37 | std::string ErrorNodeImpl::getText() { 38 | return symbol->getText(); 39 | } 40 | 41 | std::string ErrorNodeImpl::toStringTree(Parser * /*parser*/, bool /*pretty*/) { 42 | return toString(); 43 | } 44 | 45 | std::string ErrorNodeImpl::toString() { 46 | if (symbol->getType() == Token::EOF) { 47 | return ""; 48 | } 49 | return symbol->getText(); 50 | } 51 | 52 | std::string ErrorNodeImpl::toStringTree(bool /*pretty*/) { 53 | return toString(); 54 | } 55 | -------------------------------------------------------------------------------- /lib/antlr4/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 ErrorNode { 25 | public: 26 | Token *symbol; 27 | 28 | explicit ErrorNodeImpl(Token *symbol) : ErrorNode(ParseTreeType::ERROR), symbol(symbol) {} 29 | 30 | virtual Token* getSymbol() const override; 31 | virtual void setParent(RuleContext *parent) override; 32 | virtual misc::Interval getSourceInterval() override; 33 | 34 | virtual std::any accept(ParseTreeVisitor *visitor) override; 35 | 36 | virtual std::string getText() override; 37 | virtual std::string toStringTree(Parser *parser, bool pretty = false) override; 38 | virtual std::string toString() override; 39 | virtual std::string toStringTree(bool pretty = false) override; 40 | }; 41 | 42 | } // namespace tree 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /lib/antlr4/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 | bool ParseTree::operator == (const ParseTree &other) const { 11 | return &other == this; 12 | } 13 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/tree/ParseTreeType.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 9 | 10 | #include "antlr4-common.h" 11 | 12 | namespace antlr4 { 13 | namespace tree { 14 | 15 | enum class ParseTreeType : size_t { 16 | TERMINAL = 1, 17 | ERROR = 2, 18 | RULE = 3, 19 | }; 20 | 21 | } // namespace tree 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | #include "support/Casts.h" 11 | 12 | #include "tree/IterativeParseTreeWalker.h" 13 | #include "tree/ParseTreeWalker.h" 14 | 15 | using namespace antlr4::tree; 16 | using namespace antlrcpp; 17 | 18 | static IterativeParseTreeWalker defaultWalker; 19 | ParseTreeWalker &ParseTreeWalker::DEFAULT = defaultWalker; 20 | 21 | void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const { 22 | if (ErrorNode::is(*t)) { 23 | listener->visitErrorNode(downCast(t)); 24 | return; 25 | } 26 | if (TerminalNode::is(*t)) { 27 | listener->visitTerminal(downCast(t)); 28 | return; 29 | } 30 | 31 | enterRule(listener, t); 32 | for (auto &child : t->children) { 33 | walk(listener, child); 34 | } 35 | exitRule(listener, t); 36 | } 37 | 38 | void ParseTreeWalker::enterRule(ParseTreeListener *listener, ParseTree *r) const { 39 | auto *ctx = downCast(r); 40 | listener->enterEveryRule(ctx); 41 | ctx->enterRule(listener); 42 | } 43 | 44 | void ParseTreeWalker::exitRule(ParseTreeListener *listener, ParseTree *r) const { 45 | auto *ctx = downCast(r); 46 | ctx->exitRule(listener); 47 | listener->exitEveryRule(ctx); 48 | } 49 | -------------------------------------------------------------------------------- /lib/antlr4/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 | static bool is(const tree::ParseTree &parseTree) { 16 | const auto treeType = parseTree.getTreeType(); 17 | return treeType == ParseTreeType::TERMINAL || treeType == ParseTreeType::ERROR; 18 | } 19 | 20 | static bool is(const tree::ParseTree *parseTree) { return parseTree != nullptr && is(*parseTree); } 21 | 22 | virtual Token* getSymbol() const = 0; 23 | 24 | /** Set the parent for this leaf node. 25 | * 26 | * Technically, this is not backward compatible as it changes 27 | * the interface but no one was able to create custom 28 | * TerminalNodes anyway so I'm adding as it improves internal 29 | * code quality. 30 | * 31 | * @since 4.7 32 | */ 33 | virtual void setParent(RuleContext *parent) = 0; 34 | 35 | protected: 36 | using ParseTree::ParseTree; 37 | }; 38 | 39 | } // namespace tree 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /lib/antlr4/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 | Token* TerminalNodeImpl::getSymbol() const { 17 | return symbol; 18 | } 19 | 20 | void TerminalNodeImpl::setParent(RuleContext *parent_) { 21 | this->parent = parent_; 22 | } 23 | 24 | misc::Interval TerminalNodeImpl::getSourceInterval() { 25 | if (symbol == nullptr) { 26 | return misc::Interval::INVALID; 27 | } 28 | 29 | size_t tokenIndex = symbol->getTokenIndex(); 30 | return misc::Interval(tokenIndex, tokenIndex); 31 | } 32 | 33 | std::any TerminalNodeImpl::accept(ParseTreeVisitor *visitor) { 34 | return visitor->visitTerminal(this); 35 | } 36 | 37 | std::string TerminalNodeImpl::getText() { 38 | return symbol->getText(); 39 | } 40 | 41 | std::string TerminalNodeImpl::toStringTree(Parser * /*parser*/, bool /*pretty*/) { 42 | return toString(); 43 | } 44 | 45 | std::string TerminalNodeImpl::toString() { 46 | if (symbol->getType() == Token::EOF) { 47 | return ""; 48 | } 49 | return symbol->getText(); 50 | } 51 | 52 | std::string TerminalNodeImpl::toStringTree(bool /*pretty*/) { 53 | return toString(); 54 | } 55 | -------------------------------------------------------------------------------- /lib/antlr4/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 TerminalNode { 14 | public: 15 | Token *symbol; 16 | 17 | explicit TerminalNodeImpl(Token *symbol) : TerminalNode(ParseTreeType::TERMINAL), symbol(symbol) {} 18 | 19 | virtual Token* getSymbol() const override; 20 | virtual void setParent(RuleContext *parent) override; 21 | virtual misc::Interval getSourceInterval() override; 22 | 23 | virtual std::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 | } // namespace tree 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/tree/xpath/XPathLexer.h: -------------------------------------------------------------------------------- 1 | 2 | // Generated from XPathLexer.g4 by ANTLR 4.13.1 3 | 4 | #pragma once 5 | 6 | 7 | #include "antlr4-runtime.h" 8 | 9 | 10 | 11 | 12 | class XPathLexer : public antlr4::Lexer { 13 | public: 14 | enum { 15 | TOKEN_REF = 1, RULE_REF = 2, ANYWHERE = 3, ROOT = 4, WILDCARD = 5, BANG = 6, 16 | ID = 7, STRING = 8 17 | }; 18 | 19 | explicit XPathLexer(antlr4::CharStream *input); 20 | 21 | ~XPathLexer() override; 22 | 23 | 24 | std::string getGrammarFileName() const override; 25 | 26 | const std::vector& getRuleNames() const override; 27 | 28 | const std::vector& getChannelNames() const override; 29 | 30 | const std::vector& getModeNames() const override; 31 | 32 | const antlr4::dfa::Vocabulary& getVocabulary() const override; 33 | 34 | antlr4::atn::SerializedATNView getSerializedATN() const override; 35 | 36 | const antlr4::atn::ATN& getATN() const override; 37 | 38 | void action(antlr4::RuleContext *context, size_t ruleIndex, size_t actionIndex) override; 39 | 40 | // By default the static state used to implement the lexer is lazily initialized during the first 41 | // call to the constructor. You can call this function if you wish to initialize the static state 42 | // ahead of time. 43 | static void initialize(); 44 | 45 | private: 46 | 47 | // Individual action functions triggered by action() above. 48 | void IDAction(antlr4::RuleContext *context, size_t actionIndex); 49 | 50 | // Individual semantic predicate functions triggered by sempred() above. 51 | 52 | }; 53 | 54 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/antlr4/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 | -------------------------------------------------------------------------------- /lib/lua/.gitignore: -------------------------------------------------------------------------------- 1 | /manual 2 | /testes 3 | all 4 | bugs 5 | ltests* 6 | lua.c 7 | makefile 8 | onelua.c 9 | README.md 10 | -------------------------------------------------------------------------------- /lib/lua/SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | Import('env') 4 | Import('env_luascript') 5 | 6 | env_lua = env_luascript.Clone() 7 | 8 | if env_lua['PLATFORM'] == 'posix': 9 | env_lua.Append(CPPDEFINES='LUA_USE_POSIX') 10 | 11 | if not env.msvc: 12 | env_lua['CFLAGS'].remove('-std=gnu11') 13 | env_lua.Append(CFLAGS=['-std=c99']) 14 | 15 | env_lua.add_source_files(env.modules_sources,'*.c') 16 | -------------------------------------------------------------------------------- /lib/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | #if defined(LUA_USE_APICHECK) 16 | #include 17 | #define api_check(l,e,msg) assert(e) 18 | #else /* for testing */ 19 | #define api_check(l,e,msg) ((void)(l), lua_assert((e) && msg)) 20 | #endif 21 | 22 | 23 | 24 | /* Increments 'L->top.p', checking for stack overflows */ 25 | #define api_incr_top(L) \ 26 | (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow")) 27 | 28 | 29 | /* 30 | ** macros that are executed whenever program enters the Lua core 31 | ** ('lua_lock') and leaves the core ('lua_unlock') 32 | */ 33 | #if !defined(lua_lock) 34 | #define lua_lock(L) ((void) 0) 35 | #define lua_unlock(L) ((void) 0) 36 | #endif 37 | 38 | 39 | 40 | /* 41 | ** If a call returns too many multiple returns, the callee may not have 42 | ** stack space to accommodate all results. In this case, this macro 43 | ** increases its stack space ('L->ci->top.p'). 44 | */ 45 | #define adjustresults(L,nres) \ 46 | { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \ 47 | L->ci->top.p = L->top.p; } 48 | 49 | 50 | /* Ensure the stack has at least 'n' elements */ 51 | #define api_checknelems(L,n) \ 52 | api_check(L, (n) < (L->top.p - L->ci->func.p), \ 53 | "not enough elements in the stack") 54 | 55 | 56 | /* Ensure the stack has at least 'n' elements to be popped. (Some 57 | ** functions only update a slot after checking it for popping, but that 58 | ** is only an optimization for a pop followed by a push.) 59 | */ 60 | #define api_checkpop(L,n) \ 61 | api_check(L, (n) < L->top.p - L->ci->func.p && \ 62 | L->tbclist.p < L->top.p - (n), \ 63 | "not enough free elements in the stack") 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /lib/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) \ 15 | (offsetof(CClosure, upvalue) + sizeof(TValue) * cast_uint(n)) 16 | 17 | #define sizeLclosure(n) \ 18 | (offsetof(LClosure, upvals) + sizeof(TValue *) * cast_uint(n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v.p != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC size_t luaF_protosize (Proto *p); 60 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 61 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 62 | int pc); 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /lib/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | 12 | #include "lprefix.h" 13 | 14 | 15 | #include 16 | 17 | #include "lua.h" 18 | 19 | #include "lualib.h" 20 | #include "lauxlib.h" 21 | #include "llimits.h" 22 | 23 | 24 | /* 25 | ** Standard Libraries. (Must be listed in the same ORDER of their 26 | ** respective constants LUA_K.) 27 | */ 28 | static const luaL_Reg stdlibs[] = { 29 | {LUA_GNAME, luaopen_base}, 30 | {LUA_LOADLIBNAME, luaopen_package}, 31 | {LUA_COLIBNAME, luaopen_coroutine}, 32 | {LUA_DBLIBNAME, luaopen_debug}, 33 | {LUA_IOLIBNAME, luaopen_io}, 34 | {LUA_MATHLIBNAME, luaopen_math}, 35 | {LUA_OSLIBNAME, luaopen_os}, 36 | {LUA_STRLIBNAME, luaopen_string}, 37 | {LUA_TABLIBNAME, luaopen_table}, 38 | {LUA_UTF8LIBNAME, luaopen_utf8}, 39 | {NULL, NULL} 40 | }; 41 | 42 | 43 | /* 44 | ** require and preload selected standard libraries 45 | */ 46 | LUALIB_API void luaL_openselectedlibs (lua_State *L, int load, int preload) { 47 | int mask; 48 | const luaL_Reg *lib; 49 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 50 | for (lib = stdlibs, mask = 1; lib->name != NULL; lib++, mask <<= 1) { 51 | if (load & mask) { /* selected? */ 52 | luaL_requiref(L, lib->name, lib->func, 1); /* require library */ 53 | lua_pop(L, 1); /* remove result from the stack */ 54 | } 55 | else if (preload & mask) { /* selected? */ 56 | lua_pushcfunction(L, lib->func); 57 | lua_setfield(L, -2, lib->name); /* add library to PRELOAD table */ 58 | } 59 | } 60 | lua_assert((mask >> 1) == LUA_UTF8LIBK); 61 | lua_pop(L, 1); /* remove PRELOAD table */ 62 | } 63 | 64 | -------------------------------------------------------------------------------- /lib/lua/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /lib/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /lib/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /lib/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | #define LUA_GLIBK 1 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_LOADLIBNAME "package" 21 | #define LUA_LOADLIBK (LUA_GLIBK << 1) 22 | LUAMOD_API int (luaopen_package) (lua_State *L); 23 | 24 | 25 | #define LUA_COLIBNAME "coroutine" 26 | #define LUA_COLIBK (LUA_LOADLIBK << 1) 27 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 28 | 29 | #define LUA_DBLIBNAME "debug" 30 | #define LUA_DBLIBK (LUA_COLIBK << 1) 31 | LUAMOD_API int (luaopen_debug) (lua_State *L); 32 | 33 | #define LUA_IOLIBNAME "io" 34 | #define LUA_IOLIBK (LUA_DBLIBK << 1) 35 | LUAMOD_API int (luaopen_io) (lua_State *L); 36 | 37 | #define LUA_MATHLIBNAME "math" 38 | #define LUA_MATHLIBK (LUA_IOLIBK << 1) 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_OSLIBNAME "os" 42 | #define LUA_OSLIBK (LUA_MATHLIBK << 1) 43 | LUAMOD_API int (luaopen_os) (lua_State *L); 44 | 45 | #define LUA_STRLIBNAME "string" 46 | #define LUA_STRLIBK (LUA_OSLIBK << 1) 47 | LUAMOD_API int (luaopen_string) (lua_State *L); 48 | 49 | #define LUA_TABLIBNAME "table" 50 | #define LUA_TABLIBK (LUA_STRLIBK << 1) 51 | LUAMOD_API int (luaopen_table) (lua_State *L); 52 | 53 | #define LUA_UTF8LIBNAME "utf8" 54 | #define LUA_UTF8LIBK (LUA_TABLIBK << 1) 55 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 56 | 57 | 58 | /* open selected libraries */ 59 | LUALIB_API void (luaL_openselectedlibs) (lua_State *L, int load, int preload); 60 | 61 | /* open all libraries */ 62 | #define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0) 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /lib/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include 11 | 12 | #include "llimits.h" 13 | #include "lobject.h" 14 | #include "lzio.h" 15 | 16 | 17 | /* data to catch conversion errors */ 18 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 19 | 20 | #define LUAC_INT 0x5678 21 | #define LUAC_NUM cast_num(370.5) 22 | 23 | /* 24 | ** Encode major-minor version in one byte, one nibble for each 25 | */ 26 | #define LUAC_VERSION (LUA_VERSION_MAJOR_N*16+LUA_VERSION_MINOR_N) 27 | 28 | #define LUAC_FORMAT 0 /* this is the official format */ 29 | 30 | 31 | /* load one chunk; from lundump.c */ 32 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name, 33 | int fixed); 34 | 35 | /* dump one chunk; from ldump.c */ 36 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 37 | void* data, int strip); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= cast_sizet(i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | LUAI_FUNC const void *luaZ_getaddr (ZIO* z, size_t n); 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; /* reader function */ 60 | void *data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /lua_script_resource_formate_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "core/io/resource_loader.h" 23 | 24 | class LuaScriptResourceFormatLoader : public ResourceFormatLoader { 25 | public: 26 | LuaScriptResourceFormatLoader(); 27 | ~LuaScriptResourceFormatLoader(); 28 | 29 | Ref load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override; 30 | void get_recognized_extensions(List *p_extensions) const override; 31 | bool handles_type(const String &p_type) const override; 32 | String get_resource_type(const String &p_path) const override; 33 | void get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types = false) override; 34 | }; 35 | -------------------------------------------------------------------------------- /lua_script_resource_formate_saver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "core/io/resource_saver.h" 23 | 24 | class LuaScriptResourceFormatSaver : public ResourceFormatSaver { 25 | public: 26 | LuaScriptResourceFormatSaver(); 27 | virtual ~LuaScriptResourceFormatSaver(); 28 | 29 | Error save(const Ref &p_resource, const String &p_path, uint32_t p_flags = 0) override; 30 | void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const override; 31 | bool recognize(const Ref &p_resource) const override; 32 | }; 33 | -------------------------------------------------------------------------------- /parser/SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | Import('env') 4 | Import('env_luascript') 5 | 6 | env_parser = env_luascript.Clone() 7 | 8 | env_parser.Append(CPPPATH = ['../lib/antlr4']) 9 | 10 | # Enable exceptions for ANTLR4 11 | if env_parser.msvc: 12 | env_parser.Append(CPPDEFINES=[("_HAS_EXCEPTIONS", 1)]) 13 | else: 14 | env_parser.Append(CCFLAGS=["-fexceptions"]) 15 | 16 | env_parser.add_source_files(env.modules_sources,'ast/*.cpp') 17 | env_parser.add_source_files(env.modules_sources,'generated/*.cpp') 18 | env_parser.add_source_files(env.modules_sources,'*.cpp') 19 | -------------------------------------------------------------------------------- /parser/ast/abstract_syntax_tree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #include "abstract_syntax_tree.h" 21 | 22 | namespace parser::ast { 23 | 24 | AbstractSyntaxTree::AbstractSyntaxTree(Methods &&methods, bool valid) : 25 | methods{ methods }, 26 | valid{ valid } { 27 | } 28 | 29 | AbstractSyntaxTree::~AbstractSyntaxTree() { 30 | } 31 | 32 | Methods AbstractSyntaxTree::get_methods() const { 33 | return this->methods; 34 | } 35 | 36 | bool AbstractSyntaxTree::is_valid() { 37 | return this->valid; 38 | } 39 | 40 | } // namespace parser::ast 41 | -------------------------------------------------------------------------------- /parser/ast/antlr_tree_walker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "tree_walker.h" 23 | 24 | #include "../generated/LuaBaseListener.h" 25 | 26 | #include 27 | 28 | namespace parser::ast { 29 | 30 | class AntlrTreeWalker : public TreeWalker, generated::LuaBaseListener { 31 | public: 32 | AntlrTreeWalker(); 33 | ~AntlrTreeWalker(); 34 | 35 | [[nodiscard]] AST walk(const std::string_view chunk) override; 36 | 37 | private: 38 | void exitStatFunction(generated::LuaParser::StatFunctionContext *ctx) override; 39 | 40 | private: 41 | Methods methods; 42 | }; 43 | 44 | } // namespace parser::ast -------------------------------------------------------------------------------- /parser/ast/tree_walker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "abstract_syntax_tree.h" 23 | 24 | #include 25 | #include 26 | 27 | namespace parser::ast { 28 | 29 | class TreeWalker { 30 | public: 31 | virtual ~TreeWalker() = default; 32 | 33 | virtual AST walk(const std::string_view chunk) = 0; 34 | }; 35 | 36 | } // namespace parser::ast 37 | -------------------------------------------------------------------------------- /parser/generated/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | DisableFormat: true 5 | SortIncludes: false 6 | ... 7 | 8 | -------------------------------------------------------------------------------- /parser/generated/LuaBaseListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from /Users/perbone/Work/luascript/Lua.g4 by ANTLR 4.10.1 3 | 4 | 5 | #include "LuaBaseListener.h" 6 | 7 | 8 | using namespace parser::generated; 9 | 10 | -------------------------------------------------------------------------------- /parser/generated/LuaListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from /Users/perbone/Work/luascript/Lua.g4 by ANTLR 4.10.1 3 | 4 | 5 | #include "LuaListener.h" 6 | 7 | 8 | using namespace parser::generated; 9 | 10 | -------------------------------------------------------------------------------- /parser/parser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #include "parser.h" 21 | 22 | #include "ast/antlr_tree_walker.h" 23 | 24 | namespace parser { 25 | 26 | Parser::Parser() : 27 | treeWalker{ std::make_unique() } { 28 | } 29 | 30 | Parser::~Parser() { 31 | } 32 | 33 | ast::AST Parser::parse(const std::string_view chunk) const { 34 | return treeWalker->walk(chunk); 35 | } 36 | 37 | } // namespace parser 38 | -------------------------------------------------------------------------------- /parser/parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "ast/tree_walker.h" 23 | 24 | #include 25 | #include 26 | 27 | namespace parser { 28 | 29 | class Parser { 30 | public: 31 | Parser(); 32 | ~Parser(); 33 | 34 | ast::AST parse(const std::string_view chunk) const; 35 | 36 | private: 37 | std::unique_ptr treeWalker; 38 | }; 39 | 40 | } // namespace parser -------------------------------------------------------------------------------- /register_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuaScript 3 | * https://github.com/perbone/luascrip/ 4 | * 5 | * Copyright 2017-2024 Paulo Perbone 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "modules/register_module_types.h" 23 | 24 | void initialize_luascript_module(ModuleInitializationLevel p_level); 25 | void uninitialize_luascript_module(ModuleInitializationLevel p_level); 26 | --------------------------------------------------------------------------------