├── .github └── workflows │ └── check-commit.yml ├── .gitignore ├── .swiftlint.yml ├── CHANGELOG.md ├── Examples ├── Example.graphql ├── Example.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ └── Example.xcscheme └── Example │ └── Sources │ └── Command.swift ├── LICENSE ├── Makefile ├── Package.swift ├── README.md ├── Resources ├── GraphQLLanguage.png └── LICENSE ├── Sources └── GraphQLLanguage │ ├── Builder.swift │ ├── Generated │ ├── GraphQLBaseListener.swift │ ├── GraphQLLexer.swift │ ├── GraphQLLexerATN.swift │ ├── GraphQLListener.swift │ ├── GraphQLParser.swift │ └── GraphQLParserATN.swift │ ├── Language.swift │ ├── Parsing.swift │ ├── Rewriter.swift │ ├── Source.swift │ ├── String.swift │ └── Visitor.swift ├── Tests └── GraphQLLanguageTests │ ├── BuilderTest.swift │ ├── ParsingTest.swift │ ├── RewriterTest.swift │ ├── SourceTest.swift │ └── VisitorTest.swift └── Vendor └── antlr4 ├── LICENSE.txt └── runtime └── Swift ├── .gitignore ├── Package.swift └── Sources ├── Antlr4 ├── ANTLRErrorListener.swift ├── ANTLRErrorStrategy.swift ├── ANTLRFileStream.swift ├── ANTLRInputStream.swift ├── BailErrorStrategy.swift ├── BaseErrorListener.swift ├── BufferedTokenStream.swift ├── CharStream.swift ├── CommonToken.swift ├── CommonTokenFactory.swift ├── CommonTokenStream.swift ├── ConsoleErrorListener.swift ├── DefaultErrorStrategy.swift ├── DiagnosticErrorListener.swift ├── FailedPredicateException.swift ├── InputMismatchException.swift ├── IntStream.swift ├── InterpreterRuleContext.swift ├── Lexer.swift ├── LexerInterpreter.swift ├── LexerNoViableAltException.swift ├── ListTokenSource.swift ├── NoViableAltException.swift ├── Parser.swift ├── ParserInterpreter.swift ├── ParserRuleContext.swift ├── ProxyErrorListener.swift ├── RecognitionException.swift ├── Recognizer.swift ├── RuleContext.swift ├── RuntimeMetaData.swift ├── Token.swift ├── TokenFactory.swift ├── TokenSource.swift ├── TokenStream.swift ├── TokenStreamRewriter.swift ├── UnbufferedCharStream.swift ├── UnbufferedTokenStream.swift ├── VocabularySingle.swift ├── WritableToken.swift ├── atn │ ├── ATN.swift │ ├── ATNConfig.swift │ ├── ATNConfigSet.swift │ ├── ATNDeserializationOptions.swift │ ├── ATNDeserializer.swift │ ├── ATNSimulator.swift │ ├── ATNState.swift │ ├── ATNType.swift │ ├── AbstractPredicateTransition.swift │ ├── ActionTransition.swift │ ├── AmbiguityInfo.swift │ ├── ArrayPredictionContext.swift │ ├── AtomTransition.swift │ ├── BasicBlockStartState.swift │ ├── BasicState.swift │ ├── BlockEndState.swift │ ├── BlockStartState.swift │ ├── ContextSensitivityInfo.swift │ ├── DecisionEventInfo.swift │ ├── DecisionInfo.swift │ ├── DecisionState.swift │ ├── DefaultATNConfig.swift │ ├── EmptyPredictionContext.swift │ ├── EpsilonTransition.swift │ ├── ErrorInfo.swift │ ├── LL1Analyzer.swift │ ├── LexerATNConfig.swift │ ├── LexerATNSimulator.swift │ ├── LexerAction.swift │ ├── LexerActionExecutor.swift │ ├── LexerActionType.swift │ ├── LexerChannelAction.swift │ ├── LexerCustomAction.swift │ ├── LexerIndexedCustomAction.swift │ ├── LexerModeAction.swift │ ├── LexerMoreAction.swift │ ├── LexerPopModeAction.swift │ ├── LexerPushModeAction.swift │ ├── LexerSkipAction.swift │ ├── LexerTypeAction.swift │ ├── LookaheadEventInfo.swift │ ├── LookupATNConfig.swift │ ├── LookupDictionary.swift │ ├── LoopEndState.swift │ ├── NotSetTransition.swift │ ├── ParseInfo.swift │ ├── ParserATNSimulator.swift │ ├── PlusBlockStartState.swift │ ├── PlusLoopbackState.swift │ ├── PrecedencePredicateTransition.swift │ ├── PredicateEvalInfo.swift │ ├── PredicateTransition.swift │ ├── PredictionContext.swift │ ├── PredictionContextCache.swift │ ├── PredictionMode.swift │ ├── ProfilingATNSimulator.swift │ ├── RangeTransition.swift │ ├── RuleStartState.swift │ ├── RuleStopState.swift │ ├── RuleTransition.swift │ ├── SemanticContext.swift │ ├── SetTransition.swift │ ├── SingletonPredictionContext.swift │ ├── StarBlockStartState.swift │ ├── StarLoopEntryState.swift │ ├── StarLoopbackState.swift │ ├── TokensStartState.swift │ ├── Transition.swift │ └── WildcardTransition.swift ├── dfa │ ├── DFA.swift │ ├── DFASerializer.swift │ ├── DFAState.swift │ └── LexerDFASerializer.swift ├── misc │ ├── BitSet.swift │ ├── DoubleKeyMap.swift │ ├── IntSet.swift │ ├── InterpreterDataReader.swift │ ├── Interval.swift │ ├── IntervalSet.swift │ ├── MultiMap.swift │ ├── MurmurHash.swift │ ├── Utils.swift │ ├── exception │ │ ├── ANTLRError.swift │ │ └── ANTLRException.swift │ ├── extension │ │ ├── ArrayExtension.swift │ │ ├── CharacterExtension.swift │ │ ├── IntStreamExtension.swift │ │ ├── StringExtension.swift │ │ ├── TokenExtension.swift │ │ └── UUIDExtension.swift │ └── utils │ │ ├── CommonUtil.swift │ │ ├── Mutex.swift │ │ └── Stack.swift └── tree │ ├── AbstractParseTreeVisitor.swift │ ├── ErrorNode.swift │ ├── ParseTree.swift │ ├── ParseTreeListener.swift │ ├── ParseTreeProperty.swift │ ├── ParseTreeVisitor.swift │ ├── ParseTreeWalker.swift │ ├── RuleNode.swift │ ├── SyntaxTree.swift │ ├── TerminalNode.swift │ ├── TerminalNodeImpl.swift │ ├── Tree.swift │ ├── Trees.swift │ └── pattern │ ├── Chunk.swift │ ├── ParseTreeMatch.swift │ ├── ParseTreePattern.swift │ ├── ParseTreePatternMatcher.swift │ ├── RuleTagToken.swift │ ├── TagChunk.swift │ ├── TextChunk.swift │ └── TokenTagToken.swift ├── Info-IOS.plist └── Info-OSX.plist /.github/workflows/check-commit.yml: -------------------------------------------------------------------------------- 1 | name: check-commit 2 | 3 | on: 4 | - push 5 | - pull_request 6 | 7 | jobs: 8 | check-commit: 9 | runs-on: macOS-11 10 | 11 | steps: 12 | - name: Use Xcode 13.1 13 | run: | 14 | sudo xcode-select -s /Applications/Xcode_13.1.app/Contents/Developer 15 | 16 | - name: Current platform versions 17 | run: | 18 | sw_vers 19 | xcodebuild -version 20 | swift --version 21 | swiftlint version 22 | 23 | - name: Checkout default branch 24 | uses: actions/checkout@v2 25 | 26 | - name: Run lint 27 | run: | 28 | make lint 29 | 30 | - name: Run test 31 | run: | 32 | make test 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.interp 2 | *.tokens 3 | .DS_Store 4 | .antlr/ 5 | .idea/ 6 | xcuserdata/ 7 | project.xcworkspace/ 8 | /*.xcodeproj 9 | /.build 10 | /.swiftpm 11 | /Vendor/antlr4-graphql-grammar 12 | /antlr4.jar 13 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | included: 2 | - Package.swift 3 | - Sources 4 | - Tests 5 | 6 | excluded: 7 | - Vendor 8 | - Sources/GraphQLLanguage/Generated 9 | 10 | disabled_rules: 11 | - cyclomatic_complexity 12 | - file_length 13 | - function_body_length 14 | - function_parameter_count 15 | - identifier_name 16 | - line_length 17 | - nesting 18 | - opening_brace 19 | - todo 20 | - type_body_length 21 | 22 | opt_in_rules: 23 | - anyobject_protocol 24 | - closure_spacing 25 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 0.3.1 5 | ----- 6 | 7 | Address crash problem and minor updates. 8 | 9 | - Crash when getting `BuildError.debugDescription` (#5) 10 | - Lint code. 11 | 12 | 0.3.0 13 | ----- 14 | 15 | Update API for error handling. 16 | 17 | - Allow for rewriting operations to throw errors (#4) 18 | 19 | 0.2.1 20 | ----- 21 | 22 | Minor changes to suppress various warnings. 23 | 24 | - Suppress warnings in ANTLR generated code (#3). 25 | - Remove excluded resources causing warnings (#2). 26 | 27 | 0.2.0 28 | ----- 29 | 30 | - Add public initializers to Language definitions (#1). 31 | - Update ANTLR4 to 4.9.3. 32 | 33 | 34 | 0.1.0 35 | ----- 36 | 37 | - Initial release with a version tag. 38 | -------------------------------------------------------------------------------- /Examples/Example.graphql: -------------------------------------------------------------------------------- 1 | """ 2 | Example of object type definition. 3 | """ 4 | type Cat { 5 | name: String! 6 | meowing: Boolean 7 | } 8 | 9 | # Example of fragment 10 | fragment cat on Cat { 11 | name 12 | meowing 13 | } 14 | 15 | # Example of query 16 | query($name: String! = "maru", $cute: Boolean! = true) { 17 | cats(name: $name) { 18 | ... cat @include(if: $cute) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 44 | 46 | 52 | 53 | 54 | 55 | 58 | 59 | 62 | 63 | 66 | 67 | 68 | 69 | 75 | 77 | 83 | 84 | 85 | 86 | 88 | 89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Examples/Example/Sources/Command.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Command.swift 3 | // Example 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20. 6 | // 7 | 8 | import ArgumentParser 9 | import Foundation 10 | import GraphQLLanguage 11 | 12 | @main 13 | struct Command: ParsableCommand { 14 | static var configuration = CommandConfiguration( 15 | abstract: "An example command-line tool for using GraphQLLanguage package", 16 | subcommands: [ 17 | Parse.self, 18 | RemoveDirectives.self], 19 | defaultSubcommand: Parse.self) 20 | 21 | struct CommonOptions: ParsableArguments { 22 | @Option(name: .shortAndLong, help: "Path to the GraphQL file") 23 | var file: String 24 | } 25 | } 26 | 27 | extension Command { 28 | struct Parse: ParsableCommand { 29 | static var configuration = CommandConfiguration( 30 | abstract: "Parse given GraphQL file and print each defintion") 31 | 32 | @OptionGroup 33 | var options: CommonOptions 34 | 35 | mutating func run() throws { 36 | let source = try Source(atPath: options.file) 37 | let document = try Document.parsing(source) 38 | for definition in document.definitions { 39 | print(definition) 40 | } 41 | } 42 | } 43 | 44 | struct RemoveDirectives: ParsableCommand { 45 | static var configuration = CommandConfiguration( 46 | abstract: "Rewrite given GraphQL file and print the one without any directives") 47 | 48 | @OptionGroup 49 | var options: CommonOptions 50 | 51 | mutating func run() throws { 52 | let source = try Source(atPath: options.file) 53 | let document = try Document.parsing(source) 54 | let result = try document.rewrite { rewritable in 55 | switch rewritable { 56 | case is Directive: 57 | return "" 58 | default: 59 | return nil 60 | } 61 | } 62 | print(result) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020-2021 Yoshimasa Niwa 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CURL = curl 2 | GIT = git 3 | JAVA = java 4 | SWIFT = swift 5 | SWIFTLINT = swiftlint 6 | 7 | ANTLR4_JAR_URL = https://www.antlr.org/download/antlr-4.9.3-complete.jar 8 | ANTLR4_GRAPHQL_GRAMMAR_URL = https://github.com/niw/antlr4-graphql-grammar.git 9 | ANTLR4_GRAPHQL_GRAMMAR_COMMIT = ebfcdc12a6f0cbdb21ebb1e66a56afdfc1c1eec9 10 | 11 | .PHONY: all 12 | all: build 13 | 14 | .PHONY: clean 15 | clean: 16 | $(GIT) clean -dffX 17 | 18 | .PHONY: correct 19 | correct: 20 | $(SWIFTLINT) autocorrect 21 | 22 | .PHONY: lint 23 | lint: 24 | $(SWIFTLINT) 25 | 26 | antlr4.jar: 27 | $(CURL) -o "$@" $(ANTLR4_JAR_URL) 28 | 29 | Vendor/antlr4-graphql-grammar: 30 | $(GIT) clone $(ANTLR4_GRAPHQL_GRAMMAR_URL) "$@" 31 | $(GIT) -C "$@" checkout $(ANTLR4_GRAPHQL_GRAMMAR_COMMIT) 32 | touch "$@" 33 | 34 | Vendor/antlr4-graphql-grammar/src/main/antlr4/GraphQL.g4: Vendor/antlr4-graphql-grammar 35 | 36 | Sources/GraphQLLanguage/Generated: Vendor/antlr4-graphql-grammar/src/main/antlr4/GraphQL.g4 antlr4.jar 37 | $(JAVA) -jar antlr4.jar \ 38 | -o "$@" \ 39 | -message-format gnu \ 40 | -Dlanguage=Swift \ 41 | -DaccessLevel=internal \ 42 | -Xexact-output-dir \ 43 | "$<" 44 | touch "$@" 45 | 46 | .PHONY: grammar 47 | grammar: Sources/GraphQLLanguage/Generated 48 | 49 | .PHONY: test 50 | test: 51 | $(SWIFT) test 52 | 53 | .PHONY: build 54 | build: correct debug 55 | 56 | .PHONY: debug 57 | debug: Sources/*/*.swift 58 | $(SWIFT) build --configuration "$@" 59 | 60 | .PHONY: release 61 | release: Sources/*/*.swift 62 | $(SWIFT) build --configuration "$@" 63 | 64 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "GraphQLLanguage", 8 | products: [ 9 | .library( 10 | name: "GraphQLLanguage-Auto", 11 | targets: [ 12 | "GraphQLLanguage" 13 | ]), 14 | .library( 15 | name: "GraphQLLanguage", 16 | type: .dynamic, 17 | targets: [ 18 | "GraphQLLanguage" 19 | ]) 20 | ], 21 | targets: [ 22 | .target( 23 | name: "GraphQLLanguage", 24 | dependencies: [ 25 | .target(name: "Antlr4") 26 | ]), 27 | .target( 28 | name: "Antlr4", 29 | dependencies: [], 30 | path: "Vendor/antlr4/runtime/Swift/Sources/Antlr4"), 31 | .testTarget( 32 | name: "GraphQLLanguageTests", 33 | dependencies: [ 34 | .target(name: "GraphQLLanguage") 35 | ]) 36 | ] 37 | ) 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GraphQL Language 2 | ================ 3 | 4 | A simple GraphQL language parser library for Swift. 5 | 6 | ![GraphQL Language](Resources/GraphQLLanguage.png) 7 | 8 | This library provides a plain Swift representation of GraphQL language 9 | implemented by using [ANTLR4 GraphQL Grammar](https://github.com/niw/antlr4-graphql-grammar), 10 | that is a language independent implementation of ANTLR4 grammar for GraphQL language. 11 | 12 | Try it 13 | ------ 14 | 15 | Open `Examples/Example.xcodeproj` in Xcode and Run `Example` scheme. 16 | 17 | It builds a tiny command line tool and runs it for [Example.graphql](Examples/Example.graphql), 18 | then print Swift presentation of it. 19 | 20 | Usage 21 | ----- 22 | 23 | Add the following lines to your `Package.swift` or use Xcode “Add Package Dependency…” menu. 24 | 25 | ```swift 26 | // In your `Package.swift` 27 | 28 | dependencies: [ 29 | .package(name: "GraphQLLanguage", url: "https://github.com/niw/GraphQLLanguage", ...), 30 | ... 31 | ], 32 | targets: [ 33 | .target( 34 | name: ..., 35 | dependencies: [ 36 | .product(name: "GraphQLLanguage", package: "GraphQLLanguage"), 37 | ... 38 | ] 39 | ), 40 | ... 41 | ] 42 | ``` 43 | 44 | License 45 | ------- 46 | 47 | This library contains multiple products such as [ANTLR4 runtime](Vendor/antlr4). 48 | See license file under each directory. 49 | -------------------------------------------------------------------------------- /Resources/GraphQLLanguage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niw/GraphQLLanguage/121d5c716c204001f6b722752be26b1186d9ff03/Resources/GraphQLLanguage.png -------------------------------------------------------------------------------- /Resources/LICENSE: -------------------------------------------------------------------------------- 1 | https://github.com/graphql/graphql-spec 2 | 3 | GraphQL logo is licensed under Creative Commons Attribution 4.0 International License. 4 | https://creativecommons.org/licenses/by/4.0/ 5 | 6 | See also https://github.com/graphql/graphql-spec/issues/398 7 | -------------------------------------------------------------------------------- /Sources/GraphQLLanguage/Parsing.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Parsing.swift 3 | // GraphQLLanguage 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | import Antlr4 9 | 10 | private class BailErrorGraphQLLexer: GraphQLLexer { 11 | override func recover(_ e: LexerNoViableAltException) throws { 12 | throw ANTLRException.recognition(e: e) 13 | } 14 | } 15 | 16 | extension GraphQLParser { 17 | convenience init(_ inputStream: ANTLRInputStream) throws { 18 | let lexer = BailErrorGraphQLLexer(inputStream) 19 | let tokens = CommonTokenStream(lexer) 20 | 21 | try self.init(tokens) 22 | 23 | removeParseListeners() 24 | removeErrorListeners() 25 | setErrorHandler(BailErrorStrategy()) 26 | } 27 | } 28 | 29 | class ParseBuildContext: BuildContext { 30 | let source: Source 31 | let parser: GraphQLParser 32 | 33 | init(source: Source, parser: GraphQLParser) { 34 | self.source = source 35 | self.parser = parser 36 | } 37 | } 38 | 39 | extension LanguageNode { 40 | var parseBuildContext: ParseBuildContext? { 41 | buildLanguageContext?.buildContext as? ParseBuildContext 42 | } 43 | } 44 | 45 | extension Document { 46 | public static func parsing(_ source: Source) throws -> Self { 47 | let parser = try GraphQLParser(source.inputStream()) 48 | let document = try parser.document() 49 | return try document.build(with: ParseBuildContext(source: source, parser: parser)) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/GraphQLLanguage/Rewriter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Rewriter.swift 3 | // GraphQLLanguage 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | public typealias Rewritable = Visitable 9 | 10 | public protocol Rewriter { 11 | func rewrite(_ rewritable: Rewritable) throws -> String? 12 | } 13 | 14 | private struct BlockRewriter: Rewriter { 15 | var block: (Rewritable) throws -> String? 16 | 17 | func rewrite(_ rewritable: Rewritable) throws -> String? { 18 | try block(rewritable) 19 | } 20 | } 21 | 22 | private extension Collection { 23 | var range: Range { 24 | startIndex.. 31 | let string: String 32 | } 33 | 34 | let rewriter: Rewriter 35 | var rewritings: [Rewriting] = [] 36 | 37 | init(rewriter: Rewriter) { 38 | self.rewriter = rewriter 39 | } 40 | 41 | func visit(on visitable: Visitable) throws { 42 | guard let sourceRange = visitable.sourceRange else { 43 | return 44 | } 45 | 46 | guard let rewritingString = try rewriter.rewrite(visitable) else { 47 | return 48 | } 49 | 50 | let rewriting = Rewriting(range: sourceRange, string: rewritingString) 51 | rewritings.append(rewriting) 52 | } 53 | } 54 | 55 | enum RewriteError: Error { 56 | case unavailableSource 57 | case conflictedRewritings 58 | } 59 | 60 | extension Document { 61 | public func rewrite(with rewriter: Rewriter) throws -> String { 62 | guard let source = source else { 63 | throw RewriteError.unavailableSource 64 | } 65 | var unicodeScalars = source.unicodeScalars 66 | 67 | let rewritingVisitor = RewritingVisitor(rewriter: rewriter) 68 | try visit(with: rewritingVisitor) 69 | 70 | // Sort rewritings by each lower bounds. 71 | let rewritings = rewritingVisitor.rewritings.sorted { a, b in 72 | a.range.lowerBound < b.range.lowerBound 73 | } 74 | 75 | // Ensure if each lower bound doesn't overwrap with previous upper bound. 76 | var upperBound = unicodeScalars.startIndex 77 | for rewriting in rewritings { 78 | guard upperBound <= rewriting.range.lowerBound else { 79 | throw RewriteError.conflictedRewritings 80 | } 81 | upperBound = rewriting.range.upperBound 82 | } 83 | 84 | // Rewrite backwards. 85 | for rewriting in rewritings.reversed() { 86 | unicodeScalars.replaceSubrange(rewriting.range, with: rewriting.string.unicodeScalars) 87 | } 88 | 89 | return String(unicodeScalars) 90 | } 91 | 92 | public func rewrite(with rewriter: @escaping (Rewritable) throws -> String?) throws -> String { 93 | try rewrite(with: BlockRewriter(block: rewriter)) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Sources/GraphQLLanguage/Source.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Source.swift 3 | // GraphQLLanguage 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | import Antlr4 9 | 10 | public struct Source { 11 | public let string: String 12 | let unicodeScalars: [UnicodeScalar] 13 | 14 | public var name: String? 15 | 16 | public init(string: String) { 17 | self.string = string 18 | self.unicodeScalars = Array(string.unicodeScalars) 19 | } 20 | 21 | public init(atPath path: String, encoding: String.Encoding = .utf8) throws { 22 | self.init(string: try String(contentsOfFile: path, encoding: encoding)) 23 | } 24 | 25 | func inputStream() -> ANTLRInputStream { 26 | let inputStream = ANTLRInputStream(unicodeScalars, unicodeScalars.count) 27 | inputStream.name = name 28 | return inputStream 29 | } 30 | } 31 | 32 | extension Document { 33 | public var source: Source? { 34 | parseBuildContext?.source 35 | } 36 | } 37 | 38 | extension LanguageNode { 39 | var sourceRange: Range.Index>? { 40 | guard let parserRuleContext = buildLanguageContext?.parserRuleContext, 41 | let startOffset = parserRuleContext.getStart()?.getStartIndex(), 42 | let endOffset = parserRuleContext.getStop()?.getStopIndex() 43 | else { 44 | return nil 45 | } 46 | return startOffset..(_ unicodeScalarSequence: S) where S: Sequence, S.Element == Unicode.Scalar { 12 | var unicodeScalarView = UnicodeScalarView() 13 | unicodeScalarView.append(contentsOf: unicodeScalarSequence) 14 | self.init(unicodeScalarView) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/GraphQLLanguage/Visitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Visitor.swift 3 | // GraphQLLanguage 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | public typealias Visitable = LanguageNode 9 | 10 | public protocol Visitor { 11 | func visit(on visitable: Visitable) throws 12 | } 13 | 14 | private struct BlockVisitor: Visitor { 15 | var block: (Visitable) throws -> Void 16 | 17 | func visit(on visitable: Visitable) throws { 18 | try block(visitable) 19 | } 20 | } 21 | 22 | extension Visitable { 23 | public func visit(with visitor: Visitor) throws { 24 | // Use reflection to depth-first traverse `Visitable`. 25 | let mirror = Mirror(reflecting: self) 26 | 27 | for child in mirror.children { 28 | // Reveal `Optional` in `Any` by matching to `Optional` (`Any?`.) 29 | var childValue: Any 30 | switch child.value { 31 | case let optional as Any?: 32 | guard let value = optional else { 33 | // `.none` is not visitable. 34 | continue 35 | } 36 | childValue = value 37 | default: 38 | childValue = child.value 39 | } 40 | 41 | // These are known child field representation in each `Visitable` 42 | switch childValue { 43 | case let visitable as Visitable: 44 | try visitable.visit(with: visitor) 45 | case let array as [Visitable]: 46 | for visitable in array { 47 | try visitable.visit(with: visitor) 48 | } 49 | // See `ObjectValue` 50 | case let dictionary as [String: Visitable]: 51 | for (_, visitable) in dictionary { 52 | try visitable.visit(with: visitor) 53 | } 54 | default: 55 | break 56 | } 57 | } 58 | try visitor.visit(on: self) 59 | } 60 | 61 | public func visit(with visitor: @escaping (Visitable) throws -> Void) throws { 62 | try visit(with: BlockVisitor(block: visitor)) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Tests/GraphQLLanguageTests/ParsingTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ParsingTest.swift 3 | // GraphQLLanguageTests 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | import XCTest 9 | @testable import GraphQLLanguage 10 | 11 | final class ParsingTest: XCTestCase { 12 | func testDocumentParsing() { 13 | let source = Source(string: "type Cat") 14 | 15 | XCTAssertNoThrow(try Document.parsing(source)) 16 | } 17 | 18 | func testUnexpectedContext() { 19 | let source = Source(string: "query { cat(age: \(Int(Int32.max) + 1)) }") 20 | 21 | XCTAssertThrowsError(try Document.parsing(source)) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tests/GraphQLLanguageTests/RewriterTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RewriterTest.swift 3 | // GraphQLLanguageTests 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | import XCTest 9 | @testable import GraphQLLanguage 10 | 11 | final class RewriterTest: XCTestCase { 12 | func testRewriteDocument() throws { 13 | let source = Source(string: "type Cat @meow { cat: Cat @meow }") 14 | let document = try Document.parsing(source) 15 | 16 | let result = try document.rewrite { rewritable in 17 | switch rewritable { 18 | case is Directive: 19 | return "@meowmeow" 20 | default: 21 | return nil 22 | } 23 | } 24 | 25 | XCTAssertEqual(result, "type Cat @meowmeow { cat: Cat @meowmeow }") 26 | } 27 | 28 | func testRewriteDocumentWithoutRewritings() throws { 29 | let source = Source(string: "type Cat") 30 | let document = try Document.parsing(source) 31 | 32 | let result = try document.rewrite { _ in 33 | return nil 34 | } 35 | 36 | XCTAssertEqual(result, source.string) 37 | } 38 | 39 | func testRewriteDocumentWithConflictedRewritings() throws { 40 | let source = Source(string: "type Cat") 41 | let document = try Document.parsing(source) 42 | 43 | XCTAssertThrowsError(try document.rewrite { _ in return "rewriting" }) 44 | } 45 | 46 | func testRewriteDocumentWithRewritingEntireDocument() throws { 47 | let source = Source(string: "type Cat") 48 | let document = try Document.parsing(source) 49 | 50 | let result = try document.rewrite { rewritable in 51 | switch rewritable { 52 | case is Document: 53 | return "meow" 54 | default: 55 | return nil 56 | } 57 | } 58 | 59 | XCTAssertEqual(result, "meow") 60 | } 61 | 62 | func testThrowingRewriter() throws { 63 | let source = Source(string: "type Cat") 64 | let document = try Document.parsing(source) 65 | 66 | enum Foo: Error { 67 | case bar 68 | } 69 | 70 | do { 71 | _ = try document.rewrite { _ in 72 | throw Foo.bar 73 | } 74 | XCTFail("Expected exception") 75 | } catch Foo.bar { 76 | // Pass 77 | } catch { 78 | XCTFail("Expected Foo.bar, got \(error)") 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Tests/GraphQLLanguageTests/SourceTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SourceTest.swift 3 | // GraphQLLanguageTests 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | import XCTest 9 | @testable import GraphQLLanguage 10 | 11 | final class SourceTest: XCTestCase { 12 | func testSourceUnicodeScalars() throws { 13 | let source = Source(string: "type Cat @meow") 14 | let sourceUnicodeScalars = source.unicodeScalars 15 | let document = try Document.parsing(source) 16 | 17 | let objectTypeDefinition = try XCTUnwrap(document.definitions.first as? ObjectTypeDefinition) 18 | let objectTypeDefinitionRange = try XCTUnwrap(objectTypeDefinition.sourceRange) 19 | let objectTypeDefinitionString = try XCTUnwrap(objectTypeDefinition.sourceString) 20 | 21 | XCTAssertEqual(objectTypeDefinitionRange.startIndex, sourceUnicodeScalars.startIndex) 22 | XCTAssertEqual(objectTypeDefinitionRange.endIndex, sourceUnicodeScalars.endIndex) 23 | XCTAssertEqual(objectTypeDefinitionString, "type Cat @meow") 24 | 25 | let directive = try XCTUnwrap(objectTypeDefinition.directives?.first) 26 | let directiveRange = try XCTUnwrap(directive.sourceRange) 27 | let directiveString = try XCTUnwrap(directive.sourceString) 28 | 29 | XCTAssertEqual(directiveRange.startIndex, sourceUnicodeScalars.index(sourceUnicodeScalars.startIndex, offsetBy: 9)) 30 | XCTAssertEqual(directiveRange.endIndex, sourceUnicodeScalars.endIndex) 31 | XCTAssertEqual(directiveString, "@meow") 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tests/GraphQLLanguageTests/VisitorTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VisitorTest.swift 3 | // GraphQLLanguageTests 4 | // 5 | // Created by Yoshimasa Niwa on 12/24/20 6 | // 7 | 8 | import XCTest 9 | @testable import GraphQLLanguage 10 | 11 | final class VisitorTest: XCTestCase { 12 | func testVisitDocument() throws { 13 | let source = Source(string: "query ($cat1: Cat = { cat: 1 }, $cat2: Cat = 2) { cat }") 14 | let document = try Document.parsing(source) 15 | 16 | var visited: [Visitable] = [] 17 | try document.visit { visitable in 18 | visited.append(visitable) 19 | } 20 | 21 | let visitedNames = visited.map { node in 22 | String(describing: Mirror(reflecting: node).subjectType) 23 | } 24 | XCTAssertEqual(visitedNames, [ 25 | "Variable", "NamedType", "IntValue", "ObjectValue", "VariableDefinition", 26 | "Variable", "NamedType", "IntValue", "VariableDefinition", 27 | "Field", 28 | "OperationDefinition", 29 | "Document" 30 | ]) 31 | } 32 | 33 | func testThrowingVisitor() throws { 34 | let source = Source(string: "type Cat") 35 | let document = try Document.parsing(source) 36 | 37 | enum Foo: Error { 38 | case bar 39 | } 40 | 41 | do { 42 | _ = try document.visit { _ in 43 | throw Foo.bar 44 | } 45 | XCTFail("Expected exception") 46 | } catch Foo.bar { 47 | // Pass 48 | } catch { 49 | XCTFail("Expected Foo.bar, got \(error)") 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Vendor/antlr4/LICENSE.txt: -------------------------------------------------------------------------------- 1 | [The "BSD 3-clause license"] 2 | Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | ===== 29 | 30 | MIT License for codepointat.js from https://git.io/codepointat 31 | MIT License for fromcodepoint.js from https://git.io/vDW1m 32 | 33 | Copyright Mathias Bynens 34 | 35 | Permission is hereby granted, free of charge, to any person obtaining 36 | a copy of this software and associated documentation files (the 37 | "Software"), to deal in the Software without restriction, including 38 | without limitation the rights to use, copy, modify, merge, publish, 39 | distribute, sublicense, and/or sell copies of the Software, and to 40 | permit persons to whom the Software is furnished to do so, subject to 41 | the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be 44 | included in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 47 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 48 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 49 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 50 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 51 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 52 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/.gitignore: -------------------------------------------------------------------------------- 1 | .build/ 2 | Antlr4.xcodeproj/ 3 | xcuserdata/ 4 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.0 2 | // Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | // Use of this file is governed by the BSD 3-clause license that 4 | // can be found in the LICENSE.txt file in the project root. 5 | 6 | import PackageDescription 7 | 8 | let package = Package( 9 | name: "Antlr4", 10 | products: [ 11 | .library( 12 | name: "Antlr4", 13 | type: .dynamic, 14 | targets: ["Antlr4"]), 15 | ], 16 | targets: [ 17 | .target( 18 | name: "Antlr4", 19 | dependencies: []), 20 | ] 21 | ) 22 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/ANTLRFileStream.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// This is an _org.antlr.v4.runtime.ANTLRInputStream_ that is loaded from a file all at once 6 | /// when you construct the object. 7 | /// 8 | 9 | import Foundation 10 | 11 | public class ANTLRFileStream: ANTLRInputStream { 12 | private let fileName: String 13 | 14 | public init(_ fileName: String, _ encoding: String.Encoding? = nil) throws { 15 | self.fileName = fileName 16 | let fileContents = try String(contentsOfFile: fileName, encoding: encoding ?? .utf8) 17 | let data = Array(fileContents.unicodeScalars) 18 | super.init(data, data.count) 19 | } 20 | 21 | override 22 | public func getSourceName() -> String { 23 | return fileName 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/BailErrorStrategy.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// 10 | /// This implementation of _org.antlr.v4.runtime.ANTLRErrorStrategy_ responds to syntax errors 11 | /// by immediately canceling the parse operation with a 12 | /// _org.antlr.v4.runtime.misc.ParseCancellationException_. The implementation ensures that the 13 | /// _org.antlr.v4.runtime.ParserRuleContext#exception_ field is set for all parse tree nodes 14 | /// that were not completed prior to encountering the error. 15 | /// 16 | /// This error strategy is useful in the following scenarios. 17 | /// 18 | /// * __Two-stage parsing:__ This error strategy allows the first 19 | /// stage of two-stage parsing to immediately terminate if an error is 20 | /// encountered, and immediately fall back to the second stage. In addition to 21 | /// avoiding wasted work by attempting to recover from errors here, the empty 22 | /// implementation of _org.antlr.v4.runtime.BailErrorStrategy#sync_ improves the performance of 23 | /// the first stage. 24 | /// 25 | /// * __Silent validation:__ When syntax errors are not being 26 | /// reported or logged, and the parse result is simply ignored if errors occur, 27 | /// the _org.antlr.v4.runtime.BailErrorStrategy_ avoids wasting work on recovering from errors 28 | /// when the result will be ignored either way. 29 | /// 30 | /// `myparser.setErrorHandler(new BailErrorStrategy());` 31 | /// 32 | /// - seealso: org.antlr.v4.runtime.Parser#setErrorHandler(org.antlr.v4.runtime.ANTLRErrorStrategy) 33 | /// 34 | /// 35 | open class BailErrorStrategy: DefaultErrorStrategy { 36 | public override init() { 37 | } 38 | 39 | /// 40 | /// Instead of recovering from exception `e`, re-throw it wrapped 41 | /// in a _org.antlr.v4.runtime.misc.ParseCancellationException_ so it is not caught by the 42 | /// rule function catches. Use _Exception#getCause()_ to get the 43 | /// original _org.antlr.v4.runtime.RecognitionException_. 44 | /// 45 | override open func recover(_ recognizer: Parser, _ e: RecognitionException) throws { 46 | var context = recognizer.getContext() 47 | while let contextWrap = context { 48 | contextWrap.exception = e 49 | context = (contextWrap.getParent() as? ParserRuleContext) 50 | } 51 | 52 | throw ANTLRException.parseCancellation(e: e) 53 | } 54 | 55 | /// 56 | /// Make sure we don't attempt to recover inline; if the parser 57 | /// successfully recovers, it won't throw an exception. 58 | /// 59 | override 60 | open func recoverInline(_ recognizer: Parser) throws -> Token { 61 | let e = InputMismatchException(recognizer) 62 | var context = recognizer.getContext() 63 | while let contextWrap = context { 64 | contextWrap.exception = e 65 | context = (contextWrap.getParent() as? ParserRuleContext) 66 | } 67 | 68 | throw ANTLRException.parseCancellation(e: e) 69 | } 70 | 71 | /// 72 | /// Make sure we don't attempt to recover from problems in subrules. 73 | /// 74 | override 75 | open func sync(_ recognizer: Parser) { 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Provides an empty default implementation of _org.antlr.v4.runtime.ANTLRErrorListener_. The 10 | /// default implementation of each method does nothing, but can be overridden as 11 | /// necessary. 12 | /// 13 | /// - Sam Harwell 14 | /// 15 | 16 | open class BaseErrorListener: ANTLRErrorListener { 17 | public init() { 18 | } 19 | 20 | open func syntaxError(_ recognizer: Recognizer, 21 | _ offendingSymbol: AnyObject?, 22 | _ line: Int, 23 | _ charPositionInLine: Int, 24 | _ msg: String, 25 | _ e: AnyObject? 26 | ) { 27 | } 28 | 29 | 30 | open func reportAmbiguity(_ recognizer: Parser, 31 | _ dfa: DFA, 32 | _ startIndex: Int, 33 | _ stopIndex: Int, 34 | _ exact: Bool, 35 | _ ambigAlts: BitSet, 36 | _ configs: ATNConfigSet) { 37 | } 38 | 39 | 40 | open func reportAttemptingFullContext(_ recognizer: Parser, 41 | _ dfa: DFA, 42 | _ startIndex: Int, 43 | _ stopIndex: Int, 44 | _ conflictingAlts: BitSet?, 45 | _ configs: ATNConfigSet) { 46 | } 47 | 48 | 49 | open func reportContextSensitivity(_ recognizer: Parser, 50 | _ dfa: DFA, 51 | _ startIndex: Int, 52 | _ stopIndex: Int, 53 | _ prediction: Int, 54 | _ configs: ATNConfigSet) { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/CharStream.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// A source of characters for an ANTLR lexer. 10 | /// 11 | 12 | public protocol CharStream: IntStream { 13 | /// 14 | /// This method returns the text for a range of characters within this input 15 | /// stream. This method is guaranteed to not throw an exception if the 16 | /// specified `interval` lies entirely within a marked range. For more 17 | /// information about marked ranges, see _org.antlr.v4.runtime.IntStream#mark_. 18 | /// 19 | /// - parameter interval: an interval within the stream 20 | /// - returns: the text of the specified interval 21 | /// 22 | /// - throws: _ANTLRError.illegalArgument_ if `interval.a < 0`, or if 23 | /// `interval.b < interval.a - 1`, or if `interval.b` lies at or 24 | /// past the end of the stream 25 | /// - throws: _ANTLRError.unsupportedOperation_ if the stream does not support 26 | /// getting the text of the specified interval 27 | /// 28 | func getText(_ interval: Interval) throws -> String 29 | } 30 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/CommonTokenFactory.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// This default implementation of _org.antlr.v4.runtime.TokenFactory_ creates 11 | /// _org.antlr.v4.runtime.CommonToken_ objects. 12 | /// 13 | 14 | public class CommonTokenFactory: TokenFactory { 15 | /// 16 | /// The default _org.antlr.v4.runtime.CommonTokenFactory_ instance. 17 | /// 18 | /// 19 | /// This token factory does not explicitly copy token text when constructing 20 | /// tokens. 21 | /// 22 | public static let DEFAULT: TokenFactory = CommonTokenFactory() 23 | 24 | /// 25 | /// Indicates whether _org.antlr.v4.runtime.CommonToken#setText_ should be called after 26 | /// constructing tokens to explicitly set the text. This is useful for cases 27 | /// where the input stream might not be able to provide arbitrary substrings 28 | /// of text from the input after the lexer creates a token (e.g. the 29 | /// implementation of _org.antlr.v4.runtime.CharStream#getText_ in 30 | /// _org.antlr.v4.runtime.UnbufferedCharStream_ throws an 31 | /// _UnsupportedOperationException_). Explicitly setting the token text 32 | /// allows _org.antlr.v4.runtime.Token#getText_ to be called at any time regardless of the 33 | /// input stream implementation. 34 | /// 35 | /// 36 | /// The default value is `false` to avoid the performance and memory 37 | /// overhead of copying text for every token unless explicitly requested. 38 | /// 39 | internal let copyText: Bool 40 | 41 | /// 42 | /// Constructs a _org.antlr.v4.runtime.CommonTokenFactory_ with the specified value for 43 | /// _#copyText_. 44 | /// 45 | /// 46 | /// When `copyText` is `false`, the _#DEFAULT_ instance 47 | /// should be used instead of constructing a new instance. 48 | /// 49 | /// - parameter copyText: The value for _#copyText_. 50 | /// 51 | public init(_ copyText: Bool) { 52 | self.copyText = copyText 53 | } 54 | 55 | /// 56 | /// Constructs a _org.antlr.v4.runtime.CommonTokenFactory_ with _#copyText_ set to 57 | /// `false`. 58 | /// 59 | /// 60 | /// The _#DEFAULT_ instance should be used instead of calling this 61 | /// directly. 62 | /// 63 | public convenience init() { 64 | self.init(false) 65 | } 66 | 67 | 68 | public func create(_ source: TokenSourceAndStream, _ type: Int, _ text: String?, 69 | _ channel: Int, _ start: Int, _ stop: Int, 70 | _ line: Int, _ charPositionInLine: Int) -> Token { 71 | let t = CommonToken(source, type, channel, start, stop) 72 | t.setLine(line) 73 | t.setCharPositionInLine(charPositionInLine) 74 | if let text = text { 75 | t.setText(text) 76 | } 77 | else if let cStream = source.stream, copyText { 78 | t.setText(try! cStream.getText(Interval.of(start, stop))) 79 | } 80 | 81 | return t 82 | } 83 | 84 | 85 | public func create(_ type: Int, _ text: String) -> Token { 86 | return CommonToken(type, text) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// 10 | /// - Sam Harwell 11 | /// 12 | 13 | public class ConsoleErrorListener: BaseErrorListener { 14 | /// 15 | /// Provides a default instance of _org.antlr.v4.runtime.ConsoleErrorListener_. 16 | /// 17 | public static let INSTANCE: ConsoleErrorListener = ConsoleErrorListener() 18 | 19 | /// 20 | /// 21 | /// This implementation prints messages to _System#err_ containing the 22 | /// values of `line`, `charPositionInLine`, and `msg` using 23 | /// the following format. 24 | /// 25 | /// line __line__:__charPositionInLine__ __msg__ 26 | /// 27 | /// 28 | override public func syntaxError(_ recognizer: Recognizer, 29 | _ offendingSymbol: AnyObject?, 30 | _ line: Int, 31 | _ charPositionInLine: Int, 32 | _ msg: String, 33 | _ e: AnyObject? 34 | ) { 35 | if Parser.ConsoleError { 36 | errPrint("line \(line):\(charPositionInLine) \(msg)") 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/FailedPredicateException.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// A semantic predicate failed during validation. Validation of predicates 10 | /// occurs when normally parsing the alternative just like matching a token. 11 | /// Disambiguating predicate evaluation occurs when we test a predicate during 12 | /// prediction. 13 | /// 14 | public class FailedPredicateException: RecognitionException { 15 | private let ruleIndex: Int 16 | private let predicateIndex: Int 17 | private let predicate: String? 18 | 19 | public init(_ recognizer: Parser, _ predicate: String? = nil, _ message: String? = nil) { 20 | let s = recognizer.getInterpreter().atn.states[recognizer.getState()]! 21 | 22 | let trans = s.transition(0) as! AbstractPredicateTransition 23 | if let predex = trans as? PredicateTransition { 24 | self.ruleIndex = predex.ruleIndex 25 | self.predicateIndex = predex.predIndex 26 | } 27 | else { 28 | self.ruleIndex = 0 29 | self.predicateIndex = 0 30 | } 31 | 32 | self.predicate = predicate 33 | 34 | super.init(recognizer, recognizer.getInputStream()!, recognizer._ctx, FailedPredicateException.formatMessage(predicate, message)) 35 | if let token = try? recognizer.getCurrentToken() { 36 | setOffendingToken(token) 37 | } 38 | } 39 | 40 | public func getRuleIndex() -> Int { 41 | return ruleIndex 42 | } 43 | 44 | public func getPredIndex() -> Int { 45 | return predicateIndex 46 | } 47 | 48 | public func getPredicate() -> String? { 49 | return predicate 50 | } 51 | 52 | 53 | private static func formatMessage(_ predicate: String?, _ message: String?) -> String { 54 | if message != nil { 55 | return message! 56 | } 57 | 58 | let predstr = predicate ?? "" 59 | return "failed predicate: {\(predstr)}?" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/InputMismatchException.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// This signifies any kind of mismatched input exceptions such as 10 | /// when the current input does not match the expected token. 11 | /// 12 | 13 | public class InputMismatchException: RecognitionException { 14 | public init(_ recognizer: Parser, state: Int = ATNState.INVALID_STATE_NUMBER, ctx: ParserRuleContext? = nil) { 15 | let bestCtx = ctx ?? recognizer._ctx 16 | 17 | super.init(recognizer, recognizer.getInputStream()!, bestCtx) 18 | 19 | if let token = try? recognizer.getCurrentToken() { 20 | setOffendingToken(token) 21 | } 22 | if (state != ATNState.INVALID_STATE_NUMBER) { 23 | setOffendingState(state) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/InterpreterRuleContext.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// This class extends _org.antlr.v4.runtime.ParserRuleContext_ by allowing the value of 10 | /// _#getRuleIndex_ to be explicitly set for the context. 11 | /// 12 | /// 13 | /// _org.antlr.v4.runtime.ParserRuleContext_ does not include field storage for the rule index 14 | /// since the context classes created by the code generator override the 15 | /// _#getRuleIndex_ method to return the correct value for that context. 16 | /// Since the parser interpreter does not use the context classes generated for a 17 | /// parser, this class (with slightly more memory overhead per node) is used to 18 | /// provide equivalent functionality. 19 | /// 20 | 21 | public class InterpreterRuleContext: ParserRuleContext { 22 | /// 23 | /// This is the backing field for _#getRuleIndex_. 24 | /// 25 | private var ruleIndex: Int = -1 26 | 27 | public override init() { 28 | super.init() 29 | } 30 | 31 | /// 32 | /// Constructs a new _org.antlr.v4.runtime.InterpreterRuleContext_ with the specified 33 | /// parent, invoking state, and rule index. 34 | /// 35 | /// - parameter parent: The parent context. 36 | /// - parameter invokingStateNumber: The invoking state number. 37 | /// - parameter ruleIndex: The rule index for the current context. 38 | /// 39 | public init(_ parent: ParserRuleContext?, 40 | _ invokingStateNumber: Int, 41 | _ ruleIndex: Int) { 42 | self.ruleIndex = ruleIndex 43 | super.init(parent, invokingStateNumber) 44 | 45 | } 46 | 47 | override 48 | public func getRuleIndex() -> Int { 49 | return ruleIndex 50 | } 51 | 52 | /// 53 | /// Copy a _org.antlr.v4.runtime.ParserRuleContext_ or _org.antlr.v4.runtime.InterpreterRuleContext_ 54 | /// stack to a _org.antlr.v4.runtime.InterpreterRuleContext_ tree. 55 | /// Return _null_ if `ctx` is null. 56 | /// 57 | public static func fromParserRuleContext(_ ctx: ParserRuleContext?) -> InterpreterRuleContext? { 58 | guard let ctx = ctx else { 59 | return nil 60 | } 61 | let dup: InterpreterRuleContext = InterpreterRuleContext() 62 | dup.copyFrom(ctx) 63 | dup.ruleIndex = ctx.getRuleIndex() 64 | dup.parent = fromParserRuleContext(ctx.getParent() as? ParserRuleContext) 65 | return dup 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/LexerInterpreter.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public class LexerInterpreter: Lexer { 9 | internal let grammarFileName: String 10 | internal let atn: ATN 11 | 12 | internal let ruleNames: [String] 13 | internal let channelNames: [String] 14 | internal let modeNames: [String] 15 | 16 | private let vocabulary: Vocabulary? 17 | 18 | internal final var _decisionToDFA: [DFA] 19 | internal let _sharedContextCache = PredictionContextCache() 20 | 21 | public init(_ grammarFileName: String, _ vocabulary: Vocabulary, _ ruleNames: Array, _ channelNames: Array, _ modeNames: Array, _ atn: ATN, _ input: CharStream) throws { 22 | 23 | self.grammarFileName = grammarFileName 24 | self.atn = atn 25 | self.ruleNames = ruleNames 26 | self.channelNames = channelNames 27 | self.modeNames = modeNames 28 | self.vocabulary = vocabulary 29 | 30 | self._decisionToDFA = [DFA]() 31 | for i in 0 ..< atn.getNumberOfDecisions() { 32 | _decisionToDFA.append(DFA(atn.getDecisionState(i)!, i)) 33 | } 34 | super.init(input) 35 | self._interp = LexerATNSimulator(self, atn, _decisionToDFA, _sharedContextCache) 36 | 37 | if atn.grammarType != ATNType.lexer { 38 | throw ANTLRError.illegalArgument(msg: "The ATN must be a lexer ATN.") 39 | 40 | } 41 | } 42 | 43 | public required init(_ input: CharStream) { 44 | fatalError("Use the other initializer") 45 | } 46 | 47 | override 48 | public func getATN() -> ATN { 49 | return atn 50 | } 51 | 52 | override 53 | public func getGrammarFileName() -> String { 54 | return grammarFileName 55 | } 56 | 57 | override 58 | public func getRuleNames() -> [String] { 59 | return ruleNames 60 | } 61 | 62 | override 63 | public func getChannelNames() -> [String] { 64 | return channelNames 65 | } 66 | 67 | override 68 | public func getModeNames() -> [String] { 69 | return modeNames 70 | } 71 | 72 | override 73 | public func getVocabulary() -> Vocabulary { 74 | if vocabulary != nil { 75 | return vocabulary! 76 | } 77 | 78 | return super.getVocabulary() 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/LexerNoViableAltException.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public class LexerNoViableAltException: RecognitionException, CustomStringConvertible { 9 | /// 10 | /// Matching attempted at what input index? 11 | /// 12 | private let startIndex: Int 13 | 14 | /// 15 | /// Which configurations did we try at input.index() that couldn't match input.LA(1)? 16 | /// 17 | private let deadEndConfigs: ATNConfigSet 18 | 19 | public init(_ lexer: Lexer?, 20 | _ input: CharStream, 21 | _ startIndex: Int, 22 | _ deadEndConfigs: ATNConfigSet) { 23 | let ctx: ParserRuleContext? = nil 24 | self.startIndex = startIndex 25 | self.deadEndConfigs = deadEndConfigs 26 | super.init(lexer, input as IntStream, ctx) 27 | 28 | } 29 | 30 | public func getStartIndex() -> Int { 31 | return startIndex 32 | } 33 | 34 | public func getDeadEndConfigs() -> ATNConfigSet { 35 | return deadEndConfigs 36 | } 37 | 38 | public var description: String { 39 | var symbol = "" 40 | if let charStream = getInputStream() as? CharStream, startIndex >= 0 && startIndex < charStream.size() { 41 | let interval = Interval.of(startIndex, startIndex) 42 | symbol = try! charStream.getText(interval) 43 | symbol = Utils.escapeWhitespace(symbol, false) 44 | } 45 | 46 | return "\(LexerNoViableAltException.self)('\(symbol)')" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/NoViableAltException.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// Indicates that the parser could not decide which of two or more paths 8 | /// to take based upon the remaining input. It tracks the starting token 9 | /// of the offending input and also knows where the parser was 10 | /// in the various paths when the error. Reported by reportNoViableAlternative() 11 | /// 12 | 13 | public class NoViableAltException: RecognitionException { 14 | /// Which configurations did we try at input.index() that couldn't match input.LT(1)? 15 | 16 | private let deadEndConfigs: ATNConfigSet? 17 | 18 | /// The token object at the start index; the input stream might 19 | /// not be buffering tokens so get a reference to it. (At the 20 | /// time the error occurred, of course the stream needs to keep a 21 | /// buffer all of the tokens but later we might not have access to those.) 22 | /// 23 | private let startToken: Token 24 | 25 | public convenience init(_ recognizer: Parser) { 26 | // LL(1) error 27 | let token = try! recognizer.getCurrentToken() 28 | self.init(recognizer, 29 | recognizer.getInputStream()!, 30 | token, 31 | token, 32 | nil, 33 | recognizer._ctx) 34 | } 35 | 36 | public init(_ recognizer: Parser?, 37 | _ input: IntStream, 38 | _ startToken: Token, 39 | _ offendingToken: Token?, 40 | _ deadEndConfigs: ATNConfigSet?, 41 | _ ctx: ParserRuleContext?) { 42 | 43 | self.deadEndConfigs = deadEndConfigs 44 | self.startToken = startToken 45 | 46 | super.init(recognizer, input, ctx) 47 | if let offendingToken = offendingToken { 48 | setOffendingToken(offendingToken) 49 | } 50 | } 51 | 52 | 53 | public func getStartToken() -> Token { 54 | return startToken 55 | } 56 | 57 | 58 | public func getDeadEndConfigs() -> ATNConfigSet? { 59 | return deadEndConfigs 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// 8 | /// This implementation of _org.antlr.v4.runtime.ANTLRErrorListener_ dispatches all calls to a 9 | /// collection of delegate listeners. This reduces the effort required to support multiple 10 | /// listeners. 11 | /// 12 | /// - Author: Sam Harwell 13 | /// 14 | 15 | public class ProxyErrorListener: ANTLRErrorListener { 16 | private final var delegates: [ANTLRErrorListener] 17 | 18 | public init(_ delegates: [ANTLRErrorListener]) { 19 | self.delegates = delegates 20 | } 21 | 22 | public func syntaxError(_ recognizer: Recognizer, 23 | _ offendingSymbol: AnyObject?, 24 | _ line: Int, 25 | _ charPositionInLine: Int, 26 | _ msg: String, 27 | _ e: AnyObject?) 28 | { 29 | for listener in delegates { 30 | listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) 31 | } 32 | } 33 | 34 | 35 | public func reportAmbiguity(_ recognizer: Parser, 36 | _ dfa: DFA, 37 | _ startIndex: Int, 38 | _ stopIndex: Int, 39 | _ exact: Bool, 40 | _ ambigAlts: BitSet, 41 | _ configs: ATNConfigSet) { 42 | for listener in delegates { 43 | listener.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) 44 | } 45 | } 46 | 47 | 48 | public func reportAttemptingFullContext(_ recognizer: Parser, 49 | _ dfa: DFA, 50 | _ startIndex: Int, 51 | _ stopIndex: Int, 52 | _ conflictingAlts: BitSet?, 53 | _ configs: ATNConfigSet) { 54 | for listener in delegates { 55 | listener.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) 56 | } 57 | } 58 | 59 | 60 | public func reportContextSensitivity(_ recognizer: Parser, 61 | _ dfa: DFA, 62 | _ startIndex: Int, 63 | _ stopIndex: Int, 64 | _ prediction: Int, 65 | _ configs: ATNConfigSet) { 66 | for listener in delegates { 67 | listener.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/Token.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | 8 | /// A token has properties: text, type, line, character position in the line 9 | /// (so we can ignore tabs), token channel, index, and source from which 10 | /// we obtained this token. 11 | /// 12 | 13 | public protocol Token: AnyObject, CustomStringConvertible { 14 | //let INVALID_TYPE : Int = 0; 15 | 16 | /// During lookahead operations, this "token" signifies we hit rule end ATN state 17 | /// and did not follow it despite needing to. 18 | /// 19 | //let EPSILON : Int = -2; 20 | 21 | //let MIN_USER_TOKEN_TYPE : Int = 1; 22 | 23 | //let EOF : Int = IntStream.EOF; 24 | 25 | /// All tokens go to the parser (unless skip() is called in that rule) 26 | /// on a particular "channel". The parser tunes to a particular channel 27 | /// so that whitespace etc... can go to the parser on a "hidden" channel. 28 | /// 29 | //let DEFAULT_CHANNEL : Int = 0; 30 | 31 | /// Anything on different channel than DEFAULT_CHANNEL is not parsed 32 | /// by parser. 33 | /// 34 | //let HIDDEN_CHANNEL : Int = 1; 35 | 36 | /// 37 | /// This is the minimum constant value which can be assigned to a 38 | /// user-defined token channel. 39 | /// 40 | /// 41 | /// The non-negative numbers less than _#MIN_USER_CHANNEL_VALUE_ are 42 | /// assigned to the predefined channels _#DEFAULT_CHANNEL_ and 43 | /// _#HIDDEN_CHANNEL_. 44 | /// 45 | /// - SeeAlso: org.antlr.v4.runtime.Token#getChannel() 46 | /// 47 | //let MIN_USER_CHANNEL_VALUE : Int = 2; 48 | 49 | /// 50 | /// Get the text of the token. 51 | /// 52 | func getText() -> String? 53 | 54 | /// Get the token type of the token 55 | func getType() -> Int 56 | 57 | /// The line number on which the 1st character of this token was matched, 58 | /// line=1..n 59 | /// 60 | func getLine() -> Int 61 | 62 | /// The index of the first character of this token relative to the 63 | /// beginning of the line at which it occurs, 0..n-1 64 | /// 65 | func getCharPositionInLine() -> Int 66 | 67 | /// Return the channel this token. Each token can arrive at the parser 68 | /// on a different channel, but the parser only "tunes" to a single channel. 69 | /// The parser ignores everything not on DEFAULT_CHANNEL. 70 | /// 71 | func getChannel() -> Int 72 | 73 | /// An index from 0..n-1 of the token object in the input stream. 74 | /// This must be valid in order to print token streams and 75 | /// use TokenRewriteStream. 76 | /// 77 | /// Return -1 to indicate that this token was conjured up since 78 | /// it doesn't have a valid index. 79 | /// 80 | func getTokenIndex() -> Int 81 | 82 | /// The starting character index of the token 83 | /// This method is optional; return -1 if not implemented. 84 | /// 85 | func getStartIndex() -> Int 86 | 87 | /// The last character index of the token. 88 | /// This method is optional; return -1 if not implemented. 89 | /// 90 | func getStopIndex() -> Int 91 | 92 | /// Gets the _org.antlr.v4.runtime.TokenSource_ which created this token. 93 | /// 94 | func getTokenSource() -> TokenSource? 95 | 96 | /// 97 | /// Gets the _org.antlr.v4.runtime.CharStream_ from which this token was derived. 98 | /// 99 | func getInputStream() -> CharStream? 100 | 101 | func getTokenSourceAndStream() -> TokenSourceAndStream 102 | 103 | var visited: Bool { get set } 104 | } 105 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/TokenFactory.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// The default mechanism for creating tokens. It's used by default in Lexer and 8 | /// the error handling strategy (to create missing tokens). Notifying the parser 9 | /// of a new factory means that it notifies it's token source and error strategy. 10 | /// 11 | public protocol TokenFactory { 12 | 13 | //typealias Symbol 14 | /// This is the method used to create tokens in the lexer and in the 15 | /// error handling strategy. If text!=null, than the start and stop positions 16 | /// are wiped to -1 in the text override is set in the CommonToken. 17 | /// 18 | func create(_ source: TokenSourceAndStream, _ type: Int, _ text: String?, 19 | _ channel: Int, _ start: Int, _ stop: Int, 20 | _ line: Int, _ charPositionInLine: Int) -> Token 21 | /// Generically useful 22 | func create(_ type: Int, _ text: String) -> Token 23 | 24 | } 25 | 26 | 27 | /** 28 | Holds the references to the TokenSource and CharStream used to create a Token. 29 | These are together to reduce memory footprint by having one instance of 30 | TokenSourceAndStream shared across many tokens. The references here are weak 31 | to avoid retain cycles. 32 | */ 33 | public class TokenSourceAndStream { 34 | /// 35 | /// An empty TokenSourceAndStream which is used as the default value of 36 | /// _#source_ for tokens that do not have a source. 37 | /// 38 | public static let EMPTY = TokenSourceAndStream() 39 | 40 | public weak var tokenSource: TokenSource? 41 | public weak var stream: CharStream? 42 | 43 | public init(_ tokenSource: TokenSource? = nil, _ stream: CharStream? = nil) { 44 | self.tokenSource = tokenSource 45 | self.stream = stream 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/TokenSource.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// 8 | /// A source of tokens must provide a sequence of tokens via _#nextToken()_ 9 | /// and also must reveal it's source of characters; _org.antlr.v4.runtime.CommonToken_'s text is 10 | /// computed from a _org.antlr.v4.runtime.CharStream_; it only store indices into the char 11 | /// stream. 12 | /// 13 | /// Errors from the lexer are never passed to the parser. Either you want to keep 14 | /// going or you do not upon token recognition error. If you do not want to 15 | /// continue lexing then you do not want to continue parsing. Just throw an 16 | /// exception not under _org.antlr.v4.runtime.RecognitionException_ and Java will naturally toss 17 | /// you all the way out of the recognizers. If you want to continue lexing then 18 | /// you should not throw an exception to the parser--it has already requested a 19 | /// token. Keep lexing until you get a valid one. Just report errors and keep 20 | /// going, looking for a valid token. 21 | /// 22 | 23 | public protocol TokenSource: AnyObject { 24 | /// 25 | /// Return a _org.antlr.v4.runtime.Token_ object from your input stream (usually a 26 | /// _org.antlr.v4.runtime.CharStream_). Do not fail/return upon lexing error; keep chewing 27 | /// on the characters until you get a good one; errors are not passed through 28 | /// to the parser. 29 | /// 30 | func nextToken() throws -> Token 31 | 32 | /// 33 | /// Get the line number for the current position in the input stream. The 34 | /// first line in the input is line 1. 35 | /// 36 | /// - Returns: The line number for the current position in the input stream, or 37 | /// 0 if the current token source does not track line numbers. 38 | /// 39 | func getLine() -> Int 40 | 41 | /// 42 | /// Get the index into the current line for the current position in the input 43 | /// stream. The first character on a line has position 0. 44 | /// 45 | /// - Returns: The line number for the current position in the input stream, or 46 | /// -1 if the current token source does not track character positions. 47 | /// 48 | func getCharPositionInLine() -> Int 49 | 50 | /// 51 | /// Get the _org.antlr.v4.runtime.CharStream_ from which this token source is currently 52 | /// providing tokens. 53 | /// 54 | /// - Returns: The _org.antlr.v4.runtime.CharStream_ associated with the current position in 55 | /// the input, or `null` if no input stream is available for the token 56 | /// source. 57 | /// 58 | func getInputStream() -> CharStream? 59 | 60 | /// 61 | /// Gets the name of the underlying input source. This method returns a 62 | /// non-null, non-empty string. If such a name is not known, this method 63 | /// returns _org.antlr.v4.runtime.IntStream#UNKNOWN_SOURCE_NAME_. 64 | /// 65 | func getSourceName() -> String 66 | 67 | /// 68 | /// Set the _org.antlr.v4.runtime.TokenFactory_ this token source should use for creating 69 | /// _org.antlr.v4.runtime.Token_ objects from the input. 70 | /// 71 | /// - Parameter factory: The _org.antlr.v4.runtime.TokenFactory_ to use for creating tokens. 72 | /// 73 | func setTokenFactory(_ factory: TokenFactory) 74 | 75 | /// 76 | /// Gets the _org.antlr.v4.runtime.TokenFactory_ this token source is currently using for 77 | /// creating _org.antlr.v4.runtime.Token_ objects from the input. 78 | /// 79 | /// - Returns: The _org.antlr.v4.runtime.TokenFactory_ currently used by this token source. 80 | /// 81 | func getTokenFactory() -> TokenFactory 82 | } 83 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/WritableToken.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | public protocol WritableToken: Token { 8 | func setText(_ text: String) 9 | 10 | func setType(_ ttype: Int) 11 | 12 | func setLine(_ line: Int) 13 | 14 | func setCharPositionInLine(_ pos: Int) 15 | 16 | func setChannel(_ channel: Int) 17 | 18 | func setTokenIndex(_ index: Int) 19 | } 20 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ATNDeserializationOptions.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | public struct ATNDeserializationOptions { 8 | public var verifyATN = true 9 | public var generateRuleBypassTransitions = false 10 | } 11 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ATNSimulator.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | import Foundation 9 | 10 | open class ATNSimulator { 11 | /// 12 | /// Must distinguish between missing edge and edge we know leads nowhere 13 | /// 14 | public static let ERROR: DFAState = { 15 | let error = DFAState(ATNConfigSet()) 16 | error.stateNumber = Int.max 17 | return error 18 | }() 19 | 20 | public let atn: ATN 21 | 22 | /// 23 | /// The context cache maps all PredictionContext objects that are equals() 24 | /// to a single cached copy. This cache is shared across all contexts 25 | /// in all ATNConfigs in all DFA states. We rebuild each ATNConfigSet 26 | /// to use only cached nodes/graphs in addDFAState(). We don't want to 27 | /// fill this during closure() since there are lots of contexts that 28 | /// pop up but are not used ever again. It also greatly slows down closure(). 29 | /// 30 | /// This cache makes a huge difference in memory and a little bit in speed. 31 | /// For the Java grammar on java.*, it dropped the memory requirements 32 | /// at the end from 25M to 16M. We don't store any of the full context 33 | /// graphs in the DFA because they are limited to local context only, 34 | /// but apparently there's a lot of repetition there as well. We optimize 35 | /// the config contexts before storing the config set in the DFA states 36 | /// by literally rebuilding them with cached subgraphs only. 37 | /// 38 | /// I tried a cache for use during closure operations, that was 39 | /// whacked after each adaptivePredict(). It cost a little bit 40 | /// more time I think and doesn't save on the overall footprint 41 | /// so it's not worth the complexity. 42 | /// 43 | internal let sharedContextCache: PredictionContextCache 44 | 45 | public init(_ atn: ATN, 46 | _ sharedContextCache: PredictionContextCache) { 47 | 48 | self.atn = atn 49 | self.sharedContextCache = sharedContextCache 50 | } 51 | 52 | open func reset() { 53 | fatalError(#function + " must be overridden") 54 | } 55 | 56 | /// 57 | /// Clear the DFA cache used by the current instance. Since the DFA cache may 58 | /// be shared by multiple ATN simulators, this method may affect the 59 | /// performance (but not accuracy) of other parsers which are being used 60 | /// concurrently. 61 | /// 62 | /// - throws: ANTLRError.unsupportedOperation if the current instance does not 63 | /// support clearing the DFA. 64 | /// 65 | /// - since: 4.3 66 | /// 67 | open func clearDFA() throws { 68 | throw ANTLRError.unsupportedOperation(msg: "This ATN simulator does not support clearing the DFA. ") 69 | } 70 | 71 | open func getSharedContextCache() -> PredictionContextCache { 72 | return sharedContextCache 73 | } 74 | 75 | open func getCachedContext(_ context: PredictionContext) -> PredictionContext { 76 | //TODO: synced (sharedContextCache!) 77 | //synced (sharedContextCache!) { 78 | var visited = [PredictionContext: PredictionContext]() 79 | return PredictionContext.getCachedContext(context, 80 | sharedContextCache, 81 | &visited) 82 | } 83 | 84 | public static func edgeFactory(_ atn: ATN, 85 | _ type: Int, _ src: Int, _ trg: Int, 86 | _ arg1: Int, _ arg2: Int, _ arg3: Int, 87 | _ sets: Array) throws -> Transition { 88 | return try ATNDeserializer().edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ATNType.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Represents the type of recognizer an ATN applies to. 11 | /// 12 | /// - Sam Harwell 13 | /// 14 | 15 | public enum ATNType: Int { 16 | 17 | /// 18 | /// A lexer grammar. 19 | /// 20 | case lexer = 0 21 | 22 | /// 23 | /// A parser grammar. 24 | /// 25 | case parser 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/AbstractPredicateTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// 11 | /// - Sam Harwell 12 | /// 13 | 14 | public class AbstractPredicateTransition: Transition { 15 | 16 | /*public override init(_ target : ATNState) { 17 | super.init(target); 18 | }*/ 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ActionTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class ActionTransition: Transition, CustomStringConvertible { 9 | public let ruleIndex: Int 10 | public let actionIndex: Int 11 | public let isCtxDependent: Bool 12 | // e.g., $i ref in action 13 | 14 | 15 | public convenience init(_ target: ATNState, _ ruleIndex: Int) { 16 | self.init(target, ruleIndex, -1, false) 17 | } 18 | 19 | public init(_ target: ATNState, _ ruleIndex: Int, _ actionIndex: Int, _ isCtxDependent: Bool) { 20 | 21 | self.ruleIndex = ruleIndex 22 | self.actionIndex = actionIndex 23 | self.isCtxDependent = isCtxDependent 24 | super.init(target) 25 | } 26 | 27 | override 28 | public func getSerializationType() -> Int { 29 | return Transition.ACTION 30 | } 31 | 32 | override 33 | public func isEpsilon() -> Bool { 34 | return true // we are to be ignored by analysis 'cept for predicates 35 | } 36 | 37 | override 38 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 39 | return false 40 | } 41 | 42 | public var description: String { 43 | return "action_\(ruleIndex):\(actionIndex)" 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/AmbiguityInfo.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// This class represents profiling event information for an ambiguity. 11 | /// Ambiguities are decisions where a particular input resulted in an SLL 12 | /// conflict, followed by LL prediction also reaching a conflict state 13 | /// (indicating a true ambiguity in the grammar). 14 | /// 15 | /// 16 | /// This event may be reported during SLL prediction in cases where the 17 | /// conflicting SLL configuration set provides sufficient information to 18 | /// determine that the SLL conflict is truly an ambiguity. For example, if none 19 | /// of the ATN configurations in the conflicting SLL configuration set have 20 | /// traversed a global follow transition (i.e. 21 | /// _org.antlr.v4.runtime.atn.ATNConfig#reachesIntoOuterContext_ is 0 for all configurations), then 22 | /// the result of SLL prediction for that input is known to be equivalent to the 23 | /// result of LL prediction for that input. 24 | /// 25 | /// 26 | /// In some cases, the minimum represented alternative in the conflicting LL 27 | /// configuration set is not equal to the minimum represented alternative in the 28 | /// conflicting SLL configuration set. Grammars and inputs which result in this 29 | /// scenario are unable to use _org.antlr.v4.runtime.atn.PredictionMode#SLL_, which in turn means 30 | /// they cannot use the two-stage parsing strategy to improve parsing performance 31 | /// for that input. 32 | /// 33 | /// - seealso: org.antlr.v4.runtime.atn.ParserATNSimulator#reportAmbiguity 34 | /// - seealso: org.antlr.v4.runtime.ANTLRErrorListener#reportAmbiguity 35 | /// 36 | /// - 4.3 37 | /// 38 | 39 | public class AmbiguityInfo: DecisionEventInfo { 40 | /// 41 | /// The set of alternative numbers for this decision event that lead to a valid parse. 42 | /// 43 | public var ambigAlts: BitSet 44 | 45 | /// 46 | /// Constructs a new instance of the _org.antlr.v4.runtime.atn.AmbiguityInfo_ class with the 47 | /// specified detailed ambiguity information. 48 | /// 49 | /// - parameter decision: The decision number 50 | /// - parameter configs: The final configuration set identifying the ambiguous 51 | /// alternatives for the current input 52 | /// - parameter ambigAlts: The set of alternatives in the decision that lead to a valid parse. 53 | /// - parameter input: The input token stream 54 | /// - parameter startIndex: The start index for the current prediction 55 | /// - parameter stopIndex: The index at which the ambiguity was identified during 56 | /// prediction 57 | /// - parameter fullCtx: `true` if the ambiguity was identified during LL 58 | /// prediction; otherwise, `false` if the ambiguity was identified 59 | /// during SLL prediction 60 | /// 61 | public init(_ decision: Int, 62 | _ configs: ATNConfigSet, 63 | _ ambigAlts: BitSet, 64 | _ input: TokenStream, _ startIndex: Int, _ stopIndex: Int, 65 | _ fullCtx: Bool) { 66 | self.ambigAlts = ambigAlts 67 | super.init(decision, configs, input, startIndex, stopIndex, fullCtx) 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ArrayPredictionContext.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public class ArrayPredictionContext: PredictionContext { 9 | /// 10 | /// Parent can be null only if full ctx mode and we make an array 11 | /// from _#EMPTY_ and non-empty. We merge _#EMPTY_ by using null parent and 12 | /// returnState == _#EMPTY_RETURN_STATE_. 13 | /// 14 | public private(set) final var parents: [PredictionContext?] 15 | 16 | /// 17 | /// Sorted for merge, no duplicates; if present, 18 | /// _#EMPTY_RETURN_STATE_ is always last. 19 | /// 20 | public final let returnStates: [Int] 21 | 22 | public convenience init(_ a: SingletonPredictionContext) { 23 | let parents = [a.parent] 24 | self.init(parents, [a.returnState]) 25 | } 26 | 27 | public init(_ parents: [PredictionContext?], _ returnStates: [Int]) { 28 | 29 | self.parents = parents 30 | self.returnStates = returnStates 31 | super.init(PredictionContext.calculateHashCode(parents, returnStates)) 32 | } 33 | 34 | override 35 | final public func isEmpty() -> Bool { 36 | // since EMPTY_RETURN_STATE can only appear in the last position, we 37 | // don't need to verify that size==1 38 | return returnStates[0] == PredictionContext.EMPTY_RETURN_STATE 39 | } 40 | 41 | override 42 | final public func size() -> Int { 43 | return returnStates.count 44 | } 45 | 46 | override 47 | final public func getParent(_ index: Int) -> PredictionContext? { 48 | return parents[index] 49 | } 50 | 51 | override 52 | final public func getReturnState(_ index: Int) -> Int { 53 | return returnStates[index] 54 | } 55 | 56 | override 57 | public var description: String { 58 | if isEmpty() { 59 | return "[]" 60 | } 61 | var buf = "[" 62 | for (i, returnState) in returnStates.enumerated() { 63 | if i > 0 { 64 | buf += ", " 65 | } 66 | if returnState == PredictionContext.EMPTY_RETURN_STATE { 67 | buf += "$" 68 | continue 69 | } 70 | buf += "\(returnState)" 71 | if let parent = parents[i] { 72 | buf += " \(parent)" 73 | } 74 | else { 75 | buf += "null" 76 | } 77 | } 78 | buf += "]" 79 | return buf 80 | } 81 | 82 | internal final func combineCommonParents() { 83 | 84 | let length = parents.count 85 | var uniqueParents: Dictionary = 86 | Dictionary() 87 | for p in 0.. Bool { 107 | if lhs === rhs { 108 | return true 109 | } 110 | if lhs.hashValue != rhs.hashValue { 111 | return false 112 | } 113 | 114 | return lhs.returnStates == rhs.returnStates && lhs.parents == rhs.parents 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/AtomTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// TODO: make all transitions sets? no, should remove set edges 10 | /// 11 | 12 | public final class AtomTransition: Transition, CustomStringConvertible { 13 | /// 14 | /// The token type or character value; or, signifies special label. 15 | /// 16 | public let label: Int 17 | 18 | public init(_ target: ATNState, _ label: Int) { 19 | 20 | self.label = label 21 | super.init(target) 22 | } 23 | 24 | override 25 | public func getSerializationType() -> Int { 26 | return Transition.ATOM 27 | } 28 | 29 | override 30 | public func labelIntervalSet() -> IntervalSet? { 31 | return IntervalSet(label) 32 | } 33 | 34 | override 35 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 36 | return label == symbol 37 | } 38 | 39 | 40 | public var description: String { 41 | return String(label) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/BasicBlockStartState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// 11 | /// - Sam Harwell 12 | /// 13 | 14 | public final class BasicBlockStartState: BlockStartState { 15 | override 16 | public func getStateType() -> Int { 17 | return BlockStartState.BLOCK_START 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/BasicState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// 11 | /// - Sam Harwell 12 | /// 13 | 14 | public final class BasicState: ATNState { 15 | 16 | override 17 | public func getStateType() -> Int { 18 | return ATNState.BASIC 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/BlockEndState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Terminal node of a simple `(a|b|c)` block. 11 | /// 12 | 13 | public final class BlockEndState: ATNState { 14 | public var startState: BlockStartState? 15 | 16 | override 17 | public func getStateType() -> Int { 18 | return ATNState.BLOCK_END 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/BlockStartState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// The start of a regular `(...)` block. 10 | /// 11 | 12 | public class BlockStartState: DecisionState { 13 | public var endState: BlockEndState? 14 | } 15 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ContextSensitivityInfo.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// This class represents profiling event information for a context sensitivity. 10 | /// Context sensitivities are decisions where a particular input resulted in an 11 | /// SLL conflict, but LL prediction produced a single unique alternative. 12 | /// 13 | /// 14 | /// In some cases, the unique alternative identified by LL prediction is not 15 | /// equal to the minimum represented alternative in the conflicting SLL 16 | /// configuration set. Grammars and inputs which result in this scenario are 17 | /// unable to use _org.antlr.v4.runtime.atn.PredictionMode#SLL_, which in turn means they cannot use 18 | /// the two-stage parsing strategy to improve parsing performance for that 19 | /// input. 20 | /// 21 | /// - seealso: org.antlr.v4.runtime.atn.ParserATNSimulator#reportContextSensitivity 22 | /// - seealso: org.antlr.v4.runtime.ANTLRErrorListener#reportContextSensitivity 23 | /// 24 | /// - 4.3 25 | /// 26 | 27 | public class ContextSensitivityInfo: DecisionEventInfo { 28 | /// 29 | /// Constructs a new instance of the _org.antlr.v4.runtime.atn.ContextSensitivityInfo_ class 30 | /// with the specified detailed context sensitivity information. 31 | /// 32 | /// - parameter decision: The decision number 33 | /// - parameter configs: The final configuration set containing the unique 34 | /// alternative identified by full-context prediction 35 | /// - parameter input: The input token stream 36 | /// - parameter startIndex: The start index for the current prediction 37 | /// - parameter stopIndex: The index at which the context sensitivity was 38 | /// identified during full-context prediction 39 | /// 40 | public init(_ decision: Int, 41 | _ configs: ATNConfigSet, 42 | _ input: TokenStream, _ startIndex: Int, _ stopIndex: Int) { 43 | super.init(decision, configs, input, startIndex, stopIndex, true) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/DecisionEventInfo.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// This is the base class for gathering detailed information about prediction 11 | /// events which occur during parsing. 12 | /// 13 | /// Note that we could record the parser call stack at the time this event 14 | /// occurred but in the presence of left recursive rules, the stack is kind of 15 | /// meaningless. It's better to look at the individual configurations for their 16 | /// individual stacks. Of course that is a _org.antlr.v4.runtime.atn.PredictionContext_ object 17 | /// not a parse tree node and so it does not have information about the extent 18 | /// (start...stop) of the various subtrees. Examining the stack tops of all 19 | /// configurations provide the return states for the rule invocations. 20 | /// From there you can get the enclosing rule. 21 | /// 22 | /// - 4.3 23 | /// 24 | 25 | public class DecisionEventInfo { 26 | /// 27 | /// The invoked decision number which this event is related to. 28 | /// 29 | /// - seealso: org.antlr.v4.runtime.atn.ATN#decisionToState 30 | /// 31 | public let decision: Int 32 | 33 | /// 34 | /// The configuration set containing additional information relevant to the 35 | /// prediction state when the current event occurred, or `null` if no 36 | /// additional information is relevant or available. 37 | /// 38 | public let configs: ATNConfigSet? 39 | 40 | /// 41 | /// The input token stream which is being parsed. 42 | /// 43 | public let input: TokenStream 44 | 45 | /// 46 | /// The token index in the input stream at which the current prediction was 47 | /// originally invoked. 48 | /// 49 | public let startIndex: Int 50 | 51 | /// 52 | /// The token index in the input stream at which the current event occurred. 53 | /// 54 | public let stopIndex: Int 55 | 56 | /// 57 | /// `true` if the current event occurred during LL prediction; 58 | /// otherwise, `false` if the input occurred during SLL prediction. 59 | /// 60 | public let fullCtx: Bool 61 | 62 | public init(_ decision: Int, 63 | _ configs: ATNConfigSet?, 64 | _ input: TokenStream, 65 | _ startIndex: Int, 66 | _ stopIndex: Int, 67 | _ fullCtx: Bool) { 68 | self.decision = decision 69 | self.fullCtx = fullCtx 70 | self.stopIndex = stopIndex 71 | self.input = input 72 | self.startIndex = startIndex 73 | self.configs = configs 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/DecisionState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public class DecisionState: ATNState { 9 | public var decision: Int = -1 10 | public var nonGreedy: Bool = false 11 | } 12 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/DefaultATNConfig.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // DefaultATNConfig.swift 9 | // antlr.swift 10 | // 11 | // Created by janyou on 15/9/14. 12 | // 13 | 14 | import Foundation 15 | //public struct DefaultATNConfig: ATNConfig { 16 | // public var state: ATNState 17 | // public var alt: Int 18 | // public var context: PredictionContext? 19 | // public var semanticContext: SemanticContext 20 | // public var hashValue: Int { 21 | // 22 | // var hashCode: Int = 7 23 | // hashCode = 31 * hashCode + state.stateNumber 24 | // hashCode = 31 * hashCode + alt 25 | // hashCode = 31 * hashCode + semanticContext.hashValue 26 | // return hashCode 27 | // 28 | // } 29 | // 30 | // 31 | //} 32 | // 33 | //public func ==(lhs: DefaultATNConfig, rhs: DefaultATNConfig) -> Bool { 34 | // 35 | // if lhs === rhs { 36 | // return true 37 | // } 38 | // 39 | // let same: Bool = 40 | // lhs.state.stateNumber == rhs.state.stateNumber && 41 | // lhs.alt == rhs.alt && 42 | // lhs.semanticContext == rhs.semanticContext 43 | // 44 | // return same 45 | // 46 | //} 47 | //public class DefaultATNConfig: ATNConfig { 48 | // 49 | // override 50 | // public var hashValue: Int { 51 | // 52 | // var hashCode: Int = 7 53 | // hashCode = 31 * hashCode + state.stateNumber 54 | // hashCode = 31 * hashCode + alt 55 | // hashCode = 31 * hashCode + semanticContext.hashValue 56 | // return hashCode 57 | // 58 | // } 59 | // 60 | // 61 | //} 62 | // 63 | //public func ==(lhs: DefaultATNConfig, rhs: DefaultATNConfig) -> Bool { 64 | // 65 | // if lhs === rhs { 66 | // return true 67 | // } 68 | // 69 | // let same: Bool = 70 | // lhs.state.stateNumber == rhs.state.stateNumber && 71 | // lhs.alt == rhs.alt && 72 | // lhs.semanticContext == rhs.semanticContext 73 | // 74 | // return same 75 | // 76 | //} 77 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/EmptyPredictionContext.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public class EmptyPredictionContext: SingletonPredictionContext { 9 | public init() { 10 | super.init(nil, PredictionContext.EMPTY_RETURN_STATE) 11 | } 12 | 13 | override 14 | public func isEmpty() -> Bool { 15 | return true 16 | } 17 | 18 | override 19 | public func size() -> Int { 20 | return 1 21 | } 22 | 23 | override 24 | public func getParent(_ index: Int) -> PredictionContext? { 25 | return nil 26 | } 27 | 28 | override 29 | public func getReturnState(_ index: Int) -> Int { 30 | return returnState 31 | } 32 | 33 | 34 | override 35 | public var description: String { 36 | return "$" 37 | } 38 | } 39 | 40 | 41 | public func ==(lhs: EmptyPredictionContext, rhs: EmptyPredictionContext) -> Bool { 42 | if lhs === rhs { 43 | return true 44 | } 45 | 46 | return false 47 | } 48 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/EpsilonTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class EpsilonTransition: Transition, CustomStringConvertible { 9 | 10 | private let outermostPrecedenceReturnInside: Int 11 | 12 | public convenience override init(_ target: ATNState) { 13 | self.init(target, -1) 14 | } 15 | 16 | public init(_ target: ATNState, _ outermostPrecedenceReturn: Int) { 17 | 18 | self.outermostPrecedenceReturnInside = outermostPrecedenceReturn 19 | super.init(target) 20 | } 21 | 22 | /// 23 | /// - returns: the rule index of a precedence rule for which this transition is 24 | /// returning from, where the precedence value is 0; otherwise, -1. 25 | /// 26 | /// - seealso: org.antlr.v4.runtime.atn.ATNConfig#isPrecedenceFilterSuppressed() 27 | /// - seealso: org.antlr.v4.runtime.atn.ParserATNSimulator#applyPrecedenceFilter(org.antlr.v4.runtime.atn.ATNConfigSet) 28 | /// - 4.4.1 29 | /// 30 | public func outermostPrecedenceReturn() -> Int { 31 | return outermostPrecedenceReturnInside 32 | } 33 | 34 | override 35 | public func getSerializationType() -> Int { 36 | return Transition.EPSILON 37 | } 38 | 39 | override 40 | public func isEpsilon() -> Bool { 41 | return true 42 | } 43 | 44 | override 45 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 46 | return false 47 | } 48 | 49 | 50 | public var description: String { 51 | return "epsilon" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/ErrorInfo.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// This class represents profiling event information for a syntax error 11 | /// identified during prediction. Syntax errors occur when the prediction 12 | /// algorithm is unable to identify an alternative which would lead to a 13 | /// successful parse. 14 | /// 15 | /// - seealso: org.antlr.v4.runtime.Parser#notifyErrorListeners(org.antlr.v4.runtime.Token, String, org.antlr.v4.runtime.RecognitionException) 16 | /// - seealso: org.antlr.v4.runtime.ANTLRErrorListener#syntaxError 17 | /// 18 | /// - 4.3 19 | /// 20 | 21 | public class ErrorInfo: DecisionEventInfo { 22 | /// 23 | /// Constructs a new instance of the _org.antlr.v4.runtime.atn.ErrorInfo_ class with the 24 | /// specified detailed syntax error information. 25 | /// 26 | /// - parameter decision: The decision number 27 | /// - parameter configs: The final configuration set reached during prediction 28 | /// prior to reaching the _org.antlr.v4.runtime.atn.ATNSimulator#ERROR_ state 29 | /// - parameter input: The input token stream 30 | /// - parameter startIndex: The start index for the current prediction 31 | /// - parameter stopIndex: The index at which the syntax error was identified 32 | /// - parameter fullCtx: `true` if the syntax error was identified during LL 33 | /// prediction; otherwise, `false` if the syntax error was identified 34 | /// during SLL prediction 35 | /// 36 | public init(_ decision: Int, 37 | _ configs: ATNConfigSet, 38 | _ input: TokenStream, _ startIndex: Int, _ stopIndex: Int, 39 | _ fullCtx: Bool) { 40 | super.init(decision, configs, input, startIndex, stopIndex, fullCtx) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Represents a single action which can be executed following the successful 11 | /// match of a lexer rule. Lexer actions are used for both embedded action syntax 12 | /// and ANTLR 4's new lexer command syntax. 13 | /// 14 | /// - Sam Harwell 15 | /// - 4.2 16 | /// 17 | 18 | public class LexerAction: Hashable { 19 | /// 20 | /// Gets the serialization type of the lexer action. 21 | /// 22 | /// - returns: The serialization type of the lexer action. 23 | /// 24 | public func getActionType() -> LexerActionType { 25 | fatalError(#function + " must be overridden") 26 | } 27 | 28 | 29 | /// 30 | /// Gets whether the lexer action is position-dependent. Position-dependent 31 | /// actions may have different semantics depending on the _org.antlr.v4.runtime.CharStream_ 32 | /// index at the time the action is executed. 33 | /// 34 | /// Many lexer commands, including `type`, `skip`, and 35 | /// `more`, do not check the input index during their execution. 36 | /// Actions like this are position-independent, and may be stored more 37 | /// efficiently as part of the _org.antlr.v4.runtime.atn.LexerATNConfig#lexerActionExecutor_. 38 | /// 39 | /// - returns: `true` if the lexer action semantics can be affected by the 40 | /// position of the input _org.antlr.v4.runtime.CharStream_ at the time it is executed; 41 | /// otherwise, `false`. 42 | /// 43 | public func isPositionDependent() -> Bool { 44 | fatalError(#function + " must be overridden") 45 | } 46 | 47 | /// 48 | /// Execute the lexer action in the context of the specified _org.antlr.v4.runtime.Lexer_. 49 | /// 50 | /// For position-dependent actions, the input stream must already be 51 | /// positioned correctly prior to calling this method. 52 | /// 53 | /// - parameter lexer: The lexer instance. 54 | /// 55 | public func execute(_ lexer: Lexer) throws { 56 | fatalError(#function + " must be overridden") 57 | } 58 | 59 | public func hash(into hasher: inout Hasher) { 60 | fatalError(#function + " must be overridden") 61 | } 62 | 63 | } 64 | 65 | public func ==(lhs: LexerAction, rhs: LexerAction) -> Bool { 66 | 67 | if lhs === rhs { 68 | return true 69 | } 70 | 71 | if (lhs is LexerChannelAction) && (rhs is LexerChannelAction) { 72 | return (lhs as! LexerChannelAction) == (rhs as! LexerChannelAction) 73 | } else if (lhs is LexerCustomAction) && (rhs is LexerCustomAction) { 74 | return (lhs as! LexerCustomAction) == (rhs as! LexerCustomAction) 75 | } else if (lhs is LexerIndexedCustomAction) && (rhs is LexerIndexedCustomAction) { 76 | return (lhs as! LexerIndexedCustomAction) == (rhs as! LexerIndexedCustomAction) 77 | } else if (lhs is LexerModeAction) && (rhs is LexerModeAction) { 78 | return (lhs as! LexerModeAction) == (rhs as! LexerModeAction) 79 | } else if (lhs is LexerMoreAction) && (rhs is LexerMoreAction) { 80 | return (lhs as! LexerMoreAction) == (rhs as! LexerMoreAction) 81 | } else if (lhs is LexerPopModeAction) && (rhs is LexerPopModeAction) { 82 | return (lhs as! LexerPopModeAction) == (rhs as! LexerPopModeAction) 83 | } else if (lhs is LexerPushModeAction) && (rhs is LexerPushModeAction) { 84 | return (lhs as! LexerPushModeAction) == (rhs as! LexerPushModeAction) 85 | } else if (lhs is LexerSkipAction) && (rhs is LexerSkipAction) { 86 | return (lhs as! LexerSkipAction) == (rhs as! LexerSkipAction) 87 | } else if (lhs is LexerTypeAction) && (rhs is LexerTypeAction) { 88 | return (lhs as! LexerTypeAction) == (rhs as! LexerTypeAction) 89 | } 90 | 91 | 92 | return false 93 | 94 | } 95 | 96 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerActionType.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Represents the serialization type of a _org.antlr.v4.runtime.atn.LexerAction_. 11 | /// 12 | /// - Sam Harwell 13 | /// - 4.2 14 | /// 15 | 16 | public enum LexerActionType: Int { 17 | /// 18 | /// The type of a _org.antlr.v4.runtime.atn.LexerChannelAction_ action. 19 | /// 20 | case channel = 0 21 | /// 22 | /// The type of a _org.antlr.v4.runtime.atn.LexerCustomAction_ action. 23 | /// 24 | case custom 25 | /// 26 | /// The type of a _org.antlr.v4.runtime.atn.LexerModeAction_ action. 27 | /// 28 | case mode 29 | /// 30 | /// The type of a _org.antlr.v4.runtime.atn.LexerMoreAction_ action. 31 | /// 32 | case more 33 | /// 34 | /// The type of a _org.antlr.v4.runtime.atn.LexerPopModeAction_ action. 35 | /// 36 | case popMode 37 | /// 38 | /// The type of a _org.antlr.v4.runtime.atn.LexerPushModeAction_ action. 39 | /// 40 | case pushMode 41 | /// 42 | /// The type of a _org.antlr.v4.runtime.atn.LexerSkipAction_ action. 43 | /// 44 | case skip 45 | /// 46 | /// The type of a _org.antlr.v4.runtime.atn.LexerTypeAction_ action. 47 | /// 48 | case type 49 | } 50 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerChannelAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Implements the `channel` lexer action by calling 10 | /// _org.antlr.v4.runtime.Lexer#setChannel_ with the assigned channel. 11 | /// 12 | /// - Sam Harwell 13 | /// - 4.2 14 | /// 15 | 16 | public final class LexerChannelAction: LexerAction, CustomStringConvertible { 17 | fileprivate let channel: Int 18 | 19 | /// 20 | /// Constructs a new `channel` action with the specified channel value. 21 | /// - parameter channel: The channel value to pass to _org.antlr.v4.runtime.Lexer#setChannel_. 22 | /// 23 | public init(_ channel: Int) { 24 | self.channel = channel 25 | } 26 | 27 | /// 28 | /// Gets the channel to use for the _org.antlr.v4.runtime.Token_ created by the lexer. 29 | /// 30 | /// - returns: The channel to use for the _org.antlr.v4.runtime.Token_ created by the lexer. 31 | /// 32 | public func getChannel() -> Int { 33 | return channel 34 | } 35 | 36 | /// 37 | /// 38 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#CHANNEL_. 39 | /// 40 | 41 | public override func getActionType() -> LexerActionType { 42 | return LexerActionType.channel 43 | } 44 | 45 | /// 46 | /// 47 | /// - returns: This method returns `false`. 48 | /// 49 | 50 | public override func isPositionDependent() -> Bool { 51 | return false 52 | } 53 | 54 | /// 55 | /// 56 | /// 57 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#setChannel_ with the 58 | /// value provided by _#getChannel_. 59 | /// 60 | 61 | public override func execute(_ lexer: Lexer) { 62 | lexer.setChannel(channel) 63 | } 64 | 65 | 66 | public override func hash(into hasher: inout Hasher) { 67 | hasher.combine(getActionType()) 68 | hasher.combine(channel) 69 | } 70 | 71 | public var description: String { 72 | return "channel\(channel)" 73 | } 74 | 75 | } 76 | 77 | 78 | public func ==(lhs: LexerChannelAction, rhs: LexerChannelAction) -> Bool { 79 | 80 | if lhs === rhs { 81 | return true 82 | } 83 | 84 | 85 | return lhs.channel == rhs.channel 86 | } 87 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerCustomAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Executes a custom lexer action by calling _org.antlr.v4.runtime.Recognizer#action_ with the 10 | /// rule and action indexes assigned to the custom action. The implementation of 11 | /// a custom action is added to the generated code for the lexer in an override 12 | /// of _org.antlr.v4.runtime.Recognizer#action_ when the grammar is compiled. 13 | /// 14 | /// This class may represent embedded actions created with the {...} 15 | /// syntax in ANTLR 4, as well as actions created for lexer commands where the 16 | /// command argument could not be evaluated when the grammar was compiled. 17 | /// 18 | /// - Sam Harwell 19 | /// - 4.2 20 | /// 21 | 22 | public final class LexerCustomAction: LexerAction { 23 | fileprivate let ruleIndex: Int 24 | fileprivate let actionIndex: Int 25 | 26 | /// 27 | /// Constructs a custom lexer action with the specified rule and action 28 | /// indexes. 29 | /// 30 | /// - parameter ruleIndex: The rule index to use for calls to 31 | /// _org.antlr.v4.runtime.Recognizer#action_. 32 | /// - parameter actionIndex: The action index to use for calls to 33 | /// _org.antlr.v4.runtime.Recognizer#action_. 34 | /// 35 | public init(_ ruleIndex: Int, _ actionIndex: Int) { 36 | self.ruleIndex = ruleIndex 37 | self.actionIndex = actionIndex 38 | } 39 | 40 | /// 41 | /// Gets the rule index to use for calls to _org.antlr.v4.runtime.Recognizer#action_. 42 | /// 43 | /// - returns: The rule index for the custom action. 44 | /// 45 | public func getRuleIndex() -> Int { 46 | return ruleIndex 47 | } 48 | 49 | /// 50 | /// Gets the action index to use for calls to _org.antlr.v4.runtime.Recognizer#action_. 51 | /// 52 | /// - returns: The action index for the custom action. 53 | /// 54 | public func getActionIndex() -> Int { 55 | return actionIndex 56 | } 57 | 58 | /// 59 | /// 60 | /// 61 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#CUSTOM_. 62 | /// 63 | 64 | public override func getActionType() -> LexerActionType { 65 | return LexerActionType.custom 66 | } 67 | 68 | /// 69 | /// Gets whether the lexer action is position-dependent. Position-dependent 70 | /// actions may have different semantics depending on the _org.antlr.v4.runtime.CharStream_ 71 | /// index at the time the action is executed. 72 | /// 73 | /// Custom actions are position-dependent since they may represent a 74 | /// user-defined embedded action which makes calls to methods like 75 | /// _org.antlr.v4.runtime.Lexer#getText_. 76 | /// 77 | /// - returns: This method returns `true`. 78 | /// 79 | override 80 | public func isPositionDependent() -> Bool { 81 | return true 82 | } 83 | 84 | /// 85 | /// 86 | /// 87 | /// Custom actions are implemented by calling _org.antlr.v4.runtime.Lexer#action_ with the 88 | /// appropriate rule and action indexes. 89 | /// 90 | override 91 | public func execute(_ lexer: Lexer) throws { 92 | try lexer.action(nil, ruleIndex, actionIndex) 93 | } 94 | 95 | public override func hash(into hasher: inout Hasher) { 96 | hasher.combine(ruleIndex) 97 | hasher.combine(actionIndex) 98 | } 99 | } 100 | 101 | public func ==(lhs: LexerCustomAction, rhs: LexerCustomAction) -> Bool { 102 | if lhs === rhs { 103 | return true 104 | } 105 | 106 | return lhs.ruleIndex == rhs.ruleIndex 107 | && lhs.actionIndex == rhs.actionIndex 108 | } 109 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerIndexedCustomAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// This implementation of _org.antlr.v4.runtime.atn.LexerAction_ is used for tracking input offsets 11 | /// for position-dependent actions within a _org.antlr.v4.runtime.atn.LexerActionExecutor_. 12 | /// 13 | /// This action is not serialized as part of the ATN, and is only required for 14 | /// position-dependent lexer actions which appear at a location other than the 15 | /// end of a rule. For more information about DFA optimizations employed for 16 | /// lexer actions, see _org.antlr.v4.runtime.atn.LexerActionExecutor#append_ and 17 | /// _org.antlr.v4.runtime.atn.LexerActionExecutor#fixOffsetBeforeMatch_. 18 | /// 19 | /// - Sam Harwell 20 | /// - 4.2 21 | /// 22 | 23 | public final class LexerIndexedCustomAction: LexerAction { 24 | fileprivate let offset: Int 25 | fileprivate let action: LexerAction 26 | 27 | /// 28 | /// Constructs a new indexed custom action by associating a character offset 29 | /// with a _org.antlr.v4.runtime.atn.LexerAction_. 30 | /// 31 | /// Note: This class is only required for lexer actions for which 32 | /// _org.antlr.v4.runtime.atn.LexerAction#isPositionDependent_ returns `true`. 33 | /// 34 | /// - parameter offset: The offset into the input _org.antlr.v4.runtime.CharStream_, relative to 35 | /// the token start index, at which the specified lexer action should be 36 | /// executed. 37 | /// - parameter action: The lexer action to execute at a particular offset in the 38 | /// input _org.antlr.v4.runtime.CharStream_. 39 | /// 40 | public init(_ offset: Int, _ action: LexerAction) { 41 | self.offset = offset 42 | self.action = action 43 | } 44 | 45 | /// 46 | /// Gets the location in the input _org.antlr.v4.runtime.CharStream_ at which the lexer 47 | /// action should be executed. The value is interpreted as an offset relative 48 | /// to the token start index. 49 | /// 50 | /// - returns: The location in the input _org.antlr.v4.runtime.CharStream_ at which the lexer 51 | /// action should be executed. 52 | /// 53 | public func getOffset() -> Int { 54 | return offset 55 | } 56 | 57 | /// 58 | /// Gets the lexer action to execute. 59 | /// 60 | /// - returns: A _org.antlr.v4.runtime.atn.LexerAction_ object which executes the lexer action. 61 | /// 62 | public func getAction() -> LexerAction { 63 | return action 64 | } 65 | 66 | /// 67 | /// 68 | /// 69 | /// - returns: This method returns the result of calling _#getActionType_ 70 | /// on the _org.antlr.v4.runtime.atn.LexerAction_ returned by _#getAction_. 71 | /// 72 | 73 | public override func getActionType() -> LexerActionType { 74 | return action.getActionType() 75 | } 76 | 77 | /// 78 | /// 79 | /// - returns: This method returns `true`. 80 | /// 81 | 82 | public override func isPositionDependent() -> Bool { 83 | return true 84 | } 85 | 86 | /// 87 | /// 88 | /// 89 | /// This method calls _#execute_ on the result of _#getAction_ 90 | /// using the provided `lexer`. 91 | /// 92 | 93 | public override func execute(_ lexer: Lexer) throws { 94 | // assume the input stream position was properly set by the calling code 95 | try action.execute(lexer) 96 | } 97 | 98 | 99 | public override func hash(into hasher: inout Hasher) { 100 | hasher.combine(offset) 101 | hasher.combine(action) 102 | } 103 | } 104 | 105 | public func ==(lhs: LexerIndexedCustomAction, rhs: LexerIndexedCustomAction) -> Bool { 106 | if lhs === rhs { 107 | return true 108 | } 109 | 110 | return lhs.offset == rhs.offset 111 | && lhs.action == rhs.action 112 | } 113 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerModeAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Implements the `mode` lexer action by calling _org.antlr.v4.runtime.Lexer#mode_ with 11 | /// the assigned mode. 12 | /// 13 | /// - Sam Harwell 14 | /// - 4.2 15 | /// 16 | 17 | public final class LexerModeAction: LexerAction, CustomStringConvertible { 18 | fileprivate let mode: Int 19 | 20 | /// 21 | /// Constructs a new `mode` action with the specified mode value. 22 | /// - parameter mode: The mode value to pass to _org.antlr.v4.runtime.Lexer#mode_. 23 | /// 24 | public init(_ mode: Int) { 25 | self.mode = mode 26 | } 27 | 28 | /// 29 | /// Get the lexer mode this action should transition the lexer to. 30 | /// 31 | /// - returns: The lexer mode for this `mode` command. 32 | /// 33 | public func getMode() -> Int { 34 | return mode 35 | } 36 | 37 | /// 38 | /// 39 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#MODE_. 40 | /// 41 | 42 | public override func getActionType() -> LexerActionType { 43 | return LexerActionType.mode 44 | } 45 | 46 | /// 47 | /// 48 | /// - returns: This method returns `false`. 49 | /// 50 | 51 | public override func isPositionDependent() -> Bool { 52 | return false 53 | } 54 | 55 | /// 56 | /// 57 | /// 58 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#mode_ with the 59 | /// value provided by _#getMode_. 60 | /// 61 | override 62 | public func execute(_ lexer: Lexer) { 63 | lexer.mode(mode) 64 | } 65 | 66 | public override func hash(into hasher: inout Hasher) { 67 | hasher.combine(mode) 68 | } 69 | 70 | public var description: String { 71 | return "mode(\(mode))" 72 | } 73 | } 74 | 75 | public func ==(lhs: LexerModeAction, rhs: LexerModeAction) -> Bool { 76 | if lhs === rhs { 77 | return true 78 | } 79 | 80 | return lhs.mode == rhs.mode 81 | } 82 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerMoreAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Implements the `more` lexer action by calling _org.antlr.v4.runtime.Lexer#more_. 10 | /// 11 | /// The `more` command does not have any parameters, so this action is 12 | /// implemented as a singleton instance exposed by _#INSTANCE_. 13 | /// 14 | /// - Sam Harwell 15 | /// - 4.2 16 | /// 17 | 18 | public final class LexerMoreAction: LexerAction, CustomStringConvertible { 19 | /// 20 | /// Provides a singleton instance of this parameterless lexer action. 21 | /// 22 | public static let INSTANCE: LexerMoreAction = LexerMoreAction() 23 | 24 | /// 25 | /// Constructs the singleton instance of the lexer `more` command. 26 | /// 27 | private override init() { 28 | } 29 | 30 | /// 31 | /// 32 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#MORE_. 33 | /// 34 | override 35 | public func getActionType() -> LexerActionType { 36 | return LexerActionType.more 37 | } 38 | 39 | /// 40 | /// 41 | /// - returns: This method returns `false`. 42 | /// 43 | override 44 | public func isPositionDependent() -> Bool { 45 | return false 46 | } 47 | 48 | /// 49 | /// 50 | /// 51 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#more_. 52 | /// 53 | override 54 | public func execute(_ lexer: Lexer) { 55 | lexer.more() 56 | } 57 | 58 | 59 | public override func hash(into hasher: inout Hasher) { 60 | hasher.combine(ObjectIdentifier(self)) 61 | } 62 | 63 | public var description: String { 64 | return "more" 65 | } 66 | } 67 | 68 | public func ==(lhs: LexerMoreAction, rhs: LexerMoreAction) -> Bool { 69 | return lhs === rhs 70 | } 71 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerPopModeAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Implements the `popMode` lexer action by calling _org.antlr.v4.runtime.Lexer#popMode_. 11 | /// 12 | /// The `popMode` command does not have any parameters, so this action is 13 | /// implemented as a singleton instance exposed by _#INSTANCE_. 14 | /// 15 | /// - Sam Harwell 16 | /// - 4.2 17 | /// 18 | 19 | public final class LexerPopModeAction: LexerAction, CustomStringConvertible { 20 | /// 21 | /// Provides a singleton instance of this parameterless lexer action. 22 | /// 23 | public static let INSTANCE: LexerPopModeAction = LexerPopModeAction() 24 | 25 | /// 26 | /// Constructs the singleton instance of the lexer `popMode` command. 27 | /// 28 | private override init() { 29 | } 30 | 31 | /// 32 | /// 33 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#popMode_. 34 | /// 35 | override 36 | public func getActionType() -> LexerActionType { 37 | return LexerActionType.popMode 38 | } 39 | 40 | /// 41 | /// 42 | /// - returns: This method returns `false`. 43 | /// 44 | 45 | public override func isPositionDependent() -> Bool { 46 | return false 47 | } 48 | 49 | /// 50 | /// 51 | /// 52 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#popMode_. 53 | /// 54 | 55 | public override func execute(_ lexer: Lexer) throws { 56 | try lexer.popMode() 57 | } 58 | 59 | 60 | public override func hash(into hasher: inout Hasher) { 61 | hasher.combine(ObjectIdentifier(self)) 62 | } 63 | 64 | public var description: String { 65 | return "popMode" 66 | } 67 | } 68 | 69 | public func ==(lhs: LexerPopModeAction, rhs: LexerPopModeAction) -> Bool { 70 | return lhs === rhs 71 | } 72 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerPushModeAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Implements the `pushMode` lexer action by calling 11 | /// _org.antlr.v4.runtime.Lexer#pushMode_ with the assigned mode. 12 | /// 13 | /// - Sam Harwell 14 | /// - 4.2 15 | /// 16 | 17 | public final class LexerPushModeAction: LexerAction, CustomStringConvertible { 18 | fileprivate let mode: Int 19 | 20 | /// 21 | /// Constructs a new `pushMode` action with the specified mode value. 22 | /// - parameter mode: The mode value to pass to _org.antlr.v4.runtime.Lexer#pushMode_. 23 | /// 24 | public init(_ mode: Int) { 25 | self.mode = mode 26 | } 27 | 28 | /// 29 | /// Get the lexer mode this action should transition the lexer to. 30 | /// 31 | /// - returns: The lexer mode for this `pushMode` command. 32 | /// 33 | public func getMode() -> Int { 34 | return mode 35 | } 36 | 37 | /// 38 | /// 39 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#pushMode_. 40 | /// 41 | 42 | public override func getActionType() -> LexerActionType { 43 | return LexerActionType.pushMode 44 | } 45 | 46 | /// 47 | /// 48 | /// - returns: This method returns `false`. 49 | /// 50 | 51 | public override func isPositionDependent() -> Bool { 52 | return false 53 | } 54 | 55 | /// 56 | /// 57 | /// 58 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#pushMode_ with the 59 | /// value provided by _#getMode_. 60 | /// 61 | override 62 | public func execute(_ lexer: Lexer) { 63 | lexer.pushMode(mode) 64 | } 65 | 66 | public override func hash(into hasher: inout Hasher) { 67 | hasher.combine(mode) 68 | } 69 | 70 | public var description: String { 71 | return "pushMode(\(mode))" 72 | } 73 | } 74 | 75 | 76 | public func ==(lhs: LexerPushModeAction, rhs: LexerPushModeAction) -> Bool { 77 | if lhs === rhs { 78 | return true 79 | } 80 | return lhs.mode == rhs.mode 81 | } 82 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerSkipAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Implements the `skip` lexer action by calling _org.antlr.v4.runtime.Lexer#skip_. 10 | /// 11 | /// The `skip` command does not have any parameters, so this action is 12 | /// implemented as a singleton instance exposed by _#INSTANCE_. 13 | /// 14 | /// - Sam Harwell 15 | /// - 4.2 16 | /// 17 | 18 | public final class LexerSkipAction: LexerAction, CustomStringConvertible { 19 | /// 20 | /// Provides a singleton instance of this parameterless lexer action. 21 | /// 22 | public static let INSTANCE: LexerSkipAction = LexerSkipAction() 23 | 24 | /// 25 | /// Constructs the singleton instance of the lexer `skip` command. 26 | /// 27 | private override init() { 28 | } 29 | 30 | /// 31 | /// 32 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#SKIP_. 33 | /// 34 | override 35 | public func getActionType() -> LexerActionType { 36 | return LexerActionType.skip 37 | } 38 | 39 | /// 40 | /// 41 | /// - returns: This method returns `false`. 42 | /// 43 | override 44 | public func isPositionDependent() -> Bool { 45 | return false 46 | } 47 | 48 | /// 49 | /// 50 | /// 51 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#skip_. 52 | /// 53 | override 54 | public func execute(_ lexer: Lexer) { 55 | lexer.skip() 56 | } 57 | 58 | 59 | public override func hash(into hasher: inout Hasher) { 60 | hasher.combine(ObjectIdentifier(self)) 61 | } 62 | 63 | public var description: String { 64 | return "skip" 65 | } 66 | } 67 | 68 | public func ==(lhs: LexerSkipAction, rhs: LexerSkipAction) -> Bool { 69 | return lhs === rhs 70 | } 71 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LexerTypeAction.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Implements the `type` lexer action by calling _org.antlr.v4.runtime.Lexer#setType_ 10 | /// with the assigned type. 11 | /// 12 | /// - Sam Harwell 13 | /// - 4.2 14 | /// 15 | 16 | public class LexerTypeAction: LexerAction, CustomStringConvertible { 17 | fileprivate let type: Int 18 | 19 | /// 20 | /// Constructs a new `type` action with the specified token type value. 21 | /// - parameter type: The type to assign to the token using _org.antlr.v4.runtime.Lexer#setType_. 22 | /// 23 | public init(_ type: Int) { 24 | self.type = type 25 | } 26 | 27 | /// 28 | /// Gets the type to assign to a token created by the lexer. 29 | /// - returns: The type to assign to a token created by the lexer. 30 | /// 31 | public func getType() -> Int { 32 | return type 33 | } 34 | 35 | /// 36 | /// 37 | /// - returns: This method returns _org.antlr.v4.runtime.atn.LexerActionType#TYPE_. 38 | /// 39 | 40 | public override func getActionType() -> LexerActionType { 41 | return LexerActionType.type 42 | } 43 | 44 | /// 45 | /// 46 | /// - returns: This method returns `false`. 47 | /// 48 | override 49 | public func isPositionDependent() -> Bool { 50 | return false 51 | } 52 | 53 | /// 54 | /// 55 | /// 56 | /// This action is implemented by calling _org.antlr.v4.runtime.Lexer#setType_ with the 57 | /// value provided by _#getType_. 58 | /// 59 | 60 | public override func execute(_ lexer: Lexer) { 61 | lexer.setType(type) 62 | } 63 | 64 | 65 | public override func hash(into hasher: inout Hasher) { 66 | hasher.combine(type) 67 | } 68 | 69 | public var description: String { 70 | return "type(\(type))" 71 | } 72 | } 73 | 74 | public func ==(lhs: LexerTypeAction, rhs: LexerTypeAction) -> Bool { 75 | if lhs === rhs { 76 | return true 77 | } 78 | return lhs.type == rhs.type 79 | } 80 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LookaheadEventInfo.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// This class represents profiling event information for tracking the lookahead 10 | /// depth required in order to make a prediction. 11 | /// 12 | /// - 4.3 13 | /// 14 | 15 | public class LookaheadEventInfo: DecisionEventInfo { 16 | /// 17 | /// Constructs a new instance of the _org.antlr.v4.runtime.atn.LookaheadEventInfo_ class with 18 | /// the specified detailed lookahead information. 19 | /// 20 | /// - parameter decision: The decision number 21 | /// - parameter configs: The final configuration set containing the necessary 22 | /// information to determine the result of a prediction, or `null` if 23 | /// the final configuration set is not available 24 | /// - parameter input: The input token stream 25 | /// - parameter startIndex: The start index for the current prediction 26 | /// - parameter stopIndex: The index at which the prediction was finally made 27 | /// - parameter fullCtx: `true` if the current lookahead is part of an LL 28 | /// prediction; otherwise, `false` if the current lookahead is part of 29 | /// an SLL prediction 30 | /// 31 | public override init(_ decision: Int, 32 | _ configs: ATNConfigSet?, 33 | _ input: TokenStream, _ startIndex: Int, _ stopIndex: Int, 34 | _ fullCtx: Bool) { 35 | super.init(decision, configs, input, startIndex, stopIndex, fullCtx) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LookupATNConfig.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // LookupATNConfig.swift 9 | // objc2swiftwithswith 10 | // 11 | // Created by janyou on 15/9/22. 12 | // 13 | 14 | import Foundation 15 | 16 | public class LookupATNConfig: Hashable { 17 | 18 | public let config: ATNConfig 19 | public init(_ old: ATNConfig) { 20 | // dup 21 | config = old 22 | } 23 | 24 | public func hash(into hasher: inout Hasher) { 25 | hasher.combine(config.state.stateNumber) 26 | hasher.combine(config.alt) 27 | hasher.combine(config.semanticContext) 28 | } 29 | } 30 | 31 | public func ==(lhs: LookupATNConfig, rhs: LookupATNConfig) -> Bool { 32 | if lhs.config === rhs.config { 33 | return true 34 | } 35 | 36 | return lhs.config.state.stateNumber == rhs.config.state.stateNumber && 37 | lhs.config.alt == rhs.config.alt && 38 | lhs.config.semanticContext == rhs.config.semanticContext 39 | } 40 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LookupDictionary.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // LookupDictionary.swift 9 | // antlr.swift 10 | // 11 | // Created by janyou on 15/9/23. 12 | // 13 | 14 | import Foundation 15 | 16 | public enum LookupDictionaryType: Int { 17 | case lookup = 0 18 | case ordered 19 | } 20 | 21 | public struct LookupDictionary { 22 | private let type: LookupDictionaryType 23 | private var cache = [Int: ATNConfig]() 24 | 25 | public init(type: LookupDictionaryType = LookupDictionaryType.lookup) { 26 | self.type = type 27 | } 28 | 29 | private func hash(_ config: ATNConfig) -> Int { 30 | if type == LookupDictionaryType.lookup { 31 | /* migrating to XCode 12.3/Swift 5.3 introduced a very weird bug 32 | where reading hashValue from a SemanticContext.AND instance woul: 33 | call the AND empty constructor 34 | NOT call AND.hash(into) 35 | Could it be a Swift compiler bug ? 36 | All tests pass when using Hasher.combine() 37 | Keeping the old code for reference: 38 | 39 | var hashCode: Int = 7 40 | hashCode = 31 * hashCode + config.state.stateNumber 41 | hashCode = 31 * hashCode + config.alt 42 | hashCode = 31 * hashCode + config.semanticContext.hashValue // <- the crash would occur here 43 | return hashCode 44 | 45 | */ 46 | var hasher = Hasher() 47 | hasher.combine(7) 48 | hasher.combine(config.state.stateNumber) 49 | hasher.combine(config.alt) 50 | hasher.combine(config.semanticContext) 51 | return hasher.finalize() 52 | } else { 53 | //Ordered 54 | return config.hashValue 55 | } 56 | } 57 | 58 | private func equal(_ lhs: ATNConfig, _ rhs: ATNConfig) -> Bool { 59 | if type == LookupDictionaryType.lookup { 60 | if lhs === rhs { 61 | return true 62 | } 63 | 64 | return 65 | lhs.state.stateNumber == rhs.state.stateNumber && 66 | lhs.alt == rhs.alt && 67 | lhs.semanticContext == rhs.semanticContext 68 | } 69 | else { 70 | //Ordered 71 | return lhs == rhs 72 | } 73 | } 74 | 75 | public mutating func getOrAdd(_ config: ATNConfig) -> ATNConfig { 76 | let h = hash(config) 77 | 78 | if let configList = cache[h] { 79 | return configList 80 | } 81 | else { 82 | cache[h] = config 83 | } 84 | 85 | return config 86 | } 87 | 88 | public var isEmpty: Bool { 89 | return cache.isEmpty 90 | } 91 | 92 | public func contains(_ config: ATNConfig) -> Bool { 93 | let h = hash(config) 94 | return cache[h] != nil 95 | } 96 | 97 | public mutating func removeAll() { 98 | cache.removeAll() 99 | } 100 | 101 | } 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/LoopEndState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Mark the end of a * or + loop. 11 | /// 12 | 13 | public final class LoopEndState: ATNState { 14 | public var loopBackState: ATNState? 15 | 16 | override 17 | public func getStateType() -> Int { 18 | return ATNState.LOOP_END 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/NotSetTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class NotSetTransition: SetTransition { 9 | // public override init(_ target : ATNState, inout _ set : IntervalSet?) { 10 | // super.init(target, &set); 11 | // } 12 | 13 | override 14 | public func getSerializationType() -> Int { 15 | return Transition.NOT_SET 16 | } 17 | 18 | override 19 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 20 | return symbol >= minVocabSymbol 21 | && symbol <= maxVocabSymbol 22 | && !super.matches(symbol, minVocabSymbol, maxVocabSymbol) 23 | } 24 | 25 | override 26 | public var description: String { 27 | return "~" + super.description 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/PlusBlockStartState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Start of `(A|B|...)+` loop. Technically a decision state, but 11 | /// we don't use for code generation; somebody might need it, so I'm defining 12 | /// it for completeness. In reality, the _org.antlr.v4.runtime.atn.PlusLoopbackState_ node is the 13 | /// real decision-making note for `A+`. 14 | /// 15 | 16 | public final class PlusBlockStartState: BlockStartState { 17 | public var loopBackState: PlusLoopbackState? 18 | 19 | override 20 | public func getStateType() -> Int { 21 | return ATNState.PLUS_BLOCK_START 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/PlusLoopbackState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Decision state for `A+` and `(A|B)+`. It has two transitions: 11 | /// one to the loop back to start of the block and one to exit. 12 | /// 13 | 14 | public final class PlusLoopbackState: DecisionState { 15 | 16 | override 17 | public func getStateType() -> Int { 18 | return ATNState.PLUS_LOOP_BACK 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/PrecedencePredicateTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// 11 | /// - Sam Harwell 12 | /// 13 | 14 | public final class PrecedencePredicateTransition: AbstractPredicateTransition, CustomStringConvertible { 15 | public let precedence: Int 16 | 17 | public init(_ target: ATNState, _ precedence: Int) { 18 | 19 | self.precedence = precedence 20 | super.init(target) 21 | } 22 | 23 | override 24 | public func getSerializationType() -> Int { 25 | return Transition.PRECEDENCE 26 | } 27 | 28 | override 29 | public func isEpsilon() -> Bool { 30 | return true 31 | } 32 | 33 | override 34 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 35 | return false 36 | } 37 | 38 | public func getPredicate() -> SemanticContext.PrecedencePredicate { 39 | return SemanticContext.PrecedencePredicate(precedence) 40 | } 41 | 42 | public var description: String { 43 | return "\(precedence) >= _p" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/PredicateEvalInfo.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// This class represents profiling event information for semantic predicate 11 | /// evaluations which occur during prediction. 12 | /// 13 | /// - seealso: org.antlr.v4.runtime.atn.ParserATNSimulator#evalSemanticContext 14 | /// 15 | /// - 4.3 16 | /// 17 | 18 | public class PredicateEvalInfo: DecisionEventInfo { 19 | /// 20 | /// The semantic context which was evaluated. 21 | /// 22 | public private(set) var semctx: SemanticContext 23 | /// 24 | /// The alternative number for the decision which is guarded by the semantic 25 | /// context _#semctx_. Note that other ATN 26 | /// configurations may predict the same alternative which are guarded by 27 | /// other semantic contexts and/or _org.antlr.v4.runtime.atn.SemanticContext#NONE_. 28 | /// 29 | public private(set) var predictedAlt: Int 30 | /// 31 | /// The result of evaluating the semantic context _#semctx_. 32 | /// 33 | public private(set) var evalResult: Bool 34 | 35 | /// 36 | /// Constructs a new instance of the _org.antlr.v4.runtime.atn.PredicateEvalInfo_ class with the 37 | /// specified detailed predicate evaluation information. 38 | /// 39 | /// - parameter decision: The decision number 40 | /// - parameter input: The input token stream 41 | /// - parameter startIndex: The start index for the current prediction 42 | /// - parameter stopIndex: The index at which the predicate evaluation was 43 | /// triggered. Note that the input stream may be reset to other positions for 44 | /// the actual evaluation of individual predicates. 45 | /// - parameter semctx: The semantic context which was evaluated 46 | /// - parameter evalResult: The results of evaluating the semantic context 47 | /// - parameter predictedAlt: The alternative number for the decision which is 48 | /// guarded by the semantic context `semctx`. See _#predictedAlt_ 49 | /// for more information. 50 | /// - parameter fullCtx: `true` if the semantic context was 51 | /// evaluated during LL prediction; otherwise, `false` if the semantic 52 | /// context was evaluated during SLL prediction 53 | /// 54 | /// - seealso: org.antlr.v4.runtime.atn.ParserATNSimulator#evalSemanticContext(org.antlr.v4.runtime.atn.SemanticContext, org.antlr.v4.runtime.ParserRuleContext, int, boolean) 55 | /// - seealso: org.antlr.v4.runtime.atn.SemanticContext#eval(org.antlr.v4.runtime.Recognizer, org.antlr.v4.runtime.RuleContext) 56 | /// 57 | public init(_ decision: Int, 58 | _ input: TokenStream, 59 | _ startIndex: Int, 60 | _ stopIndex: Int, 61 | _ semctx: SemanticContext, 62 | _ evalResult: Bool, 63 | _ predictedAlt: Int, 64 | _ fullCtx: Bool) { 65 | 66 | self.semctx = semctx 67 | self.evalResult = evalResult 68 | self.predictedAlt = predictedAlt 69 | super.init(decision, ATNConfigSet(), input, startIndex, stopIndex, fullCtx) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/PredicateTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// TODO: this is old comment: 11 | /// A tree of semantic predicates from the grammar AST if label==SEMPRED. 12 | /// In the ATN, labels will always be exactly one predicate, but the DFA 13 | /// may have to combine a bunch of them as it collects predicates from 14 | /// multiple ATN configurations into a single DFA state. 15 | /// 16 | 17 | public final class PredicateTransition: AbstractPredicateTransition, CustomStringConvertible { 18 | public let ruleIndex: Int 19 | public let predIndex: Int 20 | public let isCtxDependent: Bool 21 | // e.g., $i ref in pred 22 | 23 | public init(_ target: ATNState, _ ruleIndex: Int, _ predIndex: Int, _ isCtxDependent: Bool) { 24 | 25 | self.ruleIndex = ruleIndex 26 | self.predIndex = predIndex 27 | self.isCtxDependent = isCtxDependent 28 | super.init(target) 29 | } 30 | 31 | override 32 | public func getSerializationType() -> Int { 33 | return PredicateTransition.PREDICATE 34 | } 35 | 36 | override 37 | public func isEpsilon() -> Bool { 38 | return true 39 | } 40 | 41 | override 42 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 43 | return false 44 | } 45 | 46 | public func getPredicate() -> SemanticContext.Predicate { 47 | return SemanticContext.Predicate(ruleIndex, predIndex, isCtxDependent) 48 | } 49 | 50 | public var description: String { 51 | return "pred_\(ruleIndex):\(predIndex)" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/PredictionContextCache.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// Used to cache _org.antlr.v4.runtime.atn.PredictionContext_ objects. Its used for the shared 10 | /// context cash associated with contexts in DFA states. This cache 11 | /// can be used for both lexers and parsers. 12 | /// 13 | 14 | public final class PredictionContextCache { 15 | private var cache = [PredictionContext: PredictionContext]() 16 | 17 | public init() { 18 | } 19 | 20 | /// 21 | /// Add a context to the cache and return it. If the context already exists, 22 | /// return that one instead and do not add a new context to the cache. 23 | /// Protect shared cache from unsafe thread access. 24 | /// 25 | @discardableResult 26 | public func add(_ ctx: PredictionContext) -> PredictionContext { 27 | if ctx === PredictionContext.EMPTY { 28 | return PredictionContext.EMPTY 29 | } 30 | if let existing = cache[ctx] { 31 | // print(name+" reuses "+existing); 32 | return existing 33 | } 34 | cache[ctx] = ctx 35 | return ctx 36 | } 37 | 38 | public func get(_ ctx: PredictionContext) -> PredictionContext? { 39 | return cache[ctx] 40 | } 41 | 42 | public func size() -> Int { 43 | return cache.count 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/RangeTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class RangeTransition: Transition, CustomStringConvertible { 9 | public let from: Int 10 | public let to: Int 11 | 12 | public init(_ target: ATNState, _ from: Int, _ to: Int) { 13 | 14 | self.from = from 15 | self.to = to 16 | super.init(target) 17 | } 18 | 19 | override 20 | public func getSerializationType() -> Int { 21 | return Transition.RANGE 22 | } 23 | 24 | override 25 | public func labelIntervalSet() -> IntervalSet? { 26 | return IntervalSet.of(from, to) 27 | } 28 | 29 | override 30 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 31 | return symbol >= from && symbol <= to 32 | } 33 | 34 | public var description: String { 35 | return "'" + String(from) + "'..'" + String(to) + "'" 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/RuleStartState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class RuleStartState: ATNState { 9 | public var stopState: RuleStopState? 10 | public var isPrecedenceRule: Bool = false 11 | //Synonymous with rule being left recursive; consider renaming. 12 | 13 | override 14 | public func getStateType() -> Int { 15 | return ATNState.RULE_START 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/RuleStopState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// The last node in the ATN for a rule, unless that rule is the start symbol. 11 | /// In that case, there is one transition to EOF. Later, we might encode 12 | /// references to all calls to this rule to compute FOLLOW sets for 13 | /// error handling. 14 | /// 15 | 16 | public final class RuleStopState: ATNState { 17 | 18 | override 19 | public func getStateType() -> Int { 20 | return ATNState.RULE_STOP 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/RuleTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | 10 | 11 | public final class RuleTransition: Transition { 12 | /// 13 | /// Ptr to the rule definition object for this rule ref 14 | /// 15 | public let ruleIndex: Int 16 | // no Rule object at runtime 17 | 18 | public let precedence: Int 19 | 20 | /// 21 | /// What node to begin computations following ref to rule 22 | /// 23 | public let followState: ATNState 24 | 25 | public init(_ ruleStart: RuleStartState, 26 | _ ruleIndex: Int, 27 | _ precedence: Int, 28 | _ followState: ATNState) { 29 | 30 | self.ruleIndex = ruleIndex 31 | self.precedence = precedence 32 | self.followState = followState 33 | 34 | super.init(ruleStart) 35 | } 36 | 37 | override 38 | public func getSerializationType() -> Int { 39 | return Transition.RULE 40 | } 41 | 42 | override 43 | public func isEpsilon() -> Bool { 44 | return true 45 | } 46 | 47 | override 48 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 49 | return false 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/SetTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// A transition containing a set of values. 11 | /// 12 | 13 | public class SetTransition: Transition, CustomStringConvertible { 14 | public let set: IntervalSet 15 | 16 | // TODO (sam): should we really allow null here? 17 | public init(_ target: ATNState, _ set: IntervalSet) { 18 | 19 | self.set = set 20 | super.init(target) 21 | } 22 | 23 | override 24 | public func getSerializationType() -> Int { 25 | return Transition.SET 26 | } 27 | 28 | override 29 | public func labelIntervalSet() -> IntervalSet? { 30 | return set 31 | } 32 | 33 | override 34 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 35 | return set.contains(symbol) 36 | } 37 | 38 | public var description: String { 39 | return set.description 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/SingletonPredictionContext.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | public class SingletonPredictionContext: PredictionContext { 10 | public final let parent: PredictionContext? 11 | public final let returnState: Int 12 | 13 | init(_ parent: PredictionContext?, _ returnState: Int) { 14 | 15 | //TODO assert 16 | //assert ( returnState=ATNState.INVALID_STATE_NUMBER,"Expected: returnState!/=ATNState.INVALID_STATE_NUMBER"); 17 | self.parent = parent 18 | self.returnState = returnState 19 | 20 | 21 | super.init(parent != nil ? PredictionContext.calculateHashCode(parent!, returnState) : PredictionContext.calculateEmptyHashCode()) 22 | } 23 | 24 | public static func create(_ parent: PredictionContext?, _ returnState: Int) -> SingletonPredictionContext { 25 | if returnState == PredictionContext.EMPTY_RETURN_STATE && parent == nil { 26 | // someone can pass in the bits of an array ctx that mean $ 27 | return PredictionContext.EMPTY 28 | } 29 | return SingletonPredictionContext(parent, returnState) 30 | } 31 | 32 | override 33 | public func size() -> Int { 34 | return 1 35 | } 36 | 37 | override 38 | public func getParent(_ index: Int) -> PredictionContext? { 39 | assert(index == 0, "Expected: index==0") 40 | return parent 41 | } 42 | 43 | override 44 | public func getReturnState(_ index: Int) -> Int { 45 | assert(index == 0, "Expected: index==0") 46 | return returnState 47 | } 48 | 49 | 50 | override 51 | public var description: String { 52 | let up = parent?.description ?? "" 53 | if up.isEmpty { 54 | if returnState == PredictionContext.EMPTY_RETURN_STATE { 55 | return "$" 56 | } 57 | return String(returnState) 58 | } 59 | return String(returnState) + " " + up 60 | } 61 | } 62 | 63 | 64 | public func ==(lhs: SingletonPredictionContext, rhs: SingletonPredictionContext) -> Bool { 65 | if lhs === rhs { 66 | return true 67 | } 68 | if lhs.hashValue != rhs.hashValue { 69 | return false 70 | } 71 | if lhs.returnState != rhs.returnState { 72 | return false 73 | } 74 | var parentCompare = false 75 | if (lhs.parent == nil) && (rhs.parent == nil) { 76 | parentCompare = true 77 | } else if lhs.parent == nil || rhs.parent == nil { 78 | parentCompare = false 79 | } else { 80 | parentCompare = (lhs.parent! == rhs.parent!) 81 | } 82 | 83 | return parentCompare 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/StarBlockStartState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// The block that begins a closure loop. 11 | /// 12 | 13 | public final class StarBlockStartState: BlockStartState { 14 | 15 | override 16 | public func getStateType() -> Int { 17 | return ATNState.STAR_BLOCK_START 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/StarLoopEntryState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class StarLoopEntryState: DecisionState { 9 | public var loopBackState: StarLoopbackState? 10 | 11 | /// 12 | /// Indicates whether this state can benefit from a precedence DFA during SLL 13 | /// decision making. 14 | /// 15 | /// This is a computed property that is calculated during ATN deserialization 16 | /// and stored for use in _org.antlr.v4.runtime.atn.ParserATNSimulator_ and 17 | /// _org.antlr.v4.runtime.ParserInterpreter_. 18 | /// 19 | /// - seealso: org.antlr.v4.runtime.dfa.DFA#isPrecedenceDfa() 20 | /// 21 | public var precedenceRuleDecision: Bool = false 22 | 23 | override 24 | public func getStateType() -> Int { 25 | return ATNState.STAR_LOOP_ENTRY 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/StarLoopbackState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public final class StarLoopbackState: ATNState { 9 | public func getLoopEntryState() -> StarLoopEntryState { 10 | return transition(0).target as! StarLoopEntryState 11 | } 12 | 13 | override 14 | public func getStateType() -> Int { 15 | return ATNState.STAR_LOOP_BACK 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/TokensStartState.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// The Tokens rule start state linking to each lexer rule start state 10 | /// 11 | 12 | public final class TokensStartState: DecisionState { 13 | 14 | override 15 | public func getStateType() -> Int { 16 | return ATNState.TOKEN_START 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/Transition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// An ATN transition between any two ATN states. Subclasses define 10 | /// atom, set, epsilon, action, predicate, rule transitions. 11 | /// 12 | /// This is a one way link. It emanates from a state (usually via a list of 13 | /// transitions) and has a target state. 14 | /// 15 | /// Since we never have to change the ATN transitions once we construct it, 16 | /// we can fix these transitions as specific classes. The DFA transitions 17 | /// on the other hand need to update the labels as it adds transitions to 18 | /// the states. We'll use the term Edge for the DFA to distinguish them from 19 | /// ATN transitions. 20 | /// 21 | 22 | import Foundation 23 | 24 | public class Transition { 25 | // constants for serialization 26 | public static let EPSILON: Int = 1 27 | public static let RANGE: Int = 2 28 | public static let RULE: Int = 3 29 | public static let PREDICATE: Int = 4 30 | // e.g., {isType(input.LT(1))}? 31 | public static let ATOM: Int = 5 32 | public static let ACTION: Int = 6 33 | public static let SET: Int = 7 34 | // ~(A|B) or ~atom, wildcard, which convert to next 2 35 | public static let NOT_SET: Int = 8 36 | public static let WILDCARD: Int = 9 37 | public static let PRECEDENCE: Int = 10 38 | 39 | 40 | public let serializationNames: Array = 41 | 42 | ["INVALID", 43 | "EPSILON", 44 | "RANGE", 45 | "RULE", 46 | "PREDICATE", 47 | "ATOM", 48 | "ACTION", 49 | "SET", 50 | "NOT_SET", 51 | "WILDCARD", 52 | "PRECEDENCE"] 53 | 54 | 55 | public static let serializationTypes: Dictionary = [ 56 | 57 | String(describing: EpsilonTransition.self): EPSILON, 58 | String(describing: RangeTransition.self): RANGE, 59 | String(describing: RuleTransition.self): RULE, 60 | String(describing: PredicateTransition.self): PREDICATE, 61 | String(describing: AtomTransition.self): ATOM, 62 | String(describing: ActionTransition.self): ACTION, 63 | String(describing: SetTransition.self): SET, 64 | String(describing: NotSetTransition.self): NOT_SET, 65 | String(describing: WildcardTransition.self): WILDCARD, 66 | String(describing: PrecedencePredicateTransition.self): PRECEDENCE, 67 | 68 | 69 | ] 70 | 71 | 72 | /// 73 | /// The target of this transition. 74 | /// 75 | 76 | public internal(set) final var target: ATNState 77 | 78 | init(_ target: ATNState) { 79 | 80 | 81 | self.target = target 82 | } 83 | 84 | public func getSerializationType() -> Int { 85 | fatalError(#function + " must be overridden") 86 | } 87 | 88 | /// 89 | /// Determines if the transition is an "epsilon" transition. 90 | /// 91 | /// The default implementation returns `false`. 92 | /// 93 | /// - returns: `true` if traversing this transition in the ATN does not 94 | /// consume an input symbol; otherwise, `false` if traversing this 95 | /// transition consumes (matches) an input symbol. 96 | /// 97 | public func isEpsilon() -> Bool { 98 | return false 99 | } 100 | 101 | 102 | public func labelIntervalSet() -> IntervalSet? { 103 | return nil 104 | } 105 | 106 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 107 | fatalError(#function + " must be overridden") 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/atn/WildcardTransition.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | final public class WildcardTransition: Transition, CustomStringConvertible { 9 | public override init(_ target: ATNState) { 10 | super.init(target) 11 | } 12 | 13 | override 14 | public func getSerializationType() -> Int { 15 | return Transition.WILDCARD 16 | } 17 | 18 | override 19 | public func matches(_ symbol: Int, _ minVocabSymbol: Int, _ maxVocabSymbol: Int) -> Bool { 20 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 21 | } 22 | 23 | public var description: String { 24 | 25 | return "." 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/dfa/DFASerializer.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | /// 9 | /// A DFA walker that knows how to dump them to serialized strings. 10 | /// 11 | 12 | public class DFASerializer: CustomStringConvertible { 13 | private let dfa: DFA 14 | private let vocabulary: Vocabulary 15 | 16 | public init(_ dfa: DFA, _ vocabulary: Vocabulary) { 17 | self.dfa = dfa 18 | self.vocabulary = vocabulary 19 | } 20 | 21 | public var description: String { 22 | if dfa.s0 == nil { 23 | return "" 24 | } 25 | var buf = "" 26 | let states = dfa.getStates() 27 | for s in states { 28 | guard let edges = s.edges else { 29 | continue 30 | } 31 | for (i, t) in edges.enumerated() { 32 | guard let t = t, t.stateNumber != Int.max else { 33 | continue 34 | } 35 | let edgeLabel = getEdgeLabel(i) 36 | buf += getStateString(s) 37 | buf += "-\(edgeLabel)->" 38 | buf += getStateString(t) 39 | buf += "\n" 40 | } 41 | } 42 | 43 | return buf 44 | } 45 | 46 | internal func getEdgeLabel(_ i: Int) -> String { 47 | return vocabulary.getDisplayName(i - 1) 48 | } 49 | 50 | 51 | internal func getStateString(_ s: DFAState) -> String { 52 | let n = s.stateNumber 53 | 54 | let s1 = s.isAcceptState ? ":" : "" 55 | let s2 = s.requiresFullContext ? "^" : "" 56 | let baseStateStr = s1 + "s" + String(n) + s2 57 | if s.isAcceptState { 58 | if let predicates = s.predicates { 59 | return baseStateStr + "=>\(predicates)" 60 | } else { 61 | return baseStateStr + "=>\(s.prediction)" 62 | } 63 | } else { 64 | return baseStateStr 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/dfa/LexerDFASerializer.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | public class LexerDFASerializer: DFASerializer { 9 | public init(_ dfa: DFA) { 10 | super.init(dfa, Vocabulary.EMPTY_VOCABULARY) 11 | } 12 | 13 | override 14 | 15 | internal func getEdgeLabel(_ i: Int) -> String { 16 | return "'\(Character(integerLiteral: i))'" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/DoubleKeyMap.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | 9 | /// 10 | /// Sometimes we need to map a key to a value but key is two pieces of data. 11 | /// This nested hash table saves creating a single key each time we access 12 | /// map; avoids mem creation. 13 | /// 14 | public struct DoubleKeyMap { 15 | private var data = [Key1: [Key2: Value]]() 16 | 17 | @discardableResult 18 | public mutating func put(_ k1: Key1, _ k2: Key2, _ v: Value) -> Value? { 19 | 20 | let prev: Value? 21 | if var data2 = data[k1] { 22 | prev = data2[k2] 23 | data2[k2] = v 24 | data[k1] = data2 25 | } 26 | else { 27 | prev = nil 28 | let data2 = [ 29 | k2: v 30 | ] 31 | data[k1] = data2 32 | } 33 | return prev 34 | } 35 | 36 | public func get(_ k1: Key1, _ k2: Key2) -> Value? { 37 | if let data2 = data[k1] { 38 | return data2[k2] 39 | } 40 | return nil 41 | } 42 | 43 | public func get(_ k1: Key1) -> [Key2: Value]? { 44 | return data[k1] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/MultiMap.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | public class MultiMap { 7 | private var mapping = [K: Array]() 8 | public func map(_ key: K, _ value: V) { 9 | mapping[key, default: Array()].append(value) 10 | } 11 | 12 | public func getPairs() -> Array<(K, V)> { 13 | var pairs: Array<(K, V)> = Array<(K, V)>() 14 | for key: K in mapping.keys { 15 | for value: V in mapping[key]! { 16 | pairs.append((key, value)) 17 | } 18 | } 19 | return pairs 20 | } 21 | 22 | public func get(_ key: K) -> Array<(V)>? { 23 | return mapping[key] 24 | } 25 | 26 | public func size() -> Int { 27 | return mapping.count 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/Utils.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | 8 | import Foundation 9 | 10 | public class Utils { 11 | 12 | public static func escapeWhitespace(_ s: String, _ escapeSpaces: Bool) -> String { 13 | var buf = "" 14 | for c in s { 15 | if c == " " && escapeSpaces { 16 | buf += "\u{00B7}" 17 | } 18 | else if c == "\t" { 19 | buf += "\\t" 20 | } 21 | else if c == "\n" { 22 | buf += "\\n" 23 | } 24 | else if c == "\r" { 25 | buf += "\\r" 26 | } 27 | else { 28 | buf.append(c) 29 | } 30 | } 31 | return buf 32 | } 33 | 34 | 35 | public static func toMap(_ keys: [String]) -> [String: Int] { 36 | var m = [String: Int]() 37 | for (index, v) in keys.enumerated() { 38 | m[v] = index 39 | } 40 | return m 41 | } 42 | 43 | public static func bitLeftShift(_ n: Int) -> Int64 { 44 | return (Int64(1) << Int64(n % 64)) 45 | } 46 | 47 | 48 | public static func testBitLeftShiftArray(_ nArray: [Int],_ bitsShift: Int) -> Bool { 49 | let test: Bool = (((nArray[0] - bitsShift) & ~0x3f) == 0) 50 | 51 | var temp: Int64 = Int64(nArray[0] - bitsShift) 52 | temp = (temp < 0) ? (64 + (temp % 64 )) : (temp % 64) 53 | let test1: Int64 = (Int64(1) << temp) 54 | 55 | var test2: Int64 = Utils.bitLeftShift(nArray[1] - bitsShift) 56 | 57 | for i in 1 ..< nArray.count { 58 | test2 = test2 | Utils.bitLeftShift(nArray[i] - bitsShift) 59 | } 60 | return test && (( test1 & test2 ) != 0) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // ANTLRError.swift 9 | // antlr.swift 10 | // 11 | // Created by janyou on 15/9/4. 12 | // 13 | 14 | import Foundation 15 | 16 | public enum ANTLRError: Error { 17 | case unsupportedOperation(msg:String) 18 | case indexOutOfBounds(msg:String) 19 | case illegalState(msg:String) 20 | case illegalArgument(msg:String) 21 | case negativeArraySize(msg:String) 22 | } 23 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRException.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // ANTLRException.swift 9 | // antlr.swift 10 | // 11 | // Created by janyou on 15/9/8. 12 | // 13 | 14 | 15 | import Foundation 16 | 17 | public enum ANTLRException: Error { 18 | case parseCancellation(e: RecognitionException) 19 | case recognition(e: RecognitionException) 20 | } 21 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/extension/ArrayExtension.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | import Foundation 8 | 9 | //https://github.com/pNre/ExSwift/blob/master/ExSwift/Array.swift 10 | extension Array { 11 | @discardableResult 12 | mutating func concat(_ addArray: [Element]) -> [Element] { 13 | return self + addArray 14 | } 15 | 16 | mutating func removeObject(_ object: T) { 17 | var index: Int? 18 | for (idx, objectToCompare) in self.enumerated() { 19 | 20 | if let to = objectToCompare as? T { 21 | if object == to { 22 | index = idx 23 | } 24 | } 25 | } 26 | 27 | if index != nil { 28 | 29 | self.remove(at: index!) 30 | } 31 | 32 | } 33 | 34 | /// 35 | /// Removes the last element from self and returns it. 36 | /// 37 | /// :returns: The removed element 38 | /// 39 | mutating func pop() -> Element { 40 | return removeLast() 41 | } 42 | /// 43 | /// Same as append. 44 | /// 45 | /// :param: newElement Element to append 46 | /// 47 | mutating func push(_ newElement: Element) { 48 | return append(newElement) 49 | } 50 | 51 | func all(_ test: (Element) -> Bool) -> Bool { 52 | for item in self { 53 | if !test(item) { 54 | return false 55 | } 56 | } 57 | 58 | return true 59 | } 60 | 61 | 62 | /// 63 | /// Checks if test returns true for all the elements in self 64 | /// 65 | /// :param: test Function to call for each element 66 | /// :returns: True if test returns true for all the elements in self 67 | /// 68 | func every(_ test: (Element) -> Bool) -> Bool { 69 | for item in self { 70 | if !test(item) { 71 | return false 72 | } 73 | } 74 | 75 | return true 76 | } 77 | 78 | /// 79 | /// Checks if test returns true for any element of self. 80 | /// 81 | /// :param: test Function to call for each element 82 | /// :returns: true if test returns true for any element of self 83 | /// 84 | func any(_ test: (Element) -> Bool) -> Bool { 85 | for item in self { 86 | if test(item) { 87 | return true 88 | } 89 | } 90 | 91 | return false 92 | } 93 | 94 | 95 | 96 | /// 97 | /// slice array 98 | /// :param: index slice index 99 | /// :param: isClose is close array 100 | /// :param: first First array 101 | /// :param: second Second array 102 | /// 103 | //func slice(startIndex startIndex:Int, endIndex:Int) -> Slice { 104 | func slice(startIndex: Int, endIndex: Int) -> ArraySlice { 105 | 106 | 107 | return self[startIndex ... endIndex] 108 | 109 | } 110 | // func slice(index:Int,isClose:Bool = false) ->(first:Slice ,second:Slice){ 111 | func slice(_ index: Int, isClose: Bool = false) -> (first:ArraySlice, second:ArraySlice) { 112 | var first = self[0 ... index] 113 | var second = self[index ..< count] 114 | 115 | if isClose { 116 | first = second + first 117 | second = [] 118 | } 119 | 120 | return (first, second) 121 | 122 | } 123 | 124 | 125 | } 126 | 127 | 128 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/extension/CharacterExtension.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // CharacterEextension.swift 9 | // Antlr.swift 10 | // 11 | // Created by janyou on 15/9/4. 12 | // 13 | 14 | import Foundation 15 | 16 | extension Character { 17 | 18 | //"1" -> 1 "2" -> 2 19 | var integerValue: Int { 20 | return Int(String(self)) ?? 0 21 | } 22 | public init(integerLiteral value: IntegerLiteralType) { 23 | self = Character(UnicodeScalar(value)!) 24 | } 25 | var utf8Value: UInt8 { 26 | for s in String(self).utf8 { 27 | return s 28 | } 29 | return 0 30 | } 31 | 32 | var utf16Value: UInt16 { 33 | for s in String(self).utf16 { 34 | return s 35 | } 36 | return 0 37 | } 38 | 39 | //char -> int 40 | var unicodeValue: Int { 41 | return Int(String(self).unicodeScalars.first?.value ?? 0) 42 | } 43 | 44 | public static var MAX_VALUE: Int { 45 | let c: Character = "\u{10FFFF}" 46 | return c.unicodeValue 47 | } 48 | public static var MIN_VALUE: Int { 49 | let c: Character = "\u{0000}" 50 | return c.unicodeValue 51 | } 52 | 53 | public static func isJavaIdentifierStart(_ char: Int) -> Bool { 54 | let ch = Character(integerLiteral: char) 55 | return ch == "_" || ch == "$" || ("a" <= ch && ch <= "z") 56 | || ("A" <= ch && ch <= "Z") 57 | 58 | } 59 | 60 | public static func isJavaIdentifierPart(_ char: Int) -> Bool { 61 | let ch = Character(integerLiteral: char) 62 | return isJavaIdentifierStart(char) || ("0" <= ch && ch <= "9") 63 | } 64 | 65 | public static func toCodePoint(_ high: Int, _ low: Int) -> Int { 66 | let MIN_SUPPLEMENTARY_CODE_POINT = 65536 // 0x010000 67 | let MIN_HIGH_SURROGATE = 0xd800 //"\u{dbff}" //"\u{DBFF}" //"\u{DBFF}" 68 | let MIN_LOW_SURROGATE = 0xdc00 //"\u{dc00}" //"\u{DC00}" 69 | return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT 70 | - (MIN_HIGH_SURROGATE << 10) 71 | - MIN_LOW_SURROGATE) 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/extension/IntStreamExtension.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // IntStreamExtension.swift 9 | // Antlr.swift 10 | // 11 | // Created by janyou on 15/9/3. 12 | // 13 | 14 | import Foundation 15 | 16 | extension IntStream { 17 | 18 | /// 19 | /// The value returned by _#LA LA()_ when the end of the stream is 20 | /// reached. 21 | /// 22 | public static var EOF: Int { 23 | return -1 24 | } 25 | 26 | /// 27 | /// The value returned by _#getSourceName_ when the actual name of the 28 | /// underlying source is not known. 29 | /// 30 | public static var UNKNOWN_SOURCE_NAME: String { 31 | return "" 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | import Foundation 8 | 9 | extension String { 10 | func lastIndex(of target: String) -> String.Index? { 11 | if target.isEmpty { 12 | return nil 13 | } 14 | var result: String.Index? = nil 15 | var substring = self[...] 16 | while true { 17 | guard let targetRange = substring.range(of: target) else { 18 | return result 19 | } 20 | result = targetRange.lowerBound 21 | let nextChar = substring.index(after: targetRange.lowerBound) 22 | substring = self[nextChar...] 23 | } 24 | } 25 | 26 | subscript(integerRange: Range) -> String { 27 | let start = index(startIndex, offsetBy: integerRange.lowerBound) 28 | let end = index(startIndex, offsetBy: integerRange.upperBound) 29 | let range = start ..< end 30 | return String(self[range]) 31 | } 32 | } 33 | 34 | 35 | // Implement Substring.hasPrefix, which is not currently in the Linux stdlib. 36 | // https://bugs.swift.org/browse/SR-5627 37 | #if os(Linux) 38 | extension Substring { 39 | func hasPrefix(_ prefix: String) -> Bool { 40 | return String(self).hasPrefix(prefix) 41 | } 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/extension/TokenExtension.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | // 8 | // TokenExtension.swift 9 | // Antlr.swift 10 | // 11 | // Created by janyou on 15/9/4. 12 | // 13 | 14 | import Foundation 15 | 16 | extension Token { 17 | 18 | static public var INVALID_TYPE: Int { 19 | return 0 20 | } 21 | 22 | /// 23 | /// During lookahead operations, this "token" signifies we hit rule end ATN state 24 | /// and did not follow it despite needing to. 25 | /// 26 | static public var EPSILON: Int { 27 | return -2 28 | } 29 | 30 | 31 | static public var MIN_USER_TOKEN_TYPE: Int { 32 | return 1 33 | } 34 | 35 | static public var EOF: Int { 36 | return -1 37 | } 38 | 39 | /// 40 | /// All tokens go to the parser (unless skip() is called in that rule) 41 | /// on a particular "channel". The parser tunes to a particular channel 42 | /// so that whitespace etc... can go to the parser on a "hidden" channel. 43 | /// 44 | static public var DEFAULT_CHANNEL: Int { 45 | return 0 46 | } 47 | 48 | /// 49 | /// Anything on different channel than DEFAULT_CHANNEL is not parsed 50 | /// by parser. 51 | /// 52 | static public var HIDDEN_CHANNEL: Int { 53 | return 1 54 | } 55 | 56 | /// 57 | /// This is the minimum constant value which can be assigned to a 58 | /// user-defined token channel. 59 | /// 60 | /// 61 | /// The non-negative numbers less than _#MIN_USER_CHANNEL_VALUE_ are 62 | /// assigned to the predefined channels _#DEFAULT_CHANNEL_ and 63 | /// _#HIDDEN_CHANNEL_. 64 | /// 65 | /// - seealso: org.antlr.v4.runtime.Token#getChannel() 66 | /// 67 | static public var MIN_USER_CHANNEL_VALUE: Int { 68 | return 2 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/extension/UUIDExtension.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | /// Use of this file is governed by the BSD 3-clause license that 4 | /// can be found in the LICENSE.txt file in the project root. 5 | /// 6 | 7 | import Foundation 8 | 9 | 10 | extension UUID { 11 | public init(mostSigBits: Int64, leastSigBits: Int64) { 12 | let bytes = UnsafeMutablePointer.allocate(capacity: 16) 13 | defer { 14 | bytes.deallocate() 15 | } 16 | bytes.withMemoryRebound(to: Int64.self, capacity: 2) { 17 | $0.pointee = leastSigBits 18 | $0.advanced(by: 1).pointee = mostSigBits 19 | } 20 | let u = NSUUID(uuidBytes: bytes) 21 | self.init(uuidString: u.uuidString)! 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/utils/CommonUtil.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | // 7 | // CommonUtil.swift 8 | // antlr.swift 9 | // 10 | // Created by janyou on 15/9/4. 11 | // 12 | 13 | import Foundation 14 | 15 | func errPrint(_ msg: String) { 16 | fputs(msg + "\n", stderr) 17 | } 18 | 19 | public func +(lhs: String, rhs: Int) -> String { 20 | return lhs + String(rhs) 21 | } 22 | 23 | public func +(lhs: Int, rhs: String) -> String { 24 | return String(lhs) + rhs 25 | } 26 | 27 | public func +(lhs: String, rhs: Token) -> String { 28 | return lhs + rhs.description 29 | } 30 | 31 | public func +(lhs: Token, rhs: String) -> String { 32 | return lhs.description + rhs 33 | } 34 | 35 | infix operator >>> : BitwiseShiftPrecedence 36 | 37 | func >>>(lhs: Int32, rhs: Int32) -> Int32 { 38 | let left = UInt32(bitPattern: lhs) 39 | let right = UInt32(bitPattern: rhs) % 32 40 | 41 | return Int32(bitPattern: left >> right) 42 | } 43 | 44 | func >>>(lhs: Int64, rhs: Int64) -> Int64 { 45 | let left = UInt64(bitPattern: lhs) 46 | let right = UInt64(bitPattern: rhs) % 64 47 | 48 | return Int64(bitPattern: left >> right) 49 | } 50 | 51 | func >>>(lhs: Int, rhs: Int) -> Int { 52 | let numberOfBits: UInt = MemoryLayout.size == MemoryLayout.size ? 64 : 32 53 | 54 | let left = UInt(bitPattern: lhs) 55 | let right = UInt(bitPattern: rhs) % numberOfBits 56 | 57 | return Int(bitPattern: left >> right) 58 | } 59 | 60 | func intChar2String(_ i: Int) -> String { 61 | return String(Character(integerLiteral: i)) 62 | } 63 | 64 | func log(_ message: String = "", file: String = #file, function: String = #function, lineNum: Int = #line) { 65 | 66 | // #if DEBUG 67 | print("FILE: \(URL(fileURLWithPath: file).pathComponents.last!),FUNC: \(function), LINE: \(lineNum) MESSAGE: \(message)") 68 | // #else 69 | // do nothing 70 | // #endif 71 | } 72 | 73 | func toInt(_ c: Character) -> Int { 74 | return c.unicodeValue 75 | } 76 | 77 | func toInt32(_ data: [Character], _ offset: Int) -> Int { 78 | return data[offset].unicodeValue | (data[offset + 1].unicodeValue << 16) 79 | } 80 | 81 | func toLong(_ data: [Character], _ offset: Int) -> Int64 { 82 | let mask: Int64 = 0x00000000FFFFFFFF 83 | let lowOrder: Int64 = Int64(toInt32(data, offset)) & mask 84 | return lowOrder | Int64(toInt32(data, offset + 2) << 32) 85 | } 86 | 87 | func toUUID(_ data: [Character], _ offset: Int) -> UUID { 88 | let leastSigBits: Int64 = toLong(data, offset) 89 | let mostSigBits: Int64 = toLong(data, offset + 4) 90 | return UUID(mostSigBits: mostSigBits, leastSigBits: leastSigBits) 91 | } 92 | 93 | func ==(_ lhs: [T?], _ rhs: [T?]) -> Bool { 94 | 95 | if lhs.count != rhs.count { 96 | return false 97 | } 98 | 99 | for i in 0..(closure: () throws -> R) rethrows -> R { 31 | pthread_mutex_lock(&mutex) 32 | defer { 33 | pthread_mutex_unlock(&mutex) 34 | } 35 | return try closure() 36 | } 37 | 38 | deinit { 39 | // free the mutex resource 40 | pthread_mutex_destroy(&mutex) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/misc/utils/Stack.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | // 7 | // Stack.swift 8 | // antlr.swift 9 | // 10 | // Created by janyou on 15/9/8. 11 | // 12 | 13 | import Foundation 14 | 15 | public struct Stack { 16 | var items = [T]() 17 | public mutating func push(_ item: T) { 18 | items.append(item) 19 | } 20 | @discardableResult 21 | public mutating func pop() -> T { 22 | return items.removeLast() 23 | } 24 | 25 | public mutating func clear() { 26 | return items.removeAll() 27 | } 28 | 29 | public func peek() -> T? { 30 | return items.last 31 | } 32 | public var isEmpty: Bool { 33 | return items.isEmpty 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/ErrorNode.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// Represents a token that was consumed during resynchronization 8 | /// rather than during a valid match operation. For example, 9 | /// we will create this kind of a node during single token insertion 10 | /// and deletion as well as during "consume until error recovery set" 11 | /// upon no viable alternative exceptions. 12 | /// 13 | public class ErrorNode: TerminalNodeImpl { 14 | public override init(_ token: Token) { 15 | super.init(token) 16 | } 17 | 18 | 19 | override 20 | public func accept(_ visitor: ParseTreeVisitor) -> T? { 21 | return visitor.visitErrorNode(self) 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/ParseTree.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// An interface to access the tree of _org.antlr.v4.runtime.RuleContext_ objects created 8 | /// during a parse that makes the data structure look like a simple parse tree. 9 | /// This node represents both internal nodes, rule invocations, 10 | /// and leaf nodes, token matches. 11 | /// 12 | /// The payload is either a _org.antlr.v4.runtime.Token_ or a _org.antlr.v4.runtime.RuleContext_ object. 13 | /// 14 | public protocol ParseTree: SyntaxTree, CustomStringConvertible, CustomDebugStringConvertible { 15 | /// Set the parent for this leaf node. 16 | func setParent(_ parent: RuleContext) 17 | 18 | /// The _org.antlr.v4.runtime.tree.ParseTreeVisitor_ needs a double dispatch method. 19 | func accept(_ visitor: ParseTreeVisitor) -> T? 20 | 21 | /// Return the combined text of all leaf nodes. Does not get any 22 | /// off-channel tokens (if any) so won't return whitespace and 23 | /// comments if they are sent to parser on hidden channel. 24 | func getText() -> String 25 | 26 | /// Specialize toStringTree so that it can print out more information 27 | /// based upon the parser. 28 | func toStringTree(_ parser: Parser) -> String 29 | 30 | /// Equivalent to `getChild(index)! as! ParseTree` 31 | subscript(index: Int) -> ParseTree { get } 32 | } 33 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/ParseTreeListener.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | 8 | /// This interface describes the minimal core of methods triggered 9 | /// by _org.antlr.v4.runtime.tree.ParseTreeWalker_. E.g., 10 | /// 11 | /// ParseTreeWalker walker = new ParseTreeWalker(); 12 | /// walker.walk(myParseTreeListener, myParseTree); <-- triggers events in your listener 13 | /// 14 | /// If you want to trigger events in multiple listeners during a single 15 | /// tree walk, you can use the ParseTreeDispatcher object available at 16 | /// 17 | /// https://github.com/antlr/antlr4/issues/841 18 | /// 19 | 20 | public protocol ParseTreeListener: AnyObject { 21 | func visitTerminal(_ node: TerminalNode) 22 | 23 | func visitErrorNode(_ node: ErrorNode) 24 | 25 | func enterEveryRule(_ ctx: ParserRuleContext) throws 26 | 27 | func exitEveryRule(_ ctx: ParserRuleContext) throws 28 | } 29 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/ParseTreeProperty.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | import Foundation 6 | 7 | public class ParseTreeProperty { 8 | var annotations = Dictionary() 9 | 10 | public init() {} 11 | 12 | open func get(_ node: ParseTree) -> V? { return annotations[ObjectIdentifier(node)] } 13 | open func put(_ node: ParseTree, _ value: V) { annotations[ObjectIdentifier(node)] = value } 14 | open func removeFrom(_ node: ParseTree) { annotations.removeValue(forKey: ObjectIdentifier(node)) } 15 | } 16 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/ParseTreeVisitor.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | 8 | /// 9 | /// This interface defines the basic notion of a parse tree visitor. Generated 10 | /// visitors implement this interface and the `XVisitor` interface for 11 | /// grammar `X`. 12 | /// 13 | /// - Parameter : The return type of the visit operation. Use _Void_ for 14 | /// operations with no return type. 15 | /// 16 | 17 | 18 | open class ParseTreeVisitor { 19 | public init() { 20 | 21 | } 22 | // typealias T 23 | /// 24 | /// Visit a parse tree, and return a user-defined result of the operation. 25 | /// 26 | /// - Parameter tree: The _org.antlr.v4.runtime.tree.ParseTree_ to visit. 27 | /// - Returns: The result of visiting the parse tree. 28 | /// 29 | open func visit(_ tree: ParseTree) -> T? { 30 | fatalError(#function + " must be overridden") 31 | } 32 | 33 | /// 34 | /// Visit the children of a node, and return a user-defined result of the 35 | /// operation. 36 | /// 37 | /// - Parameter node: The _org.antlr.v4.runtime.tree.RuleNode_ whose children should be visited. 38 | /// - Returns: The result of visiting the children of the node. 39 | /// 40 | open func visitChildren(_ node: RuleNode) -> T? { 41 | fatalError(#function + " must be overridden") 42 | } 43 | 44 | /// 45 | /// Visit a terminal node, and return a user-defined result of the operation. 46 | /// 47 | /// - Parameter node: The _org.antlr.v4.runtime.tree.TerminalNode_ to visit. 48 | /// - Returns: The result of visiting the node. 49 | /// 50 | open func visitTerminal(_ node: TerminalNode) -> T? { 51 | fatalError(#function + " must be overridden") 52 | } 53 | 54 | /// 55 | /// Visit an error node, and return a user-defined result of the operation. 56 | /// 57 | /// - Parameter node: The _org.antlr.v4.runtime.tree.ErrorNode_ to visit. 58 | /// - Returns: The result of visiting the node. 59 | /// 60 | open func visitErrorNode(_ node: ErrorNode) -> T? { 61 | fatalError(#function + " must be overridden") 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/ParseTreeWalker.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | public class ParseTreeWalker { 8 | public static let DEFAULT = ParseTreeWalker() 9 | 10 | public init() { 11 | } 12 | 13 | /** 14 | * Performs a walk on the given parse tree starting at the root and going down recursively 15 | * with depth-first search. On each node, ParseTreeWalker.enterRule is called before 16 | * recursively walking down into child nodes, then 17 | * ParseTreeWalker.exitRule is called after the recursive call to wind up. 18 | * - Parameter listener: The listener used by the walker to process grammar rules 19 | * - Parameter t: The parse tree to be walked on 20 | */ 21 | public func walk(_ listener: ParseTreeListener, _ t: ParseTree) throws { 22 | if let errNode = t as? ErrorNode { 23 | listener.visitErrorNode(errNode) 24 | } 25 | else if let termNode = t as? TerminalNode { 26 | listener.visitTerminal(termNode) 27 | } 28 | else if let r = t as? RuleNode { 29 | try enterRule(listener, r) 30 | let n = r.getChildCount() 31 | for i in 0.. RuleContext 9 | } 10 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/SyntaxTree.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// A tree that knows about an interval in a token stream 8 | /// is some kind of syntax tree. Subinterfaces distinguish 9 | /// between parse trees and other kinds of syntax trees we might want to create. 10 | /// 11 | 12 | public protocol SyntaxTree: Tree { 13 | /// 14 | /// Return an _org.antlr.v4.runtime.misc.Interval_ indicating the index in the 15 | /// _org.antlr.v4.runtime.TokenStream_ of the first and last token associated with this 16 | /// subtree. If this node is a leaf, then the interval represents a single 17 | /// token. 18 | /// 19 | /// If source interval is unknown, this returns _org.antlr.v4.runtime.misc.Interval#INVALID_. 20 | /// 21 | 22 | func getSourceInterval() -> Interval 23 | } 24 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/TerminalNode.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | public protocol TerminalNode: ParseTree { 8 | func getSymbol() -> Token? 9 | } 10 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/TerminalNodeImpl.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | public class TerminalNodeImpl: TerminalNode { 8 | public var symbol: Token 9 | public weak var parent: ParseTree? 10 | 11 | public init(_ symbol: Token) { 12 | self.symbol = symbol 13 | } 14 | 15 | 16 | public func getChild(_ i: Int) -> Tree? { 17 | return nil 18 | } 19 | 20 | open subscript(index: Int) -> ParseTree { 21 | preconditionFailure("Index out of range (TerminalNode never has children)") 22 | } 23 | 24 | public func getSymbol() -> Token? { 25 | return symbol 26 | } 27 | 28 | public func getParent() -> Tree? { 29 | return parent 30 | } 31 | 32 | public func setParent(_ parent: RuleContext) { 33 | self.parent = parent 34 | } 35 | 36 | public func getPayload() -> AnyObject { 37 | return symbol 38 | } 39 | 40 | public func getSourceInterval() -> Interval { 41 | //if symbol == nil { return Interval.INVALID; } 42 | 43 | let tokenIndex: Int = symbol.getTokenIndex() 44 | return Interval(tokenIndex, tokenIndex) 45 | } 46 | 47 | public func getChildCount() -> Int { 48 | return 0 49 | } 50 | 51 | 52 | public func accept(_ visitor: ParseTreeVisitor) -> T? { 53 | return visitor.visitTerminal(self) 54 | } 55 | 56 | public func getText() -> String { 57 | return (symbol.getText())! 58 | } 59 | 60 | public func toStringTree(_ parser: Parser) -> String { 61 | return description 62 | } 63 | 64 | public var description: String { 65 | //TODO: symbol == nil? 66 | //if symbol == nil {return ""; } 67 | if symbol.getType() == CommonToken.EOF { 68 | return "" 69 | } 70 | return symbol.getText()! 71 | } 72 | 73 | public var debugDescription: String { 74 | return description 75 | } 76 | 77 | public func toStringTree() -> String { 78 | return description 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/Tree.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// The basic notion of a tree has a parent, a payload, and a list of children. 8 | /// It is the most abstract interface for all the trees used by ANTLR. 9 | /// 10 | 11 | public protocol Tree: AnyObject { 12 | /// The parent of this node. If the return value is null, then this 13 | /// node is the root of the tree. 14 | /// 15 | func getParent() -> Tree? 16 | 17 | /// 18 | /// This method returns whatever object represents the data at this note. For 19 | /// example, for parse trees, the payload can be a _org.antlr.v4.runtime.Token_ representing 20 | /// a leaf node or a _org.antlr.v4.runtime.RuleContext_ object representing a rule 21 | /// invocation. For abstract syntax trees (ASTs), this is a _org.antlr.v4.runtime.Token_ 22 | /// object. 23 | /// 24 | func getPayload() -> AnyObject 25 | 26 | /// If there are children, get the `i`th value indexed from 0. 27 | func getChild(_ i: Int) -> Tree? 28 | 29 | /// How many children are there? If there is none, then this 30 | /// node represents a leaf node. 31 | /// 32 | func getChildCount() -> Int 33 | 34 | /// Print out a whole tree, not just a node, in LISP format 35 | /// `(root child1 .. childN)`. Print just a node if this is a leaf. 36 | /// 37 | func toStringTree() -> String 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/pattern/Chunk.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | 8 | /// 9 | /// A chunk is either a token tag, a rule tag, or a span of literal text within a 10 | /// tree pattern. 11 | /// 12 | /// The method _org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher#split(String)_ returns a list of 13 | /// chunks in preparation for creating a token stream by 14 | /// _org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher#tokenize(String)_. From there, we get a parse 15 | /// tree from with _org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher#compile(String, int)_. These 16 | /// chunks are converted to _org.antlr.v4.runtime.tree.pattern.RuleTagToken_, _org.antlr.v4.runtime.tree.pattern.TokenTagToken_, or the 17 | /// regular tokens of the text surrounding the tags. 18 | /// 19 | 20 | public class Chunk: Equatable { 21 | public static func ==(lhs: Chunk, rhs: Chunk) -> Bool { 22 | return lhs.isEqual(rhs) 23 | } 24 | 25 | public func isEqual(_ other: Chunk) -> Bool { 26 | return false 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/pattern/TagChunk.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// 8 | /// Represents a placeholder tag in a tree pattern. A tag can have any of the 9 | /// following forms. 10 | /// 11 | /// * `expr`: An unlabeled placeholder for a parser rule `expr`. 12 | /// * `ID`: An unlabeled placeholder for a token of type `ID`. 13 | /// * `e:expr`: A labeled placeholder for a parser rule `expr`. 14 | /// * `id:ID`: A labeled placeholder for a token of type `ID`. 15 | /// 16 | /// This class does not perform any validation on the tag or label names aside 17 | /// from ensuring that the tag is a non-null, non-empty string. 18 | /// 19 | public class TagChunk: Chunk, CustomStringConvertible { 20 | /// 21 | /// This is the backing field for _#getTag_. 22 | /// 23 | private let tag: String 24 | /// 25 | /// This is the backing field for _#getLabel_. 26 | /// 27 | private let label: String? 28 | 29 | /// 30 | /// Construct a new instance of _org.antlr.v4.runtime.tree.pattern.TagChunk_ using the specified tag and 31 | /// no label. 32 | /// 33 | /// - Parameter tag: The tag, which should be the name of a parser rule or token 34 | /// type. 35 | /// 36 | /// - Throws: ANTLRError.illegalArgument if `tag` is `null` or 37 | /// empty. 38 | /// 39 | public convenience init(_ tag: String) throws { 40 | try self.init(nil, tag) 41 | } 42 | 43 | /// 44 | /// Construct a new instance of _org.antlr.v4.runtime.tree.pattern.TagChunk_ using the specified label 45 | /// and tag. 46 | /// 47 | /// - Parameter label: The label for the tag. If this is `null`, the 48 | /// _org.antlr.v4.runtime.tree.pattern.TagChunk_ represents an unlabeled tag. 49 | /// - Parameter tag: The tag, which should be the name of a parser rule or token 50 | /// type. 51 | /// 52 | /// - Throws: ANTLRError.illegalArgument if `tag` is `null` or 53 | /// empty. 54 | /// 55 | public init(_ label: String?, _ tag: String) throws { 56 | 57 | self.label = label 58 | self.tag = tag 59 | super.init() 60 | if tag.isEmpty { 61 | throw ANTLRError.illegalArgument(msg: "tag cannot be null or empty") 62 | } 63 | } 64 | 65 | /// 66 | /// Get the tag for this chunk. 67 | /// 68 | /// - Returns: The tag for the chunk. 69 | /// 70 | public final func getTag() -> String { 71 | return tag 72 | } 73 | 74 | /// 75 | /// Get the label, if any, assigned to this chunk. 76 | /// 77 | /// - Returns: The label assigned to this chunk, or `null` if no label is 78 | /// assigned to the chunk. 79 | /// 80 | public final func getLabel() -> String? { 81 | return label 82 | } 83 | 84 | /// 85 | /// This method returns a text representation of the tag chunk. Labeled tags 86 | /// are returned in the form `label:tag`, and unlabeled tags are 87 | /// returned as just the tag name. 88 | /// 89 | public var description: String { 90 | if let label = label { 91 | return "\(label):\(tag)" 92 | } 93 | else { 94 | return tag 95 | } 96 | } 97 | 98 | 99 | override public func isEqual(_ other: Chunk) -> Bool { 100 | guard let other = other as? TagChunk else { 101 | return false 102 | } 103 | return tag == other.tag && label == other.label 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/pattern/TextChunk.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | /// 8 | /// Represents a span of raw text (concrete syntax) between tags in a tree 9 | /// pattern string. 10 | /// 11 | 12 | public class TextChunk: Chunk, CustomStringConvertible { 13 | /// 14 | /// This is the backing field for _#getText_. 15 | /// 16 | 17 | private let text: String 18 | 19 | /// 20 | /// Constructs a new instance of _org.antlr.v4.runtime.tree.pattern.TextChunk_ with the specified text. 21 | /// 22 | /// - Parameter text: The text of this chunk. 23 | /// - Throws: ANTLRError.illegalArgument if `text` is `null`. 24 | /// 25 | public init(_ text: String) { 26 | self.text = text 27 | } 28 | 29 | /// 30 | /// Gets the raw text of this chunk. 31 | /// 32 | /// - Returns: The text of the chunk. 33 | /// 34 | 35 | public final func getText() -> String { 36 | return text 37 | } 38 | 39 | /// 40 | /// The implementation for _org.antlr.v4.runtime.tree.pattern.TextChunk_ returns the result of 41 | /// _#getText()_ in single quotes. 42 | /// 43 | public var description: String { 44 | return "'\(text)'" 45 | } 46 | 47 | 48 | override public func isEqual(_ other: Chunk) -> Bool { 49 | guard let other = other as? TextChunk else { 50 | return false 51 | } 52 | return text == other.text 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Antlr4/tree/pattern/TokenTagToken.swift: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | 7 | 8 | /// 9 | /// A _org.antlr.v4.runtime.Token_ object representing a token of a particular type; e.g., 10 | /// ``. These tokens are created for _org.antlr.v4.runtime.tree.pattern.TagChunk_ chunks where the 11 | /// tag corresponds to a lexer rule or token type. 12 | /// 13 | 14 | public class TokenTagToken: CommonToken { 15 | /// 16 | /// This is the backing field for _#getTokenName_. 17 | /// 18 | 19 | private let tokenName: String 20 | /// 21 | /// This is the backing field for _#getLabel_. 22 | /// 23 | 24 | private let label: String? 25 | 26 | /// 27 | /// Constructs a new instance of _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ for an unlabeled tag 28 | /// with the specified token name and type. 29 | /// 30 | /// - Parameter tokenName: The token name. 31 | /// - Parameter type: The token type. 32 | /// 33 | public convenience init(_ tokenName: String, _ type: Int) { 34 | self.init(tokenName, type, nil) 35 | } 36 | 37 | /// 38 | /// Constructs a new instance of _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ with the specified 39 | /// token name, type, and label. 40 | /// 41 | /// - Parameter tokenName: The token name. 42 | /// - Parameter type: The token type. 43 | /// - Parameter label: The label associated with the token tag, or `null` if 44 | /// the token tag is unlabeled. 45 | /// 46 | public init(_ tokenName: String, _ type: Int, _ label: String?) { 47 | 48 | self.tokenName = tokenName 49 | self.label = label 50 | super.init(type) 51 | } 52 | 53 | /// 54 | /// Gets the token name. 55 | /// - Returns: The token name. 56 | /// 57 | 58 | public final func getTokenName() -> String { 59 | return tokenName 60 | } 61 | 62 | /// 63 | /// Gets the label associated with the rule tag. 64 | /// 65 | /// - Returns: The name of the label associated with the rule tag, or 66 | /// `null` if this is an unlabeled rule tag. 67 | /// 68 | 69 | public final func getLabel() -> String? { 70 | return label 71 | } 72 | 73 | /// 74 | /// 75 | /// 76 | /// The implementation for _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ returns the token tag 77 | /// formatted with `<` and `>` delimiters. 78 | /// 79 | override 80 | public func getText() -> String { 81 | if label != nil { 82 | return "<" + label! + ":" + tokenName + ">" 83 | } 84 | 85 | return "<" + tokenName + ">" 86 | } 87 | 88 | /// 89 | /// 90 | /// 91 | /// The implementation for _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ returns a string of the form 92 | /// `tokenName:type`. 93 | /// 94 | 95 | override 96 | public var description: String { 97 | return tokenName + ":" + String(type) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Info-IOS.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Vendor/antlr4/runtime/Swift/Sources/Info-OSX.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | --------------------------------------------------------------------------------