diff --git a/Package.resolved b/Package.resolved index a04aae51..8843e16a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,15 +1,6 @@ { - "originHash" : "029cdd924f33e24dda5691965bc7449ab1e416e5eb3ae208eb4e9a6bd2cd204e", + "originHash" : "6466a3de6b03a7f9499cc6ad528be037cd42ee688a16c00bd96a3fa208099b1e", "pins" : [ - { - "identity" : "antlr4", - "kind" : "remoteSourceControl", - "location" : "https://github.com/antlr/antlr4", - "state" : { - "revision" : "7ed420ff2c78d62883875c442d75f32e73bc86c8", - "version" : "4.13.1" - } - }, { "identity" : "hotkey", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 7fb48c47..7b7791be 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,6 @@ let package = Package( .library(name: "AppBundle", targets: ["AppBundle"]), ], dependencies: [ - .package(path: "./ShellParserGenerated"), .package(url: "https://github.com/InerziaSoft/ISSoundAdditions.git", exact: "2.0.1"), .package(url: "https://github.com/dduan/TOMLDecoder", exact: "0.4.4"), .package(url: "https://github.com/apple/swift-collections.git", exact: "1.3.0"), @@ -50,7 +49,6 @@ let package = Package( .product(name: "Collections", package: "swift-collections"), .product(name: "HotKey", package: "HotKey"), .product(name: "ISSoundAdditions", package: "ISSoundAdditions"), - .product(name: "ShellParserGenerated", package: "ShellParserGenerated"), .product(name: "TOMLDecoder", package: "TOMLDecoder"), .target(name: "Common"), .target(name: "PrivateApi"), diff --git a/ShellParserGenerated/.gitignore b/ShellParserGenerated/.gitignore deleted file mode 100644 index 0023a534..00000000 --- a/ShellParserGenerated/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/ShellParserGenerated/Package.swift b/ShellParserGenerated/Package.swift deleted file mode 100644 index 8cc8adb9..00000000 --- a/ShellParserGenerated/Package.swift +++ /dev/null @@ -1,28 +0,0 @@ -// swift-tools-version: 5.9 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "ShellParserGenerated", - products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. - .library( - name: "ShellParserGenerated", - targets: ["ShellParserGenerated"] - ), - ], - dependencies: [ - .package(url: "https://github.com/antlr/antlr4", exact: "4.13.1"), - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .target( - name: "ShellParserGenerated", - dependencies: [ - .product(name: "Antlr4Static", package: "antlr4"), - ] - ), - ] -) diff --git a/ShellParserGenerated/Sources/ShellParserGenerated/ShellLexer.swift b/ShellParserGenerated/Sources/ShellParserGenerated/ShellLexer.swift deleted file mode 100644 index 35ef84c4..00000000 --- a/ShellParserGenerated/Sources/ShellParserGenerated/ShellLexer.swift +++ /dev/null @@ -1,236 +0,0 @@ -// Generated from ./grammar/ShellLexer.g4 by ANTLR 4.13.1 -import Antlr4 - -open class ShellLexer: Lexer { - - internal static var _decisionToDFA: [DFA] = { - var decisionToDFA = [DFA]() - let length = ShellLexer._ATN.getNumberOfDecisions() - for i in 0.. Vocabulary { - return ShellLexer.VOCABULARY - } - - public - required init(_ input: CharStream) { - RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION) - super.init(input) - _interp = LexerATNSimulator(self, ShellLexer._ATN, ShellLexer._decisionToDFA, ShellLexer._sharedContextCache) - } - - override open - func getGrammarFileName() -> String { return "ShellLexer.g4" } - - override open - func getRuleNames() -> [String] { return ShellLexer.ruleNames } - - override open - func getSerializedATN() -> [Int] { return ShellLexer._serializedATN } - - override open - func getChannelNames() -> [String] { return ShellLexer.channelNames } - - override open - func getModeNames() -> [String] { return ShellLexer.modeNames } - - override open - func getATN() -> ATN { return ShellLexer._ATN } - - override open - func action(_ _localctx: RuleContext?, _ ruleIndex: Int, _ actionIndex: Int) throws { - switch (ruleIndex) { - case 5: - try RPAR_action((_localctx as RuleContext?), actionIndex) - - case 33: - try RDQUOTE_action((_localctx as RuleContext?), actionIndex) - - default: break - } - } - private func RPAR_action(_ _localctx: RuleContext?, _ actionIndex: Int) throws { - switch (actionIndex) { - case 0: - - _ = try? popMode() - - - default: break - } - } - private func RDQUOTE_action(_ _localctx: RuleContext?, _ actionIndex: Int) throws { - switch (actionIndex) { - case 1: - - _ = try? popMode() - - - default: break - } - } - - static let _serializedATN:[Int] = [ - 4,0,34,316,6,-1,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2, - 6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13, - 2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20, - 2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27, - 2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,2,33,7,33,1,0,1,0,1, - 0,1,0,1,0,1,0,3,0,77,8,0,1,1,1,1,5,1,81,8,1,10,1,12,1,84,9,1,1,1,1,1,1, - 2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,6,1,6, - 1,6,1,6,1,6,1,6,5,6,110,8,6,10,6,12,6,113,9,6,1,7,1,7,1,7,1,7,5,7,119, - 8,7,10,7,12,7,122,9,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,5,8,132,8,8,10,8, - 12,8,135,9,8,1,9,1,9,1,9,1,9,1,9,1,9,5,9,143,8,9,10,9,12,9,146,9,9,1,10, - 1,10,1,10,1,10,5,10,152,8,10,10,10,12,10,155,9,10,1,11,1,11,1,11,1,11, - 1,11,1,11,5,11,163,8,11,10,11,12,11,166,9,11,1,12,1,12,1,12,1,12,1,12, - 1,12,5,12,174,8,12,10,12,12,12,177,9,12,1,13,1,13,1,13,1,13,1,13,5,13, - 184,8,13,10,13,12,13,187,9,13,1,14,1,14,1,14,1,14,1,14,1,14,1,14,5,14, - 196,8,14,10,14,12,14,199,9,14,1,15,1,15,1,15,1,15,1,15,1,15,1,15,5,15, - 208,8,15,10,15,12,15,211,9,15,1,16,1,16,1,16,1,16,5,16,217,8,16,10,16, - 12,16,220,9,16,1,17,1,17,1,17,1,17,1,17,5,17,227,8,17,10,17,12,17,230, - 9,17,1,18,1,18,1,18,1,18,1,18,1,18,1,18,5,18,239,8,18,10,18,12,18,242, - 9,18,1,19,1,19,1,19,1,20,1,20,1,21,1,21,1,21,1,22,1,22,1,23,3,23,255,8, - 23,1,23,3,23,258,8,23,1,23,1,23,1,24,4,24,263,8,24,11,24,12,24,264,1,25, - 4,25,268,8,25,11,25,12,25,269,1,26,1,26,3,26,274,8,26,1,26,3,26,277,8, - 26,1,26,1,26,1,26,1,26,1,27,1,27,5,27,285,8,27,10,27,12,27,288,9,27,1, - 27,1,27,1,28,4,28,293,8,28,11,28,12,28,294,1,28,1,28,1,29,1,29,1,30,4, - 30,302,8,30,11,30,12,30,303,1,31,1,31,1,31,1,31,1,31,1,32,1,32,1,32,1, - 33,1,33,1,33,1,82,0,34,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8,18,9,20,10, - 22,11,24,12,26,13,28,14,30,15,32,16,34,17,36,18,38,19,40,20,42,21,44,22, - 46,23,48,24,50,25,52,26,54,27,56,28,58,29,60,30,62,31,64,32,66,33,68,34, - 2,0,1,5,4,0,45,47,65,90,95,95,97,122,8,0,33,33,37,37,43,57,61,61,65,90, - 94,95,97,123,125,125,1,0,10,10,2,0,9,9,32,32,3,0,34,34,36,36,92,92,338, - 0,2,1,0,0,0,0,4,1,0,0,0,0,6,1,0,0,0,0,8,1,0,0,0,0,10,1,0,0,0,0,12,1,0, - 0,0,0,14,1,0,0,0,0,16,1,0,0,0,0,18,1,0,0,0,0,20,1,0,0,0,0,22,1,0,0,0,0, - 24,1,0,0,0,0,26,1,0,0,0,0,28,1,0,0,0,0,30,1,0,0,0,0,32,1,0,0,0,0,34,1, - 0,0,0,0,36,1,0,0,0,0,38,1,0,0,0,0,40,1,0,0,0,0,42,1,0,0,0,0,44,1,0,0,0, - 0,46,1,0,0,0,0,48,1,0,0,0,0,50,1,0,0,0,0,52,1,0,0,0,0,54,1,0,0,0,0,56, - 1,0,0,0,0,58,1,0,0,0,0,60,1,0,0,0,1,62,1,0,0,0,1,64,1,0,0,0,1,66,1,0,0, - 0,1,68,1,0,0,0,2,76,1,0,0,0,4,78,1,0,0,0,6,87,1,0,0,0,8,91,1,0,0,0,10, - 95,1,0,0,0,12,100,1,0,0,0,14,103,1,0,0,0,16,114,1,0,0,0,18,123,1,0,0,0, - 20,136,1,0,0,0,22,147,1,0,0,0,24,156,1,0,0,0,26,167,1,0,0,0,28,178,1,0, - 0,0,30,188,1,0,0,0,32,200,1,0,0,0,34,212,1,0,0,0,36,221,1,0,0,0,38,231, - 1,0,0,0,40,243,1,0,0,0,42,246,1,0,0,0,44,248,1,0,0,0,46,251,1,0,0,0,48, - 254,1,0,0,0,50,262,1,0,0,0,52,267,1,0,0,0,54,271,1,0,0,0,56,282,1,0,0, - 0,58,292,1,0,0,0,60,298,1,0,0,0,62,301,1,0,0,0,64,305,1,0,0,0,66,310,1, - 0,0,0,68,313,1,0,0,0,70,71,5,34,0,0,71,72,5,34,0,0,72,77,5,34,0,0,73,74, - 5,39,0,0,74,75,5,39,0,0,75,77,5,39,0,0,76,70,1,0,0,0,76,73,1,0,0,0,77, - 3,1,0,0,0,78,82,5,39,0,0,79,81,9,0,0,0,80,79,1,0,0,0,81,84,1,0,0,0,82, - 83,1,0,0,0,82,80,1,0,0,0,83,85,1,0,0,0,84,82,1,0,0,0,85,86,5,39,0,0,86, - 5,1,0,0,0,87,88,5,34,0,0,88,89,1,0,0,0,89,90,6,2,0,0,90,7,1,0,0,0,91,92, - 5,40,0,0,92,93,1,0,0,0,93,94,6,3,1,0,94,9,1,0,0,0,95,96,5,36,0,0,96,97, - 5,40,0,0,97,98,1,0,0,0,98,99,6,4,1,0,99,11,1,0,0,0,100,101,5,41,0,0,101, - 102,6,5,2,0,102,13,1,0,0,0,103,104,5,101,0,0,104,105,5,108,0,0,105,106, - 5,105,0,0,106,107,5,102,0,0,107,111,1,0,0,0,108,110,3,48,23,0,109,108, - 1,0,0,0,110,113,1,0,0,0,111,109,1,0,0,0,111,112,1,0,0,0,112,15,1,0,0,0, - 113,111,1,0,0,0,114,115,5,105,0,0,115,116,5,102,0,0,116,120,1,0,0,0,117, - 119,3,48,23,0,118,117,1,0,0,0,119,122,1,0,0,0,120,118,1,0,0,0,120,121, - 1,0,0,0,121,17,1,0,0,0,122,120,1,0,0,0,123,124,5,115,0,0,124,125,5,119, - 0,0,125,126,5,105,0,0,126,127,5,116,0,0,127,128,5,99,0,0,128,129,5,104, - 0,0,129,133,1,0,0,0,130,132,3,48,23,0,131,130,1,0,0,0,132,135,1,0,0,0, - 133,131,1,0,0,0,133,134,1,0,0,0,134,19,1,0,0,0,135,133,1,0,0,0,136,137, - 5,99,0,0,137,138,5,97,0,0,138,139,5,115,0,0,139,140,5,101,0,0,140,144, - 1,0,0,0,141,143,3,48,23,0,142,141,1,0,0,0,143,146,1,0,0,0,144,142,1,0, - 0,0,144,145,1,0,0,0,145,21,1,0,0,0,146,144,1,0,0,0,147,148,5,100,0,0,148, - 149,5,111,0,0,149,153,1,0,0,0,150,152,3,48,23,0,151,150,1,0,0,0,152,155, - 1,0,0,0,153,151,1,0,0,0,153,154,1,0,0,0,154,23,1,0,0,0,155,153,1,0,0,0, - 156,157,5,116,0,0,157,158,5,104,0,0,158,159,5,101,0,0,159,160,5,110,0, - 0,160,164,1,0,0,0,161,163,3,48,23,0,162,161,1,0,0,0,163,166,1,0,0,0,164, - 162,1,0,0,0,164,165,1,0,0,0,165,25,1,0,0,0,166,164,1,0,0,0,167,168,5,101, - 0,0,168,169,5,108,0,0,169,170,5,115,0,0,170,171,5,101,0,0,171,175,1,0, - 0,0,172,174,3,48,23,0,173,172,1,0,0,0,174,177,1,0,0,0,175,173,1,0,0,0, - 175,176,1,0,0,0,176,27,1,0,0,0,177,175,1,0,0,0,178,179,5,102,0,0,179,180, - 5,111,0,0,180,181,5,114,0,0,181,185,1,0,0,0,182,184,3,48,23,0,183,182, - 1,0,0,0,184,187,1,0,0,0,185,183,1,0,0,0,185,186,1,0,0,0,186,29,1,0,0,0, - 187,185,1,0,0,0,188,189,5,119,0,0,189,190,5,104,0,0,190,191,5,105,0,0, - 191,192,5,108,0,0,192,193,5,101,0,0,193,197,1,0,0,0,194,196,3,48,23,0, - 195,194,1,0,0,0,196,199,1,0,0,0,197,195,1,0,0,0,197,198,1,0,0,0,198,31, - 1,0,0,0,199,197,1,0,0,0,200,201,5,99,0,0,201,202,5,97,0,0,202,203,5,116, - 0,0,203,204,5,99,0,0,204,205,5,104,0,0,205,209,1,0,0,0,206,208,3,48,23, - 0,207,206,1,0,0,0,208,211,1,0,0,0,209,207,1,0,0,0,209,210,1,0,0,0,210, - 33,1,0,0,0,211,209,1,0,0,0,212,213,5,105,0,0,213,214,5,110,0,0,214,218, - 1,0,0,0,215,217,3,48,23,0,216,215,1,0,0,0,217,220,1,0,0,0,218,216,1,0, - 0,0,218,219,1,0,0,0,219,35,1,0,0,0,220,218,1,0,0,0,221,222,5,101,0,0,222, - 223,5,110,0,0,223,224,5,100,0,0,224,228,1,0,0,0,225,227,3,48,23,0,226, - 225,1,0,0,0,227,230,1,0,0,0,228,226,1,0,0,0,228,229,1,0,0,0,229,37,1,0, - 0,0,230,228,1,0,0,0,231,232,5,100,0,0,232,233,5,101,0,0,233,234,5,102, - 0,0,234,235,5,101,0,0,235,236,5,114,0,0,236,240,1,0,0,0,237,239,3,48,23, - 0,238,237,1,0,0,0,239,242,1,0,0,0,240,238,1,0,0,0,240,241,1,0,0,0,241, - 39,1,0,0,0,242,240,1,0,0,0,243,244,5,38,0,0,244,245,5,38,0,0,245,41,1, - 0,0,0,246,247,5,124,0,0,247,43,1,0,0,0,248,249,5,124,0,0,249,250,5,124, - 0,0,250,45,1,0,0,0,251,252,5,59,0,0,252,47,1,0,0,0,253,255,3,58,28,0,254, - 253,1,0,0,0,254,255,1,0,0,0,255,257,1,0,0,0,256,258,5,13,0,0,257,256,1, - 0,0,0,257,258,1,0,0,0,258,259,1,0,0,0,259,260,5,10,0,0,260,49,1,0,0,0, - 261,263,7,0,0,0,262,261,1,0,0,0,263,264,1,0,0,0,264,262,1,0,0,0,264,265, - 1,0,0,0,265,51,1,0,0,0,266,268,7,1,0,0,267,266,1,0,0,0,268,269,1,0,0,0, - 269,267,1,0,0,0,269,270,1,0,0,0,270,53,1,0,0,0,271,273,5,92,0,0,272,274, - 3,58,28,0,273,272,1,0,0,0,273,274,1,0,0,0,274,276,1,0,0,0,275,277,3,56, - 27,0,276,275,1,0,0,0,276,277,1,0,0,0,277,278,1,0,0,0,278,279,5,10,0,0, - 279,280,1,0,0,0,280,281,6,26,3,0,281,55,1,0,0,0,282,286,5,35,0,0,283,285, - 8,2,0,0,284,283,1,0,0,0,285,288,1,0,0,0,286,284,1,0,0,0,286,287,1,0,0, - 0,287,289,1,0,0,0,288,286,1,0,0,0,289,290,6,27,3,0,290,57,1,0,0,0,291, - 293,7,3,0,0,292,291,1,0,0,0,293,294,1,0,0,0,294,292,1,0,0,0,294,295,1, - 0,0,0,295,296,1,0,0,0,296,297,6,28,3,0,297,59,1,0,0,0,298,299,9,0,0,0, - 299,61,1,0,0,0,300,302,8,4,0,0,301,300,1,0,0,0,302,303,1,0,0,0,303,301, - 1,0,0,0,303,304,1,0,0,0,304,63,1,0,0,0,305,306,5,36,0,0,306,307,5,40,0, - 0,307,308,1,0,0,0,308,309,6,31,1,0,309,65,1,0,0,0,310,311,5,92,0,0,311, - 312,9,0,0,0,312,67,1,0,0,0,313,314,5,34,0,0,314,315,6,33,4,0,315,69,1, - 0,0,0,28,0,1,76,82,111,120,133,144,153,164,175,185,197,209,218,228,240, - 254,257,262,264,267,269,273,276,286,294,303,5,5,1,0,5,0,0,1,5,0,6,0,0, - 1,33,1 - ] - - public - static let _ATN: ATN = try! ATNDeserializer().deserialize(_serializedATN) -} \ No newline at end of file diff --git a/ShellParserGenerated/Sources/ShellParserGenerated/ShellParser.swift b/ShellParserGenerated/Sources/ShellParserGenerated/ShellParser.swift deleted file mode 100644 index bc8a4958..00000000 --- a/ShellParserGenerated/Sources/ShellParserGenerated/ShellParser.swift +++ /dev/null @@ -1,1234 +0,0 @@ -// Generated from ./grammar/ShellParser.g4 by ANTLR 4.13.1 -import Antlr4 - -open class ShellParser: Parser { - - internal static var _decisionToDFA: [DFA] = { - var decisionToDFA = [DFA]() - let length = ShellParser._ATN.getNumberOfDecisions() - for i in 0.. String { return "ShellParser.g4" } - - override open - func getRuleNames() -> [String] { return ShellParser.ruleNames } - - override open - func getSerializedATN() -> [Int] { return ShellParser._serializedATN } - - override open - func getATN() -> ATN { return ShellParser._ATN } - - - override open - func getVocabulary() -> Vocabulary { - return ShellParser.VOCABULARY - } - - override public - init(_ input:TokenStream) throws { - RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION) - try super.init(input) - _interp = ParserATNSimulator(self,ShellParser._ATN,ShellParser._decisionToDFA, ShellParser._sharedContextCache) - } - - - public class RootContext: ParserRuleContext { - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func EOF() -> TerminalNode? { - return getToken(ShellParser.Tokens.EOF.rawValue, 0) - } - open - func NL() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.NL.rawValue) - } - open - func NL(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.NL.rawValue, i) - } - override open - func getRuleIndex() -> Int { - return ShellParser.RULE_root - } - } - @discardableResult - open func root() throws -> RootContext { - var _localctx: RootContext - _localctx = RootContext(_ctx, getState()) - try enterRule(_localctx, 0, ShellParser.RULE_root) - var _la: Int = 0 - defer { - try! exitRule() - } - do { - try enterOuterAlt(_localctx, 1) - setState(13) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (_la == ShellParser.Tokens.NL.rawValue) { - setState(10) - try match(ShellParser.Tokens.NL.rawValue) - - - setState(15) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(20) - try _errHandler.sync(self) - switch (ShellParser.Tokens(rawValue: try _input.LA(1))!) { - case .LPAR:fallthrough - case .IF:fallthrough - case .WORD: - setState(16) - try cmds() - setState(17) - try match(ShellParser.Tokens.EOF.rawValue) - - break - - case .EOF: - setState(19) - try match(ShellParser.Tokens.EOF.rawValue) - - break - default: - throw ANTLRException.recognition(e: NoViableAltException(self)) - } - - } - catch ANTLRException.recognition(let re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class CmdsContext: ParserRuleContext { - override open - func getRuleIndex() -> Int { - return ShellParser.RULE_cmds - } - } - public class IfElseContext: CmdsContext { - open - func IF() -> TerminalNode? { - return getToken(ShellParser.Tokens.IF.rawValue, 0) - } - open - func cmd() -> [CmdContext] { - return getRuleContexts(CmdContext.self) - } - open - func cmd(_ i: Int) -> CmdContext? { - return getRuleContext(CmdContext.self, i) - } - open - func THEN() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.THEN.rawValue) - } - open - func THEN(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.THEN.rawValue, i) - } - open - func END() -> TerminalNode? { - return getToken(ShellParser.Tokens.END.rawValue, 0) - } - open - func cmds() -> [CmdsContext] { - return getRuleContexts(CmdsContext.self) - } - open - func cmds(_ i: Int) -> CmdsContext? { - return getRuleContext(CmdsContext.self, i) - } - open - func ELIF() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.ELIF.rawValue) - } - open - func ELIF(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.ELIF.rawValue, i) - } - open - func ELSE() -> TerminalNode? { - return getToken(ShellParser.Tokens.ELSE.rawValue, 0) - } - - public - init(_ ctx: CmdsContext) { - super.init() - copyFrom(ctx) - } - } - public class SeqContext: CmdsContext { - open - func cmd() -> CmdContext? { - return getRuleContext(CmdContext.self, 0) - } - open - func cmds() -> [CmdsContext] { - return getRuleContexts(CmdsContext.self) - } - open - func cmds(_ i: Int) -> CmdsContext? { - return getRuleContext(CmdsContext.self, i) - } - open - func SEMICOLON() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.SEMICOLON.rawValue) - } - open - func SEMICOLON(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.SEMICOLON.rawValue, i) - } - open - func NL() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.NL.rawValue) - } - open - func NL(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.NL.rawValue, i) - } - - public - init(_ ctx: CmdsContext) { - super.init() - copyFrom(ctx) - } - } - @discardableResult - open func cmds() throws -> CmdsContext { - var _localctx: CmdsContext - _localctx = CmdsContext(_ctx, getState()) - try enterRule(_localctx, 2, ShellParser.RULE_cmds) - var _la: Int = 0 - defer { - try! exitRule() - } - do { - var _alt:Int - setState(60) - try _errHandler.sync(self) - switch(try getInterpreter().adaptivePredict(_input,9, _ctx)) { - case 1: - _localctx = IfElseContext(_localctx); - try enterOuterAlt(_localctx, 1) - setState(22) - try match(ShellParser.Tokens.IF.rawValue) - setState(23) - try cmd(0) - setState(24) - try match(ShellParser.Tokens.THEN.rawValue) - setState(26) - try _errHandler.sync(self) - _la = try _input.LA(1) - if (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 33554704) != 0)) { - setState(25) - try cmds() - - } - - setState(36) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (_la == ShellParser.Tokens.ELIF.rawValue) { - setState(28) - try match(ShellParser.Tokens.ELIF.rawValue) - setState(29) - try cmd(0) - setState(30) - try match(ShellParser.Tokens.THEN.rawValue) - setState(32) - try _errHandler.sync(self) - _la = try _input.LA(1) - if (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 33554704) != 0)) { - setState(31) - try cmds() - - } - - - - setState(38) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(43) - try _errHandler.sync(self) - _la = try _input.LA(1) - if (_la == ShellParser.Tokens.ELSE.rawValue) { - setState(39) - try match(ShellParser.Tokens.ELSE.rawValue) - setState(41) - try _errHandler.sync(self) - _la = try _input.LA(1) - if (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 33554704) != 0)) { - setState(40) - try cmds() - - } - - - } - - setState(45) - try match(ShellParser.Tokens.END.rawValue) - - break - case 2: - _localctx = SeqContext(_localctx); - try enterOuterAlt(_localctx, 2) - setState(47) - try cmd(0) - setState(49); - try _errHandler.sync(self) - _alt = 1; - repeat { - switch (_alt) { - case 1: - setState(48) - _la = try _input.LA(1) - if (!(_la == ShellParser.Tokens.SEMICOLON.rawValue || _la == ShellParser.Tokens.NL.rawValue)) { - try _errHandler.recoverInline(self) - } - else { - _errHandler.reportMatch(self) - try consume() - } - - - break - default: - throw ANTLRException.recognition(e: NoViableAltException(self)) - } - setState(51); - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,7,_ctx) - } while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) - setState(56) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,8,_ctx) - while (_alt != 1 && _alt != ATN.INVALID_ALT_NUMBER) { - if ( _alt==1+1 ) { - setState(53) - try cmds() - - - } - setState(58) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,8,_ctx) - } - - break - case 3: - _localctx = SeqContext(_localctx); - try enterOuterAlt(_localctx, 3) - setState(59) - try cmd(0) - - break - default: break - } - } - catch ANTLRException.recognition(let re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - - public class CmdContext: ParserRuleContext { - override open - func getRuleIndex() -> Int { - return ShellParser.RULE_cmd - } - } - public class ArgsContext: CmdContext { - open - func WORD() -> TerminalNode? { - return getToken(ShellParser.Tokens.WORD.rawValue, 0) - } - open - func arg() -> [ArgContext] { - return getRuleContexts(ArgContext.self) - } - open - func arg(_ i: Int) -> ArgContext? { - return getRuleContext(ArgContext.self, i) - } - - public - init(_ ctx: CmdContext) { - super.init() - copyFrom(ctx) - } - } - public class CmdErrorContext: CmdContext { - open - func LPAR() -> TerminalNode? { - return getToken(ShellParser.Tokens.LPAR.rawValue, 0) - } - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func RPAR() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.RPAR.rawValue) - } - open - func RPAR(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.RPAR.rawValue, i) - } - - public - init(_ ctx: CmdContext) { - super.init() - copyFrom(ctx) - } - } - public class OrContext: CmdContext { - open - func cmd() -> [CmdContext] { - return getRuleContexts(CmdContext.self) - } - open - func cmd(_ i: Int) -> CmdContext? { - return getRuleContext(CmdContext.self, i) - } - open - func OR() -> TerminalNode? { - return getToken(ShellParser.Tokens.OR.rawValue, 0) - } - open - func NL() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.NL.rawValue) - } - open - func NL(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.NL.rawValue, i) - } - - public - init(_ ctx: CmdContext) { - super.init() - copyFrom(ctx) - } - } - public class ParensContext: CmdContext { - open - func LPAR() -> TerminalNode? { - return getToken(ShellParser.Tokens.LPAR.rawValue, 0) - } - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func RPAR() -> TerminalNode? { - return getToken(ShellParser.Tokens.RPAR.rawValue, 0) - } - - public - init(_ ctx: CmdContext) { - super.init() - copyFrom(ctx) - } - } - public class AndContext: CmdContext { - open - func cmd() -> [CmdContext] { - return getRuleContexts(CmdContext.self) - } - open - func cmd(_ i: Int) -> CmdContext? { - return getRuleContext(CmdContext.self, i) - } - open - func AND() -> TerminalNode? { - return getToken(ShellParser.Tokens.AND.rawValue, 0) - } - open - func NL() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.NL.rawValue) - } - open - func NL(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.NL.rawValue, i) - } - - public - init(_ ctx: CmdContext) { - super.init() - copyFrom(ctx) - } - } - public class PipeContext: CmdContext { - open - func cmd() -> [CmdContext] { - return getRuleContexts(CmdContext.self) - } - open - func cmd(_ i: Int) -> CmdContext? { - return getRuleContext(CmdContext.self, i) - } - open - func PIPE() -> TerminalNode? { - return getToken(ShellParser.Tokens.PIPE.rawValue, 0) - } - open - func NL() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.NL.rawValue) - } - open - func NL(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.NL.rawValue, i) - } - - public - init(_ ctx: CmdContext) { - super.init() - copyFrom(ctx) - } - } - - public final func cmd( ) throws -> CmdContext { - return try cmd(0) - } - @discardableResult - private func cmd(_ _p: Int) throws -> CmdContext { - let _parentctx: ParserRuleContext? = _ctx - let _parentState: Int = getState() - var _localctx: CmdContext - _localctx = CmdContext(_ctx, _parentState) - let _startState: Int = 4 - try enterRecursionRule(_localctx, 4, ShellParser.RULE_cmd, _p) - var _la: Int = 0 - defer { - try! unrollRecursionContexts(_parentctx) - } - do { - var _alt: Int - try enterOuterAlt(_localctx, 1) - setState(84) - try _errHandler.sync(self) - switch(try getInterpreter().adaptivePredict(_input,11, _ctx)) { - case 1: - _localctx = ArgsContext(_localctx) - _ctx = _localctx - - setState(63) - try match(ShellParser.Tokens.WORD.rawValue) - setState(67) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,10,_ctx) - while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { - if ( _alt==1 ) { - setState(64) - try arg() - - - } - setState(69) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,10,_ctx) - } - - break - case 2: - _localctx = ParensContext(_localctx) - _ctx = _localctx - setState(70) - try match(ShellParser.Tokens.LPAR.rawValue) - setState(71) - try cmds() - setState(72) - try match(ShellParser.Tokens.RPAR.rawValue) - - break - case 3: - _localctx = CmdErrorContext(_localctx) - _ctx = _localctx - setState(74) - try match(ShellParser.Tokens.LPAR.rawValue) - setState(75) - try cmds() - setState(76) - try match(ShellParser.Tokens.RPAR.rawValue) - setState(77) - try match(ShellParser.Tokens.RPAR.rawValue) - notifyErrorListeners("Unbalanced parenthesis") - - break - case 4: - _localctx = CmdErrorContext(_localctx) - _ctx = _localctx - setState(80) - try match(ShellParser.Tokens.LPAR.rawValue) - setState(81) - try cmds() - notifyErrorListeners("Unbalanced parenthesis") - - break - default: break - } - _ctx!.stop = try _input.LT(-1) - setState(115) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,16,_ctx) - while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { - if ( _alt==1 ) { - if _parseListeners != nil { - try triggerExitRuleEvent() - } - setState(113) - try _errHandler.sync(self) - switch(try getInterpreter().adaptivePredict(_input,15, _ctx)) { - case 1: - _localctx = PipeContext( CmdContext(_parentctx, _parentState)) - try pushNewRecursionContext(_localctx, _startState, ShellParser.RULE_cmd) - setState(86) - if (!(precpred(_ctx, 6))) { - throw ANTLRException.recognition(e:FailedPredicateException(self, "precpred(_ctx, 6)")) - } - setState(90) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (_la == ShellParser.Tokens.NL.rawValue) { - setState(87) - try match(ShellParser.Tokens.NL.rawValue) - - - setState(92) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(93) - try match(ShellParser.Tokens.PIPE.rawValue) - setState(94) - try cmd(7) - - break - case 2: - _localctx = AndContext( CmdContext(_parentctx, _parentState)) - try pushNewRecursionContext(_localctx, _startState, ShellParser.RULE_cmd) - setState(95) - if (!(precpred(_ctx, 5))) { - throw ANTLRException.recognition(e:FailedPredicateException(self, "precpred(_ctx, 5)")) - } - setState(99) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (_la == ShellParser.Tokens.NL.rawValue) { - setState(96) - try match(ShellParser.Tokens.NL.rawValue) - - - setState(101) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(102) - try match(ShellParser.Tokens.AND.rawValue) - setState(103) - try cmd(6) - - break - case 3: - _localctx = OrContext( CmdContext(_parentctx, _parentState)) - try pushNewRecursionContext(_localctx, _startState, ShellParser.RULE_cmd) - setState(104) - if (!(precpred(_ctx, 4))) { - throw ANTLRException.recognition(e:FailedPredicateException(self, "precpred(_ctx, 4)")) - } - setState(108) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (_la == ShellParser.Tokens.NL.rawValue) { - setState(105) - try match(ShellParser.Tokens.NL.rawValue) - - - setState(110) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(111) - try match(ShellParser.Tokens.OR.rawValue) - setState(112) - try cmd(5) - - break - default: break - } - - } - setState(117) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,16,_ctx) - } - - } - catch ANTLRException.recognition(let re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx; - } - - public class ArgContext: ParserRuleContext { - override open - func getRuleIndex() -> Int { - return ShellParser.RULE_arg - } - } - public class WordContext: ArgContext { - open - func ARG() -> TerminalNode? { - return getToken(ShellParser.Tokens.ARG.rawValue, 0) - } - open - func WORD() -> TerminalNode? { - return getToken(ShellParser.Tokens.WORD.rawValue, 0) - } - - public - init(_ ctx: ArgContext) { - super.init() - copyFrom(ctx) - } - } - public class SubstitutionContext: ArgContext { - open - func INTERPOLATION_START() -> TerminalNode? { - return getToken(ShellParser.Tokens.INTERPOLATION_START.rawValue, 0) - } - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func RPAR() -> TerminalNode? { - return getToken(ShellParser.Tokens.RPAR.rawValue, 0) - } - - public - init(_ ctx: ArgContext) { - super.init() - copyFrom(ctx) - } - } - public class ArgErrorContext: ArgContext { - open - func LDQUOTE() -> TerminalNode? { - return getToken(ShellParser.Tokens.LDQUOTE.rawValue, 0) - } - open - func RDQUOTE() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.RDQUOTE.rawValue) - } - open - func RDQUOTE(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.RDQUOTE.rawValue, i) - } - open - func dStringFragment() -> [DStringFragmentContext] { - return getRuleContexts(DStringFragmentContext.self) - } - open - func dStringFragment(_ i: Int) -> DStringFragmentContext? { - return getRuleContext(DStringFragmentContext.self, i) - } - open - func INTERPOLATION_START() -> TerminalNode? { - return getToken(ShellParser.Tokens.INTERPOLATION_START.rawValue, 0) - } - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func RPAR() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.RPAR.rawValue) - } - open - func RPAR(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.RPAR.rawValue, i) - } - - public - init(_ ctx: ArgContext) { - super.init() - copyFrom(ctx) - } - } - public class SQuotedStringContext: ArgContext { - open - func SINGLE_QUOTED_STRING() -> TerminalNode? { - return getToken(ShellParser.Tokens.SINGLE_QUOTED_STRING.rawValue, 0) - } - - public - init(_ ctx: ArgContext) { - super.init() - copyFrom(ctx) - } - } - public class DQuotedStringContext: ArgContext { - open - func LDQUOTE() -> TerminalNode? { - return getToken(ShellParser.Tokens.LDQUOTE.rawValue, 0) - } - open - func RDQUOTE() -> TerminalNode? { - return getToken(ShellParser.Tokens.RDQUOTE.rawValue, 0) - } - open - func dStringFragment() -> [DStringFragmentContext] { - return getRuleContexts(DStringFragmentContext.self) - } - open - func dStringFragment(_ i: Int) -> DStringFragmentContext? { - return getRuleContext(DStringFragmentContext.self, i) - } - - public - init(_ ctx: ArgContext) { - super.init() - copyFrom(ctx) - } - } - @discardableResult - open func arg() throws -> ArgContext { - var _localctx: ArgContext - _localctx = ArgContext(_ctx, getState()) - try enterRule(_localctx, 6, ShellParser.RULE_arg) - var _la: Int = 0 - defer { - try! exitRule() - } - do { - var _alt:Int - setState(161) - try _errHandler.sync(self) - switch(try getInterpreter().adaptivePredict(_input,20, _ctx)) { - case 1: - _localctx = WordContext(_localctx); - try enterOuterAlt(_localctx, 1) - setState(118) - try match(ShellParser.Tokens.ARG.rawValue) - - break - case 2: - _localctx = WordContext(_localctx); - try enterOuterAlt(_localctx, 2) - setState(119) - try match(ShellParser.Tokens.WORD.rawValue) - - break - case 3: - _localctx = SQuotedStringContext(_localctx); - try enterOuterAlt(_localctx, 3) - setState(120) - try match(ShellParser.Tokens.SINGLE_QUOTED_STRING.rawValue) - - break - case 4: - _localctx = DQuotedStringContext(_localctx); - try enterOuterAlt(_localctx, 4) - setState(121) - try match(ShellParser.Tokens.LDQUOTE.rawValue) - setState(125) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 15032385536) != 0)) { - setState(122) - try dStringFragment() - - - setState(127) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(128) - try match(ShellParser.Tokens.RDQUOTE.rawValue) - - break - case 5: - _localctx = SubstitutionContext(_localctx); - try enterOuterAlt(_localctx, 5) - setState(129) - try match(ShellParser.Tokens.INTERPOLATION_START.rawValue) - setState(130) - try cmds() - setState(131) - try match(ShellParser.Tokens.RPAR.rawValue) - - break - case 6: - _localctx = ArgErrorContext(_localctx); - try enterOuterAlt(_localctx, 6) - setState(133) - try match(ShellParser.Tokens.LDQUOTE.rawValue) - setState(137) - try _errHandler.sync(self) - _la = try _input.LA(1) - while (((Int64(_la) & ~0x3f) == 0 && ((Int64(1) << _la) & 15032385536) != 0)) { - setState(134) - try dStringFragment() - - - setState(139) - try _errHandler.sync(self) - _la = try _input.LA(1) - } - setState(140) - try match(ShellParser.Tokens.RDQUOTE.rawValue) - setState(141) - try match(ShellParser.Tokens.RDQUOTE.rawValue) - notifyErrorListeners("Unbalanced quotes") - - break - case 7: - _localctx = ArgErrorContext(_localctx); - try enterOuterAlt(_localctx, 7) - setState(143) - try match(ShellParser.Tokens.LDQUOTE.rawValue) - setState(147) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,19,_ctx) - while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) { - if ( _alt==1 ) { - setState(144) - try dStringFragment() - - - } - setState(149) - try _errHandler.sync(self) - _alt = try getInterpreter().adaptivePredict(_input,19,_ctx) - } - notifyErrorListeners("Unbalanced quotes") - - break - case 8: - _localctx = ArgErrorContext(_localctx); - try enterOuterAlt(_localctx, 8) - setState(151) - try match(ShellParser.Tokens.INTERPOLATION_START.rawValue) - setState(152) - try cmds() - setState(153) - try match(ShellParser.Tokens.RPAR.rawValue) - setState(154) - try match(ShellParser.Tokens.RPAR.rawValue) - notifyErrorListeners("Unbalanced parenthesis") - - break - case 9: - _localctx = ArgErrorContext(_localctx); - try enterOuterAlt(_localctx, 9) - setState(157) - try match(ShellParser.Tokens.INTERPOLATION_START.rawValue) - setState(158) - try cmds() - notifyErrorListeners("Unbalanced parenthesis") - - break - default: break - } - } - catch ANTLRException.recognition(let re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - public class DStringFragmentContext: ParserRuleContext { - override open - func getRuleIndex() -> Int { - return ShellParser.RULE_dStringFragment - } - } - public class InterpolationContext: DStringFragmentContext { - open - func INTERPOLATION_START_IN_DSTRING() -> TerminalNode? { - return getToken(ShellParser.Tokens.INTERPOLATION_START_IN_DSTRING.rawValue, 0) - } - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func RPAR() -> TerminalNode? { - return getToken(ShellParser.Tokens.RPAR.rawValue, 0) - } - - public - init(_ ctx: DStringFragmentContext) { - super.init() - copyFrom(ctx) - } - } - public class DStringFragmentErrorContext: DStringFragmentContext { - open - func INTERPOLATION_START_IN_DSTRING() -> TerminalNode? { - return getToken(ShellParser.Tokens.INTERPOLATION_START_IN_DSTRING.rawValue, 0) - } - open - func cmds() -> CmdsContext? { - return getRuleContext(CmdsContext.self, 0) - } - open - func RPAR() -> [TerminalNode] { - return getTokens(ShellParser.Tokens.RPAR.rawValue) - } - open - func RPAR(_ i:Int) -> TerminalNode? { - return getToken(ShellParser.Tokens.RPAR.rawValue, i) - } - - public - init(_ ctx: DStringFragmentContext) { - super.init() - copyFrom(ctx) - } - } - public class EscapeSequenceContext: DStringFragmentContext { - open - func ESCAPE_SEQUENCE() -> TerminalNode? { - return getToken(ShellParser.Tokens.ESCAPE_SEQUENCE.rawValue, 0) - } - - public - init(_ ctx: DStringFragmentContext) { - super.init() - copyFrom(ctx) - } - } - public class TextContext: DStringFragmentContext { - open - func TEXT() -> TerminalNode? { - return getToken(ShellParser.Tokens.TEXT.rawValue, 0) - } - - public - init(_ ctx: DStringFragmentContext) { - super.init() - copyFrom(ctx) - } - } - @discardableResult - open func dStringFragment() throws -> DStringFragmentContext { - var _localctx: DStringFragmentContext - _localctx = DStringFragmentContext(_ctx, getState()) - try enterRule(_localctx, 8, ShellParser.RULE_dStringFragment) - defer { - try! exitRule() - } - do { - setState(179) - try _errHandler.sync(self) - switch(try getInterpreter().adaptivePredict(_input,21, _ctx)) { - case 1: - _localctx = TextContext(_localctx); - try enterOuterAlt(_localctx, 1) - setState(163) - try match(ShellParser.Tokens.TEXT.rawValue) - - break - case 2: - _localctx = EscapeSequenceContext(_localctx); - try enterOuterAlt(_localctx, 2) - setState(164) - try match(ShellParser.Tokens.ESCAPE_SEQUENCE.rawValue) - - break - case 3: - _localctx = InterpolationContext(_localctx); - try enterOuterAlt(_localctx, 3) - setState(165) - try match(ShellParser.Tokens.INTERPOLATION_START_IN_DSTRING.rawValue) - setState(166) - try cmds() - setState(167) - try match(ShellParser.Tokens.RPAR.rawValue) - - break - case 4: - _localctx = DStringFragmentErrorContext(_localctx); - try enterOuterAlt(_localctx, 4) - setState(169) - try match(ShellParser.Tokens.INTERPOLATION_START_IN_DSTRING.rawValue) - setState(170) - try cmds() - setState(171) - try match(ShellParser.Tokens.RPAR.rawValue) - setState(172) - try match(ShellParser.Tokens.RPAR.rawValue) - notifyErrorListeners("Unbalanced parenthesis") - - break - case 5: - _localctx = DStringFragmentErrorContext(_localctx); - try enterOuterAlt(_localctx, 5) - setState(175) - try match(ShellParser.Tokens.INTERPOLATION_START_IN_DSTRING.rawValue) - setState(176) - try cmds() - notifyErrorListeners("Unbalanced parenthesis") - - break - default: break - } - } - catch ANTLRException.recognition(let re) { - _localctx.exception = re - _errHandler.reportError(self, re) - try _errHandler.recover(self, re) - } - - return _localctx - } - - override open - func sempred(_ _localctx: RuleContext?, _ ruleIndex: Int, _ predIndex: Int)throws -> Bool { - switch (ruleIndex) { - case 2: - return try cmd_sempred(_localctx?.castdown(CmdContext.self), predIndex) - default: return true - } - } - private func cmd_sempred(_ _localctx: CmdContext!, _ predIndex: Int) throws -> Bool { - switch (predIndex) { - case 0:return precpred(_ctx, 6) - case 1:return precpred(_ctx, 5) - case 2:return precpred(_ctx, 4) - default: return true - } - } - - static let _serializedATN:[Int] = [ - 4,1,34,182,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,1,0,5,0,12,8,0,10,0, - 12,0,15,9,0,1,0,1,0,1,0,1,0,3,0,21,8,0,1,1,1,1,1,1,1,1,3,1,27,8,1,1,1, - 1,1,1,1,1,1,3,1,33,8,1,5,1,35,8,1,10,1,12,1,38,9,1,1,1,1,1,3,1,42,8,1, - 3,1,44,8,1,1,1,1,1,1,1,1,1,4,1,50,8,1,11,1,12,1,51,1,1,5,1,55,8,1,10,1, - 12,1,58,9,1,1,1,3,1,61,8,1,1,2,1,2,1,2,5,2,66,8,2,10,2,12,2,69,9,2,1,2, - 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,85,8,2,1,2,1,2, - 5,2,89,8,2,10,2,12,2,92,9,2,1,2,1,2,1,2,1,2,5,2,98,8,2,10,2,12,2,101,9, - 2,1,2,1,2,1,2,1,2,5,2,107,8,2,10,2,12,2,110,9,2,1,2,1,2,5,2,114,8,2,10, - 2,12,2,117,9,2,1,3,1,3,1,3,1,3,1,3,5,3,124,8,3,10,3,12,3,127,9,3,1,3,1, - 3,1,3,1,3,1,3,1,3,1,3,5,3,136,8,3,10,3,12,3,139,9,3,1,3,1,3,1,3,1,3,1, - 3,5,3,146,8,3,10,3,12,3,149,9,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1, - 3,1,3,3,3,162,8,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4, - 1,4,1,4,1,4,3,4,180,8,4,1,4,1,56,1,4,5,0,2,4,6,8,0,1,1,0,23,24,212,0,13, - 1,0,0,0,2,60,1,0,0,0,4,84,1,0,0,0,6,161,1,0,0,0,8,179,1,0,0,0,10,12,5, - 24,0,0,11,10,1,0,0,0,12,15,1,0,0,0,13,11,1,0,0,0,13,14,1,0,0,0,14,20,1, - 0,0,0,15,13,1,0,0,0,16,17,3,2,1,0,17,18,5,0,0,1,18,21,1,0,0,0,19,21,5, - 0,0,1,20,16,1,0,0,0,20,19,1,0,0,0,21,1,1,0,0,0,22,23,5,8,0,0,23,24,3,4, - 2,0,24,26,5,12,0,0,25,27,3,2,1,0,26,25,1,0,0,0,26,27,1,0,0,0,27,36,1,0, - 0,0,28,29,5,7,0,0,29,30,3,4,2,0,30,32,5,12,0,0,31,33,3,2,1,0,32,31,1,0, - 0,0,32,33,1,0,0,0,33,35,1,0,0,0,34,28,1,0,0,0,35,38,1,0,0,0,36,34,1,0, - 0,0,36,37,1,0,0,0,37,43,1,0,0,0,38,36,1,0,0,0,39,41,5,13,0,0,40,42,3,2, - 1,0,41,40,1,0,0,0,41,42,1,0,0,0,42,44,1,0,0,0,43,39,1,0,0,0,43,44,1,0, - 0,0,44,45,1,0,0,0,45,46,5,18,0,0,46,61,1,0,0,0,47,49,3,4,2,0,48,50,7,0, - 0,0,49,48,1,0,0,0,50,51,1,0,0,0,51,49,1,0,0,0,51,52,1,0,0,0,52,56,1,0, - 0,0,53,55,3,2,1,0,54,53,1,0,0,0,55,58,1,0,0,0,56,57,1,0,0,0,56,54,1,0, - 0,0,57,61,1,0,0,0,58,56,1,0,0,0,59,61,3,4,2,0,60,22,1,0,0,0,60,47,1,0, - 0,0,60,59,1,0,0,0,61,3,1,0,0,0,62,63,6,2,-1,0,63,67,5,25,0,0,64,66,3,6, - 3,0,65,64,1,0,0,0,66,69,1,0,0,0,67,65,1,0,0,0,67,68,1,0,0,0,68,85,1,0, - 0,0,69,67,1,0,0,0,70,71,5,4,0,0,71,72,3,2,1,0,72,73,5,6,0,0,73,85,1,0, - 0,0,74,75,5,4,0,0,75,76,3,2,1,0,76,77,5,6,0,0,77,78,5,6,0,0,78,79,6,2, - -1,0,79,85,1,0,0,0,80,81,5,4,0,0,81,82,3,2,1,0,82,83,6,2,-1,0,83,85,1, - 0,0,0,84,62,1,0,0,0,84,70,1,0,0,0,84,74,1,0,0,0,84,80,1,0,0,0,85,115,1, - 0,0,0,86,90,10,6,0,0,87,89,5,24,0,0,88,87,1,0,0,0,89,92,1,0,0,0,90,88, - 1,0,0,0,90,91,1,0,0,0,91,93,1,0,0,0,92,90,1,0,0,0,93,94,5,21,0,0,94,114, - 3,4,2,7,95,99,10,5,0,0,96,98,5,24,0,0,97,96,1,0,0,0,98,101,1,0,0,0,99, - 97,1,0,0,0,99,100,1,0,0,0,100,102,1,0,0,0,101,99,1,0,0,0,102,103,5,20, - 0,0,103,114,3,4,2,6,104,108,10,4,0,0,105,107,5,24,0,0,106,105,1,0,0,0, - 107,110,1,0,0,0,108,106,1,0,0,0,108,109,1,0,0,0,109,111,1,0,0,0,110,108, - 1,0,0,0,111,112,5,22,0,0,112,114,3,4,2,5,113,86,1,0,0,0,113,95,1,0,0,0, - 113,104,1,0,0,0,114,117,1,0,0,0,115,113,1,0,0,0,115,116,1,0,0,0,116,5, - 1,0,0,0,117,115,1,0,0,0,118,162,5,26,0,0,119,162,5,25,0,0,120,162,5,2, - 0,0,121,125,5,3,0,0,122,124,3,8,4,0,123,122,1,0,0,0,124,127,1,0,0,0,125, - 123,1,0,0,0,125,126,1,0,0,0,126,128,1,0,0,0,127,125,1,0,0,0,128,162,5, - 34,0,0,129,130,5,5,0,0,130,131,3,2,1,0,131,132,5,6,0,0,132,162,1,0,0,0, - 133,137,5,3,0,0,134,136,3,8,4,0,135,134,1,0,0,0,136,139,1,0,0,0,137,135, - 1,0,0,0,137,138,1,0,0,0,138,140,1,0,0,0,139,137,1,0,0,0,140,141,5,34,0, - 0,141,142,5,34,0,0,142,162,6,3,-1,0,143,147,5,3,0,0,144,146,3,8,4,0,145, - 144,1,0,0,0,146,149,1,0,0,0,147,145,1,0,0,0,147,148,1,0,0,0,148,150,1, - 0,0,0,149,147,1,0,0,0,150,162,6,3,-1,0,151,152,5,5,0,0,152,153,3,2,1,0, - 153,154,5,6,0,0,154,155,5,6,0,0,155,156,6,3,-1,0,156,162,1,0,0,0,157,158, - 5,5,0,0,158,159,3,2,1,0,159,160,6,3,-1,0,160,162,1,0,0,0,161,118,1,0,0, - 0,161,119,1,0,0,0,161,120,1,0,0,0,161,121,1,0,0,0,161,129,1,0,0,0,161, - 133,1,0,0,0,161,143,1,0,0,0,161,151,1,0,0,0,161,157,1,0,0,0,162,7,1,0, - 0,0,163,180,5,31,0,0,164,180,5,33,0,0,165,166,5,32,0,0,166,167,3,2,1,0, - 167,168,5,6,0,0,168,180,1,0,0,0,169,170,5,32,0,0,170,171,3,2,1,0,171,172, - 5,6,0,0,172,173,5,6,0,0,173,174,6,4,-1,0,174,180,1,0,0,0,175,176,5,32, - 0,0,176,177,3,2,1,0,177,178,6,4,-1,0,178,180,1,0,0,0,179,163,1,0,0,0,179, - 164,1,0,0,0,179,165,1,0,0,0,179,169,1,0,0,0,179,175,1,0,0,0,180,9,1,0, - 0,0,22,13,20,26,32,36,41,43,51,56,60,67,84,90,99,108,113,115,125,137,147, - 161,179 - ] - - public - static let _ATN = try! ATNDeserializer().deserialize(_serializedATN) -} \ No newline at end of file diff --git a/Sources/AppBundle/shell/Shell.swift b/Sources/AppBundle/shell/Shell.swift deleted file mode 100644 index cda31859..00000000 --- a/Sources/AppBundle/shell/Shell.swift +++ /dev/null @@ -1,290 +0,0 @@ -// periphery:ignore:all - This is WIP file todo -import Antlr4 -import Common -import ShellParserGenerated - -typealias TK = ShellParser.Tokens - -/// Use the following technique for quick grammar testing: -/// source .deps/python-venv/bin/activate.fish -/// echo "foo bar" | antlr4-parse ./grammar/ShellLexer.g4 ./grammar/ShellParser.g4 root -gui -extension String { - func parseShell() -> Result { - let stream = ANTLRInputStream(self) - let lexer = ShellLexer(stream) - let errorsCollector = ErrorListenerCollector() - lexer.addErrorListener(errorsCollector) - let tokenStream = CommonTokenStream(lexer) - let parser: ShellParser - switch Result(catching: { try ShellParser(tokenStream) }) { - case .success(let x): parser = x - case .failure(let msg): - return .failure(msg.localizedDescription) - } - parser.addErrorListener(errorsCollector) - let root: ShellParser.RootContext - switch Result(catching: { try parser.root() }) { - case .success(let x): root = x - case .failure(let msg): - return .failure(msg.localizedDescription) - } - if !errorsCollector.errors.isEmpty { - return .failure(errorsCollector.errors.joinErrors()) - } - return root.cmds().map { $0.toTyped() } ?? .success(.empty) - } -} - -let keywords = [TK.DO, TK.THEN, TK.IF, TK.END, TK.ELSE, TK.SWITCH, TK.IN, TK.CASE, TK.WHILE, TK.DEFER, TK.FOR, TK.CATCH].map(\.rawValue) - -final class ErrorListenerCollector: BaseErrorListener { - var errors: [String] = [] - override func syntaxError( - _ recognizer: Recognizer, - _ offendingSymbol: AnyObject?, - _ line: Int, - _ charPositionInLine: Int, - _ msg: String, - _ e: AnyObject?, - ) { - let offendingToken = (offendingSymbol as? Token)?.getType() - if offendingToken == TK.TRIPLE_QUOTE.rawValue { - errors.append("Triple quotes are reserved for future use. Please put spaces in between if you meant separate args") - return - } - let helper = if let offendingToken, keywords.contains(offendingToken), - let name = ShellParser.VOCABULARY.getSymbolicName(offendingToken) - { - ". \(name) is a reserved keyword. Please, put quotes around it, if you want to use it as an argument" - } else if offendingToken == TK.ANY.rawValue { - ". Please put the character/word in quotes, if you want to use it as an argument" - } else { - "" - } - errors.append("Syntax error at \(line):\(charPositionInLine) \(msg)\(helper)") - } -} - -extension ShellParser.CmdsContext { - func toTyped() -> Result { - if let x = self as? ShellParser.SeqContext { - return x.cmd().toTyped("seq node: nil cmd") - .combine { x.cmds().mapAllOrFailures { $0.toTyped() }.mapError { $0.joinErrors() } } - .flatMap { - let seq = [$0.0] + $0.1 - return switch seq.count { - case 0: .failure("seq node: 0 children") - case 1: .success(seq.first.orDie()) - default: .success(Shell.seq(seq)) - } - } - } - if let x = self as? ShellParser.IfElseContext { - return Result { try parseIfElse(x) }.mapError { $0 as! String } - } - return .failure("Unknown node type: \(self)") - } -} - -private func parseIfElse(_ ifElse: ShellParser.IfElseContext) throws -> Shell { - var lastCond: Shell? = nil - var branches: [Branch] = [] - var elseVisited = false - guard let children = ifElse.children else { throw "switch if: nil children" } - for child in children { - if let child = child as? ShellParser.CmdContext { - if let lastCond { branches.append(Branch(cond: lastCond, then: nil)) } - lastCond = try child.toTyped().get() - } else if let child = child as? ShellParser.CmdsContext { - if elseVisited { - return .ifElse(IfElse(branches: branches, elseBranch: try child.toTyped().get())) - } else { - try branches.append(Branch(cond: lastCond ?? throwT("nil lastCond"), then: child.toTyped().get())) - lastCond = nil - } - } else if let child = child as? TerminalNode, - child.getSymbol()?.getType() == TK.ELSE.rawValue - { - elseVisited = true - if let lastCond { branches.append(Branch(cond: lastCond, then: nil)) } - lastCond = nil - } - } - if let lastCond { - if elseVisited { throw "ifElse node: wtf" } - return .ifElse(IfElse(branches: [Branch(cond: lastCond, then: nil)], elseBranch: nil)) - } - return .ifElse(IfElse(branches: branches, elseBranch: nil)) -} - -extension ShellParser.CmdContext { - func toTyped() -> Result { - if let x = self as? ShellParser.PipeContext { - return binaryNode(Shell.pipe, x.cmd(0), x.cmd(1)) - } - if let x = self as? ShellParser.AndContext { - return binaryNode(Shell.and, x.cmd(0), x.cmd(1)) - } - if let x = self as? ShellParser.OrContext { - return binaryNode(Shell.or, x.cmd(0), x.cmd(1)) - } - if let x = self as? ShellParser.ParensContext { - return x.cmds().toTyped("parens node: nil childe") - } - if let x = self as? ShellParser.ArgsContext { - return (x.WORD()?.getText()).orFailure("args node: nil first word").map(ShellString.text) - .combine { x.arg().mapAllOrFailures { $0.toTyped() }.mapError { $0.joinErrors() } } - .map { [$0.0] + $0.1 } - .map(Shell.args) - } - return .failure("Unknown node type: \(self)") - } -} - -extension ShellParser.ArgContext { - func toTyped() -> Result, String> { - if let x = self as? ShellParser.WordContext { - return .success(.text(x.getText())) - } - if let x = self as? ShellParser.DQuotedStringContext { - return x.dStringFragment().mapAllOrFailures { $0.toTyped() } - .mapError { $0.joinErrors() }.map(ShellString.concatOptimized) - } - if let x = self as? ShellParser.SQuotedStringContext { - return .success(.text(String(x.getText().dropFirst(1).dropLast(1)))) - } - if let x = self as? ShellParser.SubstitutionContext { - return x.cmds().toTyped("substitution node: nil child").map(ShellString.interpolation) - } - return .failure("Unknown node type: \(self)") - } -} - -extension ShellParser.DStringFragmentContext { - func toTyped() -> Result, String> { - if let x = self as? ShellParser.EscapeSequenceContext { - return switch x.getText() { - case "\\n": .success(.text("\n")) - case "\\t": .success(.text("\t")) - case "\\$": .success(.text("$")) - case "\\\"": .success(.text("\"")) - case "\\\\": .success(.text("\\")) - default: .failure("Unknown ESCAPE_SEQUENCE '\(x.getText())'") - } - } - if let x = self as? ShellParser.TextContext { - return .success(.text(x.getText())) - } - if let x = self as? ShellParser.InterpolationContext { - return x.cmds().toTyped("interpolation node: nil child").map(ShellString.interpolation) - } - return .failure("Unknown node type: \(self)") - } -} - -private func binaryNode( - _ op: (RawShell, RawShell) -> RawShell, - _ a: ShellParser.CmdContext?, - _ b: ShellParser.CmdContext?, -) -> Result { - a.toTyped("binary node: nil child 0").combine { b.toTyped("binary node: nil child 1") }.map(op) -} - -extension Result { - func combine(_ other: () -> Result) -> Result<(Success, T), Failure> { - flatMap { a in - other().flatMap { b in - .success((a, b)) - } - } - } -} - -extension Result where Success == ShellParser.CmdContext, Failure == String { - func toTyped() -> Result { flatMap { $0.toTyped() } } -} -extension Result where Success == ShellParser.CmdsContext, Failure == String { - func toTyped() -> Result { flatMap { $0.toTyped() } } -} - -extension ShellParser.CmdContext? { - fileprivate func toTyped(_ msg: String) -> Result { orFailure(msg).toTyped() } -} -extension ShellParser.CmdsContext? { - fileprivate func toTyped(_ msg: String) -> Result { orFailure(msg).toTyped() } -} - -// protocol AeroShell { -// func run(_ state: CmdMutableState) -> CmdOut -// } -// extension [String] : AeroShell { -// func run(_ state: CmdMutableState) -> CmdOut { .succ(self) } -// } - -extension Shell: Equatable where T: Equatable {} -typealias AeroShell = Shell -typealias RawShell = Shell -indirect enum Shell { - case args([ShellString]) - case empty - - case ifElse(IfElse) - - // Listed in precedence order - case pipe(Shell, Shell) - case and(Shell, Shell) - case or(Shell, Shell) - case seq([Shell]) - - static func ifElse(_ branches: (Shell, Shell?)..., elseB: Shell?) -> Shell { - .ifElse(IfElse(branches: branches.map { Branch(cond: $0.0, then: $0.1) }, elseBranch: elseB)) - } -} - -extension IfElse: Equatable where T: Equatable {} -struct IfElse { - let branches: [Branch] - let elseBranch: Shell? -} - -extension Branch: Equatable where T: Equatable {} -struct Branch { - let cond: Shell - let then: Shell? -} - -extension ShellString: Equatable where T: Equatable {} -enum ShellString { - case text(String) - case interpolation(Shell) - case concat([ShellString]) - - static func concatOptimized(_ fragments: [ShellString]) -> ShellString { - var result: [ShellString] = [] - var current: String = "" - _concatOptimized(fragments, &result, ¤t) - if !current.isEmpty { - result.append(.text(current)) - } - return result.singleOrNil() ?? .concat(result) - } - - private static func _concatOptimized( - _ fragments: [ShellString], - _ result: inout [ShellString], - _ current: inout String, - ) { - for fragment in fragments { - switch fragment { - case .text(let text): current += text - case .concat(let newFragments): _concatOptimized(newFragments, &result, ¤t) - case .interpolation: - if !current.isEmpty { - result.append(.text(current)) - current = "" - } - result.append(fragment) - } - } - } -} diff --git a/Sources/AppBundleTests/shell/ShellTest.swift b/Sources/AppBundleTests/shell/ShellTest.swift deleted file mode 100644 index b638a0ee..00000000 --- a/Sources/AppBundleTests/shell/ShellTest.swift +++ /dev/null @@ -1,120 +0,0 @@ -// todo do something about ShellTest. They are commented out to reduce test log verbosity -// @testable import AppBundle -// import Common -// import XCTest -// -// final class ShellTest: XCTestCase { -// let a = cmd("a") -// let b = cmd("b") -// let c = cmd("c") -// let d = cmd("d") -// let e = cmd("e") -// let f = cmd("f") -// let g = cmd("g") -// let k = cmd("k") -// let backslash = "\\" -// let space = " " -// -// func testParse() { -// assertSucc("echo \"foo \\\" bar \(backslash)\(backslash)\(backslash)\(backslash)\" bar".parseShell(), cmd("echo", "foo \" bar \(backslash)\(backslash)", "bar")) -// assertSucc(" \n".parseShell(), .empty) -// assertSucc("a | b && c | d".parseShell(), .and(.pipe(a, b), .pipe(c, d))) -// assertSucc("foo && bar || a && baz".parseShell(), .or(.and(cmd("foo"), cmd("bar")), .and(cmd("a"), cmd("baz")))) -// assertSucc("foo a b; bar duh\n baz bro".parseShell(), .seqV(cmd("foo", "a", "b"), cmd("bar", "duh"), cmd("baz", "bro"))) -// assertSucc("(a || b) && (c || d)".parseShell(), .and(.or(a, b), .or(c, d))) -// assertSucc(""" -// a # comment 1 -// b && c # comment 2 -// d; # comment 3 -// """.parseShell(), .seqV(a, .and(b, c), d)) -// assertEquals(""" -// a && b # comment 1 -// # comment 2 -// # comment 3 -// || c && d -// """.parseShell(), .success(.or(.and(a, b), .and(c, d)))) -// assertSucc(""" -// a \(backslash)\(space) -// b c \(backslash) # comment 2 -// d && e \(backslash) -// && f -// """.parseShell(), .and(.and(cmd("a", "b", "c", "d"), e), f)) -// assertSucc( -// """ -// echo "hi \\n $(foo bar)" -// """.parseShell(), -// .args([.text("echo"), .concatV(.text("hi \n "), .interpolation(cmd("foo", "bar")))]), -// ) -// assertSucc("echo \"\\n\\t\\$\"".parseShell(), cmd("echo", "\n\t$")) -// assertSucc("echo 'single quoted \\n'".parseShell(), cmd("echo", "single quoted \\n")) -// -// assertFail("echo \"\\f\"".parseShell(), "ERROR: ERROR: Unknown ESCAPE_SEQUENCE '\\f'") -// assertFail("echo <".parseShell(), "ERROR: Syntax error at 1:5 extraneous input '<' expecting . Please put the character/word in quotes, if you want to use it as an argument") -// assertFail("echo `".parseShell(), "ERROR: Syntax error at 1:5 extraneous input '`' expecting . Please put the character/word in quotes, if you want to use it as an argument") -// assertFail("echo \"\"\"\"".parseShell(), "ERROR: Triple quotes are reserved for future use. Please put spaces in between if you meant separate args") -// assertFail("echo do".parseShell(), "ERROR: Syntax error at 1:5 extraneous input 'do' expecting . DO is a reserved keyword. Please, put quotes around it, if you want to use it as an argument") -// assertFail("echo \"foo \(backslash)\"".parseShell(), "ERROR: Syntax error at 1:12 Unbalanced quotes") -// assertFail("a; (b".parseShell(), "ERROR: Syntax error at 1:5 Unbalanced parenthesis") -// assertFail("a; (b))".parseShell(), "ERROR: Syntax error at 1:7 Unbalanced parenthesis") -// assertFail("|| foo".parseShell()) -// assertFail("a && (b || c) foo".parseShell()) -// } -// -// func testParseIf() { -// assertSucc("if a then b else c end".parseShell(), .ifElse((a, b), elseB: c)) -// assertSucc(""" -// if a && b then -// c -// else -// d -// end -// """.parseShell(), .ifElse((.and(a, b), c), elseB: d)) -// assertSucc(""" -// if a && b then -// c -// end -// """.parseShell(), .ifElse((.and(a, b), c), elseB: nil)) -// assertSucc(""" -// if a && b then -// c -// elif d then -// e -// elif f then -// g -// end -// """.parseShell(), .ifElse((.and(a, b), c), (d, e), (f, g), elseB: nil)) -// assertSucc(""" -// if a && b then -// end -// """.parseShell(), .ifElse((.and(a, b), nil), elseB: nil)) -// assertSucc(""" -// if a && b then -// else -// c -// end -// """.parseShell(), .ifElse((.and(a, b), nil), elseB: c)) -// assertSucc(""" -// echo foo -// -// echo bar;; -// -// if a && b then -// c -// elif d then -// e -// elif f then -// g -// k -// end -// """.parseShell(), .seqV(cmd("echo", "foo"), cmd("echo", "bar"), .ifElse((.and(a, b), c), (d, e), (f, .seqV(g, k)), elseB: nil))) -// } -// } -// -// func cmd(_ args: String...) -> Shell { .args(args.map(ShellString.text)) } -// extension Shell { -// static func seqV(_ seq: Shell...) -> Shell { .seq(seq) } -// } -// -// extension ShellString { -// static func concatV(_ fragments: ShellString...) -> ShellString { .concat(fragments) } -// } diff --git a/Sources/Common/util/commonUtil.swift b/Sources/Common/util/commonUtil.swift index 9c4e5037..54584c35 100644 --- a/Sources/Common/util/commonUtil.swift +++ b/Sources/Common/util/commonUtil.swift @@ -118,9 +118,8 @@ public enum RefreshSessionEvent: Sendable, CustomStringConvertible { } } -public func throwT(_ error: Error) throws -> T { - throw error -} +// periphery:ignore +public func throwT(_ error: Error) throws -> T { throw error } public func getStringStacktrace() -> String { Thread.callStackSymbols.joined(separator: "\n") } diff --git a/build-debug.sh b/build-debug.sh index ff317299..fbefd4b8 100755 --- a/build-debug.sh +++ b/build-debug.sh @@ -4,7 +4,7 @@ source ./script/setup.sh # 1. It takes 300ms for cmd-help to generate. It's too long to run in build-debug.sh, that's why we ignore it # 2. Grammar is not expected to change very often, that's why it's not regenerated by default -./generate.sh --ignore-xcodeproj --ignore-cmd-help --ignore-shell-parser +./generate.sh --ignore-xcodeproj --ignore-cmd-help swift build "$@" swift build --target AppBundleTests "$@" # swift build doesn't build test targets by default :( diff --git a/generate.sh b/generate.sh index 4a77f8cb..efb57222 100755 --- a/generate.sh +++ b/generate.sh @@ -6,7 +6,6 @@ export XCODEGEN_AEROSPACE_CODE_SIGN_IDENTITY="aerospace-codesign-certificate" build_version="0.0.0-SNAPSHOT" generate_xcodeproj=1 generate_cmd_help=1 -generate_shell_parser=1 generate_git_hash=0 while test $# -gt 0; do case $1 in @@ -15,15 +14,10 @@ while test $# -gt 0; do --generate-git-hash) generate_git_hash=1; shift 1;; --ignore-cmd-help) generate_cmd_help=0; shift 1 ;; --ignore-xcodeproj) generate_xcodeproj=0; shift 1 ;; - --ignore-shell-parser) generate_shell_parser=0; shift 1 ;; *) echo "Unknown option $1"; exit 1 ;; esac done -if test $generate_shell_parser = 1; then - ./script/generate-shell-parser.sh -fi - if test $generate_cmd_help = 1; then # It takes 300ms for the script to complete ./script/generate-cmd-help.sh diff --git a/grammar/ShellLexer.g4 b/grammar/ShellLexer.g4 deleted file mode 100644 index 23e3cd0a..00000000 --- a/grammar/ShellLexer.g4 +++ /dev/null @@ -1,51 +0,0 @@ -// shell lexer grammar. Powered by https://github.com/antlr/antlr4 -// Use ./script/generate-shell-parser.sh to regenerate grammar code -lexer grammar ShellLexer; - -TRIPLE_QUOTE : '"""' | '\'\'\'' ; // Reserved - -SINGLE_QUOTED_STRING : '\'' .*? '\'' ; - -LDQUOTE : '"' -> pushMode(IN_DSTRING) ; -LPAR : '(' -> pushMode(DEFAULT_MODE) ; -INTERPOLATION_START : '$(' -> pushMode(DEFAULT_MODE) ; -RPAR : ')' { - _ = try? popMode() -} ; - -// Keywords (some of them are unused, just reserved) -ELIF : 'elif' NL* ; -IF : 'if' NL* ; -SWITCH : 'switch' NL* ; -CASE : 'case' NL* ; -DO : 'do' NL* ; -THEN : 'then' NL* ; -ELSE : 'else' NL* ; -FOR : 'for' NL* ; -WHILE : 'while' NL* ; -CATCH : 'catch' NL* ; -IN : 'in' NL* ; -END : 'end' NL* ; -DEFER : 'defer' NL* ; - -AND : '&&' ; -PIPE : '|' ; -OR : '||' ; -SEMICOLON : ';' ; -NL : SPACES? ('\r')? '\n' ; -WORD : ([a-zA-Z] | '.' | '_' | '-' | '/')+ ; -ARG : ([a-zA-Z0-9] | '.' | '_' | '-' | '/' | '+' | ',' | '=' | '!' | '%' | '{' | '}' | '^')+ ; - -ESCAPE_NEWLINE : '\\' SPACES? COMMENT? '\n' -> skip ; -COMMENT : '#' ~('\n')* -> skip ; -SPACES : [ \t]+ -> skip ; - -ANY : . ; // Catch all other - -mode IN_DSTRING; -TEXT : ~('\\' | '"' | '$')+ ; -INTERPOLATION_START_IN_DSTRING : '$(' -> pushMode(DEFAULT_MODE) ; -ESCAPE_SEQUENCE : '\\' . ; -RDQUOTE : '"' { - _ = try? popMode() -} ; diff --git a/grammar/ShellParser.g4 b/grammar/ShellParser.g4 deleted file mode 100644 index bb34825c..00000000 --- a/grammar/ShellParser.g4 +++ /dev/null @@ -1,46 +0,0 @@ -// shell parser grammar. Powered by https://github.com/antlr/antlr4 -// Use ./script/generate-shell-parser.sh to regenerate grammar code -parser grammar ShellParser; - -options { - tokenVocab = './grammar/ShellLexer'; -} - -root : NL* (cmds EOF | EOF) ; // Consume ALL the input - -cmds - : IF cmd THEN cmds? (ELIF cmd THEN cmds?)* (ELSE cmds?)? END #IfElse - | cmd (SEMICOLON | NL)+ (cmds)*? #Seq - | cmd #Seq - ; - -cmd - : WORD arg* #Args - | cmd NL* PIPE cmd #Pipe - | cmd NL* AND cmd #And - | cmd NL* OR cmd #Or - | LPAR cmds RPAR #Parens - | LPAR cmds RPAR RPAR {notifyErrorListeners("Unbalanced parenthesis")} #CmdError - | LPAR cmds {notifyErrorListeners("Unbalanced parenthesis")} #CmdError - ; - -arg - : ARG #Word - | WORD #Word - | SINGLE_QUOTED_STRING #SQuotedString - | LDQUOTE dStringFragment* RDQUOTE #DQuotedString - | INTERPOLATION_START cmds RPAR #Substitution - - | LDQUOTE dStringFragment* RDQUOTE RDQUOTE {notifyErrorListeners("Unbalanced quotes")} #ArgError - | LDQUOTE dStringFragment* {notifyErrorListeners("Unbalanced quotes")} #ArgError - | INTERPOLATION_START cmds RPAR RPAR {notifyErrorListeners("Unbalanced parenthesis")} #ArgError - | INTERPOLATION_START cmds {notifyErrorListeners("Unbalanced parenthesis")} #ArgError - ; - -dStringFragment - : TEXT #Text - | ESCAPE_SEQUENCE #EscapeSequence - | INTERPOLATION_START_IN_DSTRING cmds RPAR #Interpolation - | INTERPOLATION_START_IN_DSTRING cmds RPAR RPAR {notifyErrorListeners("Unbalanced parenthesis")} #DStringFragmentError - | INTERPOLATION_START_IN_DSTRING cmds {notifyErrorListeners("Unbalanced parenthesis")} #DStringFragmentError - ; diff --git a/legal/README.md b/legal/README.md index 9ee4ea23..7157c1eb 100644 --- a/legal/README.md +++ b/legal/README.md @@ -16,11 +16,6 @@ HotKey is used as a more convenient wrapper around macOS Carbon API to listen fo [TOMLDecoder MIT license](./third-party-license/LICENSE-TOMLDecoder.txt). TOMLDecoder is used as TOML parsing library. -**ANTLR v4**. -[ANTLR v4 GitHub link](https://github.com/antlr/antlr4). -[ANTLR BSD-3 license](./third-party-license/LICENSE-antlr.txt). -ANTLR is used to parse AeroSpace built-in shell like language. - **swift-collections**. [swift-collections GitHub link](https://github.com/apple/swift-collections). [swift-collections Apache 2.0 license](./third-party-license/LICENSE-swift-collections.txt). diff --git a/legal/third-party-license/LICENSE-antlr.txt b/legal/third-party-license/LICENSE-antlr.txt deleted file mode 100644 index 5d276941..00000000 --- a/legal/third-party-license/LICENSE-antlr.txt +++ /dev/null @@ -1,28 +0,0 @@ -Copyright (c) 2012-2022 The ANTLR Project. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. Neither name of copyright holders nor the names of its contributors -may be used to endorse or promote products derived from this software -without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/script/generate-shell-parser.sh b/script/generate-shell-parser.sh deleted file mode 100755 index df8b5b88..00000000 --- a/script/generate-shell-parser.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -cd "$(dirname "$0")/.." -source ./script/setup.sh - -./script/install-dep.sh --antlr -./.deps/python-venv/bin/antlr4 -v "$antlr_version" -no-listener -Dlanguage=Swift \ - -o ./ShellParserGenerated/Sources/ShellParserGenerated \ - ./grammar/ShellLexer.g4 \ - ./grammar/ShellParser.g4 - - -mv ./ShellParserGenerated/Sources/ShellParserGenerated/grammar/*.swift ./ShellParserGenerated/Sources/ShellParserGenerated/ -rm -rf ./ShellParserGenerated/Sources/ShellParserGenerated/grammar # Antlr generates weird *.interp and *.tokens files - -# Sources/ShellParserGenerated/ShellParser.swift:557:7: warning: variable '_prevctx' was written to, but never read -# var _prevctx: CmdContext = _localctx -sed -i '' '/_prevctx/d' ./ShellParserGenerated/Sources/ShellParserGenerated/ShellParser.swift diff --git a/script/install-dep.sh b/script/install-dep.sh index 410b05dd..a701b235 100755 --- a/script/install-dep.sh +++ b/script/install-dep.sh @@ -3,7 +3,6 @@ cd "$(dirname "$0")/.." source ./script/setup.sh all=0 -antlr=0 complgen=0 swiftlint=0 swiftformat=0 @@ -12,7 +11,6 @@ bundler=0 periphery=0 while test $# -gt 0; do case $1 in - --antlr) antlr=1; shift ;; --complgen) complgen=1; shift ;; --swiftlint) swiftlint=1; shift ;; --xcodegen) xcodegen=1; shift ;; @@ -40,18 +38,6 @@ if test $all == 1 || test $bundler == 1; then fi fi -if test $all == 1 || test $antlr == 1; then - # https://github.com/antlr/antlr4/releases - antlr_tools='antlr4-tools==0.2.1' - marker=$(get-marker antlr $antlr_tools $antlr_version) - if ! test -f "$marker"; then - python3 -m venv .deps/python-venv - source .deps/python-venv/bin/activate - python3 -m pip install "$antlr_tools" - create-marker "$marker" - fi -fi - if test $all == 1 || test $complgen == 1; then # https://github.com/adaszko/complgen/releases complgen_rev=cacb3970eb diff --git a/script/setup.sh b/script/setup.sh index 28e190e4..e4113d99 100644 --- a/script/setup.sh +++ b/script/setup.sh @@ -9,9 +9,6 @@ if ! grep -q '^5\.' <<< "$BASH_VERSION"; then exit 1 fi -# When you bump this version, don't forget to also bump ./ShellParserGenerated/Package.swift -export antlr_version="4.13.1" - add-optional-dep-to-bin() { if /usr/bin/which "$1" &> /dev/null; then /bin/cat > ".deps/bin/${2:-$1}" <