Better errors? WIP
This commit is contained in:
parent
40367d7e57
commit
23e2e95e77
|
@ -122,17 +122,28 @@
|
|||
;; 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]
|
||||
(loop [scanner scanner
|
||||
(loop [scanner scanner
|
||||
key ""]
|
||||
(let [char (current-char scanner)]
|
||||
(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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user