This commit is contained in:
@@ -40,10 +40,17 @@ data Lit
|
||||
| LitBool Bool
|
||||
deriving (Show, Generic)
|
||||
|
||||
data Define
|
||||
= DefineConstant Name Exp
|
||||
| DefineProcedure Name (List Name) (List Exp)
|
||||
deriving (Show, Generic)
|
||||
|
||||
data Exp
|
||||
= ExpLet (NonEmpty (Name, Exp)) Exp
|
||||
| ExpPrim (Prim Exp)
|
||||
| ExpBegin (List Exp)
|
||||
| ExpDefine Define
|
||||
| ExpIf Exp Exp Exp
|
||||
| ExpLit Lit
|
||||
| ExpApply Exp (List Exp)
|
||||
| ExpLambda (List Name) Exp
|
||||
@@ -78,17 +85,30 @@ instance SexpIso Lit where
|
||||
$ With (. sexpIso)
|
||||
$ End
|
||||
|
||||
instance SexpIso Define where
|
||||
sexpIso = match
|
||||
$ With (. defconst)
|
||||
$ With (. defun)
|
||||
$ End
|
||||
where
|
||||
defconst = list $ el (sym "define") >>> el symbol >>> el sexpIso
|
||||
defun = list $ el (sym "define") >>> el args >>> rest sexpIso
|
||||
args = list $ el symbol >>> rest symbol
|
||||
|
||||
instance SexpIso Exp where
|
||||
sexpIso = match
|
||||
$ With (. Gyehoek.Sexp.let_ symbol sexpIso sexpIso)
|
||||
$ With (. sexpIso)
|
||||
$ With (\bgn -> bgn . list (el (sym "begin") >>> rest sexpIso))
|
||||
$ With (. sexpIso)
|
||||
$ With (. if_)
|
||||
$ With (. sexpIso)
|
||||
$ With (\app -> app . list (el sexpIso >>> rest sexpIso))
|
||||
$ With (. lam)
|
||||
$ With (. symbol)
|
||||
$ End
|
||||
where
|
||||
if_ = list $ el (sym "if") >>> el sexpIso >>> el sexpIso >>> el sexpIso
|
||||
lam = list
|
||||
( el (sym "lambda")
|
||||
>>> el (sexpIso @(List Name))
|
||||
|
||||
Reference in New Issue
Block a user