From 98b147f5b808432524d409a8e7e8acf5f5788da9 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Mon, 14 Feb 2022 17:32:29 -0500 Subject: [PATCH] Factor out keyword parsing, parse bare words --- src/ludus/parser.clj | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ludus/parser.clj b/src/ludus/parser.clj index b13f8fd..1d7ea38 100644 --- a/src/ludus/parser.clj +++ b/src/ludus/parser.clj @@ -178,15 +178,39 @@ ))) +(defn- parse-word [parser curr] + (let [next (next parser)] + (case (::token/type next) + + ::token/lparen ::oops + + ::token/keyword ::oops + + (assoc (advance parser) ::ast {::ast/type ::ast/word :word (::token/lexeme curr)}) + + ))) + +(defn- parse-keyword [parser token] + (let [next (next parser)] + (case (::token/type next) + + ::token/lparen ::oops + + (parse-atom parser token)))) + (defn- parse-expr [parser] (loop [parser parser] (let [token (current parser)] (println "Parsing expr " (::token/type token)) (case (::token/type token) - (::token/number ::token/string ::token/keyword) + (::token/number ::token/string) (parse-atom parser token) + ::token/keyword (parse-keyword parser token) + + ::token/word (parse-word parser token) + (::token/nil ::token/true ::token/false) (parse-atomic-word parser token) @@ -200,7 +224,7 @@ )))) -(def source "{1; 2; :foo}\n{1}") +(def source "foo") (def tokens (:tokens (scanner/scan source)))