From 3053fd79bc6ae42415298ee056a268dc2c9b690c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 26 Jun 2022 12:55:04 -0400 Subject: New "parser" hierarchy. [Part 4] --- .../source/polytypic/lux/abstract/equivalence.lux | 6 ++-- stdlib/source/polytypic/lux/abstract/functor.lux | 41 +++++++++++----------- stdlib/source/polytypic/lux/data/format/json.lux | 10 +++--- 3 files changed, 28 insertions(+), 29 deletions(-) (limited to 'stdlib/source/polytypic') diff --git a/stdlib/source/polytypic/lux/abstract/equivalence.lux b/stdlib/source/polytypic/lux/abstract/equivalence.lux index fce8d86bd..3d8497e87 100644 --- a/stdlib/source/polytypic/lux/abstract/equivalence.lux +++ b/stdlib/source/polytypic/lux/abstract/equivalence.lux @@ -4,9 +4,8 @@ [abstract [monad (.only Monad do)]] [control - ["[0]" maybe] - ["<>" parser (.only) - ["<[0]>" type]]] + ["<>" parser] + ["[0]" maybe]] [data ["[0]" product] ["[0]" bit] @@ -35,6 +34,7 @@ ["[0]" day] ["[0]" month]] ["[0]" type (.only) + ["<[1]>" \\parser] ["[0]" poly (.only polytypic)] ["[0]" unit]]]] [\\library diff --git a/stdlib/source/polytypic/lux/abstract/functor.lux b/stdlib/source/polytypic/lux/abstract/functor.lux index 1ff6c0398..3cc3074b0 100644 --- a/stdlib/source/polytypic/lux/abstract/functor.lux +++ b/stdlib/source/polytypic/lux/abstract/functor.lux @@ -4,9 +4,7 @@ [abstract [monad (.only Monad do)]] [control - ["p" parser (.only) - ["<[0]>" type] - ["s" code (.only Parser)]]] + ["<>" parser]] [data ["[0]" product] ["[0]" text (.only) @@ -19,13 +17,14 @@ [number ["n" nat]]] ["[0]" type (.only) + ["<[1]>" \\parser] ["[0]" poly (.only polytypic)]]]] [\\library ["[0]" /]]) (def .public functor (polytypic functor - (do [! p.monad] + (do [! <>.monad] [.let [g!_ (code.local "____________") type_funcC (code.local "____________type_funcC") funcC (code.local "____________funcC") @@ -44,16 +43,16 @@ ((~! /.Functor) ((~ (poly.code *env* unwrappedT)) (~+ paramsC))))))))) Arg (is (-> Code (.Parser Code)) (function (Arg valueC) - (all p.either + (all <>.either ... Type-var - (do p.monad + (do <>.monad [.let [varI (|> num_vars (n.* 2) --)] _ (.this_parameter varI)] (in (` ((~ funcC) (~ valueC))))) ... Variants (do ! [_ (in []) - membersC (.variant (p.many (Arg valueC))) + membersC (.variant (<>.many (Arg valueC))) .let [last (-- (list.size membersC))]] (in (` (case (~ valueC) (~+ (list#conjoint (list#each (function (_ [tag memberC]) @@ -64,18 +63,18 @@ (` {(~ (code.nat tag)) #0 (~ memberC)})))) (list.enumeration membersC)))))))) ... Tuples - (do p.monad + (do <>.monad [pairsCC (is (.Parser (List [Code Code])) (.tuple (loop (again [idx 0 pairsCC (is (List [Code Code]) (list))]) - (p.either (let [slotC (|> idx %.nat (format "____________slot") code.local)] - (do ! - [_ (in []) - memberC (Arg slotC)] - (again (++ idx) - (list#composite pairsCC (list [slotC memberC]))))) - (in pairsCC)))))] + (<>.either (let [slotC (|> idx %.nat (format "____________slot") code.local)] + (do ! + [_ (in []) + memberC (Arg slotC)] + (again (++ idx) + (list#composite pairsCC (list [slotC memberC]))))) + (in pairsCC)))))] (in (` (case (~ valueC) [(~+ (list#each product.left pairsCC))] [(~+ (list#each product.right pairsCC))])))) @@ -84,7 +83,7 @@ [_ (in []) .let [g! (code.local "____________") outL (code.local "____________outL")] - [inT+ outC] (.function (p.many .any) + [inT+ outC] (.function (<>.many .any) (Arg outL)) .let [inC+ (|> (list.size inT+) list.indices @@ -93,18 +92,18 @@ (let [(~ outL) ((~ valueC) (~+ inC+))] (~ outC)))))) ... Recursion - (do p.monad + (do <>.monad [_ .recursive_call] (in (` ((~' each) (~ funcC) (~ valueC))))) ... Parameters - (do p.monad + (do <>.monad [_ .any] (in valueC)) )))] [_ _ outputC] (is (.Parser [Code (List Code) Code]) - (p.either (.polymorphic - (Arg inputC)) - (p.failure (format "Cannot create Functor for: " (%.type inputT)))))] + (<>.either (.polymorphic + (Arg inputC)) + (<>.failure (format "Cannot create Functor for: " (%.type inputT)))))] (in (` (is (~ (@Functor inputT)) (implementation (def ((~' each) (~ funcC) (~ inputC)) diff --git a/stdlib/source/polytypic/lux/data/format/json.lux b/stdlib/source/polytypic/lux/data/format/json.lux index 8ce7112e3..064e4bcce 100644 --- a/stdlib/source/polytypic/lux/data/format/json.lux +++ b/stdlib/source/polytypic/lux/data/format/json.lux @@ -5,10 +5,8 @@ [monad (.only do)] ["[0]" codec]] [control - ["[0]" try] - ["<>" parser (.only) - ["<[0]>" type] - ["<[0]>" code]]] + ["<>" parser] + ["[0]" try]] [data ["[0]" text (.only) ["%" \\format (.only format)]] @@ -21,7 +19,8 @@ ["[0]" dictionary]]] [macro [syntax (.only syntax)] - ["[0]" code]] + ["[0]" code (.only) + ["<[1]>" \\parser]]] [math [number ["n" nat (.use "[1]#[0]" decimal)] @@ -35,6 +34,7 @@ ["[0]" day] ["[0]" month]] ["[0]" type (.only) + ["<[1]>" \\parser] ["[0]" unit] ["[0]" poly (.only polytypic)]]]] [\\library -- cgit v1.2.3