Skip to content

Commit

Permalink
Fix named NEVER_MATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
markw65 committed Dec 12, 2023
1 parent 63b913d commit 40959eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/compiler/passes/generate-bytecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ function generateBytecode(ast, options) {

named(node, context) {
const match = node.match || 0;
// Expectation not required if node always fail
const nameIndex = (match === NEVER_MATCH)
// Expectation not required if node always match
const nameIndex = (match === ALWAYS_MATCH)
? -1
: addExpectedConst({ type: "rule", value: node.name });

Expand All @@ -618,7 +618,7 @@ function generateBytecode(ast, options) {
[op.SILENT_FAILS_ON],
generate(node.expression, context),
[op.SILENT_FAILS_OFF],
buildCondition(match, [op.IF_ERROR], [op.FAIL, nameIndex], [])
buildCondition(-match, [op.IF_ERROR], [op.FAIL, nameIndex], [])
);
},

Expand Down
4 changes: 2 additions & 2 deletions test/behavior/generated-parser-behavior.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ describe("generated parser behavior", () => {
});
});

it("reports match failure and doesn't records any expectations when expression never match", () => {
it("reports match failure and records an expectation of type \"other\" when expression never match", () => {
const parser = peg.generate("start 'start' = []", options);

expect(parser).to.failToParse("b", {
expected: [],
expected: [{ type:"other", description: "start" }],
});
});

Expand Down

0 comments on commit 40959eb

Please sign in to comment.