diff --git a/src/ludus/parser-new.clj b/src/ludus/parser-new.clj index 53c09e7..d94bd41 100644 --- a/src/ludus/parser-new.clj +++ b/src/ludus/parser-new.clj @@ -1,7 +1,32 @@ -(ns ludus.parser-new) +(ns ludus.parser-new + (:require + [ludus.scanner :as scan])) (defn ok? [[ok]] (= ok :ok)) +(defn kw->type [kw] (apply str (next (str kw)))) + (defn match [kw token] - ) \ No newline at end of file + (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)) + +) \ No newline at end of file