PEG.js grammar: Extract the |SemanticPredicateExpression| rule

Semantic predicates are kind of |PrimaryExpression|, not kind of
|PrefixedExpression|. Therefore I extracted a rule for them and
referenced it from the |PrimaryExpression|.
redux
David Majda 10 years ago
parent da18f6a729
commit 45c29a886f

@ -99,65 +99,55 @@ module.exports = (function() {
}, },
peg$c19 = "&", peg$c19 = "&",
peg$c20 = { type: "literal", value: "&", description: "\"&\"" }, peg$c20 = { type: "literal", value: "&", description: "\"&\"" },
peg$c21 = function(code) { peg$c21 = function(expression) {
return {
type: "semantic_and",
code: code
};
},
peg$c22 = function(expression) {
return { return {
type: "simple_and", type: "simple_and",
expression: expression expression: expression
}; };
}, },
peg$c23 = "!", peg$c22 = "!",
peg$c24 = { type: "literal", value: "!", description: "\"!\"" }, peg$c23 = { type: "literal", value: "!", description: "\"!\"" },
peg$c25 = function(code) { peg$c24 = function(expression) {
return {
type: "semantic_not",
code: code
};
},
peg$c26 = function(expression) {
return { return {
type: "simple_not", type: "simple_not",
expression: expression expression: expression
}; };
}, },
peg$c27 = "?", peg$c25 = "?",
peg$c28 = { type: "literal", value: "?", description: "\"?\"" }, peg$c26 = { type: "literal", value: "?", description: "\"?\"" },
peg$c29 = function(expression) { peg$c27 = function(expression) {
return { return {
type: "optional", type: "optional",
expression: expression expression: expression
}; };
}, },
peg$c30 = "*", peg$c28 = "*",
peg$c31 = { type: "literal", value: "*", description: "\"*\"" }, peg$c29 = { type: "literal", value: "*", description: "\"*\"" },
peg$c32 = function(expression) { peg$c30 = function(expression) {
return { return {
type: "zero_or_more", type: "zero_or_more",
expression: expression expression: expression
}; };
}, },
peg$c33 = "+", peg$c31 = "+",
peg$c34 = { type: "literal", value: "+", description: "\"+\"" }, peg$c32 = { type: "literal", value: "+", description: "\"+\"" },
peg$c35 = function(expression) { peg$c33 = function(expression) {
return { return {
type: "one_or_more", type: "one_or_more",
expression: expression expression: expression
}; };
}, },
peg$c36 = "(", peg$c34 = "(",
peg$c37 = { type: "literal", value: "(", description: "\"(\"" }, peg$c35 = { type: "literal", value: "(", description: "\"(\"" },
peg$c38 = ")", peg$c36 = ")",
peg$c39 = { type: "literal", value: ")", description: "\")\"" }, peg$c37 = { type: "literal", value: ")", description: "\")\"" },
peg$c40 = function(expression) { return expression; }, peg$c38 = function(expression) { return expression; },
peg$c41 = void 0, peg$c39 = void 0,
peg$c42 = function(name) { peg$c40 = function(name) {
return { type: "rule_ref", name: 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$c43 = { type: "any", description: "any character" },
peg$c44 = { type: "other", description: "whitespace" }, peg$c44 = { type: "other", description: "whitespace" },
peg$c45 = "\t", peg$c45 = "\t",
@ -1017,7 +1007,7 @@ module.exports = (function() {
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = peg$parse__(); s2 = peg$parse__();
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
s3 = peg$parseCodeBlock(); s3 = peg$parseSuffixedExpression();
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$reportedPos = s0; peg$reportedPos = s0;
s1 = peg$c21(s3); s1 = peg$c21(s3);
@ -1036,12 +1026,12 @@ module.exports = (function() {
} }
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s0 = peg$currPos; s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 38) { if (input.charCodeAt(peg$currPos) === 33) {
s1 = peg$c19; s1 = peg$c22;
peg$currPos++; peg$currPos++;
} else { } else {
s1 = peg$FAILED; s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c20); } if (peg$silentFails === 0) { peg$fail(peg$c23); }
} }
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = peg$parse__(); s2 = peg$parse__();
@ -1049,7 +1039,7 @@ module.exports = (function() {
s3 = peg$parseSuffixedExpression(); s3 = peg$parseSuffixedExpression();
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$reportedPos = s0; peg$reportedPos = s0;
s1 = peg$c22(s3); s1 = peg$c24(s3);
s0 = s1; s0 = s1;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
@ -1064,67 +1054,7 @@ module.exports = (function() {
s0 = peg$c0; s0 = peg$c0;
} }
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s0 = peg$currPos; s0 = peg$parseSuffixedExpression();
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();
}
}
} }
} }
} }
@ -1141,15 +1071,15 @@ module.exports = (function() {
s2 = peg$parse__(); s2 = peg$parse__();
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 63) { if (input.charCodeAt(peg$currPos) === 63) {
s3 = peg$c27; s3 = peg$c25;
peg$currPos++; peg$currPos++;
} else { } else {
s3 = peg$FAILED; s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c28); } if (peg$silentFails === 0) { peg$fail(peg$c26); }
} }
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$reportedPos = s0; peg$reportedPos = s0;
s1 = peg$c29(s1); s1 = peg$c27(s1);
s0 = s1; s0 = s1;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
@ -1170,15 +1100,15 @@ module.exports = (function() {
s2 = peg$parse__(); s2 = peg$parse__();
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 42) { if (input.charCodeAt(peg$currPos) === 42) {
s3 = peg$c30; s3 = peg$c28;
peg$currPos++; peg$currPos++;
} else { } else {
s3 = peg$FAILED; s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); } if (peg$silentFails === 0) { peg$fail(peg$c29); }
} }
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$reportedPos = s0; peg$reportedPos = s0;
s1 = peg$c32(s1); s1 = peg$c30(s1);
s0 = s1; s0 = s1;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
@ -1199,15 +1129,15 @@ module.exports = (function() {
s2 = peg$parse__(); s2 = peg$parse__();
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 43) { if (input.charCodeAt(peg$currPos) === 43) {
s3 = peg$c33; s3 = peg$c31;
peg$currPos++; peg$currPos++;
} else { } else {
s3 = peg$FAILED; s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c34); } if (peg$silentFails === 0) { peg$fail(peg$c32); }
} }
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$reportedPos = s0; peg$reportedPos = s0;
s1 = peg$c35(s1); s1 = peg$c33(s1);
s0 = s1; s0 = s1;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
@ -1241,32 +1171,38 @@ module.exports = (function() {
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s0 = peg$parseRuleReferenceExpression(); s0 = peg$parseRuleReferenceExpression();
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s0 = peg$currPos; s0 = peg$parseSemanticPredicateExpression();
if (input.charCodeAt(peg$currPos) === 40) { if (s0 === peg$FAILED) {
s1 = peg$c36; s0 = peg$currPos;
peg$currPos++; if (input.charCodeAt(peg$currPos) === 40) {
} else { s1 = peg$c34;
s1 = peg$FAILED; peg$currPos++;
if (peg$silentFails === 0) { peg$fail(peg$c37); } } else {
} s1 = peg$FAILED;
if (s1 !== peg$FAILED) { if (peg$silentFails === 0) { peg$fail(peg$c35); }
s2 = peg$parse__(); }
if (s2 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s3 = peg$parseChoiceExpression(); s2 = peg$parse__();
if (s3 !== peg$FAILED) { if (s2 !== peg$FAILED) {
s4 = peg$parse__(); s3 = peg$parseChoiceExpression();
if (s4 !== peg$FAILED) { if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 41) { s4 = peg$parse__();
s5 = peg$c38; if (s4 !== peg$FAILED) {
peg$currPos++; if (input.charCodeAt(peg$currPos) === 41) {
} else { s5 = peg$c36;
s5 = peg$FAILED; peg$currPos++;
if (peg$silentFails === 0) { peg$fail(peg$c39); } } else {
} s5 = peg$FAILED;
if (s5 !== peg$FAILED) { if (peg$silentFails === 0) { peg$fail(peg$c37); }
peg$reportedPos = s0; }
s1 = peg$c40(s3); if (s5 !== peg$FAILED) {
s0 = s1; peg$reportedPos = s0;
s1 = peg$c38(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$c0;
}
} else { } else {
peg$currPos = s0; peg$currPos = s0;
s0 = peg$c0; s0 = peg$c0;
@ -1283,9 +1219,6 @@ module.exports = (function() {
peg$currPos = s0; peg$currPos = s0;
s0 = peg$c0; s0 = peg$c0;
} }
} else {
peg$currPos = s0;
s0 = peg$c0;
} }
} }
} }
@ -1349,14 +1282,14 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
} }
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
peg$reportedPos = s0; peg$reportedPos = s0;
s1 = peg$c42(s1); s1 = peg$c40(s1);
s0 = s1; s0 = s1;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
@ -1370,6 +1303,71 @@ module.exports = (function() {
return s0; 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() { function peg$parseSourceCharacter() {
var s0; var s0;
@ -1564,7 +1562,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s5 === peg$FAILED) { if (s5 === peg$FAILED) {
s4 = peg$c41; s4 = peg$c39;
} else { } else {
peg$currPos = s4; peg$currPos = s4;
s4 = peg$c0; s4 = peg$c0;
@ -1596,7 +1594,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s5 === peg$FAILED) { if (s5 === peg$FAILED) {
s4 = peg$c41; s4 = peg$c39;
} else { } else {
peg$currPos = s4; peg$currPos = s4;
s4 = peg$c0; s4 = peg$c0;
@ -1670,7 +1668,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s5 === peg$FAILED) { if (s5 === peg$FAILED) {
s4 = peg$c41; s4 = peg$c39;
} else { } else {
peg$currPos = s4; peg$currPos = s4;
s4 = peg$c0; s4 = peg$c0;
@ -1705,7 +1703,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s5 === peg$FAILED) { if (s5 === peg$FAILED) {
s4 = peg$c41; s4 = peg$c39;
} else { } else {
peg$currPos = s4; peg$currPos = s4;
s4 = peg$c0; s4 = peg$c0;
@ -1770,7 +1768,7 @@ module.exports = (function() {
s5 = peg$parseLineTerminator(); s5 = peg$parseLineTerminator();
peg$silentFails--; peg$silentFails--;
if (s5 === peg$FAILED) { if (s5 === peg$FAILED) {
s4 = peg$c41; s4 = peg$c39;
} else { } else {
peg$currPos = s4; peg$currPos = s4;
s4 = peg$c0; s4 = peg$c0;
@ -1796,7 +1794,7 @@ module.exports = (function() {
s5 = peg$parseLineTerminator(); s5 = peg$parseLineTerminator();
peg$silentFails--; peg$silentFails--;
if (s5 === peg$FAILED) { if (s5 === peg$FAILED) {
s4 = peg$c41; s4 = peg$c39;
} else { } else {
peg$currPos = s4; peg$currPos = s4;
s4 = peg$c0; s4 = peg$c0;
@ -1839,7 +1837,7 @@ module.exports = (function() {
s2 = peg$parseReservedWord(); s2 = peg$parseReservedWord();
peg$silentFails--; peg$silentFails--;
if (s2 === peg$FAILED) { if (s2 === peg$FAILED) {
s1 = peg$c41; s1 = peg$c39;
} else { } else {
peg$currPos = s1; peg$currPos = s1;
s1 = peg$c0; s1 = peg$c0;
@ -2319,7 +2317,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s2 === peg$FAILED) { if (s2 === peg$FAILED) {
s1 = peg$c41; s1 = peg$c39;
} else { } else {
peg$currPos = s1; peg$currPos = s1;
s1 = peg$c0; s1 = peg$c0;
@ -2396,7 +2394,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s2 === peg$FAILED) { if (s2 === peg$FAILED) {
s1 = peg$c41; s1 = peg$c39;
} else { } else {
peg$currPos = s1; peg$currPos = s1;
s1 = peg$c0; s1 = peg$c0;
@ -2596,7 +2594,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s2 === peg$FAILED) { if (s2 === peg$FAILED) {
s1 = peg$c41; s1 = peg$c39;
} else { } else {
peg$currPos = s1; peg$currPos = s1;
s1 = peg$c0; s1 = peg$c0;
@ -2694,7 +2692,7 @@ module.exports = (function() {
s3 = peg$parseDecimalDigit(); s3 = peg$parseDecimalDigit();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -2867,7 +2865,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s2 === peg$FAILED) { if (s2 === peg$FAILED) {
s1 = peg$c41; s1 = peg$c39;
} else { } else {
peg$currPos = s1; peg$currPos = s1;
s1 = peg$c0; s1 = peg$c0;
@ -3393,7 +3391,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3430,7 +3428,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3467,7 +3465,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3504,7 +3502,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3541,7 +3539,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3578,7 +3576,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3615,7 +3613,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3652,7 +3650,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3689,7 +3687,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3726,7 +3724,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3763,7 +3761,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3800,7 +3798,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3837,7 +3835,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3874,7 +3872,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3911,7 +3909,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3948,7 +3946,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -3985,7 +3983,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4022,7 +4020,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4059,7 +4057,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4096,7 +4094,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4133,7 +4131,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4170,7 +4168,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4207,7 +4205,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4244,7 +4242,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4281,7 +4279,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4318,7 +4316,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4355,7 +4353,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4392,7 +4390,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4429,7 +4427,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4466,7 +4464,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4503,7 +4501,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4540,7 +4538,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4577,7 +4575,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4614,7 +4612,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4651,7 +4649,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4688,7 +4686,7 @@ module.exports = (function() {
s3 = peg$parseIdentifierPart(); s3 = peg$parseIdentifierPart();
peg$silentFails--; peg$silentFails--;
if (s3 === peg$FAILED) { if (s3 === peg$FAILED) {
s2 = peg$c41; s2 = peg$c39;
} else { } else {
peg$currPos = s2; peg$currPos = s2;
s2 = peg$c0; s2 = peg$c0;
@ -4837,7 +4835,7 @@ module.exports = (function() {
} }
peg$silentFails--; peg$silentFails--;
if (s1 === peg$FAILED) { if (s1 === peg$FAILED) {
s0 = peg$c41; s0 = peg$c39;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
s0 = peg$c0; s0 = peg$c0;

@ -294,12 +294,8 @@ describe("PEG.js grammar parser", function() {
it("parses PrefixedExpression", function() { it("parses PrefixedExpression", function() {
expect('start = $"abcd"?' ).toParseAs(oneRuleGrammar(textOptionalLiteral)); expect('start = $"abcd"?' ).toParseAs(oneRuleGrammar(textOptionalLiteral));
expect('start = $\n"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 = &"abcd"?' ).toParseAs(oneRuleGrammar(simpleAndOptionalLiteral));
expect('start = &\n"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 = !"abcd"?' ).toParseAs(oneRuleGrammar(simpleNotOptionalLiteral));
expect('start = !\n"abcd"?' ).toParseAs(oneRuleGrammar(simpleNotOptionalLiteral)); expect('start = !\n"abcd"?' ).toParseAs(oneRuleGrammar(simpleNotOptionalLiteral));
expect('start = "abcd"?' ).toParseAs(oneRuleGrammar(optionalLiteral)); 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 = [a-d]' ).toParseAs(classGrammar([["a", "d"]], "[a-d]"));
expect('start = .' ).toParseAs(oneRuleGrammar({ type: "any" })); expect('start = .' ).toParseAs(oneRuleGrammar({ type: "any" }));
expect('start = a' ).toParseAs(ruleRefGrammar("a")); expect('start = a' ).toParseAs(ruleRefGrammar("a"));
expect('start = &{ code }' ).toParseAs(oneRuleGrammar(semanticAnd));
expect('start = ("abcd")' ).toParseAs(literalGrammar("abcd")); expect('start = ("abcd")' ).toParseAs(literalGrammar("abcd"));
expect('start = (\n"abcd")').toParseAs(literalGrammar("abcd")); expect('start = (\n"abcd")').toParseAs(literalGrammar("abcd"));
expect('start = ("abcd"\n)').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")); 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. */ /* The SourceCharacter rule is not tested. */
/* Canonical WhiteSpace is " ". */ /* Canonical WhiteSpace is " ". */

@ -107,24 +107,12 @@ PrefixedExpression
expression: expression expression: expression
}; };
} }
/ "&" __ code:CodeBlock {
return {
type: "semantic_and",
code: code
};
}
/ "&" __ expression:SuffixedExpression { / "&" __ expression:SuffixedExpression {
return { return {
type: "simple_and", type: "simple_and",
expression: expression expression: expression
}; };
} }
/ "!" __ code:CodeBlock {
return {
type: "semantic_not",
code: code
};
}
/ "!" __ expression:SuffixedExpression { / "!" __ expression:SuffixedExpression {
return { return {
type: "simple_not", type: "simple_not",
@ -159,6 +147,7 @@ PrimaryExpression
/ CharacterClassMatcher / CharacterClassMatcher
/ AnyMatcher / AnyMatcher
/ RuleReferenceExpression / RuleReferenceExpression
/ SemanticPredicateExpression
/ "(" __ expression:Expression __ ")" { return expression; } / "(" __ expression:Expression __ ")" { return expression; }
RuleReferenceExpression RuleReferenceExpression
@ -166,6 +155,10 @@ RuleReferenceExpression
return { type: "rule_ref", name: name } 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 */ /* "Lexical" elements */
SourceCharacter SourceCharacter

Loading…
Cancel
Save