Skip to content

Commit 67639ea

Browse files
committed
Fix atom quoting in pretty-plz unparser
Quotes were only being used for atoms beginning with a quote-requiring character sequence, rather than atoms containing any such sequences.
1 parent 8fc3245 commit 67639ea

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/language/unparsing/pretty-plz.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ const arrow = kleur.dim('=>')
2929
const escapeStringContents = (value: string) =>
3030
value.replace('\\', '\\\\').replace('"', '\\"')
3131

32-
const quoteIfNecessary = (value: string) =>
33-
!either.isLeft(unquotedAtomParser(value))
34-
? value
35-
: quote.concat(escapeStringContents(value)).concat(quote)
32+
const quoteIfNecessary = (value: string) => {
33+
const unquotedAtomResult = unquotedAtomParser(value)
34+
if (
35+
either.isLeft(unquotedAtomResult) ||
36+
unquotedAtomResult.value.remainingInput.length !== 0
37+
) {
38+
return quote.concat(escapeStringContents(value)).concat(quote)
39+
} else {
40+
return value
41+
}
42+
}
3643

3744
const atom = (node: string): Right<string> =>
3845
either.makeRight(

0 commit comments

Comments
 (0)