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 23, 2024
1 parent 6eacc76 commit 5d5c8f9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 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
13 changes: 13 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,18 @@ 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

0 comments on commit 5d5c8f9

Please sign in to comment.