Skip to content

Commit

Permalink
Merge pull request #524 from hildjj/pluck-ws
Browse files Browse the repository at this point in the history
Allow whitespace between plucked word and its pattern
  • Loading branch information
hildjj authored Jun 19, 2024
2 parents fbd94d6 + f5dd1a9 commit aa1073f
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: echo "PLAYWRIGHT_VERSION=$(pnpm ls @playwright/test --parseable | tail -1)" >> $GITHUB_ENV
working-directory: web-test
- name: Cache playwright binaries
uses: actions/cache@v3
uses: actions/cache@v4
id: playwright-cache
with:
path: |
Expand Down
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
16 changes: 11 additions & 5 deletions web-test/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

const { defineConfig, devices } = require("@playwright/test");

const isCI = Boolean(process.env.CI);
const timeout = isCI ? 300000 : 5000;

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
Expand All @@ -17,11 +20,11 @@ module.exports = defineConfig({
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: Boolean(process.env.CI),
forbidOnly: isCI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
retries: isCI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: isCI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
["list"],
Expand All @@ -35,7 +38,10 @@ module.exports = defineConfig({
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

timeout,
expect: {
timeout,
},
/* Configure projects for major browsers */
projects: [
{
Expand Down Expand Up @@ -78,7 +84,7 @@ module.exports = defineConfig({
webServer: {
command: "npm run start",
url: "http://localhost:8080/",
reuseExistingServer: !process.env.CI,
reuseExistingServer: !isCI,
},
});

0 comments on commit aa1073f

Please sign in to comment.