This commit is contained in:
+14
-9
@@ -17,8 +17,12 @@ import Gyehoek.Sexp qualified
|
||||
|
||||
type Name = Text
|
||||
|
||||
data Prim = PrimAdd | PrimSub | PrimMul | PrimDiv
|
||||
deriving (Show, Generic)
|
||||
data Prim e
|
||||
= PrimAdd e e
|
||||
| PrimSub e e
|
||||
| PrimMul e e
|
||||
| PrimDiv e e
|
||||
deriving (Show, Generic, Functor, Foldable, Traversable)
|
||||
|
||||
data Lit
|
||||
= LitInt Int
|
||||
@@ -31,20 +35,22 @@ data Exp
|
||||
| ExpApply Exp (List Exp)
|
||||
| ExpBegin (List Exp)
|
||||
| ExpLit Lit
|
||||
| ExpPrim Prim
|
||||
| ExpPrim (Prim Exp)
|
||||
| ExpLambda (List Name) Exp
|
||||
| ExpVar Name
|
||||
deriving (Show, Generic)
|
||||
|
||||
|
||||
|
||||
instance SexpIso Prim where
|
||||
instance SexpIso a => SexpIso (Prim a) where
|
||||
sexpIso = match
|
||||
$ With (. sym "+")
|
||||
$ With (. sym "-")
|
||||
$ With (. sym "*")
|
||||
$ With (. sym "/")
|
||||
$ With (. binop "prim-+")
|
||||
$ With (. binop "prim--")
|
||||
$ With (. binop "prim-*")
|
||||
$ With (. binop "prim-/")
|
||||
$ End
|
||||
where
|
||||
binop s = list $ el (sym s) >>> el sexpIso >>> el sexpIso
|
||||
|
||||
instance SexpIso Lit where
|
||||
sexpIso = match
|
||||
@@ -52,7 +58,6 @@ instance SexpIso Lit where
|
||||
$ With (. sym "nil")
|
||||
$ With (. sexpIso)
|
||||
$ End
|
||||
where
|
||||
|
||||
instance SexpIso Exp where
|
||||
sexpIso = match
|
||||
|
||||
Reference in New Issue
Block a user