Add upper? and lower? fns

This commit is contained in:
Scott Richmond 2022-07-26 18:19:16 -04:00
parent 88c79b2b31
commit 72aac19bd7

View File

@ -1,7 +1,7 @@
(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]))
(def reserved-words (def reserved-words
@ -27,7 +27,6 @@
"true" ::token/true ;; impl "true" ::token/true ;; impl
"with" ::token/with ;; impl "with" ::token/with ;; impl
;; below here, probable
;; actor model/concurrency ;; actor model/concurrency
"receive" ::token/receive "receive" ::token/receive
"self" ::token/self ;; maybe not necessary? "self" ::token/self ;; maybe not necessary?
@ -40,17 +39,7 @@
"repeat" ::token/repeat ;; syntax sugar over "loop" "repeat" ::token/repeat ;; syntax sugar over "loop"
"test" ::token/test "test" ::token/test
"when" ::token/when "when" ::token/when
"module" ::token/module
;; below here, possibly not
;; generators (sugar over actors?)
; "gen" ::token/gen
; "yield" ::token/yield
;; event loop/concurrency
; "defer" ::token/defer
; "wait" ::token/wait
;; vars
; "mut" ::token/mut
; "var" ::token/var
}) })
(defn- new-scanner (defn- new-scanner
@ -105,6 +94,10 @@
(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- lower? [c] (char-in-range? \a \z c))
(defn- upper? [c] (char-in-range? \A \Z c))
;; legal characters in words ;; legal characters in words
(def word-chars #{\_ \? \! \* \/}) (def word-chars #{\_ \? \! \* \/})
@ -202,6 +195,16 @@
(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
[char scanner]
(loop [scanner scanner
word (str char)]
(let [curr (current-char scanner)]
(cond
(terminates? curr) (add-token scanner (get reserved-words word ::token/word))
(word-char? curr) (recur (advance scanner) (str word curr))
:else (add-error scanner (str "Unexpected " curr " after datatype " word "."))))))
(defn- add-ignored (defn- add-ignored
[scanner] [scanner]
(loop [scanner scanner (loop [scanner scanner