aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-06-25 18:10:10 +0900
committernsfisis <nsfisis@gmail.com>2023-06-25 18:22:35 +0900
commitae35f799ef6530736260a349ff026670fc600ff7 (patch)
treefd8942061121c6125a4bebfaed07eff9bdeac036 /nuldoc-src
parentb8ff78a1a631fe27d7a66a454805a116d96738d8 (diff)
downloadblog.nsfisis.dev-ae35f799ef6530736260a349ff026670fc600ff7.tar.gz
blog.nsfisis.dev-ae35f799ef6530736260a349ff026670fc600ff7.tar.zst
blog.nsfisis.dev-ae35f799ef6530736260a349ff026670fc600ff7.zip
feat(nuldoc): improve readability of error messages
Diffstat (limited to 'nuldoc-src')
-rw-r--r--nuldoc-src/xml.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/nuldoc-src/xml.ts b/nuldoc-src/xml.ts
index 87c2b71..847b5e1 100644
--- a/nuldoc-src/xml.ts
+++ b/nuldoc-src/xml.ts
@@ -203,7 +203,9 @@ function expect(p: Parser, expected: string) {
}
if (actual !== expected) {
throw new XmlParseError(
- `[parse.expect] expected ${expected}, but actually got ${actual} (pos: ${p.index})`,
+ `[parse.expect] expected ${expected}, but actually got ${
+ escapeForHuman(actual)
+ } (pos: ${p.index})`,
);
}
}
@@ -257,3 +259,11 @@ function replaceEntityReferences(s: string): string {
.replaceAll(/&apos;/g, "'")
.replaceAll(/&quot;/g, '"');
}
+
+function escapeForHuman(s: string): string {
+ // support more characters?
+ return s
+ .replaceAll("\n", "\\n")
+ .replaceAll("\t", "\\t")
+ .replaceAll("\r", "\\r");
+}