From 2866ff4eb62ff566a4e918b61dc5711827fbb142 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Tue, 2 May 2023 19:44:17 -0400 Subject: [PATCH] Make some modest moves --- src/ludus/parser-new.clj | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) 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