8000 ts SyntaxError by hildjj · Pull Request #619 · peggyjs/peggy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ts SyntaxError #619

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

Merged
merged 4 commits into from
May 7, 2025
Merged
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
17 changes: 9 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ Change Log

This file documents all notable changes to Peggy.

Unreleased
----------

Released: TBD

### Major Changes
5.0.2
-----

### New features
Released: 2025-05-07

### Bug fixes

### Documentation
- Fix TypeScript error in peg.d.ts, SyntaxError constructor should not have a return type.
[#619](https://github.com/peggyjs/peggy/pull/619)
- Add more Unicode to fizzbuzz example.
[#619](https://github.com/peggyjs/peggy/pull/619)
- Catch invalid unicode property escapes at compile time.
[#619](https://github.com/peggyjs/peggy/pull/619)

5.0.1
-----
Expand Down
11 changes: 8 additions & 3 deletions examples/fizzbuzz.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ line
/ buzz

fizzbuzz = f:fizz _ b:buzz { return f + b }
fizz = @"fizz"i !{ return currentNumber % 3 }
buzz = @"buzz"i !{ return currentNumber % 5 }
fizz
= @"fizz"i !{ return currentNumber % 3 }
/ "🍺"

buzz
= @"buzz"i !{ return currentNumber % 5 }
/ "\u{1F41D}"

// Arbitrary requirement needing &
number "number without trailing comment"
= "0x" n:$[0-9a-f]i+ &"\n" { return parseInt(n, 16) }
= "0x" n:$[\p{ASCII_Hex_Digit}]+ &"\n" { return parseInt(n, 16) }
/ n:$[0-9]+ &"\n" { return parseInt(n, 10) }

_ = $[ \t]*
5 changes: 5 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,11 @@ function peg$parse(input, options) {
};
}
function peg$f43(value) {
try {
new RegExp(`[\\${value}]`, "u");
} catch (er) {
error("Invalid Unicode property escape");
}
return {
type: "classEscape",
value,
Expand Down
2 changes: 1 addition & 1 deletion lib/peg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export namespace parser {
expected: Expectation[] | null,
found: string | null,
location: LocationRange
): SyntaxError;
);

/**
* Format the error with associated sources. The `location.source` should have
Expand Down
5 changes: 5 additions & 0 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ AtomEscape

CharacterClassEscape
= value:$("p"i "{" UnicodePropertyValueExpression "}") {
try {
new RegExp(`[\\${value}]`, "u");
} catch (er) {
error("Invalid Unicode property escape");
}
return {
type: "classEscape",
value,
Expand Down
1 change: 1 addition & 0 deletions test/unit/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ describe("Peggy grammar parser", () => {
expect("start = [\\p{a=]").to.failToParse();
expect("start = [\\p{a=b]").to.failToParse();
expect("start = [\\p{\u0661}]").to.failToParse();
expect("start = [\\p{foooo}]u").to.failToParse();
});

// Canonical ClassCharacterRange is "a-d".
Expand Down
0