diff --git a/.travis.yml b/.travis.yml index b2a837b25..e89775a58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,8 @@ deploy: api_key: secure: DNq1wbqLPHVpJPDx9O89HZM+RJB6v2R7/wk8pok7Z8NT72kUWdvbqcThGhczPO4sZ8cUTJ3ergTCE8hs9mynlR/lX6932U4fj4+uICQL9+G+deBB/t2SNyTBllkE64WrJ9BKmQvIk/Chh7ZJOM0Fro3p2BIq3JsVnfYg1tZ3U5o= file: - - package/chevrotain-binaries-0.5.18.zip - - package/chevrotain-binaries-0.5.18.tar.gz + - package/chevrotain-binaries-0.5.19.zip + - package/chevrotain-binaries-0.5.19.tar.gz on: tags : true all_branches: true diff --git a/bower.json b/bower.json index fb69b328a..d76231de0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "chevrotain", - "version": "0.5.18", + "version": "0.5.19", "description": "Chevrotain is a high performance fault Tolerant Javascript parsing DSL for building recursive decent parsers", "main": "release/chevrotain.js", "dependencies": {}, diff --git a/docs/tutorial/step2_parsing.md b/docs/tutorial/step2_parsing.md index 664983db8..82446518a 100644 --- a/docs/tutorial/step2_parsing.md +++ b/docs/tutorial/step2_parsing.md @@ -44,16 +44,16 @@ relationalOperator A Chevrotain Parser analyses a [Token](https://github.com/SAP/chevrotain/blob/master/src/scan/tokens_public.ts#L61) vector that conforms to some grammar. -The grammar is defined using the [parsing DSL](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#at_least_one), +The grammar is defined using the [parsing DSL](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#at_least_one), Which includes the following methods. -* [CONSUME](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#consume1) - 'eat' a Token. -* [SUBRULE](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#subrule1) - reference to another rule. -* [OPTION](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#option1) - optional production. -* [MANY](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#many1) - repetition zero or more. -* [AT_LEAST_ONE](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#at_least_one1) - repetition one or more. -* [MANY_SEP](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#many_sep1) - repetition (zero or more) with a separator between any two items -* [AT_LEAST_ONE_SEP](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#at_least_one_sep1) - repetition (one or more) with a separator between any two items +* [CONSUME](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#consume1) - 'eat' a Token. +* [SUBRULE](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#subrule1) - reference to another rule. +* [OPTION](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#option1) - optional production. +* [MANY](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#many1) - repetition zero or more. +* [AT_LEAST_ONE](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#at_least_one1) - repetition one or more. +* [MANY_SEP](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#many_sep1) - repetition (zero or more) with a separator between any two items +* [AT_LEAST_ONE_SEP](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#at_least_one_sep1) - repetition (one or more) with a separator between any two items #### Lets implement our first grammar rule. diff --git a/docs/tutorial/step3_adding_actions.md b/docs/tutorial/step3_adding_actions.md index 5b74c5d35..236da231e 100644 --- a/docs/tutorial/step3_adding_actions.md +++ b/docs/tutorial/step3_adding_actions.md @@ -18,9 +18,9 @@ validates the input conforms to the grammar. In most real world use cases the pa result/data structure/value. This can be accomplished using two features of the Parsing DSL: -* [CONSUME](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#consume1) will return - The [Token](http://sap.github.io/chevrotain/documentation/0_5_18/classes/token.html) instance consumed. -* [SUBRULE](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#subrule1) will return +* [CONSUME](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#consume1) will return + The [Token](http://sap.github.io/chevrotain/documentation/0_5_19/classes/token.html) instance consumed. +* [SUBRULE](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#subrule1) will return the result on invoking the rule. diff --git a/docs/tutorial/step4_fault_tolerance.md b/docs/tutorial/step4_fault_tolerance.md index a1c116e3e..dc87dda4b 100644 --- a/docs/tutorial/step4_fault_tolerance.md +++ b/docs/tutorial/step4_fault_tolerance.md @@ -47,9 +47,9 @@ Therefore the missing colon will be automatically "inserted". This heuristic's behavior can be customized by the following methods: -* [canTokenTypeBeInsertedInRecovery](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#cantokentypebeinsertedinrecovery) +* [canTokenTypeBeInsertedInRecovery](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#cantokentypebeinsertedinrecovery) -* [getTokenToInsert](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#gettokentoinsert) +* [getTokenToInsert](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#gettokentoinsert) ### In Rule Single Token deletion: @@ -204,14 +204,14 @@ from the sub-rule we have recovered from. By default **undefined** will be returned from a recovered rule, however this should most likely be customize in any but the most simple cases. -Customization is done during the definition of the grammar [RULE](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#rule). +Customization is done during the definition of the grammar [RULE](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#rule). The third parameter(**invalidRet**) is a function which will be invoked to produce the returned value in case of re-sync recovery. ####Disabling Re-Sync Recovery: Re-Sync recovery is enabled by default for all rules. In some cases it may be appropriate to disable re-sync recovery for a specific rule. -This is (once again) done during the definition of the grammar [RULE](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#rule). +This is (once again) done during the definition of the grammar [RULE](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#rule). The fourth argument is a boolean which can be controls whether or not re-sync is enabled for the defined rule. @@ -224,7 +224,7 @@ additional definitions (what should be returned value of a re-synced rule?). ### Disabling All Recovery mechanisms By default fault tolerance and error recovery heuristics are enabled. They can be disabled by passing a optional **isErrorRecoveryEnabled** parameter (default true) -To the parser's constructor [constructor](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#constructor). +To the parser's constructor [constructor](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#constructor). #### What is Next? diff --git a/package.json b/package.json index 6367355de..6e2b28f4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chevrotain", - "version": "0.5.18", + "version": "0.5.19", "description": "Chevrotain is a high performance fault tolerant javascript parsing DSL for building recursive decent parsers", "keywords": [ "parser", diff --git a/readme.md b/readme.md index 50e29e957..2643a7fa6 100644 --- a/readme.md +++ b/readme.md @@ -58,7 +58,7 @@ any code generation phase. ## Documentation * [Latest released version's HTML docs](http://sap.github.io/chevrotain/documentation) - * [Parsing DSL](http://sap.github.io/chevrotain/documentation/0_5_18/classes/parser.html#at_least_one) + * [Parsing DSL](http://sap.github.io/chevrotain/documentation/0_5_19/classes/parser.html#at_least_one) * Annotated source code (dev version): * [tokens_public.ts](https://github.com/SAP/chevrotain/blob/master/src/scan/tokens_public.ts) diff --git a/release/chevrotain.d.ts b/release/chevrotain.d.ts index f94a89b2d..9f3afc3e2 100644 --- a/release/chevrotain.d.ts +++ b/release/chevrotain.d.ts @@ -1,4 +1,4 @@ -/*! chevrotain - v0.5.18 - 2016-02-26 */ +/*! chevrotain - v0.5.19 - 2016-03-07 */ declare namespace chevrotain { class HashTable{} export function tokenName(clazz: Function): string; @@ -680,7 +680,19 @@ declare namespace chevrotain { protected RULE(ruleName: string, impl: (...implArgs: any[]) => T, invalidRet?: () => T, doReSync?: boolean): (idxInCallingRule?: number, ...args: any[]) => T; protected ruleInvocationStateUpdate(ruleName: string, idxInCallingRule: number): void; protected ruleFinallyStateUpdate(): void; + /** + * Returns an "imaginary" Token to insert when Single Token Insertion is done + * Override this if you require special behavior in your grammar + * for example if an IntegerToken is required provide one with the image '0' so it would be valid syntactically + */ protected getTokenToInsert(tokClass: Function): Token; + /** + * By default all tokens type may be inserted. This behavior may be overridden in inheriting Recognizers + * for example: One may decide that only punctuation tokens may be inserted automatically as they have no additional + * semantic value. (A mandatory semicolon has no additional semantic meaning, but an Integer may have additional meaning + * depending on its int value and context (Inserting an integer 0 in cardinality: "[1..]" will cause semantic issues + * as the max of the cardinality will be greater than the min value. (and this is a false error!) + */ protected canTokenTypeBeInsertedInRecovery(tokClass: Function): boolean; /** * @param tokClass The Type of Token we wish to consume (Reference to its constructor function) diff --git a/release/chevrotain.js b/release/chevrotain.js index 01a6aeed3..67dad8771 100644 --- a/release/chevrotain.js +++ b/release/chevrotain.js @@ -1,4 +1,4 @@ -/*! chevrotain - v0.5.18 - 2016-02-26 */ +/*! chevrotain - v0.5.19 - 2016-03-07 */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') @@ -56,6 +56,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 0 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var parser_public_1 = __webpack_require__(1); var lexer_public_1 = __webpack_require__(11); var tokens_public_1 = __webpack_require__(10); @@ -68,7 +69,7 @@ return /******/ (function(modules) { // webpackBootstrap */ var API = {}; // semantic version - API.VERSION = "0.5.18"; + API.VERSION = "0.5.19"; // runtime API API.Parser = parser_public_1.Parser; API.Lexer = lexer_public_1.Lexer; @@ -107,6 +108,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 1 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var cache = __webpack_require__(2); var exceptions_public_1 = __webpack_require__(5); var lang_extensions_1 = __webpack_require__(3); @@ -945,7 +947,7 @@ return /******/ (function(modules) { // webpackBootstrap this.SAVE_ERROR(new exceptions_public_1.exceptions.NotAllInputParsedException("Redundant input, expecting EOF but found: " + firstRedundantTok.image, firstRedundantTok)); } }; - /* + /** * Returns an "imaginary" Token to insert when Single Token Insertion is done * Override this if you require special behavior in your grammar * for example if an IntegerToken is required provide one with the image '0' so it would be valid syntactically @@ -953,7 +955,7 @@ return /******/ (function(modules) { // webpackBootstrap Parser.prototype.getTokenToInsert = function (tokClass) { return new tokClass(-1, -1); }; - /* + /** * By default all tokens type may be inserted. This behavior may be overridden in inheriting Recognizers * for example: One may decide that only punctuation tokens may be inserted automatically as they have no additional * semantic value. (A mandatory semicolon has no additional semantic meaning, but an Integer may have additional meaning @@ -965,21 +967,30 @@ return /******/ (function(modules) { // webpackBootstrap }; Parser.prototype.defaultInvalidReturn = function () { return undefined; }; Parser.prototype.tryInRepetitionRecovery = function (grammarRule, grammarRuleArgs, lookAheadFunc, expectedTokType) { + var _this = this; // TODO: can the resyncTokenType be cached? var reSyncTokType = this.findReSyncTokenType(); var orgInputIdx = this.inputIdx; var nextTokenWithoutResync = this.NEXT_TOKEN(); var currToken = this.NEXT_TOKEN(); var passedResyncPoint = false; + var generateErrorMessage = function () { + // we are preemptively re-syncing before an error has been detected, therefor we must reproduce + // the error that would have been thrown + var expectedTokName = tokens_public_1.tokenName(expectedTokType); + var msg = "Expecting token of type -->" + expectedTokName + + "<-- but found -->'" + nextTokenWithoutResync.image + "'<--"; + _this.SAVE_ERROR(new exceptions_public_1.exceptions.MismatchedTokenException(msg, nextTokenWithoutResync)); + }; while (!passedResyncPoint) { + // re-synced to a point where we can safely exit the repetition/ + if (currToken instanceof expectedTokType) { + generateErrorMessage(); + return; // must return here to avoid reverting the inputIdx + } // we skipped enough tokens so we can resync right back into another iteration of the repetition grammar rule if (lookAheadFunc.call(this)) { - // we are preemptively re-syncing before an error has been detected, therefor we must reproduce - // the error that would have been thrown - var expectedTokName = tokens_public_1.tokenName(expectedTokType); - var msg = "Expecting token of type -->" + expectedTokName + - "<-- but found -->'" + nextTokenWithoutResync.image + "'<--"; - this.SAVE_ERROR(new exceptions_public_1.exceptions.MismatchedTokenException(msg, nextTokenWithoutResync)); + generateErrorMessage(); // recursive invocation in other to support multiple re-syncs in the same top level repetition grammar rule grammarRule.apply(this, grammarRuleArgs); return; // must return here to avoid reverting the inputIdx @@ -1429,7 +1440,7 @@ return /******/ (function(modules) { // webpackBootstrap // needing to display the parser definition errors in some GUI(online playground). Parser.DEFER_DEFINITION_ERRORS_HANDLING = false; return Parser; - })(); + }()); exports.Parser = Parser; function InRuleRecoveryException(message) { this.name = lang_extensions_1.functionName(InRuleRecoveryException); @@ -1445,6 +1456,7 @@ return /******/ (function(modules) { // webpackBootstrap /** * module used to cache static information about parsers, */ + "use strict"; var lang_extensions_1 = __webpack_require__(3); var utils_1 = __webpack_require__(4); exports.CLASS_TO_DEFINITION_ERRORS = new lang_extensions_1.HashTable(); @@ -1521,6 +1533,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 3 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var utils = __webpack_require__(4); var nameRegex = /^\s*function\s*(\S*)\s*\(/; /* istanbul ignore next */ @@ -1580,7 +1593,7 @@ return /******/ (function(modules) { // webpackBootstrap this._state = {}; }; return HashTable; - })(); + }()); exports.HashTable = HashTable; @@ -1588,6 +1601,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 4 */ /***/ function(module, exports) { + "use strict"; /* Utils using lodash style API. (not necessarily 100% compliant) for functional and other utils. These utils should replace usage of lodash in the production code base. not because they are any better... @@ -1882,6 +1896,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 5 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var lang_extensions_1 = __webpack_require__(3); var utils_1 = __webpack_require__(4); var exceptions; @@ -1934,6 +1949,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 6 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) /* istanbul ignore next */ if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -1978,7 +1994,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return GastRefResolverVisitor; - })(gast_public_1.gast.GAstVisitor); + }(gast_public_1.gast.GAstVisitor)); exports.GastRefResolverVisitor = GastRefResolverVisitor; @@ -1986,6 +2002,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 7 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) /* istanbul ignore next */ if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -2006,7 +2023,7 @@ return /******/ (function(modules) { // webpackBootstrap }); }; return AbstractProduction; - })(); + }()); gast.AbstractProduction = AbstractProduction; var NonTerminal = (function (_super) { __extends(NonTerminal, _super); @@ -2036,7 +2053,7 @@ return /******/ (function(modules) { // webpackBootstrap // don't visit children of a reference, we will get cyclic infinite loops if we do so }; return NonTerminal; - })(AbstractProduction); + }(AbstractProduction)); gast.NonTerminal = NonTerminal; var Rule = (function (_super) { __extends(Rule, _super); @@ -2047,7 +2064,7 @@ return /******/ (function(modules) { // webpackBootstrap this.orgText = orgText; } return Rule; - })(AbstractProduction); + }(AbstractProduction)); gast.Rule = Rule; var Flat = (function (_super) { __extends(Flat, _super); @@ -2055,7 +2072,7 @@ return /******/ (function(modules) { // webpackBootstrap _super.call(this, definition); } return Flat; - })(AbstractProduction); + }(AbstractProduction)); gast.Flat = Flat; var Option = (function (_super) { __extends(Option, _super); @@ -2065,7 +2082,7 @@ return /******/ (function(modules) { // webpackBootstrap this.occurrenceInParent = occurrenceInParent; } return Option; - })(AbstractProduction); + }(AbstractProduction)); gast.Option = Option; var RepetitionMandatory = (function (_super) { __extends(RepetitionMandatory, _super); @@ -2075,7 +2092,7 @@ return /******/ (function(modules) { // webpackBootstrap this.occurrenceInParent = occurrenceInParent; } return RepetitionMandatory; - })(AbstractProduction); + }(AbstractProduction)); gast.RepetitionMandatory = RepetitionMandatory; var RepetitionMandatoryWithSeparator = (function (_super) { __extends(RepetitionMandatoryWithSeparator, _super); @@ -2086,7 +2103,7 @@ return /******/ (function(modules) { // webpackBootstrap this.occurrenceInParent = occurrenceInParent; } return RepetitionMandatoryWithSeparator; - })(AbstractProduction); + }(AbstractProduction)); gast.RepetitionMandatoryWithSeparator = RepetitionMandatoryWithSeparator; var Repetition = (function (_super) { __extends(Repetition, _super); @@ -2096,7 +2113,7 @@ return /******/ (function(modules) { // webpackBootstrap this.occurrenceInParent = occurrenceInParent; } return Repetition; - })(AbstractProduction); + }(AbstractProduction)); gast.Repetition = Repetition; var RepetitionWithSeparator = (function (_super) { __extends(RepetitionWithSeparator, _super); @@ -2107,7 +2124,7 @@ return /******/ (function(modules) { // webpackBootstrap this.occurrenceInParent = occurrenceInParent; } return RepetitionWithSeparator; - })(AbstractProduction); + }(AbstractProduction)); gast.RepetitionWithSeparator = RepetitionWithSeparator; var Alternation = (function (_super) { __extends(Alternation, _super); @@ -2117,7 +2134,7 @@ return /******/ (function(modules) { // webpackBootstrap this.occurrenceInParent = occurrenceInParent; } return Alternation; - })(AbstractProduction); + }(AbstractProduction)); gast.Alternation = Alternation; var Terminal = (function () { function Terminal(terminalType, occurrenceInParent) { @@ -2130,7 +2147,7 @@ return /******/ (function(modules) { // webpackBootstrap visitor.visit(this); }; return Terminal; - })(); + }()); gast.Terminal = Terminal; var GAstVisitor = (function () { function GAstVisitor() { @@ -2175,7 +2192,7 @@ return /******/ (function(modules) { // webpackBootstrap GAstVisitor.prototype.visitAlternation = function (node) { }; GAstVisitor.prototype.visitTerminal = function (node) { }; return GAstVisitor; - })(); + }()); gast.GAstVisitor = GAstVisitor; })(gast = exports.gast || (exports.gast = {})); @@ -2184,6 +2201,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 8 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) /* istanbul ignore next */ if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -2286,7 +2304,7 @@ return /******/ (function(modules) { // webpackBootstrap this.allProductions.push(terminal); }; return OccurrenceValidationCollector; - })(gast_public_1.gast.GAstVisitor); + }(gast_public_1.gast.GAstVisitor)); exports.OccurrenceValidationCollector = OccurrenceValidationCollector; var ruleNamePattern = /^[a-zA-Z_]\w*$/; function validateRuleName(ruleName, definedRulesNames, className) { @@ -2398,7 +2416,7 @@ return /******/ (function(modules) { // webpackBootstrap this.alternations.push(node); }; return OrCollector; - })(gast_public_1.gast.GAstVisitor); + }(gast_public_1.gast.GAstVisitor)); function validateEmptyOrAlternative(topLevelRule) { var orCollector = new OrCollector(); topLevelRule.accept(orCollector); @@ -2432,6 +2450,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 9 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var gast_public_1 = __webpack_require__(7); var utils_1 = __webpack_require__(4); var lang_extensions_1 = __webpack_require__(3); @@ -2505,6 +2524,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 10 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) /* istanbul ignore next */ if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -2590,7 +2610,7 @@ return /******/ (function(modules) { // webpackBootstrap this.isInsertedInRecovery = false; } return Token; - })(); + }()); exports.Token = Token; /** * a special kind of Token which does not really exist in the input @@ -2603,7 +2623,7 @@ return /******/ (function(modules) { // webpackBootstrap _super.call(this, "", -1, -1, -1, -1, -1); } return VirtualToken; - })(Token); + }(Token)); exports.VirtualToken = VirtualToken; var EOF = (function (_super) { __extends(EOF, _super); @@ -2611,7 +2631,7 @@ return /******/ (function(modules) { // webpackBootstrap _super.apply(this, arguments); } return EOF; - })(VirtualToken); + }(VirtualToken)); exports.EOF = EOF; @@ -2619,6 +2639,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 11 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var lexer_1 = __webpack_require__(12); var utils_1 = __webpack_require__(4); (function (LexerDefinitionErrorType) { @@ -2840,7 +2861,7 @@ return /******/ (function(modules) { // webpackBootstrap }; Lexer.NA = /NOT_APPLICABLE/; return Lexer; - })(); + }()); exports.Lexer = Lexer; @@ -2848,6 +2869,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 12 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var tokens_public_1 = __webpack_require__(10); var lexer_public_1 = __webpack_require__(11); var utils_1 = __webpack_require__(4); @@ -3072,6 +3094,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 13 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var gast_public_1 = __webpack_require__(7); var gast_1 = __webpack_require__(9); var utils_1 = __webpack_require__(4); @@ -3137,6 +3160,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 14 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) /* istanbul ignore next */ if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -3173,7 +3197,7 @@ return /******/ (function(modules) { // webpackBootstrap this.follows.put(followName, t_in_topProd_follows); }; return ResyncFollowsWalker; - })(rest_1.RestWalker); + }(rest_1.RestWalker)); exports.ResyncFollowsWalker = ResyncFollowsWalker; function computeAllProdsFollows(topProductions) { var reSyncFollows = new lang_extensions_1.HashTable(); @@ -3199,6 +3223,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 15 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var gast_public_1 = __webpack_require__(7); var utils_1 = __webpack_require__(4); /** @@ -3290,7 +3315,7 @@ return /******/ (function(modules) { // webpackBootstrap }); }; return RestWalker; - })(); + }()); exports.RestWalker = RestWalker; function restForRepetitionWithSeparator(repSepProd, currRest, prevRest) { var repSepRest = [new gast_public_1.gast.Option([new gast_public_1.gast.Terminal(repSepProd.separator)].concat(repSepProd.definition))]; @@ -3303,6 +3328,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 16 */ /***/ function(module, exports) { + "use strict"; // TODO: can this be removed? where is it used? exports.IN = "_~IN~_"; @@ -3311,6 +3337,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 17 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var gast_public_1 = __webpack_require__(7); var first_1 = __webpack_require__(13); var interpreter_1 = __webpack_require__(18); @@ -3350,14 +3377,14 @@ return /******/ (function(modules) { // webpackBootstrap } var hasLastAnEmptyAlt = utils_1.isEmpty(utils_1.last(alternativesTokens)); if (hasLastAnEmptyAlt) { - var lastIdx = alternativesTokens.length - 1; + var lastIdx_1 = alternativesTokens.length - 1; /** * This will return the Index of the alternative to take or the if only the empty alternative matched */ return function chooseAlternativeWithEmptyAlt() { var nextToken = this.NEXT_TOKEN(); // checking only until length - 1 because there is nothing to check in an empty alternative, it is always valid - for (var i = 0; i < lastIdx; i++) { + for (var i = 0; i < lastIdx_1; i++) { var currAltTokens = alternativesTokens[i]; // 'for' loop for performance reasons. for (var j = 0; j < currAltTokens.length; j++) { @@ -3367,7 +3394,7 @@ return /******/ (function(modules) { // webpackBootstrap } } // an OR(alternation) with an empty alternative will always match - return lastIdx; + return lastIdx_1; }; } else { @@ -3455,6 +3482,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 18 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) /* istanbul ignore next */ if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } @@ -3525,7 +3553,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return AbstractNextPossibleTokensWalker; - })(rest_1.RestWalker); + }(rest_1.RestWalker)); exports.AbstractNextPossibleTokensWalker = AbstractNextPossibleTokensWalker; var NextAfterTokenWalker = (function (_super) { __extends(NextAfterTokenWalker, _super); @@ -3547,7 +3575,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextAfterTokenWalker; - })(AbstractNextPossibleTokensWalker); + }(AbstractNextPossibleTokensWalker)); exports.NextAfterTokenWalker = NextAfterTokenWalker; var NextInsideOptionWalker = (function (_super) { __extends(NextInsideOptionWalker, _super); @@ -3568,7 +3596,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextInsideOptionWalker; - })(AbstractNextPossibleTokensWalker); + }(AbstractNextPossibleTokensWalker)); exports.NextInsideOptionWalker = NextInsideOptionWalker; var NextInsideManyWalker = (function (_super) { __extends(NextInsideManyWalker, _super); @@ -3589,7 +3617,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextInsideManyWalker; - })(AbstractNextPossibleTokensWalker); + }(AbstractNextPossibleTokensWalker)); exports.NextInsideManyWalker = NextInsideManyWalker; var NextInsideManySepWalker = (function (_super) { __extends(NextInsideManySepWalker, _super); @@ -3610,7 +3638,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextInsideManySepWalker; - })(AbstractNextPossibleTokensWalker); + }(AbstractNextPossibleTokensWalker)); exports.NextInsideManySepWalker = NextInsideManySepWalker; var NextInsideAtLeastOneWalker = (function (_super) { __extends(NextInsideAtLeastOneWalker, _super); @@ -3631,7 +3659,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextInsideAtLeastOneWalker; - })(AbstractNextPossibleTokensWalker); + }(AbstractNextPossibleTokensWalker)); exports.NextInsideAtLeastOneWalker = NextInsideAtLeastOneWalker; var NextInsideAtLeastOneSepWalker = (function (_super) { __extends(NextInsideAtLeastOneSepWalker, _super); @@ -3652,7 +3680,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextInsideAtLeastOneSepWalker; - })(AbstractNextPossibleTokensWalker); + }(AbstractNextPossibleTokensWalker)); exports.NextInsideAtLeastOneSepWalker = NextInsideAtLeastOneSepWalker; var NextInsideOrWalker = (function (_super) { __extends(NextInsideOrWalker, _super); @@ -3678,7 +3706,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextInsideOrWalker; - })(rest_1.RestWalker); + }(rest_1.RestWalker)); exports.NextInsideOrWalker = NextInsideOrWalker; /** * This walker only "walks" a single "TOP" level in the Grammar Ast, this means @@ -3697,7 +3725,7 @@ return /******/ (function(modules) { // webpackBootstrap return this.result; }; return AbstractNextTerminalAfterProductionWalker; - })(rest_1.RestWalker); + }(rest_1.RestWalker)); exports.AbstractNextTerminalAfterProductionWalker = AbstractNextTerminalAfterProductionWalker; var NextTerminalAfterManyWalker = (function (_super) { __extends(NextTerminalAfterManyWalker, _super); @@ -3718,7 +3746,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextTerminalAfterManyWalker; - })(AbstractNextTerminalAfterProductionWalker); + }(AbstractNextTerminalAfterProductionWalker)); exports.NextTerminalAfterManyWalker = NextTerminalAfterManyWalker; var NextTerminalAfterManySepWalker = (function (_super) { __extends(NextTerminalAfterManySepWalker, _super); @@ -3739,7 +3767,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextTerminalAfterManySepWalker; - })(AbstractNextTerminalAfterProductionWalker); + }(AbstractNextTerminalAfterProductionWalker)); exports.NextTerminalAfterManySepWalker = NextTerminalAfterManySepWalker; var NextTerminalAfterAtLeastOneWalker = (function (_super) { __extends(NextTerminalAfterAtLeastOneWalker, _super); @@ -3760,7 +3788,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextTerminalAfterAtLeastOneWalker; - })(AbstractNextTerminalAfterProductionWalker); + }(AbstractNextTerminalAfterProductionWalker)); exports.NextTerminalAfterAtLeastOneWalker = NextTerminalAfterAtLeastOneWalker; // TODO: reduce code duplication in the AfterWalkers var NextTerminalAfterAtLeastOneSepWalker = (function (_super) { @@ -3782,7 +3810,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; return NextTerminalAfterAtLeastOneSepWalker; - })(AbstractNextTerminalAfterProductionWalker); + }(AbstractNextTerminalAfterProductionWalker)); exports.NextTerminalAfterAtLeastOneSepWalker = NextTerminalAfterAtLeastOneSepWalker; @@ -3790,6 +3818,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 19 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var range_1 = __webpack_require__(20); var gast_public_1 = __webpack_require__(7); var utils_1 = __webpack_require__(4); @@ -4095,6 +4124,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 20 */ /***/ function(module, exports) { + "use strict"; var Range = (function () { function Range(start, end) { this.start = start; @@ -4119,7 +4149,7 @@ return /******/ (function(modules) { // webpackBootstrap return other.strictlyContainsRange(this); }; return Range; - })(); + }()); exports.Range = Range; function isValidRange(start, end) { return !(start < 0 || end < start); @@ -4131,6 +4161,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 21 */ /***/ function(module, exports, __webpack_require__) { + "use strict"; var cache_1 = __webpack_require__(2); /** * Clears the chevrotain internal cache. diff --git a/release/chevrotain.min.js b/release/chevrotain.min.js index 319ce09c9..d487c19a0 100644 --- a/release/chevrotain.min.js +++ b/release/chevrotain.min.js @@ -1,4 +1,4 @@ -/*! chevrotain - v0.5.18 - 2016-02-26 */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("chevrotain",[],e):"object"==typeof exports?exports.chevrotain=e():t.chevrotain=e()}(this,function(){return function(t){function __webpack_require__(n){if(e[n])return e[n].exports;var r=e[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,__webpack_require__),r.loaded=!0,r.exports}var e={};return __webpack_require__.m=t,__webpack_require__.c=e,__webpack_require__.p="",__webpack_require__(0)}([function(t,e,n){var r=n(1),i=n(11),o=n(10),a=n(5),s=n(7),c=n(21),u={};u.VERSION="0.5.18",u.Parser=r.Parser,u.Lexer=i.Lexer,u.Token=o.Token,u.VirtualToken=o.VirtualToken,u.EOF=o.EOF,u.extendToken=o.extendToken,u.tokenName=o.tokenName,u.EMPTY_ALT=r.EMPTY_ALT,u.exceptions={},u.exceptions.isRecognitionException=a.exceptions.isRecognitionException,u.exceptions.EarlyExitException=a.exceptions.EarlyExitException,u.exceptions.MismatchedTokenException=a.exceptions.MismatchedTokenException,u.exceptions.NotAllInputParsedException=a.exceptions.NotAllInputParsedException,u.exceptions.NoViableAltException=a.exceptions.NoViableAltException,u.gast={},u.gast.GAstVisitor=s.gast.GAstVisitor,u.gast.Flat=s.gast.Flat,u.gast.Repetition=s.gast.Repetition,u.gast.RepetitionWithSeparator=s.gast.RepetitionWithSeparator,u.gast.RepetitionMandatory=s.gast.RepetitionMandatory,u.gast.RepetitionMandatoryWithSeparator=s.gast.RepetitionMandatoryWithSeparator,u.gast.Option=s.gast.Option,u.gast.Alternation=s.gast.Alternation,u.gast.NonTerminal=s.gast.NonTerminal,u.gast.Terminal=s.gast.Terminal,u.gast.Rule=s.gast.Rule,u.clearCache=c.clearCache,t.exports=u},function(t,e,n){function EMPTY_ALT(t){return void 0===t&&(t=void 0),function(){return t}}function InRuleRecoveryException(t){this.name=o.functionName(InRuleRecoveryException),this.message=t}var r=n(2),i=n(5),o=n(3),a=n(6),s=n(8),c=n(4),u=n(14),l=n(10),p=n(17),f=n(19),h=n(18),d=n(16);!function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.DUPLICATE_PRODUCTIONS=2]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=3]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=4]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=5]="NONE_LAST_EMPTY_ALT"}(e.ParserDefinitionErrorType||(e.ParserDefinitionErrorType={}));e.ParserDefinitionErrorType;e.EMPTY_ALT=EMPTY_ALT;var E={},A=function(){function Parser(t,e,n){if(void 0===n&&(n=!0),this.errors=[],this._input=[],this.inputIdx=-1,this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.tokensMap=void 0,this.definedRulesNames=[],this._input=t,this.isErrorRecoveryEnabled=n,this.className=o.classNameFromInstance(this),this.firstAfterRepMap=r.getFirstAfterRepForClass(this.className),this.classLAFuncs=r.getLookaheadFuncsForClass(this.className),r.CLASS_TO_DEFINITION_ERRORS.containsKey(this.className)?this.definitionErrors=r.CLASS_TO_DEFINITION_ERRORS.get(this.className):(this.definitionErrors=[],r.CLASS_TO_DEFINITION_ERRORS.put(this.className,this.definitionErrors)),c.isArray(e))this.tokensMap=c.reduce(e,function(t,e){return t[l.tokenName(e)]=e,t},{});else{if(!c.isObject(e))throw new Error("'tokensMapOrArr' argument must be An Array of Token constructors or a Dictionary of Tokens.");this.tokensMap=c.cloneObj(e)}this.tokensMap[l.tokenName(l.EOF)]=l.EOF,void 0===r.CLASS_TO_OR_LA_CACHE[this.className]&&r.initLookAheadKeyCache(this.className),this.orLookaheadKeys=r.CLASS_TO_OR_LA_CACHE[this.className],this.manyLookaheadKeys=r.CLASS_TO_MANY_LA_CACHE[this.className],this.manySepLookaheadKeys=r.CLASS_TO_MANY_SEP_LA_CACHE[this.className],this.atLeastOneLookaheadKeys=r.CLASS_TO_AT_LEAST_ONE_LA_CACHE[this.className],this.atLeastOneSepLookaheadKeys=r.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[this.className],this.optionLookaheadKeys=r.CLASS_TO_OPTION_LA_CACHE[this.className]}return Parser.performSelfAnalysis=function(t){var e,n=[],i=o.classNameFromInstance(t);if(""===i)throw Error("A Parser's constructor may not be an anonymous Function, it must be a named function\nThe constructor's name is used at runtime for performance (caching) purposes.");if(!r.CLASS_TO_SELF_ANALYSIS_DONE.containsKey(i)){var l=r.getProductionsForClass(i);n=r.CLASS_TO_DEFINITION_ERRORS.get(i);var p=a.resolveGrammar(l);n.push.apply(n,p),r.CLASS_TO_SELF_ANALYSIS_DONE.put(i,!0);var f=s.validateGrammar(l.values());if(n.push.apply(n,f),!c.isEmpty(n)&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw e=c.map(n,function(t){return t.message}),new Error("Parser Definition Errors detected\n: "+e.join("\n-------------------------------\n"));if(c.isEmpty(n)){var h=u.computeAllProdsFollows(l.values());r.setResyncFollowsForClass(i,h)}}if(!c.isEmpty(r.CLASS_TO_DEFINITION_ERRORS.get(i))&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw e=c.map(r.CLASS_TO_DEFINITION_ERRORS.get(i),function(t){return t.message}),new Error("Parser Definition Errors detected\n: "+e.join("\n-------------------------------\n"))},Object.defineProperty(Parser.prototype,"input",{get:function(){return c.cloneArr(this._input)},set:function(t){this.reset(),this._input=t},enumerable:!0,configurable:!0}),Parser.prototype.reset=function(){this.isBackTrackingStack=[],this.errors=[],this._input=[],this.inputIdx=-1,this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[]},Parser.prototype.isAtEndOfInput=function(){return this.LA(1)instanceof l.EOF},Parser.prototype.getGAstProductions=function(){return r.getProductionsForClass(this.className)},Parser.prototype.isBackTracking=function(){return!c.isEmpty(this.isBackTrackingStack)},Parser.prototype.SAVE_ERROR=function(t){if(i.exceptions.isRecognitionException(t))return this.errors.push(t),t;throw Error("trying to save an Error which is not a RecognitionException")},Parser.prototype.NEXT_TOKEN=function(){return this.LA(1)},Parser.prototype.LA=function(t){return this._input.length<=this.inputIdx+t?new l.EOF:this._input[this.inputIdx+t]},Parser.prototype.isNextRule=function(t){var e=r.getLookaheadFuncsForClass(this.className),n=e.get(t);if(void 0===n){var i=this.getGAstProductions().get(t);n=p.buildLookaheadForTopLevel(i),e.put(t,n)}return n.call(this)},Parser.prototype.BACKTRACK=function(t,e){var n=this;return function(){n.isBackTrackingStack.push(1);var r=n.saveRecogState();try{var o=t.call(n);return e(o)}catch(a){if(i.exceptions.isRecognitionException(a))return!1;throw a}finally{n.reloadRecogState(r),n.isBackTrackingStack.pop()}}},Parser.prototype.SKIP_TOKEN=function(){return this.inputIdx<=this._input.length-2?(this.inputIdx++,this.NEXT_TOKEN()):new l.EOF},Parser.prototype.CONSUME=function(t){return this.CONSUME1(t)},Parser.prototype.CONSUME1=function(t){return this.consumeInternal(t,1)},Parser.prototype.CONSUME2=function(t){return this.consumeInternal(t,2)},Parser.prototype.CONSUME3=function(t){return this.consumeInternal(t,3)},Parser.prototype.CONSUME4=function(t){return this.consumeInternal(t,4)},Parser.prototype.CONSUME5=function(t){return this.consumeInternal(t,5)},Parser.prototype.SUBRULE=function(t,e){return void 0===e&&(e=[]),this.SUBRULE1(t,e)},Parser.prototype.SUBRULE1=function(t,e){return void 0===e&&(e=[]),t.call(this,1,e)},Parser.prototype.SUBRULE2=function(t,e){return void 0===e&&(e=[]),t.call(this,2,e)},Parser.prototype.SUBRULE3=function(t,e){return void 0===e&&(e=[]),t.call(this,3,e)},Parser.prototype.SUBRULE4=function(t,e){return void 0===e&&(e=[]),t.call(this,4,e)},Parser.prototype.SUBRULE5=function(t,e){return void 0===e&&(e=[]),t.call(this,5,e)},Parser.prototype.OPTION=function(t,e){return this.OPTION1.call(this,t,e)},Parser.prototype.OPTION1=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(1)),this.optionInternal(t,e)},Parser.prototype.OPTION2=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(2)),this.optionInternal(t,e)},Parser.prototype.OPTION3=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(3)),this.optionInternal(t,e)},Parser.prototype.OPTION4=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(4)),this.optionInternal(t,e)},Parser.prototype.OPTION5=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(5)),this.optionInternal(t,e)},Parser.prototype.OR=function(t,e,n){return void 0===n&&(n=!1),this.OR1(t,e,n)},Parser.prototype.OR1=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,1,n)},Parser.prototype.OR2=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,2,n)},Parser.prototype.OR3=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,3,n)},Parser.prototype.OR4=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,4,n)},Parser.prototype.OR5=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,5,n)},Parser.prototype.MANY=function(t,e){return this.MANY1.call(this,t,e)},Parser.prototype.MANY1=function(t,e){this.manyInternal(this.MANY1,"MANY1",1,t,e)},Parser.prototype.MANY2=function(t,e){this.manyInternal(this.MANY2,"MANY2",2,t,e)},Parser.prototype.MANY3=function(t,e){this.manyInternal(this.MANY3,"MANY3",3,t,e)},Parser.prototype.MANY4=function(t,e){this.manyInternal(this.MANY4,"MANY4",4,t,e)},Parser.prototype.MANY5=function(t,e){this.manyInternal(this.MANY5,"MANY5",5,t,e)},Parser.prototype.MANY_SEP=function(t,e,n){return this.MANY_SEP1.call(this,t,e,n)},Parser.prototype.MANY_SEP1=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP1,"MANY_SEP1",1,t,e,n)},Parser.prototype.MANY_SEP2=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP2,"MANY_SEP2",2,t,e,n)},Parser.prototype.MANY_SEP3=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP3,"MANY_SEP3",3,t,e,n)},Parser.prototype.MANY_SEP4=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP4,"MANY_SEP4",4,t,e,n)},Parser.prototype.MANY_SEP5=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP5,"MANY_SEP5",5,t,e,n)},Parser.prototype.AT_LEAST_ONE=function(t,e,n){return this.AT_LEAST_ONE1.call(this,t,e,n)},Parser.prototype.AT_LEAST_ONE1=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE1,"AT_LEAST_ONE1",1,t,e,n)},Parser.prototype.AT_LEAST_ONE2=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE2,"AT_LEAST_ONE2",2,t,e,n)},Parser.prototype.AT_LEAST_ONE3=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE3,"AT_LEAST_ONE3",3,t,e,n)},Parser.prototype.AT_LEAST_ONE4=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE4,"AT_LEAST_ONE4",4,t,e,n)},Parser.prototype.AT_LEAST_ONE5=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE5,"AT_LEAST_ONE5",5,t,e,n)},Parser.prototype.AT_LEAST_ONE_SEP=function(t,e,n,r){return this.AT_LEAST_ONE_SEP1.call(this,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP1=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP1",1,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP2=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP2",2,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP3=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP3",3,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP4=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP4",4,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP5=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP5",5,t,e,n,r)},Parser.prototype.RULE_NO_RESYNC=function(t,e,n){return this.RULE(t,e,n,!1)},Parser.prototype.RULE=function(t,e,n,o){void 0===n&&(n=this.defaultInvalidReturn),void 0===o&&(o=!0);var a=s.validateRuleName(t,this.definedRulesNames,this.className);this.definedRulesNames.push(t),this.definitionErrors.push.apply(this.definitionErrors,a);var c=r.getProductionsForClass(this.className);if(!c.containsKey(t)){var u=f.buildTopProduction(e.toString(),t,this.tokensMap);c.put(t,u)}var l=function(r,a){void 0===r&&(r=1),void 0===a&&(a=[]),this.ruleInvocationStateUpdate(t,r);try{return e.apply(this,a)}catch(s){var c=1===this.RULE_STACK.length,u=c||o&&!this.isBackTracking()&&this.isErrorRecoveryEnabled;if(u&&i.exceptions.isRecognitionException(s)){var l=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(l))return this.reSyncTo(l),n();throw s}throw s}finally{this.ruleFinallyStateUpdate()}},p="ruleName";return l[p]=t,l},Parser.prototype.ruleInvocationStateUpdate=function(t,e){this.RULE_OCCURRENCE_STACK.push(e),this.RULE_STACK.push(t)},Parser.prototype.ruleFinallyStateUpdate=function(){this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop();var t=this._input.length-1;if(0===this.RULE_STACK.length&&this.inputIdx"+p+"<-- but found -->'"+s.image+"'<--";return this.SAVE_ERROR(new i.exceptions.MismatchedTokenException(f,s)),void t.apply(this,e)}c instanceof o&&(u=!0),c=this.SKIP_TOKEN()}this.inputIdx=a},Parser.prototype.shouldInRepetitionRecoveryBeTried=function(t,e){return void 0===t||void 0===e?!1:this.NEXT_TOKEN()instanceof t?!1:this.isBackTracking()?!1:!this.canPerformInRuleRecovery(t,this.getFollowsForInRuleRecovery(t,e))},Parser.prototype.getFollowsForInRuleRecovery=function(t,e){var n=c.cloneArr(this.RULE_STACK),r=c.cloneArr(this.RULE_OCCURRENCE_STACK),i={ruleStack:n,occurrenceStack:r,lastTok:t,lastTokOccurrence:e},o=c.first(n),a=this.getGAstProductions(),s=a.get(o),u=new h.NextAfterTokenWalker(s,i).startWalking();return u},Parser.prototype.tryInRuleRecovery=function(t,e){if(this.canRecoverWithSingleTokenInsertion(t,e)){var n=this.getTokenToInsert(t);return n.isInsertedInRecovery=!0,n}if(this.canRecoverWithSingleTokenDeletion(t)){var r=this.SKIP_TOKEN();return this.inputIdx++,r}throw new InRuleRecoveryException("sad sad panda")},Parser.prototype.canPerformInRuleRecovery=function(t,e){return this.canRecoverWithSingleTokenInsertion(t,e)||this.canRecoverWithSingleTokenDeletion(t)},Parser.prototype.canRecoverWithSingleTokenInsertion=function(t,e){if(!this.canTokenTypeBeInsertedInRecovery(t))return!1;if(c.isEmpty(e))return!1;var n=this.NEXT_TOKEN(),r=void 0!==c.find(e,function(t){return n instanceof t});return r},Parser.prototype.canRecoverWithSingleTokenDeletion=function(t){var e=this.LA(2)instanceof t;return e},Parser.prototype.isInCurrentRuleReSyncSet=function(t){var e=this.getCurrFollowKey(),n=this.getFollowSetFromFollowKey(e);return c.contains(n,t)},Parser.prototype.findReSyncTokenType=function(){for(var t=this.flattenFollowSet(),e=this.NEXT_TOKEN(),n=2;;){var r=e.constructor;if(c.contains(t,r))return r;e=this.LA(n),n++}},Parser.prototype.getCurrFollowKey=function(){if(1===this.RULE_STACK.length)return E;var t=this.RULE_STACK.length-1,e=t,n=t-1;return{ruleName:this.RULE_STACK[t],idxInCallingRule:this.RULE_OCCURRENCE_STACK[e],inRule:this.RULE_STACK[n]}},Parser.prototype.buildFullFollowKeyStack=function(){var t=this;return c.map(this.RULE_STACK,function(e,n){return 0===n?E:{ruleName:e,idxInCallingRule:t.RULE_OCCURRENCE_STACK[n],inRule:t.RULE_STACK[n-1]}})},Parser.prototype.flattenFollowSet=function(){var t=this,e=c.map(this.buildFullFollowKeyStack(),function(e){return t.getFollowSetFromFollowKey(e)});return c.flatten(e)},Parser.prototype.getFollowSetFromFollowKey=function(t){if(t===E)return[l.EOF];var e=t.ruleName+t.idxInCallingRule+d.IN+t.inRule;return r.getResyncFollowsForClass(this.className).get(e)},Parser.prototype.reSyncTo=function(t){for(var e=this.NEXT_TOKEN();e instanceof t==!1;)e=this.SKIP_TOKEN()},Parser.prototype.attemptInRepetitionRecovery=function(t,e,n,r,i,o,a){var s=this.getKeyForAutomaticLookahead(r,a,i),u=this.firstAfterRepMap.get(s);if(void 0===u){var p=c.last(this.RULE_STACK),f=this.getGAstProductions().get(p),h=new o(f,i);u=h.startWalking(),this.firstAfterRepMap.put(s,u)}var d=u.token,E=u.occurrence,A=u.isEndOfRule;1===this.RULE_STACK.length&&A&&void 0===d&&(d=l.EOF,E=1),this.shouldInRepetitionRecoveryBeTried(d,E)&&this.tryInRepetitionRecovery(t,e,n,d)},Parser.prototype.optionInternal=function(t,e){return t.call(this)?(e.call(this),!0):!1},Parser.prototype.atLeastOneInternal=function(t,e,n,r,o,a){if(c.isString(o)&&(a=o,o=r,r=this.getLookaheadFuncForAtLeastOne(n)),!r.call(this))throw this.SAVE_ERROR(new i.exceptions.EarlyExitException("expecting at least one: "+a,this.NEXT_TOKEN()));for(o.call(this);r.call(this);)o.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(t,[r,o,a],r,e,n,h.NextTerminalAfterAtLeastOneWalker,this.atLeastOneLookaheadKeys)},Parser.prototype.atLeastOneSepFirstInternal=function(t,e,n,r,o,a,s){var u=this,l=[];if(c.isString(a)&&(s=a,a=o,o=this.getLookaheadFuncForAtLeastOneSep(n)),!o.call(this))throw this.SAVE_ERROR(new i.exceptions.EarlyExitException("expecting at least one: "+s,this.NEXT_TOKEN()));a.call(this);for(var p=function(){return u.NEXT_TOKEN()instanceof r};p();)l.push(this.CONSUME(r)),a.call(this);return this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,n,r,p,a,l,this.atLeastOneSepLookaheadKeys,h.NextTerminalAfterAtLeastOneSepWalker],p,e,n,h.NextTerminalAfterAtLeastOneSepWalker,this.atLeastOneSepLookaheadKeys),l},Parser.prototype.manyInternal=function(t,e,n,r,i){for(void 0===i&&(i=r,r=this.getLookaheadFuncForMany(n));r.call(this);)i.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(t,[r,i],r,e,n,h.NextTerminalAfterManyWalker,this.manyLookaheadKeys)},Parser.prototype.manySepFirstInternal=function(t,e,n,r,i,o){var a=this,s=[];if(void 0===o&&(o=i,i=this.getLookaheadFuncForManySep(n)),i.call(this)){o.call(this);for(var c=function(){return a.NEXT_TOKEN()instanceof r};c();)s.push(this.CONSUME(r)),o.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,n,r,c,o,s,this.manySepLookaheadKeys,h.NextTerminalAfterManySepWalker],c,e,n,h.NextTerminalAfterManySepWalker,this.manySepLookaheadKeys)}return s},Parser.prototype.repetitionSepSecondInternal=function(t,e,n,r,i,o,a,s){for(;r();)o.push(this.CONSUME(n)),i.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,e,n,r,i,o,a,s],r,t,e,s,a)},Parser.prototype.orInternal=function(t,e,n,r){if(void 0!==t[0].WHEN){for(var i=0;i"+n+"<-- but found -->'"+e.image+"'<--";throw this.SAVE_ERROR(new i.exceptions.MismatchedTokenException(r,e))},Parser.prototype.getKeyForAutomaticLookahead=function(t,e,n){var r=e[n-1],i=c.last(this.RULE_STACK),o=r[i];return void 0===o&&(o=t+n+d.IN+i,r[i]=o),o},Parser.prototype.getLookaheadFuncForOption=function(t){var e=this.getKeyForAutomaticLookahead("OPTION",this.optionLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForOption)},Parser.prototype.getLookaheadFuncForOr=function(t,e){var n=this.getKeyForAutomaticLookahead("OR",this.orLookaheadKeys,t);return this.getLookaheadFuncFor(n,t,p.buildLookaheadForOr,[e])},Parser.prototype.getLookaheadFuncForMany=function(t){var e=this.getKeyForAutomaticLookahead("MANY",this.manyLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForMany)},Parser.prototype.getLookaheadFuncForManySep=function(t){var e=this.getKeyForAutomaticLookahead("MANY_SEP",this.manySepLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForManySep)},Parser.prototype.getLookaheadFuncForAtLeastOne=function(t){var e=this.getKeyForAutomaticLookahead("AT_LEAST_ONE",this.atLeastOneLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForAtLeastOne)},Parser.prototype.getLookaheadFuncForAtLeastOneSep=function(t){var e=this.getKeyForAutomaticLookahead("AT_LEAST_ONE_SEP",this.atLeastOneSepLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForAtLeastOneSep)},Parser.prototype.getLookaheadFuncFor=function(t,e,n,r){void 0===r&&(r=[]);var i=c.last(this.RULE_STACK),o=this.classLAFuncs.get(t);if(void 0===o){var a=this.getGAstProductions().get(i);o=n.apply(null,[e,a].concat(r)),this.classLAFuncs.put(t,o)}return o},Parser.prototype.saveRecogState=function(){var t=c.cloneArr(this.errors),e=c.cloneArr(this.RULE_STACK);return{errors:t,inputIdx:this.inputIdx,RULE_STACK:e}},Parser.prototype.reloadRecogState=function(t){this.errors=t.errors,this.inputIdx=t.inputIdx,this.RULE_STACK=t.RULE_STACK},Parser.prototype.raiseNoAltException=function(t,e){var n=" but found: '"+this.NEXT_TOKEN().image+"'";if(void 0===e){var r=c.last(this.RULE_STACK),o=this.getGAstProductions().get(r),a=new h.NextInsideOrWalker(o,t).startWalking(),s=c.flatten(a),u=c.map(s,function(t){return l.tokenName(t)});e="one of: <"+u.join(" ,")+">"}throw this.SAVE_ERROR(new i.exceptions.NoViableAltException("expecting: "+e+" "+n,this.NEXT_TOKEN()))},Parser.IGNORE_AMBIGUITIES=!0,Parser.NO_RESYNC=!1,Parser.DEFER_DEFINITION_ERRORS_HANDLING=!1,Parser}();e.Parser=A,InRuleRecoveryException.prototype=Error.prototype},function(t,e,n){function getProductionsForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_GRAMMAR_PRODUCTIONS)}function getResyncFollowsForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_RESYNC_FOLLOW_SETS)}function setResyncFollowsForClass(t,n){e.CLASS_TO_RESYNC_FOLLOW_SETS.put(t,n)}function getLookaheadFuncsForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_LOOKAHEAD_FUNCS)}function getFirstAfterRepForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_FIRST_AFTER_REPETITION)}function initLookAheadKeyCache(t){e.CLASS_TO_OR_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_MANY_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_MANY_SEP_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_AT_LEAST_ONE_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_OPTION_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),initSingleLookAheadKeyCache(e.CLASS_TO_OR_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_MANY_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_MANY_SEP_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_AT_LEAST_ONE_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_OPTION_LA_CACHE[t])}function initSingleLookAheadKeyCache(t){for(var n=0;n1}),c=i.map(i.values(a),function(e){var n=i.first(e),r=createDuplicatesErrorMessage(e,t.name),a=s.getProductionDslName(n),c={message:r,type:o.ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:a,occurrence:n.occurrenceInParent},u=getExtraProductionArgument(n);return u&&(c.parameter=u),c});return c}function createDuplicatesErrorMessage(t,e){var n=i.first(t),r=n.occurrenceInParent,o=s.getProductionDslName(n),a=getExtraProductionArgument(n),c="->"+o+"<- with occurrence index: ->"+r+"<-\n "+(a?"and argument: "+a:"")+"\n appears more than once ("+t.length+" times) in the top level rule: "+e+".\n "+(1===r?"note that "+o+" and "+o+"1 both have the same occurrence index 1}":"")+"}\n to fix this make sure each usage of "+o+" "+(a?"with the argument: "+a:"")+"\n in the rule "+e+" has a different occurrence index (1-5), as that combination acts as a unique\n position key in the grammar, which is needed by the parsing engine.";return c=c.replace(/[ \t]+/g," "),c=c.replace(/\s\s+/g,"\n")}function identifyProductionForDuplicates(t){return s.getProductionDslName(t)+"_#_"+t.occurrenceInParent+"_#_"+getExtraProductionArgument(t)}function getExtraProductionArgument(t){return t instanceof a.gast.Terminal?c.tokenName(t.terminalType):t instanceof a.gast.NonTerminal?t.nonTerminalName:""}function validateRuleName(t,e,n){var r,a=[];return t.match(p)||(r="Invalid Grammar rule name --> "+t+" it must match the pattern: "+p.toString(),a.push({message:r,type:o.ParserDefinitionErrorType.INVALID_RULE_NAME,ruleName:t})),i.contains(e,t)&&(r="Duplicate definition, rule: "+t+" is already defined in the grammar: "+n,a.push({message:r,type:o.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:t})),a}function validateNoLeftRecursion(t,e,n){void 0===n&&(n=[]);var r=[],a=getFirstNoneTerminal(e.definition);if(i.isEmpty(a))return[];var s=t.name,c=i.contains(a,t),u=i.map(n,function(t){return t.name}),l=s+" --> "+u.concat([s]).join(" --> ");if(c){var p="Left Recursion found in grammar.\n"+("rule: <"+s+"> can be invoked from itself (directly or indirectly)\n")+("without consuming any Tokens. The grammar path that causes this is: \n "+l+"\n")+" To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_Factoring.";r.push({message:p,type:o.ParserDefinitionErrorType.LEFT_RECURSION,ruleName:s})}var f=i.difference(a,n.concat([t])),h=i.map(f,function(e){var r=i.cloneArr(n);return r.push(e),validateNoLeftRecursion(t,e,r)});return r.concat(i.flatten(h))}function getFirstNoneTerminal(t){var e=[];if(i.isEmpty(t))return e;var n=i.first(t);if(n instanceof a.gast.NonTerminal){if(void 0===n.referencedRule)return e;e.push(n.referencedRule)}else if(n instanceof a.gast.Flat||n instanceof a.gast.Option||n instanceof a.gast.RepetitionMandatory||n instanceof a.gast.RepetitionMandatoryWithSeparator||n instanceof a.gast.RepetitionWithSeparator||n instanceof a.gast.Repetition)e=e.concat(getFirstNoneTerminal(n.definition));else if(n instanceof a.gast.Alternation)e=i.flatten(i.map(n.definition,function(t){return getFirstNoneTerminal(t.definition)}));else if(!(n instanceof a.gast.Terminal))throw Error("non exhaustive match");var r=s.isOptionalProd(n),o=t.length>1;if(r&&o){var c=i.drop(t);return e.concat(getFirstNoneTerminal(c))}return e}function validateEmptyOrAlternative(t){var e=new f;t.accept(e);var n=e.alternations,r=i.reduce(n,function(e,n){var r=i.dropRight(n.definition),a=i.map(r,function(e,r){return i.isEmpty(u.first(e))?{message:"Ambiguous empty alternative: <"+(r+1)+">"+(" in inside <"+t.name+"> Rule.\n")+"Only the last alternative may be an empty alternative.",type:o.ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:n.occurrenceInParent,alternative:r+1}:null});return e.concat(i.compact(a))},[]);return r}var r=this&&this.__extends||function(t,e){function __(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)},i=n(4),o=n(1),a=n(7),s=n(9),c=n(10),u=n(13);e.validateGrammar=validateGrammar,e.identifyProductionForDuplicates=identifyProductionForDuplicates;var l=function(t){function OccurrenceValidationCollector(){t.apply(this,arguments),this.allProductions=[]}return r(OccurrenceValidationCollector,t),OccurrenceValidationCollector.prototype.visitNonTerminal=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitOption=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetitionWithSeparator=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetitionMandatory=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetitionMandatoryWithSeparator=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetition=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitAlternation=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitTerminal=function(t){this.allProductions.push(t)},OccurrenceValidationCollector}(a.gast.GAstVisitor);e.OccurrenceValidationCollector=l;var p=/^[a-zA-Z_]\w*$/;e.validateRuleName=validateRuleName,e.validateNoLeftRecursion=validateNoLeftRecursion,e.getFirstNoneTerminal=getFirstNoneTerminal;var f=function(t){function OrCollector(){t.apply(this,arguments),this.alternations=[]}return r(OrCollector,t),OrCollector.prototype.visitAlternation=function(t){this.alternations.push(t)},OrCollector}(a.gast.GAstVisitor);e.validateEmptyOrAlternative=validateEmptyOrAlternative},function(t,e,n){function isSequenceProd(t){return t instanceof r.gast.Flat||t instanceof r.gast.Option||t instanceof r.gast.Repetition||t instanceof r.gast.RepetitionMandatory||t instanceof r.gast.RepetitionMandatoryWithSeparator||t instanceof r.gast.RepetitionWithSeparator||t instanceof r.gast.Terminal||t instanceof r.gast.Rule}function isOptionalProd(t,e){void 0===e&&(e=[]);var n=t instanceof r.gast.Option||t instanceof r.gast.Repetition||t instanceof r.gast.RepetitionWithSeparator;return n?!0:t instanceof r.gast.Alternation?i.some(t.definition,function(t){return isOptionalProd(t,e)}):t instanceof r.gast.NonTerminal&&i.contains(e,t)?!1:t instanceof r.gast.AbstractProduction?(t instanceof r.gast.NonTerminal&&e.push(t),i.every(t.definition,function(t){return isOptionalProd(t,e)})):!1}function isBranchingProd(t){return t instanceof r.gast.Alternation}function getProductionDslName(t){var e=t.constructor,n=o.functionName(e);return a[n]}var r=n(7),i=n(4),o=n(3);e.isSequenceProd=isSequenceProd,e.isOptionalProd=isOptionalProd,e.isBranchingProd=isBranchingProd;var a={};a[o.functionName(r.gast.NonTerminal)]="SUBRULE",a[o.functionName(r.gast.Option)]="OPTION",a[o.functionName(r.gast.RepetitionMandatory)]="AT_LEAST_ONE",a[o.functionName(r.gast.RepetitionMandatoryWithSeparator)]="AT_LEAST_ONE_SEP",a[o.functionName(r.gast.RepetitionWithSeparator)]="MANY_SEP",a[o.functionName(r.gast.Repetition)]="MANY",a[o.functionName(r.gast.Alternation)]="OR",a[o.functionName(r.gast.Terminal)]="CONSUME",e.getProductionDslName=getProductionDslName},function(t,e,n){function tokenName(t){return i.isString(t.tokenName)?t.tokenName:o.functionName(t)}function extendToken(t,e,n){void 0===e&&(e=void 0),void 0===n&&(n=s);var r;i.isRegExp(e)||e===a.Lexer.SKIPPED||e===a.Lexer.NA?r=e:i.isFunction(e)&&(n=e,r=void 0);var o=function(){n.apply(this,arguments)};return o=i.assign(o,n),o.tokenName=t,o.prototype=Object.create(n.prototype),o.prototype.constructor=o,i.isUndefined(r)||(o.PATTERN=r),o}var r=this&&this.__extends||function(t,e){function __(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)},i=n(4),o=n(3),a=n(11);e.tokenName=tokenName,e.extendToken=extendToken;var s=function(){function Token(t,e,n,r,i,o){void 0===i&&(i=n),void 0===o&&(o=r+t.length-1),this.image=t,this.offset=e,this.startLine=n,this.startColumn=r,this.endLine=i,this.endColumn=o,this.isInsertedInRecovery=!1}return Token}();e.Token=s;var c=function(t){function VirtualToken(){t.call(this,"",-1,-1,-1,-1,-1)}return r(VirtualToken,t),VirtualToken}(s);e.VirtualToken=c;var u=function(t){function EOF(){t.apply(this,arguments)}return r(EOF,t),EOF}(c);e.EOF=u},function(t,e,n){var r=n(12),i=n(4);!function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND"}(e.LexerDefinitionErrorType||(e.LexerDefinitionErrorType={}));var o=(e.LexerDefinitionErrorType,function(){function Lexer(t,e){if(void 0===e&&(e=!1),this.tokenClasses=t,this.lexerDefinitionErrors=[],this.lexerDefinitionErrors=r.validatePatterns(t),!i.isEmpty(this.lexerDefinitionErrors)&&!e){var n=i.map(this.lexerDefinitionErrors,function(t){return t.message}),o=n.join("-----------------------\n");throw new Error("Errors detected in definition of Lexer:\n"+o)}if(i.isEmpty(this.lexerDefinitionErrors)){var a=r.analyzeTokenClasses(t);this.allPatterns=a.allPatterns,this.patternIdxToClass=a.patternIdxToClass,this.patternIdxToGroup=a.patternIdxToGroup,this.patternIdxToLongerAltIdx=a.patternIdxToLongerAltIdx,this.patternIdxToCanLineTerminator=a.patternIdxToCanLineTerminator,this.emptyGroups=a.emptyGroups}}return Lexer.prototype.tokenize=function(t){var e,n,o,a,s,c,u,l,p,f,h,d,E,A,T,y,O,N,R=t,_=0,g=[],m=[],v=1,S=1,P=i.cloneObj(this.emptyGroups);if(!i.isEmpty(this.lexerDefinitionErrors)){var L=i.map(this.lexerDefinitionErrors,function(t){return t.message}),k=L.join("-----------------------\n");throw new Error("Unable to Tokenize because Errors detected in definition of Lexer:\n"+k)}for(;t.length>0;){for(e=null,n=0;ne[0].length&&(e=a,n=s));break}if(null!==e){if(c=e[0],u=c.length,l=this.patternIdxToGroup[n],void 0!==l&&(p=this.patternIdxToClass[n],f=new p(c,_,v,S),"default"===l?g.push(f):P[l].push(f)),t=t.slice(u),_+=u,S+=u,d=this.patternIdxToCanLineTerminator[n]){var I=r.countLineTerminators(c);if(0!==I){for(v+=I,y=u-1;y>=0&&(A=c.charCodeAt(y),13!==A&&10!==A);)y--;S=u-y,void 0!==l&&(N=y===u-1,E=N?-1:0,1===I&&N||(f.endLine=v+E,f.endColumn=S-1+-E))}}}else{for(var x=_,F=v,C=S,w=!1;!w&&t.length>0;)for(T=t.charCodeAt(0),10===T||13===T&&(1===t.length||t.length>1&&10!==t.charCodeAt(1))?(v++,S=1):S++,t=t.substr(1),_++,o=0;o"+R.charAt(x)+"<- at offset: "+x+","+(" skipped "+(_-x)+" characters."),m.push({line:F,column:C,length:h,message:O})}}return{tokens:g,groups:P,errors:m}},Lexer.SKIPPED={description:"This marks a skipped Token pattern, this means each token identified by it willbe consumed and then throw into oblivion, this can be used to for example: skip whitespace."},Lexer.NA=/NOT_APPLICABLE/,Lexer}());e.Lexer=o},function(t,e,n){function analyzeTokenClasses(t){var e=o.reject(t,function(t){return t[a]===i.Lexer.NA}),n=o.map(e,function(t){return addStartOfInput(t[a])}),r=o.zipObject(n,e),s=o.map(n,function(t){return r[t.toString()]}),c=o.map(e,function(t){var e=t.GROUP;if(e!==i.Lexer.SKIPPED){if(o.isString(e))return e;if(o.isUndefined(e))return"default";throw Error("non exhaustive match")}}),u=o.map(e,function(t){var n=t.LONGER_ALT;if(n){var r=o.indexOf(e,n);return r}}),l=o.map(n,function(t){return/\\n|\\r|\\s/g.test(t.source)}),p=o.reduce(e,function(t,e){var n=e.GROUP;return o.isString(n)&&(t[n]=[]),t},{});return{allPatterns:n,patternIdxToClass:s,patternIdxToGroup:c,patternIdxToLongerAltIdx:u,patternIdxToCanLineTerminator:l,emptyGroups:p}}function validatePatterns(t){var e=[],n=findMissingPatterns(t),r=n.validTokenClasses;e=e.concat(n.errors);var i=findInvalidPatterns(r);return r=i.validTokenClasses,e=e.concat(i.errors),e=e.concat(findEndOfInputAnchor(r)),e=e.concat(findUnsupportedFlags(r)),e=e.concat(findDuplicatePatterns(r)),e=e.concat(findInvalidGroupType(r))}function findMissingPatterns(t){var e=o.filter(t,function(t){return!o.has(t,a)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- missing static 'PATTERN' property",type:i.LexerDefinitionErrorType.MISSING_PATTERN,tokenClasses:[t]}}),s=o.difference(t,e);return{errors:n,validTokenClasses:s}}function findInvalidPatterns(t){var e=o.filter(t,function(t){var e=t[a];return!o.isRegExp(e)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'PATTERN' can only be a RegExp",type:i.LexerDefinitionErrorType.INVALID_PATTERN,tokenClasses:[t]}}),s=o.difference(t,e);return{errors:n,validTokenClasses:s}}function findEndOfInputAnchor(t){var e=o.filter(t,function(t){var e=t[a];return s.test(e.source)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'PATTERN' cannot contain end of input anchor '$'",type:i.LexerDefinitionErrorType.EOI_ANCHOR_FOUND,tokenClasses:[t]}});return n}function findUnsupportedFlags(t){var e=o.filter(t,function(t){var e=t[a];return e instanceof RegExp&&(e.multiline||e.global)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:i.LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND,tokenClasses:[t]}});return n}function findDuplicatePatterns(t){var e=[],n=o.map(t,function(n){return o.reduce(t,function(t,r){return n.PATTERN.source!==r.PATTERN.source||o.contains(e,r)||r.PATTERN===i.Lexer.NA?t:(e.push(r),t.push(r),t)},[])});n=o.compact(n);var a=o.filter(n,function(t){return t.length>1}),s=o.map(a,function(t){var e=o.map(t,function(t){return r.tokenName(t)}),n=o.first(t).PATTERN;return{message:"The same RegExp pattern ->"+n+"<-"+("has been used in all the following classes: "+e.join(", ")+" <-"),type:i.LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND,tokenClasses:t}});return s}function findInvalidGroupType(t){var e=o.filter(t,function(t){if(!o.has(t,"GROUP"))return!1;var e=t.GROUP;return e!==i.Lexer.SKIPPED&&e!==i.Lexer.NA&&!o.isString(e)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:i.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND,tokenClasses:[t]}});return n}function addStartOfInput(t){var e=t.ignoreCase?"i":"";return new RegExp("^(?:"+t.source+")",e)}function countLineTerminators(t){for(var e=0,n=0;na,c=!0;s&&c;)e=r[a],c=i.isOptionalProd(e),n=n.concat(first(e)),a+=1,s=r.length>a;return o.uniq(n)}function firstForBranching(t){var e=o.map(t.definition,function(t){return first(t)});return o.uniq(o.flatten(e))}function firstForTerminal(t){return[t.terminalType]}var r=n(7),i=n(9),o=n(4);e.first=first,e.firstForSequence=firstForSequence,e.firstForBranching=firstForBranching,e.firstForTerminal=firstForTerminal},function(t,e,n){function computeAllProdsFollows(t){var e=new o.HashTable;return c.forEach(t,function(t){var n=new p(t).startWalking();e.putAll(n)}),e}function buildBetweenProdsFollowPrefix(t,e){return t.name+e+u.IN}function buildInProdFollowPrefix(t){var e=l.tokenName(t.terminalType);return e+t.occurrenceInParent+u.IN}var r=this&&this.__extends||function(t,e){function __(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)},i=n(15),o=n(3),a=n(7),s=n(13),c=n(4),u=n(16),l=n(10),p=function(t){function ResyncFollowsWalker(e){t.call(this),this.topProd=e,this.follows=new o.HashTable}return r(ResyncFollowsWalker,t),ResyncFollowsWalker.prototype.startWalking=function(){return this.walk(this.topProd),this.follows},ResyncFollowsWalker.prototype.walkTerminal=function(t,e,n){},ResyncFollowsWalker.prototype.walkProdRef=function(t,e,n){var r=buildBetweenProdsFollowPrefix(t.referencedRule,t.occurrenceInParent)+this.topProd.name,i=e.concat(n),o=new a.gast.Flat(i),c=s.first(o);this.follows.put(r,c)},ResyncFollowsWalker}(i.RestWalker);e.ResyncFollowsWalker=p,e.computeAllProdsFollows=computeAllProdsFollows,e.buildBetweenProdsFollowPrefix=buildBetweenProdsFollowPrefix,e.buildInProdFollowPrefix=buildInProdFollowPrefix},function(t,e,n){function restForRepetitionWithSeparator(t,e,n){var i=[new r.gast.Option([new r.gast.Terminal(t.separator)].concat(t.definition))],o=i.concat(e,n);return o}var r=n(7),i=n(4),o=function(){function RestWalker(){}return RestWalker.prototype.walk=function(t,e){var n=this;void 0===e&&(e=[]),i.forEach(t.definition,function(o,a){var s=i.drop(t.definition,a+1);if(o instanceof r.gast.NonTerminal)n.walkProdRef(o,s,e);else if(o instanceof r.gast.Terminal)n.walkTerminal(o,s,e);else if(o instanceof r.gast.Flat)n.walkFlat(o,s,e);else if(o instanceof r.gast.Option)n.walkOption(o,s,e);else if(o instanceof r.gast.RepetitionMandatory)n.walkAtLeastOne(o,s,e);else if(o instanceof r.gast.RepetitionMandatoryWithSeparator)n.walkAtLeastOneSep(o,s,e);else if(o instanceof r.gast.RepetitionWithSeparator)n.walkManySep(o,s,e);else if(o instanceof r.gast.Repetition)n.walkMany(o,s,e);else{if(!(o instanceof r.gast.Alternation))throw Error("non exhaustive match");n.walkOr(o,s,e)}})},RestWalker.prototype.walkTerminal=function(t,e,n){},RestWalker.prototype.walkProdRef=function(t,e,n){},RestWalker.prototype.walkFlat=function(t,e,n){var r=e.concat(n);this.walk(t,r)},RestWalker.prototype.walkOption=function(t,e,n){var r=e.concat(n);this.walk(t,r)},RestWalker.prototype.walkAtLeastOne=function(t,e,n){var i=[new r.gast.Option(t.definition)].concat(e,n);this.walk(t,i)},RestWalker.prototype.walkAtLeastOneSep=function(t,e,n){var r=restForRepetitionWithSeparator(t,e,n);this.walk(t,r)},RestWalker.prototype.walkMany=function(t,e,n){var i=[new r.gast.Option(t.definition)].concat(e,n);this.walk(t,i)},RestWalker.prototype.walkManySep=function(t,e,n){var r=restForRepetitionWithSeparator(t,e,n);this.walk(t,r)},RestWalker.prototype.walkOr=function(t,e,n){var o=this,a=e.concat(n);i.forEach(t.definition,function(t){var e=new r.gast.Flat([t]);o.walk(e,a)})},RestWalker}();e.RestWalker=o},function(t,e){e.IN="_~IN~_"},function(t,e,n){function buildLookaheadForTopLevel(t){var e=new r.gast.Flat(t.definition),n=i.first(e);return getSimpleLookahead(n)}function buildLookaheadForOption(t,e){return buildLookAheadForGrammarProd(o.NextInsideOptionWalker,t,e)}function buildLookaheadForMany(t,e){return buildLookAheadForGrammarProd(o.NextInsideManyWalker,t,e)}function buildLookaheadForManySep(t,e){return buildLookAheadForGrammarProd(o.NextInsideManySepWalker,t,e)}function buildLookaheadForAtLeastOne(t,e){return buildLookAheadForGrammarProd(o.NextInsideAtLeastOneWalker,t,e)}function buildLookaheadForAtLeastOneSep(t,e){return buildLookAheadForGrammarProd(o.NextInsideAtLeastOneSepWalker,t,e)}function buildLookaheadForOr(t,e,n){void 0===n&&(n=!1);var r=new o.NextInsideOrWalker(e,t).startWalking();n||checkForOrAmbiguities(r,t,e);var i=a.isEmpty(a.last(r));if(i){var s=r.length-1;return function(){for(var t=this.NEXT_TOKEN(),e=0;s>e;e++)for(var n=r[e],i=0;i in inside <"+n.name+"> "+("Rule, <"+s.tokenName(t.token)+"> may appears as the first Terminal in all these alternatives.\n")});throw new Error(i.join("\n ---------------- \n")+"To Resolve this, either: \n1. refactor your grammar to be LL(1)\n2. provide explicit lookahead functions in the form {WHEN:laFunc, THEN_DO:...}\n3. Add ignore arg to this OR Production:\nOR([], 'msg', recognizer.IGNORE_AMBIGUITIES)\nIn that case the parser will always pick the first alternative that matches and ignore all the others")}}function checkAlternativesAmbiguities(t){var e=a.flatten(t),n=a.uniq(e),r=a.map(n,function(e){var n=a.pick(t,function(t){return a.find(t,function(t){return t===e})}),r=a.map(a.keys(n),function(t){return parseInt(t,10)+1});return{token:e,alts:r}}),i=a.filter(r,function(t){return t.alts.length>1});return i}function buildLookAheadForGrammarProd(t,e,n){var r={ruleStack:[n.name],occurrenceStack:[1],occurrence:e},i=new t(n,r),o=i.startWalking();return getSimpleLookahead(o)}function getSimpleLookahead(t){return function(){for(var e=this.NEXT_TOKEN(),n=0;nt||t>e)}var n=function(){function Range(t,e){if(this.start=t,this.end=e,!isValidRange(t,e))throw new Error("INVALID RANGE")}return Range.prototype.contains=function(t){return this.start<=t&&this.end>=t},Range.prototype.containsRange=function(t){return this.start<=t.start&&this.end>=t.end},Range.prototype.isContainedInRange=function(t){return t.containsRange(this)},Range.prototype.strictlyContainsRange=function(t){return this.startt.end},Range.prototype.isStrictlyContainedInRange=function(t){return t.strictlyContainsRange(this)},Range}();e.Range=n,e.isValidRange=isValidRange},function(t,e,n){function clearCache(){r.clearCache()}var r=n(2);e.clearCache=clearCache}])}); \ No newline at end of file +/*! chevrotain - v0.5.19 - 2016-03-07 */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("chevrotain",[],e):"object"==typeof exports?exports.chevrotain=e():t.chevrotain=e()}(this,function(){return function(t){function __webpack_require__(n){if(e[n])return e[n].exports;var r=e[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,__webpack_require__),r.loaded=!0,r.exports}var e={};return __webpack_require__.m=t,__webpack_require__.c=e,__webpack_require__.p="",__webpack_require__(0)}([function(t,e,n){"use strict";var r=n(1),i=n(11),o=n(10),a=n(5),s=n(7),c=n(21),u={};u.VERSION="0.5.19",u.Parser=r.Parser,u.Lexer=i.Lexer,u.Token=o.Token,u.VirtualToken=o.VirtualToken,u.EOF=o.EOF,u.extendToken=o.extendToken,u.tokenName=o.tokenName,u.EMPTY_ALT=r.EMPTY_ALT,u.exceptions={},u.exceptions.isRecognitionException=a.exceptions.isRecognitionException,u.exceptions.EarlyExitException=a.exceptions.EarlyExitException,u.exceptions.MismatchedTokenException=a.exceptions.MismatchedTokenException,u.exceptions.NotAllInputParsedException=a.exceptions.NotAllInputParsedException,u.exceptions.NoViableAltException=a.exceptions.NoViableAltException,u.gast={},u.gast.GAstVisitor=s.gast.GAstVisitor,u.gast.Flat=s.gast.Flat,u.gast.Repetition=s.gast.Repetition,u.gast.RepetitionWithSeparator=s.gast.RepetitionWithSeparator,u.gast.RepetitionMandatory=s.gast.RepetitionMandatory,u.gast.RepetitionMandatoryWithSeparator=s.gast.RepetitionMandatoryWithSeparator,u.gast.Option=s.gast.Option,u.gast.Alternation=s.gast.Alternation,u.gast.NonTerminal=s.gast.NonTerminal,u.gast.Terminal=s.gast.Terminal,u.gast.Rule=s.gast.Rule,u.clearCache=c.clearCache,t.exports=u},function(t,e,n){"use strict";function EMPTY_ALT(t){return void 0===t&&(t=void 0),function(){return t}}function InRuleRecoveryException(t){this.name=o.functionName(InRuleRecoveryException),this.message=t}var r=n(2),i=n(5),o=n(3),a=n(6),s=n(8),c=n(4),u=n(14),l=n(10),p=n(17),f=n(19),h=n(18),d=n(16);!function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.DUPLICATE_PRODUCTIONS=2]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=3]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=4]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=5]="NONE_LAST_EMPTY_ALT"}(e.ParserDefinitionErrorType||(e.ParserDefinitionErrorType={}));e.ParserDefinitionErrorType;e.EMPTY_ALT=EMPTY_ALT;var E={},A=function(){function Parser(t,e,n){if(void 0===n&&(n=!0),this.errors=[],this._input=[],this.inputIdx=-1,this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[],this.tokensMap=void 0,this.definedRulesNames=[],this._input=t,this.isErrorRecoveryEnabled=n,this.className=o.classNameFromInstance(this),this.firstAfterRepMap=r.getFirstAfterRepForClass(this.className),this.classLAFuncs=r.getLookaheadFuncsForClass(this.className),r.CLASS_TO_DEFINITION_ERRORS.containsKey(this.className)?this.definitionErrors=r.CLASS_TO_DEFINITION_ERRORS.get(this.className):(this.definitionErrors=[],r.CLASS_TO_DEFINITION_ERRORS.put(this.className,this.definitionErrors)),c.isArray(e))this.tokensMap=c.reduce(e,function(t,e){return t[l.tokenName(e)]=e,t},{});else{if(!c.isObject(e))throw new Error("'tokensMapOrArr' argument must be An Array of Token constructors or a Dictionary of Tokens.");this.tokensMap=c.cloneObj(e)}this.tokensMap[l.tokenName(l.EOF)]=l.EOF,void 0===r.CLASS_TO_OR_LA_CACHE[this.className]&&r.initLookAheadKeyCache(this.className),this.orLookaheadKeys=r.CLASS_TO_OR_LA_CACHE[this.className],this.manyLookaheadKeys=r.CLASS_TO_MANY_LA_CACHE[this.className],this.manySepLookaheadKeys=r.CLASS_TO_MANY_SEP_LA_CACHE[this.className],this.atLeastOneLookaheadKeys=r.CLASS_TO_AT_LEAST_ONE_LA_CACHE[this.className],this.atLeastOneSepLookaheadKeys=r.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[this.className],this.optionLookaheadKeys=r.CLASS_TO_OPTION_LA_CACHE[this.className]}return Parser.performSelfAnalysis=function(t){var e,n=[],i=o.classNameFromInstance(t);if(""===i)throw Error("A Parser's constructor may not be an anonymous Function, it must be a named function\nThe constructor's name is used at runtime for performance (caching) purposes.");if(!r.CLASS_TO_SELF_ANALYSIS_DONE.containsKey(i)){var l=r.getProductionsForClass(i);n=r.CLASS_TO_DEFINITION_ERRORS.get(i);var p=a.resolveGrammar(l);n.push.apply(n,p),r.CLASS_TO_SELF_ANALYSIS_DONE.put(i,!0);var f=s.validateGrammar(l.values());if(n.push.apply(n,f),!c.isEmpty(n)&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw e=c.map(n,function(t){return t.message}),new Error("Parser Definition Errors detected\n: "+e.join("\n-------------------------------\n"));if(c.isEmpty(n)){var h=u.computeAllProdsFollows(l.values());r.setResyncFollowsForClass(i,h)}}if(!c.isEmpty(r.CLASS_TO_DEFINITION_ERRORS.get(i))&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw e=c.map(r.CLASS_TO_DEFINITION_ERRORS.get(i),function(t){return t.message}),new Error("Parser Definition Errors detected\n: "+e.join("\n-------------------------------\n"))},Object.defineProperty(Parser.prototype,"input",{get:function(){return c.cloneArr(this._input)},set:function(t){this.reset(),this._input=t},enumerable:!0,configurable:!0}),Parser.prototype.reset=function(){this.isBackTrackingStack=[],this.errors=[],this._input=[],this.inputIdx=-1,this.RULE_STACK=[],this.RULE_OCCURRENCE_STACK=[]},Parser.prototype.isAtEndOfInput=function(){return this.LA(1)instanceof l.EOF},Parser.prototype.getGAstProductions=function(){return r.getProductionsForClass(this.className)},Parser.prototype.isBackTracking=function(){return!c.isEmpty(this.isBackTrackingStack)},Parser.prototype.SAVE_ERROR=function(t){if(i.exceptions.isRecognitionException(t))return this.errors.push(t),t;throw Error("trying to save an Error which is not a RecognitionException")},Parser.prototype.NEXT_TOKEN=function(){return this.LA(1)},Parser.prototype.LA=function(t){return this._input.length<=this.inputIdx+t?new l.EOF:this._input[this.inputIdx+t]},Parser.prototype.isNextRule=function(t){var e=r.getLookaheadFuncsForClass(this.className),n=e.get(t);if(void 0===n){var i=this.getGAstProductions().get(t);n=p.buildLookaheadForTopLevel(i),e.put(t,n)}return n.call(this)},Parser.prototype.BACKTRACK=function(t,e){var n=this;return function(){n.isBackTrackingStack.push(1);var r=n.saveRecogState();try{var o=t.call(n);return e(o)}catch(a){if(i.exceptions.isRecognitionException(a))return!1;throw a}finally{n.reloadRecogState(r),n.isBackTrackingStack.pop()}}},Parser.prototype.SKIP_TOKEN=function(){return this.inputIdx<=this._input.length-2?(this.inputIdx++,this.NEXT_TOKEN()):new l.EOF},Parser.prototype.CONSUME=function(t){return this.CONSUME1(t)},Parser.prototype.CONSUME1=function(t){return this.consumeInternal(t,1)},Parser.prototype.CONSUME2=function(t){return this.consumeInternal(t,2)},Parser.prototype.CONSUME3=function(t){return this.consumeInternal(t,3)},Parser.prototype.CONSUME4=function(t){return this.consumeInternal(t,4)},Parser.prototype.CONSUME5=function(t){return this.consumeInternal(t,5)},Parser.prototype.SUBRULE=function(t,e){return void 0===e&&(e=[]),this.SUBRULE1(t,e)},Parser.prototype.SUBRULE1=function(t,e){return void 0===e&&(e=[]),t.call(this,1,e)},Parser.prototype.SUBRULE2=function(t,e){return void 0===e&&(e=[]),t.call(this,2,e)},Parser.prototype.SUBRULE3=function(t,e){return void 0===e&&(e=[]),t.call(this,3,e)},Parser.prototype.SUBRULE4=function(t,e){return void 0===e&&(e=[]),t.call(this,4,e)},Parser.prototype.SUBRULE5=function(t,e){return void 0===e&&(e=[]),t.call(this,5,e)},Parser.prototype.OPTION=function(t,e){return this.OPTION1.call(this,t,e)},Parser.prototype.OPTION1=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(1)),this.optionInternal(t,e)},Parser.prototype.OPTION2=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(2)),this.optionInternal(t,e)},Parser.prototype.OPTION3=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(3)),this.optionInternal(t,e)},Parser.prototype.OPTION4=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(4)),this.optionInternal(t,e)},Parser.prototype.OPTION5=function(t,e){return void 0===e&&(e=t,t=this.getLookaheadFuncForOption(5)),this.optionInternal(t,e)},Parser.prototype.OR=function(t,e,n){return void 0===n&&(n=!1),this.OR1(t,e,n)},Parser.prototype.OR1=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,1,n)},Parser.prototype.OR2=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,2,n)},Parser.prototype.OR3=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,3,n)},Parser.prototype.OR4=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,4,n)},Parser.prototype.OR5=function(t,e,n){return void 0===n&&(n=!1),this.orInternal(t,e,5,n)},Parser.prototype.MANY=function(t,e){return this.MANY1.call(this,t,e)},Parser.prototype.MANY1=function(t,e){this.manyInternal(this.MANY1,"MANY1",1,t,e)},Parser.prototype.MANY2=function(t,e){this.manyInternal(this.MANY2,"MANY2",2,t,e)},Parser.prototype.MANY3=function(t,e){this.manyInternal(this.MANY3,"MANY3",3,t,e)},Parser.prototype.MANY4=function(t,e){this.manyInternal(this.MANY4,"MANY4",4,t,e)},Parser.prototype.MANY5=function(t,e){this.manyInternal(this.MANY5,"MANY5",5,t,e)},Parser.prototype.MANY_SEP=function(t,e,n){return this.MANY_SEP1.call(this,t,e,n)},Parser.prototype.MANY_SEP1=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP1,"MANY_SEP1",1,t,e,n)},Parser.prototype.MANY_SEP2=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP2,"MANY_SEP2",2,t,e,n)},Parser.prototype.MANY_SEP3=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP3,"MANY_SEP3",3,t,e,n)},Parser.prototype.MANY_SEP4=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP4,"MANY_SEP4",4,t,e,n)},Parser.prototype.MANY_SEP5=function(t,e,n){return this.manySepFirstInternal(this.MANY_SEP5,"MANY_SEP5",5,t,e,n)},Parser.prototype.AT_LEAST_ONE=function(t,e,n){return this.AT_LEAST_ONE1.call(this,t,e,n)},Parser.prototype.AT_LEAST_ONE1=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE1,"AT_LEAST_ONE1",1,t,e,n)},Parser.prototype.AT_LEAST_ONE2=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE2,"AT_LEAST_ONE2",2,t,e,n)},Parser.prototype.AT_LEAST_ONE3=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE3,"AT_LEAST_ONE3",3,t,e,n)},Parser.prototype.AT_LEAST_ONE4=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE4,"AT_LEAST_ONE4",4,t,e,n)},Parser.prototype.AT_LEAST_ONE5=function(t,e,n){this.atLeastOneInternal(this.AT_LEAST_ONE5,"AT_LEAST_ONE5",5,t,e,n)},Parser.prototype.AT_LEAST_ONE_SEP=function(t,e,n,r){return this.AT_LEAST_ONE_SEP1.call(this,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP1=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP1",1,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP2=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP2",2,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP3=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP3",3,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP4=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP4",4,t,e,n,r)},Parser.prototype.AT_LEAST_ONE_SEP5=function(t,e,n,r){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP5",5,t,e,n,r)},Parser.prototype.RULE_NO_RESYNC=function(t,e,n){return this.RULE(t,e,n,!1)},Parser.prototype.RULE=function(t,e,n,o){void 0===n&&(n=this.defaultInvalidReturn),void 0===o&&(o=!0);var a=s.validateRuleName(t,this.definedRulesNames,this.className);this.definedRulesNames.push(t),this.definitionErrors.push.apply(this.definitionErrors,a);var c=r.getProductionsForClass(this.className);if(!c.containsKey(t)){var u=f.buildTopProduction(e.toString(),t,this.tokensMap);c.put(t,u)}var l=function(r,a){void 0===r&&(r=1),void 0===a&&(a=[]),this.ruleInvocationStateUpdate(t,r);try{return e.apply(this,a)}catch(s){var c=1===this.RULE_STACK.length,u=c||o&&!this.isBackTracking()&&this.isErrorRecoveryEnabled;if(u&&i.exceptions.isRecognitionException(s)){var l=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(l))return this.reSyncTo(l),n();throw s}throw s}finally{this.ruleFinallyStateUpdate()}},p="ruleName";return l[p]=t,l},Parser.prototype.ruleInvocationStateUpdate=function(t,e){this.RULE_OCCURRENCE_STACK.push(e),this.RULE_STACK.push(t)},Parser.prototype.ruleFinallyStateUpdate=function(){this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop();var t=this._input.length-1;if(0===this.RULE_STACK.length&&this.inputIdx"+t+"<-- but found -->'"+c.image+"'<--";o.SAVE_ERROR(new i.exceptions.MismatchedTokenException(e,c))};!p;){if(u instanceof r)return void f();if(n.call(this))return f(),void t.apply(this,e);u instanceof a&&(p=!0),u=this.SKIP_TOKEN()}this.inputIdx=s},Parser.prototype.shouldInRepetitionRecoveryBeTried=function(t,e){return void 0===t||void 0===e?!1:this.NEXT_TOKEN()instanceof t?!1:this.isBackTracking()?!1:!this.canPerformInRuleRecovery(t,this.getFollowsForInRuleRecovery(t,e))},Parser.prototype.getFollowsForInRuleRecovery=function(t,e){var n=c.cloneArr(this.RULE_STACK),r=c.cloneArr(this.RULE_OCCURRENCE_STACK),i={ruleStack:n,occurrenceStack:r,lastTok:t,lastTokOccurrence:e},o=c.first(n),a=this.getGAstProductions(),s=a.get(o),u=new h.NextAfterTokenWalker(s,i).startWalking();return u},Parser.prototype.tryInRuleRecovery=function(t,e){if(this.canRecoverWithSingleTokenInsertion(t,e)){var n=this.getTokenToInsert(t);return n.isInsertedInRecovery=!0,n}if(this.canRecoverWithSingleTokenDeletion(t)){var r=this.SKIP_TOKEN();return this.inputIdx++,r}throw new InRuleRecoveryException("sad sad panda")},Parser.prototype.canPerformInRuleRecovery=function(t,e){return this.canRecoverWithSingleTokenInsertion(t,e)||this.canRecoverWithSingleTokenDeletion(t)},Parser.prototype.canRecoverWithSingleTokenInsertion=function(t,e){if(!this.canTokenTypeBeInsertedInRecovery(t))return!1;if(c.isEmpty(e))return!1;var n=this.NEXT_TOKEN(),r=void 0!==c.find(e,function(t){return n instanceof t});return r},Parser.prototype.canRecoverWithSingleTokenDeletion=function(t){var e=this.LA(2)instanceof t;return e},Parser.prototype.isInCurrentRuleReSyncSet=function(t){var e=this.getCurrFollowKey(),n=this.getFollowSetFromFollowKey(e);return c.contains(n,t)},Parser.prototype.findReSyncTokenType=function(){for(var t=this.flattenFollowSet(),e=this.NEXT_TOKEN(),n=2;;){var r=e.constructor;if(c.contains(t,r))return r;e=this.LA(n),n++}},Parser.prototype.getCurrFollowKey=function(){if(1===this.RULE_STACK.length)return E;var t=this.RULE_STACK.length-1,e=t,n=t-1;return{ruleName:this.RULE_STACK[t],idxInCallingRule:this.RULE_OCCURRENCE_STACK[e],inRule:this.RULE_STACK[n]}},Parser.prototype.buildFullFollowKeyStack=function(){var t=this;return c.map(this.RULE_STACK,function(e,n){return 0===n?E:{ruleName:e,idxInCallingRule:t.RULE_OCCURRENCE_STACK[n],inRule:t.RULE_STACK[n-1]}})},Parser.prototype.flattenFollowSet=function(){var t=this,e=c.map(this.buildFullFollowKeyStack(),function(e){return t.getFollowSetFromFollowKey(e)});return c.flatten(e)},Parser.prototype.getFollowSetFromFollowKey=function(t){if(t===E)return[l.EOF];var e=t.ruleName+t.idxInCallingRule+d.IN+t.inRule;return r.getResyncFollowsForClass(this.className).get(e)},Parser.prototype.reSyncTo=function(t){for(var e=this.NEXT_TOKEN();e instanceof t==!1;)e=this.SKIP_TOKEN()},Parser.prototype.attemptInRepetitionRecovery=function(t,e,n,r,i,o,a){var s=this.getKeyForAutomaticLookahead(r,a,i),u=this.firstAfterRepMap.get(s);if(void 0===u){var p=c.last(this.RULE_STACK),f=this.getGAstProductions().get(p),h=new o(f,i);u=h.startWalking(),this.firstAfterRepMap.put(s,u)}var d=u.token,E=u.occurrence,A=u.isEndOfRule;1===this.RULE_STACK.length&&A&&void 0===d&&(d=l.EOF,E=1),this.shouldInRepetitionRecoveryBeTried(d,E)&&this.tryInRepetitionRecovery(t,e,n,d)},Parser.prototype.optionInternal=function(t,e){return t.call(this)?(e.call(this),!0):!1},Parser.prototype.atLeastOneInternal=function(t,e,n,r,o,a){if(c.isString(o)&&(a=o,o=r,r=this.getLookaheadFuncForAtLeastOne(n)),!r.call(this))throw this.SAVE_ERROR(new i.exceptions.EarlyExitException("expecting at least one: "+a,this.NEXT_TOKEN()));for(o.call(this);r.call(this);)o.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(t,[r,o,a],r,e,n,h.NextTerminalAfterAtLeastOneWalker,this.atLeastOneLookaheadKeys)},Parser.prototype.atLeastOneSepFirstInternal=function(t,e,n,r,o,a,s){var u=this,l=[];if(c.isString(a)&&(s=a,a=o,o=this.getLookaheadFuncForAtLeastOneSep(n)),!o.call(this))throw this.SAVE_ERROR(new i.exceptions.EarlyExitException("expecting at least one: "+s,this.NEXT_TOKEN()));a.call(this);for(var p=function(){return u.NEXT_TOKEN()instanceof r};p();)l.push(this.CONSUME(r)),a.call(this);return this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,n,r,p,a,l,this.atLeastOneSepLookaheadKeys,h.NextTerminalAfterAtLeastOneSepWalker],p,e,n,h.NextTerminalAfterAtLeastOneSepWalker,this.atLeastOneSepLookaheadKeys),l},Parser.prototype.manyInternal=function(t,e,n,r,i){for(void 0===i&&(i=r,r=this.getLookaheadFuncForMany(n));r.call(this);)i.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(t,[r,i],r,e,n,h.NextTerminalAfterManyWalker,this.manyLookaheadKeys)},Parser.prototype.manySepFirstInternal=function(t,e,n,r,i,o){var a=this,s=[];if(void 0===o&&(o=i,i=this.getLookaheadFuncForManySep(n)),i.call(this)){o.call(this);for(var c=function(){return a.NEXT_TOKEN()instanceof r};c();)s.push(this.CONSUME(r)),o.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,n,r,c,o,s,this.manySepLookaheadKeys,h.NextTerminalAfterManySepWalker],c,e,n,h.NextTerminalAfterManySepWalker,this.manySepLookaheadKeys)}return s},Parser.prototype.repetitionSepSecondInternal=function(t,e,n,r,i,o,a,s){for(;r();)o.push(this.CONSUME(n)),i.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,e,n,r,i,o,a,s],r,t,e,s,a)},Parser.prototype.orInternal=function(t,e,n,r){if(void 0!==t[0].WHEN){for(var i=0;i"+n+"<-- but found -->'"+e.image+"'<--";throw this.SAVE_ERROR(new i.exceptions.MismatchedTokenException(r,e))},Parser.prototype.getKeyForAutomaticLookahead=function(t,e,n){var r=e[n-1],i=c.last(this.RULE_STACK),o=r[i];return void 0===o&&(o=t+n+d.IN+i,r[i]=o),o},Parser.prototype.getLookaheadFuncForOption=function(t){var e=this.getKeyForAutomaticLookahead("OPTION",this.optionLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForOption)},Parser.prototype.getLookaheadFuncForOr=function(t,e){var n=this.getKeyForAutomaticLookahead("OR",this.orLookaheadKeys,t);return this.getLookaheadFuncFor(n,t,p.buildLookaheadForOr,[e])},Parser.prototype.getLookaheadFuncForMany=function(t){var e=this.getKeyForAutomaticLookahead("MANY",this.manyLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForMany)},Parser.prototype.getLookaheadFuncForManySep=function(t){var e=this.getKeyForAutomaticLookahead("MANY_SEP",this.manySepLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForManySep)},Parser.prototype.getLookaheadFuncForAtLeastOne=function(t){var e=this.getKeyForAutomaticLookahead("AT_LEAST_ONE",this.atLeastOneLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForAtLeastOne)},Parser.prototype.getLookaheadFuncForAtLeastOneSep=function(t){var e=this.getKeyForAutomaticLookahead("AT_LEAST_ONE_SEP",this.atLeastOneSepLookaheadKeys,t);return this.getLookaheadFuncFor(e,t,p.buildLookaheadForAtLeastOneSep)},Parser.prototype.getLookaheadFuncFor=function(t,e,n,r){void 0===r&&(r=[]);var i=c.last(this.RULE_STACK),o=this.classLAFuncs.get(t);if(void 0===o){var a=this.getGAstProductions().get(i);o=n.apply(null,[e,a].concat(r)),this.classLAFuncs.put(t,o)}return o},Parser.prototype.saveRecogState=function(){var t=c.cloneArr(this.errors),e=c.cloneArr(this.RULE_STACK);return{errors:t,inputIdx:this.inputIdx,RULE_STACK:e}},Parser.prototype.reloadRecogState=function(t){this.errors=t.errors,this.inputIdx=t.inputIdx,this.RULE_STACK=t.RULE_STACK},Parser.prototype.raiseNoAltException=function(t,e){var n=" but found: '"+this.NEXT_TOKEN().image+"'";if(void 0===e){var r=c.last(this.RULE_STACK),o=this.getGAstProductions().get(r),a=new h.NextInsideOrWalker(o,t).startWalking(),s=c.flatten(a),u=c.map(s,function(t){return l.tokenName(t)});e="one of: <"+u.join(" ,")+">"}throw this.SAVE_ERROR(new i.exceptions.NoViableAltException("expecting: "+e+" "+n,this.NEXT_TOKEN()))},Parser.IGNORE_AMBIGUITIES=!0,Parser.NO_RESYNC=!1,Parser.DEFER_DEFINITION_ERRORS_HANDLING=!1,Parser}();e.Parser=A,InRuleRecoveryException.prototype=Error.prototype},function(t,e,n){"use strict";function getProductionsForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_GRAMMAR_PRODUCTIONS)}function getResyncFollowsForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_RESYNC_FOLLOW_SETS)}function setResyncFollowsForClass(t,n){e.CLASS_TO_RESYNC_FOLLOW_SETS.put(t,n)}function getLookaheadFuncsForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_LOOKAHEAD_FUNCS)}function getFirstAfterRepForClass(t){return getFromNestedHashTable(t,e.CLASS_TO_FIRST_AFTER_REPETITION)}function initLookAheadKeyCache(t){e.CLASS_TO_OR_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_MANY_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_MANY_SEP_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_AT_LEAST_ONE_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),e.CLASS_TO_OPTION_LA_CACHE[t]=new Array(e.MAX_OCCURRENCE_INDEX),initSingleLookAheadKeyCache(e.CLASS_TO_OR_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_MANY_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_MANY_SEP_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_AT_LEAST_ONE_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[t]),initSingleLookAheadKeyCache(e.CLASS_TO_OPTION_LA_CACHE[t])}function initSingleLookAheadKeyCache(t){for(var n=0;n1}),c=i.map(i.values(a),function(e){var n=i.first(e),r=createDuplicatesErrorMessage(e,t.name),a=s.getProductionDslName(n),c={message:r,type:o.ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:a,occurrence:n.occurrenceInParent},u=getExtraProductionArgument(n);return u&&(c.parameter=u),c});return c}function createDuplicatesErrorMessage(t,e){var n=i.first(t),r=n.occurrenceInParent,o=s.getProductionDslName(n),a=getExtraProductionArgument(n),c="->"+o+"<- with occurrence index: ->"+r+"<-\n "+(a?"and argument: "+a:"")+"\n appears more than once ("+t.length+" times) in the top level rule: "+e+".\n "+(1===r?"note that "+o+" and "+o+"1 both have the same occurrence index 1}":"")+"}\n to fix this make sure each usage of "+o+" "+(a?"with the argument: "+a:"")+"\n in the rule "+e+" has a different occurrence index (1-5), as that combination acts as a unique\n position key in the grammar, which is needed by the parsing engine.";return c=c.replace(/[ \t]+/g," "),c=c.replace(/\s\s+/g,"\n")}function identifyProductionForDuplicates(t){return s.getProductionDslName(t)+"_#_"+t.occurrenceInParent+"_#_"+getExtraProductionArgument(t)}function getExtraProductionArgument(t){return t instanceof a.gast.Terminal?c.tokenName(t.terminalType):t instanceof a.gast.NonTerminal?t.nonTerminalName:""}function validateRuleName(t,e,n){var r,a=[];return t.match(p)||(r="Invalid Grammar rule name --> "+t+" it must match the pattern: "+p.toString(),a.push({message:r,type:o.ParserDefinitionErrorType.INVALID_RULE_NAME,ruleName:t})),i.contains(e,t)&&(r="Duplicate definition, rule: "+t+" is already defined in the grammar: "+n,a.push({message:r,type:o.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:t})),a}function validateNoLeftRecursion(t,e,n){void 0===n&&(n=[]);var r=[],a=getFirstNoneTerminal(e.definition);if(i.isEmpty(a))return[];var s=t.name,c=i.contains(a,t),u=i.map(n,function(t){return t.name}),l=s+" --> "+u.concat([s]).join(" --> ");if(c){var p="Left Recursion found in grammar.\n"+("rule: <"+s+"> can be invoked from itself (directly or indirectly)\n")+("without consuming any Tokens. The grammar path that causes this is: \n "+l+"\n")+" To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_Factoring.";r.push({message:p,type:o.ParserDefinitionErrorType.LEFT_RECURSION,ruleName:s})}var f=i.difference(a,n.concat([t])),h=i.map(f,function(e){var r=i.cloneArr(n);return r.push(e),validateNoLeftRecursion(t,e,r)});return r.concat(i.flatten(h))}function getFirstNoneTerminal(t){var e=[];if(i.isEmpty(t))return e;var n=i.first(t);if(n instanceof a.gast.NonTerminal){if(void 0===n.referencedRule)return e;e.push(n.referencedRule)}else if(n instanceof a.gast.Flat||n instanceof a.gast.Option||n instanceof a.gast.RepetitionMandatory||n instanceof a.gast.RepetitionMandatoryWithSeparator||n instanceof a.gast.RepetitionWithSeparator||n instanceof a.gast.Repetition)e=e.concat(getFirstNoneTerminal(n.definition));else if(n instanceof a.gast.Alternation)e=i.flatten(i.map(n.definition,function(t){return getFirstNoneTerminal(t.definition)}));else if(!(n instanceof a.gast.Terminal))throw Error("non exhaustive match");var r=s.isOptionalProd(n),o=t.length>1;if(r&&o){var c=i.drop(t);return e.concat(getFirstNoneTerminal(c))}return e}function validateEmptyOrAlternative(t){var e=new f;t.accept(e);var n=e.alternations,r=i.reduce(n,function(e,n){var r=i.dropRight(n.definition),a=i.map(r,function(e,r){return i.isEmpty(u.first(e))?{message:"Ambiguous empty alternative: <"+(r+1)+">"+(" in inside <"+t.name+"> Rule.\n")+"Only the last alternative may be an empty alternative.",type:o.ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:n.occurrenceInParent,alternative:r+1}:null});return e.concat(i.compact(a))},[]);return r}var r=this&&this.__extends||function(t,e){function __(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)},i=n(4),o=n(1),a=n(7),s=n(9),c=n(10),u=n(13);e.validateGrammar=validateGrammar,e.identifyProductionForDuplicates=identifyProductionForDuplicates;var l=function(t){function OccurrenceValidationCollector(){t.apply(this,arguments),this.allProductions=[]}return r(OccurrenceValidationCollector,t),OccurrenceValidationCollector.prototype.visitNonTerminal=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitOption=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetitionWithSeparator=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetitionMandatory=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetitionMandatoryWithSeparator=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitRepetition=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitAlternation=function(t){this.allProductions.push(t)},OccurrenceValidationCollector.prototype.visitTerminal=function(t){this.allProductions.push(t)},OccurrenceValidationCollector}(a.gast.GAstVisitor);e.OccurrenceValidationCollector=l;var p=/^[a-zA-Z_]\w*$/;e.validateRuleName=validateRuleName,e.validateNoLeftRecursion=validateNoLeftRecursion,e.getFirstNoneTerminal=getFirstNoneTerminal;var f=function(t){function OrCollector(){t.apply(this,arguments),this.alternations=[]}return r(OrCollector,t),OrCollector.prototype.visitAlternation=function(t){this.alternations.push(t)},OrCollector}(a.gast.GAstVisitor);e.validateEmptyOrAlternative=validateEmptyOrAlternative},function(t,e,n){"use strict";function isSequenceProd(t){return t instanceof r.gast.Flat||t instanceof r.gast.Option||t instanceof r.gast.Repetition||t instanceof r.gast.RepetitionMandatory||t instanceof r.gast.RepetitionMandatoryWithSeparator||t instanceof r.gast.RepetitionWithSeparator||t instanceof r.gast.Terminal||t instanceof r.gast.Rule}function isOptionalProd(t,e){void 0===e&&(e=[]);var n=t instanceof r.gast.Option||t instanceof r.gast.Repetition||t instanceof r.gast.RepetitionWithSeparator;return n?!0:t instanceof r.gast.Alternation?i.some(t.definition,function(t){return isOptionalProd(t,e)}):t instanceof r.gast.NonTerminal&&i.contains(e,t)?!1:t instanceof r.gast.AbstractProduction?(t instanceof r.gast.NonTerminal&&e.push(t),i.every(t.definition,function(t){return isOptionalProd(t,e)})):!1}function isBranchingProd(t){return t instanceof r.gast.Alternation}function getProductionDslName(t){var e=t.constructor,n=o.functionName(e);return a[n]}var r=n(7),i=n(4),o=n(3);e.isSequenceProd=isSequenceProd,e.isOptionalProd=isOptionalProd,e.isBranchingProd=isBranchingProd;var a={};a[o.functionName(r.gast.NonTerminal)]="SUBRULE",a[o.functionName(r.gast.Option)]="OPTION",a[o.functionName(r.gast.RepetitionMandatory)]="AT_LEAST_ONE",a[o.functionName(r.gast.RepetitionMandatoryWithSeparator)]="AT_LEAST_ONE_SEP",a[o.functionName(r.gast.RepetitionWithSeparator)]="MANY_SEP",a[o.functionName(r.gast.Repetition)]="MANY",a[o.functionName(r.gast.Alternation)]="OR",a[o.functionName(r.gast.Terminal)]="CONSUME",e.getProductionDslName=getProductionDslName},function(t,e,n){"use strict";function tokenName(t){return i.isString(t.tokenName)?t.tokenName:o.functionName(t)}function extendToken(t,e,n){void 0===e&&(e=void 0),void 0===n&&(n=s);var r;i.isRegExp(e)||e===a.Lexer.SKIPPED||e===a.Lexer.NA?r=e:i.isFunction(e)&&(n=e,r=void 0);var o=function(){n.apply(this,arguments)};return o=i.assign(o,n),o.tokenName=t,o.prototype=Object.create(n.prototype),o.prototype.constructor=o,i.isUndefined(r)||(o.PATTERN=r),o}var r=this&&this.__extends||function(t,e){function __(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)},i=n(4),o=n(3),a=n(11);e.tokenName=tokenName,e.extendToken=extendToken;var s=function(){function Token(t,e,n,r,i,o){void 0===i&&(i=n),void 0===o&&(o=r+t.length-1),this.image=t,this.offset=e,this.startLine=n,this.startColumn=r,this.endLine=i,this.endColumn=o,this.isInsertedInRecovery=!1}return Token}();e.Token=s;var c=function(t){function VirtualToken(){t.call(this,"",-1,-1,-1,-1,-1)}return r(VirtualToken,t),VirtualToken}(s);e.VirtualToken=c;var u=function(t){function EOF(){t.apply(this,arguments)}return r(EOF,t),EOF}(c);e.EOF=u},function(t,e,n){"use strict";var r=n(12),i=n(4);!function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND"}(e.LexerDefinitionErrorType||(e.LexerDefinitionErrorType={}));var o=(e.LexerDefinitionErrorType,function(){function Lexer(t,e){if(void 0===e&&(e=!1),this.tokenClasses=t,this.lexerDefinitionErrors=[],this.lexerDefinitionErrors=r.validatePatterns(t),!i.isEmpty(this.lexerDefinitionErrors)&&!e){var n=i.map(this.lexerDefinitionErrors,function(t){return t.message}),o=n.join("-----------------------\n");throw new Error("Errors detected in definition of Lexer:\n"+o)}if(i.isEmpty(this.lexerDefinitionErrors)){var a=r.analyzeTokenClasses(t);this.allPatterns=a.allPatterns,this.patternIdxToClass=a.patternIdxToClass,this.patternIdxToGroup=a.patternIdxToGroup,this.patternIdxToLongerAltIdx=a.patternIdxToLongerAltIdx,this.patternIdxToCanLineTerminator=a.patternIdxToCanLineTerminator,this.emptyGroups=a.emptyGroups}}return Lexer.prototype.tokenize=function(t){var e,n,o,a,s,c,u,l,p,f,h,d,E,A,T,y,O,N,R=t,_=0,g=[],m=[],v=1,S=1,P=i.cloneObj(this.emptyGroups);if(!i.isEmpty(this.lexerDefinitionErrors)){var L=i.map(this.lexerDefinitionErrors,function(t){return t.message}),k=L.join("-----------------------\n");throw new Error("Unable to Tokenize because Errors detected in definition of Lexer:\n"+k)}for(;t.length>0;){for(e=null,n=0;ne[0].length&&(e=a,n=s));break}if(null!==e){if(c=e[0],u=c.length,l=this.patternIdxToGroup[n],void 0!==l&&(p=this.patternIdxToClass[n],f=new p(c,_,v,S),"default"===l?g.push(f):P[l].push(f)),t=t.slice(u),_+=u,S+=u,d=this.patternIdxToCanLineTerminator[n]){var I=r.countLineTerminators(c);if(0!==I){for(v+=I,y=u-1;y>=0&&(A=c.charCodeAt(y),13!==A&&10!==A);)y--;S=u-y,void 0!==l&&(N=y===u-1,E=N?-1:0,1===I&&N||(f.endLine=v+E,f.endColumn=S-1+-E))}}}else{for(var x=_,F=v,C=S,w=!1;!w&&t.length>0;)for(T=t.charCodeAt(0),10===T||13===T&&(1===t.length||t.length>1&&10!==t.charCodeAt(1))?(v++,S=1):S++,t=t.substr(1),_++,o=0;o"+R.charAt(x)+"<- at offset: "+x+","+(" skipped "+(_-x)+" characters."),m.push({line:F,column:C,length:h,message:O})}}return{tokens:g,groups:P,errors:m}},Lexer.SKIPPED={description:"This marks a skipped Token pattern, this means each token identified by it willbe consumed and then throw into oblivion, this can be used to for example: skip whitespace."},Lexer.NA=/NOT_APPLICABLE/,Lexer}());e.Lexer=o},function(t,e,n){"use strict";function analyzeTokenClasses(t){var e=o.reject(t,function(t){return t[a]===i.Lexer.NA}),n=o.map(e,function(t){return addStartOfInput(t[a])}),r=o.zipObject(n,e),s=o.map(n,function(t){return r[t.toString()]}),c=o.map(e,function(t){var e=t.GROUP;if(e!==i.Lexer.SKIPPED){if(o.isString(e))return e;if(o.isUndefined(e))return"default";throw Error("non exhaustive match")}}),u=o.map(e,function(t){var n=t.LONGER_ALT;if(n){var r=o.indexOf(e,n);return r}}),l=o.map(n,function(t){return/\\n|\\r|\\s/g.test(t.source)}),p=o.reduce(e,function(t,e){var n=e.GROUP;return o.isString(n)&&(t[n]=[]),t},{});return{allPatterns:n,patternIdxToClass:s,patternIdxToGroup:c,patternIdxToLongerAltIdx:u,patternIdxToCanLineTerminator:l,emptyGroups:p}}function validatePatterns(t){var e=[],n=findMissingPatterns(t),r=n.validTokenClasses;e=e.concat(n.errors);var i=findInvalidPatterns(r);return r=i.validTokenClasses,e=e.concat(i.errors),e=e.concat(findEndOfInputAnchor(r)),e=e.concat(findUnsupportedFlags(r)),e=e.concat(findDuplicatePatterns(r)),e=e.concat(findInvalidGroupType(r))}function findMissingPatterns(t){var e=o.filter(t,function(t){return!o.has(t,a)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- missing static 'PATTERN' property",type:i.LexerDefinitionErrorType.MISSING_PATTERN,tokenClasses:[t]}}),s=o.difference(t,e);return{errors:n,validTokenClasses:s}}function findInvalidPatterns(t){var e=o.filter(t,function(t){var e=t[a];return!o.isRegExp(e)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'PATTERN' can only be a RegExp",type:i.LexerDefinitionErrorType.INVALID_PATTERN,tokenClasses:[t]}}),s=o.difference(t,e);return{errors:n,validTokenClasses:s}}function findEndOfInputAnchor(t){var e=o.filter(t,function(t){var e=t[a];return s.test(e.source)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'PATTERN' cannot contain end of input anchor '$'",type:i.LexerDefinitionErrorType.EOI_ANCHOR_FOUND,tokenClasses:[t]}});return n}function findUnsupportedFlags(t){var e=o.filter(t,function(t){var e=t[a];return e instanceof RegExp&&(e.multiline||e.global)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:i.LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND,tokenClasses:[t]}});return n}function findDuplicatePatterns(t){var e=[],n=o.map(t,function(n){return o.reduce(t,function(t,r){return n.PATTERN.source!==r.PATTERN.source||o.contains(e,r)||r.PATTERN===i.Lexer.NA?t:(e.push(r),t.push(r),t)},[])});n=o.compact(n);var a=o.filter(n,function(t){return t.length>1}),s=o.map(a,function(t){var e=o.map(t,function(t){return r.tokenName(t)}),n=o.first(t).PATTERN;return{message:"The same RegExp pattern ->"+n+"<-"+("has been used in all the following classes: "+e.join(", ")+" <-"),type:i.LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND,tokenClasses:t}});return s}function findInvalidGroupType(t){var e=o.filter(t,function(t){if(!o.has(t,"GROUP"))return!1;var e=t.GROUP;return e!==i.Lexer.SKIPPED&&e!==i.Lexer.NA&&!o.isString(e)}),n=o.map(e,function(t){return{message:"Token class: ->"+r.tokenName(t)+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:i.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND,tokenClasses:[t]}});return n}function addStartOfInput(t){var e=t.ignoreCase?"i":"";return new RegExp("^(?:"+t.source+")",e)}function countLineTerminators(t){for(var e=0,n=0;na,c=!0;s&&c;)e=r[a],c=i.isOptionalProd(e),n=n.concat(first(e)),a+=1,s=r.length>a;return o.uniq(n)}function firstForBranching(t){var e=o.map(t.definition,function(t){return first(t)});return o.uniq(o.flatten(e))}function firstForTerminal(t){return[t.terminalType]}var r=n(7),i=n(9),o=n(4);e.first=first,e.firstForSequence=firstForSequence,e.firstForBranching=firstForBranching,e.firstForTerminal=firstForTerminal},function(t,e,n){"use strict";function computeAllProdsFollows(t){var e=new o.HashTable;return c.forEach(t,function(t){var n=new p(t).startWalking();e.putAll(n)}),e}function buildBetweenProdsFollowPrefix(t,e){return t.name+e+u.IN}function buildInProdFollowPrefix(t){var e=l.tokenName(t.terminalType);return e+t.occurrenceInParent+u.IN}var r=this&&this.__extends||function(t,e){function __(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)},i=n(15),o=n(3),a=n(7),s=n(13),c=n(4),u=n(16),l=n(10),p=function(t){function ResyncFollowsWalker(e){t.call(this),this.topProd=e,this.follows=new o.HashTable}return r(ResyncFollowsWalker,t),ResyncFollowsWalker.prototype.startWalking=function(){return this.walk(this.topProd),this.follows},ResyncFollowsWalker.prototype.walkTerminal=function(t,e,n){},ResyncFollowsWalker.prototype.walkProdRef=function(t,e,n){var r=buildBetweenProdsFollowPrefix(t.referencedRule,t.occurrenceInParent)+this.topProd.name,i=e.concat(n),o=new a.gast.Flat(i),c=s.first(o);this.follows.put(r,c)},ResyncFollowsWalker}(i.RestWalker);e.ResyncFollowsWalker=p,e.computeAllProdsFollows=computeAllProdsFollows,e.buildBetweenProdsFollowPrefix=buildBetweenProdsFollowPrefix,e.buildInProdFollowPrefix=buildInProdFollowPrefix},function(t,e,n){"use strict";function restForRepetitionWithSeparator(t,e,n){var i=[new r.gast.Option([new r.gast.Terminal(t.separator)].concat(t.definition))],o=i.concat(e,n);return o}var r=n(7),i=n(4),o=function(){function RestWalker(){}return RestWalker.prototype.walk=function(t,e){var n=this;void 0===e&&(e=[]),i.forEach(t.definition,function(o,a){var s=i.drop(t.definition,a+1);if(o instanceof r.gast.NonTerminal)n.walkProdRef(o,s,e);else if(o instanceof r.gast.Terminal)n.walkTerminal(o,s,e);else if(o instanceof r.gast.Flat)n.walkFlat(o,s,e);else if(o instanceof r.gast.Option)n.walkOption(o,s,e);else if(o instanceof r.gast.RepetitionMandatory)n.walkAtLeastOne(o,s,e);else if(o instanceof r.gast.RepetitionMandatoryWithSeparator)n.walkAtLeastOneSep(o,s,e);else if(o instanceof r.gast.RepetitionWithSeparator)n.walkManySep(o,s,e);else if(o instanceof r.gast.Repetition)n.walkMany(o,s,e);else{if(!(o instanceof r.gast.Alternation))throw Error("non exhaustive match");n.walkOr(o,s,e)}})},RestWalker.prototype.walkTerminal=function(t,e,n){},RestWalker.prototype.walkProdRef=function(t,e,n){},RestWalker.prototype.walkFlat=function(t,e,n){var r=e.concat(n);this.walk(t,r)},RestWalker.prototype.walkOption=function(t,e,n){var r=e.concat(n);this.walk(t,r)},RestWalker.prototype.walkAtLeastOne=function(t,e,n){var i=[new r.gast.Option(t.definition)].concat(e,n);this.walk(t,i)},RestWalker.prototype.walkAtLeastOneSep=function(t,e,n){var r=restForRepetitionWithSeparator(t,e,n);this.walk(t,r)},RestWalker.prototype.walkMany=function(t,e,n){var i=[new r.gast.Option(t.definition)].concat(e,n);this.walk(t,i)},RestWalker.prototype.walkManySep=function(t,e,n){var r=restForRepetitionWithSeparator(t,e,n);this.walk(t,r)},RestWalker.prototype.walkOr=function(t,e,n){var o=this,a=e.concat(n);i.forEach(t.definition,function(t){var e=new r.gast.Flat([t]);o.walk(e,a)})},RestWalker}();e.RestWalker=o},function(t,e){"use strict";e.IN="_~IN~_"},function(t,e,n){"use strict";function buildLookaheadForTopLevel(t){var e=new r.gast.Flat(t.definition),n=i.first(e);return getSimpleLookahead(n)}function buildLookaheadForOption(t,e){return buildLookAheadForGrammarProd(o.NextInsideOptionWalker,t,e)}function buildLookaheadForMany(t,e){return buildLookAheadForGrammarProd(o.NextInsideManyWalker,t,e)}function buildLookaheadForManySep(t,e){return buildLookAheadForGrammarProd(o.NextInsideManySepWalker,t,e)}function buildLookaheadForAtLeastOne(t,e){return buildLookAheadForGrammarProd(o.NextInsideAtLeastOneWalker,t,e)}function buildLookaheadForAtLeastOneSep(t,e){return buildLookAheadForGrammarProd(o.NextInsideAtLeastOneSepWalker,t,e)}function buildLookaheadForOr(t,e,n){void 0===n&&(n=!1);var r=new o.NextInsideOrWalker(e,t).startWalking();n||checkForOrAmbiguities(r,t,e);var i=a.isEmpty(a.last(r));if(i){var s=r.length-1;return function(){for(var t=this.NEXT_TOKEN(),e=0;s>e;e++)for(var n=r[e],i=0;i in inside <"+n.name+"> "+("Rule, <"+s.tokenName(t.token)+"> may appears as the first Terminal in all these alternatives.\n")});throw new Error(i.join("\n ---------------- \n")+"To Resolve this, either: \n1. refactor your grammar to be LL(1)\n2. provide explicit lookahead functions in the form {WHEN:laFunc, THEN_DO:...}\n3. Add ignore arg to this OR Production:\nOR([], 'msg', recognizer.IGNORE_AMBIGUITIES)\nIn that case the parser will always pick the first alternative that matches and ignore all the others")}}function checkAlternativesAmbiguities(t){var e=a.flatten(t),n=a.uniq(e),r=a.map(n,function(e){var n=a.pick(t,function(t){return a.find(t,function(t){return t===e})}),r=a.map(a.keys(n),function(t){return parseInt(t,10)+1});return{token:e,alts:r}}),i=a.filter(r,function(t){return t.alts.length>1});return i}function buildLookAheadForGrammarProd(t,e,n){var r={ruleStack:[n.name],occurrenceStack:[1],occurrence:e},i=new t(n,r),o=i.startWalking();return getSimpleLookahead(o)}function getSimpleLookahead(t){return function(){for(var e=this.NEXT_TOKEN(),n=0;nt||t>e)}var n=function(){function Range(t,e){if(this.start=t,this.end=e,!isValidRange(t,e))throw new Error("INVALID RANGE")}return Range.prototype.contains=function(t){return this.start<=t&&this.end>=t},Range.prototype.containsRange=function(t){return this.start<=t.start&&this.end>=t.end},Range.prototype.isContainedInRange=function(t){return t.containsRange(this)},Range.prototype.strictlyContainsRange=function(t){return this.startt.end},Range.prototype.isStrictlyContainedInRange=function(t){return t.strictlyContainsRange(this)},Range}();e.Range=n,e.isValidRange=isValidRange},function(t,e,n){"use strict";function clearCache(){r.clearCache()}var r=n(2);e.clearCache=clearCache}])}); \ No newline at end of file diff --git a/src/api.ts b/src/api.ts index 31086a39a..99b682293 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,7 +12,7 @@ import {clearCache} from "./parse/cache_public" let API:any = {} // semantic version -API.VERSION = "0.5.18" +API.VERSION = "0.5.19" // runtime API API.Parser = Parser