diff --git a/lib/parser.js b/lib/parser.js index 45d0e70..479d304 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -163,84 +163,81 @@ module.exports = (function() { name: name }; }, - peg$c40 = ".", - peg$c41 = { type: "literal", value: ".", description: "\".\"" }, - peg$c42 = function() { return { type: "any" }; }, - peg$c43 = "(", - peg$c44 = { type: "literal", value: "(", description: "\"(\"" }, - peg$c45 = ")", - peg$c46 = { type: "literal", value: ")", description: "\")\"" }, - peg$c47 = function(expression) { return expression; }, - peg$c48 = { type: "any", description: "any character" }, - peg$c49 = { type: "other", description: "whitespace" }, - peg$c50 = "\t", - peg$c51 = { type: "literal", value: "\t", description: "\"\\t\"" }, - peg$c52 = "\x0B", - peg$c53 = { type: "literal", value: "\x0B", description: "\"\\x0B\"" }, - peg$c54 = "\f", - peg$c55 = { type: "literal", value: "\f", description: "\"\\f\"" }, - peg$c56 = " ", - peg$c57 = { type: "literal", value: " ", description: "\" \"" }, - peg$c58 = "\xA0", - peg$c59 = { type: "literal", value: "\xA0", description: "\"\\xA0\"" }, - peg$c60 = "\uFEFF", - peg$c61 = { type: "literal", value: "\uFEFF", description: "\"\\uFEFF\"" }, - peg$c62 = /^[\n\r\u2028\u2029]/, - peg$c63 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" }, - peg$c64 = { type: "other", description: "end of line" }, - peg$c65 = "\n", - peg$c66 = { type: "literal", value: "\n", description: "\"\\n\"" }, - peg$c67 = "\r\n", - peg$c68 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" }, - peg$c69 = "\r", - peg$c70 = { type: "literal", value: "\r", description: "\"\\r\"" }, - peg$c71 = "\u2028", - peg$c72 = { type: "literal", value: "\u2028", description: "\"\\u2028\"" }, - peg$c73 = "\u2029", - peg$c74 = { type: "literal", value: "\u2029", description: "\"\\u2029\"" }, - peg$c75 = { type: "other", description: "comment" }, - peg$c76 = "/*", - peg$c77 = { type: "literal", value: "/*", description: "\"/*\"" }, - peg$c78 = "*/", - peg$c79 = { type: "literal", value: "*/", description: "\"*/\"" }, - peg$c80 = "//", - peg$c81 = { type: "literal", value: "//", description: "\"//\"" }, - peg$c82 = function(name) { return name; }, - peg$c83 = function(name) { + peg$c40 = "(", + peg$c41 = { type: "literal", value: "(", description: "\"(\"" }, + peg$c42 = ")", + peg$c43 = { type: "literal", value: ")", description: "\")\"" }, + peg$c44 = function(expression) { return expression; }, + peg$c45 = { type: "any", description: "any character" }, + peg$c46 = { type: "other", description: "whitespace" }, + peg$c47 = "\t", + peg$c48 = { type: "literal", value: "\t", description: "\"\\t\"" }, + peg$c49 = "\x0B", + peg$c50 = { type: "literal", value: "\x0B", description: "\"\\x0B\"" }, + peg$c51 = "\f", + peg$c52 = { type: "literal", value: "\f", description: "\"\\f\"" }, + peg$c53 = " ", + peg$c54 = { type: "literal", value: " ", description: "\" \"" }, + peg$c55 = "\xA0", + peg$c56 = { type: "literal", value: "\xA0", description: "\"\\xA0\"" }, + peg$c57 = "\uFEFF", + peg$c58 = { type: "literal", value: "\uFEFF", description: "\"\\uFEFF\"" }, + peg$c59 = /^[\n\r\u2028\u2029]/, + peg$c60 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" }, + peg$c61 = { type: "other", description: "end of line" }, + peg$c62 = "\n", + peg$c63 = { type: "literal", value: "\n", description: "\"\\n\"" }, + peg$c64 = "\r\n", + peg$c65 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" }, + peg$c66 = "\r", + peg$c67 = { type: "literal", value: "\r", description: "\"\\r\"" }, + peg$c68 = "\u2028", + peg$c69 = { type: "literal", value: "\u2028", description: "\"\\u2028\"" }, + peg$c70 = "\u2029", + peg$c71 = { type: "literal", value: "\u2029", description: "\"\\u2029\"" }, + peg$c72 = { type: "other", description: "comment" }, + peg$c73 = "/*", + peg$c74 = { type: "literal", value: "/*", description: "\"/*\"" }, + peg$c75 = "*/", + peg$c76 = { type: "literal", value: "*/", description: "\"*/\"" }, + peg$c77 = "//", + peg$c78 = { type: "literal", value: "//", description: "\"//\"" }, + peg$c79 = function(name) { return name; }, + peg$c80 = function(name) { error("Reserved word \"" + name + "\" can't be used as an identifier."); }, - peg$c84 = { type: "other", description: "identifier" }, - peg$c85 = function(first, rest) { return first + rest.join(""); }, - peg$c86 = "_", - peg$c87 = { type: "literal", value: "_", description: "\"_\"" }, - peg$c88 = "\\", - peg$c89 = { type: "literal", value: "\\", description: "\"\\\\\"" }, - peg$c90 = function(sequence) { return sequence; }, - peg$c91 = "\u200C", - peg$c92 = { type: "literal", value: "\u200C", description: "\"\\u200C\"" }, - peg$c93 = "\u200D", - peg$c94 = { type: "literal", value: "\u200D", description: "\"\\u200D\"" }, - peg$c95 = { type: "other", description: "literal" }, - peg$c96 = "i", - peg$c97 = { type: "literal", value: "i", description: "\"i\"" }, - peg$c98 = function(value, ignoreCase) { + peg$c81 = { type: "other", description: "identifier" }, + peg$c82 = function(first, rest) { return first + rest.join(""); }, + peg$c83 = "_", + peg$c84 = { type: "literal", value: "_", description: "\"_\"" }, + peg$c85 = "\\", + peg$c86 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c87 = function(sequence) { return sequence; }, + peg$c88 = "\u200C", + peg$c89 = { type: "literal", value: "\u200C", description: "\"\\u200C\"" }, + peg$c90 = "\u200D", + peg$c91 = { type: "literal", value: "\u200D", description: "\"\\u200D\"" }, + peg$c92 = { type: "other", description: "literal" }, + peg$c93 = "i", + peg$c94 = { type: "literal", value: "i", description: "\"i\"" }, + peg$c95 = function(value, ignoreCase) { return { type: "literal", value: value, ignoreCase: ignoreCase !== null }; }, - peg$c99 = { type: "other", description: "string" }, - peg$c100 = "\"", - peg$c101 = { type: "literal", value: "\"", description: "\"\\\"\"" }, - peg$c102 = function(chars) { return chars.join(""); }, - peg$c103 = "'", - peg$c104 = { type: "literal", value: "'", description: "\"'\"" }, - peg$c105 = function() { return text(); }, - peg$c106 = { type: "other", description: "character class" }, - peg$c107 = "[", - peg$c108 = { type: "literal", value: "[", description: "\"[\"" }, - peg$c109 = "^", - peg$c110 = { type: "literal", value: "^", description: "\"^\"" }, - peg$c111 = "]", - peg$c112 = { type: "literal", value: "]", description: "\"]\"" }, - peg$c113 = function(inverted, parts, ignoreCase) { + peg$c96 = { type: "other", description: "string" }, + peg$c97 = "\"", + peg$c98 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c99 = function(chars) { return chars.join(""); }, + peg$c100 = "'", + peg$c101 = { type: "literal", value: "'", description: "\"'\"" }, + peg$c102 = function() { return text(); }, + peg$c103 = { type: "other", description: "character class" }, + peg$c104 = "[", + peg$c105 = { type: "literal", value: "[", description: "\"[\"" }, + peg$c106 = "^", + peg$c107 = { type: "literal", value: "^", description: "\"^\"" }, + peg$c108 = "]", + peg$c109 = { type: "literal", value: "]", description: "\"]\"" }, + peg$c110 = function(inverted, parts, ignoreCase) { return { type: "class", parts: parts, @@ -249,9 +246,9 @@ module.exports = (function() { rawText: text() }; }, - peg$c114 = "-", - peg$c115 = { type: "literal", value: "-", description: "\"-\"" }, - peg$c116 = function(begin, end) { + peg$c111 = "-", + peg$c112 = { type: "literal", value: "-", description: "\"-\"" }, + peg$c113 = function(begin, end) { if (begin.charCodeAt(0) > end.charCodeAt(0)) { error( "Invalid character range: " + text() + "." @@ -260,39 +257,42 @@ module.exports = (function() { return [begin, end]; }, - peg$c117 = function() { return ""; }, - peg$c118 = "0", - peg$c119 = { type: "literal", value: "0", description: "\"0\"" }, - peg$c120 = function() { return "\0"; }, - peg$c121 = "b", - peg$c122 = { type: "literal", value: "b", description: "\"b\"" }, - peg$c123 = function() { return "\b"; }, - peg$c124 = "f", - peg$c125 = { type: "literal", value: "f", description: "\"f\"" }, - peg$c126 = function() { return "\f"; }, - peg$c127 = "n", - peg$c128 = { type: "literal", value: "n", description: "\"n\"" }, - peg$c129 = function() { return "\n"; }, - peg$c130 = "r", - peg$c131 = { type: "literal", value: "r", description: "\"r\"" }, - peg$c132 = function() { return "\r"; }, - peg$c133 = "t", - peg$c134 = { type: "literal", value: "t", description: "\"t\"" }, - peg$c135 = function() { return "\t"; }, - peg$c136 = "v", - peg$c137 = { type: "literal", value: "v", description: "\"v\"" }, - peg$c138 = function() { return "\x0B"; }, - peg$c139 = "x", - peg$c140 = { type: "literal", value: "x", description: "\"x\"" }, - peg$c141 = "u", - peg$c142 = { type: "literal", value: "u", description: "\"u\"" }, - peg$c143 = function(digits) { + peg$c114 = function() { return ""; }, + peg$c115 = "0", + peg$c116 = { type: "literal", value: "0", description: "\"0\"" }, + peg$c117 = function() { return "\0"; }, + peg$c118 = "b", + peg$c119 = { type: "literal", value: "b", description: "\"b\"" }, + peg$c120 = function() { return "\b"; }, + peg$c121 = "f", + peg$c122 = { type: "literal", value: "f", description: "\"f\"" }, + peg$c123 = function() { return "\f"; }, + peg$c124 = "n", + peg$c125 = { type: "literal", value: "n", description: "\"n\"" }, + peg$c126 = function() { return "\n"; }, + peg$c127 = "r", + peg$c128 = { type: "literal", value: "r", description: "\"r\"" }, + peg$c129 = function() { return "\r"; }, + peg$c130 = "t", + peg$c131 = { type: "literal", value: "t", description: "\"t\"" }, + peg$c132 = function() { return "\t"; }, + peg$c133 = "v", + peg$c134 = { type: "literal", value: "v", description: "\"v\"" }, + peg$c135 = function() { return "\x0B"; }, + peg$c136 = "x", + peg$c137 = { type: "literal", value: "x", description: "\"x\"" }, + peg$c138 = "u", + peg$c139 = { type: "literal", value: "u", description: "\"u\"" }, + peg$c140 = function(digits) { return String.fromCharCode(parseInt(digits, 16)); }, - peg$c144 = /^[0-9]/, - peg$c145 = { type: "class", value: "[0-9]", description: "[0-9]" }, - peg$c146 = /^[0-9a-f]/i, - peg$c147 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" }, + peg$c141 = /^[0-9]/, + peg$c142 = { type: "class", value: "[0-9]", description: "[0-9]" }, + peg$c143 = /^[0-9a-f]/i, + peg$c144 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" }, + peg$c145 = ".", + peg$c146 = { type: "literal", value: ".", description: "\".\"" }, + peg$c147 = function() { return { type: "any" }; }, peg$c148 = { type: "other", description: "code block" }, peg$c149 = "{", peg$c150 = { type: "literal", value: "{", description: "\"{\"" }, @@ -1383,27 +1383,15 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$parseCharacterClassMatcher(); if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 46) { - s1 = peg$c40; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } - } - if (s1 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c42(); - } - s0 = s1; + s0 = peg$parseAnyMatcher(); if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c43; + s1 = peg$c40; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c44); } + if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 !== peg$FAILED) { s2 = peg$parse__(); @@ -1413,15 +1401,15 @@ module.exports = (function() { s4 = peg$parse__(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c45; + s5 = peg$c42; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c46); } + if (peg$silentFails === 0) { peg$fail(peg$c43); } } if (s5 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c47(s3); + s1 = peg$c44(s3); s0 = s1; } else { peg$currPos = s0; @@ -1459,7 +1447,7 @@ module.exports = (function() { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c45); } } return s0; @@ -1470,51 +1458,51 @@ module.exports = (function() { peg$silentFails++; if (input.charCodeAt(peg$currPos) === 9) { - s0 = peg$c50; + s0 = peg$c47; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c51); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 11) { - s0 = peg$c52; + s0 = peg$c49; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 12) { - s0 = peg$c54; + s0 = peg$c51; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c55); } + if (peg$silentFails === 0) { peg$fail(peg$c52); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 32) { - s0 = peg$c56; + s0 = peg$c53; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c57); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 160) { - s0 = peg$c58; + s0 = peg$c55; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c56); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 65279) { - s0 = peg$c60; + s0 = peg$c57; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s0 === peg$FAILED) { s0 = peg$parseZs(); @@ -1527,7 +1515,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c49); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } return s0; @@ -1536,12 +1524,12 @@ module.exports = (function() { function peg$parseLineTerminator() { var s0; - if (peg$c62.test(input.charAt(peg$currPos))) { + if (peg$c59.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c63); } + if (peg$silentFails === 0) { peg$fail(peg$c60); } } return s0; @@ -1552,43 +1540,43 @@ module.exports = (function() { peg$silentFails++; if (input.charCodeAt(peg$currPos) === 10) { - s0 = peg$c65; + s0 = peg$c62; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c66); } + if (peg$silentFails === 0) { peg$fail(peg$c63); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c67) { - s0 = peg$c67; + if (input.substr(peg$currPos, 2) === peg$c64) { + s0 = peg$c64; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c68); } + if (peg$silentFails === 0) { peg$fail(peg$c65); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 13) { - s0 = peg$c69; + s0 = peg$c66; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c67); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8232) { - s0 = peg$c71; + s0 = peg$c68; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c72); } + if (peg$silentFails === 0) { peg$fail(peg$c69); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8233) { - s0 = peg$c73; + s0 = peg$c70; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c74); } + if (peg$silentFails === 0) { peg$fail(peg$c71); } } } } @@ -1597,7 +1585,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c64); } + if (peg$silentFails === 0) { peg$fail(peg$c61); } } return s0; @@ -1614,7 +1602,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c75); } + if (peg$silentFails === 0) { peg$fail(peg$c72); } } return s0; @@ -1624,24 +1612,24 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c76) { - s1 = peg$c76; + if (input.substr(peg$currPos, 2) === peg$c73) { + s1 = peg$c73; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c77); } + if (peg$silentFails === 0) { peg$fail(peg$c74); } } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c78) { - s5 = peg$c78; + if (input.substr(peg$currPos, 2) === peg$c75) { + s5 = peg$c75; peg$currPos += 2; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c79); } + if (peg$silentFails === 0) { peg$fail(peg$c76); } } peg$silentFails--; if (s5 === peg$FAILED) { @@ -1668,12 +1656,12 @@ module.exports = (function() { s3 = peg$currPos; s4 = peg$currPos; peg$silentFails++; - if (input.substr(peg$currPos, 2) === peg$c78) { - s5 = peg$c78; + if (input.substr(peg$currPos, 2) === peg$c75) { + s5 = peg$c75; peg$currPos += 2; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c79); } + if (peg$silentFails === 0) { peg$fail(peg$c76); } } peg$silentFails--; if (s5 === peg$FAILED) { @@ -1697,12 +1685,12 @@ module.exports = (function() { } } if (s2 !== peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c78) { - s3 = peg$c78; + if (input.substr(peg$currPos, 2) === peg$c75) { + s3 = peg$c75; peg$currPos += 2; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c79); } + if (peg$silentFails === 0) { peg$fail(peg$c76); } } if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; @@ -1727,12 +1715,12 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c80) { - s1 = peg$c80; + if (input.substr(peg$currPos, 2) === peg$c77) { + s1 = peg$c77; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c81); } + if (peg$silentFails === 0) { peg$fail(peg$c78); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1820,7 +1808,7 @@ module.exports = (function() { s2 = peg$parseIdentifierName(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c82(s2); + s1 = peg$c79(s2); s0 = s1; } else { peg$currPos = s0; @@ -1835,7 +1823,7 @@ module.exports = (function() { s1 = peg$parseIdentifierName(); if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c83(s1); + s1 = peg$c80(s1); } s0 = s1; } @@ -1858,7 +1846,7 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c85(s1, s2); + s1 = peg$c82(s1, s2); s0 = s1; } else { peg$currPos = s0; @@ -1871,7 +1859,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c84); } + if (peg$silentFails === 0) { peg$fail(peg$c81); } } return s0; @@ -1891,26 +1879,26 @@ module.exports = (function() { } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s0 = peg$c86; + s0 = peg$c83; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c87); } + if (peg$silentFails === 0) { peg$fail(peg$c84); } } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c88; + s1 = peg$c85; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s1 !== peg$FAILED) { s2 = peg$parseUnicodeEscapeSequence(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c90(s2); + s1 = peg$c87(s2); s0 = s1; } else { peg$currPos = s0; @@ -1939,19 +1927,19 @@ module.exports = (function() { s0 = peg$parsePc(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8204) { - s0 = peg$c91; + s0 = peg$c88; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c92); } + if (peg$silentFails === 0) { peg$fail(peg$c89); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 8205) { - s0 = peg$c93; + s0 = peg$c90; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c94); } + if (peg$silentFails === 0) { peg$fail(peg$c91); } } } } @@ -2141,18 +2129,18 @@ module.exports = (function() { s1 = peg$parseStringLiteral(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { - s2 = peg$c96; + s2 = peg$c93; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c97); } + if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s2 === peg$FAILED) { s2 = peg$c1; } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c98(s1, s2); + s1 = peg$c95(s1, s2); s0 = s1; } else { peg$currPos = s0; @@ -2165,7 +2153,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c95); } + if (peg$silentFails === 0) { peg$fail(peg$c92); } } return s0; @@ -2177,11 +2165,11 @@ module.exports = (function() { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c100; + s1 = peg$c97; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c98); } } if (s1 !== peg$FAILED) { s2 = []; @@ -2192,15 +2180,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c100; + s3 = peg$c97; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c98); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c102(s2); + s1 = peg$c99(s2); s0 = s1; } else { peg$currPos = s0; @@ -2217,11 +2205,11 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { - s1 = peg$c103; + s1 = peg$c100; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c104); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s1 !== peg$FAILED) { s2 = []; @@ -2232,15 +2220,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { - s3 = peg$c103; + s3 = peg$c100; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c104); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c102(s2); + s1 = peg$c99(s2); s0 = s1; } else { peg$currPos = s0; @@ -2258,7 +2246,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c99); } + if (peg$silentFails === 0) { peg$fail(peg$c96); } } return s0; @@ -2271,19 +2259,19 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c100; + s2 = peg$c97; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c98); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c88; + s2 = peg$c85; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s2 === peg$FAILED) { s2 = peg$parseLineTerminator(); @@ -2300,7 +2288,7 @@ module.exports = (function() { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c105(); + s1 = peg$c102(); s0 = s1; } else { peg$currPos = s0; @@ -2313,17 +2301,17 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c88; + s1 = peg$c85; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s1 !== peg$FAILED) { s2 = peg$parseEscapeSequence(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c90(s2); + s1 = peg$c87(s2); s0 = s1; } else { peg$currPos = s0; @@ -2348,19 +2336,19 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 39) { - s2 = peg$c103; + s2 = peg$c100; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c104); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c88; + s2 = peg$c85; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s2 === peg$FAILED) { s2 = peg$parseLineTerminator(); @@ -2377,7 +2365,7 @@ module.exports = (function() { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c105(); + s1 = peg$c102(); s0 = s1; } else { peg$currPos = s0; @@ -2390,17 +2378,17 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c88; + s1 = peg$c85; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s1 !== peg$FAILED) { s2 = peg$parseEscapeSequence(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c90(s2); + s1 = peg$c87(s2); s0 = s1; } else { peg$currPos = s0; @@ -2424,19 +2412,19 @@ module.exports = (function() { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { - s1 = peg$c107; + s1 = peg$c104; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c108); } + if (peg$silentFails === 0) { peg$fail(peg$c105); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 94) { - s2 = peg$c109; + s2 = peg$c106; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c110); } + if (peg$silentFails === 0) { peg$fail(peg$c107); } } if (s2 === peg$FAILED) { s2 = peg$c1; @@ -2456,26 +2444,26 @@ module.exports = (function() { } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { - s4 = peg$c111; + s4 = peg$c108; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + if (peg$silentFails === 0) { peg$fail(peg$c109); } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { - s5 = peg$c96; + s5 = peg$c93; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c97); } + if (peg$silentFails === 0) { peg$fail(peg$c94); } } if (s5 === peg$FAILED) { s5 = peg$c1; } if (s5 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c113(s2, s3, s5); + s1 = peg$c110(s2, s3, s5); s0 = s1; } else { peg$currPos = s0; @@ -2500,7 +2488,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c106); } + if (peg$silentFails === 0) { peg$fail(peg$c103); } } return s0; @@ -2513,17 +2501,17 @@ module.exports = (function() { s1 = peg$parseClassCharacter(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s2 = peg$c114; + s2 = peg$c111; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c115); } + if (peg$silentFails === 0) { peg$fail(peg$c112); } } if (s2 !== peg$FAILED) { s3 = peg$parseClassCharacter(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c116(s1, s3); + s1 = peg$c113(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -2548,19 +2536,19 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 93) { - s2 = peg$c111; + s2 = peg$c108; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c112); } + if (peg$silentFails === 0) { peg$fail(peg$c109); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c88; + s2 = peg$c85; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s2 === peg$FAILED) { s2 = peg$parseLineTerminator(); @@ -2577,7 +2565,7 @@ module.exports = (function() { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c105(); + s1 = peg$c102(); s0 = s1; } else { peg$currPos = s0; @@ -2590,17 +2578,17 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c88; + s1 = peg$c85; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s1 !== peg$FAILED) { s2 = peg$parseEscapeSequence(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c90(s2); + s1 = peg$c87(s2); s0 = s1; } else { peg$currPos = s0; @@ -2623,17 +2611,17 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c88; + s1 = peg$c85; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s1 !== peg$FAILED) { s2 = peg$parseLineTerminatorSequence(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c117(); + s1 = peg$c114(); s0 = s1; } else { peg$currPos = s0; @@ -2654,11 +2642,11 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 48) { - s1 = peg$c118; + s1 = peg$c115; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c119); } + if (peg$silentFails === 0) { peg$fail(peg$c116); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2673,7 +2661,7 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c120(); + s1 = peg$c117(); s0 = s1; } else { peg$currPos = s0; @@ -2709,110 +2697,110 @@ module.exports = (function() { var s0, s1; if (input.charCodeAt(peg$currPos) === 39) { - s0 = peg$c103; + s0 = peg$c100; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c104); } + if (peg$silentFails === 0) { peg$fail(peg$c101); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s0 = peg$c100; + s0 = peg$c97; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c101); } + if (peg$silentFails === 0) { peg$fail(peg$c98); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s0 = peg$c88; + s0 = peg$c85; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c89); } + if (peg$silentFails === 0) { peg$fail(peg$c86); } } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 98) { - s1 = peg$c121; + s1 = peg$c118; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c122); } + if (peg$silentFails === 0) { peg$fail(peg$c119); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c123(); + s1 = peg$c120(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 102) { - s1 = peg$c124; + s1 = peg$c121; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c125); } + if (peg$silentFails === 0) { peg$fail(peg$c122); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c126(); + s1 = peg$c123(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 110) { - s1 = peg$c127; + s1 = peg$c124; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c128); } + if (peg$silentFails === 0) { peg$fail(peg$c125); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c129(); + s1 = peg$c126(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 114) { - s1 = peg$c130; + s1 = peg$c127; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c131); } + if (peg$silentFails === 0) { peg$fail(peg$c128); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c132(); + s1 = peg$c129(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 116) { - s1 = peg$c133; + s1 = peg$c130; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c134); } + if (peg$silentFails === 0) { peg$fail(peg$c131); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c135(); + s1 = peg$c132(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 118) { - s1 = peg$c136; + s1 = peg$c133; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c137); } + if (peg$silentFails === 0) { peg$fail(peg$c134); } } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c138(); + s1 = peg$c135(); } s0 = s1; } @@ -2848,7 +2836,7 @@ module.exports = (function() { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c105(); + s1 = peg$c102(); s0 = s1; } else { peg$currPos = s0; @@ -2870,19 +2858,19 @@ module.exports = (function() { s0 = peg$parseDecimalDigit(); if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 120) { - s0 = peg$c139; + s0 = peg$c136; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c140); } + if (peg$silentFails === 0) { peg$fail(peg$c137); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 117) { - s0 = peg$c141; + s0 = peg$c138; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c142); } + if (peg$silentFails === 0) { peg$fail(peg$c139); } } } } @@ -2896,11 +2884,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 120) { - s1 = peg$c139; + s1 = peg$c136; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c140); } + if (peg$silentFails === 0) { peg$fail(peg$c137); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2925,7 +2913,7 @@ module.exports = (function() { s2 = s3; if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c143(s2); + s1 = peg$c140(s2); s0 = s1; } else { peg$currPos = s0; @@ -2944,11 +2932,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 117) { - s1 = peg$c141; + s1 = peg$c138; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c142); } + if (peg$silentFails === 0) { peg$fail(peg$c139); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2985,7 +2973,7 @@ module.exports = (function() { s2 = s3; if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c143(s2); + s1 = peg$c140(s2); s0 = s1; } else { peg$currPos = s0; @@ -3002,12 +2990,12 @@ module.exports = (function() { function peg$parseDecimalDigit() { var s0; - if (peg$c144.test(input.charAt(peg$currPos))) { + if (peg$c141.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c145); } + if (peg$silentFails === 0) { peg$fail(peg$c142); } } return s0; @@ -3016,17 +3004,37 @@ module.exports = (function() { function peg$parseHexDigit() { var s0; - if (peg$c146.test(input.charAt(peg$currPos))) { + if (peg$c143.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c147); } + if (peg$silentFails === 0) { peg$fail(peg$c144); } } return s0; } + function peg$parseAnyMatcher() { + var s0, s1; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 46) { + s1 = peg$c145; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c146); } + } + if (s1 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c147(); + } + s0 = s1; + + return s0; + } + function peg$parseCodeBlock() { var s0, s1, s2, s3; diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 2a20b2a..45f5580 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -561,6 +561,11 @@ describe("PEG.js grammar parser", function() { /* Digit rules are not tested. */ + /* Canonical AnyMatcher is ".". */ + it("parses CodeAnymatcher", function() { + expect('start = .').toParseAs(oneRuleGrammar({ type: "any" })); + }); + /* Canonical CodeBlock is "{ code }". */ it("parses CodeBlock", function() { expect('start = "abcd" { code }').toParseAs(actionGrammar(" code ")); diff --git a/src/parser.pegjs b/src/parser.pegjs index 6f6a6b8..6fd0dc4 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -166,7 +166,7 @@ Primary } / LiteralMatcher / CharacterClassMatcher - / "." { return { type: "any" }; } + / AnyMatcher / "(" __ expression:Expression __ ")" { return expression; } /* "Lexical" elements */ @@ -394,6 +394,9 @@ DecimalDigit HexDigit = [0-9a-f]i +AnyMatcher + = "." { return { type: "any" }; } + CodeBlock "code block" = "{" code:Code "}" { return code; }