-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Description
It doesn't parse repeated ". Try ""A\" B\""".
Drop interpretedEscapes, replace string by
string: () =>
token(
P.string('"')
.then(
P.alt(
P.regexp(/[^"\\]+/), // Match normal characters
P.string("\\u")
.then(P.regexp(/[0-9a-fA-F]{4}/))
.map(hex => String.fromCharCode(parseInt(hex, 16))),
P.string('\\"').result('"'), // Handle escaped double-quote
P.string("\\\\").result("\\"), // Handle escaped backslash
P.string("\\n").result("\n"), // Handle escaped newline
P.string("\\b").result("\b"), // Handle backspace
P.string("\\f").result("\f"),
P.string("\\r").result("\r"),
P.string("\\t").result("\t")
).many()
)
.skip(P.string('"'))
)
.map(chars => chars.join("")) // Convert character array to string
.desc("string"),
I didn't test everything but at least that bug is fixed. Maybe there are alternative ways.
The problem was that the example string gets parsed as A" B\", the last \ is wrong.
``
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels