Putter around in scanner
This commit is contained in:
parent
2eb7960cc9
commit
bbe20d4af1
|
@ -80,6 +80,8 @@
|
||||||
(defn- alpha? [c]
|
(defn- alpha? [c]
|
||||||
(or (char-in-range? \a \z c) (char-in-range? \A \Z c)))
|
(or (char-in-range? \a \z c) (char-in-range? \A \Z c)))
|
||||||
|
|
||||||
|
;; (defn- alpha? [c] (boolean (re-find #"\p{L}" (str c))))
|
||||||
|
|
||||||
;; legal characters in words
|
;; legal characters in words
|
||||||
(def word-chars #{\_ \? \! \* \/})
|
(def word-chars #{\_ \? \! \* \/})
|
||||||
|
|
||||||
|
@ -106,10 +108,12 @@
|
||||||
(::line scanner)
|
(::line scanner)
|
||||||
(::start scanner)))))
|
(::start scanner)))))
|
||||||
|
|
||||||
;; TODO: errors should also be
|
;; TODO: errors should also be in the vector of tokens
|
||||||
|
;; The goal is to be able to be able to hand this to an LSP
|
||||||
(defn- add-error [scanner msg]
|
(defn- add-error [scanner msg]
|
||||||
(update scanner ::errors conj {:msg msg :line (::line scanner) :start (::start scanner)}))
|
(update scanner ::errors conj {:msg msg :line (::line scanner) :start (::start scanner)}))
|
||||||
|
|
||||||
|
;; TODO: finish this
|
||||||
(defn- scan-keyword
|
(defn- scan-keyword
|
||||||
([scanner] (scan-keyword scanner scanner))
|
([scanner] (scan-keyword scanner scanner))
|
||||||
([start current]))
|
([start current]))
|
||||||
|
@ -187,8 +191,10 @@
|
||||||
(add-token (advance scanner) ::token/pipeline)
|
(add-token (advance scanner) ::token/pipeline)
|
||||||
(add-error scanner (str "Expected |>. Got " char next)))
|
(add-error scanner (str "Expected |>. Got " char next)))
|
||||||
|
|
||||||
;; possible additional operator: => (bind/result)
|
;; possible additional operator: bind/result
|
||||||
;; possible additional operator: ~> (bind/some)
|
;; possible additional operator: bind/some
|
||||||
|
;; oh god, monads
|
||||||
|
;; additional arrow possibilities: >> ||> ~> => !>
|
||||||
|
|
||||||
;; hashmap #{
|
;; hashmap #{
|
||||||
\# (if (= next \{)
|
\# (if (= next \{)
|
||||||
|
@ -201,18 +207,22 @@
|
||||||
(add-error scanner (str "Expected beginning of set: ${. Got " char next)))
|
(add-error scanner (str "Expected beginning of set: ${. Got " char next)))
|
||||||
|
|
||||||
;; placeholder
|
;; placeholder
|
||||||
|
;; TODO: add named placeholder
|
||||||
\_ (if (terminates? next)
|
\_ (if (terminates? next)
|
||||||
(add-token scanner ::token/placeholder)
|
(add-token scanner ::token/placeholder)
|
||||||
(add-word scanner))
|
(add-word scanner))
|
||||||
|
|
||||||
;; comments
|
;; comments
|
||||||
;; &
|
;; & starts an inline comment
|
||||||
;; TODO: include comments in scanned file
|
;; TODO: include comments in scanned file
|
||||||
|
;; TODO: add doc comments: &&&
|
||||||
\& (skip-comment scanner)
|
\& (skip-comment scanner)
|
||||||
|
|
||||||
;; keywords
|
;; keywords
|
||||||
|
;; TODO: instead of a separate token, scan a whole type keyword
|
||||||
|
;; e.g. ::string, ::number
|
||||||
\: (cond
|
\: (cond
|
||||||
(= \: next) (add-token (advance scanner) ::token/doublecolon))
|
;;(= \: next) (add-token (advance scanner) ::token/doublecolon))
|
||||||
(alpha? next) (add-word scanner)
|
(alpha? next) (add-word scanner)
|
||||||
:else (add-error scanner (str "Expected keyword. Got " char next))
|
:else (add-error scanner (str "Expected keyword. Got " char next))
|
||||||
|
|
||||||
|
@ -221,7 +231,7 @@
|
||||||
|
|
||||||
;; word matches
|
;; word matches
|
||||||
(cond
|
(cond
|
||||||
(whitespace? char) scanner
|
(whitespace? char) scanner ;; TODO: include whitespace in scan
|
||||||
;; (digit? char) (add-number scanner)
|
;; (digit? char) (add-number scanner)
|
||||||
;; (alpha? char) (add-word scanner)
|
;; (alpha? char) (add-word scanner)
|
||||||
:else (add-error scanner (str "Unexpected character: " char))))))
|
:else (add-error scanner (str "Unexpected character: " char))))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user