Make some modest moves

This commit is contained in:
Scott Richmond 2023-05-02 19:44:17 -04:00
parent c5a72912df
commit 2866ff4eb6

View File

@ -1,7 +1,32 @@
(ns ludus.parser-new) (ns ludus.parser-new
(:require
[ludus.scanner :as scan]))
(defn ok? [[ok]] (defn ok? [[ok]]
(= ok :ok)) (= ok :ok))
(defn kw->type [kw] (apply str (next (str kw))))
(defn match [kw token] (defn match [kw token]
(if (= kw (:type token))
[:ok token]
[:error token (str "Expected " (kw->type kw))]))
(defn parser
([kw] {:type kw :fn #(match kw %)})
([kw err] {:type kw :fn #(assoc (match kw %) 2 err)}))
(defn choice [& args])
(def eg (:tokens (scan/scan "123 :foo")))
(def word (parser :word "fuck"))
(word (first eg))
(comment
(def string (parser :string))
) )