Implement \ suppression in {}

This commit is contained in:
Tangent Wantwight 2023-08-21 23:57:27 -04:00
parent 2261d18d56
commit 8c3953cdf0
2 changed files with 11 additions and 13 deletions

View file

@ -112,12 +112,13 @@ b`)
it("can parse nested braces with text", () =>
expect(parse("{a{b}c}")).toEqual([true, [[{ text: "a{b}c" }]]]));
it.failing("doesn't count suppressed braces for nesting", () =>
expect(parse(String.raw`{a\{b}`)).toEqual([true, [[{ text: "a\\{b" }]]])
);
it.failing("doesn't count suppressed braces for unnesting", () =>
expect(parse(String.raw`{a\}b}`)).toEqual([true, [[{ text: "a\\}b" }]]])
);
it("does not allow trailing characters after a closing brace", () =>
expect(parse("{}a")).toMatchObject([false, {}]));
it("doesn't count suppressed braces for nesting", () =>
expect(parse(String.raw`{a\{b}`)).toEqual([true, [[{ text: "a\\{b" }]]]));
it("doesn't count suppressed braces for unnesting", () =>
expect(parse(String.raw`{a\}b}`)).toEqual([true, [[{ text: "a\\}b" }]]]));
it("nests braces after suppressed backslashes", () =>
expect(parse(String.raw`{a\\{b}}`)).toEqual([
true,
@ -143,12 +144,6 @@ b`)
).toEqual([true, [[{ text: "\\\\ " }]]]));
});
// Braces
// nesting
// escapes
// {, }, correct newline folding
// no trailing chars
// "Quotes"
// no trailing chars

View file

@ -31,7 +31,10 @@ const Brace: Pattern<string> = Sequence(
Use(() => Brace)
.expects("{")
.map((text) => `{${text}}`),
Regex(/[^{}]+/y)
Regex(/\\./y)
.expects("\\")
.map(([escape]) => escape),
Regex(/[^\\{}]+/y)
.expects("text")
.map(([text]) => text)
)