From ae89f5e46955e18f50a21f46e2001c2fb3caad0c Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 28 Mar 2014 11:26:15 +0100 Subject: [PATCH] PEG.js grammar: Change whitespace handling Before this commit, whitespace was handled at the lexical level by making tokens consume any whitespace coming after them. This was accomplished by appending |__| to every token rule. This commit changes whitespace handling to be more explicit. Tokens no longer consume whitespace coming after them and syntactic rules have to cope with it. While this slightly complicates the syntactic grammar, I think it's a cleaner way. Moreover, it is what JavaScript example grammar does. One small side-effect of thich change is that the grammar is now stand-alone (it doesn't require utils.js anymore). --- lib/parser.js | 1511 ++++++++++++++++++++++--------------------- spec/parser.spec.js | 156 +++-- src/parser.pegjs | 148 ++--- 3 files changed, 930 insertions(+), 885 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index f87d11c..13573be 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -38,8 +38,8 @@ module.exports = (function() { peg$c3 = function(initializer, rules) { return { type: "grammar", - initializer: initializer, - rules: rules + initializer: extractOptional(initializer, 0), + rules: extractList(rules, 0) }; }, peg$c4 = function(code) { @@ -55,46 +55,31 @@ module.exports = (function() { expression: displayName !== null ? { type: "named", - name: displayName, + name: displayName[0], expression: expression } : expression }; }, - peg$c6 = function(head, tail) { - if (tail.length > 0) { - var alternatives = [head].concat(utils.map( - tail, - function(element) { return element[1]; } - )); - return { - type: "choice", - alternatives: alternatives - }; - } else { - return head; - } + peg$c6 = function(first, rest) { + return rest.length > 0 + ? { type: "choice", alternatives: buildList(first, rest, 3) } + : first; }, - peg$c7 = function(elements, code) { - var expression = elements.length !== 1 - ? { - type: "sequence", - elements: elements - } - : elements[0]; + peg$c7 = function(first, rest, code) { + var expression = rest.length > 0 + ? { type: "sequence", elements: buildList(first, rest, 1) } + : first; return { type: "action", expression: expression, code: code }; }, - peg$c8 = function(elements) { - return elements.length !== 1 - ? { - type: "sequence", - elements: elements - } - : elements[0]; + peg$c8 = function(first, rest) { + return rest.length > 0 + ? { type: "sequence", elements: buildList(first, rest, 1) } + : first; }, peg$c9 = function(label, expression) { return { @@ -170,99 +155,84 @@ module.exports = (function() { peg$c29 = { type: "class", value: "[^{}]", description: "[^{}]" }, peg$c30 = "=", peg$c31 = { type: "literal", value: "=", description: "\"=\"" }, - peg$c32 = function() { return "="; }, - peg$c33 = ":", - peg$c34 = { type: "literal", value: ":", description: "\":\"" }, - peg$c35 = function() { return ":"; }, - peg$c36 = ";", - peg$c37 = { type: "literal", value: ";", description: "\";\"" }, - peg$c38 = function() { return ";"; }, - peg$c39 = "/", - peg$c40 = { type: "literal", value: "/", description: "\"/\"" }, - peg$c41 = function() { return "/"; }, - peg$c42 = "&", - peg$c43 = { type: "literal", value: "&", description: "\"&\"" }, - peg$c44 = function() { return "&"; }, - peg$c45 = "!", - peg$c46 = { type: "literal", value: "!", description: "\"!\"" }, - peg$c47 = function() { return "!"; }, - peg$c48 = "$", - peg$c49 = { type: "literal", value: "$", description: "\"$\"" }, - peg$c50 = function() { return "$"; }, - peg$c51 = "?", - peg$c52 = { type: "literal", value: "?", description: "\"?\"" }, - peg$c53 = function() { return "?"; }, - peg$c54 = "*", - peg$c55 = { type: "literal", value: "*", description: "\"*\"" }, - peg$c56 = function() { return "*"; }, - peg$c57 = "+", - peg$c58 = { type: "literal", value: "+", description: "\"+\"" }, - peg$c59 = function() { return "+"; }, - peg$c60 = "(", - peg$c61 = { type: "literal", value: "(", description: "\"(\"" }, - peg$c62 = function() { return "("; }, - peg$c63 = ")", - peg$c64 = { type: "literal", value: ")", description: "\")\"" }, - peg$c65 = function() { return ")"; }, - peg$c66 = ".", - peg$c67 = { type: "literal", value: ".", description: "\".\"" }, - peg$c68 = function() { return "."; }, - peg$c69 = { type: "other", description: "identifier" }, - peg$c70 = "_", - peg$c71 = { type: "literal", value: "_", description: "\"_\"" }, - peg$c72 = function(chars) { return chars; }, - peg$c73 = { type: "other", description: "literal" }, - peg$c74 = "i", - peg$c75 = { type: "literal", value: "i", description: "\"i\"" }, - peg$c76 = function(value, flags) { + peg$c32 = ":", + peg$c33 = { type: "literal", value: ":", description: "\":\"" }, + peg$c34 = ";", + peg$c35 = { type: "literal", value: ";", description: "\";\"" }, + peg$c36 = "/", + peg$c37 = { type: "literal", value: "/", description: "\"/\"" }, + peg$c38 = "&", + peg$c39 = { type: "literal", value: "&", description: "\"&\"" }, + peg$c40 = "!", + peg$c41 = { type: "literal", value: "!", description: "\"!\"" }, + peg$c42 = "$", + peg$c43 = { type: "literal", value: "$", description: "\"$\"" }, + peg$c44 = "?", + peg$c45 = { type: "literal", value: "?", description: "\"?\"" }, + peg$c46 = "*", + peg$c47 = { type: "literal", value: "*", description: "\"*\"" }, + peg$c48 = "+", + peg$c49 = { type: "literal", value: "+", description: "\"+\"" }, + peg$c50 = "(", + peg$c51 = { type: "literal", value: "(", description: "\"(\"" }, + peg$c52 = ")", + peg$c53 = { type: "literal", value: ")", description: "\")\"" }, + peg$c54 = ".", + peg$c55 = { type: "literal", value: ".", description: "\".\"" }, + peg$c56 = { type: "other", description: "identifier" }, + peg$c57 = "_", + peg$c58 = { type: "literal", value: "_", description: "\"_\"" }, + peg$c59 = { type: "other", description: "literal" }, + peg$c60 = "i", + peg$c61 = { type: "literal", value: "i", description: "\"i\"" }, + peg$c62 = function(value, flags) { return { type: "literal", value: value, ignoreCase: flags === "i" }; }, - peg$c77 = { type: "other", description: "string" }, - peg$c78 = function(string) { return string; }, - peg$c79 = "\"", - peg$c80 = { type: "literal", value: "\"", description: "\"\\\"\"" }, - peg$c81 = function(chars) { return chars.join(""); }, - peg$c82 = "\\", - peg$c83 = { type: "literal", value: "\\", description: "\"\\\\\"" }, - peg$c84 = { type: "any", description: "any character" }, - peg$c85 = function(char_) { return char_; }, - peg$c86 = "'", - peg$c87 = { type: "literal", value: "'", description: "\"'\"" }, - peg$c88 = { type: "other", description: "character class" }, - peg$c89 = "[", - peg$c90 = { type: "literal", value: "[", description: "\"[\"" }, - peg$c91 = "^", - peg$c92 = { type: "literal", value: "^", description: "\"^\"" }, - peg$c93 = "]", - peg$c94 = { type: "literal", value: "]", description: "\"]\"" }, - peg$c95 = function(inverted, parts, flags) { - return { - type: "class", - parts: parts, - rawText: text().replace(/\s+$/, ""), - inverted: inverted === "^", - ignoreCase: flags === "i" - }; - }, - peg$c96 = function(class_) { return class_; }, - peg$c97 = "-", - peg$c98 = { type: "literal", value: "-", description: "\"-\"" }, - peg$c99 = function(begin, end) { + peg$c63 = { type: "other", description: "string" }, + peg$c64 = function(string) { return string; }, + peg$c65 = "\"", + peg$c66 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c67 = function(chars) { return chars.join(""); }, + peg$c68 = "\\", + peg$c69 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c70 = { type: "any", description: "any character" }, + peg$c71 = function(char_) { return char_; }, + peg$c72 = "'", + peg$c73 = { type: "literal", value: "'", description: "\"'\"" }, + peg$c74 = { type: "other", description: "character class" }, + peg$c75 = "[", + peg$c76 = { type: "literal", value: "[", description: "\"[\"" }, + peg$c77 = "^", + peg$c78 = { type: "literal", value: "^", description: "\"^\"" }, + peg$c79 = "]", + peg$c80 = { type: "literal", value: "]", description: "\"]\"" }, + peg$c81 = function(inverted, parts, flags) { + return { + type: "class", + parts: parts, + rawText: text().replace(/\s+$/, ""), + inverted: inverted === "^", + ignoreCase: flags === "i" + }; + }, + peg$c82 = "-", + peg$c83 = { type: "literal", value: "-", description: "\"-\"" }, + peg$c84 = function(begin, end) { if (begin.charCodeAt(0) > end.charCodeAt(0)) { error("Invalid character range: " + text() + "."); } return [begin, end]; }, - peg$c100 = "x", - peg$c101 = { type: "literal", value: "x", description: "\"x\"" }, - peg$c102 = "u", - peg$c103 = { type: "literal", value: "u", description: "\"u\"" }, - peg$c104 = function(char_) { + peg$c85 = "x", + peg$c86 = { type: "literal", value: "x", description: "\"x\"" }, + peg$c87 = "u", + peg$c88 = { type: "literal", value: "u", description: "\"u\"" }, + peg$c89 = function(char_) { return char_ .replace("b", "\b") .replace("f", "\f") @@ -271,48 +241,48 @@ module.exports = (function() { .replace("t", "\t") .replace("v", "\x0B"); // IE does not recognize "\v". }, - peg$c105 = "\\0", - peg$c106 = { type: "literal", value: "\\0", description: "\"\\\\0\"" }, - peg$c107 = function() { return "\x00"; }, - peg$c108 = "\\x", - peg$c109 = { type: "literal", value: "\\x", description: "\"\\\\x\"" }, - peg$c110 = function(digits) { + peg$c90 = "\\0", + peg$c91 = { type: "literal", value: "\\0", description: "\"\\\\0\"" }, + peg$c92 = function() { return "\x00"; }, + peg$c93 = "\\x", + peg$c94 = { type: "literal", value: "\\x", description: "\"\\\\x\"" }, + peg$c95 = function(digits) { return String.fromCharCode(parseInt(digits, 16)); }, - peg$c111 = "\\u", - peg$c112 = { type: "literal", value: "\\u", description: "\"\\\\u\"" }, - peg$c113 = function(eol) { return ""; }, - peg$c114 = /^[0-9]/, - peg$c115 = { type: "class", value: "[0-9]", description: "[0-9]" }, - peg$c116 = /^[0-9a-fA-F]/, - peg$c117 = { type: "class", value: "[0-9a-fA-F]", description: "[0-9a-fA-F]" }, - peg$c118 = /^[a-z]/, - peg$c119 = { type: "class", value: "[a-z]", description: "[a-z]" }, - peg$c120 = /^[A-Z]/, - peg$c121 = { type: "class", value: "[A-Z]", description: "[A-Z]" }, - peg$c122 = { type: "other", description: "comment" }, - peg$c123 = "//", - peg$c124 = { type: "literal", value: "//", description: "\"//\"" }, - peg$c125 = "/*", - peg$c126 = { type: "literal", value: "/*", description: "\"/*\"" }, - peg$c127 = "*/", - peg$c128 = { type: "literal", value: "*/", description: "\"*/\"" }, - peg$c129 = { type: "other", description: "end of line" }, - peg$c130 = "\n", - peg$c131 = { type: "literal", value: "\n", description: "\"\\n\"" }, - peg$c132 = "\r\n", - peg$c133 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" }, - peg$c134 = "\r", - peg$c135 = { type: "literal", value: "\r", description: "\"\\r\"" }, - peg$c136 = "\u2028", - peg$c137 = { type: "literal", value: "\u2028", description: "\"\\u2028\"" }, - peg$c138 = "\u2029", - peg$c139 = { type: "literal", value: "\u2029", description: "\"\\u2029\"" }, - peg$c140 = /^[\n\r\u2028\u2029]/, - peg$c141 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" }, - peg$c142 = { type: "other", description: "whitespace" }, - peg$c143 = /^[ \t\x0B\f\xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/, - peg$c144 = { type: "class", value: "[ \\t\\v\\f\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]", description: "[ \\t\\v\\f\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]" }, + peg$c96 = "\\u", + peg$c97 = { type: "literal", value: "\\u", description: "\"\\\\u\"" }, + peg$c98 = function(eol) { return ""; }, + peg$c99 = /^[0-9]/, + peg$c100 = { type: "class", value: "[0-9]", description: "[0-9]" }, + peg$c101 = /^[0-9a-fA-F]/, + peg$c102 = { type: "class", value: "[0-9a-fA-F]", description: "[0-9a-fA-F]" }, + peg$c103 = /^[a-z]/, + peg$c104 = { type: "class", value: "[a-z]", description: "[a-z]" }, + peg$c105 = /^[A-Z]/, + peg$c106 = { type: "class", value: "[A-Z]", description: "[A-Z]" }, + peg$c107 = { type: "other", description: "comment" }, + peg$c108 = "//", + peg$c109 = { type: "literal", value: "//", description: "\"//\"" }, + peg$c110 = "/*", + peg$c111 = { type: "literal", value: "/*", description: "\"/*\"" }, + peg$c112 = "*/", + peg$c113 = { type: "literal", value: "*/", description: "\"*/\"" }, + peg$c114 = { type: "other", description: "end of line" }, + peg$c115 = "\n", + peg$c116 = { type: "literal", value: "\n", description: "\"\\n\"" }, + peg$c117 = "\r\n", + peg$c118 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" }, + peg$c119 = "\r", + peg$c120 = { type: "literal", value: "\r", description: "\"\\r\"" }, + peg$c121 = "\u2028", + peg$c122 = { type: "literal", value: "\u2028", description: "\"\\u2028\"" }, + peg$c123 = "\u2029", + peg$c124 = { type: "literal", value: "\u2029", description: "\"\\u2029\"" }, + peg$c125 = /^[\n\r\u2028\u2029]/, + peg$c126 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" }, + peg$c127 = { type: "other", description: "whitespace" }, + peg$c128 = /^[ \t\x0B\f\xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/, + peg$c129 = { type: "class", value: "[ \\t\\v\\f\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]", description: "[ \\t\\v\\f\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]" }, peg$currPos = 0, peg$reportedPos = 0, @@ -481,22 +451,64 @@ module.exports = (function() { } function peg$parseGrammar() { - var s0, s1, s2, s3, s4; + var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; s1 = peg$parse__(); if (s1 !== peg$FAILED) { - s2 = peg$parseInitializer(); + s2 = peg$currPos; + s3 = peg$parseInitializer(); + if (s3 !== peg$FAILED) { + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s3 = [s3, s4]; + s2 = s3; + } else { + peg$currPos = s2; + s2 = peg$c0; + } + } else { + peg$currPos = s2; + s2 = peg$c0; + } if (s2 === peg$FAILED) { s2 = peg$c1; } if (s2 !== peg$FAILED) { s3 = []; - s4 = peg$parseRule(); + s4 = peg$currPos; + s5 = peg$parseRule(); + if (s5 !== peg$FAILED) { + s6 = peg$parse__(); + if (s6 !== peg$FAILED) { + s5 = [s5, s6]; + s4 = s5; + } else { + peg$currPos = s4; + s4 = peg$c0; + } + } else { + peg$currPos = s4; + s4 = peg$c0; + } if (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) { s3.push(s4); - s4 = peg$parseRule(); + s4 = peg$currPos; + s5 = peg$parseRule(); + if (s5 !== peg$FAILED) { + s6 = peg$parse__(); + if (s6 !== peg$FAILED) { + s5 = [s5, s6]; + s4 = s5; + } else { + peg$currPos = s4; + s4 = peg$c0; + } + } else { + peg$currPos = s4; + s4 = peg$c0; + } } } else { s3 = peg$c0; @@ -522,12 +534,26 @@ module.exports = (function() { } function peg$parseInitializer() { - var s0, s1, s2; + var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = peg$parseAction(); if (s1 !== peg$FAILED) { - s2 = peg$parseSemicolon(); + s2 = peg$currPos; + s3 = peg$parse__(); + if (s3 !== peg$FAILED) { + s4 = peg$parseSemicolon(); + if (s4 !== peg$FAILED) { + s3 = [s3, s4]; + s2 = s3; + } else { + peg$currPos = s2; + s2 = peg$c0; + } + } else { + peg$currPos = s2; + s2 = peg$c0; + } if (s2 === peg$FAILED) { s2 = peg$c1; } @@ -548,28 +574,68 @@ module.exports = (function() { } function peg$parseRule() { - var s0, s1, s2, s3, s4, s5; + var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; s0 = peg$currPos; s1 = peg$parseIdentifier(); if (s1 !== peg$FAILED) { - s2 = peg$parseString(); - if (s2 === peg$FAILED) { - s2 = peg$c1; - } + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - s3 = peg$parseEquals(); + s3 = peg$currPos; + s4 = peg$parseString(); + if (s4 !== peg$FAILED) { + s5 = peg$parse__(); + if (s5 !== peg$FAILED) { + s4 = [s4, s5]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } + if (s3 === peg$FAILED) { + s3 = peg$c1; + } if (s3 !== peg$FAILED) { - s4 = peg$parseChoice(); + s4 = peg$parseEquals(); if (s4 !== peg$FAILED) { - s5 = peg$parseSemicolon(); - if (s5 === peg$FAILED) { - s5 = peg$c1; - } + s5 = peg$parse__(); if (s5 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c5(s1, s2, s4); - s0 = s1; + s6 = peg$parseChoice(); + if (s6 !== peg$FAILED) { + s7 = peg$currPos; + s8 = peg$parse__(); + if (s8 !== peg$FAILED) { + s9 = peg$parseSemicolon(); + if (s9 !== peg$FAILED) { + s8 = [s8, s9]; + s7 = s8; + } else { + peg$currPos = s7; + s7 = peg$c0; + } + } else { + peg$currPos = s7; + s7 = peg$c0; + } + if (s7 === peg$FAILED) { + s7 = peg$c1; + } + if (s7 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c5(s1, s3, s6); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -595,19 +661,31 @@ module.exports = (function() { } function peg$parseChoice() { - var s0, s1, s2, s3, s4, s5; + var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$parseSequence(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; - s4 = peg$parseSlash(); + s4 = peg$parse__(); if (s4 !== peg$FAILED) { - s5 = peg$parseSequence(); + s5 = peg$parseSlash(); if (s5 !== peg$FAILED) { - s4 = [s4, s5]; - s3 = s4; + s6 = peg$parse__(); + if (s6 !== peg$FAILED) { + s7 = peg$parseSequence(); + if (s7 !== peg$FAILED) { + s4 = [s4, s5, s6, s7]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } } else { peg$currPos = s3; s3 = peg$c0; @@ -619,12 +697,24 @@ module.exports = (function() { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; - s4 = peg$parseSlash(); + s4 = peg$parse__(); if (s4 !== peg$FAILED) { - s5 = peg$parseSequence(); + s5 = peg$parseSlash(); if (s5 !== peg$FAILED) { - s4 = [s4, s5]; - s3 = s4; + s6 = peg$parse__(); + if (s6 !== peg$FAILED) { + s7 = peg$parseSequence(); + if (s7 !== peg$FAILED) { + s4 = [s4, s5, s6, s7]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } } else { peg$currPos = s3; s3 = peg$c0; @@ -651,25 +741,61 @@ module.exports = (function() { } function peg$parseSequence() { - var s0, s1, s2; + var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - s1 = []; - s2 = peg$parseLabeled(); - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseLabeled(); - } - } else { - s1 = peg$c0; - } + s1 = peg$parseLabeled(); if (s1 !== peg$FAILED) { - s2 = peg$parseAction(); + s2 = []; + s3 = peg$currPos; + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s5 = peg$parseLabeled(); + if (s5 !== peg$FAILED) { + s4 = [s4, s5]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$currPos; + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s5 = peg$parseLabeled(); + if (s5 !== peg$FAILED) { + s4 = [s4, s5]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c7(s1, s2); - s0 = s1; + s3 = peg$parse__(); + if (s3 !== peg$FAILED) { + s4 = peg$parseAction(); + if (s4 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c7(s1, s2, s4); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -680,39 +806,84 @@ module.exports = (function() { } if (s0 === peg$FAILED) { s0 = peg$currPos; - s1 = []; - s2 = peg$parseLabeled(); - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseLabeled(); + s1 = peg$parseLabeled(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s5 = peg$parseLabeled(); + if (s5 !== peg$FAILED) { + s4 = [s4, s5]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$currPos; + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s5 = peg$parseLabeled(); + if (s5 !== peg$FAILED) { + s4 = [s4, s5]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } else { + peg$currPos = s3; + s3 = peg$c0; + } + } + if (s2 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c8(s1, s2); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; } } else { - s1 = peg$c0; - } - if (s1 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c8(s1); + peg$currPos = s0; + s0 = peg$c0; } - s0 = s1; } return s0; } function peg$parseLabeled() { - var s0, s1, s2, s3; + var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parseIdentifier(); if (s1 !== peg$FAILED) { - s2 = peg$parseColon(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - s3 = peg$parsePrefixed(); + s3 = peg$parseColon(); if (s3 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c9(s1, s3); - s0 = s1; + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s5 = peg$parsePrefixed(); + if (s5 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c9(s1, s5); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -733,16 +904,22 @@ module.exports = (function() { } function peg$parsePrefixed() { - var s0, s1, s2; + var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parseDollar(); if (s1 !== peg$FAILED) { - s2 = peg$parseSuffixed(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c10(s2); - s0 = s1; + s3 = peg$parseSuffixed(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c10(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -755,11 +932,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseAnd(); if (s1 !== peg$FAILED) { - s2 = peg$parseAction(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c11(s2); - s0 = s1; + s3 = peg$parseAction(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c11(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -772,11 +955,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseAnd(); if (s1 !== peg$FAILED) { - s2 = peg$parseSuffixed(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c12(s2); - s0 = s1; + s3 = peg$parseSuffixed(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c12(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -789,11 +978,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseNot(); if (s1 !== peg$FAILED) { - s2 = peg$parseAction(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c13(s2); - s0 = s1; + s3 = peg$parseAction(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c13(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -806,11 +1001,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseNot(); if (s1 !== peg$FAILED) { - s2 = peg$parseSuffixed(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c14(s2); - s0 = s1; + s3 = peg$parseSuffixed(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c14(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -831,16 +1032,22 @@ module.exports = (function() { } function peg$parseSuffixed() { - var s0, s1, s2; + var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parsePrimary(); if (s1 !== peg$FAILED) { - s2 = peg$parseQuestion(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c15(s1); - s0 = s1; + s3 = peg$parseQuestion(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c15(s1); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -853,11 +1060,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parsePrimary(); if (s1 !== peg$FAILED) { - s2 = peg$parseStar(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c16(s1); - s0 = s1; + s3 = peg$parseStar(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c16(s1); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -870,11 +1083,17 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parsePrimary(); if (s1 !== peg$FAILED) { - s2 = peg$parsePlus(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c17(s1); - s0 = s1; + s3 = peg$parsePlus(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c17(s1); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -893,7 +1112,7 @@ module.exports = (function() { } function peg$parsePrimary() { - var s0, s1, s2, s3, s4, s5; + var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$parseIdentifier(); @@ -901,15 +1120,35 @@ module.exports = (function() { s2 = peg$currPos; peg$silentFails++; s3 = peg$currPos; - s4 = peg$parseString(); - if (s4 === peg$FAILED) { - s4 = peg$c1; - } + s4 = peg$parse__(); if (s4 !== peg$FAILED) { - s5 = peg$parseEquals(); + s5 = peg$currPos; + s6 = peg$parseString(); + if (s6 !== peg$FAILED) { + s7 = peg$parse__(); + if (s7 !== peg$FAILED) { + s6 = [s6, s7]; + s5 = s6; + } else { + peg$currPos = s5; + s5 = peg$c0; + } + } else { + peg$currPos = s5; + s5 = peg$c0; + } + if (s5 === peg$FAILED) { + s5 = peg$c1; + } if (s5 !== peg$FAILED) { - s4 = [s4, s5]; - s3 = s4; + s6 = peg$parseEquals(); + if (s6 !== peg$FAILED) { + s4 = [s4, s5, s6]; + s3 = s4; + } else { + peg$currPos = s3; + s3 = peg$c0; + } } else { peg$currPos = s3; s3 = peg$c0; @@ -953,13 +1192,25 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$parseLparen(); if (s1 !== peg$FAILED) { - s2 = peg$parseChoice(); + s2 = peg$parse__(); if (s2 !== peg$FAILED) { - s3 = peg$parseRparen(); + s3 = peg$parseChoice(); if (s3 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c21(s2); - s0 = s1; + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + s5 = peg$parseRparen(); + if (s5 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c21(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -1097,470 +1348,260 @@ module.exports = (function() { } function peg$parseEquals() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 61) { - s1 = peg$c30; + s0 = peg$c30; peg$currPos++; } else { - s1 = peg$FAILED; + s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c31); } } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c32(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } return s0; } function peg$parseColon() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 58) { - s1 = peg$c33; + s0 = peg$c32; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c34); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c35(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c33); } } return s0; } function peg$parseSemicolon() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 59) { - s1 = peg$c36; + s0 = peg$c34; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c37); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c38(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c35); } } return s0; } function peg$parseSlash() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 47) { - s1 = peg$c39; + s0 = peg$c36; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c40); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c41(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c37); } } return s0; } function peg$parseAnd() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 38) { - s1 = peg$c42; + s0 = peg$c38; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c43); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c44(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c39); } } return s0; } function peg$parseNot() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 33) { - s1 = peg$c45; + s0 = peg$c40; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c46); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c47(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c41); } } return s0; } function peg$parseDollar() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 36) { - s1 = peg$c48; + s0 = peg$c42; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c49); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c50(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c43); } } return s0; } - function peg$parseQuestion() { - var s0, s1, s2; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 63) { - s1 = peg$c51; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c52); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c53(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } + function peg$parseQuestion() { + var s0; + + if (input.charCodeAt(peg$currPos) === 63) { + s0 = peg$c44; + peg$currPos++; } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c45); } } return s0; } function peg$parseStar() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 42) { - s1 = peg$c54; + s0 = peg$c46; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c55); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c56(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c47); } } return s0; } function peg$parsePlus() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 43) { - s1 = peg$c57; + s0 = peg$c48; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c58); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c59(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c49); } } return s0; } function peg$parseLparen() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c60; + s0 = peg$c50; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c62(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c51); } } return s0; } function peg$parseRparen() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 41) { - s1 = peg$c63; + s0 = peg$c52; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c64); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c65(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c53); } } return s0; } function peg$parseDot() { - var s0, s1, s2; + var s0; - s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { - s1 = peg$c66; + s0 = peg$c54; peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c67); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c68(); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c55); } } return s0; } function peg$parseIdentifier() { - var s0, s1, s2, s3, s4, s5; + var s0, s1, s2, s3, s4; peg$silentFails++; s0 = peg$currPos; s1 = peg$currPos; - s2 = peg$currPos; - s3 = peg$parseLetter(); - if (s3 === peg$FAILED) { + s2 = peg$parseLetter(); + if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s3 = peg$c70; + s2 = peg$c57; peg$currPos++; } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c71); } + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c58); } } } - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseLetter(); - if (s5 === peg$FAILED) { - s5 = peg$parseDigit(); - if (s5 === peg$FAILED) { + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parseLetter(); + if (s4 === peg$FAILED) { + s4 = peg$parseDigit(); + if (s4 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s5 = peg$c70; + s4 = peg$c57; peg$currPos++; } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c71); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c58); } } } } - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseLetter(); - if (s5 === peg$FAILED) { - s5 = peg$parseDigit(); - if (s5 === peg$FAILED) { + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseLetter(); + if (s4 === peg$FAILED) { + s4 = peg$parseDigit(); + if (s4 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s5 = peg$c70; + s4 = peg$c57; peg$currPos++; } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c71); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c58); } } } } } - if (s4 !== peg$FAILED) { - s3 = [s3, s4]; - s2 = s3; + if (s3 !== peg$FAILED) { + s2 = [s2, s3]; + s1 = s2; } else { - peg$currPos = s2; - s2 = peg$c0; + peg$currPos = s1; + s1 = peg$c0; } } else { - peg$currPos = s2; - s2 = peg$c0; - } - if (s2 !== peg$FAILED) { - s2 = input.substring(s1, peg$currPos); + peg$currPos = s1; + s1 = peg$c0; } - s1 = s2; if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c72(s1); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + s1 = input.substring(s0, peg$currPos); } + s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c56); } } return s0; } function peg$parseLiteral() { - var s0, s1, s2, s3; + var s0, s1, s2; peg$silentFails++; s0 = peg$currPos; @@ -1570,25 +1611,19 @@ module.exports = (function() { } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { - s2 = peg$c74; + s2 = peg$c60; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c75); } + if (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s2 === peg$FAILED) { s2 = peg$c1; } if (s2 !== peg$FAILED) { - s3 = peg$parse__(); - if (s3 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c76(s1, s2); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } + peg$reportedPos = s0; + s1 = peg$c62(s1, s2); + s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; @@ -1600,14 +1635,14 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c73); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } return s0; } function peg$parseString() { - var s0, s1, s2; + var s0, s1; peg$silentFails++; s0 = peg$currPos; @@ -1616,23 +1651,14 @@ module.exports = (function() { s1 = peg$parseSingleQuotedString(); } if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c78(s1); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; + peg$reportedPos = s0; + s1 = peg$c64(s1); } + s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c77); } + if (peg$silentFails === 0) { peg$fail(peg$c63); } } return s0; @@ -1643,11 +1669,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c79; + s1 = peg$c65; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1658,15 +1684,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c79; + s3 = peg$c65; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c81(s2); + s1 = peg$c67(s2); s0 = s1; } else { peg$currPos = s0; @@ -1714,19 +1740,19 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c79; + s2 = peg$c65; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c66); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c82; + s2 = peg$c68; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s2 === peg$FAILED) { s2 = peg$parseEOLChar(); @@ -1745,11 +1771,11 @@ module.exports = (function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c85(s2); + s1 = peg$c71(s2); s0 = s1; } else { peg$currPos = s0; @@ -1768,11 +1794,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { - s1 = peg$c86; + s1 = peg$c72; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c87); } + if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1783,15 +1809,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { - s3 = peg$c86; + s3 = peg$c72; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c87); } + if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c81(s2); + s1 = peg$c67(s2); s0 = s1; } else { peg$currPos = s0; @@ -1839,19 +1865,19 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 39) { - s2 = peg$c86; + s2 = peg$c72; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c87); } + if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c82; + s2 = peg$c68; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s2 === peg$FAILED) { s2 = peg$parseEOLChar(); @@ -1870,11 +1896,11 @@ module.exports = (function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c85(s2); + s1 = peg$c71(s2); s0 = s1; } else { peg$currPos = s0; @@ -1889,91 +1915,76 @@ module.exports = (function() { } function peg$parseClass() { - var s0, s1, s2, s3, s4, s5, s6; + var s0, s1, s2, s3, s4, s5; peg$silentFails++; s0 = peg$currPos; - s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { - s2 = peg$c89; + s1 = peg$c75; peg$currPos++; } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c90); } + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c76); } } - if (s2 !== peg$FAILED) { + if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 94) { - s3 = peg$c91; + s2 = peg$c77; peg$currPos++; } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c92); } + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c78); } } - if (s3 === peg$FAILED) { - s3 = peg$c1; + if (s2 === peg$FAILED) { + s2 = peg$c1; } - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseClassCharacterRange(); - if (s5 === peg$FAILED) { - s5 = peg$parseBracketDelimitedCharacter(); + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parseClassCharacterRange(); + if (s4 === peg$FAILED) { + s4 = peg$parseBracketDelimitedCharacter(); } - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseClassCharacterRange(); - if (s5 === peg$FAILED) { - s5 = peg$parseBracketDelimitedCharacter(); + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseClassCharacterRange(); + if (s4 === peg$FAILED) { + s4 = peg$parseBracketDelimitedCharacter(); } } - if (s4 !== peg$FAILED) { + if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { - s5 = peg$c93; + s4 = peg$c79; peg$currPos++; } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c94); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c80); } } - if (s5 !== peg$FAILED) { + if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { - s6 = peg$c74; + s5 = peg$c60; peg$currPos++; } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c75); } + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c61); } } - if (s6 === peg$FAILED) { - s6 = peg$c1; + if (s5 === peg$FAILED) { + s5 = peg$c1; } - if (s6 !== peg$FAILED) { - peg$reportedPos = s1; - s2 = peg$c95(s3, s4, s6); - s1 = s2; + if (s5 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c81(s2, s3, s5); + s0 = s1; } else { - peg$currPos = s1; - s1 = peg$c0; + peg$currPos = s0; + s0 = peg$c0; } } else { - peg$currPos = s1; - s1 = peg$c0; + peg$currPos = s0; + s0 = peg$c0; } } else { - peg$currPos = s1; - s1 = peg$c0; + peg$currPos = s0; + s0 = peg$c0; } - } else { - peg$currPos = s1; - s1 = peg$c0; - } - } else { - peg$currPos = s1; - s1 = peg$c0; - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c96(s1); - s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; @@ -1985,7 +1996,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c88); } + if (peg$silentFails === 0) { peg$fail(peg$c74); } } return s0; @@ -1998,17 +2009,17 @@ module.exports = (function() { s1 = peg$parseBracketDelimitedCharacter(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s2 = peg$c97; + s2 = peg$c82; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c98); } + if (peg$silentFails === 0) { peg$fail(peg$c83); } } if (s2 !== peg$FAILED) { s3 = peg$parseBracketDelimitedCharacter(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c99(s1, s3); + s1 = peg$c84(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -2056,19 +2067,19 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 93) { - s2 = peg$c93; + s2 = peg$c79; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c94); } + if (peg$silentFails === 0) { peg$fail(peg$c80); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c82; + s2 = peg$c68; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s2 === peg$FAILED) { s2 = peg$parseEOLChar(); @@ -2087,11 +2098,11 @@ module.exports = (function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c85(s2); + s1 = peg$c71(s2); s0 = s1; } else { peg$currPos = s0; @@ -2110,11 +2121,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c82; + s1 = peg$c68; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2122,19 +2133,19 @@ module.exports = (function() { s3 = peg$parseDigit(); if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 120) { - s3 = peg$c100; + s3 = peg$c85; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 117) { - s3 = peg$c102; + s3 = peg$c87; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c103); } + if (peg$silentFails === 0) { peg$fail(peg$c88); } } if (s3 === peg$FAILED) { s3 = peg$parseEOLChar(); @@ -2154,11 +2165,11 @@ module.exports = (function() { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c104(s3); + s1 = peg$c89(s3); s0 = s1; } else { peg$currPos = s0; @@ -2180,12 +2191,12 @@ module.exports = (function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c105) { - s1 = peg$c105; + if (input.substr(peg$currPos, 2) === peg$c90) { + s1 = peg$c90; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c106); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2200,7 +2211,7 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c107(); + s1 = peg$c92(); s0 = s1; } else { peg$currPos = s0; @@ -2218,12 +2229,12 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c108) { - s1 = peg$c108; + if (input.substr(peg$currPos, 2) === peg$c93) { + s1 = peg$c93; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c109); } + if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2248,7 +2259,7 @@ module.exports = (function() { s2 = s3; if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c110(s2); + s1 = peg$c95(s2); s0 = s1; } else { peg$currPos = s0; @@ -2266,12 +2277,12 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c111) { - s1 = peg$c111; + if (input.substr(peg$currPos, 2) === peg$c96) { + s1 = peg$c96; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + if (peg$silentFails === 0) { peg$fail(peg$c97); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2308,7 +2319,7 @@ module.exports = (function() { s2 = s3; if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c110(s2); + s1 = peg$c95(s2); s0 = s1; } else { peg$currPos = s0; @@ -2327,17 +2338,17 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c82; + s1 = peg$c68; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s1 !== peg$FAILED) { s2 = peg$parseEOL(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c113(s2); + s1 = peg$c98(s2); s0 = s1; } else { peg$currPos = s0; @@ -2354,12 +2365,12 @@ module.exports = (function() { function peg$parseDigit() { var s0; - if (peg$c114.test(input.charAt(peg$currPos))) { + if (peg$c99.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c115); } + if (peg$silentFails === 0) { peg$fail(peg$c100); } } return s0; @@ -2368,12 +2379,12 @@ module.exports = (function() { function peg$parseHexDigit() { var s0; - if (peg$c116.test(input.charAt(peg$currPos))) { + if (peg$c101.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c117); } + if (peg$silentFails === 0) { peg$fail(peg$c102); } } return s0; @@ -2393,12 +2404,12 @@ module.exports = (function() { function peg$parseLowerCaseLetter() { var s0; - if (peg$c118.test(input.charAt(peg$currPos))) { + if (peg$c103.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c119); } + if (peg$silentFails === 0) { peg$fail(peg$c104); } } return s0; @@ -2407,12 +2418,12 @@ module.exports = (function() { function peg$parseUpperCaseLetter() { var s0; - if (peg$c120.test(input.charAt(peg$currPos))) { + if (peg$c105.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c121); } + if (peg$silentFails === 0) { peg$fail(peg$c106); } } return s0; @@ -2454,7 +2465,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c122); } + if (peg$silentFails === 0) { peg$fail(peg$c107); } } return s0; @@ -2464,12 +2475,12 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c123) { - s1 = peg$c123; + if (input.substr(peg$currPos, 2) === peg$c108) { + s1 = peg$c108; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c124); } + if (peg$silentFails === 0) { peg$fail(peg$c109); } } if (s1 !== peg$FAILED) { s2 = []; @@ -2490,7 +2501,7 @@ module.exports = (function() { peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; @@ -2522,7 +2533,7 @@ module.exports = (function() { peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; @@ -2555,24 +2566,24 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c125) { - s1 = peg$c125; + if (input.substr(peg$currPos, 2) === peg$c110) { + s1 = peg$c110; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c126); } + if (peg$silentFails === 0) { peg$fail(peg$c111); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c127) { - s5 = peg$c127; + if (input.substr(peg$currPos, 2) === peg$c112) { + s5 = peg$c112; peg$currPos += 2; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c128); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } peg$silentFails--; if (s5 === peg$FAILED) { @@ -2587,7 +2598,7 @@ module.exports = (function() { peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; @@ -2605,12 +2616,12 @@ module.exports = (function() { s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c127) { - s5 = peg$c127; + if (input.substr(peg$currPos, 2) === peg$c112) { + s5 = peg$c112; peg$currPos += 2; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c128); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } peg$silentFails--; if (s5 === peg$FAILED) { @@ -2625,7 +2636,7 @@ module.exports = (function() { peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s5 !== peg$FAILED) { s4 = [s4, s5]; @@ -2640,12 +2651,12 @@ module.exports = (function() { } } if (s2 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c127) { - s3 = peg$c127; + if (input.substr(peg$currPos, 2) === peg$c112) { + s3 = peg$c112; peg$currPos += 2; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c128); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; @@ -2671,43 +2682,43 @@ module.exports = (function() { peg$silentFails++; if (input.charCodeAt(peg$currPos) === 10) { - s0 = peg$c130; + s0 = peg$c115; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c131); } + if (peg$silentFails === 0) { peg$fail(peg$c116); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c132) { - s0 = peg$c132; + if (input.substr(peg$currPos, 2) === peg$c117) { + s0 = peg$c117; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c133); } + if (peg$silentFails === 0) { peg$fail(peg$c118); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 13) { - s0 = peg$c134; + s0 = peg$c119; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c135); } + if (peg$silentFails === 0) { peg$fail(peg$c120); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8232) { - s0 = peg$c136; + s0 = peg$c121; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c137); } + if (peg$silentFails === 0) { peg$fail(peg$c122); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8233) { - s0 = peg$c138; + s0 = peg$c123; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c139); } + if (peg$silentFails === 0) { peg$fail(peg$c124); } } } } @@ -2716,7 +2727,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c129); } + if (peg$silentFails === 0) { peg$fail(peg$c114); } } return s0; @@ -2725,12 +2736,12 @@ module.exports = (function() { function peg$parseEOLChar() { var s0; - if (peg$c140.test(input.charAt(peg$currPos))) { + if (peg$c125.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c141); } + if (peg$silentFails === 0) { peg$fail(peg$c126); } } return s0; @@ -2740,24 +2751,40 @@ module.exports = (function() { var s0, s1; peg$silentFails++; - if (peg$c143.test(input.charAt(peg$currPos))) { + if (peg$c128.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c144); } + if (peg$silentFails === 0) { peg$fail(peg$c129); } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c142); } + if (peg$silentFails === 0) { peg$fail(peg$c127); } } return s0; } - var utils = require("./utils"); + function extractOptional(optional, index) { + return optional ? optional[index] : null; + } + + function extractList(list, index) { + var result = new Array(list.length), i; + + for (i = 0; i < list.length; i++) { + result[i] = list[i][index]; + } + + return result; + } + + function buildList(first, rest, index) { + return [first].concat(extractList(rest, index)); + } peg$result = peg$startRuleFunction(); diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 7424ccf..f14e7af 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -1,25 +1,34 @@ describe("PEG.js grammar parser", function() { var trivialGrammar, - literalAbcd = { type: "literal", value: "abcd", ignoreCase: false }, - literalEfgh = { type: "literal", value: "efgh", ignoreCase: false }, - literalIjkl = { type: "literal", value: "ijkl", ignoreCase: false }, - optionalLiteral = { type: "optional", expression: literalAbcd }, - simpleNotLiteral = { type: "simple_not", expression: literalAbcd }, - labeledAbcd = { type: "labeled", label: "a", expression: literalAbcd }, - labeledEfgh = { type: "labeled", label: "b", expression: literalEfgh }, - labeledIjkl = { type: "labeled", label: "c", expression: literalIjkl }, - sequenceOfLiterals = { + literalAbcd = { type: "literal", value: "abcd", ignoreCase: false }, + literalEfgh = { type: "literal", value: "efgh", ignoreCase: false }, + literalIjkl = { type: "literal", value: "ijkl", ignoreCase: false }, + optionalLiteral = { type: "optional", expression: literalAbcd }, + zeroOrMoreLiteral = { type: "zero_or_more", expression: literalAbcd }, + oneOrMoreLiteral = { type: "one_or_more", expression: literalAbcd }, + simpleNotLiteral = { type: "simple_not", expression: literalAbcd }, + textOptionalLiteral = { type: "text", expression: optionalLiteral }, + simpleAndOptionalLiteral = { type: "simple_and", expression: optionalLiteral }, + simpleNotOptionalLiteral = { type: "simple_not", expression: optionalLiteral }, + semanticAnd = { type: "semantic_and", code: " code " }, + semanticNot = { type: "semantic_not", code: " code " }, + labeledAbcd = { type: "labeled", label: "a", expression: literalAbcd }, + labeledEfgh = { type: "labeled", label: "b", expression: literalEfgh }, + labeledIjkl = { type: "labeled", label: "c", expression: literalIjkl }, + labeledSimpleNotLiteral = { type: "labeled", label: "label", expression: simpleNotLiteral }, + sequenceOfLiterals = { type: "sequence", elements: [literalAbcd, literalEfgh, literalIjkl] }, - sequenceOfLabeleds = { + sequenceOfLabeleds = { type: "sequence", elements: [labeledAbcd, labeledEfgh, labeledIjkl] }, - choiceOfLiterals = { + choiceOfLiterals = { type: "choice", alternatives: [literalAbcd, literalEfgh, literalIjkl] - }; + }, + namedChoiceOfLiterals = { type: "named", name: "start rule", expression: choiceOfLiterals }; function oneRuleGrammar(expression) { var initializer = arguments.length > 1 ? arguments[1] : null; @@ -192,7 +201,7 @@ describe("PEG.js grammar parser", function() { }); expect('{ code } start = "abcd"' ).toParseAs(grammar); - expect('{ code }; start = "abcd"').toParseAs(grammar); + expect('{ code }\n; start = "abcd"').toParseAs(grammar); }); /* Canonical Rule is "a: \"abcd\"". */ @@ -200,14 +209,19 @@ describe("PEG.js grammar parser", function() { expect('start = "abcd" / "efgh" / "ijkl"').toParseAs( oneRuleGrammar(choiceOfLiterals) ); + expect('start\n= "abcd" / "efgh" / "ijkl"').toParseAs( + oneRuleGrammar(choiceOfLiterals) + ); + expect('start =\n"abcd" / "efgh" / "ijkl"').toParseAs( + oneRuleGrammar(choiceOfLiterals) + ); expect('start "start rule" = "abcd" / "efgh" / "ijkl"').toParseAs( - oneRuleGrammar({ - type: "named", - name: "start rule", - expression: choiceOfLiterals - }) + oneRuleGrammar(namedChoiceOfLiterals) + ); + expect('start "start rule"\n= "abcd" / "efgh" / "ijkl"').toParseAs( + oneRuleGrammar(namedChoiceOfLiterals) ); - expect('start = "abcd" / "efgh" / "ijkl";').toParseAs( + expect('start = "abcd" / "efgh" / "ijkl"\n;').toParseAs( oneRuleGrammar(choiceOfLiterals) ); }); @@ -230,6 +244,18 @@ describe("PEG.js grammar parser", function() { type: "choice", alternatives: [sequenceOfLiterals, sequenceOfLiterals, sequenceOfLiterals] })); + expect( + 'start = "abcd" "efgh" "ijkl"\n/ "abcd" "efgh" "ijkl"\n/ "abcd" "efgh" "ijkl"' + ).toParseAs(oneRuleGrammar({ + type: "choice", + alternatives: [sequenceOfLiterals, sequenceOfLiterals, sequenceOfLiterals] + })); + expect( + 'start = "abcd" "efgh" "ijkl" /\n"abcd" "efgh" "ijkl" /\n"abcd" "efgh" "ijkl"' + ).toParseAs(oneRuleGrammar({ + type: "choice", + alternatives: [sequenceOfLiterals, sequenceOfLiterals, sequenceOfLiterals] + })); }); /* Canonical Sequence is "\"abcd\" \"efgh\" \"ijkl\"". */ @@ -237,6 +263,9 @@ describe("PEG.js grammar parser", function() { expect('start = a:"abcd" { code }').toParseAs( oneRuleGrammar({ type: "action", expression: labeledAbcd, code: " code " }) ); + expect('start = a:"abcd"\n{ code }').toParseAs( + oneRuleGrammar({ type: "action", expression: labeledAbcd, code: " code " }) + ); expect('start = a:"abcd" b:"efgh" c:"ijkl" { code }').toParseAs( oneRuleGrammar({ type: "action", @@ -244,6 +273,13 @@ describe("PEG.js grammar parser", function() { code: " code " }) ); + expect('start = a:"abcd"\nb:"efgh"\nc:"ijkl" { code }').toParseAs( + oneRuleGrammar({ + type: "action", + expression: sequenceOfLabeleds, + code: " code " + }) + ); expect('start = a:"abcd"').toParseAs( oneRuleGrammar(labeledAbcd) @@ -251,64 +287,54 @@ describe("PEG.js grammar parser", function() { expect('start = a:"abcd" b:"efgh" c:"ijkl"').toParseAs( oneRuleGrammar(sequenceOfLabeleds) ); + expect('start = a:"abcd"\nb:"efgh"\nc:"ijkl"').toParseAs( + oneRuleGrammar(sequenceOfLabeleds) + ); }); /* Canonical Labeled is "label:\"abcd\"". */ it("parses Labeled", function() { - expect('start = label:!"abcd"').toParseAs(oneRuleGrammar({ - type: "labeled", - label: "label", - expression: simpleNotLiteral - })); - expect('start = !"abcd"' ).toParseAs(oneRuleGrammar(simpleNotLiteral)); + expect('start = label:!"abcd"' ).toParseAs(oneRuleGrammar(labeledSimpleNotLiteral)); + expect('start = label\n:!"abcd"').toParseAs(oneRuleGrammar(labeledSimpleNotLiteral)); + expect('start = label:\n!"abcd"').toParseAs(oneRuleGrammar(labeledSimpleNotLiteral)); + expect('start = !"abcd"' ).toParseAs(oneRuleGrammar(simpleNotLiteral)); }); /* Canonical Prefixed is "!\"abcd\"". */ it("parses Prefixed", function() { - expect('start = $"abcd"?' ).toParseAs(oneRuleGrammar({ - type: "text", - expression: optionalLiteral - })); - expect('start = &{ code }').toParseAs(oneRuleGrammar({ - type: "semantic_and", - code: " code " - })); - expect('start = &"abcd"?' ).toParseAs(oneRuleGrammar({ - type: "simple_and", - expression: optionalLiteral - })); - expect('start = !{ code }').toParseAs(oneRuleGrammar({ - type: "semantic_not", - code: " code " - })); - expect('start = !"abcd"?' ).toParseAs(oneRuleGrammar({ - type: "simple_not", - expression: optionalLiteral - })); - expect('start = "abcd"?' ).toParseAs(oneRuleGrammar(optionalLiteral)); + expect('start = $"abcd"?' ).toParseAs(oneRuleGrammar(textOptionalLiteral)); + expect('start = $\n"abcd"?' ).toParseAs(oneRuleGrammar(textOptionalLiteral)); + expect('start = &{ code }' ).toParseAs(oneRuleGrammar(semanticAnd)); + expect('start = &\n{ code }').toParseAs(oneRuleGrammar(semanticAnd)); + expect('start = &"abcd"?' ).toParseAs(oneRuleGrammar(simpleAndOptionalLiteral)); + expect('start = &\n"abcd"?' ).toParseAs(oneRuleGrammar(simpleAndOptionalLiteral)); + expect('start = !{ code }' ).toParseAs(oneRuleGrammar(semanticNot)); + expect('start = !\n{ code }').toParseAs(oneRuleGrammar(semanticNot)); + expect('start = !"abcd"?' ).toParseAs(oneRuleGrammar(simpleNotOptionalLiteral)); + expect('start = !\n"abcd"?' ).toParseAs(oneRuleGrammar(simpleNotOptionalLiteral)); + expect('start = "abcd"?' ).toParseAs(oneRuleGrammar(optionalLiteral)); }); /* Canonical Suffixed is "\"abcd\"?". */ it("parses Suffixed", function() { - expect('start = "abcd"?').toParseAs(oneRuleGrammar(optionalLiteral)); - expect('start = "abcd"*').toParseAs(oneRuleGrammar({ - type: "zero_or_more", - expression: literalAbcd - })); - expect('start = "abcd"+').toParseAs(oneRuleGrammar({ - type: "one_or_more", - expression: literalAbcd - })); - expect('start = "abcd"' ).toParseAs(literalGrammar("abcd")); + expect('start = "abcd"?' ).toParseAs(oneRuleGrammar(optionalLiteral)); + expect('start = "abcd"\n?').toParseAs(oneRuleGrammar(optionalLiteral)); + expect('start = "abcd"*' ).toParseAs(oneRuleGrammar(zeroOrMoreLiteral)); + expect('start = "abcd"\n*').toParseAs(oneRuleGrammar(zeroOrMoreLiteral)); + expect('start = "abcd"+' ).toParseAs(oneRuleGrammar(oneOrMoreLiteral)); + expect('start = "abcd"\n+').toParseAs(oneRuleGrammar(oneOrMoreLiteral)); + expect('start = "abcd"' ).toParseAs(literalGrammar("abcd")); }); /* Canonical Primary is "\"abcd\"". */ it("parses Primary", function() { - expect('start = a' ).toParseAs(ruleRefGrammar("a")); - expect('start = "abcd"' ).toParseAs(literalGrammar("abcd")); - expect('start = [a-d]' ).toParseAs(classGrammar([["a", "d"]], "[a-d]")); - expect('start = .' ).toParseAs(oneRuleGrammar({ type: "any" })); - expect('start = ("abcd")').toParseAs(literalGrammar("abcd")); + expect('start = a' ).toParseAs(ruleRefGrammar("a")); + expect('start = "abcd"' ).toParseAs(literalGrammar("abcd")); + expect('start = [a-d]' ).toParseAs(classGrammar([["a", "d"]], "[a-d]")); + expect('start = .' ).toParseAs(oneRuleGrammar({ type: "any" })); + expect('start = ("abcd")' ).toParseAs(literalGrammar("abcd")); + expect('start = (\n"abcd")').toParseAs(literalGrammar("abcd")); + expect('start = ("abcd"\n)').toParseAs(literalGrammar("abcd")); }); /* Canonical Action is "{ code }". */ @@ -350,8 +376,6 @@ describe("PEG.js grammar parser", function() { expect('start = a0' ).toParseAs(ruleRefGrammar("a0")); expect('start = a_' ).toParseAs(ruleRefGrammar("a_")); expect('start = abcd').toParseAs(ruleRefGrammar("abcd")); - - expect('start = a\n').toParseAs(ruleRefGrammar("a")); }); /* Canonical Literal is "\"abcd\"". */ @@ -360,8 +384,6 @@ describe("PEG.js grammar parser", function() { expect("start = 'abcd'" ).toParseAs(literalGrammar("abcd")); expect('start = "abcd"i').toParseAs(literalGrammar("abcd", true)); - - expect('start = "abcd"\n').toParseAs(literalGrammar("abcd")); }); /* Canonical String is "\"abcd\"". */ @@ -374,8 +396,6 @@ describe("PEG.js grammar parser", function() { expect('start "abcd" = "abcd"' ).toParseAs(grammar); expect('start \'abcd\' = "abcd"').toParseAs(grammar); - - expect('start "abcd"\n= "abcd"').toParseAs(grammar); }); /* Canonical DoubleQuotedString is "\"abcd\"". */ @@ -445,8 +465,6 @@ describe("PEG.js grammar parser", function() { expect('start = [a-d]i').toParseAs( classGrammar([["a", "d"]], "[a-d]i", false, true) ); - - expect('start = [a-d]\n').toParseAs(classGrammar([["a", "d"]], "[a-d]")); }); /* Canonical ClassCharacterRange is "a-d". */ diff --git a/src/parser.pegjs b/src/parser.pegjs index bddb4ae..13428e1 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -1,18 +1,34 @@ { - var utils = require("./utils"); + function extractOptional(optional, index) { + return optional ? optional[index] : null; + } + + function extractList(list, index) { + var result = new Array(list.length), i; + + for (i = 0; i < list.length; i++) { + result[i] = list[i][index]; + } + + return result; + } + + function buildList(first, rest, index) { + return [first].concat(extractList(rest, index)); + } } Grammar - = __ initializer:Initializer? rules:Rule+ { + = __ initializer:(Initializer __)? rules:(Rule __)+ { return { type: "grammar", - initializer: initializer, - rules: rules + initializer: extractOptional(initializer, 0), + rules: extractList(rules, 0) }; } Initializer - = code:Action Semicolon? { + = code:Action (__ Semicolon)? { return { type: "initializer", code: code @@ -20,14 +36,17 @@ Initializer } Rule - = name:Identifier displayName:String? Equals expression:Expression Semicolon? { + = name:Identifier __ + displayName:(String __)? + Equals __ + expression:Expression (__ Semicolon)? { return { type: "rule", name: name, expression: displayName !== null ? { type: "named", - name: displayName, + name: displayName[0], expression: expression } : expression @@ -38,46 +57,31 @@ Expression = Choice Choice - = head:Sequence tail:(Slash Sequence)* { - if (tail.length > 0) { - var alternatives = [head].concat(utils.map( - tail, - function(element) { return element[1]; } - )); - return { - type: "choice", - alternatives: alternatives - }; - } else { - return head; - } + = first:Sequence rest:(__ Slash __ Sequence)* { + return rest.length > 0 + ? { type: "choice", alternatives: buildList(first, rest, 3) } + : first; } Sequence - = elements:Labeled+ code:Action { - var expression = elements.length !== 1 - ? { - type: "sequence", - elements: elements - } - : elements[0]; + = first:Labeled rest:(__ Labeled)* __ code:Action { + var expression = rest.length > 0 + ? { type: "sequence", elements: buildList(first, rest, 1) } + : first; return { type: "action", expression: expression, code: code }; } - / elements:Labeled+ { - return elements.length !== 1 - ? { - type: "sequence", - elements: elements - } - : elements[0]; + / first:Labeled rest:(__ Labeled)* { + return rest.length > 0 + ? { type: "sequence", elements: buildList(first, rest, 1) } + : first; } Labeled - = label:Identifier Colon expression:Prefixed { + = label:Identifier __ Colon __ expression:Prefixed { return { type: "labeled", label: label, @@ -87,31 +91,31 @@ Labeled / Prefixed Prefixed - = Dollar expression:Suffixed { + = Dollar __ expression:Suffixed { return { type: "text", expression: expression }; } - / And code:Action { + / And __ code:Action { return { type: "semantic_and", code: code }; } - / And expression:Suffixed { + / And __ expression:Suffixed { return { type: "simple_and", expression: expression }; } - / Not code:Action { + / Not __ code:Action { return { type: "semantic_not", code: code }; } - / Not expression:Suffixed { + / Not __ expression:Suffixed { return { type: "simple_not", expression: expression @@ -120,19 +124,19 @@ Prefixed / Suffixed Suffixed - = expression:Primary Question { + = expression:Primary __ Question { return { type: "optional", expression: expression }; } - / expression:Primary Star { + / expression:Primary __ Star { return { type: "zero_or_more", expression: expression }; } - / expression:Primary Plus { + / expression:Primary __ Plus { return { type: "one_or_more", expression: expression @@ -141,7 +145,7 @@ Suffixed / Primary Primary - = name:Identifier !(String? Equals) { + = name:Identifier !(__ (String __)? Equals) { return { type: "rule_ref", name: name @@ -150,7 +154,7 @@ Primary / Literal / Class / Dot { return { type: "any" }; } - / Lparen expression:Expression Rparen { return expression; } + / Lparen __ expression:Expression __ Rparen { return expression; } /* "Lexical" elements */ @@ -166,19 +170,19 @@ NonBraceCharacters NonBraceCharacter = [^{}] -Equals = "=" __ { return "="; } -Colon = ":" __ { return ":"; } -Semicolon = ";" __ { return ";"; } -Slash = "/" __ { return "/"; } -And = "&" __ { return "&"; } -Not = "!" __ { return "!"; } -Dollar = "$" __ { return "$"; } -Question = "?" __ { return "?"; } -Star = "*" __ { return "*"; } -Plus = "+" __ { return "+"; } -Lparen = "(" __ { return "("; } -Rparen = ")" __ { return ")"; } -Dot = "." __ { return "."; } +Equals = "=" +Colon = ":" +Semicolon = ";" +Slash = "/" +And = "&" +Not = "!" +Dollar = "$" +Question = "?" +Star = "*" +Plus = "+" +Lparen = "(" +Rparen = ")" +Dot = "." /* * Modeled after ECMA-262, 5th ed., 7.6, but much simplified: @@ -199,14 +203,14 @@ Dot = "." __ { return "."; } * purpose in the grammar. */ Identifier "identifier" - = chars:$((Letter / "_") (Letter / Digit / "_")*) __ { return chars; } + = $((Letter / "_") (Letter / Digit / "_")*) /* * Modeled after ECMA-262, 5th ed., 7.8.4. (syntax & semantics, rules only * vaguely). */ Literal "literal" - = value:(DoubleQuotedString / SingleQuotedString) flags:"i"? __ { + = value:(DoubleQuotedString / SingleQuotedString) flags:"i"? { return { type: "literal", value: value, @@ -215,7 +219,7 @@ Literal "literal" } String "string" - = string:(DoubleQuotedString / SingleQuotedString) __ { return string; } + = string:(DoubleQuotedString / SingleQuotedString) { return string; } DoubleQuotedString = '"' chars:DoubleQuotedCharacter* '"' { return chars.join(""); } @@ -246,19 +250,15 @@ SimpleSingleQuotedCharacter = !("'" / "\\" / EOLChar) char_:. { return char_; } Class "character class" - = class_:( - "[" inverted:"^"? parts:(ClassCharacterRange / ClassCharacter)* "]" flags:"i"? { - return { - type: "class", - parts: parts, - rawText: text().replace(/\s+$/, ""), - inverted: inverted === "^", - ignoreCase: flags === "i" - }; - } - ) - __ - { return class_; } + = "[" inverted:"^"? parts:(ClassCharacterRange / ClassCharacter)* "]" flags:"i"? { + return { + type: "class", + parts: parts, + rawText: text().replace(/\s+$/, ""), + inverted: inverted === "^", + ignoreCase: flags === "i" + }; + } ClassCharacterRange = begin:ClassCharacter "-" end:ClassCharacter {