Skip to content

Commit 5c75b59

Browse files
committed
Change to eliminate unnecessary EmptyB and EmptyD syntax nodes
1 parent ba3f168 commit 5c75b59

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

parser.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ dec :
201201
| atdec
202202
{ $1 }
203203
| atdec SEMI dec
204-
{ SeqD($1, $3)@@at() }
204+
{ seqD($1, $3)@@at() }
205205
;
206206

207207
dotpathexp :
@@ -378,7 +378,7 @@ bind :
378378
| atbind
379379
{ $1 }
380380
| atbind SEMI bind
381-
{ SeqB($1, $3)@@at() }
381+
{ seqB($1, $3)@@at() }
382382
;
383383

384384
atpat :

syntax.ml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,24 @@ let typParam param =
7979
let typParamList paramList =
8080
List.map typParam paramList
8181

82+
let seqD(l, r) =
83+
match l.it, r.it with
84+
| EmptyD, _ -> r.it
85+
| _, EmptyD -> l.it
86+
| _ -> SeqD(l, r)
87+
88+
let seqB(l, r) =
89+
match l.it, r.it with
90+
| EmptyB, _ -> r.it
91+
| _, EmptyB -> l.it
92+
| _ -> SeqB(l, r)
93+
8294
(* Sugar *)
8395

8496
let letE(b, e) =
8597
let x' = var "let" in
8698
let b2 = VarB(x'@@e.at, e)@@e.at in
87-
DotE(StrE(SeqB(b, b2)@@span[b.at; e.at])@@span[b.at; e.at], x'@@e.at)
99+
DotE(StrE(seqB(b, b2)@@span[b.at; e.at])@@span[b.at; e.at], x'@@e.at)
88100

89101
let letT(b, t) = PathT(letE(b, TypE(t)@@t.at)@@span[b.at; t.at])
90102
let letB(b, b') = InclB(letE(b, StrE(b')@@b'.at)@@span[b.at; b'.at])
@@ -94,15 +106,15 @@ and tupT' n = function
94106
| [] -> EmptyD@@nowhere_region
95107
| t::ts ->
96108
let d = tupT' (n + 1) ts in
97-
SeqD(VarD((index n)@@t.at, t)@@t.at, d)@@
109+
seqD(VarD((index n)@@t.at, t)@@t.at, d)@@
98110
(match d.it with EmptyD -> t.at | _ -> span[t.at; d.at])
99111

100112
let rec tupE(es) = StrE(tupE' 1 es)
101113
and tupE' n = function
102114
| [] -> EmptyB@@nowhere_region
103115
| e::es ->
104116
let b = tupE' (n + 1) es in
105-
SeqB(VarB((index n)@@e.at, e)@@e.at, b)@@
117+
seqB(VarB((index n)@@e.at, e)@@e.at, b)@@
106118
(match b.it with EmptyB -> e.at | _ -> span[e.at; b.at])
107119

108120
let rec funT(ps, t, f) = (funT'(ps, t, f)).it
@@ -138,7 +150,7 @@ let doB(e) = letB(VarB("_"@@e.at, e)@@e.at, EmptyB@@e.at)
138150

139151
let seqE(es) =
140152
let b =
141-
List.fold_right (fun e b -> SeqB(doB(e)@@e.at, b)@@span[e.at; b.at])
153+
List.fold_right (fun e b -> seqB(doB(e)@@e.at, b)@@span[e.at; b.at])
142154
es (EmptyB@@(after (Lib.List.last es).at))
143155
in
144156
doE(StrE(b)@@@(List.map at es))
@@ -172,7 +184,7 @@ let appE(e1, e2) =
172184
let x2' = var "app2" in
173185
let b1 = VarB(x1'@@e1.at, e1)@@e1.at in
174186
let b2 = VarB(x2'@@e2.at, e2)@@e2.at in
175-
let b = SeqB(b1, b2)@@span[e1.at; e2.at] in
187+
let b = seqB(b1, b2)@@span[e1.at; e2.at] in
176188
letE(b, AppE(x1'@@e1.at, x2'@@e2.at)@@span[e1.at; e2.at])
177189

178190
let wrapE(e, t) =
@@ -272,7 +284,7 @@ let asTopt(to1, to2) =
272284
let asP(p1, p2) =
273285
let b1, to1 = p1.it in
274286
let b2, to2 = p2.it in
275-
SeqB(b1.it@@p1.at, b2.it@@p2.at)@@span[p1.at; p2.at], asTopt(to1, to2)
287+
seqB(b1.it@@p1.at, b2.it@@p2.at)@@span[p1.at; p2.at], asTopt(to1, to2)
276288

277289
let annotP(p, t2) =
278290
let b, to1 = p.it in
@@ -299,9 +311,9 @@ let strP(xps, region) =
299311
List.fold_right (fun xp (b, d) ->
300312
let x, p = xp.it in
301313
let _, t = (defaultP p).it in
302-
SeqB(patB(p, DotE(VarE("$"@@xp.at)@@xp.at, x)@@xp.at)@@xp.at, b)
314+
seqB(patB(p, DotE(VarE("$"@@xp.at)@@xp.at, x)@@xp.at)@@xp.at, b)
303315
@@span[b.at; p.at],
304-
SeqD(VarD(x, t.it@@p.at)@@xp.at, d)@@span[d.at; p.at]
316+
seqD(VarD(x, t.it@@p.at)@@xp.at, d)@@span[d.at; p.at]
305317
) xps (EmptyB@@xp.at, EmptyD@@xp.at)
306318
in b, Some (StrT(d)@@d.at)
307319

0 commit comments

Comments
 (0)