diff --git a/lib/parser.js b/lib/parser.js index e7d8c0f..44548d9 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -99,65 +99,55 @@ module.exports = (function() { }, peg$c19 = "&", peg$c20 = { type: "literal", value: "&", description: "\"&\"" }, - peg$c21 = function(code) { - return { - type: "semantic_and", - code: code - }; - }, - peg$c22 = function(expression) { + peg$c21 = function(expression) { return { type: "simple_and", expression: expression }; }, - peg$c23 = "!", - peg$c24 = { type: "literal", value: "!", description: "\"!\"" }, - peg$c25 = function(code) { - return { - type: "semantic_not", - code: code - }; - }, - peg$c26 = function(expression) { + peg$c22 = "!", + peg$c23 = { type: "literal", value: "!", description: "\"!\"" }, + peg$c24 = function(expression) { return { type: "simple_not", expression: expression }; }, - peg$c27 = "?", - peg$c28 = { type: "literal", value: "?", description: "\"?\"" }, - peg$c29 = function(expression) { + peg$c25 = "?", + peg$c26 = { type: "literal", value: "?", description: "\"?\"" }, + peg$c27 = function(expression) { return { type: "optional", expression: expression }; }, - peg$c30 = "*", - peg$c31 = { type: "literal", value: "*", description: "\"*\"" }, - peg$c32 = function(expression) { + peg$c28 = "*", + peg$c29 = { type: "literal", value: "*", description: "\"*\"" }, + peg$c30 = function(expression) { return { type: "zero_or_more", expression: expression }; }, - peg$c33 = "+", - peg$c34 = { type: "literal", value: "+", description: "\"+\"" }, - peg$c35 = function(expression) { + peg$c31 = "+", + peg$c32 = { type: "literal", value: "+", description: "\"+\"" }, + peg$c33 = function(expression) { return { type: "one_or_more", expression: expression }; }, - peg$c36 = "(", - peg$c37 = { type: "literal", value: "(", description: "\"(\"" }, - peg$c38 = ")", - peg$c39 = { type: "literal", value: ")", description: "\")\"" }, - peg$c40 = function(expression) { return expression; }, - peg$c41 = void 0, - peg$c42 = function(name) { + peg$c34 = "(", + peg$c35 = { type: "literal", value: "(", description: "\"(\"" }, + peg$c36 = ")", + peg$c37 = { type: "literal", value: ")", description: "\")\"" }, + peg$c38 = function(expression) { return expression; }, + peg$c39 = void 0, + peg$c40 = function(name) { return { type: "rule_ref", name: name } }, + peg$c41 = function(code) { return { type: "semantic_and", code: code }; }, + peg$c42 = function(code) { return { type: "semantic_not", code: code }; }, peg$c43 = { type: "any", description: "any character" }, peg$c44 = { type: "other", description: "whitespace" }, peg$c45 = "\t", @@ -1017,7 +1007,7 @@ module.exports = (function() { if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { - s3 = peg$parseCodeBlock(); + s3 = peg$parseSuffixedExpression(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; s1 = peg$c21(s3); @@ -1036,12 +1026,12 @@ module.exports = (function() { } if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 38) { - s1 = peg$c19; + if (input.charCodeAt(peg$currPos) === 33) { + s1 = peg$c22; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c20); } + if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s1 !== peg$FAILED) { s2 = peg$parse__(); @@ -1049,7 +1039,7 @@ module.exports = (function() { s3 = peg$parseSuffixedExpression(); if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c22(s3); + s1 = peg$c24(s3); s0 = s1; } else { peg$currPos = s0; @@ -1064,67 +1054,7 @@ module.exports = (function() { s0 = peg$c0; } if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 33) { - s1 = peg$c23; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c24); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - s3 = peg$parseCodeBlock(); - if (s3 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c25(s3); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 33) { - s1 = peg$c23; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c24); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parse__(); - if (s2 !== peg$FAILED) { - s3 = peg$parseSuffixedExpression(); - if (s3 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c26(s3); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - } else { - peg$currPos = s0; - s0 = peg$c0; - } - if (s0 === peg$FAILED) { - s0 = peg$parseSuffixedExpression(); - } - } + s0 = peg$parseSuffixedExpression(); } } } @@ -1141,15 +1071,15 @@ module.exports = (function() { s2 = peg$parse__(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { - s3 = peg$c27; + s3 = peg$c25; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c28); } + if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c29(s1); + s1 = peg$c27(s1); s0 = s1; } else { peg$currPos = s0; @@ -1170,15 +1100,15 @@ module.exports = (function() { s2 = peg$parse__(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { - s3 = peg$c30; + s3 = peg$c28; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c31); } + if (peg$silentFails === 0) { peg$fail(peg$c29); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c32(s1); + s1 = peg$c30(s1); s0 = s1; } else { peg$currPos = s0; @@ -1199,15 +1129,15 @@ module.exports = (function() { s2 = peg$parse__(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 43) { - s3 = peg$c33; + s3 = peg$c31; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c34); } + if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s3 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c35(s1); + s1 = peg$c33(s1); s0 = s1; } else { peg$currPos = s0; @@ -1241,32 +1171,38 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$parseRuleReferenceExpression(); if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c36; - 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) { - s3 = peg$parseChoiceExpression(); - if (s3 !== peg$FAILED) { - s4 = peg$parse__(); - if (s4 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c38; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c39); } - } - if (s5 !== peg$FAILED) { - peg$reportedPos = s0; - s1 = peg$c40(s3); - s0 = s1; + s0 = peg$parseSemanticPredicateExpression(); + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 40) { + s1 = peg$c34; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c35); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parse__(); + if (s2 !== peg$FAILED) { + s3 = peg$parseChoiceExpression(); + if (s3 !== peg$FAILED) { + s4 = peg$parse__(); + if (s4 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 41) { + s5 = peg$c36; + peg$currPos++; + } else { + s5 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c37); } + } + if (s5 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c38(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } } else { peg$currPos = s0; s0 = peg$c0; @@ -1283,9 +1219,6 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$c0; } - } else { - peg$currPos = s0; - s0 = peg$c0; } } } @@ -1349,14 +1282,14 @@ module.exports = (function() { } peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; } if (s2 !== peg$FAILED) { peg$reportedPos = s0; - s1 = peg$c42(s1); + s1 = peg$c40(s1); s0 = s1; } else { peg$currPos = s0; @@ -1370,6 +1303,71 @@ module.exports = (function() { return s0; } + function peg$parseSemanticPredicateExpression() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 38) { + s1 = peg$c19; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c20); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parse__(); + if (s2 !== peg$FAILED) { + s3 = peg$parseCodeBlock(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c41(s3); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } + } else { + peg$currPos = s0; + s0 = peg$c0; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 33) { + s1 = peg$c22; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c23); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parse__(); + if (s2 !== peg$FAILED) { + s3 = peg$parseCodeBlock(); + if (s3 !== peg$FAILED) { + peg$reportedPos = s0; + s1 = peg$c42(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$parseSourceCharacter() { var s0; @@ -1564,7 +1562,7 @@ module.exports = (function() { } peg$silentFails--; if (s5 === peg$FAILED) { - s4 = peg$c41; + s4 = peg$c39; } else { peg$currPos = s4; s4 = peg$c0; @@ -1596,7 +1594,7 @@ module.exports = (function() { } peg$silentFails--; if (s5 === peg$FAILED) { - s4 = peg$c41; + s4 = peg$c39; } else { peg$currPos = s4; s4 = peg$c0; @@ -1670,7 +1668,7 @@ module.exports = (function() { } peg$silentFails--; if (s5 === peg$FAILED) { - s4 = peg$c41; + s4 = peg$c39; } else { peg$currPos = s4; s4 = peg$c0; @@ -1705,7 +1703,7 @@ module.exports = (function() { } peg$silentFails--; if (s5 === peg$FAILED) { - s4 = peg$c41; + s4 = peg$c39; } else { peg$currPos = s4; s4 = peg$c0; @@ -1770,7 +1768,7 @@ module.exports = (function() { s5 = peg$parseLineTerminator(); peg$silentFails--; if (s5 === peg$FAILED) { - s4 = peg$c41; + s4 = peg$c39; } else { peg$currPos = s4; s4 = peg$c0; @@ -1796,7 +1794,7 @@ module.exports = (function() { s5 = peg$parseLineTerminator(); peg$silentFails--; if (s5 === peg$FAILED) { - s4 = peg$c41; + s4 = peg$c39; } else { peg$currPos = s4; s4 = peg$c0; @@ -1839,7 +1837,7 @@ module.exports = (function() { s2 = peg$parseReservedWord(); peg$silentFails--; if (s2 === peg$FAILED) { - s1 = peg$c41; + s1 = peg$c39; } else { peg$currPos = s1; s1 = peg$c0; @@ -2319,7 +2317,7 @@ module.exports = (function() { } peg$silentFails--; if (s2 === peg$FAILED) { - s1 = peg$c41; + s1 = peg$c39; } else { peg$currPos = s1; s1 = peg$c0; @@ -2396,7 +2394,7 @@ module.exports = (function() { } peg$silentFails--; if (s2 === peg$FAILED) { - s1 = peg$c41; + s1 = peg$c39; } else { peg$currPos = s1; s1 = peg$c0; @@ -2596,7 +2594,7 @@ module.exports = (function() { } peg$silentFails--; if (s2 === peg$FAILED) { - s1 = peg$c41; + s1 = peg$c39; } else { peg$currPos = s1; s1 = peg$c0; @@ -2694,7 +2692,7 @@ module.exports = (function() { s3 = peg$parseDecimalDigit(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -2867,7 +2865,7 @@ module.exports = (function() { } peg$silentFails--; if (s2 === peg$FAILED) { - s1 = peg$c41; + s1 = peg$c39; } else { peg$currPos = s1; s1 = peg$c0; @@ -3393,7 +3391,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3430,7 +3428,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3467,7 +3465,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3504,7 +3502,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3541,7 +3539,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3578,7 +3576,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3615,7 +3613,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3652,7 +3650,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3689,7 +3687,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3726,7 +3724,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3763,7 +3761,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3800,7 +3798,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3837,7 +3835,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3874,7 +3872,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3911,7 +3909,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3948,7 +3946,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -3985,7 +3983,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4022,7 +4020,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4059,7 +4057,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4096,7 +4094,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4133,7 +4131,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4170,7 +4168,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4207,7 +4205,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4244,7 +4242,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4281,7 +4279,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4318,7 +4316,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4355,7 +4353,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4392,7 +4390,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4429,7 +4427,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4466,7 +4464,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4503,7 +4501,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4540,7 +4538,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4577,7 +4575,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4614,7 +4612,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4651,7 +4649,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4688,7 +4686,7 @@ module.exports = (function() { s3 = peg$parseIdentifierPart(); peg$silentFails--; if (s3 === peg$FAILED) { - s2 = peg$c41; + s2 = peg$c39; } else { peg$currPos = s2; s2 = peg$c0; @@ -4837,7 +4835,7 @@ module.exports = (function() { } peg$silentFails--; if (s1 === peg$FAILED) { - s0 = peg$c41; + s0 = peg$c39; } else { peg$currPos = s0; s0 = peg$c0; diff --git a/spec/parser.spec.js b/spec/parser.spec.js index f484374..69bada4 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -294,12 +294,8 @@ describe("PEG.js grammar parser", function() { it("parses PrefixedExpression", function() { 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)); @@ -322,6 +318,7 @@ describe("PEG.js grammar parser", function() { expect('start = [a-d]' ).toParseAs(classGrammar([["a", "d"]], "[a-d]")); expect('start = .' ).toParseAs(oneRuleGrammar({ type: "any" })); expect('start = a' ).toParseAs(ruleRefGrammar("a")); + expect('start = &{ code }' ).toParseAs(oneRuleGrammar(semanticAnd)); expect('start = ("abcd")' ).toParseAs(literalGrammar("abcd")); expect('start = (\n"abcd")').toParseAs(literalGrammar("abcd")); expect('start = ("abcd"\n)').toParseAs(literalGrammar("abcd")); @@ -332,6 +329,14 @@ describe("PEG.js grammar parser", function() { expect('start = a').toParseAs(ruleRefGrammar("a")); }); + /* Canonical SemanticPredicateExpression is "\"abcd\"". */ + it("parses SemanticPredicateExpression", function() { + expect('start = &{ code }' ).toParseAs(oneRuleGrammar(semanticAnd)); + expect('start = &\n{ code }').toParseAs(oneRuleGrammar(semanticAnd)); + expect('start = !{ code }' ).toParseAs(oneRuleGrammar(semanticNot)); + expect('start = !\n{ code }').toParseAs(oneRuleGrammar(semanticNot)); + }); + /* The SourceCharacter rule is not tested. */ /* Canonical WhiteSpace is " ". */ diff --git a/src/parser.pegjs b/src/parser.pegjs index 4eb872a..bd87c6c 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -107,24 +107,12 @@ PrefixedExpression expression: expression }; } - / "&" __ code:CodeBlock { - return { - type: "semantic_and", - code: code - }; - } / "&" __ expression:SuffixedExpression { return { type: "simple_and", expression: expression }; } - / "!" __ code:CodeBlock { - return { - type: "semantic_not", - code: code - }; - } / "!" __ expression:SuffixedExpression { return { type: "simple_not", @@ -159,6 +147,7 @@ PrimaryExpression / CharacterClassMatcher / AnyMatcher / RuleReferenceExpression + / SemanticPredicateExpression / "(" __ expression:Expression __ ")" { return expression; } RuleReferenceExpression @@ -166,6 +155,10 @@ RuleReferenceExpression return { type: "rule_ref", name: name } } +SemanticPredicateExpression + = "&" __ code:CodeBlock { return { type: "semantic_and", code: code }; } + / "!" __ code:CodeBlock { return { type: "semantic_not", code: code }; } + /* "Lexical" elements */ SourceCharacter