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