This commit is contained in:
+3
-19
@@ -12,6 +12,7 @@ import GHC.Generics
|
||||
import Prelude hiding ((.), id)
|
||||
import Control.Category
|
||||
import Data.List.NonEmpty (NonEmpty ((:|)))
|
||||
import Gyehoek.Sexp qualified
|
||||
|
||||
|
||||
type Name = Text
|
||||
@@ -36,23 +37,6 @@ data Exp
|
||||
|
||||
|
||||
|
||||
nonempty :: SexpGrammar a -> SexpGrammar (NonEmpty a)
|
||||
nonempty a =
|
||||
list (el a >>> rest a) >>>
|
||||
pair >>> iso (uncurry (:|)) (\(x :| xs) -> (x, xs))
|
||||
|
||||
letIso
|
||||
:: (forall t. Grammar Position (Sexp :- t) (a :- t))
|
||||
-> (forall t. Grammar Position (Sexp :- t) (b :- t))
|
||||
-> Grammar Position (Sexp :- (NonEmpty (a, b) :- t1)) t2
|
||||
-> Grammar Position (Sexp :- t1) t2
|
||||
letIso name rhs e = list (el (sym "let") >>> el bindings >>> el e)
|
||||
where
|
||||
-- bindings :: Grammar Position (Sexp :- _) (List (_, _) :- _)
|
||||
bindings = nonempty binding
|
||||
binding :: Grammar Position (Sexp :- t) ((_, _) :- t)
|
||||
binding = list (el name >>> el rhs) >>> pair
|
||||
|
||||
instance SexpIso Prim where
|
||||
sexpIso = match
|
||||
$ With (. sym "+")
|
||||
@@ -67,7 +51,7 @@ instance SexpIso Val where
|
||||
$ With (. sym "nil")
|
||||
$ With (. sexpIso)
|
||||
$ With lam
|
||||
$ With (\var -> var . symbol)
|
||||
$ With (. symbol)
|
||||
$ End
|
||||
where
|
||||
lam q = q . list
|
||||
@@ -77,7 +61,7 @@ instance SexpIso Val where
|
||||
|
||||
instance SexpIso Exp where
|
||||
sexpIso = match
|
||||
$ With (. letIso symbol sexpIso sexpIso)
|
||||
$ With (. Gyehoek.Sexp.let_ symbol sexpIso sexpIso)
|
||||
$ With (\app -> app . list (el sexpIso >>> rest sexpIso))
|
||||
$ With (\bgn -> bgn . list (el (sym "begin") >>> rest sexpIso))
|
||||
$ With (<<< sexpIso)
|
||||
|
||||
Reference in New Issue
Block a user