From a5da06ed0807383cefb321c5c009f9215e2f3339 Mon Sep 17 00:00:00 2001 From: Shahar Soel Date: Sun, 3 Jan 2016 00:30:09 +0200 Subject: [PATCH] release 0.5.13 --- .travis.yml | 4 +- bower.json | 3 +- package.json | 2 +- readme.md | 2 +- release/chevrotain.d.ts | 2 +- release/chevrotain.js | 190 ++++++++++++++++++-------------------- release/chevrotain.min.js | 10 +- src/api.ts | 2 +- 8 files changed, 104 insertions(+), 111 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3290e4233..13facfb3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,8 +50,8 @@ deploy: api_key: secure: DNq1wbqLPHVpJPDx9O89HZM+RJB6v2R7/wk8pok7Z8NT72kUWdvbqcThGhczPO4sZ8cUTJ3ergTCE8hs9mynlR/lX6932U4fj4+uICQL9+G+deBB/t2SNyTBllkE64WrJ9BKmQvIk/Chh7ZJOM0Fro3p2BIq3JsVnfYg1tZ3U5o= file: - - package/chevrotain-binaries-0.5.12.zip - - package/chevrotain-binaries-0.5.12.tar.gz + - package/chevrotain-binaries-0.5.13.zip + - package/chevrotain-binaries-0.5.13.tar.gz on: tags : true all_branches: true diff --git a/bower.json b/bower.json index df6d9ee92..f434129ac 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "chevrotain", - "version": "0.5.12", + "version": "0.5.13", "description": "Chevrotain is a high performance fault Tolerant Javascript parsing DSL for building recursive decent parsers", "main": "release/chevrotain.js", "dependencies": { @@ -43,7 +43,6 @@ "!release/*.*", "!readme.md", "!LICENSE.txt" - ], "license": "Apache-2.0" } diff --git a/package.json b/package.json index 962c88f17..c67eeebd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chevrotain", - "version": "0.5.12", + "version": "0.5.13", "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 c24403012..35c3d138d 100644 --- a/readme.md +++ b/readme.md @@ -57,7 +57,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_12/classes/chevrotain.parser.html#at_least_one) + * [Parsing DSL](http://sap.github.io/chevrotain/documentation/0_5_13/classes/chevrotain.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 0670c50c6..ea33a0c18 100644 --- a/release/chevrotain.d.ts +++ b/release/chevrotain.d.ts @@ -1,4 +1,4 @@ -/*! chevrotain - v0.5.12 - 2016-01-02 */ +/*! chevrotain - v0.5.13 - 2016-01-03 */ declare module chevrotain { module lang { class HashTable{} diff --git a/release/chevrotain.js b/release/chevrotain.js index def802010..6fdd30bc7 100644 --- a/release/chevrotain.js +++ b/release/chevrotain.js @@ -15,7 +15,44 @@ } }(this, function (_) { -/*! chevrotain - v0.5.12 - 2016-01-02 */ +/*! chevrotain - v0.5.13 - 2016-01-03 */ +/* + 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... + but for the purpose of being a dependency free library. + + The hotspots in the code are already written in imperative style for performance reasons. + so writing several dozen utils which may be slower than the original lodash, does not matter as much + considering they will not be invoked in hotspots... + */ +var utils; +(function (utils) { + function isEmpty(arr) { + return arr.length === 0; + } + utils.isEmpty = isEmpty; + function keys(obj) { + return Object.keys(obj); + } + utils.keys = keys; + function values(obj) { + var vals = []; + var keys = Object.keys(obj); + for (var i = 0; i < keys.length; i++) { + vals.push(obj[keys[i]]); + } + return vals; + } + utils.values = values; + function map(arr, callback) { + var result = []; + for (var idx = 0; idx < arr.length; idx++) { + result.push(callback.call(null, arr[idx], idx)); + } + return result; + } + utils.map = map; +})(utils || (utils = {})); var chevrotain; (function (chevrotain) { var lang; @@ -53,10 +90,10 @@ var chevrotain; this._state = {}; } HashTable.prototype.keys = function () { - return _.keys(this._state); + return utils.keys(this._state); }; HashTable.prototype.values = function () { - return _.values(this._state); + return utils.values(this._state); }; HashTable.prototype.put = function (key, value) { this._state[key] = value; @@ -268,8 +305,8 @@ var chevrotain; this.tokenClasses = tokenClasses; this.lexerDefinitionErrors = []; this.lexerDefinitionErrors = chevrotain.validatePatterns(tokenClasses); - if (!_.isEmpty(this.lexerDefinitionErrors) && !deferDefinitionErrorsHandling) { - var allErrMessages = _.map(this.lexerDefinitionErrors, function (error) { + if (!utils.isEmpty(this.lexerDefinitionErrors) && !deferDefinitionErrorsHandling) { + var allErrMessages = utils.map(this.lexerDefinitionErrors, function (error) { return error.message; }); var allErrMessagesString = allErrMessages.join("-----------------------\n"); @@ -278,7 +315,7 @@ var chevrotain; // If definition errors were encountered, the analysis phase may fail unexpectedly/ // Considering a lexer with definition errors may never be used, there is no point // to performing the analysis anyhow... - if (_.isEmpty(this.lexerDefinitionErrors)) { + if (utils.isEmpty(this.lexerDefinitionErrors)) { var analyzeResult = chevrotain.analyzeTokenClasses(tokenClasses); this.allPatterns = analyzeResult.allPatterns; this.patternIdxToClass = analyzeResult.patternIdxToClass; @@ -305,8 +342,8 @@ var chevrotain; var line = 1; var column = 1; var groups = _.clone(this.emptyGroups); - if (!_.isEmpty(this.lexerDefinitionErrors)) { - var allErrMessages = _.map(this.lexerDefinitionErrors, function (error) { + if (!utils.isEmpty(this.lexerDefinitionErrors)) { + var allErrMessages = utils.map(this.lexerDefinitionErrors, function (error) { return error.message; }); var allErrMessagesString = allErrMessages.join("-----------------------\n"); @@ -432,14 +469,14 @@ var chevrotain; var onlyRelevantClasses = _.reject(tokenClasses, function (currClass) { return currClass[PATTERN] === chevrotain.Lexer.NA; }); - var allTransformedPatterns = _.map(onlyRelevantClasses, function (currClass) { + var allTransformedPatterns = utils.map(onlyRelevantClasses, function (currClass) { return addStartOfInput(currClass[PATTERN]); }); var allPatternsToClass = _.zipObject(allTransformedPatterns, onlyRelevantClasses); - var patternIdxToClass = _.map(allTransformedPatterns, function (pattern) { + var patternIdxToClass = utils.map(allTransformedPatterns, function (pattern) { return allPatternsToClass[pattern.toString()]; }); - var patternIdxToGroup = _.map(onlyRelevantClasses, function (clazz) { + var patternIdxToGroup = utils.map(onlyRelevantClasses, function (clazz) { var groupName = clazz.GROUP; if (groupName === chevrotain.Lexer.SKIPPED) { return undefined; @@ -454,14 +491,14 @@ var chevrotain; /* istanbul ignore next */ throw Error("non exhaustive match"); } }); - var patternIdxToLongerAltIdx = _.map(onlyRelevantClasses, function (clazz, idx) { + var patternIdxToLongerAltIdx = utils.map(onlyRelevantClasses, function (clazz) { var longerAltClass = clazz.LONGER_ALT; if (longerAltClass) { var longerAltIdx = _.indexOf(onlyRelevantClasses, longerAltClass); return longerAltIdx; } }); - var patternIdxToCanLineTerminator = _.map(allTransformedPatterns, function (pattern) { + var patternIdxToCanLineTerminator = utils.map(allTransformedPatterns, function (pattern) { // TODO: unicode escapes of line terminators too? return /\\n|\\r|\\s/g.test(pattern.source); }); @@ -501,7 +538,7 @@ var chevrotain; var tokenClassesWithMissingPattern = _.filter(tokenClasses, function (currClass) { return !_.has(currClass, PATTERN); }); - var errors = _.map(tokenClassesWithMissingPattern, function (currClass) { + var errors = utils.map(tokenClassesWithMissingPattern, function (currClass) { return { message: "Token class: ->" + chevrotain.tokenName(currClass) + "<- missing static 'PATTERN' property", type: chevrotain.LexerDefinitionErrorType.MISSING_PATTERN, @@ -517,7 +554,7 @@ var chevrotain; var pattern = currClass[PATTERN]; return !_.isRegExp(pattern); }); - var errors = _.map(tokenClassesWithInvalidPattern, function (currClass) { + var errors = utils.map(tokenClassesWithInvalidPattern, function (currClass) { return { message: "Token class: ->" + chevrotain.tokenName(currClass) + "<- static 'PATTERN' can only be a RegExp", type: chevrotain.LexerDefinitionErrorType.INVALID_PATTERN, @@ -534,7 +571,7 @@ var chevrotain; var pattern = currClass[PATTERN]; return end_of_input.test(pattern.source); }); - var errors = _.map(invalidRegex, function (currClass) { + var errors = utils.map(invalidRegex, function (currClass) { return { message: "Token class: ->" + chevrotain.tokenName(currClass) + "<- static 'PATTERN' cannot contain end of input anchor '$'", type: chevrotain.LexerDefinitionErrorType.EOI_ANCHOR_FOUND, @@ -549,7 +586,7 @@ var chevrotain; var pattern = currClass[PATTERN]; return pattern instanceof RegExp && (pattern.multiline || pattern.global); }); - var errors = _.map(invalidFlags, function (currClass) { + var errors = utils.map(invalidFlags, function (currClass) { return { message: "Token class: ->" + chevrotain.tokenName(currClass) + "<- static 'PATTERN' may NOT contain global('g') or multiline('m')", @@ -563,7 +600,7 @@ var chevrotain; // This can only test for identical duplicate RegExps, not semantically equivalent ones. function findDuplicatePatterns(tokenClasses) { var found = []; - var identicalPatterns = _.map(tokenClasses, function (outerClass) { + var identicalPatterns = utils.map(tokenClasses, function (outerClass) { return _.reduce(tokenClasses, function (result, innerClass) { if ((outerClass.PATTERN.source === innerClass.PATTERN.source) && !_.contains(found, innerClass) && innerClass.PATTERN !== chevrotain.Lexer.NA) { @@ -579,8 +616,8 @@ var chevrotain; var duplicatePatterns = _.filter(identicalPatterns, function (currIdenticalSet) { return _.size(currIdenticalSet) > 1; }); - var errors = _.map(duplicatePatterns, function (setOfIdentical) { - var classNames = _.map(setOfIdentical, function (currClass) { + var errors = utils.map(duplicatePatterns, function (setOfIdentical) { + var classNames = utils.map(setOfIdentical, function (currClass) { return chevrotain.tokenName(currClass); }); var dupPatternSrc = _.first(setOfIdentical).PATTERN; @@ -603,7 +640,7 @@ var chevrotain; return group !== chevrotain.Lexer.SKIPPED && group !== chevrotain.Lexer.NA && !_.isString(group); }); - var errors = _.map(invalidTypes, function (currClass) { + var errors = utils.map(invalidTypes, function (currClass) { return { message: "Token class: ->" + chevrotain.tokenName(currClass) + "<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String", type: chevrotain.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND, @@ -642,50 +679,6 @@ var chevrotain; } chevrotain.countLineTerminators = countLineTerminators; })/* istanbul ignore next */ (chevrotain || (chevrotain = {})); -// todo: consider if this namespace really belongs in chevrotain? -var chevrotain; -(function (chevrotain) { - var tree; - (function (tree) { - var ParseTree = (function () { - function ParseTree(payload, children) { - if (children === void 0) { children = []; } - this.payload = payload; - this.children = children; - } - ParseTree.prototype.getImage = function () { return this.payload.image; }; - ParseTree.prototype.getLine = function () { return this.payload.startLine; }; - ParseTree.prototype.getColumn = function () { return this.payload.startColumn; }; - return ParseTree; - })(); - tree.ParseTree = ParseTree; - /** - * convenience factory for ParseTrees - * - * @param {Function|Token} tokenOrTokenClass The Token instance to be used as the root node, or a constructor Function - * that will create the root node. - * @param {ParseTree[]} children The sub nodes of the ParseTree to the built - * @returns {ParseTree} - */ - function PT(tokenOrTokenClass, children) { - if (children === void 0) { children = []; } - var childrenCompact = _.compact(children); - if (tokenOrTokenClass instanceof chevrotain.Token) { - return new ParseTree(tokenOrTokenClass, childrenCompact); - } - else if (_.isFunction(tokenOrTokenClass)) { - return new ParseTree(new tokenOrTokenClass(), childrenCompact); - } - else if (_.isUndefined(tokenOrTokenClass) || _.isNull(tokenOrTokenClass)) { - return null; - } - else { - throw "Invalid parameter " + tokenOrTokenClass + " to PT factory."; - } - } - tree.PT = PT; - })/* istanbul ignore next */ (tree = chevrotain.tree || /* istanbul ignore next */ (chevrotain.tree = {})); -})/* istanbul ignore next */ (chevrotain || (chevrotain = {})); var chevrotain; (function (chevrotain) { var range; @@ -1040,7 +1033,7 @@ var chevrotain; } first_1.firstForSequence = firstForSequence; function firstForBranching(prod) { - var allAlternativesFirsts = _.map(prod.definition, function (innerProd) { + var allAlternativesFirsts = utils.map(prod.definition, function (innerProd) { return first(innerProd); }); return _.uniq(_.flatten(allAlternativesFirsts)); @@ -1262,7 +1255,7 @@ var chevrotain; }; AbstractNextPossibleTokensWalker.prototype.updateExpectedNext = function () { // need to consume the Terminal - if (_.isEmpty(this.ruleStack)) { + if (utils.isEmpty(this.ruleStack)) { // must reset nextProductionXXX to avoid walking down another Top Level production while what we are // really seeking is the last Terminal... this.nextProductionName = ""; @@ -1418,7 +1411,7 @@ var chevrotain; }; NextInsideOrWalker.prototype.walkOr = function (orProd, currRest, prevRest) { if (orProd.occurrenceInParent === this.occurrence) { - this.result = _.map(orProd.definition, function (alt) { + this.result = utils.map(orProd.definition, function (alt) { var altWrapper = new chevrotain.gast.Flat([alt]); return f.first(altWrapper); }); @@ -1648,7 +1641,7 @@ var chevrotain; if (!ignoreAmbiguities) { checkForOrAmbiguities(alternativesTokens, orOccurrence, ruleGrammar); } - var hasLastAnEmptyAlt = _.isEmpty(_.last(alternativesTokens)); + var hasLastAnEmptyAlt = utils.isEmpty(_.last(alternativesTokens)); if (hasLastAnEmptyAlt) { var lastIdx = alternativesTokens.length - 1; /** @@ -1692,8 +1685,8 @@ var chevrotain; lookahead.buildLookaheadForOr = buildLookaheadForOr; function checkForOrAmbiguities(alternativesTokens, orOccurrence, ruleGrammar) { var altsAmbiguityErrors = checkAlternativesAmbiguities(alternativesTokens); - if (!_.isEmpty(altsAmbiguityErrors)) { - var errorMessages = _.map(altsAmbiguityErrors, function (currAmbiguity) { + if (!utils.isEmpty(altsAmbiguityErrors)) { + var errorMessages = utils.map(altsAmbiguityErrors, function (currAmbiguity) { return ("Ambiguous alternatives: <" + currAmbiguity.alts.join(" ,") + "> in inside <" + ruleGrammar.name + "> ") + ("Rule, <" + chevrotain.tokenName(currAmbiguity.token) + "> may appears as the first Terminal in all these alternatives.\n"); }); @@ -1711,13 +1704,13 @@ var chevrotain; function checkAlternativesAmbiguities(alternativesTokens) { var allTokensFlat = _.flatten(alternativesTokens); var uniqueTokensFlat = _.uniq(allTokensFlat); - var tokensToAltsIndicesItAppearsIn = _.map(uniqueTokensFlat, function (seekToken) { + var tokensToAltsIndicesItAppearsIn = utils.map(uniqueTokensFlat, function (seekToken) { var altsCurrTokenAppearsIn = _.pick(alternativesTokens, function (altToLookIn) { return _.find(altToLookIn, function (currToken) { return currToken === seekToken; }); }); - var altsIndicesTokenAppearsIn = _.map(_.keys(altsCurrTokenAppearsIn), function (index) { + var altsIndicesTokenAppearsIn = utils.map(utils.keys(altsCurrTokenAppearsIn), function (index) { return parseInt(index, 10) + 1; }); return { token: seekToken, alts: altsIndicesTokenAppearsIn }; @@ -2035,7 +2028,7 @@ var chevrotain; function findClosingOffset(opening, closing, start, text) { var parenthesisStack = [1]; var i = -1; - while (!(_.isEmpty(parenthesisStack)) && i + start < text.length) { + while (!(utils.isEmpty(parenthesisStack)) && i + start < text.length) { i++; var nextChar = text.charAt(start + i); if (nextChar === opening) { @@ -2046,7 +2039,7 @@ var chevrotain; } } // valid termination of the search loop - if (_.isEmpty(parenthesisStack)) { + if (utils.isEmpty(parenthesisStack)) { return i + start; } else { @@ -2063,9 +2056,9 @@ var chevrotain; var gast = chevrotain.gast; var GAstVisitor = chevrotain.gast.GAstVisitor; function validateGrammar(topLevels) { - var duplicateErrors = _.map(topLevels, validateDuplicateProductions); - var leftRecursionErrors = _.map(topLevels, function (currTopRule) { return validateNoLeftRecursion(currTopRule, currTopRule); }); - var emptyAltErrors = _.map(topLevels, validateEmptyOrAlternative); + var duplicateErrors = utils.map(topLevels, validateDuplicateProductions); + var leftRecursionErrors = utils.map(topLevels, function (currTopRule) { return validateNoLeftRecursion(currTopRule, currTopRule); }); + var emptyAltErrors = utils.map(topLevels, validateEmptyOrAlternative); return _.flatten(duplicateErrors.concat(leftRecursionErrors, emptyAltErrors)); } checks.validateGrammar = validateGrammar; @@ -2077,7 +2070,7 @@ var chevrotain; var duplicates = _.pick(productionGroups, function (currGroup) { return currGroup.length > 1; }); - var errors = _.map(duplicates, function (currDuplicates) { + var errors = utils.map(utils.values(duplicates), function (currDuplicates) { var firstProd = _.first(currDuplicates); var msg = createDuplicatesErrorMessage(currDuplicates, topLevelRule.name); var dslName = gast.getProductionDslName(firstProd); @@ -2182,13 +2175,13 @@ var chevrotain; if (path === void 0) { path = []; } var errors = []; var nextNonTerminals = getFirstNoneTerminal(currRule.definition); - if (_.isEmpty(nextNonTerminals)) { + if (utils.isEmpty(nextNonTerminals)) { return []; } else { var ruleName = topRule.name; var foundLeftRecursion = _.contains(nextNonTerminals, topRule); - var pathNames = _.map(path, function (currRule) { return currRule.name; }); + var pathNames = utils.map(path, function (currRule) { return currRule.name; }); var leftRecursivePath = ruleName + " --> " + pathNames.concat([ruleName]).join(" --> "); if (foundLeftRecursion) { var errMsg = "Left Recursion found in grammar.\n" + @@ -2205,7 +2198,7 @@ var chevrotain; // we are only looking for cyclic paths leading back to the specific topRule // other cyclic paths are ignored, we still need this difference to avoid infinite loops... var validNextSteps = _.difference(nextNonTerminals, path.concat([topRule])); - var errorsFromNextSteps = _.map(validNextSteps, function (currRefRule, key, all) { + var errorsFromNextSteps = utils.map(validNextSteps, function (currRefRule) { var newPath = _.clone(path); newPath.push(currRefRule); return validateNoLeftRecursion(topRule, currRefRule, newPath); @@ -2216,7 +2209,7 @@ var chevrotain; checks.validateNoLeftRecursion = validateNoLeftRecursion; function getFirstNoneTerminal(definition) { var result = []; - if (_.isEmpty(definition)) { + if (utils.isEmpty(definition)) { return result; } var firstProd = _.first(definition); @@ -2237,7 +2230,7 @@ var chevrotain; } else if (firstProd instanceof gast.Alternation) { // each sub definition in alternation is a FLAT - result = _.flatten(_.map(firstProd.definition, function (currSubDef) { return getFirstNoneTerminal(currSubDef.definition); })); + result = _.flatten(utils.map(firstProd.definition, function (currSubDef) { return getFirstNoneTerminal(currSubDef.definition); })); }/* istanbul ignore else */ else if (firstProd instanceof gast.Terminal) { } @@ -2272,8 +2265,8 @@ var chevrotain; var ors = orCollector.alternations; var errors = _.reduce(ors, function (errors, currOr) { var exceptLast = _.dropRight(currOr.definition); - var currErrors = _.map(exceptLast, function (currAlternative, currAltIdx) { - if (_.isEmpty(chevrotain.first.first(currAlternative))) { + var currErrors = utils.map(exceptLast, function (currAlternative, currAltIdx) { + if (utils.isEmpty(chevrotain.first.first(currAlternative))) { return { message: ("Ambiguous empty alternative: <" + (currAltIdx + 1) + ">") + (" in inside <" + topLevelRule.name + "> Rule.\n") + @@ -2525,18 +2518,18 @@ var chevrotain; cache.CLASS_TO_SELF_ANALYSIS_DONE.put(className, true); var validationErrors = checks.validateGrammar(grammarProductions.values()); definitionErrors.push.apply(definitionErrors, validationErrors); // mutability for the win? - if (!_.isEmpty(definitionErrors) && !Parser.DEFER_DEFINITION_ERRORS_HANDLING) { - defErrorsMsgs = _.map(definitionErrors, function (defError) { return defError.message; }); + if (!utils.isEmpty(definitionErrors) && !Parser.DEFER_DEFINITION_ERRORS_HANDLING) { + defErrorsMsgs = utils.map(definitionErrors, function (defError) { return defError.message; }); throw new Error("Parser Definition Errors detected\n: " + defErrorsMsgs.join("\n-------------------------------\n")); } - if (_.isEmpty(definitionErrors)) { + if (utils.isEmpty(definitionErrors)) { var allFollows = follows.computeAllProdsFollows(grammarProductions.values()); cache.setResyncFollowsForClass(className, allFollows); } } // reThrow the validation errors each time an erroneous parser is instantiated - if (!_.isEmpty(cache.CLASS_TO_DEFINITION_ERRORS.get(className)) && !Parser.DEFER_DEFINITION_ERRORS_HANDLING) { - defErrorsMsgs = _.map(cache.CLASS_TO_DEFINITION_ERRORS.get(className), function (defError) { return defError.message; }); + if (!utils.isEmpty(cache.CLASS_TO_DEFINITION_ERRORS.get(className)) && !Parser.DEFER_DEFINITION_ERRORS_HANDLING) { + defErrorsMsgs = utils.map(cache.CLASS_TO_DEFINITION_ERRORS.get(className), function (defError) { return defError.message; }); throw new Error("Parser Definition Errors detected\n: " + defErrorsMsgs.join("\n-------------------------------\n")); } }; @@ -2566,7 +2559,7 @@ var chevrotain; return cache.getProductionsForClass(this.className); }; Parser.prototype.isBackTracking = function () { - return !(_.isEmpty(this.isBackTrackingStack)); + return !(utils.isEmpty(this.isBackTrackingStack)); }; Parser.prototype.SAVE_ERROR = function (error) { if (exceptions.isRecognitionException(error)) { @@ -3329,7 +3322,7 @@ var chevrotain; return false; } // must know the possible following tokens to perform single token insertion - if (_.isEmpty(follows)) { + if (utils.isEmpty(follows)) { return false; } var mismatchedTok = this.NEXT_TOKEN(); @@ -3377,7 +3370,7 @@ var chevrotain; }; Parser.prototype.buildFullFollowKeyStack = function () { var _this = this; - return _.map(this.RULE_STACK, function (ruleName, idx) { + return utils.map(this.RULE_STACK, function (ruleName, idx) { if (idx === 0) { return EOF_FOLLOW_KEY; } @@ -3390,7 +3383,7 @@ var chevrotain; }; Parser.prototype.flattenFollowSet = function () { var _this = this; - var followStack = _.map(this.buildFullFollowKeyStack(), function (currKey) { + var followStack = utils.map(this.buildFullFollowKeyStack(), function (currKey) { return _this.getFollowSetFromFollowKey(currKey); }); return _.flatten(followStack); @@ -3693,7 +3686,7 @@ var chevrotain; var ruleGrammar = this.getGAstProductions().get(ruleName); var nextTokens = new interp.NextInsideOrWalker(ruleGrammar, occurrence).startWalking(); var nextTokensFlat = _.flatten(nextTokens); - var nextTokensNames = _.map(nextTokensFlat, function (currTokenClass) { return chevrotain.tokenName(currTokenClass); }); + var nextTokensNames = utils.map(nextTokensFlat, function (currTokenClass) { return chevrotain.tokenName(currTokenClass); }); errMsgTypes = "one of: <" + nextTokensNames.join(" ,") + ">"; } throw this.SAVE_ERROR(new exceptions.NoViableAltException("expecting: " + errMsgTypes + " " + errSuffix, this.NEXT_TOKEN())); @@ -3723,7 +3716,7 @@ var API = {}; /* istanbul ignore next */ if (!testMode) { // semantic version - API.VERSION = "0.5.12"; + API.VERSION = "0.5.13"; // runtime API API.Parser = chevrotain.Parser; API.Lexer = chevrotain.Lexer; @@ -3762,11 +3755,12 @@ else { // libs /// // production code +/// +// TODO: move lang --> utils ? /// /// /// /// -/// /// /// /// diff --git a/release/chevrotain.min.js b/release/chevrotain.min.js index 92aee2e51..9953e366d 100644 --- a/release/chevrotain.min.js +++ b/release/chevrotain.min.js @@ -1,5 +1,5 @@ -/*! chevrotain - v0.5.12 - 2016-01-02 */ -!function(root,factory){"function"==typeof define&&define.amd?define("chevrotain",["lodash"],function(a0){return root.API=factory(a0)}):"object"==typeof exports?module.exports=factory(require("lodash")):root.chevrotain=factory(_)}(this,function(_){var chevrotain;!function(chevrotain){var lang;!function(lang){function classNameFromInstance(instance){return functionName(instance.constructor)}function functionName(func){if(hasNativeName)return func.name;if(func.rdtFuncNameCache666)return func.rdtFuncNameCache666;var name_1=func.toString().match(nameRegex)[1];return func.rdtFuncNameCache666=name_1,name_1}var nameRegex=/^\s*function\s*(\S*)\s*\(/,hasNativeName="undefined"!=typeof function(){}.name;lang.classNameFromInstance=classNameFromInstance,lang.functionName=functionName;var HashTable=function(){function HashTable(){this._state={}}return HashTable.prototype.keys=function(){return _.keys(this._state)},HashTable.prototype.values=function(){return _.values(this._state)},HashTable.prototype.put=function(key,value){this._state[key]=value},HashTable.prototype.putAll=function(other){this._state=_.assign(this._state,other._state)},HashTable.prototype.get=function(key){return this._state[key]},HashTable.prototype.containsKey=function(key){return _.has(this._state,key)},HashTable}();lang.HashTable=HashTable}(lang=chevrotain.lang||(chevrotain.lang={}))}(chevrotain||(chevrotain={}));var chevrotain,__extends=this&&this.__extends||function(d,b){function __(){this.constructor=d}for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p]);d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)};!function(chevrotain){function tokenName(clazz){return _.isString(clazz.tokenName)?clazz.tokenName:lang.functionName(clazz)}function extendToken(tokenName,patternOrParent,parentConstructor){void 0===patternOrParent&&(patternOrParent=void 0),void 0===parentConstructor&&(parentConstructor=Token);var pattern;_.isRegExp(patternOrParent)||patternOrParent===chevrotain.Lexer.SKIPPED||patternOrParent===chevrotain.Lexer.NA?pattern=patternOrParent:_.isFunction(patternOrParent)&&(parentConstructor=patternOrParent,pattern=void 0);var derivedCostructor=function(){parentConstructor.apply(this,arguments)};return _.forOwn(parentConstructor,function(v,k){derivedCostructor[k]=v}),derivedCostructor.tokenName=tokenName,derivedCostructor.prototype=Object.create(parentConstructor.prototype),derivedCostructor.prototype.constructor=derivedCostructor,_.isUndefined(pattern)||(derivedCostructor.PATTERN=pattern),derivedCostructor}var lang=chevrotain.lang;chevrotain.tokenName=tokenName,chevrotain.extendToken=extendToken;var Token=function(){function Token(image,offset,startLine,startColumn,endLine,endColumn){void 0===endLine&&(endLine=startLine),void 0===endColumn&&(endColumn=startColumn+image.length-1),this.image=image,this.offset=offset,this.startLine=startLine,this.startColumn=startColumn,this.endLine=endLine,this.endColumn=endColumn,this.isInsertedInRecovery=!1}return Token}();chevrotain.Token=Token;var VirtualToken=function(_super){function VirtualToken(){_super.call(this,"",-1,-1,-1,-1,-1)}return __extends(VirtualToken,_super),VirtualToken}(Token);chevrotain.VirtualToken=VirtualToken;var EOF=function(_super){function EOF(){_super.apply(this,arguments)}return __extends(EOF,_super),EOF}(VirtualToken);chevrotain.EOF=EOF}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){!function(LexerDefinitionErrorType){LexerDefinitionErrorType[LexerDefinitionErrorType.MISSING_PATTERN=0]="MISSING_PATTERN",LexerDefinitionErrorType[LexerDefinitionErrorType.INVALID_PATTERN=1]="INVALID_PATTERN",LexerDefinitionErrorType[LexerDefinitionErrorType.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",LexerDefinitionErrorType[LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",LexerDefinitionErrorType[LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",LexerDefinitionErrorType[LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND"}(chevrotain.LexerDefinitionErrorType||(chevrotain.LexerDefinitionErrorType={}));var Lexer=(chevrotain.LexerDefinitionErrorType,function(){function Lexer(tokenClasses,deferDefinitionErrorsHandling){if(void 0===deferDefinitionErrorsHandling&&(deferDefinitionErrorsHandling=!1),this.tokenClasses=tokenClasses,this.lexerDefinitionErrors=[],this.lexerDefinitionErrors=chevrotain.validatePatterns(tokenClasses),!_.isEmpty(this.lexerDefinitionErrors)&&!deferDefinitionErrorsHandling){var allErrMessages=_.map(this.lexerDefinitionErrors,function(error){return error.message}),allErrMessagesString=allErrMessages.join("-----------------------\n");throw new Error("Errors detected in definition of Lexer:\n"+allErrMessagesString)}if(_.isEmpty(this.lexerDefinitionErrors)){var analyzeResult=chevrotain.analyzeTokenClasses(tokenClasses);this.allPatterns=analyzeResult.allPatterns,this.patternIdxToClass=analyzeResult.patternIdxToClass,this.patternIdxToGroup=analyzeResult.patternIdxToGroup,this.patternIdxToLongerAltIdx=analyzeResult.patternIdxToLongerAltIdx,this.patternIdxToCanLineTerminator=analyzeResult.patternIdxToCanLineTerminator,this.emptyGroups=analyzeResult.emptyGroups}}return Lexer.prototype.tokenize=function(text){var match,i,j,matchAlt,longerAltIdx,matchedImage,imageLength,group,tokClass,newToken,errLength,canMatchedContainLineTerminator,fixForEndingInLT,c,droppedChar,lastLTIdx,errorMessage,lastCharIsLT,orgInput=text,offset=0,matchedTokens=[],errors=[],line=1,column=1,groups=_.clone(this.emptyGroups);if(!_.isEmpty(this.lexerDefinitionErrors)){var allErrMessages=_.map(this.lexerDefinitionErrors,function(error){return error.message}),allErrMessagesString=allErrMessages.join("-----------------------\n");throw new Error("Unable to Tokenize because Errors detected in definition of Lexer:\n"+allErrMessagesString)}for(;text.length>0;){for(match=null,i=0;imatch[0].length&&(match=matchAlt,i=longerAltIdx));break}if(null!==match){if(matchedImage=match[0],imageLength=matchedImage.length,group=this.patternIdxToGroup[i],void 0!==group&&(tokClass=this.patternIdxToClass[i],newToken=new tokClass(matchedImage,offset,line,column),"default"===group?matchedTokens.push(newToken):groups[group].push(newToken)),text=text.slice(imageLength),offset+=imageLength,column+=imageLength,canMatchedContainLineTerminator=this.patternIdxToCanLineTerminator[i]){var lineTerminatorsInMatch=chevrotain.countLineTerminators(matchedImage);if(0!==lineTerminatorsInMatch){for(line+=lineTerminatorsInMatch,lastLTIdx=imageLength-1;lastLTIdx>=0&&(c=matchedImage.charCodeAt(lastLTIdx),13!==c&&10!==c);)lastLTIdx--;column=imageLength-lastLTIdx,void 0!==group&&(lastCharIsLT=lastLTIdx===imageLength-1,fixForEndingInLT=lastCharIsLT?-1:0,1===lineTerminatorsInMatch&&lastCharIsLT||(newToken.endLine=line+fixForEndingInLT,newToken.endColumn=column-1+-fixForEndingInLT))}}}else{for(var errorStartOffset=offset,errorLine=line,errorColumn=column,foundResyncPoint=!1;!foundResyncPoint&&text.length>0;)for(droppedChar=text.charCodeAt(0),10===droppedChar||13===droppedChar&&(1===text.length||text.length>1&&10!==text.charCodeAt(1))?(line++,column=1):column++,text=text.substr(1),offset++,j=0;j"+orgInput.charAt(errorStartOffset)+"<- at offset: "+errorStartOffset+","+(" skipped "+(offset-errorStartOffset)+" characters."),errors.push({line:errorLine,column:errorColumn,length:errLength,message:errorMessage})}}return{tokens:matchedTokens,groups:groups,errors:errors}},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}());chevrotain.Lexer=Lexer}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){function analyzeTokenClasses(tokenClasses){var onlyRelevantClasses=_.reject(tokenClasses,function(currClass){return currClass[PATTERN]===chevrotain.Lexer.NA}),allTransformedPatterns=_.map(onlyRelevantClasses,function(currClass){return addStartOfInput(currClass[PATTERN])}),allPatternsToClass=_.zipObject(allTransformedPatterns,onlyRelevantClasses),patternIdxToClass=_.map(allTransformedPatterns,function(pattern){return allPatternsToClass[pattern.toString()]}),patternIdxToGroup=_.map(onlyRelevantClasses,function(clazz){var groupName=clazz.GROUP;if(groupName!==chevrotain.Lexer.SKIPPED){if(_.isString(groupName))return groupName;if(_.isUndefined(groupName))return"default";throw Error("non exhaustive match")}}),patternIdxToLongerAltIdx=_.map(onlyRelevantClasses,function(clazz,idx){var longerAltClass=clazz.LONGER_ALT;if(longerAltClass){var longerAltIdx=_.indexOf(onlyRelevantClasses,longerAltClass);return longerAltIdx}}),patternIdxToCanLineTerminator=_.map(allTransformedPatterns,function(pattern){return/\\n|\\r|\\s/g.test(pattern.source)}),emptyGroups=_.reduce(onlyRelevantClasses,function(acc,clazz){var groupName=clazz.GROUP;return _.isString(groupName)&&(acc[groupName]=[]),acc},{});return{allPatterns:allTransformedPatterns,patternIdxToClass:patternIdxToClass,patternIdxToGroup:patternIdxToGroup,patternIdxToLongerAltIdx:patternIdxToLongerAltIdx,patternIdxToCanLineTerminator:patternIdxToCanLineTerminator,emptyGroups:emptyGroups}}function validatePatterns(tokenClasses){var errors=[],missingResult=findMissingPatterns(tokenClasses),validTokenClasses=missingResult.validTokenClasses;errors=errors.concat(missingResult.errors);var invalidResult=findInvalidPatterns(validTokenClasses);return validTokenClasses=invalidResult.validTokenClasses,errors=errors.concat(invalidResult.errors),errors=errors.concat(findEndOfInputAnchor(validTokenClasses)),errors=errors.concat(findUnsupportedFlags(validTokenClasses)),errors=errors.concat(findDuplicatePatterns(validTokenClasses)),errors=errors.concat(findInvalidGroupType(validTokenClasses))}function findMissingPatterns(tokenClasses){var tokenClassesWithMissingPattern=_.filter(tokenClasses,function(currClass){return!_.has(currClass,PATTERN)}),errors=_.map(tokenClassesWithMissingPattern,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- missing static 'PATTERN' property",type:chevrotain.LexerDefinitionErrorType.MISSING_PATTERN,tokenClasses:[currClass]}}),validTokenClasses=_.difference(tokenClasses,tokenClassesWithMissingPattern);return{errors:errors,validTokenClasses:validTokenClasses}}function findInvalidPatterns(tokenClasses){var tokenClassesWithInvalidPattern=_.filter(tokenClasses,function(currClass){var pattern=currClass[PATTERN];return!_.isRegExp(pattern)}),errors=_.map(tokenClassesWithInvalidPattern,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'PATTERN' can only be a RegExp",type:chevrotain.LexerDefinitionErrorType.INVALID_PATTERN,tokenClasses:[currClass]}}),validTokenClasses=_.difference(tokenClasses,tokenClassesWithInvalidPattern);return{errors:errors,validTokenClasses:validTokenClasses}}function findEndOfInputAnchor(tokenClasses){var invalidRegex=_.filter(tokenClasses,function(currClass){var pattern=currClass[PATTERN];return end_of_input.test(pattern.source)}),errors=_.map(invalidRegex,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'PATTERN' cannot contain end of input anchor '$'",type:chevrotain.LexerDefinitionErrorType.EOI_ANCHOR_FOUND,tokenClasses:[currClass]}});return errors}function findUnsupportedFlags(tokenClasses){var invalidFlags=_.filter(tokenClasses,function(currClass){var pattern=currClass[PATTERN];return pattern instanceof RegExp&&(pattern.multiline||pattern.global)}),errors=_.map(invalidFlags,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:chevrotain.LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND,tokenClasses:[currClass]}});return errors}function findDuplicatePatterns(tokenClasses){var found=[],identicalPatterns=_.map(tokenClasses,function(outerClass){return _.reduce(tokenClasses,function(result,innerClass){return outerClass.PATTERN.source!==innerClass.PATTERN.source||_.contains(found,innerClass)||innerClass.PATTERN===chevrotain.Lexer.NA?result:(found.push(innerClass),_.union(result,[innerClass]))},[])});identicalPatterns=_.compact(identicalPatterns);var duplicatePatterns=_.filter(identicalPatterns,function(currIdenticalSet){return _.size(currIdenticalSet)>1}),errors=_.map(duplicatePatterns,function(setOfIdentical){var classNames=_.map(setOfIdentical,function(currClass){return chevrotain.tokenName(currClass)}),dupPatternSrc=_.first(setOfIdentical).PATTERN;return{message:"The same RegExp pattern ->"+dupPatternSrc+"<-"+("has been used in all the following classes: "+classNames.join(", ")+" <-"),type:chevrotain.LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND,tokenClasses:setOfIdentical}});return errors}function findInvalidGroupType(tokenClasses){var invalidTypes=_.filter(tokenClasses,function(clazz){if(!_.has(clazz,"GROUP"))return!1;var group=clazz.GROUP;return group!==chevrotain.Lexer.SKIPPED&&group!==chevrotain.Lexer.NA&&!_.isString(group)}),errors=_.map(invalidTypes,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:chevrotain.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND,tokenClasses:[currClass]}});return errors}function addStartOfInput(pattern){var flags=pattern.ignoreCase?"i":"";return new RegExp("^(?:"+pattern.source+")",flags)}function countLineTerminators(text){for(var lineTerminators=0,currOffset=0;currOffsetstart||start>end)}var Range=function(){function Range(start,end){if(this.start=start,this.end=end,!isValidRange(start,end))throw new Error("INVALID RANGE")}return Range.prototype.contains=function(num){return this.start<=num&&this.end>=num},Range.prototype.containsRange=function(other){return this.start<=other.start&&this.end>=other.end},Range.prototype.isContainedInRange=function(other){return other.containsRange(this)},Range.prototype.strictlyContainsRange=function(other){return this.startother.end},Range.prototype.isStrictlyContainedInRange=function(other){return other.strictlyContainsRange(this)},Range}();range.Range=Range,range.isValidRange=isValidRange}(range=chevrotain.range||(chevrotain.range={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var constants;!function(constants){constants.IN="_~IN~_"}(constants=chevrotain.constants||(chevrotain.constants={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var gast;!function(gast){var AbstractProduction=function(){function AbstractProduction(definition){this.definition=definition,this.implicitOccurrenceIndex=!1}return AbstractProduction.prototype.accept=function(visitor){visitor.visit(this),_.forEach(this.definition,function(prod){prod.accept(visitor)})},AbstractProduction}();gast.AbstractProduction=AbstractProduction;var NonTerminal=function(_super){function NonTerminal(nonTerminalName,referencedRule,occurrenceInParent){void 0===referencedRule&&(referencedRule=void 0),void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,[]),this.nonTerminalName=nonTerminalName,this.referencedRule=referencedRule,this.occurrenceInParent=occurrenceInParent}return __extends(NonTerminal,_super),Object.defineProperty(NonTerminal.prototype,"definition",{get:function(){return void 0!==this.referencedRule?this.referencedRule.definition:[]},set:function(definition){},enumerable:!0,configurable:!0}),NonTerminal.prototype.accept=function(visitor){visitor.visit(this)},NonTerminal}(AbstractProduction);gast.NonTerminal=NonTerminal;var Rule=function(_super){function Rule(name,definition,orgText){void 0===orgText&&(orgText=""),_super.call(this,definition),this.name=name,this.orgText=orgText}return __extends(Rule,_super),Rule}(AbstractProduction);gast.Rule=Rule;var Flat=function(_super){function Flat(definition){_super.call(this,definition)}return __extends(Flat,_super),Flat}(AbstractProduction);gast.Flat=Flat;var Option=function(_super){function Option(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(Option,_super),Option}(AbstractProduction);gast.Option=Option;var RepetitionMandatory=function(_super){function RepetitionMandatory(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(RepetitionMandatory,_super),RepetitionMandatory}(AbstractProduction);gast.RepetitionMandatory=RepetitionMandatory;var RepetitionMandatoryWithSeparator=function(_super){function RepetitionMandatoryWithSeparator(definition,separator,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.separator=separator,this.occurrenceInParent=occurrenceInParent}return __extends(RepetitionMandatoryWithSeparator,_super),RepetitionMandatoryWithSeparator}(AbstractProduction);gast.RepetitionMandatoryWithSeparator=RepetitionMandatoryWithSeparator;var Repetition=function(_super){function Repetition(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(Repetition,_super),Repetition}(AbstractProduction);gast.Repetition=Repetition;var RepetitionWithSeparator=function(_super){function RepetitionWithSeparator(definition,separator,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.separator=separator,this.occurrenceInParent=occurrenceInParent}return __extends(RepetitionWithSeparator,_super),RepetitionWithSeparator}(AbstractProduction);gast.RepetitionWithSeparator=RepetitionWithSeparator;var Alternation=function(_super){function Alternation(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(Alternation,_super),Alternation}(AbstractProduction);gast.Alternation=Alternation;var Terminal=function(){function Terminal(terminalType,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),this.terminalType=terminalType,this.occurrenceInParent=occurrenceInParent,this.implicitOccurrenceIndex=!1}return Terminal.prototype.accept=function(visitor){visitor.visit(this)},Terminal}();gast.Terminal=Terminal;var GAstVisitor=function(){function GAstVisitor(){}return GAstVisitor.prototype.visit=function(node){node instanceof NonTerminal?this.visitNonTerminal(node):node instanceof Flat?this.visitFlat(node):node instanceof Option?this.visitOption(node):node instanceof RepetitionMandatory?this.visitRepetitionMandatory(node):node instanceof RepetitionMandatoryWithSeparator?this.visitRepetitionMandatoryWithSeparator(node):node instanceof RepetitionWithSeparator?this.visitRepetitionWithSeparator(node):node instanceof Repetition?this.visitRepetition(node):node instanceof Alternation?this.visitAlternation(node):node instanceof Terminal&&this.visitTerminal(node)},GAstVisitor.prototype.visitNonTerminal=function(node){},GAstVisitor.prototype.visitFlat=function(node){},GAstVisitor.prototype.visitOption=function(node){},GAstVisitor.prototype.visitRepetition=function(node){},GAstVisitor.prototype.visitRepetitionMandatory=function(node){},GAstVisitor.prototype.visitRepetitionMandatoryWithSeparator=function(node){},GAstVisitor.prototype.visitRepetitionWithSeparator=function(node){},GAstVisitor.prototype.visitAlternation=function(node){},GAstVisitor.prototype.visitTerminal=function(node){},GAstVisitor}();gast.GAstVisitor=GAstVisitor}(gast=chevrotain.gast||(chevrotain.gast={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var gast;!function(gast){function isSequenceProd(prod){return prod instanceof gast.Flat||prod instanceof gast.Option||prod instanceof gast.Repetition||prod instanceof gast.RepetitionMandatory||prod instanceof gast.RepetitionMandatoryWithSeparator||prod instanceof gast.RepetitionWithSeparator||prod instanceof gast.Terminal||prod instanceof gast.Rule}function isOptionalProd(prod,alreadyVisited){void 0===alreadyVisited&&(alreadyVisited=[]);var isDirectlyOptional=prod instanceof gast.Option||prod instanceof gast.Repetition||prod instanceof gast.RepetitionWithSeparator;return isDirectlyOptional?!0:prod instanceof gast.Alternation?_.some(prod.definition,function(subProd){return isOptionalProd(subProd,alreadyVisited)}):prod instanceof gast.NonTerminal&&_.contains(alreadyVisited,prod)?!1:prod instanceof gast.AbstractProduction?(prod instanceof gast.NonTerminal&&alreadyVisited.push(prod),_.every(prod.definition,function(subProd){return isOptionalProd(subProd,alreadyVisited)})):!1}function isBranchingProd(prod){return prod instanceof gast.Alternation}function getProductionDslName(prod){var clazz=prod.constructor,prodName=lang.functionName(clazz);return productionToDslName[prodName]}var lang=chevrotain.lang;gast.isSequenceProd=isSequenceProd,gast.isOptionalProd=isOptionalProd,gast.isBranchingProd=isBranchingProd;var productionToDslName={};productionToDslName[lang.functionName(gast.NonTerminal)]="SUBRULE",productionToDslName[lang.functionName(gast.Option)]="OPTION",productionToDslName[lang.functionName(gast.RepetitionMandatory)]="AT_LEAST_ONE",productionToDslName[lang.functionName(gast.RepetitionMandatoryWithSeparator)]="AT_LEAST_ONE_SEP",productionToDslName[lang.functionName(gast.RepetitionWithSeparator)]="MANY_SEP",productionToDslName[lang.functionName(gast.Repetition)]="MANY",productionToDslName[lang.functionName(gast.Alternation)]="OR",productionToDslName[lang.functionName(gast.Terminal)]="CONSUME",gast.getProductionDslName=getProductionDslName}(gast=chevrotain.gast||(chevrotain.gast={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var first;!function(first_1){function first(prod){if(prod instanceof gast.NonTerminal)return first(prod.referencedRule);if(prod instanceof gast.Terminal)return firstForTerminal(prod);if(gast.isSequenceProd(prod))return firstForSequence(prod);if(gast.isBranchingProd(prod))return firstForBranching(prod);throw Error("non exhaustive match")}function firstForSequence(prod){for(var currSubProd,firstSet=[],seq=prod.definition,nextSubProdIdx=0,hasInnerProdsRemaining=seq.length>nextSubProdIdx,isLastInnerProdOptional=!0;hasInnerProdsRemaining&&isLastInnerProdOptional;)currSubProd=seq[nextSubProdIdx],isLastInnerProdOptional=gast.isOptionalProd(currSubProd),firstSet=firstSet.concat(first(currSubProd)),nextSubProdIdx+=1,hasInnerProdsRemaining=seq.length>nextSubProdIdx;return _.uniq(firstSet)}function firstForBranching(prod){var allAlternativesFirsts=_.map(prod.definition,function(innerProd){return first(innerProd)});return _.uniq(_.flatten(allAlternativesFirsts))}function firstForTerminal(terminal){return[terminal.terminalType]}var gast=chevrotain.gast;first_1.first=first,first_1.firstForSequence=firstForSequence,first_1.firstForBranching=firstForBranching,first_1.firstForTerminal=firstForTerminal}(first=chevrotain.first||(chevrotain.first={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var rest;!function(rest){function restForRepetitionWithSeparator(repSepProd,currRest,prevRest){var repSepRest=[new g.Option([new g.Terminal(repSepProd.separator)].concat(repSepProd.definition))],fullRepSepRest=repSepRest.concat(currRest,prevRest);return fullRepSepRest}var g=chevrotain.gast,RestWalker=function(){function RestWalker(){}return RestWalker.prototype.walk=function(prod,prevRest){var _this=this;void 0===prevRest&&(prevRest=[]),_.forEach(prod.definition,function(subProd,index){var currRest=_.drop(prod.definition,index+1);if(subProd instanceof g.NonTerminal)_this.walkProdRef(subProd,currRest,prevRest);else if(subProd instanceof g.Terminal)_this.walkTerminal(subProd,currRest,prevRest);else if(subProd instanceof g.Flat)_this.walkFlat(subProd,currRest,prevRest);else if(subProd instanceof g.Option)_this.walkOption(subProd,currRest,prevRest);else if(subProd instanceof g.RepetitionMandatory)_this.walkAtLeastOne(subProd,currRest,prevRest);else if(subProd instanceof g.RepetitionMandatoryWithSeparator)_this.walkAtLeastOneSep(subProd,currRest,prevRest);else if(subProd instanceof g.RepetitionWithSeparator)_this.walkManySep(subProd,currRest,prevRest);else if(subProd instanceof g.Repetition)_this.walkMany(subProd,currRest,prevRest);else{if(!(subProd instanceof g.Alternation))throw Error("non exhaustive match");_this.walkOr(subProd,currRest,prevRest)}})},RestWalker.prototype.walkTerminal=function(terminal,currRest,prevRest){},RestWalker.prototype.walkProdRef=function(refProd,currRest,prevRest){},RestWalker.prototype.walkFlat=function(flatProd,currRest,prevRest){var fullOrRest=currRest.concat(prevRest);this.walk(flatProd,fullOrRest)},RestWalker.prototype.walkOption=function(optionProd,currRest,prevRest){var fullOrRest=currRest.concat(prevRest);this.walk(optionProd,fullOrRest)},RestWalker.prototype.walkAtLeastOne=function(atLeastOneProd,currRest,prevRest){var fullAtLeastOneRest=[new g.Option(atLeastOneProd.definition)].concat(currRest,prevRest);this.walk(atLeastOneProd,fullAtLeastOneRest)},RestWalker.prototype.walkAtLeastOneSep=function(atLeastOneSepProd,currRest,prevRest){var fullAtLeastOneSepRest=restForRepetitionWithSeparator(atLeastOneSepProd,currRest,prevRest);this.walk(atLeastOneSepProd,fullAtLeastOneSepRest)},RestWalker.prototype.walkMany=function(manyProd,currRest,prevRest){var fullManyRest=[new g.Option(manyProd.definition)].concat(currRest,prevRest);this.walk(manyProd,fullManyRest)},RestWalker.prototype.walkManySep=function(manySepProd,currRest,prevRest){var fullManySepRest=restForRepetitionWithSeparator(manySepProd,currRest,prevRest);this.walk(manySepProd,fullManySepRest)},RestWalker.prototype.walkOr=function(orProd,currRest,prevRest){var _this=this,fullOrRest=currRest.concat(prevRest);_.forEach(orProd.definition,function(alt){var prodWrapper=new chevrotain.gast.Flat([alt]);_this.walk(prodWrapper,fullOrRest)})},RestWalker}();rest.RestWalker=RestWalker}(rest=chevrotain.rest||(chevrotain.rest={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var follow;!function(follow){function computeAllProdsFollows(topProductions){var reSyncFollows=new lang.HashTable;return _.forEach(topProductions,function(topProd){var currRefsFollow=new ResyncFollowsWalker(topProd).startWalking();reSyncFollows.putAll(currRefsFollow)}),reSyncFollows}function buildBetweenProdsFollowPrefix(inner,occurenceInParent){return inner.name+occurenceInParent+IN}function buildInProdFollowPrefix(terminal){var terminalName=chevrotain.tokenName(terminal.terminalType);return terminalName+terminal.occurrenceInParent+IN}var g=chevrotain.gast,r=chevrotain.rest,f=chevrotain.first,IN=chevrotain.constants.IN,lang=chevrotain.lang,ResyncFollowsWalker=function(_super){function ResyncFollowsWalker(topProd){_super.call(this),this.topProd=topProd,this.follows=new lang.HashTable}return __extends(ResyncFollowsWalker,_super),ResyncFollowsWalker.prototype.startWalking=function(){return this.walk(this.topProd),this.follows},ResyncFollowsWalker.prototype.walkTerminal=function(terminal,currRest,prevRest){},ResyncFollowsWalker.prototype.walkProdRef=function(refProd,currRest,prevRest){var followName=buildBetweenProdsFollowPrefix(refProd.referencedRule,refProd.occurrenceInParent)+this.topProd.name,fullRest=currRest.concat(prevRest),restProd=new g.Flat(fullRest),t_in_topProd_follows=f.first(restProd);this.follows.put(followName,t_in_topProd_follows)},ResyncFollowsWalker}(r.RestWalker);follow.ResyncFollowsWalker=ResyncFollowsWalker,follow.computeAllProdsFollows=computeAllProdsFollows,follow.buildBetweenProdsFollowPrefix=buildBetweenProdsFollowPrefix,follow.buildInProdFollowPrefix=buildInProdFollowPrefix}(follow=chevrotain.follow||(chevrotain.follow={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var interpreter;!function(interpreter){var g=chevrotain.gast,f=chevrotain.first,r=chevrotain.rest,AbstractNextPossibleTokensWalker=function(_super){function AbstractNextPossibleTokensWalker(topProd,path){_super.call(this),this.topProd=topProd,this.path=path,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}return __extends(AbstractNextPossibleTokensWalker,_super),AbstractNextPossibleTokensWalker.prototype.startWalking=function(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=_.clone(this.path.ruleStack).reverse(),this.occurrenceStack=_.clone(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes},AbstractNextPossibleTokensWalker.prototype.walk=function(prod,prevRest){void 0===prevRest&&(prevRest=[]),this.found||_super.prototype.walk.call(this,prod,prevRest)},AbstractNextPossibleTokensWalker.prototype.walkProdRef=function(refProd,currRest,prevRest){if(refProd.referencedRule.name===this.nextProductionName&&refProd.occurrenceInParent===this.nextProductionOccurrence){var fullRest=currRest.concat(prevRest);this.updateExpectedNext(),this.walk(refProd.referencedRule,fullRest)}},AbstractNextPossibleTokensWalker.prototype.updateExpectedNext=function(){_.isEmpty(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())},AbstractNextPossibleTokensWalker}(r.RestWalker);interpreter.AbstractNextPossibleTokensWalker=AbstractNextPossibleTokensWalker; -var NextAfterTokenWalker=function(_super){function NextAfterTokenWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=chevrotain.tokenName(this.path.lastTok),this.nextTerminalOccurrence=this.path.lastTokOccurrence}return __extends(NextAfterTokenWalker,_super),NextAfterTokenWalker.prototype.walkTerminal=function(terminal,currRest,prevRest){if(this.isAtEndOfPath&&chevrotain.tokenName(terminal.terminalType)===this.nextTerminalName&&terminal.occurrenceInParent===this.nextTerminalOccurrence&&!this.found){var fullRest=currRest.concat(prevRest),restProd=new g.Flat(fullRest);this.possibleTokTypes=f.first(restProd),this.found=!0}},NextAfterTokenWalker}(AbstractNextPossibleTokensWalker);interpreter.NextAfterTokenWalker=NextAfterTokenWalker;var NextInsideOptionWalker=function(_super){function NextInsideOptionWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOptionOccurrence=0,this.nextOptionOccurrence=this.path.occurrence}return __extends(NextInsideOptionWalker,_super),NextInsideOptionWalker.prototype.walkOption=function(optionProd,currRest,prevRest){if(this.isAtEndOfPath&&optionProd.occurrenceInParent===this.nextOptionOccurrence&&!this.found){var restProd=new g.Flat(optionProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkOption.call(this,optionProd,currRest,prevRest)},NextInsideOptionWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideOptionWalker=NextInsideOptionWalker;var NextInsideManyWalker=function(_super){function NextInsideManyWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideManyWalker,_super),NextInsideManyWalker.prototype.walkMany=function(manyProd,currRest,prevRest){if(this.isAtEndOfPath&&manyProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(manyProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkMany.call(this,manyProd,currRest,prevRest)},NextInsideManyWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideManyWalker=NextInsideManyWalker;var NextInsideManySepWalker=function(_super){function NextInsideManySepWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideManySepWalker,_super),NextInsideManySepWalker.prototype.walkManySep=function(manySepProd,currRest,prevRest){if(this.isAtEndOfPath&&manySepProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(manySepProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkManySep.call(this,manySepProd,currRest,prevRest)},NextInsideManySepWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideManySepWalker=NextInsideManySepWalker;var NextInsideAtLeastOneWalker=function(_super){function NextInsideAtLeastOneWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideAtLeastOneWalker,_super),NextInsideAtLeastOneWalker.prototype.walkAtLeastOne=function(atLeastOneProd,currRest,prevRest){if(this.isAtEndOfPath&&atLeastOneProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(atLeastOneProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkAtLeastOne.call(this,atLeastOneProd,currRest,prevRest)},NextInsideAtLeastOneWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideAtLeastOneWalker=NextInsideAtLeastOneWalker;var NextInsideAtLeastOneSepWalker=function(_super){function NextInsideAtLeastOneSepWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideAtLeastOneSepWalker,_super),NextInsideAtLeastOneSepWalker.prototype.walkAtLeastOneSep=function(atLeastOneSepProd,currRest,prevRest){if(this.isAtEndOfPath&&atLeastOneSepProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(atLeastOneSepProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkAtLeastOneSep.call(this,atLeastOneSepProd,currRest,prevRest)},NextInsideAtLeastOneSepWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideAtLeastOneSepWalker=NextInsideAtLeastOneSepWalker;var NextInsideOrWalker=function(_super){function NextInsideOrWalker(topRule,occurrence){_super.call(this),this.topRule=topRule,this.occurrence=occurrence,this.result=[]}return __extends(NextInsideOrWalker,_super),NextInsideOrWalker.prototype.startWalking=function(){return this.walk(this.topRule),this.result},NextInsideOrWalker.prototype.walkOr=function(orProd,currRest,prevRest){orProd.occurrenceInParent===this.occurrence?this.result=_.map(orProd.definition,function(alt){var altWrapper=new chevrotain.gast.Flat([alt]);return f.first(altWrapper)}):_super.prototype.walkOr.call(this,orProd,currRest,prevRest)},NextInsideOrWalker}(r.RestWalker);interpreter.NextInsideOrWalker=NextInsideOrWalker;var AbstractNextTerminalAfterProductionWalker=function(_super){function AbstractNextTerminalAfterProductionWalker(topRule,occurrence){_super.call(this),this.topRule=topRule,this.occurrence=occurrence,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}return __extends(AbstractNextTerminalAfterProductionWalker,_super),AbstractNextTerminalAfterProductionWalker.prototype.startWalking=function(){return this.walk(this.topRule),this.result},AbstractNextTerminalAfterProductionWalker}(r.RestWalker);interpreter.AbstractNextTerminalAfterProductionWalker=AbstractNextTerminalAfterProductionWalker;var NextTerminalAfterManyWalker=function(_super){function NextTerminalAfterManyWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterManyWalker,_super),NextTerminalAfterManyWalker.prototype.walkMany=function(manyProd,currRest,prevRest){if(manyProd.occurrenceInParent===this.occurrence){var firstAfterMany=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterMany,firstAfterMany instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterMany.terminalType,this.result.occurrence=firstAfterMany.occurrenceInParent)}else _super.prototype.walkMany.call(this,manyProd,currRest,prevRest)},NextTerminalAfterManyWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterManyWalker=NextTerminalAfterManyWalker;var NextTerminalAfterManySepWalker=function(_super){function NextTerminalAfterManySepWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterManySepWalker,_super),NextTerminalAfterManySepWalker.prototype.walkManySep=function(manySepProd,currRest,prevRest){if(manySepProd.occurrenceInParent===this.occurrence){var firstAfterManySep=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterManySep,firstAfterManySep instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterManySep.terminalType,this.result.occurrence=firstAfterManySep.occurrenceInParent)}else _super.prototype.walkManySep.call(this,manySepProd,currRest,prevRest)},NextTerminalAfterManySepWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterManySepWalker=NextTerminalAfterManySepWalker;var NextTerminalAfterAtLeastOneWalker=function(_super){function NextTerminalAfterAtLeastOneWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterAtLeastOneWalker,_super),NextTerminalAfterAtLeastOneWalker.prototype.walkAtLeastOne=function(atLeastOneProd,currRest,prevRest){if(atLeastOneProd.occurrenceInParent===this.occurrence){var firstAfterAtLeastOne=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterAtLeastOne,firstAfterAtLeastOne instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterAtLeastOne.terminalType,this.result.occurrence=firstAfterAtLeastOne.occurrenceInParent)}else _super.prototype.walkAtLeastOne.call(this,atLeastOneProd,currRest,prevRest)},NextTerminalAfterAtLeastOneWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterAtLeastOneWalker=NextTerminalAfterAtLeastOneWalker;var NextTerminalAfterAtLeastOneSepWalker=function(_super){function NextTerminalAfterAtLeastOneSepWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterAtLeastOneSepWalker,_super),NextTerminalAfterAtLeastOneSepWalker.prototype.walkAtLeastOneSep=function(atleastOneSepProd,currRest,prevRest){if(atleastOneSepProd.occurrenceInParent===this.occurrence){var firstAfterfirstAfterAtLeastOneSep=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterfirstAfterAtLeastOneSep,firstAfterfirstAfterAtLeastOneSep instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterfirstAfterAtLeastOneSep.terminalType,this.result.occurrence=firstAfterfirstAfterAtLeastOneSep.occurrenceInParent)}else _super.prototype.walkAtLeastOneSep.call(this,atleastOneSepProd,currRest,prevRest)},NextTerminalAfterAtLeastOneSepWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterAtLeastOneSepWalker=NextTerminalAfterAtLeastOneSepWalker}(interpreter=chevrotain.interpreter||(chevrotain.interpreter={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var cache;!function(cache){function getProductionsForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_GRAMMAR_PRODUCTIONS)}function getResyncFollowsForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_RESYNC_FOLLOW_SETS)}function setResyncFollowsForClass(className,followSet){cache.CLASS_TO_RESYNC_FOLLOW_SETS.put(className,followSet)}function getLookaheadFuncsForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_LOOKAHEAD_FUNCS)}function getFirstAfterRepForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_FIRST_AFTER_REPETITION)}function initLookAheadKeyCache(className){cache.CLASS_TO_OR_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_MANY_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_MANY_SEP_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_AT_LEAST_ONE_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_OPTION_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),initSingleLookAheadKeyCache(cache.CLASS_TO_OR_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_MANY_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_MANY_SEP_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_AT_LEAST_ONE_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_OPTION_LA_CACHE[className])}function initSingleLookAheadKeyCache(laCache){for(var i=0;ii;i++)for(var currAltTokens=alternativesTokens[i],j=0;j in inside <"+ruleGrammar.name+"> "+("Rule, <"+chevrotain.tokenName(currAmbiguity.token)+"> may appears as the first Terminal in all these alternatives.\n")});throw new Error(errorMessages.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(alternativesTokens){var allTokensFlat=_.flatten(alternativesTokens),uniqueTokensFlat=_.uniq(allTokensFlat),tokensToAltsIndicesItAppearsIn=_.map(uniqueTokensFlat,function(seekToken){var altsCurrTokenAppearsIn=_.pick(alternativesTokens,function(altToLookIn){return _.find(altToLookIn,function(currToken){return currToken===seekToken})}),altsIndicesTokenAppearsIn=_.map(_.keys(altsCurrTokenAppearsIn),function(index){return parseInt(index,10)+1});return{token:seekToken,alts:altsIndicesTokenAppearsIn}}),tokensToAltsIndicesWithAmbiguity=_.filter(tokensToAltsIndicesItAppearsIn,function(tokAndAltsItAppearsIn){return tokAndAltsItAppearsIn.alts.length>1});return tokensToAltsIndicesWithAmbiguity}function buildLookAheadForGrammarProd(prodWalkerConstructor,ruleOccurrence,ruleGrammar){var path={ruleStack:[ruleGrammar.name],occurrenceStack:[1],occurrence:ruleOccurrence},walker=new prodWalkerConstructor(ruleGrammar,path),possibleNextTokTypes=walker.startWalking();return getSimpleLookahead(possibleNextTokTypes)}function getSimpleLookahead(possibleNextTokTypes){return function(){for(var nextToken=this.NEXT_TOKEN(),j=0;j1}),errors=_.map(duplicates,function(currDuplicates){var firstProd=_.first(currDuplicates),msg=createDuplicatesErrorMessage(currDuplicates,topLevelRule.name),dslName=gast.getProductionDslName(firstProd),defError={message:msg,type:chevrotain.ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS,ruleName:topLevelRule.name,dslName:dslName,occurrence:firstProd.occurrenceInParent},param=getExtraProductionArgument(firstProd);return param&&(defError.parameter=param),defError});return errors}function createDuplicatesErrorMessage(duplicateProds,topLevelName){var firstProd=_.first(duplicateProds),index=firstProd.occurrenceInParent,dslName=gast.getProductionDslName(firstProd),extraArgument=getExtraProductionArgument(firstProd),msg="->"+dslName+"<- with occurrence index: ->"+index+"<-\n "+(extraArgument?"and argument: "+extraArgument:"")+"\n appears more than once ("+duplicateProds.length+" times) in the top level rule: "+topLevelName+".\n "+(1===index?"note that "+dslName+" and "+dslName+"1 both have the same occurrence index 1}":"")+"}\n to fix this make sure each usage of "+dslName+" "+(extraArgument?"with the argument: "+extraArgument:"")+"\n in the rule "+topLevelName+" 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 msg=msg.replace(/[ \t]+/g," "),msg=msg.replace(/\s\s+/g,"\n")}function identifyProductionForDuplicates(prod){return gast.getProductionDslName(prod)+"_#_"+prod.occurrenceInParent+"_#_"+getExtraProductionArgument(prod)}function getExtraProductionArgument(prod){return prod instanceof gast.Terminal?chevrotain.tokenName(prod.terminalType):prod instanceof gast.NonTerminal?prod.nonTerminalName:""}function validateRuleName(ruleName,definedRulesNames,className){var errMsg,errors=[];return ruleName.match(ruleNamePattern)||(errMsg="Invalid Grammar rule name --> "+ruleName+" it must match the pattern: "+ruleNamePattern.toString(),errors.push({message:errMsg,type:chevrotain.ParserDefinitionErrorType.INVALID_RULE_NAME,ruleName:ruleName})),_.contains(definedRulesNames,ruleName)&&(errMsg="Duplicate definition, rule: "+ruleName+" is already defined in the grammar: "+className,errors.push({message:errMsg,type:chevrotain.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:ruleName})),errors}function validateNoLeftRecursion(topRule,currRule,path){ -void 0===path&&(path=[]);var errors=[],nextNonTerminals=getFirstNoneTerminal(currRule.definition);if(_.isEmpty(nextNonTerminals))return[];var ruleName=topRule.name,foundLeftRecursion=_.contains(nextNonTerminals,topRule),pathNames=_.map(path,function(currRule){return currRule.name}),leftRecursivePath=ruleName+" --> "+pathNames.concat([ruleName]).join(" --> ");if(foundLeftRecursion){var errMsg="Left Recursion found in grammar.\n"+("rule: <"+ruleName+"> can be invoked from itself (directly or indirectly)\n")+("without consuming any Tokens. The grammar path that causes this is: \n "+leftRecursivePath+"\n")+" To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_Factoring.";errors.push({message:errMsg,type:chevrotain.ParserDefinitionErrorType.LEFT_RECURSION,ruleName:ruleName})}var validNextSteps=_.difference(nextNonTerminals,path.concat([topRule])),errorsFromNextSteps=_.map(validNextSteps,function(currRefRule,key,all){var newPath=_.clone(path);return newPath.push(currRefRule),validateNoLeftRecursion(topRule,currRefRule,newPath)});return errors.concat(_.flatten(errorsFromNextSteps))}function getFirstNoneTerminal(definition){var result=[];if(_.isEmpty(definition))return result;var firstProd=_.first(definition);if(firstProd instanceof gast.NonTerminal){if(void 0===firstProd.referencedRule)return result;result.push(firstProd.referencedRule)}else if(firstProd instanceof gast.Flat||firstProd instanceof gast.Option||firstProd instanceof gast.RepetitionMandatory||firstProd instanceof gast.RepetitionMandatoryWithSeparator||firstProd instanceof gast.RepetitionWithSeparator||firstProd instanceof gast.Repetition)result=result.concat(getFirstNoneTerminal(firstProd.definition));else if(firstProd instanceof gast.Alternation)result=_.flatten(_.map(firstProd.definition,function(currSubDef){return getFirstNoneTerminal(currSubDef.definition)}));else if(!(firstProd instanceof gast.Terminal))throw Error("non exhaustive match");var isFirstOptional=gast.isOptionalProd(firstProd),hasMore=definition.length>1;if(isFirstOptional&&hasMore){var rest_1=_.drop(definition);return result.concat(getFirstNoneTerminal(rest_1))}return result}function validateEmptyOrAlternative(topLevelRule){var orCollector=new OrCollector;topLevelRule.accept(orCollector);var ors=orCollector.alternations,errors=_.reduce(ors,function(errors,currOr){var exceptLast=_.dropRight(currOr.definition),currErrors=_.map(exceptLast,function(currAlternative,currAltIdx){return _.isEmpty(chevrotain.first.first(currAlternative))?{message:"Ambiguous empty alternative: <"+(currAltIdx+1)+">"+(" in inside <"+topLevelRule.name+"> Rule.\n")+"Only the last alternative may be an empty alternative.",type:chevrotain.ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT,ruleName:topLevelRule.name,occurrence:currOr.occurrenceInParent,alternative:currAltIdx+1}:null});return errors.concat(_.compact(currErrors))},[]);return errors}var gast=chevrotain.gast,GAstVisitor=chevrotain.gast.GAstVisitor;checks.validateGrammar=validateGrammar,checks.identifyProductionForDuplicates=identifyProductionForDuplicates;var OccurrenceValidationCollector=function(_super){function OccurrenceValidationCollector(){_super.apply(this,arguments),this.allProductions=[]}return __extends(OccurrenceValidationCollector,_super),OccurrenceValidationCollector.prototype.visitNonTerminal=function(subrule){this.allProductions.push(subrule)},OccurrenceValidationCollector.prototype.visitOption=function(option){this.allProductions.push(option)},OccurrenceValidationCollector.prototype.visitRepetitionWithSeparator=function(manySep){this.allProductions.push(manySep)},OccurrenceValidationCollector.prototype.visitRepetitionMandatory=function(atLeastOne){this.allProductions.push(atLeastOne)},OccurrenceValidationCollector.prototype.visitRepetitionMandatoryWithSeparator=function(atLeastOneSep){this.allProductions.push(atLeastOneSep)},OccurrenceValidationCollector.prototype.visitRepetition=function(many){this.allProductions.push(many)},OccurrenceValidationCollector.prototype.visitAlternation=function(or){this.allProductions.push(or)},OccurrenceValidationCollector.prototype.visitTerminal=function(terminal){this.allProductions.push(terminal)},OccurrenceValidationCollector}(gast.GAstVisitor);checks.OccurrenceValidationCollector=OccurrenceValidationCollector;var ruleNamePattern=/^[a-zA-Z_]\w*$/;checks.validateRuleName=validateRuleName,checks.validateNoLeftRecursion=validateNoLeftRecursion,checks.getFirstNoneTerminal=getFirstNoneTerminal;var OrCollector=function(_super){function OrCollector(){_super.apply(this,arguments),this.alternations=[]}return __extends(OrCollector,_super),OrCollector.prototype.visitAlternation=function(node){this.alternations.push(node)},OrCollector}(GAstVisitor);checks.validateEmptyOrAlternative=validateEmptyOrAlternative}(checks=chevrotain.checks||(chevrotain.checks={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var resolver;!function(resolver){function resolveGrammar(topLevels){var refResolver=new GastRefResolverVisitor(topLevels);return refResolver.resolveRefs(),refResolver.errors}var gast=chevrotain.gast;resolver.resolveGrammar=resolveGrammar;var GastRefResolverVisitor=function(_super){function GastRefResolverVisitor(nameToTopRule){_super.call(this),this.nameToTopRule=nameToTopRule,this.errors=[]}return __extends(GastRefResolverVisitor,_super),GastRefResolverVisitor.prototype.resolveRefs=function(){var _this=this;_.forEach(this.nameToTopRule.values(),function(prod){_this.currTopLevel=prod,prod.accept(_this)})},GastRefResolverVisitor.prototype.visitNonTerminal=function(node){var ref=this.nameToTopRule.get(node.nonTerminalName);if(ref)node.referencedRule=ref;else{var msg="Invalid grammar, reference to rule which is not defined --> "+node.nonTerminalName;this.errors.push({message:msg,type:chevrotain.ParserDefinitionErrorType.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:node.nonTerminalName})}},GastRefResolverVisitor}(gast.GAstVisitor);resolver.GastRefResolverVisitor=GastRefResolverVisitor}(resolver=chevrotain.resolver||(chevrotain.resolver={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var exceptions;!function(exceptions){function isRecognitionException(error){var recognitionExceptions=[chevrotain.lang.functionName(MismatchedTokenException),chevrotain.lang.functionName(NoViableAltException),chevrotain.lang.functionName(EarlyExitException),chevrotain.lang.functionName(NotAllInputParsedException)];return _.contains(recognitionExceptions,error.name)}function MismatchedTokenException(message,token){this.name=chevrotain.lang.functionName(MismatchedTokenException),this.message=message,this.token=token}function NoViableAltException(message,token){this.name=chevrotain.lang.functionName(NoViableAltException),this.message=message,this.token=token}function NotAllInputParsedException(message,token){this.name=chevrotain.lang.functionName(NotAllInputParsedException),this.message=message,this.token=token}function EarlyExitException(message,token){this.name=chevrotain.lang.functionName(EarlyExitException),this.message=message,this.token=token}exceptions.isRecognitionException=isRecognitionException,exceptions.MismatchedTokenException=MismatchedTokenException,MismatchedTokenException.prototype=Error.prototype,exceptions.NoViableAltException=NoViableAltException,NoViableAltException.prototype=Error.prototype,exceptions.NotAllInputParsedException=NotAllInputParsedException,NotAllInputParsedException.prototype=Error.prototype,exceptions.EarlyExitException=EarlyExitException,EarlyExitException.prototype=Error.prototype}(exceptions=chevrotain.exceptions||(chevrotain.exceptions={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){function EMPTY_ALT(value){return void 0===value&&(value=void 0),function(){return value}}function InRuleRecoveryException(message){this.name=lang.functionName(InRuleRecoveryException),this.message=message}var cache=chevrotain.cache,IN=chevrotain.constants.IN,interp=chevrotain.interpreter,lang=chevrotain.lang,gastBuilder=chevrotain.gastBuilder,follows=chevrotain.follow,lookahead=chevrotain.lookahead,checks=chevrotain.checks,resolver=chevrotain.resolver,exceptions=chevrotain.exceptions;!function(ParserDefinitionErrorType){ParserDefinitionErrorType[ParserDefinitionErrorType.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",ParserDefinitionErrorType[ParserDefinitionErrorType.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",ParserDefinitionErrorType[ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS=2]="DUPLICATE_PRODUCTIONS",ParserDefinitionErrorType[ParserDefinitionErrorType.UNRESOLVED_SUBRULE_REF=3]="UNRESOLVED_SUBRULE_REF",ParserDefinitionErrorType[ParserDefinitionErrorType.LEFT_RECURSION=4]="LEFT_RECURSION",ParserDefinitionErrorType[ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT=5]="NONE_LAST_EMPTY_ALT"}(chevrotain.ParserDefinitionErrorType||(chevrotain.ParserDefinitionErrorType={}));chevrotain.ParserDefinitionErrorType;chevrotain.EMPTY_ALT=EMPTY_ALT;var EOF_FOLLOW_KEY={},Parser=function(){function Parser(input,tokensMapOrArr,isErrorRecoveryEnabled){if(void 0===isErrorRecoveryEnabled&&(isErrorRecoveryEnabled=!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=input,this.isErrorRecoveryEnabled=isErrorRecoveryEnabled,this.className=lang.classNameFromInstance(this),this.firstAfterRepMap=cache.getFirstAfterRepForClass(this.className),this.classLAFuncs=cache.getLookaheadFuncsForClass(this.className),cache.CLASS_TO_DEFINITION_ERRORS.containsKey(this.className)?this.definitionErrors=cache.CLASS_TO_DEFINITION_ERRORS.get(this.className):(this.definitionErrors=[],cache.CLASS_TO_DEFINITION_ERRORS.put(this.className,this.definitionErrors)),_.isArray(tokensMapOrArr))this.tokensMap=_.reduce(tokensMapOrArr,function(acc,tokenClazz){return acc[chevrotain.tokenName(tokenClazz)]=tokenClazz,acc},{});else{if(!_.isObject(tokensMapOrArr))throw new Error("'tokensMapOrArr' argument must be An Array of Token constructors or a Dictionary of Tokens.");this.tokensMap=_.clone(tokensMapOrArr)}this.tokensMap[chevrotain.tokenName(chevrotain.EOF)]=chevrotain.EOF,void 0===cache.CLASS_TO_OR_LA_CACHE[this.className]&&cache.initLookAheadKeyCache(this.className),this.orLookaheadKeys=cache.CLASS_TO_OR_LA_CACHE[this.className],this.manyLookaheadKeys=cache.CLASS_TO_MANY_LA_CACHE[this.className],this.manySepLookaheadKeys=cache.CLASS_TO_MANY_SEP_LA_CACHE[this.className],this.atLeastOneLookaheadKeys=cache.CLASS_TO_AT_LEAST_ONE_LA_CACHE[this.className],this.atLeastOneSepLookaheadKeys=cache.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[this.className],this.optionLookaheadKeys=cache.CLASS_TO_OPTION_LA_CACHE[this.className]}return Parser.performSelfAnalysis=function(classInstance){var defErrorsMsgs,definitionErrors=[],className=lang.classNameFromInstance(classInstance);if(!cache.CLASS_TO_SELF_ANALYSIS_DONE.containsKey(className)){var grammarProductions=cache.getProductionsForClass(className);definitionErrors=cache.CLASS_TO_DEFINITION_ERRORS.get(className);var resolverErrors=resolver.resolveGrammar(grammarProductions);definitionErrors.push.apply(definitionErrors,resolverErrors),cache.CLASS_TO_SELF_ANALYSIS_DONE.put(className,!0);var validationErrors=checks.validateGrammar(grammarProductions.values());if(definitionErrors.push.apply(definitionErrors,validationErrors),!_.isEmpty(definitionErrors)&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw defErrorsMsgs=_.map(definitionErrors,function(defError){return defError.message}),new Error("Parser Definition Errors detected\n: "+defErrorsMsgs.join("\n-------------------------------\n"));if(_.isEmpty(definitionErrors)){var allFollows=follows.computeAllProdsFollows(grammarProductions.values());cache.setResyncFollowsForClass(className,allFollows)}}if(!_.isEmpty(cache.CLASS_TO_DEFINITION_ERRORS.get(className))&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw defErrorsMsgs=_.map(cache.CLASS_TO_DEFINITION_ERRORS.get(className),function(defError){return defError.message}),new Error("Parser Definition Errors detected\n: "+defErrorsMsgs.join("\n-------------------------------\n"))},Object.defineProperty(Parser.prototype,"input",{get:function(){return _.clone(this._input)},set:function(newInput){this.reset(),this._input=newInput},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 chevrotain.EOF},Parser.prototype.getGAstProductions=function(){return cache.getProductionsForClass(this.className)},Parser.prototype.isBackTracking=function(){return!_.isEmpty(this.isBackTrackingStack)},Parser.prototype.SAVE_ERROR=function(error){if(exceptions.isRecognitionException(error))return this.errors.push(error),error;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(howMuch){return this._input.length<=this.inputIdx+howMuch?new chevrotain.EOF:this._input[this.inputIdx+howMuch]},Parser.prototype.isNextRule=function(ruleName){var classLAFuncs=cache.getLookaheadFuncsForClass(this.className),condition=classLAFuncs.get(ruleName);if(void 0===condition){var ruleGrammar=this.getGAstProductions().get(ruleName);condition=lookahead.buildLookaheadForTopLevel(ruleGrammar),classLAFuncs.put(ruleName,condition)}return condition.call(this)},Parser.prototype.BACKTRACK=function(grammarRule,isValid){var _this=this;return function(){_this.isBackTrackingStack.push(1);var orgState=_this.saveRecogState();try{var ruleResult=grammarRule.call(_this);return isValid(ruleResult)}catch(e){if(exceptions.isRecognitionException(e))return!1;throw e}finally{_this.reloadRecogState(orgState),_this.isBackTrackingStack.pop()}}},Parser.prototype.SKIP_TOKEN=function(){return this.inputIdx<=this._input.length-2?(this.inputIdx++,this.NEXT_TOKEN()):new chevrotain.EOF},Parser.prototype.CONSUME=function(tokClass){return this.CONSUME1(tokClass)},Parser.prototype.CONSUME1=function(tokClass){return this.consumeInternal(tokClass,1)},Parser.prototype.CONSUME2=function(tokClass){return this.consumeInternal(tokClass,2)},Parser.prototype.CONSUME3=function(tokClass){return this.consumeInternal(tokClass,3)},Parser.prototype.CONSUME4=function(tokClass){return this.consumeInternal(tokClass,4)},Parser.prototype.CONSUME5=function(tokClass){return this.consumeInternal(tokClass,5)},Parser.prototype.SUBRULE=function(ruleToCall,args){return void 0===args&&(args=[]),this.SUBRULE1(ruleToCall,args)},Parser.prototype.SUBRULE1=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,1,args)},Parser.prototype.SUBRULE2=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,2,args)},Parser.prototype.SUBRULE3=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,3,args)},Parser.prototype.SUBRULE4=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,4,args)},Parser.prototype.SUBRULE5=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,5,args)},Parser.prototype.OPTION=function(laFuncOrAction,action){return this.OPTION1.call(this,laFuncOrAction,action)},Parser.prototype.OPTION1=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(1)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION2=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(2)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION3=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(3)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION4=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(4)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION5=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(5)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OR=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.OR1(alts,errMsgTypes,ignoreAmbiguities)},Parser.prototype.OR1=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,1,ignoreAmbiguities)},Parser.prototype.OR2=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,2,ignoreAmbiguities)},Parser.prototype.OR3=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,3,ignoreAmbiguities)},Parser.prototype.OR4=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,4,ignoreAmbiguities)},Parser.prototype.OR5=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,5,ignoreAmbiguities)},Parser.prototype.MANY=function(laFuncOrAction,action){return this.MANY1.call(this,laFuncOrAction,action)},Parser.prototype.MANY1=function(laFuncOrAction,action){this.manyInternal(this.MANY1,"MANY1",1,laFuncOrAction,action)},Parser.prototype.MANY2=function(laFuncOrAction,action){this.manyInternal(this.MANY2,"MANY2",2,laFuncOrAction,action)},Parser.prototype.MANY3=function(laFuncOrAction,action){this.manyInternal(this.MANY3,"MANY3",3,laFuncOrAction,action)},Parser.prototype.MANY4=function(laFuncOrAction,action){this.manyInternal(this.MANY4,"MANY4",4,laFuncOrAction,action)},Parser.prototype.MANY5=function(laFuncOrAction,action){this.manyInternal(this.MANY5,"MANY5",5,laFuncOrAction,action)},Parser.prototype.MANY_SEP=function(separator,laFuncOrAction,action){return this.MANY_SEP1.call(this,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP1=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP1,"MANY_SEP1",1,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP2=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP2,"MANY_SEP2",2,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP3=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP3,"MANY_SEP3",3,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP4=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP4,"MANY_SEP4",4,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP5=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP5,"MANY_SEP5",5,separator,laFuncOrAction,action)},Parser.prototype.AT_LEAST_ONE=function(laFuncOrAction,action,errMsg){return this.AT_LEAST_ONE1.call(this,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE1=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE1,"AT_LEAST_ONE1",1,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE2=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE2,"AT_LEAST_ONE2",2,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE3=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE3,"AT_LEAST_ONE3",3,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE4=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE4,"AT_LEAST_ONE4",4,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE5=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE5,"AT_LEAST_ONE5",5,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP=function(separator,laFuncOrAction,action,errMsg){return this.AT_LEAST_ONE_SEP1.call(this,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP1=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP1",1,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP2=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP2",2,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP3=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP3",3,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP4=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP4",4,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP5=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP5",5,separator,laFuncOrAction,action,errMsg)},Parser.prototype.RULE_NO_RESYNC=function(ruleName,impl,invalidRet){return this.RULE(ruleName,impl,invalidRet,!1)},Parser.prototype.RULE=function(ruleName,impl,invalidRet,doReSync){void 0===invalidRet&&(invalidRet=this.defaultInvalidReturn),void 0===doReSync&&(doReSync=!0);var ruleNameErrors=checks.validateRuleName(ruleName,this.definedRulesNames,this.className);this.definedRulesNames.push(ruleName),this.definitionErrors.push.apply(this.definitionErrors,ruleNameErrors);var parserClassProductions=cache.getProductionsForClass(this.className);if(!parserClassProductions.containsKey(ruleName)){var gastProduction=gastBuilder.buildTopProduction(impl.toString(),ruleName,this.tokensMap);parserClassProductions.put(ruleName,gastProduction)}var wrappedGrammarRule=function(idxInCallingRule,args){void 0===idxInCallingRule&&(idxInCallingRule=1),void 0===args&&(args=[]),this.ruleInvocationStateUpdate(ruleName,idxInCallingRule);try{return impl.apply(this,args)}catch(e){var isFirstInvokedRule=1===this.RULE_STACK.length,reSyncEnabled=isFirstInvokedRule||doReSync&&!this.isBackTracking()&&this.isErrorRecoveryEnabled;if(reSyncEnabled&&exceptions.isRecognitionException(e)){var reSyncTokType=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(reSyncTokType))return this.reSyncTo(reSyncTokType),invalidRet();throw e}throw e}finally{this.ruleFinallyStateUpdate()}},ruleNamePropName="ruleName";return wrappedGrammarRule[ruleNamePropName]=ruleName,wrappedGrammarRule},Parser.prototype.ruleInvocationStateUpdate=function(ruleName,idxInCallingRule){this.RULE_OCCURRENCE_STACK.push(idxInCallingRule),this.RULE_STACK.push(ruleName)},Parser.prototype.ruleFinallyStateUpdate=function(){this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop();var maxInputIdx=this._input.length-1;if(0===this.RULE_STACK.length&&this.inputIdx"+expectedTokName+"<-- but found -->'"+nextTokenWithoutResync.image+"'<--";return this.SAVE_ERROR(new exceptions.MismatchedTokenException(msg,nextTokenWithoutResync)),void grammarRule.apply(this,grammarRuleArgs)}currToken instanceof reSyncTokType&&(passedResyncPoint=!0),currToken=this.SKIP_TOKEN()}this.inputIdx=orgInputIdx},Parser.prototype.shouldInRepetitionRecoveryBeTried=function(expectTokAfterLastMatch,nextTokIdx){return void 0===expectTokAfterLastMatch||void 0===nextTokIdx?!1:this.NEXT_TOKEN()instanceof expectTokAfterLastMatch?!1:this.isBackTracking()?!1:this.canPerformInRuleRecovery(expectTokAfterLastMatch,this.getFollowsForInRuleRecovery(expectTokAfterLastMatch,nextTokIdx))?!1:!0},Parser.prototype.getFollowsForInRuleRecovery=function(tokClass,tokIdxInRule){var pathRuleStack=_.clone(this.RULE_STACK),pathOccurrenceStack=_.clone(this.RULE_OCCURRENCE_STACK),grammarPath={ruleStack:pathRuleStack,occurrenceStack:pathOccurrenceStack,lastTok:tokClass,lastTokOccurrence:tokIdxInRule},topRuleName=_.first(pathRuleStack),gastProductions=this.getGAstProductions(),topProduction=gastProductions.get(topRuleName),follows=new interp.NextAfterTokenWalker(topProduction,grammarPath).startWalking();return follows},Parser.prototype.tryInRuleRecovery=function(expectedTokType,follows){if(this.canRecoverWithSingleTokenInsertion(expectedTokType,follows)){var tokToInsert=this.getTokenToInsert(expectedTokType);return tokToInsert.isInsertedInRecovery=!0,tokToInsert}if(this.canRecoverWithSingleTokenDeletion(expectedTokType)){var nextTok=this.SKIP_TOKEN();return this.inputIdx++,nextTok}throw new InRuleRecoveryException("sad sad panda")},Parser.prototype.canPerformInRuleRecovery=function(expectedToken,follows){return this.canRecoverWithSingleTokenInsertion(expectedToken,follows)||this.canRecoverWithSingleTokenDeletion(expectedToken)},Parser.prototype.canRecoverWithSingleTokenInsertion=function(expectedTokType,follows){if(!this.canTokenTypeBeInsertedInRecovery(expectedTokType))return!1;if(_.isEmpty(follows))return!1;var mismatchedTok=this.NEXT_TOKEN(),isMisMatchedTokInFollows=void 0!==_.find(follows,function(possibleFollowsTokType){return mismatchedTok instanceof possibleFollowsTokType});return isMisMatchedTokInFollows},Parser.prototype.canRecoverWithSingleTokenDeletion=function(expectedTokType){var isNextTokenWhatIsExpected=this.LA(2)instanceof expectedTokType;return isNextTokenWhatIsExpected},Parser.prototype.isInCurrentRuleReSyncSet=function(token){var followKey=this.getCurrFollowKey(),currentRuleReSyncSet=this.getFollowSetFromFollowKey(followKey);return _.contains(currentRuleReSyncSet,token)},Parser.prototype.findReSyncTokenType=function(){for(var allPossibleReSyncTokTypes=this.flattenFollowSet(),nextToken=this.NEXT_TOKEN(),k=2;;){var nextTokenType=nextToken.constructor;if(_.contains(allPossibleReSyncTokTypes,nextTokenType))return nextTokenType;nextToken=this.LA(k),k++}},Parser.prototype.getCurrFollowKey=function(){if(1===this.RULE_STACK.length)return EOF_FOLLOW_KEY;var currRuleIdx=this.RULE_STACK.length-1,currRuleOccIdx=currRuleIdx,prevRuleIdx=currRuleIdx-1;return{ruleName:this.RULE_STACK[currRuleIdx],idxInCallingRule:this.RULE_OCCURRENCE_STACK[currRuleOccIdx],inRule:this.RULE_STACK[prevRuleIdx]}},Parser.prototype.buildFullFollowKeyStack=function(){var _this=this;return _.map(this.RULE_STACK,function(ruleName,idx){return 0===idx?EOF_FOLLOW_KEY:{ruleName:ruleName,idxInCallingRule:_this.RULE_OCCURRENCE_STACK[idx],inRule:_this.RULE_STACK[idx-1]}})},Parser.prototype.flattenFollowSet=function(){var _this=this,followStack=_.map(this.buildFullFollowKeyStack(),function(currKey){return _this.getFollowSetFromFollowKey(currKey)});return _.flatten(followStack)},Parser.prototype.getFollowSetFromFollowKey=function(followKey){if(followKey===EOF_FOLLOW_KEY)return[chevrotain.EOF];var followName=followKey.ruleName+followKey.idxInCallingRule+IN+followKey.inRule;return cache.getResyncFollowsForClass(this.className).get(followName)},Parser.prototype.reSyncTo=function(tokClass){for(var nextTok=this.NEXT_TOKEN();nextTok instanceof tokClass==!1;)nextTok=this.SKIP_TOKEN()},Parser.prototype.attemptInRepetitionRecovery=function(prodFunc,args,lookaheadFunc,prodName,prodOccurrence,nextToksWalker,prodKeys){var key=this.getKeyForAutomaticLookahead(prodName,prodKeys,prodOccurrence),firstAfterRepInfo=this.firstAfterRepMap.get(key);if(void 0===firstAfterRepInfo){var currRuleName=_.last(this.RULE_STACK),ruleGrammar=this.getGAstProductions().get(currRuleName),walker=new nextToksWalker(ruleGrammar,prodOccurrence);firstAfterRepInfo=walker.startWalking(),this.firstAfterRepMap.put(key,firstAfterRepInfo)}var expectTokAfterLastMatch=firstAfterRepInfo.token,nextTokIdx=firstAfterRepInfo.occurrence,isEndOfRule=firstAfterRepInfo.isEndOfRule;1===this.RULE_STACK.length&&isEndOfRule&&void 0===expectTokAfterLastMatch&&(expectTokAfterLastMatch=chevrotain.EOF,nextTokIdx=1),this.shouldInRepetitionRecoveryBeTried(expectTokAfterLastMatch,nextTokIdx)&&this.tryInRepetitionRecovery(prodFunc,args,lookaheadFunc,expectTokAfterLastMatch)},Parser.prototype.optionInternal=function(condition,action){return condition.call(this)?(action.call(this),!0):!1},Parser.prototype.atLeastOneInternal=function(prodFunc,prodName,prodOccurrence,lookAheadFunc,action,errMsg){if(_.isString(action)&&(errMsg=action,action=lookAheadFunc,lookAheadFunc=this.getLookaheadFuncForAtLeastOne(prodOccurrence)),!lookAheadFunc.call(this))throw this.SAVE_ERROR(new exceptions.EarlyExitException("expecting at least one: "+errMsg,this.NEXT_TOKEN()));for(action.call(this);lookAheadFunc.call(this);)action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(prodFunc,[lookAheadFunc,action,errMsg],lookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterAtLeastOneWalker,this.atLeastOneLookaheadKeys)},Parser.prototype.atLeastOneSepFirstInternal=function(prodFunc,prodName,prodOccurrence,separator,firstIterationLookAheadFunc,action,errMsg){var _this=this,separatorsResult=[];if(_.isString(action)&&(errMsg=action,action=firstIterationLookAheadFunc,firstIterationLookAheadFunc=this.getLookaheadFuncForAtLeastOneSep(prodOccurrence)),!firstIterationLookAheadFunc.call(this))throw this.SAVE_ERROR(new exceptions.EarlyExitException("expecting at least one: "+errMsg,this.NEXT_TOKEN()));action.call(this);for(var separatorLookAheadFunc=function(){return _this.NEXT_TOKEN()instanceof separator};separatorLookAheadFunc();)separatorsResult.push(this.CONSUME(separator)),action.call(this);return this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,this.atLeastOneSepLookaheadKeys,interp.NextTerminalAfterAtLeastOneSepWalker],separatorLookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterAtLeastOneSepWalker,this.atLeastOneSepLookaheadKeys),separatorsResult},Parser.prototype.manyInternal=function(prodFunc,prodName,prodOccurrence,lookAheadFunc,action){for(void 0===action&&(action=lookAheadFunc,lookAheadFunc=this.getLookaheadFuncForMany(prodOccurrence));lookAheadFunc.call(this);)action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(prodFunc,[lookAheadFunc,action],lookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterManyWalker,this.manyLookaheadKeys)},Parser.prototype.manySepFirstInternal=function(prodFunc,prodName,prodOccurrence,separator,firstIterationLookAheadFunc,action){var _this=this,separatorsResult=[];if(void 0===action&&(action=firstIterationLookAheadFunc,firstIterationLookAheadFunc=this.getLookaheadFuncForManySep(prodOccurrence)),firstIterationLookAheadFunc.call(this)){action.call(this);for(var separatorLookAheadFunc=function(){return _this.NEXT_TOKEN()instanceof separator};separatorLookAheadFunc();)separatorsResult.push(this.CONSUME(separator)),action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,this.manySepLookaheadKeys,interp.NextTerminalAfterManySepWalker],separatorLookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterManySepWalker,this.manySepLookaheadKeys); -}return separatorsResult},Parser.prototype.repetitionSepSecondInternal=function(prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,laKeys,nextTerminalAfterWalker){for(;separatorLookAheadFunc();)separatorsResult.push(this.CONSUME(separator)),action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,laKeys,nextTerminalAfterWalker],separatorLookAheadFunc,prodName,prodOccurrence,nextTerminalAfterWalker,laKeys)},Parser.prototype.orInternal=function(alts,errMsgTypes,occurrence,ignoreAmbiguities){if(void 0!==alts[0].WHEN){for(var i=0;i"+expectedTokType+"<-- but found -->'"+nextToken.image+"'<--";throw this.SAVE_ERROR(new exceptions.MismatchedTokenException(msg,nextToken))},Parser.prototype.getKeyForAutomaticLookahead=function(prodName,prodKeys,occurrence){var occuMap=prodKeys[occurrence-1],currRule=_.last(this.RULE_STACK),key=occuMap[currRule];return void 0===key&&(key=prodName+occurrence+IN+currRule,occuMap[currRule]=key),key},Parser.prototype.getLookaheadFuncForOption=function(occurence){var key=this.getKeyForAutomaticLookahead("OPTION",this.optionLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForOption)},Parser.prototype.getLookaheadFuncForOr=function(occurence,ignoreErrors){var key=this.getKeyForAutomaticLookahead("OR",this.orLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForOr,[ignoreErrors])},Parser.prototype.getLookaheadFuncForMany=function(occurence){var key=this.getKeyForAutomaticLookahead("MANY",this.manyLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForMany)},Parser.prototype.getLookaheadFuncForManySep=function(occurence){var key=this.getKeyForAutomaticLookahead("MANY_SEP",this.manySepLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForManySep)},Parser.prototype.getLookaheadFuncForAtLeastOne=function(occurence){var key=this.getKeyForAutomaticLookahead("AT_LEAST_ONE",this.atLeastOneLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForAtLeastOne)},Parser.prototype.getLookaheadFuncForAtLeastOneSep=function(occurence){var key=this.getKeyForAutomaticLookahead("AT_LEAST_ONE_SEP",this.atLeastOneSepLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForAtLeastOneSep)},Parser.prototype.getLookaheadFuncFor=function(key,occurrence,laFuncBuilder,extraArgs){void 0===extraArgs&&(extraArgs=[]);var ruleName=_.last(this.RULE_STACK),condition=this.classLAFuncs.get(key);if(void 0===condition){var ruleGrammar=this.getGAstProductions().get(ruleName);condition=laFuncBuilder.apply(null,[occurrence,ruleGrammar].concat(extraArgs)),this.classLAFuncs.put(key,condition)}return condition},Parser.prototype.saveRecogState=function(){var savedErrors=_.clone(this.errors),savedRuleStack=_.clone(this.RULE_STACK);return{errors:savedErrors,inputIdx:this.inputIdx,RULE_STACK:savedRuleStack}},Parser.prototype.reloadRecogState=function(newState){this.errors=newState.errors,this.inputIdx=newState.inputIdx,this.RULE_STACK=newState.RULE_STACK},Parser.prototype.raiseNoAltException=function(occurrence,errMsgTypes){var errSuffix=" but found: '"+this.NEXT_TOKEN().image+"'";if(void 0===errMsgTypes){var ruleName=_.last(this.RULE_STACK),ruleGrammar=this.getGAstProductions().get(ruleName),nextTokens=new interp.NextInsideOrWalker(ruleGrammar,occurrence).startWalking(),nextTokensFlat=_.flatten(nextTokens),nextTokensNames=_.map(nextTokensFlat,function(currTokenClass){return chevrotain.tokenName(currTokenClass)});errMsgTypes="one of: <"+nextTokensNames.join(" ,")+">"}throw this.SAVE_ERROR(new exceptions.NoViableAltException("expecting: "+errMsgTypes+" "+errSuffix,this.NEXT_TOKEN()))},Parser.IGNORE_AMBIGUITIES=!0,Parser.NO_RESYNC=!1,Parser.DEFER_DEFINITION_ERRORS_HANDLING=!1,Parser}();chevrotain.Parser=Parser,InRuleRecoveryException.prototype=Error.prototype}(chevrotain||(chevrotain={}));var testMode="object"==typeof global&&global.CHEV_TEST_MODE||"object"==typeof window&&window.CHEV_TEST_MODE,API={};return testMode?(console.log("running in TEST_MODE"),API=chevrotain):(API.VERSION="0.5.12",API.Parser=chevrotain.Parser,API.Lexer=chevrotain.Lexer,API.Token=chevrotain.Token,API.VirtualToken=chevrotain.VirtualToken,API.EOF=chevrotain.EOF,API.extendToken=chevrotain.extendToken,API.tokenName=chevrotain.tokenName,API.EMPTY_ALT=chevrotain.EMPTY_ALT,API.exceptions={},API.exceptions.isRecognitionException=chevrotain.exceptions.isRecognitionException,API.exceptions.EarlyExitException=chevrotain.exceptions.EarlyExitException,API.exceptions.MismatchedTokenException=chevrotain.exceptions.MismatchedTokenException,API.exceptions.NotAllInputParsedException=chevrotain.exceptions.NotAllInputParsedException,API.exceptions.NoViableAltException=chevrotain.exceptions.NoViableAltException,API.gast={},API.gast.GAstVisitor=chevrotain.gast.GAstVisitor,API.gast.Flat=chevrotain.gast.Flat,API.gast.Repetition=chevrotain.gast.Repetition,API.gast.RepetitionWithSeparator=chevrotain.gast.RepetitionWithSeparator,API.gast.RepetitionMandatory=chevrotain.gast.RepetitionMandatory,API.gast.RepetitionMandatoryWithSeparator=chevrotain.gast.RepetitionMandatoryWithSeparator,API.gast.Option=chevrotain.gast.Option,API.gast.Alternation=chevrotain.gast.Alternation,API.gast.NonTerminal=chevrotain.gast.NonTerminal,API.gast.Terminal=chevrotain.gast.Terminal,API.gast.Rule=chevrotain.gast.Rule),API}); \ No newline at end of file +/*! chevrotain - v0.5.13 - 2016-01-03 */ +!function(root,factory){"function"==typeof define&&define.amd?define("chevrotain",["lodash"],function(a0){return root.API=factory(a0)}):"object"==typeof exports?module.exports=factory(require("lodash")):root.chevrotain=factory(_)}(this,function(_){var utils;!function(utils){function isEmpty(arr){return 0===arr.length}function keys(obj){return Object.keys(obj)}function values(obj){for(var vals=[],keys=Object.keys(obj),i=0;i0;){for(match=null,i=0;imatch[0].length&&(match=matchAlt,i=longerAltIdx));break}if(null!==match){if(matchedImage=match[0],imageLength=matchedImage.length,group=this.patternIdxToGroup[i],void 0!==group&&(tokClass=this.patternIdxToClass[i],newToken=new tokClass(matchedImage,offset,line,column),"default"===group?matchedTokens.push(newToken):groups[group].push(newToken)),text=text.slice(imageLength),offset+=imageLength,column+=imageLength,canMatchedContainLineTerminator=this.patternIdxToCanLineTerminator[i]){var lineTerminatorsInMatch=chevrotain.countLineTerminators(matchedImage);if(0!==lineTerminatorsInMatch){for(line+=lineTerminatorsInMatch,lastLTIdx=imageLength-1;lastLTIdx>=0&&(c=matchedImage.charCodeAt(lastLTIdx),13!==c&&10!==c);)lastLTIdx--;column=imageLength-lastLTIdx,void 0!==group&&(lastCharIsLT=lastLTIdx===imageLength-1,fixForEndingInLT=lastCharIsLT?-1:0,1===lineTerminatorsInMatch&&lastCharIsLT||(newToken.endLine=line+fixForEndingInLT,newToken.endColumn=column-1+-fixForEndingInLT))}}}else{for(var errorStartOffset=offset,errorLine=line,errorColumn=column,foundResyncPoint=!1;!foundResyncPoint&&text.length>0;)for(droppedChar=text.charCodeAt(0),10===droppedChar||13===droppedChar&&(1===text.length||text.length>1&&10!==text.charCodeAt(1))?(line++,column=1):column++,text=text.substr(1),offset++,j=0;j"+orgInput.charAt(errorStartOffset)+"<- at offset: "+errorStartOffset+","+(" skipped "+(offset-errorStartOffset)+" characters."),errors.push({line:errorLine,column:errorColumn,length:errLength,message:errorMessage})}}return{tokens:matchedTokens,groups:groups,errors:errors}},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}());chevrotain.Lexer=Lexer}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){function analyzeTokenClasses(tokenClasses){var onlyRelevantClasses=_.reject(tokenClasses,function(currClass){return currClass[PATTERN]===chevrotain.Lexer.NA}),allTransformedPatterns=utils.map(onlyRelevantClasses,function(currClass){return addStartOfInput(currClass[PATTERN])}),allPatternsToClass=_.zipObject(allTransformedPatterns,onlyRelevantClasses),patternIdxToClass=utils.map(allTransformedPatterns,function(pattern){return allPatternsToClass[pattern.toString()]}),patternIdxToGroup=utils.map(onlyRelevantClasses,function(clazz){var groupName=clazz.GROUP;if(groupName!==chevrotain.Lexer.SKIPPED){if(_.isString(groupName))return groupName;if(_.isUndefined(groupName))return"default";throw Error("non exhaustive match")}}),patternIdxToLongerAltIdx=utils.map(onlyRelevantClasses,function(clazz){var longerAltClass=clazz.LONGER_ALT;if(longerAltClass){var longerAltIdx=_.indexOf(onlyRelevantClasses,longerAltClass);return longerAltIdx}}),patternIdxToCanLineTerminator=utils.map(allTransformedPatterns,function(pattern){return/\\n|\\r|\\s/g.test(pattern.source)}),emptyGroups=_.reduce(onlyRelevantClasses,function(acc,clazz){var groupName=clazz.GROUP;return _.isString(groupName)&&(acc[groupName]=[]),acc},{});return{allPatterns:allTransformedPatterns,patternIdxToClass:patternIdxToClass,patternIdxToGroup:patternIdxToGroup,patternIdxToLongerAltIdx:patternIdxToLongerAltIdx,patternIdxToCanLineTerminator:patternIdxToCanLineTerminator,emptyGroups:emptyGroups}}function validatePatterns(tokenClasses){var errors=[],missingResult=findMissingPatterns(tokenClasses),validTokenClasses=missingResult.validTokenClasses;errors=errors.concat(missingResult.errors);var invalidResult=findInvalidPatterns(validTokenClasses);return validTokenClasses=invalidResult.validTokenClasses,errors=errors.concat(invalidResult.errors),errors=errors.concat(findEndOfInputAnchor(validTokenClasses)),errors=errors.concat(findUnsupportedFlags(validTokenClasses)),errors=errors.concat(findDuplicatePatterns(validTokenClasses)),errors=errors.concat(findInvalidGroupType(validTokenClasses))}function findMissingPatterns(tokenClasses){var tokenClassesWithMissingPattern=_.filter(tokenClasses,function(currClass){return!_.has(currClass,PATTERN)}),errors=utils.map(tokenClassesWithMissingPattern,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- missing static 'PATTERN' property",type:chevrotain.LexerDefinitionErrorType.MISSING_PATTERN,tokenClasses:[currClass]}}),validTokenClasses=_.difference(tokenClasses,tokenClassesWithMissingPattern);return{errors:errors,validTokenClasses:validTokenClasses}}function findInvalidPatterns(tokenClasses){var tokenClassesWithInvalidPattern=_.filter(tokenClasses,function(currClass){var pattern=currClass[PATTERN];return!_.isRegExp(pattern)}),errors=utils.map(tokenClassesWithInvalidPattern,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'PATTERN' can only be a RegExp",type:chevrotain.LexerDefinitionErrorType.INVALID_PATTERN,tokenClasses:[currClass]}}),validTokenClasses=_.difference(tokenClasses,tokenClassesWithInvalidPattern);return{errors:errors,validTokenClasses:validTokenClasses}}function findEndOfInputAnchor(tokenClasses){var invalidRegex=_.filter(tokenClasses,function(currClass){var pattern=currClass[PATTERN];return end_of_input.test(pattern.source)}),errors=utils.map(invalidRegex,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'PATTERN' cannot contain end of input anchor '$'",type:chevrotain.LexerDefinitionErrorType.EOI_ANCHOR_FOUND,tokenClasses:[currClass]}});return errors}function findUnsupportedFlags(tokenClasses){var invalidFlags=_.filter(tokenClasses,function(currClass){var pattern=currClass[PATTERN];return pattern instanceof RegExp&&(pattern.multiline||pattern.global)}),errors=utils.map(invalidFlags,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:chevrotain.LexerDefinitionErrorType.UNSUPPORTED_FLAGS_FOUND,tokenClasses:[currClass]}});return errors}function findDuplicatePatterns(tokenClasses){var found=[],identicalPatterns=utils.map(tokenClasses,function(outerClass){return _.reduce(tokenClasses,function(result,innerClass){return outerClass.PATTERN.source!==innerClass.PATTERN.source||_.contains(found,innerClass)||innerClass.PATTERN===chevrotain.Lexer.NA?result:(found.push(innerClass),_.union(result,[innerClass]))},[])});identicalPatterns=_.compact(identicalPatterns);var duplicatePatterns=_.filter(identicalPatterns,function(currIdenticalSet){return _.size(currIdenticalSet)>1}),errors=utils.map(duplicatePatterns,function(setOfIdentical){var classNames=utils.map(setOfIdentical,function(currClass){return chevrotain.tokenName(currClass)}),dupPatternSrc=_.first(setOfIdentical).PATTERN;return{message:"The same RegExp pattern ->"+dupPatternSrc+"<-"+("has been used in all the following classes: "+classNames.join(", ")+" <-"),type:chevrotain.LexerDefinitionErrorType.DUPLICATE_PATTERNS_FOUND,tokenClasses:setOfIdentical}});return errors}function findInvalidGroupType(tokenClasses){var invalidTypes=_.filter(tokenClasses,function(clazz){if(!_.has(clazz,"GROUP"))return!1;var group=clazz.GROUP;return group!==chevrotain.Lexer.SKIPPED&&group!==chevrotain.Lexer.NA&&!_.isString(group)}),errors=utils.map(invalidTypes,function(currClass){return{message:"Token class: ->"+chevrotain.tokenName(currClass)+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:chevrotain.LexerDefinitionErrorType.INVALID_GROUP_TYPE_FOUND,tokenClasses:[currClass]}});return errors}function addStartOfInput(pattern){var flags=pattern.ignoreCase?"i":"";return new RegExp("^(?:"+pattern.source+")",flags)}function countLineTerminators(text){for(var lineTerminators=0,currOffset=0;currOffsetstart||start>end)}var Range=function(){function Range(start,end){if(this.start=start,this.end=end,!isValidRange(start,end))throw new Error("INVALID RANGE")}return Range.prototype.contains=function(num){return this.start<=num&&this.end>=num},Range.prototype.containsRange=function(other){return this.start<=other.start&&this.end>=other.end},Range.prototype.isContainedInRange=function(other){return other.containsRange(this)},Range.prototype.strictlyContainsRange=function(other){return this.startother.end},Range.prototype.isStrictlyContainedInRange=function(other){return other.strictlyContainsRange(this)},Range}();range.Range=Range,range.isValidRange=isValidRange}(range=chevrotain.range||(chevrotain.range={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var constants;!function(constants){constants.IN="_~IN~_"}(constants=chevrotain.constants||(chevrotain.constants={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var gast;!function(gast){var AbstractProduction=function(){function AbstractProduction(definition){this.definition=definition,this.implicitOccurrenceIndex=!1}return AbstractProduction.prototype.accept=function(visitor){visitor.visit(this),_.forEach(this.definition,function(prod){prod.accept(visitor)})},AbstractProduction}();gast.AbstractProduction=AbstractProduction;var NonTerminal=function(_super){function NonTerminal(nonTerminalName,referencedRule,occurrenceInParent){void 0===referencedRule&&(referencedRule=void 0),void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,[]),this.nonTerminalName=nonTerminalName,this.referencedRule=referencedRule,this.occurrenceInParent=occurrenceInParent}return __extends(NonTerminal,_super),Object.defineProperty(NonTerminal.prototype,"definition",{get:function(){return void 0!==this.referencedRule?this.referencedRule.definition:[]},set:function(definition){},enumerable:!0,configurable:!0}),NonTerminal.prototype.accept=function(visitor){visitor.visit(this)},NonTerminal}(AbstractProduction);gast.NonTerminal=NonTerminal;var Rule=function(_super){function Rule(name,definition,orgText){void 0===orgText&&(orgText=""),_super.call(this,definition),this.name=name,this.orgText=orgText}return __extends(Rule,_super),Rule}(AbstractProduction);gast.Rule=Rule;var Flat=function(_super){function Flat(definition){_super.call(this,definition)}return __extends(Flat,_super),Flat}(AbstractProduction);gast.Flat=Flat;var Option=function(_super){function Option(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(Option,_super),Option}(AbstractProduction);gast.Option=Option;var RepetitionMandatory=function(_super){function RepetitionMandatory(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(RepetitionMandatory,_super),RepetitionMandatory}(AbstractProduction);gast.RepetitionMandatory=RepetitionMandatory;var RepetitionMandatoryWithSeparator=function(_super){function RepetitionMandatoryWithSeparator(definition,separator,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.separator=separator,this.occurrenceInParent=occurrenceInParent}return __extends(RepetitionMandatoryWithSeparator,_super),RepetitionMandatoryWithSeparator}(AbstractProduction);gast.RepetitionMandatoryWithSeparator=RepetitionMandatoryWithSeparator;var Repetition=function(_super){function Repetition(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(Repetition,_super),Repetition}(AbstractProduction);gast.Repetition=Repetition;var RepetitionWithSeparator=function(_super){function RepetitionWithSeparator(definition,separator,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.separator=separator,this.occurrenceInParent=occurrenceInParent}return __extends(RepetitionWithSeparator,_super),RepetitionWithSeparator}(AbstractProduction);gast.RepetitionWithSeparator=RepetitionWithSeparator;var Alternation=function(_super){function Alternation(definition,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),_super.call(this,definition),this.occurrenceInParent=occurrenceInParent}return __extends(Alternation,_super),Alternation}(AbstractProduction);gast.Alternation=Alternation;var Terminal=function(){function Terminal(terminalType,occurrenceInParent){void 0===occurrenceInParent&&(occurrenceInParent=1),this.terminalType=terminalType,this.occurrenceInParent=occurrenceInParent,this.implicitOccurrenceIndex=!1}return Terminal.prototype.accept=function(visitor){visitor.visit(this)},Terminal}();gast.Terminal=Terminal;var GAstVisitor=function(){function GAstVisitor(){}return GAstVisitor.prototype.visit=function(node){node instanceof NonTerminal?this.visitNonTerminal(node):node instanceof Flat?this.visitFlat(node):node instanceof Option?this.visitOption(node):node instanceof RepetitionMandatory?this.visitRepetitionMandatory(node):node instanceof RepetitionMandatoryWithSeparator?this.visitRepetitionMandatoryWithSeparator(node):node instanceof RepetitionWithSeparator?this.visitRepetitionWithSeparator(node):node instanceof Repetition?this.visitRepetition(node):node instanceof Alternation?this.visitAlternation(node):node instanceof Terminal&&this.visitTerminal(node)},GAstVisitor.prototype.visitNonTerminal=function(node){},GAstVisitor.prototype.visitFlat=function(node){},GAstVisitor.prototype.visitOption=function(node){},GAstVisitor.prototype.visitRepetition=function(node){},GAstVisitor.prototype.visitRepetitionMandatory=function(node){},GAstVisitor.prototype.visitRepetitionMandatoryWithSeparator=function(node){},GAstVisitor.prototype.visitRepetitionWithSeparator=function(node){},GAstVisitor.prototype.visitAlternation=function(node){},GAstVisitor.prototype.visitTerminal=function(node){},GAstVisitor}();gast.GAstVisitor=GAstVisitor}(gast=chevrotain.gast||(chevrotain.gast={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var gast;!function(gast){function isSequenceProd(prod){return prod instanceof gast.Flat||prod instanceof gast.Option||prod instanceof gast.Repetition||prod instanceof gast.RepetitionMandatory||prod instanceof gast.RepetitionMandatoryWithSeparator||prod instanceof gast.RepetitionWithSeparator||prod instanceof gast.Terminal||prod instanceof gast.Rule}function isOptionalProd(prod,alreadyVisited){void 0===alreadyVisited&&(alreadyVisited=[]);var isDirectlyOptional=prod instanceof gast.Option||prod instanceof gast.Repetition||prod instanceof gast.RepetitionWithSeparator;return isDirectlyOptional?!0:prod instanceof gast.Alternation?_.some(prod.definition,function(subProd){return isOptionalProd(subProd,alreadyVisited)}):prod instanceof gast.NonTerminal&&_.contains(alreadyVisited,prod)?!1:prod instanceof gast.AbstractProduction?(prod instanceof gast.NonTerminal&&alreadyVisited.push(prod),_.every(prod.definition,function(subProd){return isOptionalProd(subProd,alreadyVisited)})):!1}function isBranchingProd(prod){return prod instanceof gast.Alternation}function getProductionDslName(prod){var clazz=prod.constructor,prodName=lang.functionName(clazz);return productionToDslName[prodName]}var lang=chevrotain.lang;gast.isSequenceProd=isSequenceProd,gast.isOptionalProd=isOptionalProd,gast.isBranchingProd=isBranchingProd;var productionToDslName={};productionToDslName[lang.functionName(gast.NonTerminal)]="SUBRULE",productionToDslName[lang.functionName(gast.Option)]="OPTION",productionToDslName[lang.functionName(gast.RepetitionMandatory)]="AT_LEAST_ONE",productionToDslName[lang.functionName(gast.RepetitionMandatoryWithSeparator)]="AT_LEAST_ONE_SEP",productionToDslName[lang.functionName(gast.RepetitionWithSeparator)]="MANY_SEP",productionToDslName[lang.functionName(gast.Repetition)]="MANY",productionToDslName[lang.functionName(gast.Alternation)]="OR",productionToDslName[lang.functionName(gast.Terminal)]="CONSUME",gast.getProductionDslName=getProductionDslName}(gast=chevrotain.gast||(chevrotain.gast={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var first;!function(first_1){function first(prod){if(prod instanceof gast.NonTerminal)return first(prod.referencedRule);if(prod instanceof gast.Terminal)return firstForTerminal(prod);if(gast.isSequenceProd(prod))return firstForSequence(prod);if(gast.isBranchingProd(prod))return firstForBranching(prod);throw Error("non exhaustive match")}function firstForSequence(prod){for(var currSubProd,firstSet=[],seq=prod.definition,nextSubProdIdx=0,hasInnerProdsRemaining=seq.length>nextSubProdIdx,isLastInnerProdOptional=!0;hasInnerProdsRemaining&&isLastInnerProdOptional;)currSubProd=seq[nextSubProdIdx],isLastInnerProdOptional=gast.isOptionalProd(currSubProd),firstSet=firstSet.concat(first(currSubProd)),nextSubProdIdx+=1,hasInnerProdsRemaining=seq.length>nextSubProdIdx;return _.uniq(firstSet)}function firstForBranching(prod){var allAlternativesFirsts=utils.map(prod.definition,function(innerProd){return first(innerProd)});return _.uniq(_.flatten(allAlternativesFirsts))}function firstForTerminal(terminal){return[terminal.terminalType]}var gast=chevrotain.gast;first_1.first=first,first_1.firstForSequence=firstForSequence,first_1.firstForBranching=firstForBranching,first_1.firstForTerminal=firstForTerminal}(first=chevrotain.first||(chevrotain.first={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var rest;!function(rest){function restForRepetitionWithSeparator(repSepProd,currRest,prevRest){var repSepRest=[new g.Option([new g.Terminal(repSepProd.separator)].concat(repSepProd.definition))],fullRepSepRest=repSepRest.concat(currRest,prevRest);return fullRepSepRest}var g=chevrotain.gast,RestWalker=function(){function RestWalker(){}return RestWalker.prototype.walk=function(prod,prevRest){var _this=this;void 0===prevRest&&(prevRest=[]),_.forEach(prod.definition,function(subProd,index){var currRest=_.drop(prod.definition,index+1);if(subProd instanceof g.NonTerminal)_this.walkProdRef(subProd,currRest,prevRest);else if(subProd instanceof g.Terminal)_this.walkTerminal(subProd,currRest,prevRest);else if(subProd instanceof g.Flat)_this.walkFlat(subProd,currRest,prevRest);else if(subProd instanceof g.Option)_this.walkOption(subProd,currRest,prevRest);else if(subProd instanceof g.RepetitionMandatory)_this.walkAtLeastOne(subProd,currRest,prevRest);else if(subProd instanceof g.RepetitionMandatoryWithSeparator)_this.walkAtLeastOneSep(subProd,currRest,prevRest);else if(subProd instanceof g.RepetitionWithSeparator)_this.walkManySep(subProd,currRest,prevRest);else if(subProd instanceof g.Repetition)_this.walkMany(subProd,currRest,prevRest);else{if(!(subProd instanceof g.Alternation))throw Error("non exhaustive match");_this.walkOr(subProd,currRest,prevRest)}})},RestWalker.prototype.walkTerminal=function(terminal,currRest,prevRest){},RestWalker.prototype.walkProdRef=function(refProd,currRest,prevRest){},RestWalker.prototype.walkFlat=function(flatProd,currRest,prevRest){var fullOrRest=currRest.concat(prevRest);this.walk(flatProd,fullOrRest)},RestWalker.prototype.walkOption=function(optionProd,currRest,prevRest){var fullOrRest=currRest.concat(prevRest);this.walk(optionProd,fullOrRest)},RestWalker.prototype.walkAtLeastOne=function(atLeastOneProd,currRest,prevRest){var fullAtLeastOneRest=[new g.Option(atLeastOneProd.definition)].concat(currRest,prevRest);this.walk(atLeastOneProd,fullAtLeastOneRest)},RestWalker.prototype.walkAtLeastOneSep=function(atLeastOneSepProd,currRest,prevRest){var fullAtLeastOneSepRest=restForRepetitionWithSeparator(atLeastOneSepProd,currRest,prevRest);this.walk(atLeastOneSepProd,fullAtLeastOneSepRest)},RestWalker.prototype.walkMany=function(manyProd,currRest,prevRest){var fullManyRest=[new g.Option(manyProd.definition)].concat(currRest,prevRest);this.walk(manyProd,fullManyRest)},RestWalker.prototype.walkManySep=function(manySepProd,currRest,prevRest){var fullManySepRest=restForRepetitionWithSeparator(manySepProd,currRest,prevRest);this.walk(manySepProd,fullManySepRest)},RestWalker.prototype.walkOr=function(orProd,currRest,prevRest){var _this=this,fullOrRest=currRest.concat(prevRest);_.forEach(orProd.definition,function(alt){var prodWrapper=new chevrotain.gast.Flat([alt]);_this.walk(prodWrapper,fullOrRest)})},RestWalker}();rest.RestWalker=RestWalker}(rest=chevrotain.rest||(chevrotain.rest={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var follow;!function(follow){function computeAllProdsFollows(topProductions){var reSyncFollows=new lang.HashTable;return _.forEach(topProductions,function(topProd){var currRefsFollow=new ResyncFollowsWalker(topProd).startWalking();reSyncFollows.putAll(currRefsFollow)}),reSyncFollows}function buildBetweenProdsFollowPrefix(inner,occurenceInParent){return inner.name+occurenceInParent+IN}function buildInProdFollowPrefix(terminal){var terminalName=chevrotain.tokenName(terminal.terminalType);return terminalName+terminal.occurrenceInParent+IN}var g=chevrotain.gast,r=chevrotain.rest,f=chevrotain.first,IN=chevrotain.constants.IN,lang=chevrotain.lang,ResyncFollowsWalker=function(_super){function ResyncFollowsWalker(topProd){_super.call(this),this.topProd=topProd,this.follows=new lang.HashTable}return __extends(ResyncFollowsWalker,_super),ResyncFollowsWalker.prototype.startWalking=function(){return this.walk(this.topProd),this.follows},ResyncFollowsWalker.prototype.walkTerminal=function(terminal,currRest,prevRest){},ResyncFollowsWalker.prototype.walkProdRef=function(refProd,currRest,prevRest){var followName=buildBetweenProdsFollowPrefix(refProd.referencedRule,refProd.occurrenceInParent)+this.topProd.name,fullRest=currRest.concat(prevRest),restProd=new g.Flat(fullRest),t_in_topProd_follows=f.first(restProd);this.follows.put(followName,t_in_topProd_follows)},ResyncFollowsWalker}(r.RestWalker);follow.ResyncFollowsWalker=ResyncFollowsWalker,follow.computeAllProdsFollows=computeAllProdsFollows,follow.buildBetweenProdsFollowPrefix=buildBetweenProdsFollowPrefix,follow.buildInProdFollowPrefix=buildInProdFollowPrefix}(follow=chevrotain.follow||(chevrotain.follow={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var interpreter;!function(interpreter){var g=chevrotain.gast,f=chevrotain.first,r=chevrotain.rest,AbstractNextPossibleTokensWalker=function(_super){function AbstractNextPossibleTokensWalker(topProd,path){_super.call(this),this.topProd=topProd,this.path=path,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}return __extends(AbstractNextPossibleTokensWalker,_super),AbstractNextPossibleTokensWalker.prototype.startWalking=function(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=_.clone(this.path.ruleStack).reverse(),this.occurrenceStack=_.clone(this.path.occurrenceStack).reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes},AbstractNextPossibleTokensWalker.prototype.walk=function(prod,prevRest){void 0===prevRest&&(prevRest=[]),this.found||_super.prototype.walk.call(this,prod,prevRest)},AbstractNextPossibleTokensWalker.prototype.walkProdRef=function(refProd,currRest,prevRest){if(refProd.referencedRule.name===this.nextProductionName&&refProd.occurrenceInParent===this.nextProductionOccurrence){var fullRest=currRest.concat(prevRest);this.updateExpectedNext(),this.walk(refProd.referencedRule,fullRest)}},AbstractNextPossibleTokensWalker.prototype.updateExpectedNext=function(){utils.isEmpty(this.ruleStack)?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())},AbstractNextPossibleTokensWalker}(r.RestWalker);interpreter.AbstractNextPossibleTokensWalker=AbstractNextPossibleTokensWalker;var NextAfterTokenWalker=function(_super){function NextAfterTokenWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=chevrotain.tokenName(this.path.lastTok),this.nextTerminalOccurrence=this.path.lastTokOccurrence}return __extends(NextAfterTokenWalker,_super),NextAfterTokenWalker.prototype.walkTerminal=function(terminal,currRest,prevRest){ +if(this.isAtEndOfPath&&chevrotain.tokenName(terminal.terminalType)===this.nextTerminalName&&terminal.occurrenceInParent===this.nextTerminalOccurrence&&!this.found){var fullRest=currRest.concat(prevRest),restProd=new g.Flat(fullRest);this.possibleTokTypes=f.first(restProd),this.found=!0}},NextAfterTokenWalker}(AbstractNextPossibleTokensWalker);interpreter.NextAfterTokenWalker=NextAfterTokenWalker;var NextInsideOptionWalker=function(_super){function NextInsideOptionWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOptionOccurrence=0,this.nextOptionOccurrence=this.path.occurrence}return __extends(NextInsideOptionWalker,_super),NextInsideOptionWalker.prototype.walkOption=function(optionProd,currRest,prevRest){if(this.isAtEndOfPath&&optionProd.occurrenceInParent===this.nextOptionOccurrence&&!this.found){var restProd=new g.Flat(optionProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkOption.call(this,optionProd,currRest,prevRest)},NextInsideOptionWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideOptionWalker=NextInsideOptionWalker;var NextInsideManyWalker=function(_super){function NextInsideManyWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideManyWalker,_super),NextInsideManyWalker.prototype.walkMany=function(manyProd,currRest,prevRest){if(this.isAtEndOfPath&&manyProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(manyProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkMany.call(this,manyProd,currRest,prevRest)},NextInsideManyWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideManyWalker=NextInsideManyWalker;var NextInsideManySepWalker=function(_super){function NextInsideManySepWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideManySepWalker,_super),NextInsideManySepWalker.prototype.walkManySep=function(manySepProd,currRest,prevRest){if(this.isAtEndOfPath&&manySepProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(manySepProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkManySep.call(this,manySepProd,currRest,prevRest)},NextInsideManySepWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideManySepWalker=NextInsideManySepWalker;var NextInsideAtLeastOneWalker=function(_super){function NextInsideAtLeastOneWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideAtLeastOneWalker,_super),NextInsideAtLeastOneWalker.prototype.walkAtLeastOne=function(atLeastOneProd,currRest,prevRest){if(this.isAtEndOfPath&&atLeastOneProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(atLeastOneProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkAtLeastOne.call(this,atLeastOneProd,currRest,prevRest)},NextInsideAtLeastOneWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideAtLeastOneWalker=NextInsideAtLeastOneWalker;var NextInsideAtLeastOneSepWalker=function(_super){function NextInsideAtLeastOneSepWalker(topProd,path){_super.call(this,topProd,path),this.path=path,this.nextOccurrence=0,this.nextOccurrence=this.path.occurrence}return __extends(NextInsideAtLeastOneSepWalker,_super),NextInsideAtLeastOneSepWalker.prototype.walkAtLeastOneSep=function(atLeastOneSepProd,currRest,prevRest){if(this.isAtEndOfPath&&atLeastOneSepProd.occurrenceInParent===this.nextOccurrence&&!this.found){var restProd=new g.Flat(atLeastOneSepProd.definition);this.possibleTokTypes=f.first(restProd),this.found=!0}else _super.prototype.walkAtLeastOneSep.call(this,atLeastOneSepProd,currRest,prevRest)},NextInsideAtLeastOneSepWalker}(AbstractNextPossibleTokensWalker);interpreter.NextInsideAtLeastOneSepWalker=NextInsideAtLeastOneSepWalker;var NextInsideOrWalker=function(_super){function NextInsideOrWalker(topRule,occurrence){_super.call(this),this.topRule=topRule,this.occurrence=occurrence,this.result=[]}return __extends(NextInsideOrWalker,_super),NextInsideOrWalker.prototype.startWalking=function(){return this.walk(this.topRule),this.result},NextInsideOrWalker.prototype.walkOr=function(orProd,currRest,prevRest){orProd.occurrenceInParent===this.occurrence?this.result=utils.map(orProd.definition,function(alt){var altWrapper=new chevrotain.gast.Flat([alt]);return f.first(altWrapper)}):_super.prototype.walkOr.call(this,orProd,currRest,prevRest)},NextInsideOrWalker}(r.RestWalker);interpreter.NextInsideOrWalker=NextInsideOrWalker;var AbstractNextTerminalAfterProductionWalker=function(_super){function AbstractNextTerminalAfterProductionWalker(topRule,occurrence){_super.call(this),this.topRule=topRule,this.occurrence=occurrence,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}return __extends(AbstractNextTerminalAfterProductionWalker,_super),AbstractNextTerminalAfterProductionWalker.prototype.startWalking=function(){return this.walk(this.topRule),this.result},AbstractNextTerminalAfterProductionWalker}(r.RestWalker);interpreter.AbstractNextTerminalAfterProductionWalker=AbstractNextTerminalAfterProductionWalker;var NextTerminalAfterManyWalker=function(_super){function NextTerminalAfterManyWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterManyWalker,_super),NextTerminalAfterManyWalker.prototype.walkMany=function(manyProd,currRest,prevRest){if(manyProd.occurrenceInParent===this.occurrence){var firstAfterMany=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterMany,firstAfterMany instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterMany.terminalType,this.result.occurrence=firstAfterMany.occurrenceInParent)}else _super.prototype.walkMany.call(this,manyProd,currRest,prevRest)},NextTerminalAfterManyWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterManyWalker=NextTerminalAfterManyWalker;var NextTerminalAfterManySepWalker=function(_super){function NextTerminalAfterManySepWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterManySepWalker,_super),NextTerminalAfterManySepWalker.prototype.walkManySep=function(manySepProd,currRest,prevRest){if(manySepProd.occurrenceInParent===this.occurrence){var firstAfterManySep=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterManySep,firstAfterManySep instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterManySep.terminalType,this.result.occurrence=firstAfterManySep.occurrenceInParent)}else _super.prototype.walkManySep.call(this,manySepProd,currRest,prevRest)},NextTerminalAfterManySepWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterManySepWalker=NextTerminalAfterManySepWalker;var NextTerminalAfterAtLeastOneWalker=function(_super){function NextTerminalAfterAtLeastOneWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterAtLeastOneWalker,_super),NextTerminalAfterAtLeastOneWalker.prototype.walkAtLeastOne=function(atLeastOneProd,currRest,prevRest){if(atLeastOneProd.occurrenceInParent===this.occurrence){var firstAfterAtLeastOne=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterAtLeastOne,firstAfterAtLeastOne instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterAtLeastOne.terminalType,this.result.occurrence=firstAfterAtLeastOne.occurrenceInParent)}else _super.prototype.walkAtLeastOne.call(this,atLeastOneProd,currRest,prevRest)},NextTerminalAfterAtLeastOneWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterAtLeastOneWalker=NextTerminalAfterAtLeastOneWalker;var NextTerminalAfterAtLeastOneSepWalker=function(_super){function NextTerminalAfterAtLeastOneSepWalker(){_super.apply(this,arguments)}return __extends(NextTerminalAfterAtLeastOneSepWalker,_super),NextTerminalAfterAtLeastOneSepWalker.prototype.walkAtLeastOneSep=function(atleastOneSepProd,currRest,prevRest){if(atleastOneSepProd.occurrenceInParent===this.occurrence){var firstAfterfirstAfterAtLeastOneSep=_.first(currRest.concat(prevRest));this.result.isEndOfRule=void 0===firstAfterfirstAfterAtLeastOneSep,firstAfterfirstAfterAtLeastOneSep instanceof chevrotain.gast.Terminal&&(this.result.token=firstAfterfirstAfterAtLeastOneSep.terminalType,this.result.occurrence=firstAfterfirstAfterAtLeastOneSep.occurrenceInParent)}else _super.prototype.walkAtLeastOneSep.call(this,atleastOneSepProd,currRest,prevRest)},NextTerminalAfterAtLeastOneSepWalker}(AbstractNextTerminalAfterProductionWalker);interpreter.NextTerminalAfterAtLeastOneSepWalker=NextTerminalAfterAtLeastOneSepWalker}(interpreter=chevrotain.interpreter||(chevrotain.interpreter={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var cache;!function(cache){function getProductionsForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_GRAMMAR_PRODUCTIONS)}function getResyncFollowsForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_RESYNC_FOLLOW_SETS)}function setResyncFollowsForClass(className,followSet){cache.CLASS_TO_RESYNC_FOLLOW_SETS.put(className,followSet)}function getLookaheadFuncsForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_LOOKAHEAD_FUNCS)}function getFirstAfterRepForClass(className){return getFromNestedHashTable(className,cache.CLASS_TO_FIRST_AFTER_REPETITION)}function initLookAheadKeyCache(className){cache.CLASS_TO_OR_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_MANY_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_MANY_SEP_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_AT_LEAST_ONE_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),cache.CLASS_TO_OPTION_LA_CACHE[className]=new Array(cache.MAX_OCCURRENCE_INDEX),initSingleLookAheadKeyCache(cache.CLASS_TO_OR_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_MANY_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_MANY_SEP_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_AT_LEAST_ONE_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[className]),initSingleLookAheadKeyCache(cache.CLASS_TO_OPTION_LA_CACHE[className])}function initSingleLookAheadKeyCache(laCache){for(var i=0;ii;i++)for(var currAltTokens=alternativesTokens[i],j=0;j in inside <"+ruleGrammar.name+"> "+("Rule, <"+chevrotain.tokenName(currAmbiguity.token)+"> may appears as the first Terminal in all these alternatives.\n")});throw new Error(errorMessages.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(alternativesTokens){var allTokensFlat=_.flatten(alternativesTokens),uniqueTokensFlat=_.uniq(allTokensFlat),tokensToAltsIndicesItAppearsIn=utils.map(uniqueTokensFlat,function(seekToken){var altsCurrTokenAppearsIn=_.pick(alternativesTokens,function(altToLookIn){return _.find(altToLookIn,function(currToken){return currToken===seekToken})}),altsIndicesTokenAppearsIn=utils.map(utils.keys(altsCurrTokenAppearsIn),function(index){return parseInt(index,10)+1});return{token:seekToken,alts:altsIndicesTokenAppearsIn}}),tokensToAltsIndicesWithAmbiguity=_.filter(tokensToAltsIndicesItAppearsIn,function(tokAndAltsItAppearsIn){return tokAndAltsItAppearsIn.alts.length>1});return tokensToAltsIndicesWithAmbiguity}function buildLookAheadForGrammarProd(prodWalkerConstructor,ruleOccurrence,ruleGrammar){var path={ruleStack:[ruleGrammar.name],occurrenceStack:[1],occurrence:ruleOccurrence},walker=new prodWalkerConstructor(ruleGrammar,path),possibleNextTokTypes=walker.startWalking();return getSimpleLookahead(possibleNextTokTypes)}function getSimpleLookahead(possibleNextTokTypes){return function(){for(var nextToken=this.NEXT_TOKEN(),j=0;j1}),errors=utils.map(utils.values(duplicates),function(currDuplicates){var firstProd=_.first(currDuplicates),msg=createDuplicatesErrorMessage(currDuplicates,topLevelRule.name),dslName=gast.getProductionDslName(firstProd),defError={message:msg,type:chevrotain.ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS,ruleName:topLevelRule.name,dslName:dslName,occurrence:firstProd.occurrenceInParent},param=getExtraProductionArgument(firstProd);return param&&(defError.parameter=param),defError});return errors}function createDuplicatesErrorMessage(duplicateProds,topLevelName){var firstProd=_.first(duplicateProds),index=firstProd.occurrenceInParent,dslName=gast.getProductionDslName(firstProd),extraArgument=getExtraProductionArgument(firstProd),msg="->"+dslName+"<- with occurrence index: ->"+index+"<-\n "+(extraArgument?"and argument: "+extraArgument:"")+"\n appears more than once ("+duplicateProds.length+" times) in the top level rule: "+topLevelName+".\n "+(1===index?"note that "+dslName+" and "+dslName+"1 both have the same occurrence index 1}":"")+"}\n to fix this make sure each usage of "+dslName+" "+(extraArgument?"with the argument: "+extraArgument:"")+"\n in the rule "+topLevelName+" 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 msg=msg.replace(/[ \t]+/g," "),msg=msg.replace(/\s\s+/g,"\n")}function identifyProductionForDuplicates(prod){return gast.getProductionDslName(prod)+"_#_"+prod.occurrenceInParent+"_#_"+getExtraProductionArgument(prod)}function getExtraProductionArgument(prod){return prod instanceof gast.Terminal?chevrotain.tokenName(prod.terminalType):prod instanceof gast.NonTerminal?prod.nonTerminalName:""}function validateRuleName(ruleName,definedRulesNames,className){var errMsg,errors=[];return ruleName.match(ruleNamePattern)||(errMsg="Invalid Grammar rule name --> "+ruleName+" it must match the pattern: "+ruleNamePattern.toString(),errors.push({message:errMsg,type:chevrotain.ParserDefinitionErrorType.INVALID_RULE_NAME,ruleName:ruleName})),_.contains(definedRulesNames,ruleName)&&(errMsg="Duplicate definition, rule: "+ruleName+" is already defined in the grammar: "+className,errors.push({message:errMsg,type:chevrotain.ParserDefinitionErrorType.DUPLICATE_RULE_NAME,ruleName:ruleName})),errors}function validateNoLeftRecursion(topRule,currRule,path){void 0===path&&(path=[]);var errors=[],nextNonTerminals=getFirstNoneTerminal(currRule.definition);if(utils.isEmpty(nextNonTerminals))return[];var ruleName=topRule.name,foundLeftRecursion=_.contains(nextNonTerminals,topRule),pathNames=utils.map(path,function(currRule){return currRule.name}),leftRecursivePath=ruleName+" --> "+pathNames.concat([ruleName]).join(" --> "); +if(foundLeftRecursion){var errMsg="Left Recursion found in grammar.\n"+("rule: <"+ruleName+"> can be invoked from itself (directly or indirectly)\n")+("without consuming any Tokens. The grammar path that causes this is: \n "+leftRecursivePath+"\n")+" To fix this refactor your grammar to remove the left recursion.\nsee: https://en.wikipedia.org/wiki/LL_parser#Left_Factoring.";errors.push({message:errMsg,type:chevrotain.ParserDefinitionErrorType.LEFT_RECURSION,ruleName:ruleName})}var validNextSteps=_.difference(nextNonTerminals,path.concat([topRule])),errorsFromNextSteps=utils.map(validNextSteps,function(currRefRule){var newPath=_.clone(path);return newPath.push(currRefRule),validateNoLeftRecursion(topRule,currRefRule,newPath)});return errors.concat(_.flatten(errorsFromNextSteps))}function getFirstNoneTerminal(definition){var result=[];if(utils.isEmpty(definition))return result;var firstProd=_.first(definition);if(firstProd instanceof gast.NonTerminal){if(void 0===firstProd.referencedRule)return result;result.push(firstProd.referencedRule)}else if(firstProd instanceof gast.Flat||firstProd instanceof gast.Option||firstProd instanceof gast.RepetitionMandatory||firstProd instanceof gast.RepetitionMandatoryWithSeparator||firstProd instanceof gast.RepetitionWithSeparator||firstProd instanceof gast.Repetition)result=result.concat(getFirstNoneTerminal(firstProd.definition));else if(firstProd instanceof gast.Alternation)result=_.flatten(utils.map(firstProd.definition,function(currSubDef){return getFirstNoneTerminal(currSubDef.definition)}));else if(!(firstProd instanceof gast.Terminal))throw Error("non exhaustive match");var isFirstOptional=gast.isOptionalProd(firstProd),hasMore=definition.length>1;if(isFirstOptional&&hasMore){var rest_1=_.drop(definition);return result.concat(getFirstNoneTerminal(rest_1))}return result}function validateEmptyOrAlternative(topLevelRule){var orCollector=new OrCollector;topLevelRule.accept(orCollector);var ors=orCollector.alternations,errors=_.reduce(ors,function(errors,currOr){var exceptLast=_.dropRight(currOr.definition),currErrors=utils.map(exceptLast,function(currAlternative,currAltIdx){return utils.isEmpty(chevrotain.first.first(currAlternative))?{message:"Ambiguous empty alternative: <"+(currAltIdx+1)+">"+(" in inside <"+topLevelRule.name+"> Rule.\n")+"Only the last alternative may be an empty alternative.",type:chevrotain.ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT,ruleName:topLevelRule.name,occurrence:currOr.occurrenceInParent,alternative:currAltIdx+1}:null});return errors.concat(_.compact(currErrors))},[]);return errors}var gast=chevrotain.gast,GAstVisitor=chevrotain.gast.GAstVisitor;checks.validateGrammar=validateGrammar,checks.identifyProductionForDuplicates=identifyProductionForDuplicates;var OccurrenceValidationCollector=function(_super){function OccurrenceValidationCollector(){_super.apply(this,arguments),this.allProductions=[]}return __extends(OccurrenceValidationCollector,_super),OccurrenceValidationCollector.prototype.visitNonTerminal=function(subrule){this.allProductions.push(subrule)},OccurrenceValidationCollector.prototype.visitOption=function(option){this.allProductions.push(option)},OccurrenceValidationCollector.prototype.visitRepetitionWithSeparator=function(manySep){this.allProductions.push(manySep)},OccurrenceValidationCollector.prototype.visitRepetitionMandatory=function(atLeastOne){this.allProductions.push(atLeastOne)},OccurrenceValidationCollector.prototype.visitRepetitionMandatoryWithSeparator=function(atLeastOneSep){this.allProductions.push(atLeastOneSep)},OccurrenceValidationCollector.prototype.visitRepetition=function(many){this.allProductions.push(many)},OccurrenceValidationCollector.prototype.visitAlternation=function(or){this.allProductions.push(or)},OccurrenceValidationCollector.prototype.visitTerminal=function(terminal){this.allProductions.push(terminal)},OccurrenceValidationCollector}(gast.GAstVisitor);checks.OccurrenceValidationCollector=OccurrenceValidationCollector;var ruleNamePattern=/^[a-zA-Z_]\w*$/;checks.validateRuleName=validateRuleName,checks.validateNoLeftRecursion=validateNoLeftRecursion,checks.getFirstNoneTerminal=getFirstNoneTerminal;var OrCollector=function(_super){function OrCollector(){_super.apply(this,arguments),this.alternations=[]}return __extends(OrCollector,_super),OrCollector.prototype.visitAlternation=function(node){this.alternations.push(node)},OrCollector}(GAstVisitor);checks.validateEmptyOrAlternative=validateEmptyOrAlternative}(checks=chevrotain.checks||(chevrotain.checks={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var resolver;!function(resolver){function resolveGrammar(topLevels){var refResolver=new GastRefResolverVisitor(topLevels);return refResolver.resolveRefs(),refResolver.errors}var gast=chevrotain.gast;resolver.resolveGrammar=resolveGrammar;var GastRefResolverVisitor=function(_super){function GastRefResolverVisitor(nameToTopRule){_super.call(this),this.nameToTopRule=nameToTopRule,this.errors=[]}return __extends(GastRefResolverVisitor,_super),GastRefResolverVisitor.prototype.resolveRefs=function(){var _this=this;_.forEach(this.nameToTopRule.values(),function(prod){_this.currTopLevel=prod,prod.accept(_this)})},GastRefResolverVisitor.prototype.visitNonTerminal=function(node){var ref=this.nameToTopRule.get(node.nonTerminalName);if(ref)node.referencedRule=ref;else{var msg="Invalid grammar, reference to rule which is not defined --> "+node.nonTerminalName;this.errors.push({message:msg,type:chevrotain.ParserDefinitionErrorType.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:node.nonTerminalName})}},GastRefResolverVisitor}(gast.GAstVisitor);resolver.GastRefResolverVisitor=GastRefResolverVisitor}(resolver=chevrotain.resolver||(chevrotain.resolver={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){var exceptions;!function(exceptions){function isRecognitionException(error){var recognitionExceptions=[chevrotain.lang.functionName(MismatchedTokenException),chevrotain.lang.functionName(NoViableAltException),chevrotain.lang.functionName(EarlyExitException),chevrotain.lang.functionName(NotAllInputParsedException)];return _.contains(recognitionExceptions,error.name)}function MismatchedTokenException(message,token){this.name=chevrotain.lang.functionName(MismatchedTokenException),this.message=message,this.token=token}function NoViableAltException(message,token){this.name=chevrotain.lang.functionName(NoViableAltException),this.message=message,this.token=token}function NotAllInputParsedException(message,token){this.name=chevrotain.lang.functionName(NotAllInputParsedException),this.message=message,this.token=token}function EarlyExitException(message,token){this.name=chevrotain.lang.functionName(EarlyExitException),this.message=message,this.token=token}exceptions.isRecognitionException=isRecognitionException,exceptions.MismatchedTokenException=MismatchedTokenException,MismatchedTokenException.prototype=Error.prototype,exceptions.NoViableAltException=NoViableAltException,NoViableAltException.prototype=Error.prototype,exceptions.NotAllInputParsedException=NotAllInputParsedException,NotAllInputParsedException.prototype=Error.prototype,exceptions.EarlyExitException=EarlyExitException,EarlyExitException.prototype=Error.prototype}(exceptions=chevrotain.exceptions||(chevrotain.exceptions={}))}(chevrotain||(chevrotain={}));var chevrotain;!function(chevrotain){function EMPTY_ALT(value){return void 0===value&&(value=void 0),function(){return value}}function InRuleRecoveryException(message){this.name=lang.functionName(InRuleRecoveryException),this.message=message}var cache=chevrotain.cache,IN=chevrotain.constants.IN,interp=chevrotain.interpreter,lang=chevrotain.lang,gastBuilder=chevrotain.gastBuilder,follows=chevrotain.follow,lookahead=chevrotain.lookahead,checks=chevrotain.checks,resolver=chevrotain.resolver,exceptions=chevrotain.exceptions;!function(ParserDefinitionErrorType){ParserDefinitionErrorType[ParserDefinitionErrorType.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",ParserDefinitionErrorType[ParserDefinitionErrorType.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",ParserDefinitionErrorType[ParserDefinitionErrorType.DUPLICATE_PRODUCTIONS=2]="DUPLICATE_PRODUCTIONS",ParserDefinitionErrorType[ParserDefinitionErrorType.UNRESOLVED_SUBRULE_REF=3]="UNRESOLVED_SUBRULE_REF",ParserDefinitionErrorType[ParserDefinitionErrorType.LEFT_RECURSION=4]="LEFT_RECURSION",ParserDefinitionErrorType[ParserDefinitionErrorType.NONE_LAST_EMPTY_ALT=5]="NONE_LAST_EMPTY_ALT"}(chevrotain.ParserDefinitionErrorType||(chevrotain.ParserDefinitionErrorType={}));chevrotain.ParserDefinitionErrorType;chevrotain.EMPTY_ALT=EMPTY_ALT;var EOF_FOLLOW_KEY={},Parser=function(){function Parser(input,tokensMapOrArr,isErrorRecoveryEnabled){if(void 0===isErrorRecoveryEnabled&&(isErrorRecoveryEnabled=!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=input,this.isErrorRecoveryEnabled=isErrorRecoveryEnabled,this.className=lang.classNameFromInstance(this),this.firstAfterRepMap=cache.getFirstAfterRepForClass(this.className),this.classLAFuncs=cache.getLookaheadFuncsForClass(this.className),cache.CLASS_TO_DEFINITION_ERRORS.containsKey(this.className)?this.definitionErrors=cache.CLASS_TO_DEFINITION_ERRORS.get(this.className):(this.definitionErrors=[],cache.CLASS_TO_DEFINITION_ERRORS.put(this.className,this.definitionErrors)),_.isArray(tokensMapOrArr))this.tokensMap=_.reduce(tokensMapOrArr,function(acc,tokenClazz){return acc[chevrotain.tokenName(tokenClazz)]=tokenClazz,acc},{});else{if(!_.isObject(tokensMapOrArr))throw new Error("'tokensMapOrArr' argument must be An Array of Token constructors or a Dictionary of Tokens.");this.tokensMap=_.clone(tokensMapOrArr)}this.tokensMap[chevrotain.tokenName(chevrotain.EOF)]=chevrotain.EOF,void 0===cache.CLASS_TO_OR_LA_CACHE[this.className]&&cache.initLookAheadKeyCache(this.className),this.orLookaheadKeys=cache.CLASS_TO_OR_LA_CACHE[this.className],this.manyLookaheadKeys=cache.CLASS_TO_MANY_LA_CACHE[this.className],this.manySepLookaheadKeys=cache.CLASS_TO_MANY_SEP_LA_CACHE[this.className],this.atLeastOneLookaheadKeys=cache.CLASS_TO_AT_LEAST_ONE_LA_CACHE[this.className],this.atLeastOneSepLookaheadKeys=cache.CLASS_TO_AT_LEAST_ONE_SEP_LA_CACHE[this.className],this.optionLookaheadKeys=cache.CLASS_TO_OPTION_LA_CACHE[this.className]}return Parser.performSelfAnalysis=function(classInstance){var defErrorsMsgs,definitionErrors=[],className=lang.classNameFromInstance(classInstance);if(!cache.CLASS_TO_SELF_ANALYSIS_DONE.containsKey(className)){var grammarProductions=cache.getProductionsForClass(className);definitionErrors=cache.CLASS_TO_DEFINITION_ERRORS.get(className);var resolverErrors=resolver.resolveGrammar(grammarProductions);definitionErrors.push.apply(definitionErrors,resolverErrors),cache.CLASS_TO_SELF_ANALYSIS_DONE.put(className,!0);var validationErrors=checks.validateGrammar(grammarProductions.values());if(definitionErrors.push.apply(definitionErrors,validationErrors),!utils.isEmpty(definitionErrors)&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw defErrorsMsgs=utils.map(definitionErrors,function(defError){return defError.message}),new Error("Parser Definition Errors detected\n: "+defErrorsMsgs.join("\n-------------------------------\n"));if(utils.isEmpty(definitionErrors)){var allFollows=follows.computeAllProdsFollows(grammarProductions.values());cache.setResyncFollowsForClass(className,allFollows)}}if(!utils.isEmpty(cache.CLASS_TO_DEFINITION_ERRORS.get(className))&&!Parser.DEFER_DEFINITION_ERRORS_HANDLING)throw defErrorsMsgs=utils.map(cache.CLASS_TO_DEFINITION_ERRORS.get(className),function(defError){return defError.message}),new Error("Parser Definition Errors detected\n: "+defErrorsMsgs.join("\n-------------------------------\n"))},Object.defineProperty(Parser.prototype,"input",{get:function(){return _.clone(this._input)},set:function(newInput){this.reset(),this._input=newInput},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 chevrotain.EOF},Parser.prototype.getGAstProductions=function(){return cache.getProductionsForClass(this.className)},Parser.prototype.isBackTracking=function(){return!utils.isEmpty(this.isBackTrackingStack)},Parser.prototype.SAVE_ERROR=function(error){if(exceptions.isRecognitionException(error))return this.errors.push(error),error;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(howMuch){return this._input.length<=this.inputIdx+howMuch?new chevrotain.EOF:this._input[this.inputIdx+howMuch]},Parser.prototype.isNextRule=function(ruleName){var classLAFuncs=cache.getLookaheadFuncsForClass(this.className),condition=classLAFuncs.get(ruleName);if(void 0===condition){var ruleGrammar=this.getGAstProductions().get(ruleName);condition=lookahead.buildLookaheadForTopLevel(ruleGrammar),classLAFuncs.put(ruleName,condition)}return condition.call(this)},Parser.prototype.BACKTRACK=function(grammarRule,isValid){var _this=this;return function(){_this.isBackTrackingStack.push(1);var orgState=_this.saveRecogState();try{var ruleResult=grammarRule.call(_this);return isValid(ruleResult)}catch(e){if(exceptions.isRecognitionException(e))return!1;throw e}finally{_this.reloadRecogState(orgState),_this.isBackTrackingStack.pop()}}},Parser.prototype.SKIP_TOKEN=function(){return this.inputIdx<=this._input.length-2?(this.inputIdx++,this.NEXT_TOKEN()):new chevrotain.EOF},Parser.prototype.CONSUME=function(tokClass){return this.CONSUME1(tokClass)},Parser.prototype.CONSUME1=function(tokClass){return this.consumeInternal(tokClass,1)},Parser.prototype.CONSUME2=function(tokClass){return this.consumeInternal(tokClass,2)},Parser.prototype.CONSUME3=function(tokClass){return this.consumeInternal(tokClass,3)},Parser.prototype.CONSUME4=function(tokClass){return this.consumeInternal(tokClass,4)},Parser.prototype.CONSUME5=function(tokClass){return this.consumeInternal(tokClass,5)},Parser.prototype.SUBRULE=function(ruleToCall,args){return void 0===args&&(args=[]),this.SUBRULE1(ruleToCall,args)},Parser.prototype.SUBRULE1=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,1,args)},Parser.prototype.SUBRULE2=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,2,args)},Parser.prototype.SUBRULE3=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,3,args)},Parser.prototype.SUBRULE4=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,4,args)},Parser.prototype.SUBRULE5=function(ruleToCall,args){return void 0===args&&(args=[]),ruleToCall.call(this,5,args)},Parser.prototype.OPTION=function(laFuncOrAction,action){return this.OPTION1.call(this,laFuncOrAction,action)},Parser.prototype.OPTION1=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(1)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION2=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(2)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION3=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(3)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION4=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(4)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OPTION5=function(laFuncOrAction,action){return void 0===action&&(action=laFuncOrAction,laFuncOrAction=this.getLookaheadFuncForOption(5)),this.optionInternal(laFuncOrAction,action)},Parser.prototype.OR=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.OR1(alts,errMsgTypes,ignoreAmbiguities)},Parser.prototype.OR1=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,1,ignoreAmbiguities)},Parser.prototype.OR2=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,2,ignoreAmbiguities)},Parser.prototype.OR3=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,3,ignoreAmbiguities)},Parser.prototype.OR4=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,4,ignoreAmbiguities)},Parser.prototype.OR5=function(alts,errMsgTypes,ignoreAmbiguities){return void 0===ignoreAmbiguities&&(ignoreAmbiguities=!1),this.orInternal(alts,errMsgTypes,5,ignoreAmbiguities)},Parser.prototype.MANY=function(laFuncOrAction,action){return this.MANY1.call(this,laFuncOrAction,action)},Parser.prototype.MANY1=function(laFuncOrAction,action){this.manyInternal(this.MANY1,"MANY1",1,laFuncOrAction,action)},Parser.prototype.MANY2=function(laFuncOrAction,action){this.manyInternal(this.MANY2,"MANY2",2,laFuncOrAction,action)},Parser.prototype.MANY3=function(laFuncOrAction,action){this.manyInternal(this.MANY3,"MANY3",3,laFuncOrAction,action)},Parser.prototype.MANY4=function(laFuncOrAction,action){this.manyInternal(this.MANY4,"MANY4",4,laFuncOrAction,action)},Parser.prototype.MANY5=function(laFuncOrAction,action){this.manyInternal(this.MANY5,"MANY5",5,laFuncOrAction,action)},Parser.prototype.MANY_SEP=function(separator,laFuncOrAction,action){return this.MANY_SEP1.call(this,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP1=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP1,"MANY_SEP1",1,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP2=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP2,"MANY_SEP2",2,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP3=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP3,"MANY_SEP3",3,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP4=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP4,"MANY_SEP4",4,separator,laFuncOrAction,action)},Parser.prototype.MANY_SEP5=function(separator,laFuncOrAction,action){return this.manySepFirstInternal(this.MANY_SEP5,"MANY_SEP5",5,separator,laFuncOrAction,action)},Parser.prototype.AT_LEAST_ONE=function(laFuncOrAction,action,errMsg){return this.AT_LEAST_ONE1.call(this,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE1=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE1,"AT_LEAST_ONE1",1,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE2=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE2,"AT_LEAST_ONE2",2,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE3=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE3,"AT_LEAST_ONE3",3,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE4=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE4,"AT_LEAST_ONE4",4,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE5=function(laFuncOrAction,action,errMsg){this.atLeastOneInternal(this.AT_LEAST_ONE5,"AT_LEAST_ONE5",5,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP=function(separator,laFuncOrAction,action,errMsg){return this.AT_LEAST_ONE_SEP1.call(this,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP1=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP1",1,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP2=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP2",2,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP3=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP3",3,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP4=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP4",4,separator,laFuncOrAction,action,errMsg)},Parser.prototype.AT_LEAST_ONE_SEP5=function(separator,laFuncOrAction,action,errMsg){return this.atLeastOneSepFirstInternal(this.atLeastOneSepFirstInternal,"AT_LEAST_ONE_SEP5",5,separator,laFuncOrAction,action,errMsg)},Parser.prototype.RULE_NO_RESYNC=function(ruleName,impl,invalidRet){return this.RULE(ruleName,impl,invalidRet,!1)},Parser.prototype.RULE=function(ruleName,impl,invalidRet,doReSync){void 0===invalidRet&&(invalidRet=this.defaultInvalidReturn),void 0===doReSync&&(doReSync=!0);var ruleNameErrors=checks.validateRuleName(ruleName,this.definedRulesNames,this.className);this.definedRulesNames.push(ruleName),this.definitionErrors.push.apply(this.definitionErrors,ruleNameErrors);var parserClassProductions=cache.getProductionsForClass(this.className);if(!parserClassProductions.containsKey(ruleName)){var gastProduction=gastBuilder.buildTopProduction(impl.toString(),ruleName,this.tokensMap);parserClassProductions.put(ruleName,gastProduction)}var wrappedGrammarRule=function(idxInCallingRule,args){void 0===idxInCallingRule&&(idxInCallingRule=1),void 0===args&&(args=[]),this.ruleInvocationStateUpdate(ruleName,idxInCallingRule);try{return impl.apply(this,args)}catch(e){var isFirstInvokedRule=1===this.RULE_STACK.length,reSyncEnabled=isFirstInvokedRule||doReSync&&!this.isBackTracking()&&this.isErrorRecoveryEnabled;if(reSyncEnabled&&exceptions.isRecognitionException(e)){var reSyncTokType=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(reSyncTokType))return this.reSyncTo(reSyncTokType),invalidRet();throw e}throw e}finally{this.ruleFinallyStateUpdate()}},ruleNamePropName="ruleName";return wrappedGrammarRule[ruleNamePropName]=ruleName,wrappedGrammarRule},Parser.prototype.ruleInvocationStateUpdate=function(ruleName,idxInCallingRule){this.RULE_OCCURRENCE_STACK.push(idxInCallingRule),this.RULE_STACK.push(ruleName)},Parser.prototype.ruleFinallyStateUpdate=function(){this.RULE_STACK.pop(),this.RULE_OCCURRENCE_STACK.pop();var maxInputIdx=this._input.length-1;if(0===this.RULE_STACK.length&&this.inputIdx"+expectedTokName+"<-- but found -->'"+nextTokenWithoutResync.image+"'<--";return this.SAVE_ERROR(new exceptions.MismatchedTokenException(msg,nextTokenWithoutResync)),void grammarRule.apply(this,grammarRuleArgs)}currToken instanceof reSyncTokType&&(passedResyncPoint=!0),currToken=this.SKIP_TOKEN()}this.inputIdx=orgInputIdx},Parser.prototype.shouldInRepetitionRecoveryBeTried=function(expectTokAfterLastMatch,nextTokIdx){return void 0===expectTokAfterLastMatch||void 0===nextTokIdx?!1:this.NEXT_TOKEN()instanceof expectTokAfterLastMatch?!1:this.isBackTracking()?!1:this.canPerformInRuleRecovery(expectTokAfterLastMatch,this.getFollowsForInRuleRecovery(expectTokAfterLastMatch,nextTokIdx))?!1:!0},Parser.prototype.getFollowsForInRuleRecovery=function(tokClass,tokIdxInRule){var pathRuleStack=_.clone(this.RULE_STACK),pathOccurrenceStack=_.clone(this.RULE_OCCURRENCE_STACK),grammarPath={ruleStack:pathRuleStack,occurrenceStack:pathOccurrenceStack,lastTok:tokClass,lastTokOccurrence:tokIdxInRule},topRuleName=_.first(pathRuleStack),gastProductions=this.getGAstProductions(),topProduction=gastProductions.get(topRuleName),follows=new interp.NextAfterTokenWalker(topProduction,grammarPath).startWalking();return follows},Parser.prototype.tryInRuleRecovery=function(expectedTokType,follows){if(this.canRecoverWithSingleTokenInsertion(expectedTokType,follows)){var tokToInsert=this.getTokenToInsert(expectedTokType);return tokToInsert.isInsertedInRecovery=!0,tokToInsert}if(this.canRecoverWithSingleTokenDeletion(expectedTokType)){var nextTok=this.SKIP_TOKEN();return this.inputIdx++,nextTok}throw new InRuleRecoveryException("sad sad panda")},Parser.prototype.canPerformInRuleRecovery=function(expectedToken,follows){return this.canRecoverWithSingleTokenInsertion(expectedToken,follows)||this.canRecoverWithSingleTokenDeletion(expectedToken)},Parser.prototype.canRecoverWithSingleTokenInsertion=function(expectedTokType,follows){if(!this.canTokenTypeBeInsertedInRecovery(expectedTokType))return!1;if(utils.isEmpty(follows))return!1;var mismatchedTok=this.NEXT_TOKEN(),isMisMatchedTokInFollows=void 0!==_.find(follows,function(possibleFollowsTokType){return mismatchedTok instanceof possibleFollowsTokType});return isMisMatchedTokInFollows},Parser.prototype.canRecoverWithSingleTokenDeletion=function(expectedTokType){var isNextTokenWhatIsExpected=this.LA(2)instanceof expectedTokType;return isNextTokenWhatIsExpected},Parser.prototype.isInCurrentRuleReSyncSet=function(token){var followKey=this.getCurrFollowKey(),currentRuleReSyncSet=this.getFollowSetFromFollowKey(followKey);return _.contains(currentRuleReSyncSet,token)},Parser.prototype.findReSyncTokenType=function(){for(var allPossibleReSyncTokTypes=this.flattenFollowSet(),nextToken=this.NEXT_TOKEN(),k=2;;){var nextTokenType=nextToken.constructor;if(_.contains(allPossibleReSyncTokTypes,nextTokenType))return nextTokenType;nextToken=this.LA(k),k++}},Parser.prototype.getCurrFollowKey=function(){if(1===this.RULE_STACK.length)return EOF_FOLLOW_KEY;var currRuleIdx=this.RULE_STACK.length-1,currRuleOccIdx=currRuleIdx,prevRuleIdx=currRuleIdx-1;return{ruleName:this.RULE_STACK[currRuleIdx],idxInCallingRule:this.RULE_OCCURRENCE_STACK[currRuleOccIdx],inRule:this.RULE_STACK[prevRuleIdx]}},Parser.prototype.buildFullFollowKeyStack=function(){var _this=this;return utils.map(this.RULE_STACK,function(ruleName,idx){return 0===idx?EOF_FOLLOW_KEY:{ruleName:ruleName,idxInCallingRule:_this.RULE_OCCURRENCE_STACK[idx],inRule:_this.RULE_STACK[idx-1]}})},Parser.prototype.flattenFollowSet=function(){var _this=this,followStack=utils.map(this.buildFullFollowKeyStack(),function(currKey){return _this.getFollowSetFromFollowKey(currKey)});return _.flatten(followStack)},Parser.prototype.getFollowSetFromFollowKey=function(followKey){if(followKey===EOF_FOLLOW_KEY)return[chevrotain.EOF];var followName=followKey.ruleName+followKey.idxInCallingRule+IN+followKey.inRule;return cache.getResyncFollowsForClass(this.className).get(followName)},Parser.prototype.reSyncTo=function(tokClass){for(var nextTok=this.NEXT_TOKEN();nextTok instanceof tokClass==!1;)nextTok=this.SKIP_TOKEN()},Parser.prototype.attemptInRepetitionRecovery=function(prodFunc,args,lookaheadFunc,prodName,prodOccurrence,nextToksWalker,prodKeys){var key=this.getKeyForAutomaticLookahead(prodName,prodKeys,prodOccurrence),firstAfterRepInfo=this.firstAfterRepMap.get(key);if(void 0===firstAfterRepInfo){var currRuleName=_.last(this.RULE_STACK),ruleGrammar=this.getGAstProductions().get(currRuleName),walker=new nextToksWalker(ruleGrammar,prodOccurrence);firstAfterRepInfo=walker.startWalking(),this.firstAfterRepMap.put(key,firstAfterRepInfo)}var expectTokAfterLastMatch=firstAfterRepInfo.token,nextTokIdx=firstAfterRepInfo.occurrence,isEndOfRule=firstAfterRepInfo.isEndOfRule;1===this.RULE_STACK.length&&isEndOfRule&&void 0===expectTokAfterLastMatch&&(expectTokAfterLastMatch=chevrotain.EOF,nextTokIdx=1),this.shouldInRepetitionRecoveryBeTried(expectTokAfterLastMatch,nextTokIdx)&&this.tryInRepetitionRecovery(prodFunc,args,lookaheadFunc,expectTokAfterLastMatch)},Parser.prototype.optionInternal=function(condition,action){return condition.call(this)?(action.call(this),!0):!1},Parser.prototype.atLeastOneInternal=function(prodFunc,prodName,prodOccurrence,lookAheadFunc,action,errMsg){if(_.isString(action)&&(errMsg=action,action=lookAheadFunc,lookAheadFunc=this.getLookaheadFuncForAtLeastOne(prodOccurrence)),!lookAheadFunc.call(this))throw this.SAVE_ERROR(new exceptions.EarlyExitException("expecting at least one: "+errMsg,this.NEXT_TOKEN()));for(action.call(this);lookAheadFunc.call(this);)action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(prodFunc,[lookAheadFunc,action,errMsg],lookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterAtLeastOneWalker,this.atLeastOneLookaheadKeys)},Parser.prototype.atLeastOneSepFirstInternal=function(prodFunc,prodName,prodOccurrence,separator,firstIterationLookAheadFunc,action,errMsg){var _this=this,separatorsResult=[];if(_.isString(action)&&(errMsg=action,action=firstIterationLookAheadFunc,firstIterationLookAheadFunc=this.getLookaheadFuncForAtLeastOneSep(prodOccurrence)),!firstIterationLookAheadFunc.call(this))throw this.SAVE_ERROR(new exceptions.EarlyExitException("expecting at least one: "+errMsg,this.NEXT_TOKEN()));action.call(this);for(var separatorLookAheadFunc=function(){return _this.NEXT_TOKEN()instanceof separator};separatorLookAheadFunc();)separatorsResult.push(this.CONSUME(separator)),action.call(this);return this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,this.atLeastOneSepLookaheadKeys,interp.NextTerminalAfterAtLeastOneSepWalker],separatorLookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterAtLeastOneSepWalker,this.atLeastOneSepLookaheadKeys),separatorsResult},Parser.prototype.manyInternal=function(prodFunc,prodName,prodOccurrence,lookAheadFunc,action){for(void 0===action&&(action=lookAheadFunc,lookAheadFunc=this.getLookaheadFuncForMany(prodOccurrence));lookAheadFunc.call(this);)action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(prodFunc,[lookAheadFunc,action],lookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterManyWalker,this.manyLookaheadKeys)},Parser.prototype.manySepFirstInternal=function(prodFunc,prodName,prodOccurrence,separator,firstIterationLookAheadFunc,action){var _this=this,separatorsResult=[];if(void 0===action&&(action=firstIterationLookAheadFunc,firstIterationLookAheadFunc=this.getLookaheadFuncForManySep(prodOccurrence)),firstIterationLookAheadFunc.call(this)){action.call(this);for(var separatorLookAheadFunc=function(){return _this.NEXT_TOKEN()instanceof separator};separatorLookAheadFunc();)separatorsResult.push(this.CONSUME(separator)),action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,this.manySepLookaheadKeys,interp.NextTerminalAfterManySepWalker],separatorLookAheadFunc,prodName,prodOccurrence,interp.NextTerminalAfterManySepWalker,this.manySepLookaheadKeys)}return separatorsResult},Parser.prototype.repetitionSepSecondInternal=function(prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,laKeys,nextTerminalAfterWalker){ +for(;separatorLookAheadFunc();)separatorsResult.push(this.CONSUME(separator)),action.call(this);this.isErrorRecoveryEnabled&&this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[prodName,prodOccurrence,separator,separatorLookAheadFunc,action,separatorsResult,laKeys,nextTerminalAfterWalker],separatorLookAheadFunc,prodName,prodOccurrence,nextTerminalAfterWalker,laKeys)},Parser.prototype.orInternal=function(alts,errMsgTypes,occurrence,ignoreAmbiguities){if(void 0!==alts[0].WHEN){for(var i=0;i"+expectedTokType+"<-- but found -->'"+nextToken.image+"'<--";throw this.SAVE_ERROR(new exceptions.MismatchedTokenException(msg,nextToken))},Parser.prototype.getKeyForAutomaticLookahead=function(prodName,prodKeys,occurrence){var occuMap=prodKeys[occurrence-1],currRule=_.last(this.RULE_STACK),key=occuMap[currRule];return void 0===key&&(key=prodName+occurrence+IN+currRule,occuMap[currRule]=key),key},Parser.prototype.getLookaheadFuncForOption=function(occurence){var key=this.getKeyForAutomaticLookahead("OPTION",this.optionLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForOption)},Parser.prototype.getLookaheadFuncForOr=function(occurence,ignoreErrors){var key=this.getKeyForAutomaticLookahead("OR",this.orLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForOr,[ignoreErrors])},Parser.prototype.getLookaheadFuncForMany=function(occurence){var key=this.getKeyForAutomaticLookahead("MANY",this.manyLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForMany)},Parser.prototype.getLookaheadFuncForManySep=function(occurence){var key=this.getKeyForAutomaticLookahead("MANY_SEP",this.manySepLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForManySep)},Parser.prototype.getLookaheadFuncForAtLeastOne=function(occurence){var key=this.getKeyForAutomaticLookahead("AT_LEAST_ONE",this.atLeastOneLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForAtLeastOne)},Parser.prototype.getLookaheadFuncForAtLeastOneSep=function(occurence){var key=this.getKeyForAutomaticLookahead("AT_LEAST_ONE_SEP",this.atLeastOneSepLookaheadKeys,occurence);return this.getLookaheadFuncFor(key,occurence,lookahead.buildLookaheadForAtLeastOneSep)},Parser.prototype.getLookaheadFuncFor=function(key,occurrence,laFuncBuilder,extraArgs){void 0===extraArgs&&(extraArgs=[]);var ruleName=_.last(this.RULE_STACK),condition=this.classLAFuncs.get(key);if(void 0===condition){var ruleGrammar=this.getGAstProductions().get(ruleName);condition=laFuncBuilder.apply(null,[occurrence,ruleGrammar].concat(extraArgs)),this.classLAFuncs.put(key,condition)}return condition},Parser.prototype.saveRecogState=function(){var savedErrors=_.clone(this.errors),savedRuleStack=_.clone(this.RULE_STACK);return{errors:savedErrors,inputIdx:this.inputIdx,RULE_STACK:savedRuleStack}},Parser.prototype.reloadRecogState=function(newState){this.errors=newState.errors,this.inputIdx=newState.inputIdx,this.RULE_STACK=newState.RULE_STACK},Parser.prototype.raiseNoAltException=function(occurrence,errMsgTypes){var errSuffix=" but found: '"+this.NEXT_TOKEN().image+"'";if(void 0===errMsgTypes){var ruleName=_.last(this.RULE_STACK),ruleGrammar=this.getGAstProductions().get(ruleName),nextTokens=new interp.NextInsideOrWalker(ruleGrammar,occurrence).startWalking(),nextTokensFlat=_.flatten(nextTokens),nextTokensNames=utils.map(nextTokensFlat,function(currTokenClass){return chevrotain.tokenName(currTokenClass)});errMsgTypes="one of: <"+nextTokensNames.join(" ,")+">"}throw this.SAVE_ERROR(new exceptions.NoViableAltException("expecting: "+errMsgTypes+" "+errSuffix,this.NEXT_TOKEN()))},Parser.IGNORE_AMBIGUITIES=!0,Parser.NO_RESYNC=!1,Parser.DEFER_DEFINITION_ERRORS_HANDLING=!1,Parser}();chevrotain.Parser=Parser,InRuleRecoveryException.prototype=Error.prototype}(chevrotain||(chevrotain={}));var testMode="object"==typeof global&&global.CHEV_TEST_MODE||"object"==typeof window&&window.CHEV_TEST_MODE,API={};return testMode?(console.log("running in TEST_MODE"),API=chevrotain):(API.VERSION="0.5.13",API.Parser=chevrotain.Parser,API.Lexer=chevrotain.Lexer,API.Token=chevrotain.Token,API.VirtualToken=chevrotain.VirtualToken,API.EOF=chevrotain.EOF,API.extendToken=chevrotain.extendToken,API.tokenName=chevrotain.tokenName,API.EMPTY_ALT=chevrotain.EMPTY_ALT,API.exceptions={},API.exceptions.isRecognitionException=chevrotain.exceptions.isRecognitionException,API.exceptions.EarlyExitException=chevrotain.exceptions.EarlyExitException,API.exceptions.MismatchedTokenException=chevrotain.exceptions.MismatchedTokenException,API.exceptions.NotAllInputParsedException=chevrotain.exceptions.NotAllInputParsedException,API.exceptions.NoViableAltException=chevrotain.exceptions.NoViableAltException,API.gast={},API.gast.GAstVisitor=chevrotain.gast.GAstVisitor,API.gast.Flat=chevrotain.gast.Flat,API.gast.Repetition=chevrotain.gast.Repetition,API.gast.RepetitionWithSeparator=chevrotain.gast.RepetitionWithSeparator,API.gast.RepetitionMandatory=chevrotain.gast.RepetitionMandatory,API.gast.RepetitionMandatoryWithSeparator=chevrotain.gast.RepetitionMandatoryWithSeparator,API.gast.Option=chevrotain.gast.Option,API.gast.Alternation=chevrotain.gast.Alternation,API.gast.NonTerminal=chevrotain.gast.NonTerminal,API.gast.Terminal=chevrotain.gast.Terminal,API.gast.Rule=chevrotain.gast.Rule),API}); \ No newline at end of file diff --git a/src/api.ts b/src/api.ts index 11c69b214..15ae29402 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,7 +12,7 @@ let API:any = {} /* istanbul ignore next */ if (!testMode) { // semantic version - API.VERSION = "0.5.12"; + API.VERSION = "0.5.13"; // runtime API API.Parser = chevrotain.Parser