churf/Grammar.cf
sebastianselander 41fc863658 added PEnum
2023-03-24 17:39:34 +01:00

96 lines
2.9 KiB
CFEngine3

-------------------------------------------------------------------------------
-- * PROGRAM
-------------------------------------------------------------------------------
Program. Program ::= [Def] ;
-------------------------------------------------------------------------------
-- * TOP-LEVEL
-------------------------------------------------------------------------------
DBind. Def ::= Bind ;
DSig. Def ::= Sig ;
DData. Def ::= Data ;
Sig. Sig ::= LIdent ":" Type ;
Bind. Bind ::= LIdent [LIdent] "=" Exp ;
-------------------------------------------------------------------------------
-- * TYPES
-------------------------------------------------------------------------------
TLit. Type2 ::= UIdent ;
TVar. Type2 ::= TVar ;
TAll. Type1 ::= "forall" TVar "." Type ;
TData. Type1 ::= UIdent "(" [Type] ")" ;
internal TEVar. Type1 ::= TEVar ;
TFun. Type ::= Type1 "->" Type ;
MkTVar. TVar ::= LIdent ;
internal MkTEVar. TEVar ::= LIdent ;
-------------------------------------------------------------------------------
-- * DATA TYPES
-------------------------------------------------------------------------------
Constructor. Constructor ::= UIdent ":" Type ;
Data. Data ::= "data" Type "where" "{" [Constructor] "}" ;
-------------------------------------------------------------------------------
-- * EXPRESSIONS
-------------------------------------------------------------------------------
EAnn. Exp4 ::= "(" Exp ":" Type ")" ;
EVar. Exp3 ::= LIdent ;
EInj. Exp3 ::= UIdent ;
ELit. Exp3 ::= Lit ;
EApp. Exp2 ::= Exp2 Exp3 ;
EAdd. Exp1 ::= Exp1 "+" Exp2 ;
ELet. Exp ::= "let" Bind "in" Exp ;
EAbs. Exp ::= "\\" LIdent "." Exp ;
ECase. Exp ::= "case" Exp "of" "{" [Branch] "}";
-------------------------------------------------------------------------------
-- * LITERALS
-------------------------------------------------------------------------------
LInt. Lit ::= Integer ;
LChar. Lit ::= Char ;
-------------------------------------------------------------------------------
-- * CASE
-------------------------------------------------------------------------------
Branch. Branch ::= Pattern "=>" Exp ;
PVar. Pattern1 ::= LIdent ;
PLit. Pattern1 ::= Lit ;
PCatch. Pattern1 ::= "_" ;
PEnum. Pattern1 ::= UIdent ;
PInj. Pattern ::= UIdent [Pattern1] ;
-------------------------------------------------------------------------------
-- * AUX
-------------------------------------------------------------------------------
terminator Def ";" ;
separator nonempty Constructor "" ;
separator Type " " ;
separator nonempty Pattern1 " " ;
terminator Branch ";" ;
separator Ident " ";
separator LIdent " ";
separator TVar " " ;
coercions Exp 4 ;
coercions Type 2 ;
coercions Pattern 1 ;
token UIdent (upper (letter | digit | '_')*) ;
token LIdent (lower (letter | digit | '_')*) ;
comment "--" ;
comment "{-" "-}" ;