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. --- .../source/library/lux/abstract/monad/indexed.lux | 6 +- .../source/library/lux/control/parser/binary.lux | 22 +++---- stdlib/source/library/lux/control/parser/code.lux | 16 +---- stdlib/source/library/lux/data/collection/tree.lux | 4 +- stdlib/source/library/lux/data/format/binary.lux | 22 +++---- stdlib/source/library/lux/data/format/json.lux | 75 ++++++++++++---------- stdlib/source/library/lux/documentation.lux | 24 ++----- stdlib/source/library/lux/ffi.jvm.lux | 10 +-- stdlib/source/library/lux/ffi.old.lux | 10 +-- stdlib/source/library/lux/macro.lux | 20 ++---- stdlib/source/library/lux/macro/code.lux | 31 ++------- stdlib/source/library/lux/macro/template.lux | 12 +--- stdlib/source/library/lux/meta/annotation.lux | 70 -------------------- .../lux/tool/compiler/language/lux/syntax.lux | 19 +++--- 14 files changed, 104 insertions(+), 237 deletions(-) delete mode 100644 stdlib/source/library/lux/meta/annotation.lux (limited to 'stdlib/source/library/lux') diff --git a/stdlib/source/library/lux/abstract/monad/indexed.lux b/stdlib/source/library/lux/abstract/monad/indexed.lux index 99446f84f..6e8ddb602 100644 --- a/stdlib/source/library/lux/abstract/monad/indexed.lux +++ b/stdlib/source/library/lux/abstract/monad/indexed.lux @@ -55,9 +55,9 @@ (def: named_monad (Parser [(Maybe Text) Code]) - (<>.either (.record (<>.and (\ <>.monad each (|>> #.Some) - .local_identifier) - .any)) + (<>.either (.tuple (<>.and (\ <>.monad each (|>> #.Some) + .local_identifier) + .any)) (\ <>.monad each (|>> [#.None]) .any))) diff --git a/stdlib/source/library/lux/control/parser/binary.lux b/stdlib/source/library/lux/control/parser/binary.lux index 66dd9f3c5..d6de3c7cd 100644 --- a/stdlib/source/library/lux/control/parser/binary.lux +++ b/stdlib/source/library/lux/control/parser/binary.lux @@ -268,14 +268,14 @@ (function (_ recur) (let [sequence (..list recur)] (//.and ..location - (!variant [[0 [#.Bit] ..bit] - [1 [#.Nat] ..nat] - [2 [#.Int] ..int] - [3 [#.Rev] ..rev] - [4 [#.Frac] ..frac] - [5 [#.Text] ..text] - [6 [#.Identifier] ..name] - [7 [#.Tag] ..name] - [8 [#.Form] sequence] - [9 [#.Tuple] sequence] - [10 [#.Record] (..list (//.and recur recur))]])))))) + (!variant [[00 [#.Bit] ..bit] + [01 [#.Nat] ..nat] + [02 [#.Int] ..int] + [03 [#.Rev] ..rev] + [04 [#.Frac] ..frac] + [05 [#.Text] ..text] + [06 [#.Identifier] ..name] + [07 [#.Tag] ..name] + [08 [#.Form] sequence] + [09 [#.Variant] sequence] + [10 [#.Tuple] sequence]])))))) diff --git a/stdlib/source/library/lux/control/parser/code.lux b/stdlib/source/library/lux/control/parser/code.lux index f04dddc6c..f9fc4d550 100644 --- a/stdlib/source/library/lux/control/parser/code.lux +++ b/stdlib/source/library/lux/control/parser/code.lux @@ -145,23 +145,11 @@ _ (#try.Failure ($_ text\composite "Cannot parse " (remaining_inputs tokens))))))] - [ form #.Form "form"] + [form #.Form "form"] + [variant #.Variant "variant"] [tuple #.Tuple "tuple"] ) -(def: .public (record p) - (All (_ a) - (-> (Parser a) (Parser a))) - (function (_ tokens) - (case tokens - (#.Item [[_ (#.Record pairs)] tokens']) - (case (p (un_paired pairs)) - (#try.Success [#.End x]) (#try.Success [tokens' x]) - _ (#try.Failure ($_ text\composite "Parser was expected to fully consume record" (remaining_inputs tokens)))) - - _ - (#try.Failure ($_ text\composite "Cannot parse record" (remaining_inputs tokens)))))) - (def: .public end! (Parser Any) (function (_ tokens) diff --git a/stdlib/source/library/lux/data/collection/tree.lux b/stdlib/source/library/lux/data/collection/tree.lux index b1d158c65..96d92ac6d 100644 --- a/stdlib/source/library/lux/data/collection/tree.lux +++ b/stdlib/source/library/lux/data/collection/tree.lux @@ -46,11 +46,11 @@ (def: tree^ (Parser Tree_Code) (|> (|>> <>.some - .record + .variant (<>.and .any)) <>.rec <>.some - .record + .variant (<>.else (list)) (<>.and .any))) diff --git a/stdlib/source/library/lux/data/format/binary.lux b/stdlib/source/library/lux/data/format/binary.lux index 3ee903853..234b7a093 100644 --- a/stdlib/source/library/lux/data/format/binary.lux +++ b/stdlib/source/library/lux/data/format/binary.lux @@ -277,15 +277,15 @@ try.trusted [(.++ offset)] caseT))])]) - ([0 #.Bit ..bit] - [1 #.Nat ..nat] - [2 #.Int ..int] - [3 #.Rev ..rev] - [4 #.Frac ..frac] - [5 #.Text ..text] - [6 #.Identifier ..name] - [7 #.Tag ..name] - [8 #.Form sequence] - [9 #.Tuple sequence] - [10 #.Record (..list (..and recur recur))]) + ([00 #.Bit ..bit] + [01 #.Nat ..nat] + [02 #.Int ..int] + [03 #.Rev ..rev] + [04 #.Frac ..frac] + [05 #.Text ..text] + [06 #.Identifier ..name] + [07 #.Tag ..name] + [08 #.Form sequence] + [09 #.Variant sequence] + [10 #.Tuple sequence]) ))))))) diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux index a7f22c7c0..052ce1c18 100644 --- a/stdlib/source/library/lux/data/format/json.lux +++ b/stdlib/source/library/lux/data/format/json.lux @@ -67,40 +67,47 @@ (-> (List [String JSON]) JSON) (|>> (dictionary.of_list text.hash) #..Object)) -(syntax: .public (json [token .any]) - (let [(^open "[0]") ..monad - wrapper (function (_ x) (` (..json (~ x))))] - (case token - (^template [ ] - [[_ ( value)] - (in (list (` (: JSON ( (~ ( value)))))))]) - ([#.Bit code.bit #..Boolean] - [#.Frac code.frac #..Number] - [#.Text code.text #..String]) - - [_ (#.Tag ["" "null"])] - (in (list (` (: JSON #..Null)))) - - [_ (#.Tuple members)] - (in (list (` (: JSON (#..Array ((~! row) (~+ (list\each wrapper members)))))))) - - [_ (#.Record pairs)] - (do [! ..monad] - [pairs' (monad.each ! - (function (_ [slot value]) - (case slot - [_ (#.Text key_name)] - (in (` [(~ (code.text key_name)) (~ (wrapper value))])) - - _ - (meta.failure "Wrong syntax for JSON object."))) - pairs)] - (in (list (` (: JSON (#..Object ((~! dictionary.of_list) - (~! text.hash) - (list (~+ pairs'))))))))) - - _ - (in (list token))))) +(def: jsonP + (.Parser JSON) + (<>.rec + (function (_ jsonP) + ($_ <>.or + (.local_tag! "null") + .bit + .frac + .text + (<>\each row.of_list + (.tuple (<>.some jsonP))) + (<>\each (dictionary.of_list text.hash) + (.variant (<>.some (<>.and .text jsonP)))) + )))) + +(def: (jsonF token) + (-> JSON Code) + (case token + (#Null _) + (` #..Null) + + (^template [ ] + [( value) + (` ( (~ ( value))))]) + ([code.bit #..Boolean] + [code.frac #..Number] + [code.text #..String]) + + (#Array members) + (` (#..Array ((~! row.row) (~+ (row.list (row\each jsonF members)))))) + + (#Object pairs) + (` (#..Object ((~! dictionary.of_list) + (~! text.hash) + (list (~+ (|> pairs + dictionary.entries + (list\each (function (_ [key_name value]) + (` [(~ (code.text key_name)) (~ (jsonF value))]))))))))))) + +(syntax: .public (json [token ..jsonP]) + (in (list (` (: JSON (~ (jsonF token))))))) (def: .public (fields json) (-> JSON (Try (List String))) diff --git a/stdlib/source/library/lux/documentation.lux b/stdlib/source/library/lux/documentation.lux index 17998d949..f523c3335 100644 --- a/stdlib/source/library/lux/documentation.lux +++ b/stdlib/source/library/lux/documentation.lux @@ -68,12 +68,8 @@ (list\each reference_column) (list\mix n.min column))]) ([#.Form] + [#.Variant] [#.Tuple]) - - [[_ _ column] (#.Record pairs)] - (|> (list\composite (list\each (|>> product.left reference_column) pairs) - (list\each (|>> product.right reference_column) pairs)) - (list\mix n.min column)) )) (def: (padding reference_column [_ old_line old_column] [_ new_line new_column]) @@ -89,14 +85,6 @@ "" (text.together (list.repeated (n.- reference_column new_column) " ")))))) -(def: un_paired - (All (_ a) (-> (List [a a]) (List a))) - (let [melded (: (All (_ a) (-> [a a] (List a) (List a))) - (function (_ [left right] tail) - (list& left right tail)))] - (|>> list.reversed - (list\mix melded #.End)))) - (def: (code_documentation expected_module old_location reference_column example) (-> Text Location Nat Code [Location Text]) (case example @@ -130,19 +118,19 @@ [#.Frac [%.frac]] [#.Text [%.text]]) - (^template [|<| |>| ] + (^template [|<| |>| ] [[group_location ( members)] (let [[group_location' members_documentation] (list\mix (function (_ part [last_location text_accum]) (let [[member_location member_documentation] (code_documentation expected_module last_location reference_column part)] [member_location (format text_accum member_documentation)])) [(revised@ #.column ++ group_location) ""] - ( members))] + members)] [(revised@ #.column ++ group_location') (format (padding reference_column old_location group_location) |<| members_documentation |>|)])]) - ([syntax.open_form syntax.close_form #.Form |>] - [syntax.open_tuple syntax.close_tuple #.Tuple |>] - [syntax.open_record syntax.close_record #.Record ..un_paired]) + ([syntax.open_form syntax.close_form #.Form] + [syntax.open_variant syntax.close_variant #.Variant] + [syntax.open_tuple syntax.close_tuple #.Tuple]) )) (def: blank_line diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index be7fbe0d3..fd9e9d111 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -25,8 +25,7 @@ [syntax {"+" [syntax:]}] ["[0]" code] ["[0]" template]] - ["[0]" meta - ["[0]" annotation]] + ["[0]" meta] [target [jvm [encoding @@ -437,14 +436,9 @@ [[meta ( parts)] [meta ( (list\each (replaced f) parts))]]) ([#.Form] + [#.Variant] [#.Tuple]) - [meta (#.Record pairs)] - [meta (#.Record (list\each (: (-> [Code Code] [Code Code]) - (function (_ [key val]) - [(replaced f key) (replaced f val)])) - pairs))] - ast' ast')) diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index f84cc2d4a..6e77cb642 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -24,8 +24,7 @@ [syntax {"+" [syntax:]}] ["[0]" code] ["[0]" template]] - ["[0]" meta - ["[0]" annotation]]]]) + ["[0]" meta]]]) (template [ ] [(def: .public ( value) @@ -440,14 +439,9 @@ [[meta ( parts)] [meta ( (list\each (pre_walk_replace f) parts))]]) ([#.Form] + [#.Variant] [#.Tuple]) - [meta (#.Record pairs)] - [meta (#.Record (list\each (: (-> [Code Code] [Code Code]) - (function (_ [key val]) - [(pre_walk_replace f key) (pre_walk_replace f val)])) - pairs))] - ast' ast')) diff --git a/stdlib/source/library/lux/macro.lux b/stdlib/source/library/lux/macro.lux index db6a7427c..46d2ada34 100644 --- a/stdlib/source/library/lux/macro.lux +++ b/stdlib/source/library/lux/macro.lux @@ -78,26 +78,16 @@ targs+ (monad.each //.monad full_expansion targs)] (in (list (code.form (list\composite harg+ (list\conjoint (: (List (List Code)) targs+))))))) + [_ (#.Variant members)] + (do //.monad + [members' (monad.each //.monad full_expansion members)] + (in (list (code.variant (list\conjoint members'))))) + [_ (#.Tuple members)] (do //.monad [members' (monad.each //.monad full_expansion members)] (in (list (code.tuple (list\conjoint members'))))) - [_ (#.Record members)] - (|> members - (monad.each //.monad - (function (_ [left right]) - (do //.monad - [left (full_expansion left) - right (full_expansion right)] - (case [left right] - [(#.Item left #.End) (#.Item right #.End)] - (in [left right]) - - _ - (//.failure "Record members must expand into singletons."))))) - (\ //.monad each (|>> code.record list))) - _ (\ //.monad in (list syntax)))) diff --git a/stdlib/source/library/lux/macro/code.lux b/stdlib/source/library/lux/macro/code.lux index f266c5642..b80a1a418 100644 --- a/stdlib/source/library/lux/macro/code.lux +++ b/stdlib/source/library/lux/macro/code.lux @@ -29,8 +29,8 @@ ... (#.Identifier Name) ... (#.Tag Name) ... (#.Form (List (w (Code' w)))) -... (#.Tuple (List (w (Code' w)))) -... (#.Record (List [(w (Code' w)) (w (Code' w))]))) +... (#.Variant (List (w (Code' w)))) +... (#.Tuple (List (w (Code' w))))) ... (type: Code ... (Ann Location (Code' (Ann Location)))) @@ -49,8 +49,8 @@ [identifier Name #.Identifier] [tag Name #.Tag] [form (List Code) #.Form] + [variant (List Code) #.Variant] [tuple (List Code) #.Tuple] - [record (List [Code Code]) #.Record] ) (template [ ] @@ -82,11 +82,8 @@ [[[_ ( xs')] [_ ( ys')]] (\ (list.equivalence =) = xs' ys')]) ([#.Form] + [#.Variant] [#.Tuple]) - - [[_ (#.Record xs')] [_ (#.Record ys')]] - (\ (list.equivalence (product.equivalence = =)) - = xs' ys') _ false))) @@ -123,19 +120,8 @@ members) )]) ([#.Form "(" ")"] + [#.Variant "{" "}"] [#.Tuple "[" "]"]) - - [_ (#.Record pairs)] - ($_ text\composite - "{" - (list\mix (function (_ [left right] prev) - (let [next ($_ text\composite (format left) " " (format right))] - (if (text\= "" prev) - next - ($_ text\composite prev " " next)))) - "" - pairs) - "}") )) (def: .public (replaced original substitute ast) @@ -147,13 +133,8 @@ [[location ( parts)] [location ( (list\each (replaced original substitute) parts))]]) ([#.Form] + [#.Variant] [#.Tuple]) - [location (#.Record parts)] - [location (#.Record (list\each (function (_ [left right]) - [(replaced original substitute left) - (replaced original substitute right)]) - parts))] - _ ast))) diff --git a/stdlib/source/library/lux/macro/template.lux b/stdlib/source/library/lux/macro/template.lux index 3da90c053..2f690935b 100644 --- a/stdlib/source/library/lux/macro/template.lux +++ b/stdlib/source/library/lux/macro/template.lux @@ -114,15 +114,9 @@ (^template [] [[meta ( elems)] [meta ( (list\each (applied env) elems))]]) - ([#.Tuple] - [#.Form]) - - [meta (#.Record members)] - [meta (#.Record (list\each (: (-> [Code Code] [Code Code]) - (function (_ [key value]) - [(applied env key) - (applied env value)])) - members))] + ([#.Form] + [#.Variant] + [#.Tuple]) _ template)) diff --git a/stdlib/source/library/lux/meta/annotation.lux b/stdlib/source/library/lux/meta/annotation.lux deleted file mode 100644 index e157be601..000000000 --- a/stdlib/source/library/lux/meta/annotation.lux +++ /dev/null @@ -1,70 +0,0 @@ -(.module: - [library - [lux {"-" [nat int rev]} - [abstract - ["[0]" monad {"+" [do]}]] - [control - ["[0]" maybe]] - [data - ["[0]" name ("[1]\[0]" equivalence)]]]]) - -(type: .public Annotation - Code) - -(def: .public (value tag ann) - (-> Name Annotation (Maybe Code)) - (case ann - [_ (#.Record ann)] - (loop [ann ann] - (case ann - (#.Item [key value] ann') - (case key - [_ (#.Tag tag')] - (if (name\= tag tag') - (#.Some value) - (recur ann')) - - _ - (recur ann')) - - #.End - #.None)) - - _ - #.None)) - -(template [ ] - [(def: .public ( tag ann) - (-> Name Annotation (Maybe )) - (case (..value tag ann) - (#.Some [_ ( value)]) - (#.Some value) - - _ - #.None))] - - [bit #.Bit Bit] - [nat #.Nat Nat] - [int #.Int Int] - [rev #.Rev Rev] - [frac #.Frac Frac] - [text #.Text Text] - [identifier #.Identifier Name] - [tag #.Tag Name] - [form #.Form (List Code)] - [tuple #.Tuple (List Code)] - [record #.Record (List [Code Code])] - ) - -(def: .public (flagged? flag) - (-> Name Annotation Bit) - (|>> (..bit flag) (maybe.else false))) - -(def: (text_parser input) - (-> Code (Maybe Text)) - (case input - [_ (#.Text actual_value)] - (#.Some actual_value) - - _ - #.None)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux index bd1aca3b3..ec444b003 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux @@ -117,14 +117,14 @@ ["(" open_form] [")" close_form] + ... Variant delimiters + ["{" open_variant] + ["}" close_variant] + ... Tuple delimiters ["[" open_tuple] ["]" close_tuple] - ... Record delimiters - ["{" open_record] - ["}" close_record] - ["#" sigil] ["," digit_separator] @@ -239,8 +239,9 @@ ... Form and tuple syntax is mostly the same, differing only in the ... delimiters involved. ... They may have an arbitrary number of arbitrary Code nodes as elements. - [form_parser ..close_form #.Form] - [tuple_parser ..close_tuple #.Tuple] + [form_parser ..close_form #.Form] + [variant_parser ..close_variant #.Variant] + [tuple_parser ..close_tuple #.Tuple] ) (inline: (record_parser parse where offset source_code) @@ -254,7 +255,7 @@ (recur sourceFV (#.Item [field value] stack))) (#.Left [source' error]) - (if (same? ..close_record error) + (if (same? ..close_variant error) (#.Right [source' [where (#.Record (list.reversed stack))]]) (#.Left [source' error]))))) @@ -292,8 +293,8 @@ [text.new_line] [text.carriage_return] [..name_separator] [..open_form] [..close_form] + [..open_variant] [..close_variant] [..open_tuple] [..close_tuple] - [..open_record] [..close_record] [..text_delimiter] [..sigil]) (static ..digit_separator)] @@ -517,8 +518,8 @@ (!close )] [..open_form ..close_form form_parser] + [..open_variant ..close_variant variant_parser] [..open_tuple ..close_tuple tuple_parser] - [..open_record ..close_record record_parser] )] (`` ("lux syntax char case!" char/0 [[(~~ (static text.space)) -- cgit v1.2.3