summaryrefslogtreecommitdiff
path: root/src/GF/Source/GF.cf
blob: d6170a6e7976cb6338b86864089a7f9a41570a9a (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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
-- AR 2/5/2003, 14-16 o'clock, Torino

entrypoints Grammar, ModDef, OldGrammar, Exp ; -- let's see if more are needed

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

-- the top-level grammar

Gr. Grammar ::= [ModDef] ;

-- semicolon after module is permitted but not obligatory

terminator ModDef "" ;
_. ModDef ::= ModDef ";" ;

-- The $main$ multilingual grammar structure

MMain. ModDef ::= "grammar" Ident "=" "{" "abstract" "=" Ident ";" [ConcSpec] "}" ;

ConcSpec. ConcSpec ::= Ident "=" ConcExp ;
separator ConcSpec ";" ;

ConcExp. ConcExp ::= Ident [Transfer] ;

separator Transfer "" ;
TransferIn.  Transfer ::= "(" "transfer" "in" Open ")" ;  
TransferOut. Transfer ::= "(" "transfer" "out" Open ")" ;  

-- the individual modules

MModule. ModDef ::= ComplMod ModType "=" ModBody ;

MTAbstract.  ModType ::= "abstract" Ident ;
MTResource.  ModType ::= "resource" Ident ;
MTInterface. ModType ::= "interface" Ident ;
MTConcrete.  ModType ::= "concrete" Ident "of" Ident ;
MTInstance.  ModType ::= "instance" Ident "of" Ident ;
MTTransfer.  ModType ::= "transfer" Ident ":" Open "->" Open ;

MBody.  ModBody ::= Extend Opens "{" [TopDef] "}" ;
MWith.  ModBody ::= Ident "with" [Open] ;
MReuse. ModBody ::= "reuse" Ident ;
MUnion. ModBody ::= "union" [Included] ;

separator TopDef "" ;

Ext.   Extend ::= [Ident] "**" ;
NoExt. Extend ::= ;

separator Open "," ;
NoOpens. Opens ::= ;
Opens.   Opens ::= "open" [Open] "in" ;

OName.   Open ::= Ident ;
OQualQO. Open ::= "(" QualOpen Ident ")" ;
OQual.   Open ::= "(" QualOpen Ident "=" Ident ")" ;

CMCompl.   ComplMod ::= ;
CMIncompl. ComplMod ::= "incomplete" ;

QOCompl.     QualOpen ::= ;
QOIncompl.   QualOpen ::= "incomplete" ;
QOInterface. QualOpen ::= "interface" ;

separator Included "," ;

IAll.  Included ::= Ident ;
ISome. Included ::= Ident "[" [Ident] "]" ;

-- definitions after the $oper$ keywords

DDecl.  Def ::= [Ident] ":" Exp ;
DDef.   Def ::= [Ident] "=" Exp ;
DPatt.  Def ::= Ident [Patt] "=" Exp ;  -- non-empty pattern list
DFull.  Def ::= [Ident] ":" Exp "=" Exp ;

-- top-level definitions

DefCat.    TopDef ::= "cat" [CatDef] ;
DefFun.    TopDef ::= "fun" [FunDef] ;
DefFunData.TopDef ::= "data" [FunDef] ;
DefDef.    TopDef ::= "def" [Def] ;
DefData.   TopDef ::= "data" [DataDef] ;

DefTrans.  TopDef ::= "transfer" [Def] ;

DefPar.    TopDef ::= "param" [ParDef] ;
DefOper.   TopDef ::= "oper"  [Def] ;

DefLincat. TopDef ::= "lincat" [PrintDef] ;
DefLindef. TopDef ::= "lindef" [Def] ;
DefLin.    TopDef ::= "lin"    [Def] ;

DefPrintCat. TopDef ::= "printname" "cat" [PrintDef] ;
DefPrintFun. TopDef ::= "printname" "fun" [PrintDef] ;
DefFlag.     TopDef ::= "flags" [FlagDef] ;

CatDef.    CatDef ::= Ident [DDecl] ;
FunDef.    FunDef ::= [Ident] ":" Exp ;

DataDef.   DataDef    ::= Ident "=" [DataConstr] ;
DataId.    DataConstr ::= Ident ;
DataQId.   DataConstr ::= Ident "." Ident ;
separator DataConstr "|" ;


ParDef.      ParDef ::= Ident "=" [ParConstr] ;
ParDefIndir. ParDef ::= Ident "=" "(" "in" Ident ")" ;
ParDefAbs.   ParDef ::= Ident ;

ParConstr. ParConstr ::= Ident [DDecl] ;

PrintDef. PrintDef ::= [Ident] "=" Exp ;

FlagDef. FlagDef ::= Ident "=" Ident ;

terminator nonempty Def ";" ;
terminator nonempty CatDef ";" ;
terminator nonempty FunDef ";" ;
terminator nonempty DataDef ";" ;
terminator nonempty ParDef ";" ;

terminator nonempty PrintDef ";" ;
terminator nonempty FlagDef ";" ;

separator ParConstr "|" ;

separator nonempty Ident "," ;

-- definitions in records and $let$ expressions

LDDecl.  LocDef ::= [Ident] ":" Exp ;
LDDef.   LocDef ::= [Ident] "=" Exp ;
LDFull.  LocDef ::= [Ident] ":" Exp "=" Exp ;

separator LocDef ";" ;

-- terms and types

EIdent.    Exp4 ::= Ident ;
EConstr.   Exp4 ::= "{" Ident "}" ;
ECons.     Exp4 ::= "[" Ident "]" ;
ESort.     Exp4 ::= Sort ;
EString.   Exp4 ::= String ;
EInt.      Exp4 ::= Integer ;
EMeta.     Exp4 ::= "?" ;
EEmpty.    Exp4 ::= "[" "]" ;
EData.     Exp4 ::= "data" ;
EStrings.  Exp4 ::= "[" String "]" ;
ERecord.   Exp4 ::= "{" [LocDef] "}" ; -- !
ETuple.    Exp4 ::= "<" [TupleComp] ">" ;  --- needed for separator ","
EIndir.    Exp4 ::= "(" "in" Ident ")" ;   -- indirection, used in judgements
ETyped.    Exp4 ::= "<" Exp ":" Exp ">" ;  -- typing, used for annotations

EProj.     Exp3 ::= Exp3 "." Label ;
EQConstr.  Exp3 ::= "{" Ident "." Ident "}" ;  -- qualified constructor
EQCons.    Exp3 ::= "[" Ident "." Ident "]" ;  -- qualified constant

EApp.      Exp2 ::= Exp2 Exp3 ;
ETable.    Exp2 ::= "table" "{" [Case] "}" ;
ETTable.   Exp2 ::= "table" Exp4 "{" [Case] "}" ;
ECase.     Exp2 ::= "case" Exp "of" "{" [Case] "}" ;
EVariants. Exp2 ::= "variants" "{" [Exp] "}" ;
EPre.      Exp2 ::= "pre" "{" Exp ";" [Altern] "}" ;
EStrs.     Exp2 ::= "strs" "{" [Exp] "}" ;
EConAt.    Exp2 ::= Ident "@" Exp4 ;

ESelect.   Exp1 ::= Exp1 "!" Exp2 ;
ETupTyp.   Exp1 ::= Exp1 "*" Exp2 ;
EExtend.   Exp1 ::= Exp1 "**" Exp2 ;

EAbstr.    Exp  ::= "\\" [Bind] "->" Exp ;
ECTable.   Exp  ::= "\\""\\" [Bind] "=>" Exp ;
EProd.     Exp  ::= Decl "->" Exp ;
ETType.    Exp  ::= Exp1 "=>" Exp ; -- these are thus right associative
EConcat.   Exp  ::= Exp1 "++" Exp ;
EGlue.     Exp  ::= Exp1 "+"  Exp ;
ELet.      Exp  ::= "let" "{" [LocDef] "}" "in" Exp ;
ELetb.     Exp  ::= "let" [LocDef] "in" Exp ;
EWhere.    Exp  ::= Exp1 "where" "{" [LocDef] "}" ;
EEqs.      Exp  ::= "fn" "{" [Equation] "}" ;

coercions Exp 4 ;

separator Exp ";" ; -- in variants

-- patterns

PW.    Patt1 ::= "_" ;
PV.    Patt1 ::= Ident ;
PCon.  Patt1 ::= "{" Ident "}" ;
PQ.    Patt1 ::= Ident "." Ident ;
PInt.  Patt1 ::= Integer ;
PStr.  Patt1 ::= String ;
PR.    Patt1 ::= "{" [PattAss] "}" ;
PTup.  Patt1 ::= "<" [PattTupleComp] ">" ;
PC.    Patt  ::= Ident [Patt] ;
PQC.   Patt  ::= Ident "." Ident [Patt] ;

coercions Patt 1 ;

PA.  PattAss ::= [Ident] "=" Patt ;

-- labels

LIdent. Label ::= Ident ;
LVar.   Label ::= "$" Integer ;

-- basic types

rules Sort ::= "Type" | "PType" | "Tok" | "Str" | "Strs" ;

separator PattAss ";" ;

AltP. PattAlt ::= Patt ;

-- this is explicit to force higher precedence level on rhs
(:[]). [Patt] ::= Patt1 ;
(:).   [Patt] ::= Patt1 [Patt] ;

separator nonempty PattAlt "|" ;

-- binds in lambdas and lin rules

BIdent. Bind ::= Ident ;
BWild.  Bind ::= "_" ;

separator Bind "," ;


-- declarations in function types

DDec.  Decl ::= "(" [Bind] ":" Exp ")" ;
DExp.  Decl ::= Exp2 ; -- can thus be an application

-- tuple component (term or pattern)

TComp. TupleComp ::= Exp ;
PTComp. PattTupleComp ::= Patt ;

separator TupleComp "," ;
separator PattTupleComp "," ;

-- case branches

Case. Case ::= [PattAlt] "=>" Exp ;

separator nonempty Case ";" ;

-- cases in abstract syntax

Equ. Equation ::= [Patt] "->" Exp ;

separator Equation ";" ;

-- prefix alternatives

Alt. Altern ::= Exp "/" Exp ;

separator Altern ";" ;

-- in a context, higher precedence is required than in function types

DDDec.  DDecl ::= "(" [Bind] ":" Exp ")" ;
DDExp.  DDecl ::= Exp4 ;  -- can thus *not* be an application

separator DDecl "" ;


--------------------------------------

-- for backward compatibility

OldGr.  OldGrammar ::= Include [TopDef] ;

NoIncl. Include ::= ;
Incl.   Include ::= "include" [FileName] ;

FString. FileName ::= String ;

terminator nonempty FileName ";" ;

FIdent.  FileName ::= Ident ;
FSlash.  FileName ::= "/" FileName ;
FDot.    FileName ::= "." FileName ;
FMinus.  FileName ::= "-" FileName ;
FAddId.  FileName ::= Ident FileName ;

token LString '\'' (char - '\'')* '\'' ;
ELString.  Exp4 ::= LString ;
ELin.      Exp2 ::= "Lin" Ident ;

DefPrintOld.  TopDef ::= "printname" [PrintDef] ;
DefLintype.   TopDef ::= "lintype"   [Def] ;
DefPattern.   TopDef ::= "pattern"   [Def] ;

-- deprecated packages are attempted to be interpreted
DefPackage.   TopDef ::= "package" Ident "=" "{" [TopDef] "}" ";" ;

-- these two are just ignored after parsing
DefVars.      TopDef ::= "var" [Def] ;
DefTokenizer. TopDef ::= "tokenizer" Ident ";" ;