Skip to content

Commit 00790e1

Browse files
committed
Fix a regression from fad4ab7 in description of character classes
Character class description contains redundant commas between class parts: [1,2,3-5] instead of [123-5] for class [123-5]
1 parent 05fcaff commit 00790e1

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Released: TBD
1919

2020
- [#164](https://github.com/peggyjs/peggy/pull/164): Fix some errors in the typescript definitions
2121
- [#169](https://github.com/peggyjs/peggy/issues/169): Expose string escape functions
22+
- [#197](https://github.com/peggyjs/peggy/pull/197): Fix a regression of redundant commas in the
23+
character classes in the error messages, introduced in fad4ab74d1de67ef1902cd22d479c81ccab73224
2224

2325
1.2.0
2426
-----

lib/compiler/passes/generate-js.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ function generateJS(ast, options) {
554554
" : classEscape(part);",
555555
" });",
556556
"",
557-
" return \"[\" + (expectation.inverted ? \"^\" : \"\") + escapedParts + \"]\";",
557+
" return \"[\" + (expectation.inverted ? \"^\" : \"\") + escapedParts.join(\"\") + \"]\";",
558558
" },",
559559
"",
560560
" any: function() {",

test/api/generated-parser-api.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ describe("generated parser API", () => {
2020
expect(() => { parser.parse("b"); }).to.throw();
2121
});
2222

23+
// Regression: https://github.com/peggyjs/peggy/pull/196
24+
it("correctly describe character class in syntax error", () => {
25+
const parser = peg.generate("start = [123-5]");
26+
27+
expect(() => { parser.parse("0"); }).to.throw("[123-5]");
28+
});
29+
2330
describe("start rule", () => {
2431
const parser = peg.generate([
2532
"a = 'x' { return 'a'; }",

0 commit comments

Comments
 (0)