diff --git a/Rakefile b/Rakefile index f7470e3..71273a8 100644 --- a/Rakefile +++ b/Rakefile @@ -21,4 +21,12 @@ file "lib/pegjs-runtime-#{version}.min.js" => "lib/runtime.js" do |t| File.open(t.name, "w") { |f| f.write(response.body) } end -task :default => "lib/pegjs-runtime-#{version}.min.js" +file "lib/metagrammar.js" => "lib/metagrammar.pegjs" do |t| + system "bin/pegjs --start grammar PEG.grammarParser lib/metagrammar.pegjs" +end + +desc "Build the minified parser runtime" +task :minify => "lib/pegjs-runtime-#{version}.min.js" + +desc "Generate the grammar parser" +task :metaparser => "lib/metagrammar.js" diff --git a/bin/pegjs-main.js b/bin/pegjs-main.js index f6c4361..7db14fa 100644 --- a/bin/pegjs-main.js +++ b/bin/pegjs-main.js @@ -7,6 +7,7 @@ importPackage(java.lang); */ load(arguments[0] + "/../lib/runtime.js"); load(arguments[0] + "/../lib/compiler.js"); +load(arguments[0] + "/../lib/metagrammar.js"); var FILE_STDIN = "-"; var FILE_STDOUT = "-"; diff --git a/lib/compiler.js b/lib/compiler.js index 7520f08..4e31734 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -518,864 +518,4 @@ PEG.Grammar.Action.prototype.compile = function(resultVar) { ); }; -/* ===== PEG.grammarParser ===== */ - -var returnFirstArg = function() { return arguments[0]; } -var returnSecondArg = function() { return arguments[1]; } -var returnSecondArgJoined = function() { return arguments[1].join(""); } -var returnFirstArgAndSecondArgJoined = function() { return arguments[0] + arguments[1].join(""); } - -function characterRule(name, ch) { - with (PEG.Grammar) { - return new Rule( - name, - null, - new Action( - new Sequence([new Literal(ch), new RuleRef("__")]), - returnFirstArg - ) - ); - } -} - -/* Bootstrapping is really badly needed. */ - -with (PEG.Grammar) { - PEG.grammarParser = PEG.buildParser({ - grammar: - new Rule( - "grammar", - null, - new Action( - new Sequence([ - new RuleRef("__"), - new RuleRef("rule"), - new ZeroOrMore(new RuleRef("rule")) - ]), - function(dummy, first, rest) { - var rules = [first].concat(rest); - var result = {}; - for (var i = 0; i < rules.length; i++) { - result[rules[i].getName()] = rules[i]; - } - return result; - } - ) - ), - - rule: - new Rule( - "rule", - null, - new Action( - new Sequence([ - new RuleRef("identifier"), - new Choice([new RuleRef("literal"), new Literal("")]), - new RuleRef("colon"), - new RuleRef("expression") - ]), - function(name, humanName, dummy, expression) { - return new PEG.Grammar.Rule( - name, - humanName !== "" ? humanName : null, - expression - ); - } - ) - ), - - expression: - new Rule("expression", null, new RuleRef("choice")), - - choice: - new Rule( - "choice", - null, - new Action( - new Sequence([ - new RuleRef("sequence"), - new ZeroOrMore( - new Sequence([new RuleRef("slash"), new RuleRef("sequence")]) - ) - ]), - function(first, rest) { - return rest.length > 0 - ? new PEG.Grammar.Choice([first].concat(PEG.ArrayUtils.map( - rest, - function(element) { return element[1]; } - ))) - : first; - } - ) - ), - - sequence: - new Rule( - "sequence", - null, - new Choice([ - new Action( - new Sequence([ - new ZeroOrMore(new RuleRef("prefixed")), - new RuleRef("action") - ]), - function(expressions, action) { - return new PEG.Grammar.Action( - expressions.length != 1 - ? new PEG.Grammar.Sequence(expressions) - : expressions[0], - action - ); - } - ), - new Action( - new ZeroOrMore(new RuleRef("prefixed")), - function(expressions) { - return expressions.length != 1 - ? new PEG.Grammar.Sequence(expressions) - : expressions[0]; - } - ) - ]) - ), - - prefixed: - new Rule( - "prefixed", - null, - new Choice([ - new Action( - new Sequence([new RuleRef("and"), new RuleRef("suffixed")]), - function(dummy, expression) { - return new PEG.Grammar.NotPredicate( - new PEG.Grammar.NotPredicate(expression) - ); - } - ), - new Action( - new Sequence([new RuleRef("not"), new RuleRef("suffixed")]), - function(dummy, expression) { - return new PEG.Grammar.NotPredicate(expression); - } - ), - new RuleRef("suffixed") - ]) - ), - - suffixed: - new Rule( - "suffixed", - null, - new Choice([ - new Action( - new Sequence([new RuleRef("primary"), new RuleRef("question")]), - function(expression) { - return new PEG.Grammar.Choice([ - expression, - new PEG.Grammar.Literal("") - ]); - } - ), - new Action( - new Sequence([new RuleRef("primary"), new RuleRef("star")]), - function(expression) { return new PEG.Grammar.ZeroOrMore(expression); } - ), - new Action( - new Sequence([new RuleRef("primary"), new RuleRef("plus")]), - function(expression) { - return new PEG.Grammar.Action( - new PEG.Grammar.Sequence([ - expression, - new PEG.Grammar.ZeroOrMore(expression) - ]), - function(first, rest) { return [first].concat(rest); } - ); - } - ), - new RuleRef("primary") - ]) - ), - - primary: - new Rule( - "primary", - null, - new Choice([ - new Action( - new Sequence([ - new RuleRef("identifier"), - new NotPredicate( - new Sequence([ - new Choice([new RuleRef("literal"), new Literal("")]), - new RuleRef("colon") - ]) - ) - ]), - function(identifier) { return new PEG.Grammar.RuleRef(identifier); } - ), - new Action( - new RuleRef("literal"), - function(literal) { return new PEG.Grammar.Literal(literal); } - ), - new Action( - new RuleRef("dot"), - function() { return new PEG.Grammar.Any(); } - ), - new Action( - new RuleRef("class"), - function(characters) { - return new PEG.Grammar.Choice( - PEG.ArrayUtils.map( - characters.split(""), - function(character) { - return new PEG.Grammar.Literal(character); - } - ) - ); - } - ), - new Action( - new Sequence([ - new RuleRef("lparen"), - new RuleRef("expression"), - new RuleRef("rparen") - ]), - returnSecondArg - ) - ]) - ), - - /* "Lexical" elements */ - - action: - new Rule( - "action", - "action", - new Action( - new Sequence([new RuleRef("braced"), new RuleRef("__")]), - function(braced) { return braced.substr(1, braced.length - 2); } - ) - ), - - braced: - new Rule( - "braced", - null, - new Action( - new Sequence([ - new Literal("{"), - new ZeroOrMore( - new Choice([ - new RuleRef("braced"), - new RuleRef("nonBraceCharacters") - ]) - ), - new Literal("}") - ]), - function(leftBrace, parts, rightBrace) { - return leftBrace + parts.join("") + rightBrace; - } - ) - ), - - nonBraceCharacters: - new Rule( - "nonBraceCharacters", - null, - new Action( - new Sequence([ - new RuleRef("nonBraceCharacter"), - new ZeroOrMore(new RuleRef("nonBraceCharacter")) - ]), - returnFirstArgAndSecondArgJoined - ) - ), - - nonBraceCharacter: - new Rule( - "nonBraceCharacter", - null, - new Action( - new Sequence([ - new NotPredicate(new Choice([new Literal("{"), new Literal("}")])), - new Any() - ]), - returnSecondArg - ) - ), - - colon: characterRule("colon", ":"), - slash: characterRule("slash", "/"), - and: characterRule("and", "&"), - not: characterRule("not", "!"), - question: characterRule("question", "?"), - star: characterRule("star", "*"), - plus: characterRule("plus", "+"), - lparen: characterRule("lparen", "("), - rparen: characterRule("rparen", ")"), - dot: characterRule("dot", "."), - - /* - * Modelled after ECMA-262, 5th ed., 7.6, but much simplified: - * - * * no Unicode escape sequences - * - * * "Unicode combining marks" and "Unicode connection punctuation" can't - * be part of the identifier - * - * * only [a-zA-Z] is considered a "Unicode letter" - * - * * only [0-9] is considered a "Unicode digit" - * - * The simplifications were made just to make the implementation little - * bit easier, there is no "philosophical" reason behind them. - */ - identifier: - new Rule( - "identifier", - "identifier", - new Action( - new Sequence([ - new Choice([ - new RuleRef("letter"), - new Literal("_"), - new Literal("$") - ]), - new ZeroOrMore( - new Choice([ - new RuleRef("letter"), - new RuleRef("digit"), - new Literal("_"), - new Literal("$") - ]) - ), - new RuleRef("__") - ]), - returnFirstArgAndSecondArgJoined - ) - ), - - /* - * Modelled after ECMA-262, 5th ed., 7.8.4. (syntax & semantics, rules only - * vaguely), - */ - literal: - new Rule( - "literal", - "literal", - new Action( - new Sequence([ - new Choice([ - new RuleRef("doubleQuotedLiteral"), - new RuleRef("singleQuotedLiteral") - ]), - new RuleRef("__") - ]), - returnFirstArg - ) - ), - - doubleQuotedLiteral: - new Rule( - "doubleQuotedLiteral", - null, - new Action( - new Sequence([ - new Literal('"'), - new ZeroOrMore(new RuleRef("doubleQuotedCharacter")), - new Literal('"') - ]), - returnSecondArgJoined - ) - ), - - doubleQuotedCharacter: - new Rule( - "doubleQuotedCharacter", - null, - new Choice([ - new RuleRef("simpleDoubleQuotedCharacter"), - new RuleRef("simpleEscapeSequence"), - new RuleRef("zeroEscapeSequence"), - new RuleRef("hexEscapeSequence"), - new RuleRef("unicodeEscapeSequence"), - new RuleRef("eolEscapeSequence") - ]) - ), - - simpleDoubleQuotedCharacter: - new Rule( - "simpleDoubleQuotedCharacter", - null, - new Action( - new Sequence([ - new NotPredicate( - new Choice([ - new Literal('"'), - new Literal("\\"), - new RuleRef("eolChar") - ]) - ), - new Any() - ]), - returnSecondArg - ) - ), - - singleQuotedLiteral: - new Rule( - "singleQuotedLiteral", - null, - new Action( - new Sequence([ - new Literal("'"), - new ZeroOrMore(new RuleRef("singleQuotedCharacter")), - new Literal("'") - ]), - returnSecondArgJoined - ) - ), - - singleQuotedCharacter: - new Rule( - "singleQuotedCharacter", - null, - new Choice([ - new RuleRef("simpleSingleQuotedCharacter"), - new RuleRef("simpleEscapeSequence"), - new RuleRef("zeroEscapeSequence"), - new RuleRef("hexEscapeSequence"), - new RuleRef("unicodeEscapeSequence"), - new RuleRef("eolEscapeSequence") - ]) - ), - - simpleSingleQuotedCharacter: - new Rule( - "simpleSingleQuotedCharacter", - null, - new Action( - new Sequence([ - new NotPredicate( - new Choice([ - new Literal("'"), - new Literal("\\"), - new RuleRef("eolChar") - ]) - ), - new Any() - ]), - returnSecondArg - ) - ), - - "class": - new Rule( - "class", - "character class", - new Action( - new Sequence([ - new Literal("["), - new ZeroOrMore( - new Choice([ - new RuleRef("classCharacterRange"), - new RuleRef("classCharacter") - ]) - ), - new Literal("]"), - new RuleRef("__") - ]), - returnSecondArgJoined - ) - ), - - classCharacterRange: - new Rule( - "classCharacterRange", - null, - new Action( - new Sequence([ - new RuleRef("bracketDelimitedCharacter"), - new Literal("-"), - new RuleRef("bracketDelimitedCharacter") - ]), - function(begin, dummy2, end) { - var beginCharCode = begin.charCodeAt(0); - var endCharCode = end.charCodeAt(0); - if (beginCharCode > endCharCode) { - throw new PEG.Parser.SyntaxError( - "Invalid character range: " + begin + "-" + end + "." - ); - } - - var result = ""; - - for (var charCode = beginCharCode; charCode <= endCharCode; charCode++) { - result += String.fromCharCode(charCode); - } - - return result; - } - ) - ), - - classCharacter: - new Rule("classCharacter", null, new RuleRef("bracketDelimitedCharacter")), - - bracketDelimitedCharacter: - new Rule( - "bracketDelimitedCharacter", - null, - new Choice([ - new RuleRef("simpleBracketDelimitedCharacter"), - new RuleRef("simpleEscapeSequence"), - new RuleRef("zeroEscapeSequence"), - new RuleRef("hexEscapeSequence"), - new RuleRef("unicodeEscapeSequence"), - new RuleRef("eolEscapeSequence") - ]) - ), - - simpleBracketDelimitedCharacter: - new Rule( - "simpleBracketDelimitedCharacter", - null, - new Action( - new Sequence([ - new NotPredicate( - new Choice([ - new Literal(']'), - new Literal("\\"), - new RuleRef("eolChar") - ]) - ), - new Any() - ]), - returnSecondArg - ) - ), - - simpleEscapeSequence: - new Rule( - "simpleEscapeSequence", - null, - new Action( - new Sequence([ - new Literal("\\"), - new NotPredicate( - new Choice([ - new RuleRef("digit"), - new Literal("x"), - new Literal("u"), - new RuleRef("eolChar") - ]) - ), - new Any() - ]), - function(dummy1, dummy2, character) { - return character - .replace("b", "\b") - .replace("f", "\f") - .replace("n", "\n") - .replace("r", "\r") - .replace("t", "\t") - .replace("v", "\v") - } - ) - ), - - zeroEscapeSequence: - new Rule( - "zeroEscapeSequence", - null, - new Action( - new Sequence([ - new Literal("\\0"), - new NotPredicate(new RuleRef("digit")) - ]), - function() { return "\0" } - ) - ), - - hexEscapeSequence: - new Rule( - "hexEscapeSequence", - null, - new Action( - new Sequence([ - new Literal("\\x"), - new RuleRef("hexDigit"), - new RuleRef("hexDigit") - ]), - function(dummy, digit1, digit2) { - return String.fromCharCode(parseInt("0x" + digit1 + digit2)); - } - ) - ), - - unicodeEscapeSequence: - new Rule( - "unicodeEscapeSequence", - null, - new Action( - new Sequence([ - new Literal("\\u"), - new RuleRef("hexDigit"), - new RuleRef("hexDigit"), - new RuleRef("hexDigit"), - new RuleRef("hexDigit") - ]), - function(dummy, digit1, digit2, digit3, digit4) { - return String.fromCharCode(parseInt( - "0x" + digit1 + digit2 + digit3 + digit4 - )); - } - ) - ), - - eolEscapeSequence: - new Rule( - "eolEscapeSequence", - null, - new Action( - new Sequence([new Literal("\\"), new RuleRef("eol")]), - returnSecondArg - ) - ), - - digit: - new Rule( - "digit", - null, - new Choice([ - new Literal("0"), - new Literal("1"), - new Literal("2"), - new Literal("3"), - new Literal("4"), - new Literal("5"), - new Literal("6"), - new Literal("7"), - new Literal("8"), - new Literal("9") - ]) - ), - - hexDigit: - new Rule( - "hexDigit", - null, - new Choice([ - new Literal("0"), - new Literal("1"), - new Literal("2"), - new Literal("3"), - new Literal("4"), - new Literal("5"), - new Literal("6"), - new Literal("7"), - new Literal("8"), - new Literal("9"), - new Literal("a"), - new Literal("b"), - new Literal("c"), - new Literal("d"), - new Literal("e"), - new Literal("f"), - new Literal("A"), - new Literal("B"), - new Literal("C"), - new Literal("D"), - new Literal("E"), - new Literal("F") - ]) - ), - - letter: - new Rule( - "letter", - null, - new Choice([ - new RuleRef("lowerCaseLetter"), - new RuleRef("upperCaseLetter") - ]) - ), - - lowerCaseLetter: - new Rule( - "lowerCaseLetter", - null, - new Choice([ - new Literal("a"), - new Literal("b"), - new Literal("c"), - new Literal("d"), - new Literal("e"), - new Literal("f"), - new Literal("g"), - new Literal("h"), - new Literal("i"), - new Literal("j"), - new Literal("k"), - new Literal("l"), - new Literal("m"), - new Literal("n"), - new Literal("o"), - new Literal("p"), - new Literal("q"), - new Literal("r"), - new Literal("s"), - new Literal("t"), - new Literal("u"), - new Literal("v"), - new Literal("w"), - new Literal("x"), - new Literal("y"), - new Literal("z") - ]) - ), - - upperCaseLetter: - new Rule( - "upperCaseLetter", - null, - new Choice([ - new Literal("A"), - new Literal("B"), - new Literal("C"), - new Literal("D"), - new Literal("E"), - new Literal("F"), - new Literal("G"), - new Literal("H"), - new Literal("I"), - new Literal("J"), - new Literal("K"), - new Literal("L"), - new Literal("M"), - new Literal("N"), - new Literal("O"), - new Literal("P"), - new Literal("Q"), - new Literal("R"), - new Literal("S"), - new Literal("T"), - new Literal("U"), - new Literal("V"), - new Literal("W"), - new Literal("X"), - new Literal("Y"), - new Literal("Z") - ]) - ), - - __: - new Rule( - "__", - null, - new ZeroOrMore( - new Choice([ - new RuleRef("whitespace"), - new RuleRef("eol"), - new RuleRef("comment") - ]) - ) - ), - - /* Modelled after ECMA-262, 5th ed., 7.4. */ - comment: - new Rule( - "comment", - "comment", - new Choice([ - new RuleRef("singleLineComment"), - new RuleRef("multiLineComment") - ]) - ), - - singleLineComment: - new Rule( - "singleLineComment", - null, - new Sequence([ - new Literal("//"), - new ZeroOrMore( - new Sequence([new NotPredicate(new RuleRef("eolChar")), new Any()]) - ) - ]) - ), - - multiLineComment: - new Rule( - "multiLineComment", - null, - new Sequence([ - new Literal("/*"), - new ZeroOrMore( - new Sequence([new NotPredicate(new Literal("*/")), new Any()]) - ), - new Literal("*/") - ]) - ), - - /* Modelled after ECMA-262, 5th ed., 7.3. */ - eol: - new Rule( - "eol", - "end of line", - new Choice([ - new Literal("\n"), - new Literal("\r\n"), - new Literal("\r"), - new Literal("\u2028"), - new Literal("\u2029") - ]) - ), - - eolChar: - new Rule( - "eolChar", - null, - new Choice([ - new Literal("\n"), - new Literal("\r"), - new Literal("\u2028"), - new Literal("\u2029") - ]) - ), - - /* Modelled after ECMA-262, 5th ed., 7.2. */ - whitespace: - new Rule( - "whitespace", - "whitespace", - new Choice([ - new Literal(" "), - new Literal("\t"), - new Literal("\v"), - new Literal("\f"), - new Literal("\xA0"), - // Should be here, but causes infinite loop in Rhino: - // new Literal("\uFEFF"), - new Literal("\u1680"), - new Literal("\u180E"), - new Literal("\u2000"), - new Literal("\u2001"), - new Literal("\u2002"), - new Literal("\u2003"), - new Literal("\u2004"), - new Literal("\u2005"), - new Literal("\u2006"), - new Literal("\u2007"), - new Literal("\u2008"), - new Literal("\u2009"), - new Literal("\u200A"), - new Literal("\u202F"), - new Literal("\u205F"), - new Literal("\u3000") - ]) - ), - }, "grammar"); -} - })(); diff --git a/lib/metagrammar.js b/lib/metagrammar.js new file mode 100644 index 0000000..38241e3 --- /dev/null +++ b/lib/metagrammar.js @@ -0,0 +1,4625 @@ +PEG.grammarParser = (function(){ + var result = new PEG.Parser("grammar"); + + result._parse_grammar = function(context) { + this._cache["grammar"] = this._cache["grammar"] || []; + var cachedResult = this._cache["grammar"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos0 = this._pos; + var result2 = this._parse___(context); + if (result2 !== null) { + var savedPos1 = this._pos; + var result5 = this._parse_rule(context); + if (result5 !== null) { + var result6 = []; + var result7 = this._parse_rule(context); + while (result7 !== null) { + result6.push(result7); + var result7 = this._parse_rule(context); + } + if (result6 !== null) { + var result4 = [result5, result6]; + } else { + var result4 = null; + this._pos = savedPos1; + } + } else { + var result4 = null; + this._pos = savedPos1; + } + var result3 = result4 !== null + ? ( + function (first, rest) { + return [first].concat(rest); + } + ).apply(this, result4) + : null; + if (result3 !== null) { + var result1 = [result2, result3]; + } else { + var result1 = null; + this._pos = savedPos0; + } + } else { + var result1 = null; + this._pos = savedPos0; + } + var result0 = result1 !== null + ? (function() { + var result = {}; + for (var i = 0; i < (arguments[1]).length; i++) { result[(arguments[1])[i].getName()] = (arguments[1])[i]; } + return result; + }).apply(this, result1) + : null; + + + + this._cache["grammar"][pos] = { + length: this._pos - pos, + result: result0 + }; + return result0; + }; + + result._parse_rule = function(context) { + this._cache["rule"] = this._cache["rule"] || []; + var cachedResult = this._cache["rule"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos2 = this._pos; + var result10 = this._parse_identifier(context); + if (result10 !== null) { + var result15 = this._parse_literal(context); + if (result15 !== null) { + var result11 = result15; + } else { + if (this._input.substr(this._pos, 0) === "") { + var result14 = ""; + this._pos += 0; + } else { + var result14 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("")); + } + } + if (result14 !== null) { + var result11 = result14; + } else { + var result11 = null;; + }; + } + if (result11 !== null) { + var result12 = this._parse_colon(context); + if (result12 !== null) { + var result13 = this._parse_expression(context); + if (result13 !== null) { + var result9 = [result10, result11, result12, result13]; + } else { + var result9 = null; + this._pos = savedPos2; + } + } else { + var result9 = null; + this._pos = savedPos2; + } + } else { + var result9 = null; + this._pos = savedPos2; + } + } else { + var result9 = null; + this._pos = savedPos2; + } + var result8 = result9 !== null + ? (function() { + return new PEG.Grammar.Rule((arguments[0]), (arguments[1]) !== "" ? (arguments[1]) : null, (arguments[3])); + }).apply(this, result9) + : null; + + + + this._cache["rule"][pos] = { + length: this._pos - pos, + result: result8 + }; + return result8; + }; + + result._parse_expression = function(context) { + this._cache["expression"] = this._cache["expression"] || []; + var cachedResult = this._cache["expression"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result16 = this._parse_choice(context); + + + + this._cache["expression"][pos] = { + length: this._pos - pos, + result: result16 + }; + return result16; + }; + + result._parse_choice = function(context) { + this._cache["choice"] = this._cache["choice"] || []; + var cachedResult = this._cache["choice"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos3 = this._pos; + var result19 = this._parse_sequence(context); + if (result19 !== null) { + var result20 = []; + var savedPos4 = this._pos; + var result22 = this._parse_slash(context); + if (result22 !== null) { + var result23 = this._parse_sequence(context); + if (result23 !== null) { + var result21 = [result22, result23]; + } else { + var result21 = null; + this._pos = savedPos4; + } + } else { + var result21 = null; + this._pos = savedPos4; + } + while (result21 !== null) { + result20.push(result21); + var savedPos4 = this._pos; + var result22 = this._parse_slash(context); + if (result22 !== null) { + var result23 = this._parse_sequence(context); + if (result23 !== null) { + var result21 = [result22, result23]; + } else { + var result21 = null; + this._pos = savedPos4; + } + } else { + var result21 = null; + this._pos = savedPos4; + } + } + if (result20 !== null) { + var result18 = [result19, result20]; + } else { + var result18 = null; + this._pos = savedPos3; + } + } else { + var result18 = null; + this._pos = savedPos3; + } + var result17 = result18 !== null + ? (function() { + return (arguments[1]).length > 0 + ? new PEG.Grammar.Choice([(arguments[0])].concat(PEG.ArrayUtils.map( + (arguments[1]), + function(element) { return element[1]; } + ))) + : (arguments[0]); + }).apply(this, result18) + : null; + + + + this._cache["choice"][pos] = { + length: this._pos - pos, + result: result17 + }; + return result17; + }; + + result._parse_sequence = function(context) { + this._cache["sequence"] = this._cache["sequence"] || []; + var cachedResult = this._cache["sequence"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos5 = this._pos; + var result30 = []; + var result32 = this._parse_prefixed(context); + while (result32 !== null) { + result30.push(result32); + var result32 = this._parse_prefixed(context); + } + if (result30 !== null) { + var result31 = this._parse_action(context); + if (result31 !== null) { + var result29 = [result30, result31]; + } else { + var result29 = null; + this._pos = savedPos5; + } + } else { + var result29 = null; + this._pos = savedPos5; + } + var result28 = result29 !== null + ? (function() { + return new PEG.Grammar.Action( + (arguments[0]).length != 1 ? new PEG.Grammar.Sequence((arguments[0])) : (arguments[0])[0], + (arguments[1]) + ); + }).apply(this, result29) + : null; + if (result28 !== null) { + var result24 = result28; + } else { + var result26 = []; + var result27 = this._parse_prefixed(context); + while (result27 !== null) { + result26.push(result27); + var result27 = this._parse_prefixed(context); + } + var result25 = result26 !== null + ? (function() { return (arguments[0]).length != 1 ? new PEG.Grammar.Sequence((arguments[0])) : (arguments[0])[0]; }).call(this, result26) + : null; + if (result25 !== null) { + var result24 = result25; + } else { + var result24 = null;; + }; + } + + + + this._cache["sequence"][pos] = { + length: this._pos - pos, + result: result24 + }; + return result24; + }; + + result._parse_prefixed = function(context) { + this._cache["prefixed"] = this._cache["prefixed"] || []; + var cachedResult = this._cache["prefixed"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos7 = this._pos; + var result41 = this._parse_and(context); + if (result41 !== null) { + var result42 = this._parse_suffixed(context); + if (result42 !== null) { + var result40 = [result41, result42]; + } else { + var result40 = null; + this._pos = savedPos7; + } + } else { + var result40 = null; + this._pos = savedPos7; + } + var result39 = result40 !== null + ? (function() { + return new PEG.Grammar.NotPredicate(new PEG.Grammar.NotPredicate((arguments[1]))); + }).apply(this, result40) + : null; + if (result39 !== null) { + var result33 = result39; + } else { + var savedPos6 = this._pos; + var result37 = this._parse_not(context); + if (result37 !== null) { + var result38 = this._parse_suffixed(context); + if (result38 !== null) { + var result36 = [result37, result38]; + } else { + var result36 = null; + this._pos = savedPos6; + } + } else { + var result36 = null; + this._pos = savedPos6; + } + var result35 = result36 !== null + ? (function() { return new PEG.Grammar.NotPredicate((arguments[1])); }).apply(this, result36) + : null; + if (result35 !== null) { + var result33 = result35; + } else { + var result34 = this._parse_suffixed(context); + if (result34 !== null) { + var result33 = result34; + } else { + var result33 = null;; + }; + }; + } + + + + this._cache["prefixed"][pos] = { + length: this._pos - pos, + result: result33 + }; + return result33; + }; + + result._parse_suffixed = function(context) { + this._cache["suffixed"] = this._cache["suffixed"] || []; + var cachedResult = this._cache["suffixed"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos10 = this._pos; + var result55 = this._parse_primary(context); + if (result55 !== null) { + var result56 = this._parse_question(context); + if (result56 !== null) { + var result54 = [result55, result56]; + } else { + var result54 = null; + this._pos = savedPos10; + } + } else { + var result54 = null; + this._pos = savedPos10; + } + var result53 = result54 !== null + ? (function() { + return new PEG.Grammar.Choice([(arguments[0]), new PEG.Grammar.Literal("")]); + }).apply(this, result54) + : null; + if (result53 !== null) { + var result43 = result53; + } else { + var savedPos9 = this._pos; + var result51 = this._parse_primary(context); + if (result51 !== null) { + var result52 = this._parse_star(context); + if (result52 !== null) { + var result50 = [result51, result52]; + } else { + var result50 = null; + this._pos = savedPos9; + } + } else { + var result50 = null; + this._pos = savedPos9; + } + var result49 = result50 !== null + ? (function() { return new PEG.Grammar.ZeroOrMore((arguments[0])); }).apply(this, result50) + : null; + if (result49 !== null) { + var result43 = result49; + } else { + var savedPos8 = this._pos; + var result47 = this._parse_primary(context); + if (result47 !== null) { + var result48 = this._parse_plus(context); + if (result48 !== null) { + var result46 = [result47, result48]; + } else { + var result46 = null; + this._pos = savedPos8; + } + } else { + var result46 = null; + this._pos = savedPos8; + } + var result45 = result46 !== null + ? (function() { + return new PEG.Grammar.Action( + new PEG.Grammar.Sequence([(arguments[0]), new PEG.Grammar.ZeroOrMore((arguments[0]))]), + function(first, rest) { return [first].concat(rest); } + ); + }).apply(this, result46) + : null; + if (result45 !== null) { + var result43 = result45; + } else { + var result44 = this._parse_primary(context); + if (result44 !== null) { + var result43 = result44; + } else { + var result43 = null;; + }; + }; + }; + } + + + + this._cache["suffixed"][pos] = { + length: this._pos - pos, + result: result43 + }; + return result43; + }; + + result._parse_primary = function(context) { + this._cache["primary"] = this._cache["primary"] || []; + var cachedResult = this._cache["primary"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos12 = this._pos; + var result71 = this._parse_identifier(context); + if (result71 !== null) { + var savedPos13 = this._pos; + var savedReportMatchFailuresVar0 = context.reportMatchFailures; + context.reportMatchFailures = false; + var savedPos14 = this._pos; + var result77 = this._parse_literal(context); + if (result77 !== null) { + var result74 = result77; + } else { + if (this._input.substr(this._pos, 0) === "") { + var result76 = ""; + this._pos += 0; + } else { + var result76 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("")); + } + } + if (result76 !== null) { + var result74 = result76; + } else { + var result74 = null;; + }; + } + if (result74 !== null) { + var result75 = this._parse_colon(context); + if (result75 !== null) { + var result73 = [result74, result75]; + } else { + var result73 = null; + this._pos = savedPos14; + } + } else { + var result73 = null; + this._pos = savedPos14; + } + context.reportMatchFailures = savedReportMatchFailuresVar0; + if (result73 === null) { + var result72 = ''; + } else { + var result72 = null; + this._pos = savedPos13; + } + if (result72 !== null) { + var result70 = [result71, result72]; + } else { + var result70 = null; + this._pos = savedPos12; + } + } else { + var result70 = null; + this._pos = savedPos12; + } + var result69 = result70 !== null + ? (function() { return new PEG.Grammar.RuleRef((arguments[0])); }).apply(this, result70) + : null; + if (result69 !== null) { + var result57 = result69; + } else { + var result68 = this._parse_literal(context); + var result67 = result68 !== null + ? (function() { return new PEG.Grammar.Literal((arguments[0])); }).call(this, result68) + : null; + if (result67 !== null) { + var result57 = result67; + } else { + var result66 = this._parse_dot(context); + var result65 = result66 !== null + ? (function() { return new PEG.Grammar.Any(); }).call(this, result66) + : null; + if (result65 !== null) { + var result57 = result65; + } else { + var result64 = this._parse_class(context); + var result63 = result64 !== null + ? (function() { + return new PEG.Grammar.Choice( + PEG.ArrayUtils.map( + (arguments[0]).split(""), + function(character) { return new PEG.Grammar.Literal(character); } + ) + ); + }).call(this, result64) + : null; + if (result63 !== null) { + var result57 = result63; + } else { + var savedPos11 = this._pos; + var result60 = this._parse_lparen(context); + if (result60 !== null) { + var result61 = this._parse_expression(context); + if (result61 !== null) { + var result62 = this._parse_rparen(context); + if (result62 !== null) { + var result59 = [result60, result61, result62]; + } else { + var result59 = null; + this._pos = savedPos11; + } + } else { + var result59 = null; + this._pos = savedPos11; + } + } else { + var result59 = null; + this._pos = savedPos11; + } + var result58 = result59 !== null + ? (function() { return (arguments[1]); }).apply(this, result59) + : null; + if (result58 !== null) { + var result57 = result58; + } else { + var result57 = null;; + }; + }; + }; + }; + } + + + + this._cache["primary"][pos] = { + length: this._pos - pos, + result: result57 + }; + return result57; + }; + + result._parse_action = function(context) { + this._cache["action"] = this._cache["action"] || []; + var cachedResult = this._cache["action"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + var savedPos15 = this._pos; + var result80 = this._parse_braced(context); + if (result80 !== null) { + var result81 = this._parse___(context); + if (result81 !== null) { + var result79 = [result80, result81]; + } else { + var result79 = null; + this._pos = savedPos15; + } + } else { + var result79 = null; + this._pos = savedPos15; + } + var result78 = result79 !== null + ? (function() { return (arguments[0]).substr(1, (arguments[0]).length - 2); }).apply(this, result79) + : null; + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result78 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("action")); + } + + this._cache["action"][pos] = { + length: this._pos - pos, + result: result78 + }; + return result78; + }; + + result._parse_braced = function(context) { + this._cache["braced"] = this._cache["braced"] || []; + var cachedResult = this._cache["braced"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos16 = this._pos; + if (this._input.substr(this._pos, 1) === "{") { + var result84 = "{"; + this._pos += 1; + } else { + var result84 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("{")); + } + } + if (result84 !== null) { + var result85 = []; + var result89 = this._parse_braced(context); + if (result89 !== null) { + var result87 = result89; + } else { + var result88 = this._parse_nonBraceCharacter(context); + if (result88 !== null) { + var result87 = result88; + } else { + var result87 = null;; + }; + } + while (result87 !== null) { + result85.push(result87); + var result89 = this._parse_braced(context); + if (result89 !== null) { + var result87 = result89; + } else { + var result88 = this._parse_nonBraceCharacter(context); + if (result88 !== null) { + var result87 = result88; + } else { + var result87 = null;; + }; + } + } + if (result85 !== null) { + if (this._input.substr(this._pos, 1) === "}") { + var result86 = "}"; + this._pos += 1; + } else { + var result86 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("}")); + } + } + if (result86 !== null) { + var result83 = [result84, result85, result86]; + } else { + var result83 = null; + this._pos = savedPos16; + } + } else { + var result83 = null; + this._pos = savedPos16; + } + } else { + var result83 = null; + this._pos = savedPos16; + } + var result82 = result83 !== null + ? (function() { return (arguments[0]) + (arguments[1]).join("") + (arguments[2]); }).apply(this, result83) + : null; + + + + this._cache["braced"][pos] = { + length: this._pos - pos, + result: result82 + }; + return result82; + }; + + result._parse_nonBraceCharacters = function(context) { + this._cache["nonBraceCharacters"] = this._cache["nonBraceCharacters"] || []; + var cachedResult = this._cache["nonBraceCharacters"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos17 = this._pos; + var result93 = this._parse_nonBraceCharacter(context); + if (result93 !== null) { + var result94 = []; + var result95 = this._parse_nonBraceCharacter(context); + while (result95 !== null) { + result94.push(result95); + var result95 = this._parse_nonBraceCharacter(context); + } + if (result94 !== null) { + var result92 = [result93, result94]; + } else { + var result92 = null; + this._pos = savedPos17; + } + } else { + var result92 = null; + this._pos = savedPos17; + } + var result91 = result92 !== null + ? ( + function (first, rest) { + return [first].concat(rest); + } + ).apply(this, result92) + : null; + var result90 = result91 !== null + ? (function() { return (arguments[0]).join(""); }).call(this, result91) + : null; + + + + this._cache["nonBraceCharacters"][pos] = { + length: this._pos - pos, + result: result90 + }; + return result90; + }; + + result._parse_nonBraceCharacter = function(context) { + this._cache["nonBraceCharacter"] = this._cache["nonBraceCharacter"] || []; + var cachedResult = this._cache["nonBraceCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos18 = this._pos; + var savedPos19 = this._pos; + var savedReportMatchFailuresVar1 = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 1) === "{") { + var result102 = "{"; + this._pos += 1; + } else { + var result102 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("{")); + } + } + if (result102 !== null) { + var result100 = result102; + } else { + if (this._input.substr(this._pos, 1) === "}") { + var result101 = "}"; + this._pos += 1; + } else { + var result101 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("}")); + } + } + if (result101 !== null) { + var result100 = result101; + } else { + var result100 = null;; + }; + } + context.reportMatchFailures = savedReportMatchFailuresVar1; + if (result100 === null) { + var result98 = ''; + } else { + var result98 = null; + this._pos = savedPos19; + } + if (result98 !== null) { + if (this._input.length > this._pos) { + var result99 = this._input[this._pos]; + this._pos++; + } else { + var result99 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result99 !== null) { + var result97 = [result98, result99]; + } else { + var result97 = null; + this._pos = savedPos18; + } + } else { + var result97 = null; + this._pos = savedPos18; + } + var result96 = result97 !== null + ? (function() { return (arguments[1]); }).apply(this, result97) + : null; + + + + this._cache["nonBraceCharacter"][pos] = { + length: this._pos - pos, + result: result96 + }; + return result96; + }; + + result._parse_colon = function(context) { + this._cache["colon"] = this._cache["colon"] || []; + var cachedResult = this._cache["colon"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos20 = this._pos; + if (this._input.substr(this._pos, 1) === ":") { + var result105 = ":"; + this._pos += 1; + } else { + var result105 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(":")); + } + } + if (result105 !== null) { + var result106 = this._parse___(context); + if (result106 !== null) { + var result104 = [result105, result106]; + } else { + var result104 = null; + this._pos = savedPos20; + } + } else { + var result104 = null; + this._pos = savedPos20; + } + var result103 = result104 !== null + ? (function() { return (arguments[0]); }).apply(this, result104) + : null; + + + + this._cache["colon"][pos] = { + length: this._pos - pos, + result: result103 + }; + return result103; + }; + + result._parse_slash = function(context) { + this._cache["slash"] = this._cache["slash"] || []; + var cachedResult = this._cache["slash"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos21 = this._pos; + if (this._input.substr(this._pos, 1) === "/") { + var result109 = "/"; + this._pos += 1; + } else { + var result109 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("/")); + } + } + if (result109 !== null) { + var result110 = this._parse___(context); + if (result110 !== null) { + var result108 = [result109, result110]; + } else { + var result108 = null; + this._pos = savedPos21; + } + } else { + var result108 = null; + this._pos = savedPos21; + } + var result107 = result108 !== null + ? (function() { return (arguments[0]); }).apply(this, result108) + : null; + + + + this._cache["slash"][pos] = { + length: this._pos - pos, + result: result107 + }; + return result107; + }; + + result._parse_and = function(context) { + this._cache["and"] = this._cache["and"] || []; + var cachedResult = this._cache["and"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos22 = this._pos; + if (this._input.substr(this._pos, 1) === "&") { + var result113 = "&"; + this._pos += 1; + } else { + var result113 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("&")); + } + } + if (result113 !== null) { + var result114 = this._parse___(context); + if (result114 !== null) { + var result112 = [result113, result114]; + } else { + var result112 = null; + this._pos = savedPos22; + } + } else { + var result112 = null; + this._pos = savedPos22; + } + var result111 = result112 !== null + ? (function() { return (arguments[0]); }).apply(this, result112) + : null; + + + + this._cache["and"][pos] = { + length: this._pos - pos, + result: result111 + }; + return result111; + }; + + result._parse_not = function(context) { + this._cache["not"] = this._cache["not"] || []; + var cachedResult = this._cache["not"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos23 = this._pos; + if (this._input.substr(this._pos, 1) === "!") { + var result117 = "!"; + this._pos += 1; + } else { + var result117 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("!")); + } + } + if (result117 !== null) { + var result118 = this._parse___(context); + if (result118 !== null) { + var result116 = [result117, result118]; + } else { + var result116 = null; + this._pos = savedPos23; + } + } else { + var result116 = null; + this._pos = savedPos23; + } + var result115 = result116 !== null + ? (function() { return (arguments[0]); }).apply(this, result116) + : null; + + + + this._cache["not"][pos] = { + length: this._pos - pos, + result: result115 + }; + return result115; + }; + + result._parse_question = function(context) { + this._cache["question"] = this._cache["question"] || []; + var cachedResult = this._cache["question"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos24 = this._pos; + if (this._input.substr(this._pos, 1) === "?") { + var result121 = "?"; + this._pos += 1; + } else { + var result121 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("?")); + } + } + if (result121 !== null) { + var result122 = this._parse___(context); + if (result122 !== null) { + var result120 = [result121, result122]; + } else { + var result120 = null; + this._pos = savedPos24; + } + } else { + var result120 = null; + this._pos = savedPos24; + } + var result119 = result120 !== null + ? (function() { return (arguments[0]); }).apply(this, result120) + : null; + + + + this._cache["question"][pos] = { + length: this._pos - pos, + result: result119 + }; + return result119; + }; + + result._parse_star = function(context) { + this._cache["star"] = this._cache["star"] || []; + var cachedResult = this._cache["star"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos25 = this._pos; + if (this._input.substr(this._pos, 1) === "*") { + var result125 = "*"; + this._pos += 1; + } else { + var result125 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("*")); + } + } + if (result125 !== null) { + var result126 = this._parse___(context); + if (result126 !== null) { + var result124 = [result125, result126]; + } else { + var result124 = null; + this._pos = savedPos25; + } + } else { + var result124 = null; + this._pos = savedPos25; + } + var result123 = result124 !== null + ? (function() { return (arguments[0]); }).apply(this, result124) + : null; + + + + this._cache["star"][pos] = { + length: this._pos - pos, + result: result123 + }; + return result123; + }; + + result._parse_plus = function(context) { + this._cache["plus"] = this._cache["plus"] || []; + var cachedResult = this._cache["plus"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos26 = this._pos; + if (this._input.substr(this._pos, 1) === "+") { + var result129 = "+"; + this._pos += 1; + } else { + var result129 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("+")); + } + } + if (result129 !== null) { + var result130 = this._parse___(context); + if (result130 !== null) { + var result128 = [result129, result130]; + } else { + var result128 = null; + this._pos = savedPos26; + } + } else { + var result128 = null; + this._pos = savedPos26; + } + var result127 = result128 !== null + ? (function() { return (arguments[0]); }).apply(this, result128) + : null; + + + + this._cache["plus"][pos] = { + length: this._pos - pos, + result: result127 + }; + return result127; + }; + + result._parse_lparen = function(context) { + this._cache["lparen"] = this._cache["lparen"] || []; + var cachedResult = this._cache["lparen"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos27 = this._pos; + if (this._input.substr(this._pos, 1) === "(") { + var result133 = "("; + this._pos += 1; + } else { + var result133 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("(")); + } + } + if (result133 !== null) { + var result134 = this._parse___(context); + if (result134 !== null) { + var result132 = [result133, result134]; + } else { + var result132 = null; + this._pos = savedPos27; + } + } else { + var result132 = null; + this._pos = savedPos27; + } + var result131 = result132 !== null + ? (function() { return (arguments[0]); }).apply(this, result132) + : null; + + + + this._cache["lparen"][pos] = { + length: this._pos - pos, + result: result131 + }; + return result131; + }; + + result._parse_rparen = function(context) { + this._cache["rparen"] = this._cache["rparen"] || []; + var cachedResult = this._cache["rparen"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos28 = this._pos; + if (this._input.substr(this._pos, 1) === ")") { + var result137 = ")"; + this._pos += 1; + } else { + var result137 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(")")); + } + } + if (result137 !== null) { + var result138 = this._parse___(context); + if (result138 !== null) { + var result136 = [result137, result138]; + } else { + var result136 = null; + this._pos = savedPos28; + } + } else { + var result136 = null; + this._pos = savedPos28; + } + var result135 = result136 !== null + ? (function() { return (arguments[0]); }).apply(this, result136) + : null; + + + + this._cache["rparen"][pos] = { + length: this._pos - pos, + result: result135 + }; + return result135; + }; + + result._parse_dot = function(context) { + this._cache["dot"] = this._cache["dot"] || []; + var cachedResult = this._cache["dot"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos29 = this._pos; + if (this._input.substr(this._pos, 1) === ".") { + var result141 = "."; + this._pos += 1; + } else { + var result141 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(".")); + } + } + if (result141 !== null) { + var result142 = this._parse___(context); + if (result142 !== null) { + var result140 = [result141, result142]; + } else { + var result140 = null; + this._pos = savedPos29; + } + } else { + var result140 = null; + this._pos = savedPos29; + } + var result139 = result140 !== null + ? (function() { return (arguments[0]); }).apply(this, result140) + : null; + + + + this._cache["dot"][pos] = { + length: this._pos - pos, + result: result139 + }; + return result139; + }; + + result._parse_identifier = function(context) { + this._cache["identifier"] = this._cache["identifier"] || []; + var cachedResult = this._cache["identifier"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + var savedPos30 = this._pos; + var result155 = this._parse_letter(context); + if (result155 !== null) { + var result145 = result155; + } else { + if (this._input.substr(this._pos, 1) === "_") { + var result154 = "_"; + this._pos += 1; + } else { + var result154 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("_")); + } + } + if (result154 !== null) { + var result145 = result154; + } else { + if (this._input.substr(this._pos, 1) === "$") { + var result153 = "$"; + this._pos += 1; + } else { + var result153 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("$")); + } + } + if (result153 !== null) { + var result145 = result153; + } else { + var result145 = null;; + }; + }; + } + if (result145 !== null) { + var result146 = []; + var result152 = this._parse_letter(context); + if (result152 !== null) { + var result148 = result152; + } else { + var result151 = this._parse_digit(context); + if (result151 !== null) { + var result148 = result151; + } else { + if (this._input.substr(this._pos, 1) === "_") { + var result150 = "_"; + this._pos += 1; + } else { + var result150 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("_")); + } + } + if (result150 !== null) { + var result148 = result150; + } else { + if (this._input.substr(this._pos, 1) === "$") { + var result149 = "$"; + this._pos += 1; + } else { + var result149 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("$")); + } + } + if (result149 !== null) { + var result148 = result149; + } else { + var result148 = null;; + }; + }; + }; + } + while (result148 !== null) { + result146.push(result148); + var result152 = this._parse_letter(context); + if (result152 !== null) { + var result148 = result152; + } else { + var result151 = this._parse_digit(context); + if (result151 !== null) { + var result148 = result151; + } else { + if (this._input.substr(this._pos, 1) === "_") { + var result150 = "_"; + this._pos += 1; + } else { + var result150 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("_")); + } + } + if (result150 !== null) { + var result148 = result150; + } else { + if (this._input.substr(this._pos, 1) === "$") { + var result149 = "$"; + this._pos += 1; + } else { + var result149 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("$")); + } + } + if (result149 !== null) { + var result148 = result149; + } else { + var result148 = null;; + }; + }; + }; + } + } + if (result146 !== null) { + var result147 = this._parse___(context); + if (result147 !== null) { + var result144 = [result145, result146, result147]; + } else { + var result144 = null; + this._pos = savedPos30; + } + } else { + var result144 = null; + this._pos = savedPos30; + } + } else { + var result144 = null; + this._pos = savedPos30; + } + var result143 = result144 !== null + ? (function() { + return (arguments[0]) + (arguments[1]).join(""); + }).apply(this, result144) + : null; + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result143 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("identifier")); + } + + this._cache["identifier"][pos] = { + length: this._pos - pos, + result: result143 + }; + return result143; + }; + + result._parse_literal = function(context) { + this._cache["literal"] = this._cache["literal"] || []; + var cachedResult = this._cache["literal"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + var savedPos31 = this._pos; + var result161 = this._parse_doubleQuotedLiteral(context); + if (result161 !== null) { + var result158 = result161; + } else { + var result160 = this._parse_singleQuotedLiteral(context); + if (result160 !== null) { + var result158 = result160; + } else { + var result158 = null;; + }; + } + if (result158 !== null) { + var result159 = this._parse___(context); + if (result159 !== null) { + var result157 = [result158, result159]; + } else { + var result157 = null; + this._pos = savedPos31; + } + } else { + var result157 = null; + this._pos = savedPos31; + } + var result156 = result157 !== null + ? (function() { return (arguments[0]); }).apply(this, result157) + : null; + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result156 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("literal")); + } + + this._cache["literal"][pos] = { + length: this._pos - pos, + result: result156 + }; + return result156; + }; + + result._parse_doubleQuotedLiteral = function(context) { + this._cache["doubleQuotedLiteral"] = this._cache["doubleQuotedLiteral"] || []; + var cachedResult = this._cache["doubleQuotedLiteral"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos32 = this._pos; + if (this._input.substr(this._pos, 1) === "\"") { + var result164 = "\""; + this._pos += 1; + } else { + var result164 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\"")); + } + } + if (result164 !== null) { + var result165 = []; + var result167 = this._parse_doubleQuotedCharacter(context); + while (result167 !== null) { + result165.push(result167); + var result167 = this._parse_doubleQuotedCharacter(context); + } + if (result165 !== null) { + if (this._input.substr(this._pos, 1) === "\"") { + var result166 = "\""; + this._pos += 1; + } else { + var result166 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\"")); + } + } + if (result166 !== null) { + var result163 = [result164, result165, result166]; + } else { + var result163 = null; + this._pos = savedPos32; + } + } else { + var result163 = null; + this._pos = savedPos32; + } + } else { + var result163 = null; + this._pos = savedPos32; + } + var result162 = result163 !== null + ? (function() { return (arguments[1]).join(""); }).apply(this, result163) + : null; + + + + this._cache["doubleQuotedLiteral"][pos] = { + length: this._pos - pos, + result: result162 + }; + return result162; + }; + + result._parse_doubleQuotedCharacter = function(context) { + this._cache["doubleQuotedCharacter"] = this._cache["doubleQuotedCharacter"] || []; + var cachedResult = this._cache["doubleQuotedCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result174 = this._parse_simpleDoubleQuotedCharacter(context); + if (result174 !== null) { + var result168 = result174; + } else { + var result173 = this._parse_simpleEscapeSequence(context); + if (result173 !== null) { + var result168 = result173; + } else { + var result172 = this._parse_zeroEscapeSequence(context); + if (result172 !== null) { + var result168 = result172; + } else { + var result171 = this._parse_hexEscapeSequence(context); + if (result171 !== null) { + var result168 = result171; + } else { + var result170 = this._parse_unicodeEscapeSequence(context); + if (result170 !== null) { + var result168 = result170; + } else { + var result169 = this._parse_eolEscapeSequence(context); + if (result169 !== null) { + var result168 = result169; + } else { + var result168 = null;; + }; + }; + }; + }; + }; + } + + + + this._cache["doubleQuotedCharacter"][pos] = { + length: this._pos - pos, + result: result168 + }; + return result168; + }; + + result._parse_simpleDoubleQuotedCharacter = function(context) { + this._cache["simpleDoubleQuotedCharacter"] = this._cache["simpleDoubleQuotedCharacter"] || []; + var cachedResult = this._cache["simpleDoubleQuotedCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos33 = this._pos; + var savedPos34 = this._pos; + var savedReportMatchFailuresVar2 = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 1) === "\"") { + var result182 = "\""; + this._pos += 1; + } else { + var result182 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\"")); + } + } + if (result182 !== null) { + var result179 = result182; + } else { + if (this._input.substr(this._pos, 1) === "\\") { + var result181 = "\\"; + this._pos += 1; + } else { + var result181 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\")); + } + } + if (result181 !== null) { + var result179 = result181; + } else { + var result180 = this._parse_eolChar(context); + if (result180 !== null) { + var result179 = result180; + } else { + var result179 = null;; + }; + }; + } + context.reportMatchFailures = savedReportMatchFailuresVar2; + if (result179 === null) { + var result177 = ''; + } else { + var result177 = null; + this._pos = savedPos34; + } + if (result177 !== null) { + if (this._input.length > this._pos) { + var result178 = this._input[this._pos]; + this._pos++; + } else { + var result178 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result178 !== null) { + var result176 = [result177, result178]; + } else { + var result176 = null; + this._pos = savedPos33; + } + } else { + var result176 = null; + this._pos = savedPos33; + } + var result175 = result176 !== null + ? (function() { return (arguments[1]); }).apply(this, result176) + : null; + + + + this._cache["simpleDoubleQuotedCharacter"][pos] = { + length: this._pos - pos, + result: result175 + }; + return result175; + }; + + result._parse_singleQuotedLiteral = function(context) { + this._cache["singleQuotedLiteral"] = this._cache["singleQuotedLiteral"] || []; + var cachedResult = this._cache["singleQuotedLiteral"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos35 = this._pos; + if (this._input.substr(this._pos, 1) === "'") { + var result185 = "'"; + this._pos += 1; + } else { + var result185 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("'")); + } + } + if (result185 !== null) { + var result186 = []; + var result188 = this._parse_singleQuotedCharacter(context); + while (result188 !== null) { + result186.push(result188); + var result188 = this._parse_singleQuotedCharacter(context); + } + if (result186 !== null) { + if (this._input.substr(this._pos, 1) === "'") { + var result187 = "'"; + this._pos += 1; + } else { + var result187 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("'")); + } + } + if (result187 !== null) { + var result184 = [result185, result186, result187]; + } else { + var result184 = null; + this._pos = savedPos35; + } + } else { + var result184 = null; + this._pos = savedPos35; + } + } else { + var result184 = null; + this._pos = savedPos35; + } + var result183 = result184 !== null + ? (function() { return (arguments[1]).join(""); }).apply(this, result184) + : null; + + + + this._cache["singleQuotedLiteral"][pos] = { + length: this._pos - pos, + result: result183 + }; + return result183; + }; + + result._parse_singleQuotedCharacter = function(context) { + this._cache["singleQuotedCharacter"] = this._cache["singleQuotedCharacter"] || []; + var cachedResult = this._cache["singleQuotedCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result195 = this._parse_simpleSingleQuotedCharacter(context); + if (result195 !== null) { + var result189 = result195; + } else { + var result194 = this._parse_simpleEscapeSequence(context); + if (result194 !== null) { + var result189 = result194; + } else { + var result193 = this._parse_zeroEscapeSequence(context); + if (result193 !== null) { + var result189 = result193; + } else { + var result192 = this._parse_hexEscapeSequence(context); + if (result192 !== null) { + var result189 = result192; + } else { + var result191 = this._parse_unicodeEscapeSequence(context); + if (result191 !== null) { + var result189 = result191; + } else { + var result190 = this._parse_eolEscapeSequence(context); + if (result190 !== null) { + var result189 = result190; + } else { + var result189 = null;; + }; + }; + }; + }; + }; + } + + + + this._cache["singleQuotedCharacter"][pos] = { + length: this._pos - pos, + result: result189 + }; + return result189; + }; + + result._parse_simpleSingleQuotedCharacter = function(context) { + this._cache["simpleSingleQuotedCharacter"] = this._cache["simpleSingleQuotedCharacter"] || []; + var cachedResult = this._cache["simpleSingleQuotedCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos36 = this._pos; + var savedPos37 = this._pos; + var savedReportMatchFailuresVar3 = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 1) === "'") { + var result203 = "'"; + this._pos += 1; + } else { + var result203 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("'")); + } + } + if (result203 !== null) { + var result200 = result203; + } else { + if (this._input.substr(this._pos, 1) === "\\") { + var result202 = "\\"; + this._pos += 1; + } else { + var result202 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\")); + } + } + if (result202 !== null) { + var result200 = result202; + } else { + var result201 = this._parse_eolChar(context); + if (result201 !== null) { + var result200 = result201; + } else { + var result200 = null;; + }; + }; + } + context.reportMatchFailures = savedReportMatchFailuresVar3; + if (result200 === null) { + var result198 = ''; + } else { + var result198 = null; + this._pos = savedPos37; + } + if (result198 !== null) { + if (this._input.length > this._pos) { + var result199 = this._input[this._pos]; + this._pos++; + } else { + var result199 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result199 !== null) { + var result197 = [result198, result199]; + } else { + var result197 = null; + this._pos = savedPos36; + } + } else { + var result197 = null; + this._pos = savedPos36; + } + var result196 = result197 !== null + ? (function() { return (arguments[1]); }).apply(this, result197) + : null; + + + + this._cache["simpleSingleQuotedCharacter"][pos] = { + length: this._pos - pos, + result: result196 + }; + return result196; + }; + + result._parse_class = function(context) { + this._cache["class"] = this._cache["class"] || []; + var cachedResult = this._cache["class"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + var savedPos38 = this._pos; + if (this._input.substr(this._pos, 1) === "[") { + var result206 = "["; + this._pos += 1; + } else { + var result206 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("[")); + } + } + if (result206 !== null) { + var result207 = []; + var result212 = this._parse_classCharacterRange(context); + if (result212 !== null) { + var result210 = result212; + } else { + var result211 = this._parse_classCharacter(context); + if (result211 !== null) { + var result210 = result211; + } else { + var result210 = null;; + }; + } + while (result210 !== null) { + result207.push(result210); + var result212 = this._parse_classCharacterRange(context); + if (result212 !== null) { + var result210 = result212; + } else { + var result211 = this._parse_classCharacter(context); + if (result211 !== null) { + var result210 = result211; + } else { + var result210 = null;; + }; + } + } + if (result207 !== null) { + if (this._input.substr(this._pos, 1) === "]") { + var result208 = "]"; + this._pos += 1; + } else { + var result208 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("]")); + } + } + if (result208 !== null) { + var result209 = this._parse___(context); + if (result209 !== null) { + var result205 = [result206, result207, result208, result209]; + } else { + var result205 = null; + this._pos = savedPos38; + } + } else { + var result205 = null; + this._pos = savedPos38; + } + } else { + var result205 = null; + this._pos = savedPos38; + } + } else { + var result205 = null; + this._pos = savedPos38; + } + var result204 = result205 !== null + ? (function() { + return (arguments[1]).join(""); + }).apply(this, result205) + : null; + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result204 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("character class")); + } + + this._cache["class"][pos] = { + length: this._pos - pos, + result: result204 + }; + return result204; + }; + + result._parse_classCharacterRange = function(context) { + this._cache["classCharacterRange"] = this._cache["classCharacterRange"] || []; + var cachedResult = this._cache["classCharacterRange"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos39 = this._pos; + var result215 = this._parse_bracketDelimitedCharacter(context); + if (result215 !== null) { + if (this._input.substr(this._pos, 1) === "-") { + var result216 = "-"; + this._pos += 1; + } else { + var result216 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("-")); + } + } + if (result216 !== null) { + var result217 = this._parse_bracketDelimitedCharacter(context); + if (result217 !== null) { + var result214 = [result215, result216, result217]; + } else { + var result214 = null; + this._pos = savedPos39; + } + } else { + var result214 = null; + this._pos = savedPos39; + } + } else { + var result214 = null; + this._pos = savedPos39; + } + var result213 = result214 !== null + ? (function() { + var beginCharCode = (arguments[0]).charCodeAt(0); + var endCharCode = (arguments[2]).charCodeAt(0); + if (beginCharCode > endCharCode) { + throw new PEG.Parser.SyntaxError( + "Invalid character range: " + (arguments[0]) + "-" + (arguments[2]) + "." + ); + } + + var result = ""; + for (var charCode = beginCharCode; charCode <= endCharCode; charCode++) { + result += String.fromCharCode(charCode); + } + return result; + }).apply(this, result214) + : null; + + + + this._cache["classCharacterRange"][pos] = { + length: this._pos - pos, + result: result213 + }; + return result213; + }; + + result._parse_classCharacter = function(context) { + this._cache["classCharacter"] = this._cache["classCharacter"] || []; + var cachedResult = this._cache["classCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result218 = this._parse_bracketDelimitedCharacter(context); + + + + this._cache["classCharacter"][pos] = { + length: this._pos - pos, + result: result218 + }; + return result218; + }; + + result._parse_bracketDelimitedCharacter = function(context) { + this._cache["bracketDelimitedCharacter"] = this._cache["bracketDelimitedCharacter"] || []; + var cachedResult = this._cache["bracketDelimitedCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result225 = this._parse_simpleBracketDelimitedCharacter(context); + if (result225 !== null) { + var result219 = result225; + } else { + var result224 = this._parse_simpleEscapeSequence(context); + if (result224 !== null) { + var result219 = result224; + } else { + var result223 = this._parse_zeroEscapeSequence(context); + if (result223 !== null) { + var result219 = result223; + } else { + var result222 = this._parse_hexEscapeSequence(context); + if (result222 !== null) { + var result219 = result222; + } else { + var result221 = this._parse_unicodeEscapeSequence(context); + if (result221 !== null) { + var result219 = result221; + } else { + var result220 = this._parse_eolEscapeSequence(context); + if (result220 !== null) { + var result219 = result220; + } else { + var result219 = null;; + }; + }; + }; + }; + }; + } + + + + this._cache["bracketDelimitedCharacter"][pos] = { + length: this._pos - pos, + result: result219 + }; + return result219; + }; + + result._parse_simpleBracketDelimitedCharacter = function(context) { + this._cache["simpleBracketDelimitedCharacter"] = this._cache["simpleBracketDelimitedCharacter"] || []; + var cachedResult = this._cache["simpleBracketDelimitedCharacter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos40 = this._pos; + var savedPos41 = this._pos; + var savedReportMatchFailuresVar4 = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 1) === "]") { + var result233 = "]"; + this._pos += 1; + } else { + var result233 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("]")); + } + } + if (result233 !== null) { + var result230 = result233; + } else { + if (this._input.substr(this._pos, 1) === "\\") { + var result232 = "\\"; + this._pos += 1; + } else { + var result232 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\")); + } + } + if (result232 !== null) { + var result230 = result232; + } else { + var result231 = this._parse_eolChar(context); + if (result231 !== null) { + var result230 = result231; + } else { + var result230 = null;; + }; + }; + } + context.reportMatchFailures = savedReportMatchFailuresVar4; + if (result230 === null) { + var result228 = ''; + } else { + var result228 = null; + this._pos = savedPos41; + } + if (result228 !== null) { + if (this._input.length > this._pos) { + var result229 = this._input[this._pos]; + this._pos++; + } else { + var result229 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result229 !== null) { + var result227 = [result228, result229]; + } else { + var result227 = null; + this._pos = savedPos40; + } + } else { + var result227 = null; + this._pos = savedPos40; + } + var result226 = result227 !== null + ? (function() { return (arguments[1]); }).apply(this, result227) + : null; + + + + this._cache["simpleBracketDelimitedCharacter"][pos] = { + length: this._pos - pos, + result: result226 + }; + return result226; + }; + + result._parse_simpleEscapeSequence = function(context) { + this._cache["simpleEscapeSequence"] = this._cache["simpleEscapeSequence"] || []; + var cachedResult = this._cache["simpleEscapeSequence"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos42 = this._pos; + if (this._input.substr(this._pos, 1) === "\\") { + var result236 = "\\"; + this._pos += 1; + } else { + var result236 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\")); + } + } + if (result236 !== null) { + var savedPos43 = this._pos; + var savedReportMatchFailuresVar5 = context.reportMatchFailures; + context.reportMatchFailures = false; + var result243 = this._parse_digit(context); + if (result243 !== null) { + var result239 = result243; + } else { + if (this._input.substr(this._pos, 1) === "x") { + var result242 = "x"; + this._pos += 1; + } else { + var result242 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("x")); + } + } + if (result242 !== null) { + var result239 = result242; + } else { + if (this._input.substr(this._pos, 1) === "u") { + var result241 = "u"; + this._pos += 1; + } else { + var result241 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("u")); + } + } + if (result241 !== null) { + var result239 = result241; + } else { + var result240 = this._parse_eolChar(context); + if (result240 !== null) { + var result239 = result240; + } else { + var result239 = null;; + }; + }; + }; + } + context.reportMatchFailures = savedReportMatchFailuresVar5; + if (result239 === null) { + var result237 = ''; + } else { + var result237 = null; + this._pos = savedPos43; + } + if (result237 !== null) { + if (this._input.length > this._pos) { + var result238 = this._input[this._pos]; + this._pos++; + } else { + var result238 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result238 !== null) { + var result235 = [result236, result237, result238]; + } else { + var result235 = null; + this._pos = savedPos42; + } + } else { + var result235 = null; + this._pos = savedPos42; + } + } else { + var result235 = null; + this._pos = savedPos42; + } + var result234 = result235 !== null + ? (function() { + return (arguments[2]) + .replace("b", "\b") + .replace("f", "\f") + .replace("n", "\n") + .replace("r", "\r") + .replace("t", "\t") + .replace("v", "\v") + }).apply(this, result235) + : null; + + + + this._cache["simpleEscapeSequence"][pos] = { + length: this._pos - pos, + result: result234 + }; + return result234; + }; + + result._parse_zeroEscapeSequence = function(context) { + this._cache["zeroEscapeSequence"] = this._cache["zeroEscapeSequence"] || []; + var cachedResult = this._cache["zeroEscapeSequence"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos44 = this._pos; + if (this._input.substr(this._pos, 2) === "\\0") { + var result246 = "\\0"; + this._pos += 2; + } else { + var result246 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\0")); + } + } + if (result246 !== null) { + var savedPos45 = this._pos; + var savedReportMatchFailuresVar6 = context.reportMatchFailures; + context.reportMatchFailures = false; + var result248 = this._parse_digit(context); + context.reportMatchFailures = savedReportMatchFailuresVar6; + if (result248 === null) { + var result247 = ''; + } else { + var result247 = null; + this._pos = savedPos45; + } + if (result247 !== null) { + var result245 = [result246, result247]; + } else { + var result245 = null; + this._pos = savedPos44; + } + } else { + var result245 = null; + this._pos = savedPos44; + } + var result244 = result245 !== null + ? (function() { return "\0"; }).apply(this, result245) + : null; + + + + this._cache["zeroEscapeSequence"][pos] = { + length: this._pos - pos, + result: result244 + }; + return result244; + }; + + result._parse_hexEscapeSequence = function(context) { + this._cache["hexEscapeSequence"] = this._cache["hexEscapeSequence"] || []; + var cachedResult = this._cache["hexEscapeSequence"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos46 = this._pos; + if (this._input.substr(this._pos, 2) === "\\x") { + var result251 = "\\x"; + this._pos += 2; + } else { + var result251 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\x")); + } + } + if (result251 !== null) { + var result252 = this._parse_hexDigit(context); + if (result252 !== null) { + var result253 = this._parse_hexDigit(context); + if (result253 !== null) { + var result250 = [result251, result252, result253]; + } else { + var result250 = null; + this._pos = savedPos46; + } + } else { + var result250 = null; + this._pos = savedPos46; + } + } else { + var result250 = null; + this._pos = savedPos46; + } + var result249 = result250 !== null + ? (function() { + return String.fromCharCode(parseInt("0x" + (arguments[1]) + (arguments[2]))); + }).apply(this, result250) + : null; + + + + this._cache["hexEscapeSequence"][pos] = { + length: this._pos - pos, + result: result249 + }; + return result249; + }; + + result._parse_unicodeEscapeSequence = function(context) { + this._cache["unicodeEscapeSequence"] = this._cache["unicodeEscapeSequence"] || []; + var cachedResult = this._cache["unicodeEscapeSequence"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos47 = this._pos; + if (this._input.substr(this._pos, 2) === "\\u") { + var result256 = "\\u"; + this._pos += 2; + } else { + var result256 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\u")); + } + } + if (result256 !== null) { + var result257 = this._parse_hexDigit(context); + if (result257 !== null) { + var result258 = this._parse_hexDigit(context); + if (result258 !== null) { + var result259 = this._parse_hexDigit(context); + if (result259 !== null) { + var result260 = this._parse_hexDigit(context); + if (result260 !== null) { + var result255 = [result256, result257, result258, result259, result260]; + } else { + var result255 = null; + this._pos = savedPos47; + } + } else { + var result255 = null; + this._pos = savedPos47; + } + } else { + var result255 = null; + this._pos = savedPos47; + } + } else { + var result255 = null; + this._pos = savedPos47; + } + } else { + var result255 = null; + this._pos = savedPos47; + } + var result254 = result255 !== null + ? (function() { + return String.fromCharCode(parseInt("0x" + (arguments[1]) + (arguments[2]) + (arguments[3]) + (arguments[4]))); + }).apply(this, result255) + : null; + + + + this._cache["unicodeEscapeSequence"][pos] = { + length: this._pos - pos, + result: result254 + }; + return result254; + }; + + result._parse_eolEscapeSequence = function(context) { + this._cache["eolEscapeSequence"] = this._cache["eolEscapeSequence"] || []; + var cachedResult = this._cache["eolEscapeSequence"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos48 = this._pos; + if (this._input.substr(this._pos, 1) === "\\") { + var result263 = "\\"; + this._pos += 1; + } else { + var result263 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\")); + } + } + if (result263 !== null) { + var result264 = this._parse_eol(context); + if (result264 !== null) { + var result262 = [result263, result264]; + } else { + var result262 = null; + this._pos = savedPos48; + } + } else { + var result262 = null; + this._pos = savedPos48; + } + var result261 = result262 !== null + ? (function() { return (arguments[1]); }).apply(this, result262) + : null; + + + + this._cache["eolEscapeSequence"][pos] = { + length: this._pos - pos, + result: result261 + }; + return result261; + }; + + result._parse_digit = function(context) { + this._cache["digit"] = this._cache["digit"] || []; + var cachedResult = this._cache["digit"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + if (this._input.substr(this._pos, 1) === "0") { + var result275 = "0"; + this._pos += 1; + } else { + var result275 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("0")); + } + } + if (result275 !== null) { + var result265 = result275; + } else { + if (this._input.substr(this._pos, 1) === "1") { + var result274 = "1"; + this._pos += 1; + } else { + var result274 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("1")); + } + } + if (result274 !== null) { + var result265 = result274; + } else { + if (this._input.substr(this._pos, 1) === "2") { + var result273 = "2"; + this._pos += 1; + } else { + var result273 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("2")); + } + } + if (result273 !== null) { + var result265 = result273; + } else { + if (this._input.substr(this._pos, 1) === "3") { + var result272 = "3"; + this._pos += 1; + } else { + var result272 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("3")); + } + } + if (result272 !== null) { + var result265 = result272; + } else { + if (this._input.substr(this._pos, 1) === "4") { + var result271 = "4"; + this._pos += 1; + } else { + var result271 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("4")); + } + } + if (result271 !== null) { + var result265 = result271; + } else { + if (this._input.substr(this._pos, 1) === "5") { + var result270 = "5"; + this._pos += 1; + } else { + var result270 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("5")); + } + } + if (result270 !== null) { + var result265 = result270; + } else { + if (this._input.substr(this._pos, 1) === "6") { + var result269 = "6"; + this._pos += 1; + } else { + var result269 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("6")); + } + } + if (result269 !== null) { + var result265 = result269; + } else { + if (this._input.substr(this._pos, 1) === "7") { + var result268 = "7"; + this._pos += 1; + } else { + var result268 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("7")); + } + } + if (result268 !== null) { + var result265 = result268; + } else { + if (this._input.substr(this._pos, 1) === "8") { + var result267 = "8"; + this._pos += 1; + } else { + var result267 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("8")); + } + } + if (result267 !== null) { + var result265 = result267; + } else { + if (this._input.substr(this._pos, 1) === "9") { + var result266 = "9"; + this._pos += 1; + } else { + var result266 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("9")); + } + } + if (result266 !== null) { + var result265 = result266; + } else { + var result265 = null;; + }; + }; + }; + }; + }; + }; + }; + }; + }; + } + + + + this._cache["digit"][pos] = { + length: this._pos - pos, + result: result265 + }; + return result265; + }; + + result._parse_hexDigit = function(context) { + this._cache["hexDigit"] = this._cache["hexDigit"] || []; + var cachedResult = this._cache["hexDigit"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + if (this._input.substr(this._pos, 1) === "0") { + var result298 = "0"; + this._pos += 1; + } else { + var result298 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("0")); + } + } + if (result298 !== null) { + var result276 = result298; + } else { + if (this._input.substr(this._pos, 1) === "1") { + var result297 = "1"; + this._pos += 1; + } else { + var result297 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("1")); + } + } + if (result297 !== null) { + var result276 = result297; + } else { + if (this._input.substr(this._pos, 1) === "2") { + var result296 = "2"; + this._pos += 1; + } else { + var result296 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("2")); + } + } + if (result296 !== null) { + var result276 = result296; + } else { + if (this._input.substr(this._pos, 1) === "3") { + var result295 = "3"; + this._pos += 1; + } else { + var result295 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("3")); + } + } + if (result295 !== null) { + var result276 = result295; + } else { + if (this._input.substr(this._pos, 1) === "4") { + var result294 = "4"; + this._pos += 1; + } else { + var result294 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("4")); + } + } + if (result294 !== null) { + var result276 = result294; + } else { + if (this._input.substr(this._pos, 1) === "5") { + var result293 = "5"; + this._pos += 1; + } else { + var result293 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("5")); + } + } + if (result293 !== null) { + var result276 = result293; + } else { + if (this._input.substr(this._pos, 1) === "6") { + var result292 = "6"; + this._pos += 1; + } else { + var result292 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("6")); + } + } + if (result292 !== null) { + var result276 = result292; + } else { + if (this._input.substr(this._pos, 1) === "7") { + var result291 = "7"; + this._pos += 1; + } else { + var result291 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("7")); + } + } + if (result291 !== null) { + var result276 = result291; + } else { + if (this._input.substr(this._pos, 1) === "8") { + var result290 = "8"; + this._pos += 1; + } else { + var result290 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("8")); + } + } + if (result290 !== null) { + var result276 = result290; + } else { + if (this._input.substr(this._pos, 1) === "9") { + var result289 = "9"; + this._pos += 1; + } else { + var result289 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("9")); + } + } + if (result289 !== null) { + var result276 = result289; + } else { + if (this._input.substr(this._pos, 1) === "a") { + var result288 = "a"; + this._pos += 1; + } else { + var result288 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("a")); + } + } + if (result288 !== null) { + var result276 = result288; + } else { + if (this._input.substr(this._pos, 1) === "b") { + var result287 = "b"; + this._pos += 1; + } else { + var result287 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("b")); + } + } + if (result287 !== null) { + var result276 = result287; + } else { + if (this._input.substr(this._pos, 1) === "c") { + var result286 = "c"; + this._pos += 1; + } else { + var result286 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("c")); + } + } + if (result286 !== null) { + var result276 = result286; + } else { + if (this._input.substr(this._pos, 1) === "d") { + var result285 = "d"; + this._pos += 1; + } else { + var result285 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("d")); + } + } + if (result285 !== null) { + var result276 = result285; + } else { + if (this._input.substr(this._pos, 1) === "e") { + var result284 = "e"; + this._pos += 1; + } else { + var result284 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("e")); + } + } + if (result284 !== null) { + var result276 = result284; + } else { + if (this._input.substr(this._pos, 1) === "f") { + var result283 = "f"; + this._pos += 1; + } else { + var result283 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("f")); + } + } + if (result283 !== null) { + var result276 = result283; + } else { + if (this._input.substr(this._pos, 1) === "A") { + var result282 = "A"; + this._pos += 1; + } else { + var result282 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("A")); + } + } + if (result282 !== null) { + var result276 = result282; + } else { + if (this._input.substr(this._pos, 1) === "B") { + var result281 = "B"; + this._pos += 1; + } else { + var result281 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("B")); + } + } + if (result281 !== null) { + var result276 = result281; + } else { + if (this._input.substr(this._pos, 1) === "C") { + var result280 = "C"; + this._pos += 1; + } else { + var result280 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("C")); + } + } + if (result280 !== null) { + var result276 = result280; + } else { + if (this._input.substr(this._pos, 1) === "D") { + var result279 = "D"; + this._pos += 1; + } else { + var result279 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("D")); + } + } + if (result279 !== null) { + var result276 = result279; + } else { + if (this._input.substr(this._pos, 1) === "E") { + var result278 = "E"; + this._pos += 1; + } else { + var result278 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("E")); + } + } + if (result278 !== null) { + var result276 = result278; + } else { + if (this._input.substr(this._pos, 1) === "F") { + var result277 = "F"; + this._pos += 1; + } else { + var result277 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("F")); + } + } + if (result277 !== null) { + var result276 = result277; + } else { + var result276 = null;; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + } + + + + this._cache["hexDigit"][pos] = { + length: this._pos - pos, + result: result276 + }; + return result276; + }; + + result._parse_letter = function(context) { + this._cache["letter"] = this._cache["letter"] || []; + var cachedResult = this._cache["letter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result301 = this._parse_lowerCaseLetter(context); + if (result301 !== null) { + var result299 = result301; + } else { + var result300 = this._parse_upperCaseLetter(context); + if (result300 !== null) { + var result299 = result300; + } else { + var result299 = null;; + }; + } + + + + this._cache["letter"][pos] = { + length: this._pos - pos, + result: result299 + }; + return result299; + }; + + result._parse_lowerCaseLetter = function(context) { + this._cache["lowerCaseLetter"] = this._cache["lowerCaseLetter"] || []; + var cachedResult = this._cache["lowerCaseLetter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + if (this._input.substr(this._pos, 1) === "a") { + var result328 = "a"; + this._pos += 1; + } else { + var result328 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("a")); + } + } + if (result328 !== null) { + var result302 = result328; + } else { + if (this._input.substr(this._pos, 1) === "b") { + var result327 = "b"; + this._pos += 1; + } else { + var result327 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("b")); + } + } + if (result327 !== null) { + var result302 = result327; + } else { + if (this._input.substr(this._pos, 1) === "c") { + var result326 = "c"; + this._pos += 1; + } else { + var result326 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("c")); + } + } + if (result326 !== null) { + var result302 = result326; + } else { + if (this._input.substr(this._pos, 1) === "d") { + var result325 = "d"; + this._pos += 1; + } else { + var result325 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("d")); + } + } + if (result325 !== null) { + var result302 = result325; + } else { + if (this._input.substr(this._pos, 1) === "e") { + var result324 = "e"; + this._pos += 1; + } else { + var result324 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("e")); + } + } + if (result324 !== null) { + var result302 = result324; + } else { + if (this._input.substr(this._pos, 1) === "f") { + var result323 = "f"; + this._pos += 1; + } else { + var result323 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("f")); + } + } + if (result323 !== null) { + var result302 = result323; + } else { + if (this._input.substr(this._pos, 1) === "g") { + var result322 = "g"; + this._pos += 1; + } else { + var result322 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("g")); + } + } + if (result322 !== null) { + var result302 = result322; + } else { + if (this._input.substr(this._pos, 1) === "h") { + var result321 = "h"; + this._pos += 1; + } else { + var result321 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("h")); + } + } + if (result321 !== null) { + var result302 = result321; + } else { + if (this._input.substr(this._pos, 1) === "i") { + var result320 = "i"; + this._pos += 1; + } else { + var result320 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("i")); + } + } + if (result320 !== null) { + var result302 = result320; + } else { + if (this._input.substr(this._pos, 1) === "j") { + var result319 = "j"; + this._pos += 1; + } else { + var result319 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("j")); + } + } + if (result319 !== null) { + var result302 = result319; + } else { + if (this._input.substr(this._pos, 1) === "k") { + var result318 = "k"; + this._pos += 1; + } else { + var result318 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("k")); + } + } + if (result318 !== null) { + var result302 = result318; + } else { + if (this._input.substr(this._pos, 1) === "l") { + var result317 = "l"; + this._pos += 1; + } else { + var result317 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("l")); + } + } + if (result317 !== null) { + var result302 = result317; + } else { + if (this._input.substr(this._pos, 1) === "m") { + var result316 = "m"; + this._pos += 1; + } else { + var result316 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("m")); + } + } + if (result316 !== null) { + var result302 = result316; + } else { + if (this._input.substr(this._pos, 1) === "n") { + var result315 = "n"; + this._pos += 1; + } else { + var result315 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("n")); + } + } + if (result315 !== null) { + var result302 = result315; + } else { + if (this._input.substr(this._pos, 1) === "o") { + var result314 = "o"; + this._pos += 1; + } else { + var result314 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("o")); + } + } + if (result314 !== null) { + var result302 = result314; + } else { + if (this._input.substr(this._pos, 1) === "p") { + var result313 = "p"; + this._pos += 1; + } else { + var result313 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("p")); + } + } + if (result313 !== null) { + var result302 = result313; + } else { + if (this._input.substr(this._pos, 1) === "q") { + var result312 = "q"; + this._pos += 1; + } else { + var result312 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("q")); + } + } + if (result312 !== null) { + var result302 = result312; + } else { + if (this._input.substr(this._pos, 1) === "r") { + var result311 = "r"; + this._pos += 1; + } else { + var result311 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("r")); + } + } + if (result311 !== null) { + var result302 = result311; + } else { + if (this._input.substr(this._pos, 1) === "s") { + var result310 = "s"; + this._pos += 1; + } else { + var result310 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("s")); + } + } + if (result310 !== null) { + var result302 = result310; + } else { + if (this._input.substr(this._pos, 1) === "t") { + var result309 = "t"; + this._pos += 1; + } else { + var result309 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("t")); + } + } + if (result309 !== null) { + var result302 = result309; + } else { + if (this._input.substr(this._pos, 1) === "u") { + var result308 = "u"; + this._pos += 1; + } else { + var result308 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("u")); + } + } + if (result308 !== null) { + var result302 = result308; + } else { + if (this._input.substr(this._pos, 1) === "v") { + var result307 = "v"; + this._pos += 1; + } else { + var result307 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("v")); + } + } + if (result307 !== null) { + var result302 = result307; + } else { + if (this._input.substr(this._pos, 1) === "w") { + var result306 = "w"; + this._pos += 1; + } else { + var result306 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("w")); + } + } + if (result306 !== null) { + var result302 = result306; + } else { + if (this._input.substr(this._pos, 1) === "x") { + var result305 = "x"; + this._pos += 1; + } else { + var result305 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("x")); + } + } + if (result305 !== null) { + var result302 = result305; + } else { + if (this._input.substr(this._pos, 1) === "y") { + var result304 = "y"; + this._pos += 1; + } else { + var result304 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("y")); + } + } + if (result304 !== null) { + var result302 = result304; + } else { + if (this._input.substr(this._pos, 1) === "z") { + var result303 = "z"; + this._pos += 1; + } else { + var result303 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("z")); + } + } + if (result303 !== null) { + var result302 = result303; + } else { + var result302 = null;; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + } + + + + this._cache["lowerCaseLetter"][pos] = { + length: this._pos - pos, + result: result302 + }; + return result302; + }; + + result._parse_upperCaseLetter = function(context) { + this._cache["upperCaseLetter"] = this._cache["upperCaseLetter"] || []; + var cachedResult = this._cache["upperCaseLetter"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + if (this._input.substr(this._pos, 1) === "A") { + var result355 = "A"; + this._pos += 1; + } else { + var result355 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("A")); + } + } + if (result355 !== null) { + var result329 = result355; + } else { + if (this._input.substr(this._pos, 1) === "B") { + var result354 = "B"; + this._pos += 1; + } else { + var result354 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("B")); + } + } + if (result354 !== null) { + var result329 = result354; + } else { + if (this._input.substr(this._pos, 1) === "C") { + var result353 = "C"; + this._pos += 1; + } else { + var result353 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("C")); + } + } + if (result353 !== null) { + var result329 = result353; + } else { + if (this._input.substr(this._pos, 1) === "D") { + var result352 = "D"; + this._pos += 1; + } else { + var result352 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("D")); + } + } + if (result352 !== null) { + var result329 = result352; + } else { + if (this._input.substr(this._pos, 1) === "E") { + var result351 = "E"; + this._pos += 1; + } else { + var result351 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("E")); + } + } + if (result351 !== null) { + var result329 = result351; + } else { + if (this._input.substr(this._pos, 1) === "F") { + var result350 = "F"; + this._pos += 1; + } else { + var result350 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("F")); + } + } + if (result350 !== null) { + var result329 = result350; + } else { + if (this._input.substr(this._pos, 1) === "G") { + var result349 = "G"; + this._pos += 1; + } else { + var result349 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("G")); + } + } + if (result349 !== null) { + var result329 = result349; + } else { + if (this._input.substr(this._pos, 1) === "H") { + var result348 = "H"; + this._pos += 1; + } else { + var result348 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("H")); + } + } + if (result348 !== null) { + var result329 = result348; + } else { + if (this._input.substr(this._pos, 1) === "I") { + var result347 = "I"; + this._pos += 1; + } else { + var result347 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("I")); + } + } + if (result347 !== null) { + var result329 = result347; + } else { + if (this._input.substr(this._pos, 1) === "J") { + var result346 = "J"; + this._pos += 1; + } else { + var result346 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("J")); + } + } + if (result346 !== null) { + var result329 = result346; + } else { + if (this._input.substr(this._pos, 1) === "K") { + var result345 = "K"; + this._pos += 1; + } else { + var result345 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("K")); + } + } + if (result345 !== null) { + var result329 = result345; + } else { + if (this._input.substr(this._pos, 1) === "L") { + var result344 = "L"; + this._pos += 1; + } else { + var result344 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("L")); + } + } + if (result344 !== null) { + var result329 = result344; + } else { + if (this._input.substr(this._pos, 1) === "M") { + var result343 = "M"; + this._pos += 1; + } else { + var result343 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("M")); + } + } + if (result343 !== null) { + var result329 = result343; + } else { + if (this._input.substr(this._pos, 1) === "N") { + var result342 = "N"; + this._pos += 1; + } else { + var result342 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("N")); + } + } + if (result342 !== null) { + var result329 = result342; + } else { + if (this._input.substr(this._pos, 1) === "O") { + var result341 = "O"; + this._pos += 1; + } else { + var result341 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("O")); + } + } + if (result341 !== null) { + var result329 = result341; + } else { + if (this._input.substr(this._pos, 1) === "P") { + var result340 = "P"; + this._pos += 1; + } else { + var result340 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("P")); + } + } + if (result340 !== null) { + var result329 = result340; + } else { + if (this._input.substr(this._pos, 1) === "Q") { + var result339 = "Q"; + this._pos += 1; + } else { + var result339 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("Q")); + } + } + if (result339 !== null) { + var result329 = result339; + } else { + if (this._input.substr(this._pos, 1) === "R") { + var result338 = "R"; + this._pos += 1; + } else { + var result338 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("R")); + } + } + if (result338 !== null) { + var result329 = result338; + } else { + if (this._input.substr(this._pos, 1) === "S") { + var result337 = "S"; + this._pos += 1; + } else { + var result337 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("S")); + } + } + if (result337 !== null) { + var result329 = result337; + } else { + if (this._input.substr(this._pos, 1) === "T") { + var result336 = "T"; + this._pos += 1; + } else { + var result336 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("T")); + } + } + if (result336 !== null) { + var result329 = result336; + } else { + if (this._input.substr(this._pos, 1) === "U") { + var result335 = "U"; + this._pos += 1; + } else { + var result335 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("U")); + } + } + if (result335 !== null) { + var result329 = result335; + } else { + if (this._input.substr(this._pos, 1) === "V") { + var result334 = "V"; + this._pos += 1; + } else { + var result334 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("V")); + } + } + if (result334 !== null) { + var result329 = result334; + } else { + if (this._input.substr(this._pos, 1) === "W") { + var result333 = "W"; + this._pos += 1; + } else { + var result333 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("W")); + } + } + if (result333 !== null) { + var result329 = result333; + } else { + if (this._input.substr(this._pos, 1) === "X") { + var result332 = "X"; + this._pos += 1; + } else { + var result332 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("X")); + } + } + if (result332 !== null) { + var result329 = result332; + } else { + if (this._input.substr(this._pos, 1) === "Y") { + var result331 = "Y"; + this._pos += 1; + } else { + var result331 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("Y")); + } + } + if (result331 !== null) { + var result329 = result331; + } else { + if (this._input.substr(this._pos, 1) === "Z") { + var result330 = "Z"; + this._pos += 1; + } else { + var result330 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("Z")); + } + } + if (result330 !== null) { + var result329 = result330; + } else { + var result329 = null;; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + } + + + + this._cache["upperCaseLetter"][pos] = { + length: this._pos - pos, + result: result329 + }; + return result329; + }; + + result._parse___ = function(context) { + this._cache["__"] = this._cache["__"] || []; + var cachedResult = this._cache["__"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var result356 = []; + var result360 = this._parse_whitespace(context); + if (result360 !== null) { + var result357 = result360; + } else { + var result359 = this._parse_eol(context); + if (result359 !== null) { + var result357 = result359; + } else { + var result358 = this._parse_comment(context); + if (result358 !== null) { + var result357 = result358; + } else { + var result357 = null;; + }; + }; + } + while (result357 !== null) { + result356.push(result357); + var result360 = this._parse_whitespace(context); + if (result360 !== null) { + var result357 = result360; + } else { + var result359 = this._parse_eol(context); + if (result359 !== null) { + var result357 = result359; + } else { + var result358 = this._parse_comment(context); + if (result358 !== null) { + var result357 = result358; + } else { + var result357 = null;; + }; + }; + } + } + + + + this._cache["__"][pos] = { + length: this._pos - pos, + result: result356 + }; + return result356; + }; + + result._parse_comment = function(context) { + this._cache["comment"] = this._cache["comment"] || []; + var cachedResult = this._cache["comment"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + var result363 = this._parse_singleLineComment(context); + if (result363 !== null) { + var result361 = result363; + } else { + var result362 = this._parse_multiLineComment(context); + if (result362 !== null) { + var result361 = result362; + } else { + var result361 = null;; + }; + } + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result361 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("comment")); + } + + this._cache["comment"][pos] = { + length: this._pos - pos, + result: result361 + }; + return result361; + }; + + result._parse_singleLineComment = function(context) { + this._cache["singleLineComment"] = this._cache["singleLineComment"] || []; + var cachedResult = this._cache["singleLineComment"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos49 = this._pos; + if (this._input.substr(this._pos, 2) === "//") { + var result365 = "//"; + this._pos += 2; + } else { + var result365 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("//")); + } + } + if (result365 !== null) { + var result366 = []; + var savedPos50 = this._pos; + var savedPos51 = this._pos; + var savedReportMatchFailuresVar7 = context.reportMatchFailures; + context.reportMatchFailures = false; + var result370 = this._parse_eolChar(context); + context.reportMatchFailures = savedReportMatchFailuresVar7; + if (result370 === null) { + var result368 = ''; + } else { + var result368 = null; + this._pos = savedPos51; + } + if (result368 !== null) { + if (this._input.length > this._pos) { + var result369 = this._input[this._pos]; + this._pos++; + } else { + var result369 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result369 !== null) { + var result367 = [result368, result369]; + } else { + var result367 = null; + this._pos = savedPos50; + } + } else { + var result367 = null; + this._pos = savedPos50; + } + while (result367 !== null) { + result366.push(result367); + var savedPos50 = this._pos; + var savedPos51 = this._pos; + var savedReportMatchFailuresVar7 = context.reportMatchFailures; + context.reportMatchFailures = false; + var result370 = this._parse_eolChar(context); + context.reportMatchFailures = savedReportMatchFailuresVar7; + if (result370 === null) { + var result368 = ''; + } else { + var result368 = null; + this._pos = savedPos51; + } + if (result368 !== null) { + if (this._input.length > this._pos) { + var result369 = this._input[this._pos]; + this._pos++; + } else { + var result369 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result369 !== null) { + var result367 = [result368, result369]; + } else { + var result367 = null; + this._pos = savedPos50; + } + } else { + var result367 = null; + this._pos = savedPos50; + } + } + if (result366 !== null) { + var result364 = [result365, result366]; + } else { + var result364 = null; + this._pos = savedPos49; + } + } else { + var result364 = null; + this._pos = savedPos49; + } + + + + this._cache["singleLineComment"][pos] = { + length: this._pos - pos, + result: result364 + }; + return result364; + }; + + result._parse_multiLineComment = function(context) { + this._cache["multiLineComment"] = this._cache["multiLineComment"] || []; + var cachedResult = this._cache["multiLineComment"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + var savedPos52 = this._pos; + if (this._input.substr(this._pos, 2) === "/*") { + var result372 = "/*"; + this._pos += 2; + } else { + var result372 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("/*")); + } + } + if (result372 !== null) { + var result373 = []; + var savedPos53 = this._pos; + var savedPos54 = this._pos; + var savedReportMatchFailuresVar8 = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 2) === "*/") { + var result378 = "*/"; + this._pos += 2; + } else { + var result378 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("*/")); + } + } + context.reportMatchFailures = savedReportMatchFailuresVar8; + if (result378 === null) { + var result376 = ''; + } else { + var result376 = null; + this._pos = savedPos54; + } + if (result376 !== null) { + if (this._input.length > this._pos) { + var result377 = this._input[this._pos]; + this._pos++; + } else { + var result377 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result377 !== null) { + var result375 = [result376, result377]; + } else { + var result375 = null; + this._pos = savedPos53; + } + } else { + var result375 = null; + this._pos = savedPos53; + } + while (result375 !== null) { + result373.push(result375); + var savedPos53 = this._pos; + var savedPos54 = this._pos; + var savedReportMatchFailuresVar8 = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 2) === "*/") { + var result378 = "*/"; + this._pos += 2; + } else { + var result378 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("*/")); + } + } + context.reportMatchFailures = savedReportMatchFailuresVar8; + if (result378 === null) { + var result376 = ''; + } else { + var result376 = null; + this._pos = savedPos54; + } + if (result376 !== null) { + if (this._input.length > this._pos) { + var result377 = this._input[this._pos]; + this._pos++; + } else { + var result377 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.AnyMatchFailure()); + } + } + if (result377 !== null) { + var result375 = [result376, result377]; + } else { + var result375 = null; + this._pos = savedPos53; + } + } else { + var result375 = null; + this._pos = savedPos53; + } + } + if (result373 !== null) { + if (this._input.substr(this._pos, 2) === "*/") { + var result374 = "*/"; + this._pos += 2; + } else { + var result374 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("*/")); + } + } + if (result374 !== null) { + var result371 = [result372, result373, result374]; + } else { + var result371 = null; + this._pos = savedPos52; + } + } else { + var result371 = null; + this._pos = savedPos52; + } + } else { + var result371 = null; + this._pos = savedPos52; + } + + + + this._cache["multiLineComment"][pos] = { + length: this._pos - pos, + result: result371 + }; + return result371; + }; + + result._parse_eol = function(context) { + this._cache["eol"] = this._cache["eol"] || []; + var cachedResult = this._cache["eol"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 1) === "\n") { + var result384 = "\n"; + this._pos += 1; + } else { + var result384 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\n")); + } + } + if (result384 !== null) { + var result379 = result384; + } else { + if (this._input.substr(this._pos, 2) === "\r\n") { + var result383 = "\r\n"; + this._pos += 2; + } else { + var result383 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\r\n")); + } + } + if (result383 !== null) { + var result379 = result383; + } else { + if (this._input.substr(this._pos, 1) === "\r") { + var result382 = "\r"; + this._pos += 1; + } else { + var result382 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\r")); + } + } + if (result382 !== null) { + var result379 = result382; + } else { + if (this._input.substr(this._pos, 1) === "\u2028") { + var result381 = "\u2028"; + this._pos += 1; + } else { + var result381 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\u2028")); + } + } + if (result381 !== null) { + var result379 = result381; + } else { + if (this._input.substr(this._pos, 1) === "\u2029") { + var result380 = "\u2029"; + this._pos += 1; + } else { + var result380 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\u2029")); + } + } + if (result380 !== null) { + var result379 = result380; + } else { + var result379 = null;; + }; + }; + }; + }; + } + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result379 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("end of line")); + } + + this._cache["eol"][pos] = { + length: this._pos - pos, + result: result379 + }; + return result379; + }; + + result._parse_eolChar = function(context) { + this._cache["eolChar"] = this._cache["eolChar"] || []; + var cachedResult = this._cache["eolChar"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + + if (this._input.substr(this._pos, 1) === "\n") { + var result389 = "\n"; + this._pos += 1; + } else { + var result389 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\n")); + } + } + if (result389 !== null) { + var result385 = result389; + } else { + if (this._input.substr(this._pos, 1) === "\r") { + var result388 = "\r"; + this._pos += 1; + } else { + var result388 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\r")); + } + } + if (result388 !== null) { + var result385 = result388; + } else { + if (this._input.substr(this._pos, 1) === "\u2028") { + var result387 = "\u2028"; + this._pos += 1; + } else { + var result387 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\u2028")); + } + } + if (result387 !== null) { + var result385 = result387; + } else { + if (this._input.substr(this._pos, 1) === "\u2029") { + var result386 = "\u2029"; + this._pos += 1; + } else { + var result386 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("\u2029")); + } + } + if (result386 !== null) { + var result385 = result386; + } else { + var result385 = null;; + }; + }; + }; + } + + + + this._cache["eolChar"][pos] = { + length: this._pos - pos, + result: result385 + }; + return result385; + }; + + result._parse_whitespace = function(context) { + this._cache["whitespace"] = this._cache["whitespace"] || []; + var cachedResult = this._cache["whitespace"][this._pos]; + if (cachedResult !== undefined) { + this._pos += cachedResult.length; + return cachedResult.result; + } + + var pos = this._pos; + + var savedReportMatchFailures = context.reportMatchFailures; + context.reportMatchFailures = false; + if (this._input.substr(this._pos, 1) === " ") { + var result411 = " "; + this._pos += 1; + } else { + var result411 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result411 !== null) { + var result390 = result411; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result410 = " "; + this._pos += 1; + } else { + var result410 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result410 !== null) { + var result390 = result410; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result409 = " "; + this._pos += 1; + } else { + var result409 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result409 !== null) { + var result390 = result409; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result408 = " "; + this._pos += 1; + } else { + var result408 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result408 !== null) { + var result390 = result408; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result407 = " "; + this._pos += 1; + } else { + var result407 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result407 !== null) { + var result390 = result407; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result406 = " "; + this._pos += 1; + } else { + var result406 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result406 !== null) { + var result390 = result406; + } else { + if (this._input.substr(this._pos, 1) === "᠎") { + var result405 = "᠎"; + this._pos += 1; + } else { + var result405 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure("᠎")); + } + } + if (result405 !== null) { + var result390 = result405; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result404 = " "; + this._pos += 1; + } else { + var result404 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result404 !== null) { + var result390 = result404; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result403 = " "; + this._pos += 1; + } else { + var result403 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result403 !== null) { + var result390 = result403; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result402 = " "; + this._pos += 1; + } else { + var result402 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result402 !== null) { + var result390 = result402; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result401 = " "; + this._pos += 1; + } else { + var result401 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result401 !== null) { + var result390 = result401; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result400 = " "; + this._pos += 1; + } else { + var result400 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result400 !== null) { + var result390 = result400; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result399 = " "; + this._pos += 1; + } else { + var result399 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result399 !== null) { + var result390 = result399; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result398 = " "; + this._pos += 1; + } else { + var result398 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result398 !== null) { + var result390 = result398; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result397 = " "; + this._pos += 1; + } else { + var result397 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result397 !== null) { + var result390 = result397; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result396 = " "; + this._pos += 1; + } else { + var result396 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result396 !== null) { + var result390 = result396; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result395 = " "; + this._pos += 1; + } else { + var result395 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result395 !== null) { + var result390 = result395; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result394 = " "; + this._pos += 1; + } else { + var result394 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result394 !== null) { + var result390 = result394; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result393 = " "; + this._pos += 1; + } else { + var result393 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result393 !== null) { + var result390 = result393; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result392 = " "; + this._pos += 1; + } else { + var result392 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result392 !== null) { + var result390 = result392; + } else { + if (this._input.substr(this._pos, 1) === " ") { + var result391 = " "; + this._pos += 1; + } else { + var result391 = null; + if (context.reportMatchFailures) { + this._matchFailed(new PEG.Parser.LiteralMatchFailure(" ")); + } + } + if (result391 !== null) { + var result390 = result391; + } else { + var result390 = null;; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + } + context.reportMatchFailures = savedReportMatchFailures; + if (context.reportMatchFailures && result390 === null) { + this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("whitespace")); + } + + this._cache["whitespace"][pos] = { + length: this._pos - pos, + result: result390 + }; + return result390; + }; + + return result; +})(); diff --git a/lib/metagrammar.pegjs b/lib/metagrammar.pegjs new file mode 100644 index 0000000..47d4229 --- /dev/null +++ b/lib/metagrammar.pegjs @@ -0,0 +1,217 @@ +grammar: __ rule+ { + var result = {}; + for (var i = 0; i < $2.length; i++) { result[$2[i].getName()] = $2[i]; } + return result; +} + +rule: identifier (literal / "") colon expression { + return new PEG.Grammar.Rule($1, $2 !== "" ? $2 : null, $4); +} + +expression: choice + +choice: sequence (slash sequence)* { + return $2.length > 0 + ? new PEG.Grammar.Choice([$1].concat(PEG.ArrayUtils.map( + $2, + function(element) { return element[1]; } + ))) + : $1; +} + +sequence + : prefixed* action { + return new PEG.Grammar.Action( + $1.length != 1 ? new PEG.Grammar.Sequence($1) : $1[0], + $2 + ); + } + / prefixed* { return $1.length != 1 ? new PEG.Grammar.Sequence($1) : $1[0]; } + +prefixed + : and suffixed { + return new PEG.Grammar.NotPredicate(new PEG.Grammar.NotPredicate($2)); + } + / not suffixed { return new PEG.Grammar.NotPredicate($2); } + / suffixed + +suffixed + : primary question { + return new PEG.Grammar.Choice([$1, new PEG.Grammar.Literal("")]); + } + / primary star { return new PEG.Grammar.ZeroOrMore($1); } + / primary plus { + return new PEG.Grammar.Action( + new PEG.Grammar.Sequence([$1, new PEG.Grammar.ZeroOrMore($1)]), + function(first, rest) { return [first].concat(rest); } + ); + } + / primary + +primary + : identifier !(( literal / "") colon) { return new PEG.Grammar.RuleRef($1); } + / literal { return new PEG.Grammar.Literal($1); } + / dot { return new PEG.Grammar.Any(); } + / class { + return new PEG.Grammar.Choice( + PEG.ArrayUtils.map( + $1.split(""), + function(character) { return new PEG.Grammar.Literal(character); } + ) + ); + } + / lparen expression rparen { return $2; } + +/* "Lexical" elements */ + +action "action": braced __ { return $1.substr(1, $1.length - 2); } + +braced: "{" (braced / nonBraceCharacter)* "}" { return $1 + $2.join("") + $3; } + +nonBraceCharacters: nonBraceCharacter+ { return $1.join(""); } + +nonBraceCharacter: !("{" / "}") . { return $2; } + +colon: ":" __ { return $1; } +slash: "/" __ { return $1; } +and: "&" __ { return $1; } +not: "!" __ { return $1; } +question: "?" __ { return $1; } +star: "*" __ { return $1; } +plus: "+" __ { return $1; } +lparen: "(" __ { return $1; } +rparen: ")" __ { return $1; } +dot: "." __ { return $1; } + +/* + * Modelled after ECMA-262, 5th ed., 7.6, but much simplified: + * + * * no Unicode escape sequences + * + * * "Unicode combining marks" and "Unicode connection punctuation" can't be + * part of the identifier + * + * * only [a-zA-Z] is considered a "Unicode letter" + * + * * only [0-9] is considered a "Unicode digit" + * + * The simplifications were made just to make the implementation little bit + * easier, there is no "philosophical" reason behind them. + */ +identifier "identifier": (letter / "_" / "$") (letter / digit / "_" / "$")* __ { + return $1 + $2.join(""); +} + +/* + * Modelled after ECMA-262, 5th ed., 7.8.4. (syntax & semantics, rules only + * vaguely). + */ +literal "literal": (doubleQuotedLiteral / singleQuotedLiteral) __ { return $1; } + +doubleQuotedLiteral: '"' doubleQuotedCharacter* '"' { return $2.join(""); } + +doubleQuotedCharacter + : simpleDoubleQuotedCharacter + / simpleEscapeSequence + / zeroEscapeSequence + / hexEscapeSequence + / unicodeEscapeSequence + / eolEscapeSequence + +simpleDoubleQuotedCharacter: !('"' / "\\" / eolChar) . { return $2; } + +singleQuotedLiteral: "'" singleQuotedCharacter* "'" { return $2.join(""); } + +singleQuotedCharacter + : simpleSingleQuotedCharacter + / simpleEscapeSequence + / zeroEscapeSequence + / hexEscapeSequence + / unicodeEscapeSequence + / eolEscapeSequence + +simpleSingleQuotedCharacter: !("'" / "\\" / eolChar) . { return $2; } + +class "character class": "[" (classCharacterRange / classCharacter)* "]" __ { + return $2.join(""); +} + +classCharacterRange: bracketDelimitedCharacter "-" bracketDelimitedCharacter { + var beginCharCode = $1.charCodeAt(0); + var endCharCode = $3.charCodeAt(0); + if (beginCharCode > endCharCode) { + throw new PEG.Parser.SyntaxError( + "Invalid character range: " + $1 + "-" + $3 + "." + ); + } + + var result = ""; + for (var charCode = beginCharCode; charCode <= endCharCode; charCode++) { + result += String.fromCharCode(charCode); + } + return result; +} + +classCharacter: bracketDelimitedCharacter + +bracketDelimitedCharacter + : simpleBracketDelimitedCharacter + / simpleEscapeSequence + / zeroEscapeSequence + / hexEscapeSequence + / unicodeEscapeSequence + / eolEscapeSequence + +simpleBracketDelimitedCharacter: !("]" / "\\" / eolChar) . { return $2; } + +simpleEscapeSequence: "\\" !(digit / "x" / "u" / eolChar) . { + return $3 + .replace("b", "\b") + .replace("f", "\f") + .replace("n", "\n") + .replace("r", "\r") + .replace("t", "\t") + .replace("v", "\v") +} + +zeroEscapeSequence: "\\0" !digit { return "\0"; } + +hexEscapeSequence: "\\x" hexDigit hexDigit { + return String.fromCharCode(parseInt("0x" + $2 + $3)); +} + +unicodeEscapeSequence: "\\u" hexDigit hexDigit hexDigit hexDigit { + return String.fromCharCode(parseInt("0x" + $2 + $3 + $4 + $5)); +} + +eolEscapeSequence: "\\" eol { return $2; } + +digit: [0-9] + +hexDigit: [0-9a-fA-F] + +letter: lowerCaseLetter / upperCaseLetter + +lowerCaseLetter: [a-z] + +upperCaseLetter: [A-Z] + +__: (whitespace / eol / comment)* + +/* Modelled after ECMA-262, 5th ed., 7.4. */ +comment "comment": singleLineComment / multiLineComment + +singleLineComment: "//" (!eolChar .)* + +multiLineComment: "/*" (!"*/" .)* "*/" + +/* Modelled after ECMA-262, 5th ed., 7.3. */ +eol "end of line": "\n" / "\r\n" / "\r" / "\u2028" / "\u2029" + +eolChar: [\n\r\u2028\u2029] + +/* + * Modelled after ECMA-262, 5th ed., 7.2. \uFEFF should be between the + * characters too, but it causes infinite loop in Rhino. + */ +whitespace "whitespace": [ \t\v\f\xA0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] diff --git a/test/compiler-test.js b/test/compiler-test.js index 6173aa2..9d5998f 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -57,14 +57,6 @@ global.doesNotParseWithPos = function(parser, input, line, column) { } }; -global.grammarParserParses = function(input, expected) { - global.parses(PEG.grammarParser, input, expected); -}; - -global.grammarParserDoesNotParse = function(input) { - global.doesNotParse(PEG.grammarParser, input); -} - /* ===== PEG.Compiler ===== */ module("PEG.Compiler"); @@ -526,449 +518,4 @@ test("nested comments", function() { ); }); -/* ===== Grammar Parser ===== */ - -module("Grammar Parser"); - -with (PEG.Grammar) { - var literalEmpty = new Literal(""); - var literalAbcd = new Literal("abcd"); - var literalEfgh = new Literal("efgh"); - var literalIjkl = new Literal("ijkl"); - - var choice = new Choice([literalAbcd, literalEmpty]); - - var notAbcd = new NotPredicate(literalAbcd); - var notEfgh = new NotPredicate(literalEfgh); - var notIjkl = new NotPredicate(literalIjkl); - - var sequenceEmpty = new Sequence([]); - var sequenceNots = new Sequence([notAbcd, notEfgh, notIjkl]); - var sequenceLiterals = new Sequence([literalAbcd, literalEfgh, literalIjkl]); - - function oneRuleGrammar(expression) { - return { start: new PEG.Grammar.Rule("start", null, expression) }; - } - - var simpleGrammar = oneRuleGrammar(new Literal("abcd")); - - function identifierGrammar(identifier) { - return oneRuleGrammar(new PEG.Grammar.RuleRef(identifier)); - } - - function literalGrammar(literal) { - return oneRuleGrammar(new PEG.Grammar.Literal(literal)); - } - - function classGrammar(chars) { - return oneRuleGrammar(new PEG.Grammar.Choice( - PEG.ArrayUtils.map( - chars.split(""), - function(char) { return new PEG.Grammar.Literal(char); } - ) - )); - } - - var anyGrammar = oneRuleGrammar(new Any()); - - function actionGrammar(action) { - return oneRuleGrammar(new PEG.Grammar.Action(new PEG.Grammar.Literal("a"), action)); - } - - /* Canonical grammar is "a: \"abcd\";\nb: \"efgh\";\nc: \"ijkl\";". */ - test("parses grammar", function() { - grammarParserParses('a: "abcd"', { a: new Rule("a", null, literalAbcd) }); - grammarParserParses( - 'a: "abcd"\nb: "efgh"\nc: "ijkl"', - { - a: new Rule("a", null, literalAbcd), - b: new Rule("b", null, literalEfgh), - c: new Rule("c", null, literalIjkl) - } - ); - }); - - /* Canonical rule is "a: \"abcd\"". */ - test("parses rule", function() { - grammarParserParses( - 'start: "abcd" / "efgh" / "ijkl"', - oneRuleGrammar(new Choice([literalAbcd, literalEfgh, literalIjkl])) - ); - grammarParserParses( - 'start "start rule": "abcd" / "efgh" / "ijkl"', - { - start: - new Rule( - "start", - "start rule", - new Choice([literalAbcd, literalEfgh, literalIjkl]) - ) - } - ); - }); - - /* Canonical expression is "\"abcd\" / \"efgh\" / \"ijkl\"". */ - test("parses expression", function() { - grammarParserParses( - 'start: "abcd" / "efgh" / "ijkl"', - oneRuleGrammar(new Choice([literalAbcd, literalEfgh, literalIjkl])) - ); - }); - - /* Canonical choice is "\"abcd\" / \"efgh\" / \"ijkl\"". */ - test("parses choice", function() { - grammarParserParses( - 'start: "abcd" "efgh" "ijkl"', - oneRuleGrammar(sequenceLiterals) - ); - grammarParserParses( - 'start: "abcd" "efgh" "ijkl" / "abcd" "efgh" "ijkl" / "abcd" "efgh" "ijkl"', - oneRuleGrammar(new Choice([ - sequenceLiterals, - sequenceLiterals, - sequenceLiterals - ])) - ); - }); - - /* Canonical sequence is "\"abcd\" \"efgh\" \"ijkl\"". */ - test("parses sequence", function() { - grammarParserParses( - 'start: { code }', - oneRuleGrammar(new Action(sequenceEmpty, " code ")) - ); - grammarParserParses( - 'start: !"abcd" { code }', - oneRuleGrammar(new Action(notAbcd, " code ")) - ); - grammarParserParses( - 'start: !"abcd" !"efgh" !"ijkl" { code }', - oneRuleGrammar(new Action(sequenceNots, " code ")) - ); - - grammarParserParses('start: ', oneRuleGrammar(sequenceEmpty)); - grammarParserParses('start: !"abcd"', oneRuleGrammar(notAbcd)); - grammarParserParses( - 'start: !"abcd" !"efgh" !"ijkl"', - oneRuleGrammar(sequenceNots) - ); - }); - - /* Canonical prefixed is "!\"abcd\"". */ - test("parses prefixed", function() { - grammarParserParses( - 'start: &"abcd"?', - oneRuleGrammar(new NotPredicate(new NotPredicate(choice))) - ); - grammarParserParses('start: !"abcd"?', oneRuleGrammar(new NotPredicate(choice))); - grammarParserParses('start: "abcd"?', oneRuleGrammar(choice)); - }); - - /* Canonical suffixed is "\"abcd\"?". */ - test("parses suffixed", function() { - grammarParserParses('start: "abcd"?', oneRuleGrammar(choice)); - grammarParserParses('start: "abcd"*', oneRuleGrammar(new ZeroOrMore(literalAbcd))); - grammarParserParses( - 'start: "abcd"+', - oneRuleGrammar(new Action( - new Sequence([literalAbcd, new ZeroOrMore(literalAbcd)]), - function(first, rest) { return [first].concat(rest); } - )) - ); - grammarParserParses('start: "abcd"', literalGrammar("abcd")); - }); - - /* Canonical primary is "\"abcd\"". */ - test("parses primary", function() { - grammarParserParses('start: a', identifierGrammar("a")); - grammarParserParses('start: "abcd"', literalGrammar("abcd")); - grammarParserParses('start: .', anyGrammar); - grammarParserParses('start: [a-d]', classGrammar("abcd")); - grammarParserParses('start: ("abcd")', literalGrammar("abcd")); - }); - - /* Canonical action is "{ code }". */ - test("parses action", function() { - grammarParserParses('start: "a" { code }', actionGrammar(" code ")); - }); - - /* Canonical braced is "{ code }". */ - test("parses braced", function() { - grammarParserParses('start: "a" {}', actionGrammar("")); - grammarParserParses('start: "a" {a}', actionGrammar("a")); - grammarParserParses('start: "a" {{a}}', actionGrammar("{a}")); - grammarParserParses('start: "a" {aaa}', actionGrammar("aaa")); - }); - - /* Trivial character rules are not tested. */ - - /* Canonical identifier is "a". */ - test("parses identifier", function() { - grammarParserParses('start: a', identifierGrammar("a")); - grammarParserParses('start: z', identifierGrammar("z")); - grammarParserParses('start: A', identifierGrammar("A")); - grammarParserParses('start: Z', identifierGrammar("Z")); - grammarParserParses('start: _', identifierGrammar("_")); - grammarParserParses('start: $', identifierGrammar("$")); - grammarParserParses('start: aa', identifierGrammar("aa")); - grammarParserParses('start: az', identifierGrammar("az")); - grammarParserParses('start: aA', identifierGrammar("aA")); - grammarParserParses('start: aZ', identifierGrammar("aZ")); - grammarParserParses('start: a0', identifierGrammar("a0")); - grammarParserParses('start: a9', identifierGrammar("a9")); - grammarParserParses('start: a_', identifierGrammar("a_")); - grammarParserParses('start: a$', identifierGrammar("a$")); - grammarParserParses('start: abcd', identifierGrammar("abcd")); - - grammarParserParses('start: a\n', identifierGrammar("a")); - }); - - /* Canonical literal is "\"abcd\"". */ - test("parses literal", function() { - grammarParserParses('start: "abcd"', literalGrammar("abcd")); - grammarParserParses("start: 'abcd'", literalGrammar("abcd")); - }); - - /* Canonical doubleQuotedLiteral is "\"abcd\"". */ - test("parses doubleQuotedLiteral", function() { - grammarParserParses('start: ""', literalGrammar("")); - grammarParserParses('start: "a"', literalGrammar("a")); - grammarParserParses('start: "abc"', literalGrammar("abc")); - - grammarParserParses('start: "abcd"\n', literalGrammar("abcd")); - }); - - /* Canonical doubleQuotedCharacter is "a". */ - test("parses doubleQuotedCharacter", function() { - grammarParserParses('start: "a"', literalGrammar("a")); - grammarParserParses('start: "\\n"', literalGrammar("\n")); - grammarParserParses('start: "\\0"', literalGrammar("\0")); - grammarParserParses('start: "\\x00"', literalGrammar("\x00")); - grammarParserParses('start: "\\u0120"', literalGrammar("\u0120")); - grammarParserParses('start: "\\\n"', literalGrammar("\n")); - }); - - /* Canonical simpleDoubleQuotedCharacter is "a". */ - test("parses simpleDoubleQuotedCharacter", function() { - grammarParserParses('start: "a"', literalGrammar("a")); - grammarParserParses('start: "\'"', literalGrammar("'")); - grammarParserDoesNotParse('start: """'); - grammarParserDoesNotParse('start: "\\"'); - grammarParserDoesNotParse('start: "\n"'); - grammarParserDoesNotParse('start: "\r"'); - grammarParserDoesNotParse('start: "\u2028"'); - grammarParserDoesNotParse('start: "\u2029"'); - }); - - /* Canonical singleQuotedLiteral is "'abcd'". */ - test("parses singleQuotedLiteral", function() { - grammarParserParses("start: ''", literalGrammar("")); - grammarParserParses("start: 'a'", literalGrammar("a")); - grammarParserParses("start: 'abc'", literalGrammar("abc")); - - grammarParserParses("start: 'abcd'\n", literalGrammar("abcd")); - }); - - /* Canonical singleQuotedCharacter is "a". */ - test("parses singleQuotedCharacter", function() { - grammarParserParses("start: 'a'", literalGrammar("a")); - grammarParserParses("start: '\\n'", literalGrammar("\n")); - grammarParserParses("start: '\\0'", literalGrammar("\0")); - grammarParserParses("start: '\\x00'", literalGrammar("\x00")); - grammarParserParses("start: '\\u0120'", literalGrammar("\u0120")); - grammarParserParses("start: '\\\n'", literalGrammar("\n")); - }); - - /* Canonical simpleSingleQuotedCharacter is "a". */ - test("parses simpleSingleQuotedCharacter", function() { - grammarParserParses("start: 'a'", literalGrammar("a")); - grammarParserParses("start: '\"'", literalGrammar("\"")); - grammarParserDoesNotParse("start: '''"); - grammarParserDoesNotParse("start: '\\'"); - grammarParserDoesNotParse("start: '\n'"); - grammarParserDoesNotParse("start: '\r'"); - grammarParserDoesNotParse("start: '\u2028'"); - grammarParserDoesNotParse("start: '\u2029'"); - }); - - /* Canonical class is "[a-d]". */ - test("parses classCharacterRange", function() { - grammarParserParses("start: []", classGrammar("")); - grammarParserParses("start: [a-d]", classGrammar("abcd")); - grammarParserParses("start: [a]", classGrammar("a")); - grammarParserParses("start: [a-de-hi-l]", classGrammar("abcdefghijkl")); - - grammarParserParses("start: [a-d]\n", classGrammar("abcd")); - }); - - /* Canonical classCharacterRange is "a-d". */ - test("parses classCharacterRange", function() { - grammarParserParses("start: [a-d]", classGrammar("abcd")); - grammarParserParses("start: [a-a]", classGrammar("a")); - grammarParserDoesNotParse("start: [b-a]"); - }); - - /* Canonical classCharacter is "a". */ - test("parses classCharacter", function() { - grammarParserParses("start: [a]", classGrammar("a")); - }); - - /* Canonical bracketDelimitedCharacter is "a". */ - test("parses bracketDelimitedCharacter", function() { - grammarParserParses("start: [a]", classGrammar("a")); - grammarParserParses("start: [\\n]", classGrammar("\n")); - grammarParserParses("start: [\\0]", classGrammar("\0")); - grammarParserParses("start: [\\x00]", classGrammar("\x00")); - grammarParserParses("start: [\\u0120]", classGrammar("\u0120")); - grammarParserParses("start: [\\\n]", classGrammar("\n")); - }); - - /* Canonical simpleBracketDelimiedCharacter is "a". */ - test("parses simpleBracketDelimitedCharacter", function() { - grammarParserParses("start: [a]", classGrammar("a")); - grammarParserParses("start: [[]", classGrammar("[")); - grammarParserDoesNotParse("start: []]"); - grammarParserDoesNotParse("start: [\\]"); - grammarParserDoesNotParse("start: [\n]"); - grammarParserDoesNotParse("start: [\r]"); - grammarParserDoesNotParse("start: [\u2028]"); - grammarParserDoesNotParse("start: [\u2029]"); - }); - - /* Canonical simpleEscapeSequence is "\\n". */ - test("parses simpleEscapeSequence", function() { - grammarParserParses('start: "\\\'"', literalGrammar("'")); - grammarParserParses('start: "\\""', literalGrammar("\"")); - grammarParserParses('start: "\\\\"', literalGrammar("\\")); - grammarParserParses('start: "\\b"', literalGrammar("\b")); - grammarParserParses('start: "\\f"', literalGrammar("\f")); - grammarParserParses('start: "\\n"', literalGrammar("\n")); - grammarParserParses('start: "\\r"', literalGrammar("\r")); - grammarParserParses('start: "\\t"', literalGrammar("\t")); - grammarParserParses('start: "\\v"', literalGrammar("\v")); - - grammarParserParses('start: "\\a"', literalGrammar("a")); - }); - - /* Canonical zeroEscapeSequence is "\\0". */ - test("parses zeroEscapeSequence", function() { - grammarParserParses('start: "\\0"', literalGrammar("\0")); - grammarParserDoesNotParse('start: "\\00"'); - grammarParserDoesNotParse('start: "\\09"'); - }); - - /* Canonical hexEscapeSequence is "\\x00". */ - test("parses hexEscapeSequence", function() { - grammarParserParses('start: "\\x00"', literalGrammar("\x00")); - grammarParserParses('start: "\\x09"', literalGrammar("\x09")); - grammarParserParses('start: "\\x0a"', literalGrammar("\x0a")); - grammarParserParses('start: "\\x0f"', literalGrammar("\x0f")); - grammarParserParses('start: "\\x0A"', literalGrammar("\x0A")); - grammarParserParses('start: "\\x0F"', literalGrammar("\x0F")); - grammarParserDoesNotParse('start: "\\x0"'); - grammarParserParses('start: "\\x000"', literalGrammar("\x000")); - }); - - /* Canonical unicodeEscapeSequence is "\\u0120". */ - test("parses unicodeEscapeSequence", function() { - grammarParserParses('start: "\\u0120"', literalGrammar("\u0120")); - grammarParserParses('start: "\\u0129"', literalGrammar("\u0129")); - grammarParserParses('start: "\\u012a"', literalGrammar("\u012a")); - grammarParserParses('start: "\\u012f"', literalGrammar("\u012f")); - grammarParserParses('start: "\\u012A"', literalGrammar("\u012A")); - grammarParserParses('start: "\\u012F"', literalGrammar("\u012F")); - grammarParserDoesNotParse('start: "\\u012"'); - grammarParserParses('start: "\\u01234"', literalGrammar("\u01234")); - }); - - /* Canonical eolEscapeSequence is "\\\n". */ - test("parses eolEscapeSequence", function() { - grammarParserParses('start: "\\\n"', literalGrammar("\n")); - grammarParserParses('start: "\\\r\n"', literalGrammar("\r\n")); - grammarParserParses('start: "\\\r"', literalGrammar("\r")); - grammarParserParses('start: "\\\u2028"', literalGrammar("\u2028")); - grammarParserParses('start: "\\\u2029"', literalGrammar("\u2029")); - }); - - /* Canonical __ is "\n". */ - test("parses __", function() { - grammarParserParses('start:"abcd"', simpleGrammar); - grammarParserParses('start: "abcd"', simpleGrammar); - grammarParserParses('start:\n"abcd"', simpleGrammar); - grammarParserParses('start:/* comment */"abcd"', simpleGrammar); - grammarParserParses('start: "abcd"', simpleGrammar); - }); - - /* Trivial character class rules are not tested. */ - - /* Canonical comment is "\/* comment *\/". */ - test("parses comment", function() { - grammarParserParses('start:// comment\n"abcd"', simpleGrammar); - grammarParserParses('start:/* comment */"abcd"', simpleGrammar); - }); - /* Canonical singleLineComment is "// comment". */ - test("parses singleLineComment", function() { - grammarParserParses('start://\n"abcd"', simpleGrammar); - grammarParserParses('start://a\n"abcd"', simpleGrammar); - grammarParserParses('start://aaa\n"abcd"', simpleGrammar); - grammarParserParses('start: "abcd"//', simpleGrammar); - }); - - /* Canonical multiLineComment is "\/* comment *\/". */ - test("parses multiLineComment", function() { - grammarParserParses('start:/**/"abcd"', simpleGrammar); - grammarParserParses('start:/*a*/"abcd"', simpleGrammar); - grammarParserParses('start:/*aaa*/"abcd"', simpleGrammar); - grammarParserParses('start:/*\n*/"abcd"', simpleGrammar); - grammarParserParses('start:/***/"abcd"', simpleGrammar); - grammarParserParses('start:/*a/*/"abcd"', simpleGrammar); - - grammarParserDoesNotParse('start:/*"abcd"'); - grammarParserDoesNotParse('start:/*/"abcd"'); - grammarParserDoesNotParse('start:/*/**/*/"abcd"'); - }); - - /* Canonical eol is "\n". */ - test("parses eol", function() { - grammarParserParses('start:\n"abcd"', simpleGrammar); - grammarParserParses('start:\r\n"abcd"', simpleGrammar); - grammarParserParses('start:\r"abcd"', simpleGrammar); - grammarParserParses('start:\u2028"abcd"', simpleGrammar); - grammarParserParses('start:\u2029"abcd"', simpleGrammar); - }); - - /* Canonical eolChar is "\n". */ - test("parses eolChar", function() { - grammarParserParses('start:\n"abcd"', simpleGrammar); - grammarParserParses('start:\r"abcd"', simpleGrammar); - grammarParserParses('start:\u2028"abcd"', simpleGrammar); - grammarParserParses('start:\u2029"abcd"', simpleGrammar); - }); - - /* Canonical whitespace is " ". */ - test("parses whitespace", function() { - grammarParserParses('start:\t"abcd"', simpleGrammar); - grammarParserParses('start:\v"abcd"', simpleGrammar); - grammarParserParses('start:\f"abcd"', simpleGrammar); - grammarParserParses('start: "abcd"', simpleGrammar); - grammarParserParses('start:\xA0"abcd"', simpleGrammar); - grammarParserParses('start:\u1680"abcd"', simpleGrammar); - grammarParserParses('start:\u180E"abcd"', simpleGrammar); - grammarParserParses('start:\u2000"abcd"', simpleGrammar); - grammarParserParses('start:\u2001"abcd"', simpleGrammar); - grammarParserParses('start:\u2002"abcd"', simpleGrammar); - grammarParserParses('start:\u2003"abcd"', simpleGrammar); - grammarParserParses('start:\u2004"abcd"', simpleGrammar); - grammarParserParses('start:\u2005"abcd"', simpleGrammar); - grammarParserParses('start:\u2006"abcd"', simpleGrammar); - grammarParserParses('start:\u2007"abcd"', simpleGrammar); - grammarParserParses('start:\u2008"abcd"', simpleGrammar); - grammarParserParses('start:\u2009"abcd"', simpleGrammar); - grammarParserParses('start:\u200A"abcd"', simpleGrammar); - grammarParserParses('start:\u202F"abcd"', simpleGrammar); - grammarParserParses('start:\u205F"abcd"', simpleGrammar); - grammarParserParses('start:\u3000"abcd"', simpleGrammar); - }); -} - })(); diff --git a/test/index.html b/test/index.html index e8fec66..d841e0e 100644 --- a/test/index.html +++ b/test/index.html @@ -7,8 +7,10 @@ + +

PEG.js Test Suite

diff --git a/test/metagrammar-test.js b/test/metagrammar-test.js new file mode 100644 index 0000000..629047c --- /dev/null +++ b/test/metagrammar-test.js @@ -0,0 +1,460 @@ +(function() { + +var global = this; + +/* ===== Helpers ===== */ + +global.grammarParserParses = function(input, expected) { + global.parses(PEG.grammarParser, input, expected); +}; + +global.grammarParserDoesNotParse = function(input) { + global.doesNotParse(PEG.grammarParser, input); +} + +/* ===== Grammar Parser ===== */ + +module("Grammar Parser"); + +with (PEG.Grammar) { + var literalEmpty = new Literal(""); + var literalAbcd = new Literal("abcd"); + var literalEfgh = new Literal("efgh"); + var literalIjkl = new Literal("ijkl"); + + var choice = new Choice([literalAbcd, literalEmpty]); + + var notAbcd = new NotPredicate(literalAbcd); + var notEfgh = new NotPredicate(literalEfgh); + var notIjkl = new NotPredicate(literalIjkl); + + var sequenceEmpty = new Sequence([]); + var sequenceNots = new Sequence([notAbcd, notEfgh, notIjkl]); + var sequenceLiterals = new Sequence([literalAbcd, literalEfgh, literalIjkl]); + + function oneRuleGrammar(expression) { + return { start: new PEG.Grammar.Rule("start", null, expression) }; + } + + var simpleGrammar = oneRuleGrammar(new Literal("abcd")); + + function identifierGrammar(identifier) { + return oneRuleGrammar(new PEG.Grammar.RuleRef(identifier)); + } + + function literalGrammar(literal) { + return oneRuleGrammar(new PEG.Grammar.Literal(literal)); + } + + function classGrammar(chars) { + return oneRuleGrammar(new PEG.Grammar.Choice( + PEG.ArrayUtils.map( + chars.split(""), + function(char) { return new PEG.Grammar.Literal(char); } + ) + )); + } + + var anyGrammar = oneRuleGrammar(new Any()); + + function actionGrammar(action) { + return oneRuleGrammar(new PEG.Grammar.Action(new PEG.Grammar.Literal("a"), action)); + } + + /* Canonical grammar is "a: \"abcd\";\nb: \"efgh\";\nc: \"ijkl\";". */ + test("parses grammar", function() { + grammarParserParses('a: "abcd"', { a: new Rule("a", null, literalAbcd) }); + grammarParserParses( + 'a: "abcd"\nb: "efgh"\nc: "ijkl"', + { + a: new Rule("a", null, literalAbcd), + b: new Rule("b", null, literalEfgh), + c: new Rule("c", null, literalIjkl) + } + ); + }); + + /* Canonical rule is "a: \"abcd\"". */ + test("parses rule", function() { + grammarParserParses( + 'start: "abcd" / "efgh" / "ijkl"', + oneRuleGrammar(new Choice([literalAbcd, literalEfgh, literalIjkl])) + ); + grammarParserParses( + 'start "start rule": "abcd" / "efgh" / "ijkl"', + { + start: + new Rule( + "start", + "start rule", + new Choice([literalAbcd, literalEfgh, literalIjkl]) + ) + } + ); + }); + + /* Canonical expression is "\"abcd\" / \"efgh\" / \"ijkl\"". */ + test("parses expression", function() { + grammarParserParses( + 'start: "abcd" / "efgh" / "ijkl"', + oneRuleGrammar(new Choice([literalAbcd, literalEfgh, literalIjkl])) + ); + }); + + /* Canonical choice is "\"abcd\" / \"efgh\" / \"ijkl\"". */ + test("parses choice", function() { + grammarParserParses( + 'start: "abcd" "efgh" "ijkl"', + oneRuleGrammar(sequenceLiterals) + ); + grammarParserParses( + 'start: "abcd" "efgh" "ijkl" / "abcd" "efgh" "ijkl" / "abcd" "efgh" "ijkl"', + oneRuleGrammar(new Choice([ + sequenceLiterals, + sequenceLiterals, + sequenceLiterals + ])) + ); + }); + + /* Canonical sequence is "\"abcd\" \"efgh\" \"ijkl\"". */ + test("parses sequence", function() { + grammarParserParses( + 'start: { code }', + oneRuleGrammar(new Action(sequenceEmpty, " code ")) + ); + grammarParserParses( + 'start: !"abcd" { code }', + oneRuleGrammar(new Action(notAbcd, " code ")) + ); + grammarParserParses( + 'start: !"abcd" !"efgh" !"ijkl" { code }', + oneRuleGrammar(new Action(sequenceNots, " code ")) + ); + + grammarParserParses('start: ', oneRuleGrammar(sequenceEmpty)); + grammarParserParses('start: !"abcd"', oneRuleGrammar(notAbcd)); + grammarParserParses( + 'start: !"abcd" !"efgh" !"ijkl"', + oneRuleGrammar(sequenceNots) + ); + }); + + /* Canonical prefixed is "!\"abcd\"". */ + test("parses prefixed", function() { + grammarParserParses( + 'start: &"abcd"?', + oneRuleGrammar(new NotPredicate(new NotPredicate(choice))) + ); + grammarParserParses('start: !"abcd"?', oneRuleGrammar(new NotPredicate(choice))); + grammarParserParses('start: "abcd"?', oneRuleGrammar(choice)); + }); + + /* Canonical suffixed is "\"abcd\"?". */ + test("parses suffixed", function() { + grammarParserParses('start: "abcd"?', oneRuleGrammar(choice)); + grammarParserParses('start: "abcd"*', oneRuleGrammar(new ZeroOrMore(literalAbcd))); + grammarParserParses( + 'start: "abcd"+', + oneRuleGrammar(new Action( + new Sequence([literalAbcd, new ZeroOrMore(literalAbcd)]), + function(first, rest) { return [first].concat(rest); } + )) + ); + grammarParserParses('start: "abcd"', literalGrammar("abcd")); + }); + + /* Canonical primary is "\"abcd\"". */ + test("parses primary", function() { + grammarParserParses('start: a', identifierGrammar("a")); + grammarParserParses('start: "abcd"', literalGrammar("abcd")); + grammarParserParses('start: .', anyGrammar); + grammarParserParses('start: [a-d]', classGrammar("abcd")); + grammarParserParses('start: ("abcd")', literalGrammar("abcd")); + }); + + /* Canonical action is "{ code }". */ + test("parses action", function() { + grammarParserParses('start: "a" { code }', actionGrammar(" code ")); + }); + + /* Canonical braced is "{ code }". */ + test("parses braced", function() { + grammarParserParses('start: "a" {}', actionGrammar("")); + grammarParserParses('start: "a" {a}', actionGrammar("a")); + grammarParserParses('start: "a" {{a}}', actionGrammar("{a}")); + grammarParserParses('start: "a" {aaa}', actionGrammar("aaa")); + }); + + /* Trivial character rules are not tested. */ + + /* Canonical identifier is "a". */ + test("parses identifier", function() { + grammarParserParses('start: a', identifierGrammar("a")); + grammarParserParses('start: z', identifierGrammar("z")); + grammarParserParses('start: A', identifierGrammar("A")); + grammarParserParses('start: Z', identifierGrammar("Z")); + grammarParserParses('start: _', identifierGrammar("_")); + grammarParserParses('start: $', identifierGrammar("$")); + grammarParserParses('start: aa', identifierGrammar("aa")); + grammarParserParses('start: az', identifierGrammar("az")); + grammarParserParses('start: aA', identifierGrammar("aA")); + grammarParserParses('start: aZ', identifierGrammar("aZ")); + grammarParserParses('start: a0', identifierGrammar("a0")); + grammarParserParses('start: a9', identifierGrammar("a9")); + grammarParserParses('start: a_', identifierGrammar("a_")); + grammarParserParses('start: a$', identifierGrammar("a$")); + grammarParserParses('start: abcd', identifierGrammar("abcd")); + + grammarParserParses('start: a\n', identifierGrammar("a")); + }); + + /* Canonical literal is "\"abcd\"". */ + test("parses literal", function() { + grammarParserParses('start: "abcd"', literalGrammar("abcd")); + grammarParserParses("start: 'abcd'", literalGrammar("abcd")); + }); + + /* Canonical doubleQuotedLiteral is "\"abcd\"". */ + test("parses doubleQuotedLiteral", function() { + grammarParserParses('start: ""', literalGrammar("")); + grammarParserParses('start: "a"', literalGrammar("a")); + grammarParserParses('start: "abc"', literalGrammar("abc")); + + grammarParserParses('start: "abcd"\n', literalGrammar("abcd")); + }); + + /* Canonical doubleQuotedCharacter is "a". */ + test("parses doubleQuotedCharacter", function() { + grammarParserParses('start: "a"', literalGrammar("a")); + grammarParserParses('start: "\\n"', literalGrammar("\n")); + grammarParserParses('start: "\\0"', literalGrammar("\0")); + grammarParserParses('start: "\\x00"', literalGrammar("\x00")); + grammarParserParses('start: "\\u0120"', literalGrammar("\u0120")); + grammarParserParses('start: "\\\n"', literalGrammar("\n")); + }); + + /* Canonical simpleDoubleQuotedCharacter is "a". */ + test("parses simpleDoubleQuotedCharacter", function() { + grammarParserParses('start: "a"', literalGrammar("a")); + grammarParserParses('start: "\'"', literalGrammar("'")); + grammarParserDoesNotParse('start: """'); + grammarParserDoesNotParse('start: "\\"'); + grammarParserDoesNotParse('start: "\n"'); + grammarParserDoesNotParse('start: "\r"'); + grammarParserDoesNotParse('start: "\u2028"'); + grammarParserDoesNotParse('start: "\u2029"'); + }); + + /* Canonical singleQuotedLiteral is "'abcd'". */ + test("parses singleQuotedLiteral", function() { + grammarParserParses("start: ''", literalGrammar("")); + grammarParserParses("start: 'a'", literalGrammar("a")); + grammarParserParses("start: 'abc'", literalGrammar("abc")); + + grammarParserParses("start: 'abcd'\n", literalGrammar("abcd")); + }); + + /* Canonical singleQuotedCharacter is "a". */ + test("parses singleQuotedCharacter", function() { + grammarParserParses("start: 'a'", literalGrammar("a")); + grammarParserParses("start: '\\n'", literalGrammar("\n")); + grammarParserParses("start: '\\0'", literalGrammar("\0")); + grammarParserParses("start: '\\x00'", literalGrammar("\x00")); + grammarParserParses("start: '\\u0120'", literalGrammar("\u0120")); + grammarParserParses("start: '\\\n'", literalGrammar("\n")); + }); + + /* Canonical simpleSingleQuotedCharacter is "a". */ + test("parses simpleSingleQuotedCharacter", function() { + grammarParserParses("start: 'a'", literalGrammar("a")); + grammarParserParses("start: '\"'", literalGrammar("\"")); + grammarParserDoesNotParse("start: '''"); + grammarParserDoesNotParse("start: '\\'"); + grammarParserDoesNotParse("start: '\n'"); + grammarParserDoesNotParse("start: '\r'"); + grammarParserDoesNotParse("start: '\u2028'"); + grammarParserDoesNotParse("start: '\u2029'"); + }); + + /* Canonical class is "[a-d]". */ + test("parses classCharacterRange", function() { + grammarParserParses("start: []", classGrammar("")); + grammarParserParses("start: [a-d]", classGrammar("abcd")); + grammarParserParses("start: [a]", classGrammar("a")); + grammarParserParses("start: [a-de-hi-l]", classGrammar("abcdefghijkl")); + + grammarParserParses("start: [a-d]\n", classGrammar("abcd")); + }); + + /* Canonical classCharacterRange is "a-d". */ + test("parses classCharacterRange", function() { + grammarParserParses("start: [a-d]", classGrammar("abcd")); + grammarParserParses("start: [a-a]", classGrammar("a")); + grammarParserDoesNotParse("start: [b-a]"); + }); + + /* Canonical classCharacter is "a". */ + test("parses classCharacter", function() { + grammarParserParses("start: [a]", classGrammar("a")); + }); + + /* Canonical bracketDelimitedCharacter is "a". */ + test("parses bracketDelimitedCharacter", function() { + grammarParserParses("start: [a]", classGrammar("a")); + grammarParserParses("start: [\\n]", classGrammar("\n")); + grammarParserParses("start: [\\0]", classGrammar("\0")); + grammarParserParses("start: [\\x00]", classGrammar("\x00")); + grammarParserParses("start: [\\u0120]", classGrammar("\u0120")); + grammarParserParses("start: [\\\n]", classGrammar("\n")); + }); + + /* Canonical simpleBracketDelimiedCharacter is "a". */ + test("parses simpleBracketDelimitedCharacter", function() { + grammarParserParses("start: [a]", classGrammar("a")); + grammarParserParses("start: [[]", classGrammar("[")); + grammarParserDoesNotParse("start: []]"); + grammarParserDoesNotParse("start: [\\]"); + grammarParserDoesNotParse("start: [\n]"); + grammarParserDoesNotParse("start: [\r]"); + grammarParserDoesNotParse("start: [\u2028]"); + grammarParserDoesNotParse("start: [\u2029]"); + }); + + /* Canonical simpleEscapeSequence is "\\n". */ + test("parses simpleEscapeSequence", function() { + grammarParserParses('start: "\\\'"', literalGrammar("'")); + grammarParserParses('start: "\\""', literalGrammar("\"")); + grammarParserParses('start: "\\\\"', literalGrammar("\\")); + grammarParserParses('start: "\\b"', literalGrammar("\b")); + grammarParserParses('start: "\\f"', literalGrammar("\f")); + grammarParserParses('start: "\\n"', literalGrammar("\n")); + grammarParserParses('start: "\\r"', literalGrammar("\r")); + grammarParserParses('start: "\\t"', literalGrammar("\t")); + grammarParserParses('start: "\\v"', literalGrammar("\v")); + + grammarParserParses('start: "\\a"', literalGrammar("a")); + }); + + /* Canonical zeroEscapeSequence is "\\0". */ + test("parses zeroEscapeSequence", function() { + grammarParserParses('start: "\\0"', literalGrammar("\0")); + grammarParserDoesNotParse('start: "\\00"'); + grammarParserDoesNotParse('start: "\\09"'); + }); + + /* Canonical hexEscapeSequence is "\\x00". */ + test("parses hexEscapeSequence", function() { + grammarParserParses('start: "\\x00"', literalGrammar("\x00")); + grammarParserParses('start: "\\x09"', literalGrammar("\x09")); + grammarParserParses('start: "\\x0a"', literalGrammar("\x0a")); + grammarParserParses('start: "\\x0f"', literalGrammar("\x0f")); + grammarParserParses('start: "\\x0A"', literalGrammar("\x0A")); + grammarParserParses('start: "\\x0F"', literalGrammar("\x0F")); + grammarParserDoesNotParse('start: "\\x0"'); + grammarParserParses('start: "\\x000"', literalGrammar("\x000")); + }); + + /* Canonical unicodeEscapeSequence is "\\u0120". */ + test("parses unicodeEscapeSequence", function() { + grammarParserParses('start: "\\u0120"', literalGrammar("\u0120")); + grammarParserParses('start: "\\u0129"', literalGrammar("\u0129")); + grammarParserParses('start: "\\u012a"', literalGrammar("\u012a")); + grammarParserParses('start: "\\u012f"', literalGrammar("\u012f")); + grammarParserParses('start: "\\u012A"', literalGrammar("\u012A")); + grammarParserParses('start: "\\u012F"', literalGrammar("\u012F")); + grammarParserDoesNotParse('start: "\\u012"'); + grammarParserParses('start: "\\u01234"', literalGrammar("\u01234")); + }); + + /* Canonical eolEscapeSequence is "\\\n". */ + test("parses eolEscapeSequence", function() { + grammarParserParses('start: "\\\n"', literalGrammar("\n")); + grammarParserParses('start: "\\\r\n"', literalGrammar("\r\n")); + grammarParserParses('start: "\\\r"', literalGrammar("\r")); + grammarParserParses('start: "\\\u2028"', literalGrammar("\u2028")); + grammarParserParses('start: "\\\u2029"', literalGrammar("\u2029")); + }); + + /* Canonical __ is "\n". */ + test("parses __", function() { + grammarParserParses('start:"abcd"', simpleGrammar); + grammarParserParses('start: "abcd"', simpleGrammar); + grammarParserParses('start:\n"abcd"', simpleGrammar); + grammarParserParses('start:/* comment */"abcd"', simpleGrammar); + grammarParserParses('start: "abcd"', simpleGrammar); + }); + + /* Trivial character class rules are not tested. */ + + /* Canonical comment is "\/* comment *\/". */ + test("parses comment", function() { + grammarParserParses('start:// comment\n"abcd"', simpleGrammar); + grammarParserParses('start:/* comment */"abcd"', simpleGrammar); + }); + /* Canonical singleLineComment is "// comment". */ + test("parses singleLineComment", function() { + grammarParserParses('start://\n"abcd"', simpleGrammar); + grammarParserParses('start://a\n"abcd"', simpleGrammar); + grammarParserParses('start://aaa\n"abcd"', simpleGrammar); + grammarParserParses('start: "abcd"//', simpleGrammar); + }); + + /* Canonical multiLineComment is "\/* comment *\/". */ + test("parses multiLineComment", function() { + grammarParserParses('start:/**/"abcd"', simpleGrammar); + grammarParserParses('start:/*a*/"abcd"', simpleGrammar); + grammarParserParses('start:/*aaa*/"abcd"', simpleGrammar); + grammarParserParses('start:/*\n*/"abcd"', simpleGrammar); + grammarParserParses('start:/***/"abcd"', simpleGrammar); + grammarParserParses('start:/*a/*/"abcd"', simpleGrammar); + + grammarParserDoesNotParse('start:/*"abcd"'); + grammarParserDoesNotParse('start:/*/"abcd"'); + grammarParserDoesNotParse('start:/*/**/*/"abcd"'); + }); + + /* Canonical eol is "\n". */ + test("parses eol", function() { + grammarParserParses('start:\n"abcd"', simpleGrammar); + grammarParserParses('start:\r\n"abcd"', simpleGrammar); + grammarParserParses('start:\r"abcd"', simpleGrammar); + grammarParserParses('start:\u2028"abcd"', simpleGrammar); + grammarParserParses('start:\u2029"abcd"', simpleGrammar); + }); + + /* Canonical eolChar is "\n". */ + test("parses eolChar", function() { + grammarParserParses('start:\n"abcd"', simpleGrammar); + grammarParserParses('start:\r"abcd"', simpleGrammar); + grammarParserParses('start:\u2028"abcd"', simpleGrammar); + grammarParserParses('start:\u2029"abcd"', simpleGrammar); + }); + + /* Canonical whitespace is " ". */ + test("parses whitespace", function() { + grammarParserParses('start:\t"abcd"', simpleGrammar); + grammarParserParses('start:\v"abcd"', simpleGrammar); + grammarParserParses('start:\f"abcd"', simpleGrammar); + grammarParserParses('start: "abcd"', simpleGrammar); + grammarParserParses('start:\xA0"abcd"', simpleGrammar); + grammarParserParses('start:\u1680"abcd"', simpleGrammar); + grammarParserParses('start:\u180E"abcd"', simpleGrammar); + grammarParserParses('start:\u2000"abcd"', simpleGrammar); + grammarParserParses('start:\u2001"abcd"', simpleGrammar); + grammarParserParses('start:\u2002"abcd"', simpleGrammar); + grammarParserParses('start:\u2003"abcd"', simpleGrammar); + grammarParserParses('start:\u2004"abcd"', simpleGrammar); + grammarParserParses('start:\u2005"abcd"', simpleGrammar); + grammarParserParses('start:\u2006"abcd"', simpleGrammar); + grammarParserParses('start:\u2007"abcd"', simpleGrammar); + grammarParserParses('start:\u2008"abcd"', simpleGrammar); + grammarParserParses('start:\u2009"abcd"', simpleGrammar); + grammarParserParses('start:\u200A"abcd"', simpleGrammar); + grammarParserParses('start:\u202F"abcd"', simpleGrammar); + grammarParserParses('start:\u205F"abcd"', simpleGrammar); + grammarParserParses('start:\u3000"abcd"', simpleGrammar); + }); +} + +})();