This commit is contained in:
@@ -11,6 +11,7 @@ import Language.SexpGrammar.Generic
|
||||
import GHC.Generics
|
||||
import Prelude hiding ((.), id)
|
||||
import Control.Category
|
||||
import Data.List.NonEmpty (NonEmpty ((:|)))
|
||||
|
||||
|
||||
type Name = Text
|
||||
@@ -27,7 +28,7 @@ data Val
|
||||
deriving (Show, Generic)
|
||||
|
||||
data Exp
|
||||
= ExpLet (List (Name, Exp)) Exp
|
||||
= ExpLet (NonEmpty (Name, Exp)) Exp
|
||||
| ExpApply Exp (List Exp)
|
||||
| ExpBegin (List Exp)
|
||||
| ExpVal Val
|
||||
@@ -35,15 +36,20 @@ 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 :- (List (a, b) :- t1)) t2
|
||||
-> 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 = list $ rest binding
|
||||
bindings = nonempty binding
|
||||
binding :: Grammar Position (Sexp :- t) ((_, _) :- t)
|
||||
binding = list (el name >>> el rhs) >>> pair
|
||||
|
||||
|
||||
Reference in New Issue
Block a user