Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predicates shouldn't be wrapped in SILENT_FAILS #455

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/js/benchmark-bundle.min.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions docs/js/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,15 +833,13 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 98) {
s3 = peg$c4;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e9); }
}
peg$silentFails--;
if (s3 !== peg$FAILED) {
peg$currPos = s2;
s2 = undefined;
Expand Down Expand Up @@ -877,15 +875,13 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 98) {
s3 = peg$c4;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e9); }
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down
2 changes: 1 addition & 1 deletion docs/js/test-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/vendor/peggy/peggy.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions lib/compiler/passes/generate-bytecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,12 @@ function generateBytecode(ast, options) {

return buildSequence(
[op.PUSH_CURR_POS],
[op.SILENT_FAILS_ON],
// eslint-disable-next-line no-use-before-define -- Mutual recursion
generate(expression, {
sp: context.sp + 1,
env: cloneEnv(context.env),
action: null,
}),
[op.SILENT_FAILS_OFF],
buildCondition(
negative ? -match : match,
[negative ? op.IF_ERROR : op.IF_NOT_ERROR],
Expand Down
34 changes: 0 additions & 34 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,6 @@ function peg$parse(input, options) {
s1 = peg$parseIdentifierName();
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$currPos;
s4 = peg$parse__();
s5 = peg$currPos;
Expand Down Expand Up @@ -1450,7 +1449,6 @@ function peg$parse(input, options) {
peg$currPos = s3;
s3 = peg$FAILED;
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down Expand Up @@ -1627,15 +1625,13 @@ function peg$parse(input, options) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 2) === peg$c14) {
s5 = peg$c14;
peg$currPos += 2;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e24); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand All @@ -1659,15 +1655,13 @@ function peg$parse(input, options) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 2) === peg$c14) {
s5 = peg$c14;
peg$currPos += 2;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e24); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand Down Expand Up @@ -1725,7 +1719,6 @@ function peg$parse(input, options) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 2) === peg$c14) {
s5 = peg$c14;
peg$currPos += 2;
Expand All @@ -1736,7 +1729,6 @@ function peg$parse(input, options) {
if (s5 === peg$FAILED) {
s5 = peg$parseLineTerminator();
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand All @@ -1760,7 +1752,6 @@ function peg$parse(input, options) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 2) === peg$c14) {
s5 = peg$c14;
peg$currPos += 2;
Expand All @@ -1771,7 +1762,6 @@ function peg$parse(input, options) {
if (s5 === peg$FAILED) {
s5 = peg$parseLineTerminator();
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand Down Expand Up @@ -1829,9 +1819,7 @@ function peg$parse(input, options) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = peg$parseLineTerminator();
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand All @@ -1855,9 +1843,7 @@ function peg$parse(input, options) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = peg$parseLineTerminator();
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand Down Expand Up @@ -2116,15 +2102,13 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$currPos;
peg$silentFails++;
s3 = input.charAt(peg$currPos);
if (peg$r10.test(s3)) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e37); }
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down Expand Up @@ -2184,15 +2168,13 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$currPos;
peg$silentFails++;
s3 = input.charAt(peg$currPos);
if (peg$r11.test(s3)) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e38); }
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down Expand Up @@ -2358,15 +2340,13 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$currPos;
peg$silentFails++;
s3 = input.charAt(peg$currPos);
if (peg$r12.test(s3)) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e44); }
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down Expand Up @@ -2463,9 +2443,7 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseDecimalDigit();
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down Expand Up @@ -2615,12 +2593,10 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$currPos;
peg$silentFails++;
s3 = peg$parseEscapeCharacter();
if (s3 === peg$FAILED) {
s3 = peg$parseLineTerminator();
}
peg$silentFails--;
if (s3 === peg$FAILED) {
s2 = undefined;
} else {
Expand Down Expand Up @@ -2882,15 +2858,13 @@ function peg$parse(input, options) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = input.charAt(peg$currPos);
if (peg$r17.test(s5)) {
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e60); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand All @@ -2915,15 +2889,13 @@ function peg$parse(input, options) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = input.charAt(peg$currPos);
if (peg$r17.test(s5)) {
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e60); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand Down Expand Up @@ -2982,15 +2954,13 @@ function peg$parse(input, options) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = input.charAt(peg$currPos);
if (peg$r17.test(s5)) {
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e60); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand All @@ -3015,15 +2985,13 @@ function peg$parse(input, options) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = input.charAt(peg$currPos);
if (peg$r17.test(s5)) {
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e60); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = undefined;
} else {
Expand Down Expand Up @@ -3389,15 +3357,13 @@ function peg$parse(input, options) {
var s0, s1;

s0 = peg$currPos;
peg$silentFails++;
if (input.length > peg$currPos) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e14); }
}
peg$silentFails--;
if (s1 === peg$FAILED) {
s0 = undefined;
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/behavior/generated-parser-behavior.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2177,12 +2177,13 @@ describe("generated parser behavior", () => {
expect(parser).to.failToParse("b");
});

it("discards any expectations recorded when matching the expression", () => {
it("keeps any expectations recorded when matching the expression", () => {
const parser = peg.generate("start = 'a' / &'b' / 'c'", options);

expect(parser).to.failToParse("d", {
expected: [
{ type: "literal", text: "a", ignoreCase: false },
{ type: "literal", text: "b", ignoreCase: false },
{ type: "literal", text: "c", ignoreCase: false },
],
});
Expand Down
4 changes: 0 additions & 4 deletions test/unit/compiler/passes/generate-bytecode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ describe("compiler pass |generateBytecode|", () => {
it("generates correct bytecode", () => {
expect(pass).to.changeAST(grammar, bytecodeDetails([
5, // PUSH_CURR_POS
28, // SILENT_FAILS_ON
18, 0, 2, 2, 22, 0, 23, 0, // <expression>
29, // SILENT_FAILS_OFF
15, 3, 3, // IF_NOT_ERROR
6, // * POP
7, // POP_CURR_POS
Expand All @@ -427,9 +425,7 @@ describe("compiler pass |generateBytecode|", () => {
it("generates correct bytecode", () => {
expect(pass).to.changeAST(grammar, bytecodeDetails([
5, // PUSH_CURR_POS
28, // SILENT_FAILS_ON
18, 0, 2, 2, 22, 0, 23, 0, // <expression>
29, // SILENT_FAILS_OFF
14, 3, 3, // IF_ERROR
6, // * POP
6, // POP
Expand Down