Add struct to scanner; new reserved words.

This commit is contained in:
Scott Richmond 2022-04-03 14:22:01 -04:00
parent 98530b0f0f
commit 811a57be1c

View File

@ -10,6 +10,7 @@
;; see ludus-spec repo for more info ;; see ludus-spec repo for more info
{"as" ::token/as {"as" ::token/as
"cond" ::token/cond "cond" ::token/cond
"data" ::token/data
"do" ::token/do "do" ::token/do
"else" ::token/else "else" ::token/else
"false" ::token/false "false" ::token/false
@ -21,6 +22,7 @@
"mut" ::token/mut "mut" ::token/mut
"nil" ::token/nil "nil" ::token/nil
"panic!" ::token/panic "panic!" ::token/panic
"ref" ::token/ref
"then" ::token/then "then" ::token/then
"true" ::token/true "true" ::token/true
"var" ::token/var "var" ::token/var
@ -260,6 +262,11 @@
(add-token (advance scanner) ::token/startset) (add-token (advance scanner) ::token/startset)
(add-error scanner (str "Expected beginning of set: ${. Got " char next))) (add-error scanner (str "Expected beginning of set: ${. Got " char next)))
;; struct @{
\@ (if (= next \{)
(add-token (advance scanner) ::token/startstruct)
(add-error scanner (str "Expected beginning of struct: @{. Got " char next)))
;; placeholders ;; placeholders
;; there's a flat _, and then ignored words ;; there's a flat _, and then ignored words
\_ (cond \_ (cond
@ -270,14 +277,11 @@
;; comments ;; comments
;; & starts an inline comment ;; & starts an inline comment
;; TODO: include comments in scanned file ;; TODO: include comments in scanned file
;; TODO: add doc comments: &&& ;; TODO, maybe: add doc comments: &&& (or perhaps a docstring in an fn?)
\& (add-comment char scanner) \& (add-comment char 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))
(alpha? next) (add-keyword scanner) (alpha? next) (add-keyword scanner)
:else (add-error scanner (str "Expected keyword. Got " char next))) :else (add-error scanner (str "Expected keyword. Got " char next)))