From bcb527164910ad6720f358220e8e04acca846080 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 28 Mar 2014 13:55:25 +0100 Subject: [PATCH] PEG.js grammar: More JavaScript-like rules for skipped elements --- lib/parser.js | 1270 +++++++++++++++++++++++-------------------- spec/parser.spec.js | 124 ++--- src/parser.pegjs | 92 +++- 3 files changed, 789 insertions(+), 697 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 9958100..b178aef 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -171,46 +171,79 @@ module.exports = (function() { peg$c45 = ")", peg$c46 = { type: "literal", value: ")", description: "\")\"" }, peg$c47 = function(expression) { return expression; }, - peg$c48 = { type: "other", description: "action" }, - peg$c49 = function(braced) { return braced.substr(1, braced.length - 2); }, - peg$c50 = "{", - peg$c51 = { type: "literal", value: "{", description: "\"{\"" }, - peg$c52 = "}", - peg$c53 = { type: "literal", value: "}", description: "\"}\"" }, - peg$c54 = /^[^{}]/, - peg$c55 = { type: "class", 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) { + 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 = { type: "other", description: "action" }, + peg$c83 = function(braced) { return braced.substr(1, braced.length - 2); }, + peg$c84 = "{", + peg$c85 = { type: "literal", value: "{", description: "\"{\"" }, + peg$c86 = "}", + peg$c87 = { type: "literal", value: "}", description: "\"}\"" }, + peg$c88 = /^[^{}]/, + peg$c89 = { type: "class", value: "[^{}]", description: "[^{}]" }, + peg$c90 = { type: "other", description: "identifier" }, + peg$c91 = "_", + peg$c92 = { type: "literal", value: "_", description: "\"_\"" }, + peg$c93 = { type: "other", description: "literal" }, + peg$c94 = "i", + peg$c95 = { type: "literal", value: "i", description: "\"i\"" }, + peg$c96 = function(value, flags) { return { type: "literal", value: value, ignoreCase: flags === "i" }; }, - 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) { + peg$c97 = { type: "other", description: "string" }, + peg$c98 = function(string) { return string; }, + peg$c99 = "\"", + peg$c100 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c101 = function(chars) { return chars.join(""); }, + peg$c102 = "\\", + peg$c103 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c104 = function(char_) { return char_; }, + peg$c105 = "'", + peg$c106 = { type: "literal", value: "'", description: "\"'\"" }, + peg$c107 = { type: "other", description: "character class" }, + 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 = function(inverted, parts, flags) { return { type: "class", parts: parts, @@ -219,20 +252,20 @@ module.exports = (function() { ignoreCase: flags === "i" }; }, - peg$c82 = "-", - peg$c83 = { type: "literal", value: "-", description: "\"-\"" }, - peg$c84 = function(begin, end) { + peg$c115 = "-", + peg$c116 = { type: "literal", value: "-", description: "\"-\"" }, + peg$c117 = function(begin, end) { if (begin.charCodeAt(0) > end.charCodeAt(0)) { error("Invalid character range: " + text() + "."); } return [begin, end]; }, - 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_) { + peg$c118 = "x", + peg$c119 = { type: "literal", value: "x", description: "\"x\"" }, + peg$c120 = "u", + peg$c121 = { type: "literal", value: "u", description: "\"u\"" }, + peg$c122 = function(char_) { return char_ .replace("b", "\b") .replace("f", "\f") @@ -241,48 +274,27 @@ module.exports = (function() { .replace("t", "\t") .replace("v", "\x0B"); // IE does not recognize "\v". }, - 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) { + peg$c123 = "\\0", + peg$c124 = { type: "literal", value: "\\0", description: "\"\\\\0\"" }, + peg$c125 = function() { return "\x00"; }, + peg$c126 = "\\x", + peg$c127 = { type: "literal", value: "\\x", description: "\"\\\\x\"" }, + peg$c128 = function(digits) { return String.fromCharCode(parseInt(digits, 16)); }, - 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$c129 = "\\u", + peg$c130 = { type: "literal", value: "\\u", description: "\"\\\\u\"" }, + peg$c131 = function(eol) { return ""; }, + peg$c132 = /^[0-9]/, + peg$c133 = { type: "class", value: "[0-9]", description: "[0-9]" }, + peg$c134 = /^[0-9a-fA-F]/, + peg$c135 = { type: "class", value: "[0-9a-fA-F]", description: "[0-9a-fA-F]" }, + peg$c136 = /^[a-z]/, + peg$c137 = { type: "class", value: "[a-z]", description: "[a-z]" }, + peg$c138 = /^[A-Z]/, + peg$c139 = { type: "class", value: "[A-Z]", description: "[A-Z]" }, + peg$c140 = /^[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/, + peg$c141 = { type: "class", value: "[\\u0020\\u00A0\\u1680\\u2000-\\u200A\\u202F\\u205F\\u3000]", description: "[\\u0020\\u00A0\\u1680\\u2000-\\u200A\\u202F\\u205F\\u3000]" }, peg$currPos = 0, peg$reportedPos = 0, @@ -1339,6 +1351,357 @@ module.exports = (function() { return s0; } + function peg$parseSourceCharacter() { + var s0; + + if (input.length > peg$currPos) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c48); } + } + + return s0; + } + + function peg$parseWhiteSpace() { + var s0, s1; + + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 9) { + s0 = peg$c50; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c51); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 11) { + s0 = peg$c52; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c53); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 12) { + s0 = peg$c54; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c55); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 32) { + s0 = peg$c56; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c57); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 160) { + s0 = peg$c58; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c59); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 65279) { + s0 = peg$c60; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c61); } + } + if (s0 === peg$FAILED) { + s0 = peg$parseZs(); + } + } + } + } + } + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c49); } + } + + return s0; + } + + function peg$parseLineTerminator() { + var s0; + + if (peg$c62.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c63); } + } + + return s0; + } + + function peg$parseLineTerminatorSequence() { + var s0, s1; + + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 10) { + s0 = peg$c65; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c66); } + } + if (s0 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c67) { + s0 = peg$c67; + peg$currPos += 2; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c68); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 13) { + s0 = peg$c69; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c70); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 8232) { + s0 = peg$c71; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c72); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 8233) { + s0 = peg$c73; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c74); } + } + } + } + } + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c64); } + } + + return s0; + } + + function peg$parseComment() { + var s0, s1; + + peg$silentFails++; + s0 = peg$parseMultiLineComment(); + if (s0 === peg$FAILED) { + s0 = peg$parseSingleLineComment(); + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c75); } + } + + return s0; + } + + function peg$parseMultiLineComment() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 2) === peg$c76) { + s1 = peg$c76; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c77); } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = peg$currPos; + peg$silentFails++; + if (input.substr(peg$currPos, 2) === peg$c78) { + s5 = peg$c78; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c79); } + } + peg$silentFails--; + if (s5 === peg$FAILED) { + s4 = peg$c38; + } else { + peg$currPos = s4; + s4 = peg$c0; + } + if (s4 !== peg$FAILED) { + s5 = peg$parseSourceCharacter(); + 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$currPos; + peg$silentFails++; + if (input.substr(peg$currPos, 2) === peg$c78) { + s5 = peg$c78; + peg$currPos += 2; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c79); } + } + peg$silentFails--; + if (s5 === peg$FAILED) { + s4 = peg$c38; + } else { + peg$currPos = s4; + s4 = peg$c0; + } + if (s4 !== peg$FAILED) { + s5 = peg$parseSourceCharacter(); + 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) { + if (input.substr(peg$currPos, 2) === peg$c78) { + s3 = peg$c78; + peg$currPos += 2; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c79); } + } + if (s3 !== peg$FAILED) { + s1 = [s1, s2, s3]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } + + return s0; + } + + function peg$parseSingleLineComment() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 2) === peg$c80) { + s1 = peg$c80; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c81); } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$currPos; + s4 = peg$currPos; + peg$silentFails++; + s5 = peg$parseLineTerminator(); + peg$silentFails--; + if (s5 === peg$FAILED) { + s4 = peg$c38; + } else { + peg$currPos = s4; + s4 = peg$c0; + } + if (s4 !== peg$FAILED) { + s5 = peg$parseSourceCharacter(); + 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$currPos; + peg$silentFails++; + s5 = peg$parseLineTerminator(); + peg$silentFails--; + if (s5 === peg$FAILED) { + s4 = peg$c38; + } else { + peg$currPos = s4; + s4 = peg$c0; + } + if (s4 !== peg$FAILED) { + s5 = peg$parseSourceCharacter(); + 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) { + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } + + return s0; + } + function peg$parseAction() { var s0, s1, s2; @@ -1349,7 +1712,7 @@ module.exports = (function() { s2 = peg$parse__(); if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c49(s1); + s1 = peg$c83(s1); s0 = s1; } else { peg$currPos = s0; @@ -1362,7 +1725,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c48); } + if (peg$silentFails === 0) { peg$fail(peg$c82); } } return s0; @@ -1374,11 +1737,11 @@ module.exports = (function() { s0 = peg$currPos; s1 = peg$currPos; if (input.charCodeAt(peg$currPos) === 123) { - s2 = peg$c50; + s2 = peg$c84; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c51); } + if (peg$silentFails === 0) { peg$fail(peg$c85); } } if (s2 !== peg$FAILED) { s3 = []; @@ -1395,11 +1758,11 @@ module.exports = (function() { } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { - s4 = peg$c52; + s4 = peg$c86; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c87); } } if (s4 !== peg$FAILED) { s2 = [s2, s3, s4]; @@ -1444,12 +1807,12 @@ module.exports = (function() { function peg$parseNonBraceCharacter() { var s0; - if (peg$c54.test(input.charAt(peg$currPos))) { + if (peg$c88.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c55); } + if (peg$silentFails === 0) { peg$fail(peg$c89); } } return s0; @@ -1464,11 +1827,11 @@ module.exports = (function() { s2 = peg$parseLetter(); if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s2 = peg$c57; + s2 = peg$c91; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c58); } + if (peg$silentFails === 0) { peg$fail(peg$c92); } } } if (s2 !== peg$FAILED) { @@ -1478,11 +1841,11 @@ module.exports = (function() { s4 = peg$parseDigit(); if (s4 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s4 = peg$c57; + s4 = peg$c91; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c58); } + if (peg$silentFails === 0) { peg$fail(peg$c92); } } } } @@ -1493,11 +1856,11 @@ module.exports = (function() { s4 = peg$parseDigit(); if (s4 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 95) { - s4 = peg$c57; + s4 = peg$c91; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c58); } + if (peg$silentFails === 0) { peg$fail(peg$c92); } } } } @@ -1520,7 +1883,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c56); } + if (peg$silentFails === 0) { peg$fail(peg$c90); } } return s0; @@ -1537,18 +1900,18 @@ module.exports = (function() { } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { - s2 = peg$c60; + s2 = peg$c94; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c95); } } if (s2 === peg$FAILED) { s2 = peg$c1; } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c62(s1, s2); + s1 = peg$c96(s1, s2); s0 = s1; } else { peg$currPos = s0; @@ -1561,7 +1924,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c59); } + if (peg$silentFails === 0) { peg$fail(peg$c93); } } return s0; @@ -1578,13 +1941,13 @@ module.exports = (function() { } if (s1 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c64(s1); + s1 = peg$c98(s1); } s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c63); } + if (peg$silentFails === 0) { peg$fail(peg$c97); } } return s0; @@ -1595,11 +1958,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c65; + s1 = peg$c99; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c66); } + if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1610,15 +1973,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c65; + s3 = peg$c99; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c66); } + if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c67(s2); + s1 = peg$c101(s2); s0 = s1; } else { peg$currPos = s0; @@ -1666,22 +2029,22 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c65; + s2 = peg$c99; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c66); } + if (peg$silentFails === 0) { peg$fail(peg$c100); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c68; + s2 = peg$c102; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c103); } } if (s2 === peg$FAILED) { - s2 = peg$parseEOLChar(); + s2 = peg$parseLineTerminator(); } } peg$silentFails--; @@ -1697,11 +2060,11 @@ module.exports = (function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c71(s2); + s1 = peg$c104(s2); s0 = s1; } else { peg$currPos = s0; @@ -1720,11 +2083,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 39) { - s1 = peg$c72; + s1 = peg$c105; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c73); } + if (peg$silentFails === 0) { peg$fail(peg$c106); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1735,15 +2098,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 39) { - s3 = peg$c72; + s3 = peg$c105; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c73); } + if (peg$silentFails === 0) { peg$fail(peg$c106); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c67(s2); + s1 = peg$c101(s2); s0 = s1; } else { peg$currPos = s0; @@ -1791,22 +2154,22 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 39) { - s2 = peg$c72; + s2 = peg$c105; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c73); } + if (peg$silentFails === 0) { peg$fail(peg$c106); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c68; + s2 = peg$c102; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c103); } } if (s2 === peg$FAILED) { - s2 = peg$parseEOLChar(); + s2 = peg$parseLineTerminator(); } } peg$silentFails--; @@ -1822,11 +2185,11 @@ module.exports = (function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c71(s2); + s1 = peg$c104(s2); s0 = s1; } else { peg$currPos = s0; @@ -1846,19 +2209,19 @@ module.exports = (function() { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 91) { - s1 = peg$c75; + s1 = peg$c108; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c76); } + if (peg$silentFails === 0) { peg$fail(peg$c109); } } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 94) { - s2 = peg$c77; + s2 = peg$c110; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c78); } + if (peg$silentFails === 0) { peg$fail(peg$c111); } } if (s2 === peg$FAILED) { s2 = peg$c1; @@ -1878,26 +2241,26 @@ module.exports = (function() { } if (s3 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 93) { - s4 = peg$c79; + s4 = peg$c112; peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 105) { - s5 = peg$c60; + s5 = peg$c94; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c95); } } if (s5 === peg$FAILED) { s5 = peg$c1; } if (s5 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c81(s2, s3, s5); + s1 = peg$c114(s2, s3, s5); s0 = s1; } else { peg$currPos = s0; @@ -1922,7 +2285,7 @@ module.exports = (function() { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c74); } + if (peg$silentFails === 0) { peg$fail(peg$c107); } } return s0; @@ -1935,17 +2298,17 @@ module.exports = (function() { s1 = peg$parseBracketDelimitedCharacter(); if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 45) { - s2 = peg$c82; + s2 = peg$c115; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c83); } + if (peg$silentFails === 0) { peg$fail(peg$c116); } } if (s2 !== peg$FAILED) { s3 = peg$parseBracketDelimitedCharacter(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c84(s1, s3); + s1 = peg$c117(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -1993,22 +2356,22 @@ module.exports = (function() { s1 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 93) { - s2 = peg$c79; + s2 = peg$c112; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c113); } } if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s2 = peg$c68; + s2 = peg$c102; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c103); } } if (s2 === peg$FAILED) { - s2 = peg$parseEOLChar(); + s2 = peg$parseLineTerminator(); } } peg$silentFails--; @@ -2024,11 +2387,11 @@ module.exports = (function() { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c71(s2); + s1 = peg$c104(s2); s0 = s1; } else { peg$currPos = s0; @@ -2047,11 +2410,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c68; + s1 = peg$c102; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c103); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2059,22 +2422,22 @@ module.exports = (function() { s3 = peg$parseDigit(); if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 120) { - s3 = peg$c85; + s3 = peg$c118; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c86); } + if (peg$silentFails === 0) { peg$fail(peg$c119); } } if (s3 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 117) { - s3 = peg$c87; + s3 = peg$c120; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c88); } + if (peg$silentFails === 0) { peg$fail(peg$c121); } } if (s3 === peg$FAILED) { - s3 = peg$parseEOLChar(); + s3 = peg$parseLineTerminator(); } } } @@ -2091,11 +2454,11 @@ module.exports = (function() { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c89(s3); + s1 = peg$c122(s3); s0 = s1; } else { peg$currPos = s0; @@ -2117,12 +2480,12 @@ module.exports = (function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c90) { - s1 = peg$c90; + if (input.substr(peg$currPos, 2) === peg$c123) { + s1 = peg$c123; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c91); } + if (peg$silentFails === 0) { peg$fail(peg$c124); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -2137,7 +2500,7 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c92(); + s1 = peg$c125(); s0 = s1; } else { peg$currPos = s0; @@ -2155,280 +2518,19 @@ module.exports = (function() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; - 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$c94); } - } - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - s3 = peg$currPos; - s4 = peg$parseHexDigit(); - if (s4 !== peg$FAILED) { - s5 = peg$parseHexDigit(); - 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 = input.substring(s2, peg$currPos); - } - s2 = s3; - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c95(s2); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - - return s0; - } - - function peg$parseUnicodeEscapeSequence() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - s0 = peg$currPos; - 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$c97); } - } - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - s3 = peg$currPos; - s4 = peg$parseHexDigit(); - if (s4 !== peg$FAILED) { - s5 = peg$parseHexDigit(); - if (s5 !== peg$FAILED) { - s6 = peg$parseHexDigit(); - if (s6 !== peg$FAILED) { - s7 = peg$parseHexDigit(); - 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; - } - } else { - peg$currPos = s3; - s3 = peg$c0; - } - if (s3 !== peg$FAILED) { - s3 = input.substring(s2, peg$currPos); - } - s2 = s3; - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c95(s2); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - - return s0; - } - - function peg$parseEOLEscapeSequence() { - var s0, s1, s2; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c68; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parseEOL(); - if (s2 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c98(s2); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - - return s0; - } - - function peg$parseDigit() { - var s0; - - 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$c100); } - } - - return s0; - } - - function peg$parseHexDigit() { - var s0; - - 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$c102); } - } - - return s0; - } - - function peg$parseLetter() { - var s0; - - s0 = peg$parseLowerCaseLetter(); - if (s0 === peg$FAILED) { - s0 = peg$parseUpperCaseLetter(); - } - - return s0; - } - - function peg$parseLowerCaseLetter() { - var s0; - - 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$c104); } - } - - return s0; - } - - function peg$parseUpperCaseLetter() { - var s0; - - 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$c106); } - } - - return s0; - } - - function peg$parse__() { - var s0, s1; - - s0 = []; - s1 = peg$parseWhitespace(); - if (s1 === peg$FAILED) { - s1 = peg$parseEOL(); - if (s1 === peg$FAILED) { - s1 = peg$parseComment(); - } - } - while (s1 !== peg$FAILED) { - s0.push(s1); - s1 = peg$parseWhitespace(); - if (s1 === peg$FAILED) { - s1 = peg$parseEOL(); - if (s1 === peg$FAILED) { - s1 = peg$parseComment(); - } - } - } - - return s0; - } - - function peg$parseComment() { - var s0, s1; - - peg$silentFails++; - s0 = peg$parseSingleLineComment(); - if (s0 === peg$FAILED) { - s0 = peg$parseMultiLineComment(); - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c107); } - } - - return s0; - } - - function peg$parseSingleLineComment() { - 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$c126) { + s1 = peg$c126; peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c109); } - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$currPos; - peg$silentFails++; - s5 = peg$parseEOLChar(); - peg$silentFails--; - if (s5 === peg$FAILED) { - s4 = peg$c38; - } else { - peg$currPos = s4; - s4 = peg$c0; - } + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c127); } + } + if (s1 !== peg$FAILED) { + s2 = peg$currPos; + s3 = peg$currPos; + s4 = peg$parseHexDigit(); if (s4 !== peg$FAILED) { - if (input.length > peg$currPos) { - s5 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } - } + s5 = peg$parseHexDigit(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; @@ -2440,41 +2542,13 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$currPos; - peg$silentFails++; - s5 = peg$parseEOLChar(); - peg$silentFails--; - if (s5 === peg$FAILED) { - s4 = peg$c38; - } else { - peg$currPos = s4; - s4 = peg$c0; - } - if (s4 !== peg$FAILED) { - if (input.length > peg$currPos) { - s5 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } - } - 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 = input.substring(s2, peg$currPos); } + s2 = s3; if (s2 !== peg$FAILED) { - s1 = [s1, s2]; + peg$reportedPos = s0; + s1 = peg$c128(s2); s0 = s1; } else { peg$currPos = s0; @@ -2488,85 +2562,34 @@ module.exports = (function() { return s0; } - function peg$parseMultiLineComment() { - var s0, s1, s2, s3, s4, s5; + function peg$parseUnicodeEscapeSequence() { + var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c110) { - s1 = peg$c110; + if (input.substr(peg$currPos, 2) === peg$c129) { + s1 = peg$c129; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c111); } + if (peg$silentFails === 0) { peg$fail(peg$c130); } } if (s1 !== peg$FAILED) { - s2 = []; + s2 = peg$currPos; s3 = peg$currPos; - s4 = peg$currPos; - peg$silentFails++; - 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$c113); } - } - peg$silentFails--; - if (s5 === peg$FAILED) { - s4 = peg$c38; - } else { - peg$currPos = s4; - s4 = peg$c0; - } + s4 = peg$parseHexDigit(); if (s4 !== peg$FAILED) { - if (input.length > peg$currPos) { - s5 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } - } + s5 = peg$parseHexDigit(); 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$currPos; - peg$silentFails++; - 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$c113); } - } - peg$silentFails--; - if (s5 === peg$FAILED) { - s4 = peg$c38; - } else { - peg$currPos = s4; - s4 = peg$c0; - } - if (s4 !== peg$FAILED) { - if (input.length > peg$currPos) { - s5 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } - } - if (s5 !== peg$FAILED) { - s4 = [s4, s5]; - s3 = s4; + s6 = peg$parseHexDigit(); + if (s6 !== peg$FAILED) { + s7 = peg$parseHexDigit(); + 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; @@ -2575,22 +2598,18 @@ module.exports = (function() { peg$currPos = s3; s3 = peg$c0; } + } else { + peg$currPos = s3; + s3 = peg$c0; + } + if (s3 !== peg$FAILED) { + s3 = input.substring(s2, peg$currPos); } + s2 = s3; if (s2 !== peg$FAILED) { - 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$c113); } - } - if (s3 !== peg$FAILED) { - s1 = [s1, s2, s3]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } + peg$reportedPos = s0; + s1 = peg$c128(s2); + s0 = s1; } else { peg$currPos = s0; s0 = peg$c0; @@ -2603,91 +2622,136 @@ module.exports = (function() { return s0; } - function peg$parseEOL() { - var s0, s1; + function peg$parseEOLEscapeSequence() { + var s0, s1, s2; - peg$silentFails++; - if (input.charCodeAt(peg$currPos) === 10) { - s0 = peg$c115; + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 92) { + s1 = peg$c102; peg$currPos++; } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c116); } + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c103); } } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c117) { - s0 = peg$c117; - peg$currPos += 2; + if (s1 !== peg$FAILED) { + s2 = peg$parseLineTerminatorSequence(); + if (s2 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c131(s2); + s0 = s1; } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c118); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 13) { - s0 = peg$c119; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c120); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 8232) { - s0 = peg$c121; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c122); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 8233) { - s0 = peg$c123; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c124); } - } - } - } + peg$currPos = s0; + s0 = peg$c0; } + } else { + peg$currPos = s0; + s0 = peg$c0; } - peg$silentFails--; + + return s0; + } + + function peg$parseDigit() { + var s0; + + if (peg$c132.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c133); } + } + + return s0; + } + + function peg$parseHexDigit() { + var s0; + + if (peg$c134.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c135); } + } + + return s0; + } + + function peg$parseLetter() { + var s0; + + s0 = peg$parseLowerCaseLetter(); if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c114); } + s0 = peg$parseUpperCaseLetter(); } return s0; } - function peg$parseEOLChar() { + function peg$parseLowerCaseLetter() { var s0; - if (peg$c125.test(input.charAt(peg$currPos))) { + if (peg$c136.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c126); } + if (peg$silentFails === 0) { peg$fail(peg$c137); } } return s0; } - function peg$parseWhitespace() { - var s0, s1; + function peg$parseUpperCaseLetter() { + var s0; - peg$silentFails++; - if (peg$c128.test(input.charAt(peg$currPos))) { + if (peg$c138.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c129); } + if (peg$silentFails === 0) { peg$fail(peg$c139); } } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c127); } + + return s0; + } + + function peg$parseZs() { + var s0; + + if (peg$c140.test(input.charAt(peg$currPos))) { + s0 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c141); } + } + + return s0; + } + + function peg$parse__() { + var s0, s1; + + s0 = []; + s1 = peg$parseWhiteSpace(); + if (s1 === peg$FAILED) { + s1 = peg$parseLineTerminatorSequence(); + if (s1 === peg$FAILED) { + s1 = peg$parseComment(); + } + } + while (s1 !== peg$FAILED) { + s0.push(s1); + s1 = peg$parseWhiteSpace(); + if (s1 === peg$FAILED) { + s1 = peg$parseLineTerminatorSequence(); + if (s1 === peg$FAILED) { + s1 = peg$parseComment(); + } + } } return s0; diff --git a/spec/parser.spec.js b/spec/parser.spec.js index bb68165..5a69b0d 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -337,6 +337,58 @@ describe("PEG.js grammar parser", function() { expect('start = ("abcd"\n)').toParseAs(literalGrammar("abcd")); }); + /* The SourceCharacter rule is not tested. */ + + /* Canonical WhiteSpace is " ". */ + it("parses WhiteSpace", function() { + expect('start =\t"abcd"' ).toParseAs(trivialGrammar); + expect('start =\x0B"abcd"' ).toParseAs(trivialGrammar); // no "\v" in IE + expect('start =\f"abcd"' ).toParseAs(trivialGrammar); + expect('start = "abcd"' ).toParseAs(trivialGrammar); + expect('start =\u00A0"abcd"').toParseAs(trivialGrammar); + expect('start =\uFEFF"abcd"').toParseAs(trivialGrammar); + expect('start =\u1680"abcd"').toParseAs(trivialGrammar); + }); + + /* Canonical LineTerminator is "\n". */ + it("parses LineTerminator", function() { + expect('start = "\n"' ).toFailToParse(); + expect('start = "\r"' ).toFailToParse(); + expect('start = "\u2028"').toFailToParse(); + expect('start = "\u2029"').toFailToParse(); + }); + + /* Canonical LineTerminatorSequence is "\r\n". */ + it("parses LineTerminatorSequence", function() { + expect('start =\n"abcd"' ).toParseAs(trivialGrammar); + expect('start =\r\n"abcd"' ).toParseAs(trivialGrammar); + expect('start =\r"abcd"' ).toParseAs(trivialGrammar); + expect('start =\u2028"abcd"').toParseAs(trivialGrammar); + expect('start =\u2029"abcd"').toParseAs(trivialGrammar); + }); + + // Canonical Comment is "/* comment */". + it("parses Comment", function() { + expect('start =// comment\n"abcd"' ).toParseAs(trivialGrammar); + expect('start =/* comment */"abcd"').toParseAs(trivialGrammar); + }); + + // Canonical MultiLineComment is "/* comment */". + it("parses MultiLineComment", function() { + expect('start =/**/"abcd"' ).toParseAs(trivialGrammar); + expect('start =/*a*/"abcd"' ).toParseAs(trivialGrammar); + expect('start =/*aaa*/"abcd"').toParseAs(trivialGrammar); + + expect('start =/**/*/"abcd"').toFailToParse(); + }); + + /* Canonical SingleLineComment is "// comment". */ + it("parses SingleLineComment", function() { + expect('start =//\n"abcd"' ).toParseAs(trivialGrammar); + expect('start =//a\n"abcd"' ).toParseAs(trivialGrammar); + expect('start =//aaa\n"abcd"').toParseAs(trivialGrammar); + }); + /* Canonical Action is "{ code }". */ it("parses Action", function() { expect('start = "abcd" { code }').toParseAs(actionGrammar(" code ")); @@ -534,83 +586,19 @@ describe("PEG.js grammar parser", function() { /* Canonical EOLEscapeSequence is "\\\n". */ it("parses EOLEscapeSequence", function() { - expect('start = "\\\n"' ).toParseAs(literalGrammar("")); + expect('start = "\\\r\n"').toParseAs(literalGrammar("")); }); /* Trivial character class rules are not tested. */ + /* Unicode character category rules are not tested. */ + /* Canonical __ is "\n". */ it("parses __", function() { expect('start ="abcd"' ).toParseAs(trivialGrammar); expect('start = "abcd"' ).toParseAs(trivialGrammar); - expect('start =\n"abcd"' ).toParseAs(trivialGrammar); + expect('start =\r\n"abcd"' ).toParseAs(trivialGrammar); expect('start =/* comment */"abcd"').toParseAs(trivialGrammar); expect('start = "abcd"' ).toParseAs(trivialGrammar); }); - - // Canonical Comment is "/* comment */". - it("parses Comment", function() { - expect('start =// comment\n"abcd"' ).toParseAs(trivialGrammar); - expect('start =/* comment */"abcd"').toParseAs(trivialGrammar); - }); - - /* Canonical SingleLineComment is "// comment". */ - it("parses SingleLineComment", function() { - expect('start =//\n"abcd"' ).toParseAs(trivialGrammar); - expect('start =//a\n"abcd"' ).toParseAs(trivialGrammar); - expect('start =//aaa\n"abcd"').toParseAs(trivialGrammar); - }); - - // Canonical MultiLineComment is "/* comment */". - it("parses MultiLineComment", function() { - expect('start =/**/"abcd"' ).toParseAs(trivialGrammar); - expect('start =/*a*/"abcd"' ).toParseAs(trivialGrammar); - expect('start =/*aaa*/"abcd"').toParseAs(trivialGrammar); - expect('start =/***/"abcd"' ).toParseAs(trivialGrammar); - - expect('start =/**/*/"abcd"').toFailToParse(); - }); - - /* Canonical EOL is "\n". */ - it("parses EOL", function() { - expect('start =\n"abcd"' ).toParseAs(trivialGrammar); - expect('start =\r\n"abcd"' ).toParseAs(trivialGrammar); - expect('start =\r"abcd"' ).toParseAs(trivialGrammar); - expect('start =\u2028"abcd"').toParseAs(trivialGrammar); - expect('start =\u2029"abcd"').toParseAs(trivialGrammar); - }); - - /* Canonical EOLChar is "\n". */ - it("parses EOLChar", function() { - expect('start =\n"abcd"' ).toParseAs(trivialGrammar); - expect('start =\r"abcd"' ).toParseAs(trivialGrammar); - expect('start =\u2028"abcd"').toParseAs(trivialGrammar); - expect('start =\u2029"abcd"').toParseAs(trivialGrammar); - }); - - /* Canonical Whitespace is " ". */ - it("parses Whitespace", function() { - expect('start =\t"abcd"' ).toParseAs(trivialGrammar); - expect('start =\x0B"abcd"' ).toParseAs(trivialGrammar); // no "\v" in IE - expect('start =\f"abcd"' ).toParseAs(trivialGrammar); - expect('start = "abcd"' ).toParseAs(trivialGrammar); - expect('start =\u00A0"abcd"').toParseAs(trivialGrammar); - expect('start =\uFEFF"abcd"').toParseAs(trivialGrammar); - expect('start =\u1680"abcd"').toParseAs(trivialGrammar); - expect('start =\u180E"abcd"').toParseAs(trivialGrammar); - expect('start =\u2000"abcd"').toParseAs(trivialGrammar); - expect('start =\u2001"abcd"').toParseAs(trivialGrammar); - expect('start =\u2002"abcd"').toParseAs(trivialGrammar); - expect('start =\u2003"abcd"').toParseAs(trivialGrammar); - expect('start =\u2004"abcd"').toParseAs(trivialGrammar); - expect('start =\u2005"abcd"').toParseAs(trivialGrammar); - expect('start =\u2006"abcd"').toParseAs(trivialGrammar); - expect('start =\u2007"abcd"').toParseAs(trivialGrammar); - expect('start =\u2008"abcd"').toParseAs(trivialGrammar); - expect('start =\u2009"abcd"').toParseAs(trivialGrammar); - expect('start =\u200A"abcd"').toParseAs(trivialGrammar); - expect('start =\u202F"abcd"').toParseAs(trivialGrammar); - expect('start =\u205F"abcd"').toParseAs(trivialGrammar); - expect('start =\u3000"abcd"').toParseAs(trivialGrammar); - }); }); diff --git a/src/parser.pegjs b/src/parser.pegjs index 0494f07..62cab17 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -171,6 +171,38 @@ Primary /* "Lexical" elements */ +SourceCharacter + = . + +WhiteSpace "whitespace" + = "\t" + / "\v" + / "\f" + / " " + / "\u00A0" + / "\uFEFF" + / Zs + +LineTerminator + = [\n\r\u2028\u2029] + +LineTerminatorSequence "end of line" + = "\n" + / "\r\n" + / "\r" + / "\u2028" + / "\u2029" + +Comment "comment" + = MultiLineComment + / SingleLineComment + +MultiLineComment + = "/*" (!"*/" SourceCharacter)* "*/" + +SingleLineComment + = "//" (!LineTerminator SourceCharacter)* + Action "action" = braced:Braced __ { return braced.substr(1, braced.length - 2); } @@ -210,7 +242,7 @@ DoubleQuotedCharacter / EOLEscapeSequence SimpleDoubleQuotedCharacter - = !('"' / "\\" / EOLChar) char_:. { return char_; } + = !('"' / "\\" / LineTerminator) char_:. { return char_; } SingleQuotedString = "'" chars:SingleQuotedCharacter* "'" { return chars.join(""); } @@ -224,7 +256,7 @@ SingleQuotedCharacter / EOLEscapeSequence SimpleSingleQuotedCharacter - = !("'" / "\\" / EOLChar) char_:. { return char_; } + = !("'" / "\\" / LineTerminator) char_:. { return char_; } Class "character class" = "[" inverted:"^"? parts:(ClassCharacterRange / ClassCharacter)* "]" flags:"i"? { @@ -258,10 +290,10 @@ BracketDelimitedCharacter / EOLEscapeSequence SimpleBracketDelimitedCharacter - = !("]" / "\\" / EOLChar) char_:. { return char_; } + = !("]" / "\\" / LineTerminator) char_:. { return char_; } SimpleEscapeSequence - = "\\" !(Digit / "x" / "u" / EOLChar) char_:. { + = "\\" !(Digit / "x" / "u" / LineTerminator) char_:. { return char_ .replace("b", "\b") .replace("f", "\f") @@ -285,7 +317,7 @@ UnicodeEscapeSequence } EOLEscapeSequence - = "\\" eol:EOL { return ""; } + = "\\" eol:LineTerminatorSequence { return ""; } Digit = [0-9] @@ -303,27 +335,35 @@ LowerCaseLetter UpperCaseLetter = [A-Z] -__ = (Whitespace / EOL / Comment)* - -Comment "comment" - = SingleLineComment - / MultiLineComment - -SingleLineComment - = "//" (!EOLChar .)* - -MultiLineComment - = "/*" (!"*/" .)* "*/" +/* + * Unicode Character Categories + * + * Extracted from the following Unicode Character Database file: + * + * http://www.unicode.org/Public/6.3.0/ucd/extracted/DerivedGeneralCategory.txt + * + * Unix magic used: + * + * grep "; $CATEGORY" DerivedGeneralCategory.txt | # Filter characters + * cut -f1 -d " " | # Extract code points + * grep -v '[0-9a-fA-F]\{5\}' | # Exclude non-BMP characters + * sed -e 's/\.\./-/' | # Adjust formatting + * sed -e 's/\([0-9a-fA-F]\{4\}\)/\\u\1/g' | # Adjust formatting + * tr -d '\n' # Join lines + * + * ECMA-262 allows using Unicode 3.0 or later, version 6.3.0 was the latest one + * at the time of writing. + * + * Non-BMP characters are completely ignored to avoid surrogate pair handling + * (detecting surrogate pairs isn't possible with a simple character class and + * other methods would degrade performance). I don't consider it a big deal as + * even parsers in JavaScript engines of common browsers seem to ignore them. + */ -EOL "end of line" - = "\n" - / "\r\n" - / "\r" - / "\u2028" - / "\u2029" +// Separator, Space +Zs = [\u0020\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000] -EOLChar - = [\n\r\u2028\u2029] +/* Skipped */ -Whitespace "whitespace" - = [ \t\v\f\u00A0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] +__ + = (WhiteSpace / LineTerminatorSequence / Comment)*