-
Notifications
You must be signed in to change notification settings - Fork 165
/
Alfa.cf
149 lines (103 loc) · 3.69 KB
/
Alfa.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
-- layout rules
layout "of", "let", "where", "sig", "struct", "mutual" ;
layout stop "in" ;
layout toplevel ;
-- top level
-- Module. Module ::= "{" [Decl] "}" ;
separator Decl ";" ;
separator Def ";" ;
-- declarations/definitions
DDef. Decl ::= [DefAttr] Def ;
DImp. Decl ::= Import ;
Value. Def ::= AIdent [VarDecl] "::" Exp "=" Exp ;
Binding. Def ::= AIdent "=" Exp ;
Package. Def ::= "package" AIdent [Typing] "where" PackageBody ;
Open. Def ::= "open" Exp "use" [OpenArg] ;
Data. Def ::= "data" AIdent [Typing] "=" [Constructor] ;
Type. Def ::= "type" AIdent [Typing] "=" Exp ;
Axiom. Def ::= "postulate" AIdent [Typing] "::" Exp ;
Mutual. Def ::= "mutual" "{" [Def] "}" ;
Commt. Def ::= Comment ;
-- expressions
EVar. Exp4 ::= AIdent ;
ECon. Exp4 ::= AIdent "@_" ;
ESet. Exp4 ::= "Set" ;
EType. Exp4 ::= "Type" ;
EMeta. Exp4 ::= "?" ;
EStar. Exp4 ::= "#" Integer ;
EMetaU. Exp4 ::= "_" ;
EString. Exp4 ::= String ;
EChar. Exp4 ::= Char ;
EInt. Exp4 ::= Integer ;
EDouble. Exp4 ::= Double ;
EProj. Exp3 ::= Exp3 "." AIdent ;
EApp. Exp1 ::= Exp1 Exp2 ;
EInfix. Exp ::= Exp1 Infix Exp1 ;
ESig. Exp1 ::= "sig" "{" [FieldDecl] "}" ;
EStr. Exp1 ::= "struct" "{" [Binding] "}" ;
ESum. Exp ::= "data" [Constructor] ;
EPi. Exp ::= VarDecl Arrow Exp ;
EFun. Exp ::= Exp1 Arrow Exp ;
EAbs. Exp ::= "\\" VarDecl Arrow Exp ;
EAbsUnt. Exp ::= "\\" [AIdent] Arrow Exp ;
ELet. Exp ::= "let" "{" [Decl] "}" "in" Exp ;
EOpen. Exp ::= "open" Exp "use" [OpenArg] "in" Exp ; ---- "in" does not parse
ECase. Exp ::= "case" Exp "of" "{" [Branch] "}" ;
EIData. Exp ::= "idata" [VarDecl] [IndConstructor] ; --- [Typing]
ECommL. Exp ::= Comment Exp1 ;
ECommR. Exp ::= Exp1 Comment ;
internal EConst. Exp4 ::= AIdent ;
internal EMetaN. Exp4 ::= "?" Integer ;
coercions Exp 4 ;
-- shown/hidden arguments
AShow. Arrow ::= "->" ;
AHide. Arrow ::= "|->" ;
-- typings/hypotheses
TDecl. Typing ::= VarDecl ;
TExp. Typing ::= Exp2 ;
terminator Typing "" ;
VDecl. VarDecl ::= "(" [Bound] "::" Exp ")" ;
BVar. Bound ::= AIdent ;
BHide. Bound ::= "|" AIdent ;
separator nonempty Bound "," ;
terminator VarDecl "" ;
FDecl. FieldDecl ::= AIdent "::" Exp ;
separator FieldDecl ";" ;
-- case branches
BranchCon . Branch ::= "(" AIdent [AIdent] ")" "->" Exp ; --- no deeper patterns?
BranchInf . Branch ::= "(" AIdent Infix AIdent ")" "->" Exp ;
BranchVar . Branch ::= AIdent "->" Exp ;
separator Branch ";" ;
-- constructions in data definitions
Cnstr . Constructor ::= AIdent [Typing] ;
separator Constructor "|" ;
ICnstr . IndConstructor ::= AIdent [Typing] "::" "_" [Exp2] ;
separator IndConstructor "|" ;
terminator Exp2 "" ;
-- bindings in structures
Bind . Binding ::= AIdent "=" Exp ;
separator Binding ";" ;
PackageDef . PackageBody ::= "{" [Decl] "}" ;
PackageInst . PackageBody ::= Exp ;
OArg . OpenArg ::= [DefAttr] AIdent ;
OArgT . OpenArg ::= [DefAttr] AIdent "::" Exp ;
OArgD . OpenArg ::= [DefAttr] AIdent "=" Exp ;
OArgTD. OpenArg ::= [DefAttr] AIdent "::" Exp "=" Exp ;
Private . DefAttr ::= "private" ;
Public . DefAttr ::= "public" ;
Abstract . DefAttr ::= "abstract" ;
Concrete . DefAttr ::= "concrete" ;
Import . Import ::= "import" String ";" ;
separator DefAttr "" ;
separator AIdent "" ;
separator OpenArg "," ;
-- two kinds of comments; preserve enclosed ones
comment "--" ;
comment "{-" "-}" ;
token Comment ('{' '-' ((char - '-') | '-' (char - '}'))* ('-')+ '}') ;
--- identifiers, including infix in parentheses
token Infix ([".:-^*+=<>&%$!#%|/\\"]+) ;
I. AIdent ::= "(" Infix ")" ;
F. AIdent ::= PIdent ;
-- ordinary identifiers now have position
position token PIdent (letter (letter|digit|'_'|'\'')*) ;