From 5d5c8f9499eeb3b14d970b0743f346db971c1c13 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Fri, 22 Mar 2024 19:36:36 -0700 Subject: [PATCH] bump grammarkdown and account for unescaping of < --- package-lock.json | 20 +++++++++++--------- package.json | 2 +- src/formatter/grammarkdown.ts | 13 +++++++++++++ test/formatter.js | 4 ++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index b6bc5f71..01a366cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,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", @@ -1861,12 +1861,13 @@ "dev": true }, "node_modules/grammarkdown": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/grammarkdown/-/grammarkdown-3.2.0.tgz", - "integrity": "sha512-pEVUvG2Kxv/PwM3Dm3kFEU1/GHRkNcFWmk/zkqN/y0uoQtPaZ+5VaBacMQAaFOIL9WGYjHXtqpkT5YRvySsISQ==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/grammarkdown/-/grammarkdown-3.3.2.tgz", + "integrity": "sha512-inNbeEotDr7MENqoZlms3x4gBzvK73wR2NGpNVnw4oEZcsq2METUbAh0J3VWtEqd9t2+U3poEqiJ9CDgBXr5Tg==", "dependencies": { "@esfx/async-canceltoken": "^1.0.0-pre.13", - "@esfx/cancelable": "^1.0.0-pre.13" + "@esfx/cancelable": "^1.0.0-pre.13", + "@esfx/disposable": "^1.0.0-pre.13" }, "bin": { "grammarkdown": "bin/grammarkdown" @@ -4921,12 +4922,13 @@ "dev": true }, "grammarkdown": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/grammarkdown/-/grammarkdown-3.2.0.tgz", - "integrity": "sha512-pEVUvG2Kxv/PwM3Dm3kFEU1/GHRkNcFWmk/zkqN/y0uoQtPaZ+5VaBacMQAaFOIL9WGYjHXtqpkT5YRvySsISQ==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/grammarkdown/-/grammarkdown-3.3.2.tgz", + "integrity": "sha512-inNbeEotDr7MENqoZlms3x4gBzvK73wR2NGpNVnw4oEZcsq2METUbAh0J3VWtEqd9t2+U3poEqiJ9CDgBXr5Tg==", "requires": { "@esfx/async-canceltoken": "^1.0.0-pre.13", - "@esfx/cancelable": "^1.0.0-pre.13" + "@esfx/cancelable": "^1.0.0-pre.13", + "@esfx/disposable": "^1.0.0-pre.13" } }, "graphemer": { diff --git a/package.json b/package.json index af3be09b..e0be8380 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/formatter/grammarkdown.ts b/src/formatter/grammarkdown.ts index 4215139c..b16711d1 100644 --- a/src/formatter/grammarkdown.ts +++ b/src/formatter/grammarkdown.ts @@ -6,6 +6,7 @@ import type { OneOfList, ParameterList, Trivia, + UnicodeCharacterLiteral, } from 'grammarkdown'; import { NewLineKind, @@ -249,6 +250,18 @@ class EmitterWithComments extends GrammarkdownEmitter { this.writer.write('> '); 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('<'); + this.writer.write(node.text!.slice(1, -1)); + this.writer.write('>'); + } } // uuuuugh, grammarkdown is only async diff --git a/test/formatter.js b/test/formatter.js index 56371cd7..6244fae7 100644 --- a/test/formatter.js +++ b/test/formatter.js @@ -339,6 +339,8 @@ describe('grammar formatting', () => { A : B C#prod2 + <ASCII> + U+2000 `, dedentKeepingTrailingNewline` @@ -351,6 +353,8 @@ describe('grammar formatting', () => { A : B C #prod2 + <ASCII> + U+2000 `, );