Better errors? WIP

This commit is contained in:
Scott Richmond 2022-02-19 14:34:07 -05:00
parent 40367d7e57
commit 23e2e95e77

View File

@ -122,7 +122,18 @@
;; The goal is to be able to be able to hand this to an LSP?
;; Do we need a different structure
(defn- add-error [scanner msg]
(update scanner ::errors conj {:msg msg :line (::line scanner) :start (::start scanner)}))
(let [
token (token/token
::token/error
(current-lexeme scanner)
nil
(::line scanner)
(::start scanner))
err-token (assoc token :msg msg)
]
(-> scanner
(update ::errors conj err-token)
(update ::tokens conj err-token))))
(defn- add-keyword
[scanner]
@ -132,7 +143,7 @@
(cond
(terminates? char) (add-token scanner ::token/keyword (keyword key))
(word-char? char) (recur (advance scanner) (str key char))
:else (add-error scanner "Unexpected " char "after keyword :" key)))))
:else (add-error scanner (str "Unexpected " char "after keyword :" key))))))
;; TODO: improve number parsing?
;; Currently this uses Clojure's number formatting rules (since we use the EDN reader)