Update reserved words list & impl
This commit is contained in:
parent
5c07f43713
commit
e7eccca000
|
@ -1,16 +1,16 @@
|
||||||
(ns ludus.scanner
|
(ns ludus.scanner
|
||||||
(:require
|
(:require
|
||||||
[ludus.token :as token]
|
[ludus.token :as token]
|
||||||
[clojure.pprint :as pp]
|
[clojure.pprint :as pp]
|
||||||
[clojure.edn :as edn]
|
[clojure.edn :as edn]
|
||||||
[clojure.string :as s]))
|
[clojure.string :as s]))
|
||||||
|
|
||||||
(def reserved-words
|
(def reserved-words
|
||||||
"List of Ludus reserved words."
|
"List of Ludus reserved words."
|
||||||
;; see ludus-spec repo for more info
|
;; see ludus-spec repo for more info
|
||||||
{"as" ::token/as
|
{
|
||||||
|
"as" ::token/as ;; impl for `import`; not yet for patterns
|
||||||
"cond" ::token/cond ;; impl
|
"cond" ::token/cond ;; impl
|
||||||
"data" ::token/data
|
|
||||||
"do" ::token/do ;; impl
|
"do" ::token/do ;; impl
|
||||||
"else" ::token/else ;; impl
|
"else" ::token/else ;; impl
|
||||||
"false" ::token/false ;; impl
|
"false" ::token/false ;; impl
|
||||||
|
@ -23,21 +23,28 @@
|
||||||
"nil" ::token/nil ;; impl
|
"nil" ::token/nil ;; impl
|
||||||
"ns" ::token/ns ;; impl
|
"ns" ::token/ns ;; impl
|
||||||
"recur" ::token/recur
|
"recur" ::token/recur
|
||||||
"ref" ::token/ref
|
"ref" ::token/ref ;; impl
|
||||||
"then" ::token/then ;; impl
|
"then" ::token/then ;; impl
|
||||||
"true" ::token/true ;; impl
|
"true" ::token/true ;; impl
|
||||||
"with" ::token/with ;; impl
|
"with" ::token/with ;; impl
|
||||||
;; below here, probable
|
;; below here, probable
|
||||||
"defer" ::token/defer
|
"data" ::token/data
|
||||||
"gen" ::token/gen
|
"receive" ::token/receive
|
||||||
"mut" ::token/mut
|
|
||||||
"repeat" ::token/repeat
|
"repeat" ::token/repeat
|
||||||
|
"self" ::token/self
|
||||||
|
"send" ::token/send
|
||||||
|
"spawn" ::token/spawn
|
||||||
"test" ::token/test
|
"test" ::token/test
|
||||||
|
"to" ::token/to
|
||||||
|
"when" ::token/when
|
||||||
|
;; below here, possible
|
||||||
|
"gen" ::token/gen
|
||||||
|
"defer" ::token/defer
|
||||||
|
"mut" ::token/mut
|
||||||
"var" ::token/var
|
"var" ::token/var
|
||||||
"wait" ::token/wait
|
"wait" ::token/wait
|
||||||
"yield" ::token/yield
|
"yield" ::token/yield
|
||||||
;; below here, possible
|
})
|
||||||
"when" ::token/when})
|
|
||||||
|
|
||||||
(defn- new-scanner
|
(defn- new-scanner
|
||||||
"Creates a new scanner."
|
"Creates a new scanner."
|
||||||
|
@ -76,8 +83,8 @@
|
||||||
|
|
||||||
(defn- char-in-range? [start end char]
|
(defn- char-in-range? [start end char]
|
||||||
(and char
|
(and char
|
||||||
(>= (int char) (int start))
|
(>= (int char) (int start))
|
||||||
(<= (int char) (int end))))
|
(<= (int char) (int end))))
|
||||||
|
|
||||||
(defn- digit? [c]
|
(defn- digit? [c]
|
||||||
(char-in-range? \0 \9 c))
|
(char-in-range? \0 \9 c))
|
||||||
|
@ -110,27 +117,27 @@
|
||||||
(add-token scanner token-type nil))
|
(add-token scanner token-type nil))
|
||||||
([scanner token-type literal]
|
([scanner token-type literal]
|
||||||
(update scanner ::tokens conj
|
(update scanner ::tokens conj
|
||||||
(token/token
|
(token/token
|
||||||
token-type
|
token-type
|
||||||
(current-lexeme scanner)
|
(current-lexeme scanner)
|
||||||
literal
|
literal
|
||||||
(::line scanner)
|
(::line scanner)
|
||||||
(::start scanner)))))
|
(::start scanner)))))
|
||||||
|
|
||||||
;; TODO: errors should also be in the vector of tokens
|
;; 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?
|
;; The goal is to be able to be able to hand this to an LSP?
|
||||||
;; Do we need a different structure
|
;; Do we need a different structure
|
||||||
(defn- add-error [scanner msg]
|
(defn- add-error [scanner msg]
|
||||||
(let [token (token/token
|
(let [token (token/token
|
||||||
::token/error
|
::token/error
|
||||||
(current-lexeme scanner)
|
(current-lexeme scanner)
|
||||||
nil
|
nil
|
||||||
(::line scanner)
|
(::line scanner)
|
||||||
(::start scanner))
|
(::start scanner))
|
||||||
err-token (assoc token :message msg)]
|
err-token (assoc token :message msg)]
|
||||||
(-> scanner
|
(-> scanner
|
||||||
(update ::errors conj err-token)
|
(update ::errors conj err-token)
|
||||||
(update ::tokens conj err-token))))
|
(update ::tokens conj err-token))))
|
||||||
|
|
||||||
(defn- add-keyword
|
(defn- add-keyword
|
||||||
[scanner]
|
[scanner]
|
||||||
|
@ -205,8 +212,8 @@
|
||||||
(if (= \newline char)
|
(if (= \newline char)
|
||||||
(update scanner ::line inc)
|
(update scanner ::line inc)
|
||||||
;;(if (s/starts-with? comm "&&&")
|
;;(if (s/starts-with? comm "&&&")
|
||||||
;;(add-token (update scanner ::line inc) ::token/docstring)
|
;;(add-token (update scanner ::line inc) ::token/docstring)
|
||||||
;;(add-token (update scanner ::line inc) ::token/comment))
|
;;(add-token (update scanner ::line inc) ::token/comment))
|
||||||
(recur (advance scanner) (str comm char))))))
|
(recur (advance scanner) (str comm char))))))
|
||||||
|
|
||||||
(defn- scan-token [scanner]
|
(defn- scan-token [scanner]
|
||||||
|
@ -264,8 +271,8 @@
|
||||||
|
|
||||||
;; struct @{
|
;; struct @{
|
||||||
\@ (if (= next \{)
|
\@ (if (= next \{)
|
||||||
(add-token (advance scanner) ::token/startstruct)
|
(add-token (advance scanner) ::token/startstruct)
|
||||||
(add-error scanner (str "Expected beginning of struct: @{. Got " char next)))
|
(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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user