-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLing.cf
199 lines (156 loc) · 5.45 KB
/
Ling.cf
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
layout toplevel ;
layout "of" ;
comment "--" ;
comment "{-" "-}" ;
Prg. Program ::= [Dec] ;
token Name ( ["_"] (letter | ["-+*/%:=<>&|."] | digit)*
(letter | ["-+*/%:=<>&|."])
(letter | ["-+*/%:=<>&|.'"] | digit)*
["_"]
| ["_"]
| letter
(letter | ["_-'"] | digit)*
| digit
(letter | ["_-'"] | digit)*
letter
(letter | ["_-'"] | digit)*
);
-- This "new/"·Name
token NewName
{"new/"} ( ["_"] (letter | ["-+*/%:=<>&|."] | digit)*
(letter | ["-+*/%:=<>&|."])
(letter | ["-+*/%:=<>&|.'"] | digit)*
["_"]
| ["_"]
| letter
(letter | ["_-'"] | digit)*
| digit
(letter | ["_-'"] | digit)*
letter
(letter | ["_-'"] | digit)*
);
token OpName
( (letter | ["-+*/%"] | digit)*
["-+*/%"]
(letter | ["-+*/%_'"] | digit)*
| (letter | ["-+*/%=<>&|"] | digit)*
["-+*/%=<>&|"]+
(letter | ["-+*/%_=<>&|'"] | digit)*
| ["-+*/%=<>&|."]* ["."] ["-+*/%=<>&|."]+
| ["-+*/%=<>&|."]+ ["."]
);
DDef. Dec ::= Name OptSig "=" Term ;
DSig. Dec ::= Name ":" Term ;
DDat. Dec ::= "data" Name "=" [ConName] ;
DAsr. Dec ::= "assert" Assertion ;
AEq. Assertion ::= Term "=" Term OptSig ;
CN. ConName ::= "`" Name ;
separator ConName "|" ;
NoSig. OptSig ::= ;
SoSig. OptSig ::= ":" Term ;
separator Dec "," ;
VD. VarDec ::= "(" Name OptSig ")" ;
CD. ChanDec ::= Name OptRepl OptSession ;
separator ChanDec "," ;
Br. Branch ::= ConName "->" Term ;
separator Branch "," ;
LInteger. Literal ::= Integer ;
LDouble. Literal ::= Double ;
LString. Literal ::= String ;
LChar. Literal ::= Char ;
-- Atomic terms
Var. ATerm ::= Name ;
Op. ATerm ::= OpName ;
Lit. ATerm ::= Literal ;
Con. ATerm ::= ConName ;
TTyp. ATerm ::= "Type" ;
TProto. ATerm ::= "<" [RSession] ">" ;
Paren. ATerm ::= "(" Term OptSig ")" ;
-- Sessions
End. ATerm ::= "end" ;
Par. ATerm ::= "{" [RSession] "}" ;
Ten. ATerm ::= "[" [RSession] "]" ;
Seq. ATerm ::= "[:" [RSession] ":]" ;
separator ATerm "" ;
RawApp. Term3 ::= ATerm [ATerm] ;
Case. Term2 ::= "case" Term "of" "{" [Branch] "}" ;
Snd. Term2 ::= "!" Term3 CSession ;
Rcv. Term2 ::= "?" Term3 CSession ;
Dual. Term2 ::= "~" Term2 ;
TRecv. Term2 ::= "<-" Name ;
_. Term2 ::= Term3 ;
Loli. Term1 ::= Term2 "-o" Term1 ;
-- WARNING: Dependent `->`/`**` (e.g. Π/Σ) are recognized afterwards.
-- Notice that `Term2` is used on the left of `->` and `**`.
-- In Ling.Reify this `Term2` is analysed:
-- If it matches against `("(" Name [Name] ":" Term ")")+` then this is a
-- dependent (`->`/`**`).
-- Otherwise it is considered as a *non* dependent `->`/`**`.
-- For instance `(Vec Int n : Type)-> F Vec Int n` is a dependent `->`
-- which introduces 3 types `Vec`, `Int`, and `n`, while
-- `(Vec Int 42 : Type)-> T` is single non-dependent `->` where `: Type` is
-- an annotation.
TFun. Term1 ::= Term2 "->" Term1 ;
TSig. Term1 ::= Term2 "**" Term1 ;
Let. Term1 ::= "let" Name OptSig "=" Term "in" Term ;
_. Term1 ::= Term2 ;
-- WARNING: The `Term2` is further analysed as: `("(" Name [Name] ":" Term ")")+`
Lam. Term ::= "\\" Term2 "->" Term ;
TProc. Term ::= "proc" "(" [ChanDec] ")" Proc ;
_. Term ::= Term1 ;
PAct. Proc1 ::= Act ;
PPrll. Proc1 ::= "(" [Proc] ")" ;
PRepl. Proc1 ::= ReplKind "^" ATerm WithIndex Proc1 ;
PNxt. Proc ::= Proc1 Proc ;
PDot. Proc ::= Proc1 "." Proc ;
PSem. Proc ::= Proc1 ";" Proc ;
_. Proc ::= Proc1 ;
separator Proc "|" ;
ReplSeq. ReplKind ::= "sequence" ;
ReplPar. ReplKind ::= "parallel" ;
NoIndex. WithIndex ::= ;
SoIndex. WithIndex ::= "with" Name ;
Nu. Act ::= NewAlloc ;
Split. Act ::= Split ;
Send. Act ::= "send" Name ATerm ;
NewSend. Act ::= Name OptSession "<-" ATerm ;
Recv. Act ::= "recv" Name VarDec ;
NewRecv. Act ::= "let" Name OptSig "<-" Name ;
LetRecv. Act ::= "let" Name OptSig "<=" ATerm ;
Ax. Act ::= "fwd" ASession "(" [ChanDec] ")" ;
SplitAx. Act ::= "fwd" Integer ASession Name ;
At. Act ::= "@" ATerm TopCPatt ;
LetA. Act ::= "let" Name OptSig "=" ATerm ;
AS. ASession ::= ATerm ;
PatSplit. Split ::= "split" Name OptAs CPatt ;
ParSplit. Split ::= Name "{" [ChanDec] "}" ;
TenSplit. Split ::= Name "[" [ChanDec] "]" ;
SeqSplit. Split ::= Name "[:" [ChanDec] ":]" ;
NoAs. OptAs ::= ;
SoAs. OptAs ::= "as" ;
OldTopPatt. TopCPatt ::= "(" [ChanDec] ")" ;
ParTopPatt. TopCPatt ::= "{" [CPatt] "}" ;
TenTopPatt. TopCPatt ::= "[" [CPatt] "]" ;
SeqTopPatt. TopCPatt ::= "[:" [CPatt] ":]" ;
ChaPatt. CPatt ::= ChanDec ;
ParPatt. CPatt ::= "{" [CPatt] "}" ;
TenPatt. CPatt ::= "[" [CPatt] "]" ;
SeqPatt. CPatt ::= "[:" [CPatt] ":]" ;
separator CPatt "," ;
NoSession. OptSession ::= ;
SoSession. OptSession ::= ":" RSession ;
Repl. RSession ::= Term OptRepl ;
separator RSession "," ;
One. OptRepl ::= ;
Some. OptRepl ::= "^" ATerm ;
Cont. CSession ::= "." Term1 ;
Done. CSession ::= ;
NoNewSig. NewSig ::= ;
NewTypeSig. NewSig ::= ":*" Term ;
NewSessSig. NewSig ::= ":" Term ;
TenNewPatt. NewPatt ::= "[" [CPatt] "]" ;
SeqNewPatt. NewPatt ::= "[:" [CPatt] ":]" ;
CntNewPatt. NewPatt ::= "(" Name NewSig ")" ;
New. NewAlloc ::= "new" NewPatt ;
NewSAnn. NewAlloc ::= "new/" "(" Term OptSig ")" NewPatt ;
NewNAnn. NewAlloc ::= NewName NewPatt ;