fix escaping brace bug, which was fixing next-char bug; also clean some stuff up
This commit is contained in:
parent
c5d04ddd66
commit
3f16e45204
|
@ -71,7 +71,7 @@
|
|||
length (length source)]
|
||||
(if (>= next length)
|
||||
nil
|
||||
(string/from-bytes (get source current)))))
|
||||
(string/from-bytes (get source next)))))
|
||||
|
||||
(defn- current-lexeme
|
||||
[scanner]
|
||||
|
@ -126,7 +126,6 @@
|
|||
"&" true
|
||||
"," true
|
||||
">" true
|
||||
# nil was in here; I don't want to be passing in literal nil to this function anyway, and "nil" is also not it...
|
||||
"\"" true})
|
||||
|
||||
(defn- terminates? [c]
|
||||
|
@ -171,9 +170,7 @@
|
|||
|
||||
(defn- read-literal [lit] (-> lit parse-all first))
|
||||
|
||||
## TODO: improve number parsing?
|
||||
## Currently this uses Clojure's number formatting rules (since we use the EDN reader)
|
||||
## These rules are here: https://cljs.github.io/api/syntax/number
|
||||
### TODO: consider whether Janet's number rules are right for Ludus
|
||||
(defn- add-number [char scanner]
|
||||
(defn recur [scanner num float?]
|
||||
(let [curr (current-char scanner)]
|
||||
|
@ -192,19 +189,21 @@
|
|||
(print "Adding string")
|
||||
(defn recur [scanner buff interpolate?]
|
||||
(let [char (current-char scanner)]
|
||||
(print "scanning current char: " char)
|
||||
(case char
|
||||
"{" (recur (advance scanner) (buffer/push buff char) true)
|
||||
# allow multiline strings
|
||||
"\n" (recur (update (advance scanner) :line inc) (buffer/push buff char) interpolate?)
|
||||
"\"" (add-token (advance scanner) (if interpolate? :interpolated :string)(string buff))
|
||||
### FIXME: Actually add the escaped character to the string;
|
||||
### The only weird escapy-thing is actually the lbrace
|
||||
### So only do anything fancy if the next char is "{"
|
||||
"\\" (let [next (next-char scanner)
|
||||
scanner (if (= next "\n")
|
||||
(update scanner :line inc)
|
||||
scanner)]
|
||||
(recur (advance (advance scanner)) (buffer/push buff next) interpolate?))
|
||||
"\\" (let [next (next-char scanner)]
|
||||
(print "found slash")
|
||||
(print "next char: " next)
|
||||
(if (= next "{")
|
||||
(do
|
||||
(print "escaped brace")
|
||||
(buffer/push buff next)
|
||||
(recur (advance (advance scanner)) buff interpolate?))
|
||||
(recur (advance scanner) (buffer/push buff char) interpolate?)))
|
||||
(if (at-end? scanner)
|
||||
(add-error scanner "Unterminated string.")
|
||||
(recur (advance scanner) (buffer/push buff char) interpolate?)))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user