summaryrefslogtreecommitdiff
path: root/src/Transfer/Syntax/Syntax.cf
blob: 3550786d5f4403af0e1be360ed2d1e878e896ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
entrypoints Module, Exp ;

layout "let", "where", "of","rec", "sig", "do" ;
layout stop "in" ;
layout toplevel ;

comment "--" ;
comment "{-" "-}" ;

Module. Module ::= [Import] [Decl] ;

Import. Import ::= "import" Ident ;
separator Import ";" ;

DataDecl.  Decl ::= "data" Ident ":" Exp "where" "{" [ConsDecl] "}" ;
TypeDecl.  Decl ::= Ident ":" Exp ;
ValueDecl. Decl ::= Ident [Pattern] "=" Exp ;
DeriveDecl. Decl ::= "derive" Ident Ident ;
separator Decl ";" ;

ConsDecl. ConsDecl ::= Ident ":" Exp ;
separator ConsDecl ";" ;

-- Disjunctive patterns.
POr.      Pattern ::= Pattern1 "||" Pattern ;

-- Hack: constructor applied to at least one pattern
-- this is to separate it from variable patterns
PConsTop. Pattern1 ::= Ident Pattern2 [Pattern] ;

-- Real constructor pattern
internal PCons.    Pattern2 ::= "(" Ident [Pattern] ")" ;

-- Record patterns
PRec.     Pattern2 ::= "rec" "{" [FieldPattern] "}";
-- The pattern matching the Type constant
PType.    Pattern2 ::= "Type" ;
-- String literal patterns
PStr.     Pattern2 ::= String ;
-- Integer literal patterns
PInt.     Pattern2 ::= Integer ;
-- Variable patterns
PVar.     Pattern2 ::= Ident ;
-- Wild card patterns
PWild.    Pattern2 ::= "_" ;

coercions Pattern 2 ;

[].  [Pattern] ::= ;
(:). [Pattern] ::= Pattern2 [Pattern] ;

FieldPattern. FieldPattern ::= Ident "=" Pattern ;
separator FieldPattern ";" ;

ELet.      Exp  ::= "let" "{" [LetDef] "}" "in" Exp ;
LetDef.    LetDef ::= Ident ":" Exp "=" Exp ;
separator LetDef ";" ;

ECase.     Exp  ::= "case" Exp "of" "{" [Case] "}" ;
Case. Case ::= Pattern "->" Exp ;
separator Case ";" ;

EIf.       Exp  ::= "if" Exp "then" Exp "else" Exp ;

EDo.       Exp  ::= "do" "{" [Bind] Exp "}" ;
BindVar.   Bind ::= VarOrWild "<-" Exp ;
BindNoVar. Bind ::= Exp ;
terminator Bind ";" ;

EAbs.      Exp2 ::= "\\" VarOrWild "->" Exp ;
EPi.       Exp2 ::= "(" VarOrWild ":" Exp ")" "->" Exp ;
EPiNoVar.  Exp2 ::= Exp3 "->" Exp ;
VVar.      VarOrWild ::= Ident ;
VWild.     VarOrWild ::= "_" ;

EBind.     Exp3 ::= Exp3 ">>=" Exp4 ;
EBindC.    Exp3 ::= Exp3 ">>"  Exp4 ;

EOr.       Exp4 ::= Exp5 "||" Exp4 ;

EAnd.      Exp5 ::= Exp6 "&&" Exp5 ;

EEq.       Exp6 ::= Exp7 "==" Exp7 ;
ENe.       Exp6 ::= Exp7 "/=" Exp7 ;
ELt.       Exp6 ::= Exp7 "<"  Exp7 ;
ELe.       Exp6 ::= Exp7 "<=" Exp7 ;
EGt.       Exp6 ::= Exp7 ">"  Exp7 ;
EGe.       Exp6 ::= Exp7 ">=" Exp7 ;

EListCons. Exp7 ::= Exp8 "::" Exp7 ;

EAdd.      Exp8 ::= Exp8 "+" Exp9 ;
ESub.      Exp8 ::= Exp8 "-" Exp9 ;

EMul.      Exp9 ::= Exp9 "*" Exp10 ;
EDiv.      Exp9 ::= Exp9 "/" Exp10 ;
EMod.      Exp9 ::= Exp9 "%" Exp10 ;

ENeg.      Exp10 ::= "-" Exp10 ;

EApp.      Exp11 ::= Exp11 Exp12 ;

EProj.     Exp12 ::= Exp12 "." Ident ;

ERecType.  Exp13 ::= "sig" "{" [FieldType] "}" ;
FieldType. FieldType  ::= Ident ":" Exp ;
separator FieldType ";" ;

ERec.      Exp13 ::= "rec" "{" [FieldValue] "}" ;
FieldValue.FieldValue ::= Ident "=" Exp ;
separator FieldValue ";" ;

EList.     Exp13 ::= "[" [Exp] "]" ;

EVar.      Exp13 ::= Ident ;
EType.     Exp13 ::= "Type" ;
EStr.      Exp13 ::= String ;
EInt.      Exp13 ::= Integer ;
EMeta.     Exp13 ::= "?" ;

coercions Exp 13 ;

separator Exp "," ;