Add datatype tokens
This commit is contained in:
parent
72aac19bd7
commit
18e4826960
|
@ -195,13 +195,13 @@
|
||||||
(word-char? curr) (recur (advance scanner) (str word curr))
|
(word-char? curr) (recur (advance scanner) (str word curr))
|
||||||
:else (add-error scanner (str "Unexpected " curr " after word " word "."))))))
|
:else (add-error scanner (str "Unexpected " curr " after word " word "."))))))
|
||||||
|
|
||||||
(defn- add-datatype
|
(defn- add-data
|
||||||
[char scanner]
|
[char scanner]
|
||||||
(loop [scanner scanner
|
(loop [scanner scanner
|
||||||
word (str char)]
|
word (str char)]
|
||||||
(let [curr (current-char scanner)]
|
(let [curr (current-char scanner)]
|
||||||
(cond
|
(cond
|
||||||
(terminates? curr) (add-token scanner (get reserved-words word ::token/word))
|
(terminates? curr) (add-token scanner ::token/data)
|
||||||
(word-char? curr) (recur (advance scanner) (str word curr))
|
(word-char? curr) (recur (advance scanner) (str word curr))
|
||||||
:else (add-error scanner (str "Unexpected " curr " after datatype " word "."))))))
|
:else (add-error scanner (str "Unexpected " curr " after datatype " word "."))))))
|
||||||
|
|
||||||
|
@ -312,7 +312,8 @@
|
||||||
(cond
|
(cond
|
||||||
(whitespace? char) scanner ;; for now just skip whitespace characters
|
(whitespace? char) scanner ;; for now just skip whitespace characters
|
||||||
(digit? char) (add-number char scanner)
|
(digit? char) (add-number char scanner)
|
||||||
(alpha? char) (add-word char scanner)
|
(upper? char) (add-data char scanner)
|
||||||
|
(lower? char) (add-word char scanner)
|
||||||
:else (add-error scanner (str "Unexpected character: " char))))))
|
:else (add-error scanner (str "Unexpected character: " char))))))
|
||||||
|
|
||||||
(defn- next-token [scanner]
|
(defn- next-token [scanner]
|
||||||
|
@ -325,3 +326,4 @@
|
||||||
{:tokens (::tokens scanner)
|
{:tokens (::tokens scanner)
|
||||||
:errors (::errors scanner)})
|
:errors (::errors scanner)})
|
||||||
(recur (-> scanner (scan-token) (next-token))))))
|
(recur (-> scanner (scan-token) (next-token))))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user