From ef77466323f85a3d1b65b46a3deb93652ef22085 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 9 Sep 2021 00:29:12 -0400 Subject: The old record syntax has been re-purposed as variant syntax. --- lux-bootstrapper/src/lux/analyser.clj | 10 ++++--- lux-bootstrapper/src/lux/base.clj | 14 ++++------ lux-bootstrapper/src/lux/compiler/cache/ann.clj | 17 +++--------- lux-bootstrapper/src/lux/parser.clj | 37 +++++++------------------ lux-bootstrapper/src/lux/type.clj | 6 ++-- 5 files changed, 28 insertions(+), 56 deletions(-) (limited to 'lux-bootstrapper') diff --git a/lux-bootstrapper/src/lux/analyser.clj b/lux-bootstrapper/src/lux/analyser.clj index 5ebda9c6e..f837d8cee 100644 --- a/lux-bootstrapper/src/lux/analyser.clj +++ b/lux-bootstrapper/src/lux/analyser.clj @@ -187,10 +187,12 @@ (analyse-variant+ analyse exo-type ?ident parameters)) ;; Pattern-matching syntax. - (&/$Record ?pattern-matching) - (|let [(&/$Item ?input (&/$End)) parameters] - (&/with-analysis-meta location exo-type - (&&lux/analyse-case analyse exo-type ?input ?pattern-matching))) + (&/$Variant ?pattern-matching) + (if (even? (&/|length ?pattern-matching)) + (|let [(&/$Item ?input (&/$End)) parameters] + (&/with-analysis-meta location exo-type + (&&lux/analyse-case analyse exo-type ?input (&/|as-pairs ?pattern-matching)))) + (&/fail-with-loc (str "[Analyser Error] Unknown syntax: " (&/show-ast (&/T [(&/T ["" -1 -1]) token]))))) ;; Function syntax. (&/$Tuple (&/$Item [_ (&/$Identifier "" ?self)] diff --git a/lux-bootstrapper/src/lux/base.clj b/lux-bootstrapper/src/lux/base.clj index 513462d20..eca121b6c 100644 --- a/lux-bootstrapper/src/lux/base.clj +++ b/lux-bootstrapper/src/lux/base.clj @@ -84,8 +84,8 @@ ("Identifier" 1) ("Tag" 1) ("Form" 1) - ("Tuple" 1) - ("Record" 1)) + ("Variant" 1) + ("Tuple" 1)) ;; Type (defvariant @@ -1258,16 +1258,12 @@ ?name (str ?module +name-separator+ ?name)) + [_ ($Variant ?elems)] + (str "{" (->> ?elems (|map show-ast) (|interpose " ") (fold str "")) "}") + [_ ($Tuple ?elems)] (str "[" (->> ?elems (|map show-ast) (|interpose " ") (fold str "")) "]") - [_ ($Record ?elems)] - (str "{" (->> ?elems - (|map (fn [elem] - (|let [[k v] elem] - (str (show-ast k) " " (show-ast v))))) - (|interpose " ") (fold str "")) "}") - [_ ($Form ?elems)] (str "(" (->> ?elems (|map show-ast) (|interpose " ") (fold str "")) ")") diff --git a/lux-bootstrapper/src/lux/compiler/cache/ann.clj b/lux-bootstrapper/src/lux/compiler/cache/ann.clj index 9d5a8e97f..0f13e729b 100644 --- a/lux-bootstrapper/src/lux/compiler/cache/ann.clj +++ b/lux-bootstrapper/src/lux/compiler/cache/ann.clj @@ -54,12 +54,8 @@ [_ (&/$Tuple elems)] (str "[" (serialize-seq serialize elems)) - [_ (&/$Record kvs)] - (str "{" (serialize-seq (fn [kv] - (|let [[k v] kv] - (str (serialize k) - (serialize v)))) - kvs)) + [_ (&/$Variant kvs)] + (str "{" (serialize-seq serialize elems)) _ (assert false) @@ -104,11 +100,6 @@ [(&/$Item head tail) input*])) )) -(defn ^:private deserialize-kv [input] - (when-let [[key input*] (deserialize input)] - (when-let [[ann input*] (deserialize input*)] - [(&/T [key ann]) input*]))) - (do-template [ ] (defn [^String input] (when (.startsWith input ) @@ -118,7 +109,7 @@ ^:private deserialize-form "(" &/$Form deserialize ^:private deserialize-tuple "[" &/$Tuple deserialize - ^:private deserialize-record "{" &/$Record deserialize-kv + ^:private deserialize-variant "{" &/$Variant deserialize ) (defn deserialize @@ -133,6 +124,6 @@ (deserialize-identifier input) (deserialize-tag input) (deserialize-form input) + (deserialize-variant input) (deserialize-tuple input) - (deserialize-record input) (assert false "[Cache Error] Cannot deserialize annocation."))) diff --git a/lux-bootstrapper/src/lux/parser.clj b/lux-bootstrapper/src/lux/parser.clj index 5d409400e..fa9d0a110 100644 --- a/lux-bootstrapper/src/lux/parser.clj +++ b/lux-bootstrapper/src/lux/parser.clj @@ -6,17 +6,13 @@ [lexer :as &lexer]))) ;; [Utils] -(def ^:private base-uneven-record-error - "[Parser Error] Records must have an even number of elements.") - (defn ^:private repeat% [action] (fn [state] (|case (action state) (&/$Left ^String error) - (if (or (.contains error base-uneven-record-error) - (not (.contains error "[Parser Error]"))) - (&/$Left error) - (&/$Right (&/T [state &/$End]))) + (if (.contains error "[Parser Error]") + (&/$Right (&/T [state &/$End])) + (&/$Left error)) (&/$Right state* head) ((|do [tail (repeat% action)] @@ -35,24 +31,11 @@ (&/fail-with-loc (str "[Parser Error] Unbalanced " ".")) ))) - ^:private parse-form &lexer/$Close_Paren "parantheses" &/$Form - ^:private parse-tuple &lexer/$Close_Bracket "brackets" &/$Tuple + ^:private parse-form &lexer/$Close_Paren "parantheses" &/$Form + ^:private parse-variant &lexer/$Close_Brace "braces" &/$Variant + ^:private parse-tuple &lexer/$Close_Bracket "brackets" &/$Tuple ) -(defn ^:private parse-record [parse] - (|do [elems* (repeat% parse) - token &lexer/lex - :let [elems (&/fold &/|++ &/$End elems*)]] - (|case token - [meta (&lexer/$Close_Brace _)] - (|do [_ (&/assert! (even? (&/|length elems)) - (&/fail-with-loc base-uneven-record-error))] - (return (&/$Record (&/|as-pairs elems)))) - - _ - (&/fail-with-loc "[Parser Error] Unbalanced braces.") - ))) - ;; [Interface] (def parse (|do [token &lexer/lex @@ -92,12 +75,12 @@ (|do [syntax (parse-form parse)] (return (&/|list (&/T [meta syntax])))) - (&lexer/$Open_Bracket _) - (|do [syntax (parse-tuple parse)] + (&lexer/$Open_Brace _) + (|do [syntax (parse-variant parse)] (return (&/|list (&/T [meta syntax])))) - (&lexer/$Open_Brace _) - (|do [syntax (parse-record parse)] + (&lexer/$Open_Bracket _) + (|do [syntax (parse-tuple parse)] (return (&/|list (&/T [meta syntax])))) _ diff --git a/lux-bootstrapper/src/lux/type.clj b/lux-bootstrapper/src/lux/type.clj index 9a153a821..e8d98fedf 100644 --- a/lux-bootstrapper/src/lux/type.clj +++ b/lux-bootstrapper/src/lux/type.clj @@ -157,10 +157,10 @@ Ident (&/$Sum ;; .Form Code-List - (&/$Sum ;; .Tuple + (&/$Sum ;; .Variant + Code-List + ;; .Tuple Code-List - ;; .Record - (&/$Apply (&/$Product Code Code) List) )))))))))) )))) -- cgit v1.2.3