@@ -22,32 +22,10 @@ export const isAtom = (value: unknown): value is Atom =>
2222export const unit = '' as const
2323
2424export const atomParser : Parser < Atom > = optionallySurroundedByParentheses (
25- lazy ( ( ) => oneOf ( [ quotedAtom , unquotedAtom ] ) ) ,
25+ lazy ( ( ) => oneOf ( [ unquotedAtomParser , quotedAtomParser ] ) ) ,
2626)
2727
28- const quotedAtom = map (
29- sequence ( [
30- as ( literal ( '"' ) , '' ) ,
31- map (
32- zeroOrMore (
33- oneOf ( [
34- butNot (
35- anySingleCharacter ,
36- oneOf ( [ literal ( '"' ) , literal ( '\\' ) ] ) ,
37- '`"` or `\\`' ,
38- ) ,
39- as ( literal ( '\\"' ) , '"' ) ,
40- as ( literal ( '\\\\' ) , '\\' ) ,
41- ] ) ,
42- ) ,
43- output => output . join ( '' ) ,
44- ) ,
45- as ( literal ( '"' ) , '' ) ,
46- ] ) ,
47- ( [ _1 , contents , _2 ] ) => contents ,
48- )
49-
50- const unquotedAtom = map (
28+ export const unquotedAtomParser = map (
5129 oneOrMore (
5230 butNot (
5331 anySingleCharacter ,
@@ -80,4 +58,25 @@ const unquotedAtom = map(
8058 characters => characters . join ( '' ) ,
8159)
8260
83- export { unquotedAtom as unquotedAtomParser }
61+ const quotedAtomParser = map (
62+ sequence ( [
63+ literal ( '"' ) ,
64+ map (
65+ zeroOrMore (
66+ oneOf ( [
67+ // `"` and `\` need to be escaped
68+ butNot (
69+ anySingleCharacter ,
70+ oneOf ( [ literal ( '"' ) , literal ( '\\' ) ] ) ,
71+ '`"` or `\\`' ,
72+ ) ,
73+ as ( literal ( '\\"' ) , '"' ) ,
74+ as ( literal ( '\\\\' ) , '\\' ) ,
75+ ] ) ,
76+ ) ,
77+ output => output . join ( '' ) ,
78+ ) ,
79+ literal ( '"' ) ,
80+ ] ) ,
81+ ( [ _1 , contents , _2 ] ) => contents ,
82+ )
0 commit comments