From 969c321ffbe39f1ce69bb612d6b7cead344313b6 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 4 Aug 2022 16:49:20 -0400 Subject: [PATCH] Work on datatypes --- src/ludus/parser.clj | 16 +++++++++++++--- src/ludus/scanner.clj | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ludus/parser.clj b/src/ludus/parser.clj index 2a8f7fc..eab7007 100644 --- a/src/ludus/parser.clj +++ b/src/ludus/parser.clj @@ -124,6 +124,13 @@ :token token :value (get atomic-words (::token/type token))})))) +(defn- parse-datatype [parser] + (let [token (current parser)] + (-> parser (advance) + (assoc ::ast {::ast/type ::ast/datatype + :token token + :value (::token/literal token)})))) + (defn- add-member [members member] (if (nil? member) members @@ -1080,6 +1087,9 @@ (::token/lparen ::token/keyword) (parse-synthetic parser) (parse-word parser))) + ::token/datatype + (parse-datatype parser) + (::token/nil ::token/true ::token/false) (parse-atomic-word parser) @@ -1148,9 +1158,9 @@ (parser) (parse-script))) -(comment +(do (def pp pp/pprint) - (def source "let @{a, ...foo, :c d} = :foo") + (def source "Word") (println "") (println "") @@ -1158,7 +1168,7 @@ (println "") (println "*** *** TEST PARSE *** ***") - (pp/pprint (::ast (parse (scanner/scan source))))) + (pp (::ast (parse (scanner/scan source))))) (comment " Further thoughts/still to do: diff --git a/src/ludus/scanner.clj b/src/ludus/scanner.clj index 46b7d40..9ae2b6c 100644 --- a/src/ludus/scanner.clj +++ b/src/ludus/scanner.clj @@ -201,7 +201,7 @@ word (str char)] (let [curr (current-char scanner)] (cond - (terminates? curr) (add-token scanner ::token/data) + (terminates? curr) (add-token scanner ::token/datatype) (word-char? curr) (recur (advance scanner) (str word curr)) :else (add-error scanner (str "Unexpected " curr " after datatype " word "."))))))