rlp syntax

gonna work on typechecking now lol.......
This commit is contained in:
crumbtoo
2023-12-12 13:50:07 -07:00
parent f552461cb3
commit a65ae0bd52
3 changed files with 71 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ library
, Core.Lex , Core.Lex
, Control.Monad.Errorful , Control.Monad.Errorful
, Core2Core , Core2Core
, RLP.Syntax
build-tool-depends: happy:happy, alex:alex build-tool-depends: happy:happy, alex:alex
@@ -50,6 +51,8 @@ library
, hashable , hashable
, pretty , pretty
, recursion-schemes , recursion-schemes
, megaparsec
, text
hs-source-dirs: src hs-source-dirs: src
default-language: GHC2021 default-language: GHC2021

View File

@@ -115,33 +115,33 @@ instance Monoid (Program b) where
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
class HasRHS s z | s -> z where class HasRHS s t a b | s -> a, t -> b, s b -> t, t a -> s where
_rhs :: Lens' s (Expr z) _rhs :: Lens s t a b
instance HasRHS (Alter b) b where instance HasRHS (Alter b) (Alter b) (Expr b) (Expr b) where
_rhs = lens _rhs = lens
(\ (Alter _ _ e) -> e) (\ (Alter _ _ e) -> e)
(\ (Alter t as _) e' -> Alter t as e') (\ (Alter t as _) e' -> Alter t as e')
instance HasRHS (ScDef b) b where instance HasRHS (ScDef b) (ScDef b) (Expr b) (Expr b) where
_rhs = lens _rhs = lens
(\ (ScDef _ _ e) -> e) (\ (ScDef _ _ e) -> e)
(\ (ScDef n as _) e' -> ScDef n as e') (\ (ScDef n as _) e' -> ScDef n as e')
instance HasRHS (Binding b) b where instance HasRHS (Binding b) (Binding b) (Expr b) (Expr b) where
_rhs = lens _rhs = lens
(\ (_ := e) -> e) (\ (_ := e) -> e)
(\ (k := _) e' -> k := e') (\ (k := _) e' -> k := e')
class HasLHS s a | s -> a where class HasLHS s t a b | s -> a, t -> b, s b -> t, t a -> s where
_lhs :: Lens' s a _lhs :: Lens s t a b
instance HasLHS (Alter b) (AltCon, [b]) where instance HasLHS (Alter b) (Alter b) (AltCon, [b]) (AltCon, [b]) where
_lhs = lens _lhs = lens
(\ (Alter a bs _) -> (a,bs)) (\ (Alter a bs _) -> (a,bs))
(\ (Alter _ _ e) (a',bs') -> Alter a' bs' e) (\ (Alter _ _ e) (a',bs') -> Alter a' bs' e)
instance HasLHS (ScDef b) (b, [b]) where instance HasLHS (ScDef b) (ScDef b) (b, [b]) (b, [b]) where
_lhs = lens _lhs = lens
(\ (ScDef n as _) -> (n,as)) (\ (ScDef n as _) -> (n,as))
(\ (ScDef _ _ e) (n',as') -> (ScDef n' as' e)) (\ (ScDef _ _ e) (n',as') -> (ScDef n' as' e))

59
src/RLP/Syntax.hs Normal file
View File

@@ -0,0 +1,59 @@
{-# LANGUAGE OverloadedStrings #-}
module RLP.Syntax
( RlpExpr
)
where
----------------------------------------------------------------------------------
import Data.Text (Text)
import Lens.Micro
import Core (HasRHS(..), HasLHS(..))
----------------------------------------------------------------------------------
newtype RlpProgram b = RlpProgram [Decl b]
data Decl b = InfixD InfixAssoc Int VarId
| FunD VarId [Pat b] (RlpExpr b)
| DataD ConId [ConId] [ConAlt]
data ConAlt = ConAlt ConId [ConId]
data InfixAssoc = Assoc | AssocL | AssocR
data RlpExpr b = LetE [Bind b] (RlpExpr b)
| VarE VarId
| ConE ConId
| LamE [Pat b] (RlpExpr b)
| CaseE (RlpExpr b) [Alt b]
| IfE (RlpExpr b) (RlpExpr b) (RlpExpr b)
| AppE (RlpExpr b) (RlpExpr b)
| LitE (Lit b)
-- do we want guards?
data Alt b = AltA (Pat b) (RlpExpr b)
data Bind b = PatB (Pat b) (RlpExpr b)
| FunB VarId [Pat b] (RlpExpr b)
data VarId = NameVar Text
| SymVar Text
data ConId = NameCon Text
| SymCon Text
data Pat b = VarP VarId
| LitP (Lit b)
| ConP ConId [Pat b]
data Lit b = IntL Int
| CharL Char
| ListL [RlpExpr b]
-- instance HasLHS Alt Alt Pat Pat where
-- _lhs = lens
-- (\ (AltA p _) -> p)
-- (\ (AltA _ e) p' -> AltA p' e)
-- instance HasRHS Alt Alt RlpExpr RlpExpr where
-- _rhs = lens
-- (\ (AltA _ e) -> e)
-- (\ (AltA p _) e' -> AltA p e')