Skip to content

Commit

Permalink
Fixes #513. Allow whitespace between plucked word and its pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Jun 19, 2024
1 parent fbd94d6 commit 13df923
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Unreleased
- [#520](https://github.com/peggyjs/peggy/pull/520) Grammar with token "constructor" fails to generate
- [#522](https://github.com/peggyjs/peggy/pull/522) Switched from puppeteer
to playwright for web tests, and added them to CI.
- [#513](https://github.com/peggyjs/peggy/pull/513) Allow whitespace between
plucked word and its pattern.

### Documentation
- [#506](https://github.com/peggyjs/peggy/pull/506) Added END OF INPUT (`!.`).
Expand Down
2 changes: 1 addition & 1 deletion docs/js/benchmark-bundle.min.js

Large diffs are not rendered by default.

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.

10 changes: 5 additions & 5 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1697,11 +1697,10 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$parseLabelColon();
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
s3 = peg$parsePrefixedExpression();
if (s3 !== peg$FAILED) {
s2 = peg$parsePrefixedExpression();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f23(s1, s3);
s0 = peg$f23(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
Expand Down Expand Up @@ -1739,7 +1738,7 @@ function peg$parse(input, options) {
}

function peg$parseLabelColon() {
var s0, s1, s2, s3;
var s0, s1, s2, s3, s4;

s0 = peg$currPos;
s1 = peg$parseIdentifierName();
Expand All @@ -1753,6 +1752,7 @@ function peg$parse(input, options) {
if (peg$silentFails === 0) { peg$fail(peg$e12); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
peg$savedPos = s0;
s0 = peg$f25(s1);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ LabeledExpression
location: location()
};
}
/ label:LabelColon __ expression:PrefixedExpression {
/ label:LabelColon expression:PrefixedExpression {
return {
type: "labeled",
label: label[0],
Expand All @@ -282,7 +282,7 @@ Pluck
= "@" { return location(); }

LabelColon
= label:IdentifierName __ ":" {
= label:IdentifierName __ ":" __ {
if (reservedWords.indexOf(label[0]) >= 0) {
error(`Label can't be a reserved word "${label[0]}"`, label[1]);
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ describe("Peggy grammar parser", () => {
expect("start = a:'abcd'\nb:'efgh'").to.parseAs(
oneRuleGrammar(sequence2)
);
expect("start = a: 'abcd'\nb :'efgh'").to.parseAs(
oneRuleGrammar(sequence2)
);
expect("start = a:'abcd'\nb:'efgh'\nc:'ijkl'\nd:'mnop'").to.parseAs(
oneRuleGrammar(sequence4)
);
Expand Down Expand Up @@ -395,6 +398,15 @@ describe("Peggy grammar parser", () => {
expect("start = @a:'abcd'").to.parseAs(
$S($P("a", literalAbcd))
);
expect("start = @a: 'abcd'").to.parseAs(
$S($P("a", literalAbcd))
);
expect("start = @a :'abcd'").to.parseAs(
$S($P("a", literalAbcd))
);
expect("start = @a : 'abcd'").to.parseAs(
$S($P("a", literalAbcd))
);
expect("start = 'abcd' @'efgh'").to.parseAs(
$S(literalAbcd, $P(null, literalEfgh))
);
Expand Down

0 comments on commit 13df923

Please sign in to comment.