fix string escapes
This commit is contained in:
parent
c61981fa16
commit
9584a21521
|
@ -49,10 +49,10 @@
|
||||||
(set (out :draw) (post :draw))
|
(set (out :draw) (post :draw))
|
||||||
(-> out j/encode string))
|
(-> out j/encode string))
|
||||||
|
|
||||||
(comment
|
# (comment
|
||||||
# (do
|
(do
|
||||||
(def source `
|
(def source `
|
||||||
words ("foo bar")
|
"foo \bbar"
|
||||||
`)
|
`)
|
||||||
(def out (-> source
|
(def out (-> source
|
||||||
ludus
|
ludus
|
||||||
|
|
|
@ -194,6 +194,15 @@
|
||||||
:else (add-error scanner (string "Unexpected " curr " after number " num ".")))))
|
:else (add-error scanner (string "Unexpected " curr " after number " num ".")))))
|
||||||
(recur scanner (buffer char) false))
|
(recur scanner (buffer char) false))
|
||||||
|
|
||||||
|
(def escape {
|
||||||
|
"\"" "\""
|
||||||
|
"n" "\n"
|
||||||
|
"{" "{"
|
||||||
|
"t" "\t"
|
||||||
|
"r" "\r"
|
||||||
|
"\\" "\\"
|
||||||
|
})
|
||||||
|
|
||||||
(defn- add-string
|
(defn- add-string
|
||||||
[scanner]
|
[scanner]
|
||||||
(defn recur [scanner buff interpolate?]
|
(defn recur [scanner buff interpolate?]
|
||||||
|
@ -204,12 +213,10 @@
|
||||||
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
|
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
|
||||||
"\"" (add-token (advance scanner) (if interpolate? :interpolated :string) (string buff))
|
"\"" (add-token (advance scanner) (if interpolate? :interpolated :string) (string buff))
|
||||||
"\\" (let [next (next-char scanner)]
|
"\\" (let [next (next-char scanner)]
|
||||||
(if (= next "{")
|
(recur
|
||||||
(do
|
(advance (advance scanner))
|
||||||
(buffer/push buff char)
|
(buffer/push buff (get escape next next))
|
||||||
(buffer/push buff next)
|
interpolate?))
|
||||||
(recur (advance (advance scanner)) buff interpolate?))
|
|
||||||
(recur (advance scanner) (buffer/push buff char) interpolate?)))
|
|
||||||
(if (at-end? scanner)
|
(if (at-end? scanner)
|
||||||
(add-error scanner "Unterminated string.")
|
(add-error scanner "Unterminated string.")
|
||||||
(recur (advance scanner) (buffer/push buff char) interpolate?)))))
|
(recur (advance scanner) (buffer/push buff char) interpolate?)))))
|
||||||
|
@ -341,8 +348,8 @@
|
||||||
(recur (-> scanner (scan-token) (next-token)))))
|
(recur (-> scanner (scan-token) (next-token)))))
|
||||||
(recur (new-scanner source input)))
|
(recur (new-scanner source input)))
|
||||||
|
|
||||||
# (comment
|
(comment
|
||||||
(do
|
# (do
|
||||||
(def source "/iii")
|
(def source "/iii")
|
||||||
(scan source)
|
(scan source)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user