Skip to content
This repository was archived by the owner on Oct 16, 2018. It is now read-only.

Commit 44638c1

Browse files
committed
Refactor parser.mly
1 parent 0445a16 commit 44638c1

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

lib/parser.mly

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ toplevel :
3737

3838
Program :
3939
| Expr SEMISEMI { Exp $1 }
40-
| start=LET x=ID params=list(Param) u=LetTypeAnnot EQ e=Expr SEMISEMI {
40+
| start=LET x=ID params=list(Param) u=Let_type_annot EQ e=Expr SEMISEMI {
4141
let r = join_range start (range_of_exp e) in
4242
let e = match u with None -> e | Some u -> AscExp (range_of_exp e, e, u) in
4343
let e = List.fold_right (fun (x, u) e -> FunExp (r, x.value, u, e)) params e in
4444
LetDecl (x.value, ref [], e)
4545
}
46-
| start=LET REC x=ID params=nonempty_list(Param) u2=LetRecTypeAnnot EQ e=Expr SEMISEMI {
46+
| start=LET REC x=ID params=nonempty_list(Param) u2=Let_rec_type_annot EQ e=Expr SEMISEMI {
4747
let r = join_range start (range_of_exp e) in
4848
match params with
4949
| [] -> LetDecl (x.value, ref [], AscExp (r, e, u2))
@@ -54,13 +54,13 @@ Program :
5454
}
5555

5656
Expr :
57-
| start=LET x=ID params=list(Param) u1=LetTypeAnnot EQ e1=Expr IN e2=Expr {
57+
| start=LET x=ID params=list(Param) u1=Let_type_annot EQ e1=Expr IN e2=Expr {
5858
let r = join_range start (range_of_exp e2) in
5959
let e1 = match u1 with None -> e1 | Some u1 -> AscExp (range_of_exp e1, e1, u1) in
6060
let e1 = List.fold_right (fun (x, u) e -> FunExp (r, x.value, u, e)) params e1 in
6161
LetExp (r, x.value, ref [], e1, e2)
6262
}
63-
| start=LET REC x=ID params=nonempty_list(Param) u2=LetRecTypeAnnot EQ e1=Expr IN e2=Expr {
63+
| start=LET REC x=ID params=nonempty_list(Param) u2=Let_rec_type_annot EQ e1=Expr IN e2=Expr {
6464
let r = join_range start (range_of_exp e2) in
6565
match params with
6666
| [] -> LetExp (r, x.value, ref [], AscExp (r, e1, u2), e2)
@@ -73,43 +73,43 @@ Expr :
7373
let r = join_range start (range_of_exp e) in
7474
List.fold_right (fun (x, u) e -> FunExp (r, x.value, u, e)) params e
7575
}
76-
| SeqExpr { $1 }
76+
| Seq_expr { $1 }
7777

7878
Param :
7979
| x=ID { (x, Typing.fresh_tyvar ()) }
8080
| LPAREN x=ID COLON u=Type RPAREN { (x, u) }
8181

82-
%inline LetTypeAnnot :
82+
%inline Let_type_annot :
8383
| /* empty */ { None }
8484
| COLON u=Type { Some u }
8585

86-
%inline LetRecTypeAnnot :
86+
%inline Let_rec_type_annot :
8787
| /* empty */ { Typing.fresh_tyvar () }
8888
| COLON u2=Type { u2 }
8989

90-
SeqExpr :
91-
| e1=SeqExpr SEMI e2=SeqExpr {
90+
Seq_expr :
91+
| e1=Seq_expr SEMI e2=Seq_expr {
9292
let r = join_range (range_of_exp e1) (range_of_exp e2) in
9393
LetExp (r, "_", ref [], AscExp (range_of_exp e1, e1, TyUnit), e2)
9494
}
95-
| start=IF e1=SeqExpr THEN e2=SeqExpr ELSE e3=SeqExpr %prec prec_if {
95+
| start=IF e1=Seq_expr THEN e2=Seq_expr ELSE e3=Seq_expr %prec prec_if {
9696
let r = join_range start (range_of_exp e3) in
9797
IfExp (r, e1, e2, e3)
9898
}
99-
| e1=SeqExpr op=LOR e2=SeqExpr {
99+
| e1=Seq_expr op=LOR e2=Seq_expr {
100100
let r = join_range (range_of_exp e1) (range_of_exp e2) in
101101
let t, f = BConst (r, true), BConst (r, false) in
102102
IfExp (r, e1, t, IfExp (r, e2, t, f))
103103
}
104-
| e1=SeqExpr op=LAND e2=SeqExpr {
104+
| e1=Seq_expr op=LAND e2=Seq_expr {
105105
let r = join_range (range_of_exp e1) (range_of_exp e2) in
106106
let t, f = BConst (r, true), BConst (r, false) in
107107
IfExp (r, e1, IfExp (r, e2, t, f), f)
108108
}
109-
| e1=SeqExpr op=Op e2=SeqExpr {
109+
| e1=Seq_expr op=Op e2=Seq_expr {
110110
BinOp (join_range (range_of_exp e1) (range_of_exp e2), op, e1, e2)
111111
}
112-
| UnaryExpr { $1 }
112+
| Unary_expr { $1 }
113113

114114
%inline Op :
115115
| PLUS { Plus }
@@ -124,22 +124,22 @@ SeqExpr :
124124
| GT { Gt }
125125
| GTE { Gte }
126126

127-
UnaryExpr :
128-
| PLUS e=UnaryExpr { e }
129-
| start_r=MINUS e=UnaryExpr {
127+
Unary_expr :
128+
| PLUS e=Unary_expr { e }
129+
| start_r=MINUS e=Unary_expr {
130130
let r = join_range start_r (range_of_exp e) in
131131
let zero = IConst (dummy_range, 0) in
132132
BinOp (r, Minus, zero, e)
133133
}
134-
| AppExpr { $1 }
134+
| App_expr { $1 }
135135

136-
AppExpr :
137-
| e1=AppExpr e2=SimpleExpr {
136+
App_expr :
137+
| e1=App_expr e2=Simple_expr {
138138
AppExp (join_range (range_of_exp e1) (range_of_exp e2), e1, e2)
139139
}
140-
| SimpleExpr { $1 }
140+
| Simple_expr { $1 }
141141

142-
SimpleExpr :
142+
Simple_expr :
143143
| i=INTV { IConst (i.range, i.value) }
144144
| r=TRUE { BConst (r, true) }
145145
| r=FALSE { BConst (r, false) }
@@ -153,11 +153,10 @@ SimpleExpr :
153153
| LPAREN e=Expr RPAREN { e }
154154

155155
Type :
156-
| u1=AType RARROW u2=Type { TyFun (u1, u2) }
157-
| AType { $1 }
156+
| u1=Simple_type RARROW u2=Type { TyFun (u1, u2) }
157+
| Simple_type { $1 }
158158

159-
AType :
160-
| LPAREN u=Type RPAREN { u }
159+
Simple_type :
161160
| INT { TyInt }
162161
| BOOL { TyBool }
163162
| UNIT { TyUnit }
@@ -170,3 +169,4 @@ AType :
170169
tyvenv := Environment.add x.value u !tyvenv;
171170
u
172171
}
172+
| LPAREN u=Type RPAREN { u }

0 commit comments

Comments
 (0)