Skip to content

Commit

Permalink
bump grammarkdown and account for unescaping of <
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Mar 25, 2024
1 parent 6eacc76 commit c28df27
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
20 changes: 11 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"ecmarkdown": "^8.1.0",
"eslint-formatter-codeframe": "^7.32.1",
"fast-glob": "^3.2.7",
"grammarkdown": "^3.2.0",
"grammarkdown": "^3.3.2",
"highlight.js": "11.0.1",
"html-escape": "^1.0.2",
"js-yaml": "^3.13.1",
Expand Down
15 changes: 15 additions & 0 deletions src/formatter/grammarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
OneOfList,
ParameterList,
Trivia,
UnicodeCharacterLiteral,
} from 'grammarkdown';
import {
NewLineKind,
Expand Down Expand Up @@ -249,6 +250,20 @@ class EmitterWithComments extends GrammarkdownEmitter {
this.writer.write('&gt; ');
node.fragments && this.emitNodes(node.fragments);
}

emitUnicodeCharacterLiteral(node: UnicodeCharacterLiteral) {
if (node.text?.startsWith('U+')) {
return super.emitUnicodeCharacterLiteral(node);
}
if (!(node.text?.startsWith('<') && node.text?.endsWith('>'))) {
throw new Error(
`unreachable: unicode character literal is not wrapped in <>: ${JSON.stringify(node.text)}`,
);
}
this.writer.write('&lt;');
this.writer.write(node.text.slice(1, -1));
this.writer.write('&gt;');
}
}

// uuuuugh, grammarkdown is only async
Expand Down
4 changes: 4 additions & 0 deletions test/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ describe('grammar formatting', () => {
A :
B
C#prod2
&lt;ASCII&gt;
U+2000
</emu-grammar>
`,
dedentKeepingTrailingNewline`
Expand All @@ -351,6 +353,8 @@ describe('grammar formatting', () => {
A :
B
C #prod2
&lt;ASCII&gt;
U+2000
</emu-grammar>
`,
);
Expand Down
8 changes: 4 additions & 4 deletions test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('linting whole program', () => {
{
ruleId: 'grammarkdown:2008',
nodeType: 'emu-grammar',
message: "Parameter 'a' is unused.",
message: "Parameter 'a' is unused",
},
);
});
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('linting whole program', () => {
{
ruleId: 'grammarkdown:2007',
nodeType: 'emu-grammar',
message: "There is no argument given for parameter 'a'.",
message: "There is no argument given for parameter 'a'",
},
);
});
Expand All @@ -69,7 +69,7 @@ describe('linting whole program', () => {
{
ruleId: 'grammarkdown:2008',
nodeType: 'emu-grammar',
message: "Parameter 'a' is unused.",
message: "Parameter 'a' is unused",
},
);
});
Expand All @@ -84,7 +84,7 @@ describe('linting whole program', () => {
{
ruleId: 'grammarkdown:2000',
nodeType: 'emu-grammar',
message: "Cannot find name: 'Bar'.",
message: "Cannot find name: 'Bar'",
},
);
});
Expand Down

0 comments on commit c28df27

Please sign in to comment.