1 (* Copyright (C) 2009 Matthew Fluet.
2 * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 fun reg (left, right) = Region.make {left = left, right = right}
11 fun error (reg, msg) = Control.error (reg, Layout.str msg, Layout.empty)
15 type fctbinds = {lhs: Fctid.t, rhs: Fctid.t} list
16 type sigbinds = {lhs: Sigid.t, rhs: Sigid.t} list
17 type strbinds = {lhs: Strid.t, rhs: Strid.t} list
19 type basbinds = {name: Basid.t, def: Basexp.t} list
23 ID of string | COMMA | SEMICOLON | EOF
24 | AND | BAS | BASIS | END | EQUALOP | FUNCTOR | IN | LET
25 | LOCAL | OPEN | SIGNATURE | STRUCTURE
26 | ANN | PRIM | FILE of string | STRING of string
29 ann of string * Region.t
30 | annPlus of (string * Region.t) list
31 | annStar of (string * Region.t) list
32 | basbinds of basbinds
33 | basbinds' of Basexp.t * basbinds
34 | basbinds'' of basbinds
36 | basdecnode of Basdec.node
38 | basdecsnode of Basdec.node
40 | basexpnode of Basexp.node
42 | basids of Basid.t list
43 | fctbinds of fctbinds
44 | fctbinds' of Fctid.t * fctbinds
45 | fctbinds'' of fctbinds
47 | id of Symbol.t * Region.t
49 | sigbinds of sigbinds
50 | sigbinds' of Sigid.t * sigbinds
51 | sigbinds'' of sigbinds
53 | strbinds of strbinds
54 | strbinds' of Strid.t * strbinds
55 | strbinds'' of strbinds
63 %header (functor MLBLrValsFun (structure Token: TOKEN
65 val lexAndParseProgOrMLB: File.t * Region.t ->
72 %keyword AND BAS BASIS END FUNCTOR IN LET LOCAL OPEN SIGNATURE STRUCTURE ANN PRIM
74 %change -> SEMICOLON | -> IN ID END
80 mlb : basdecs (basdecs)
83 basdecs : basdecsnode (Basdec.makeRegion'
84 (basdecsnode, basdecsnodeleft, basdecsnoderight))
86 basdecsnode : (Basdec.Seq [])
87 | SEMICOLON basdecs (Basdec.Seq [basdecs])
88 | basdec basdecs (Basdec.Seq [basdec, basdecs])
90 basdec : basdecnode (Basdec.makeRegion'
91 (basdecnode, basdecnodeleft, basdecnoderight))
96 val fctbinds = Vector.fromList fctbinds
98 Basdec.Defs (ModIdBind.makeRegion' (ModIdBind.Fct fctbinds, FUNCTORleft, fctbindsright))
102 val sigbinds = Vector.fromList sigbinds
104 Basdec.Defs (ModIdBind.makeRegion' (ModIdBind.Sig sigbinds, SIGNATUREleft, sigbindsright))
108 val strbinds = Vector.fromList strbinds
110 Basdec.Defs (ModIdBind.makeRegion' (ModIdBind.Str strbinds, STRUCTUREleft, strbindsright))
114 val basbinds = Vector.fromList basbinds
116 Basdec.Basis basbinds
118 | LOCAL basdecs IN basdecs END (Basdec.Local (basdecs1, basdecs2))
119 | OPEN basids (Basdec.Open (Vector.fromList basids))
121 (let val reg = reg (FILEleft, FILEright)
122 in lexAndParseProgOrMLB (FILE, reg)
125 (let val reg = reg (STRINGleft, STRINGright)
126 in lexAndParseProgOrMLB (STRING, reg)
129 | ANN annPlus IN basdecs END
132 let val right = valOf (Region.right (Basdec.region basdecs))
133 in fn reg => Region.extendRight (reg, right)
135 fun mkAnn' ((ann,reg), basdecs) = Basdec.Ann (ann, reg, basdecs)
136 fun mkAnn ((ann,reg), basdecsnode) : Basdec.node =
137 mkAnn' ((ann,reg), Basdec.makeRegion (basdecsnode, extendRight reg))
138 val (anns,ann) = List.splitLast annPlus
140 List.fold(anns, mkAnn'(ann, basdecs), mkAnn)
144 fctbinds : fctid EQUALOP fctbinds'
145 (let val (def, fctbinds) = fctbinds'
146 in {lhs = fctid, rhs = def}
150 ({lhs = fctid, rhs = fctid} :: fctbinds'')
152 fctbinds' : fctid fctbinds'' (fctid, fctbinds'')
155 | AND fctbinds (fctbinds)
157 sigbinds : sigid EQUALOP sigbinds'
158 (let val (def, sigbinds) = sigbinds'
159 in {lhs = sigid, rhs = def}
163 ({lhs = sigid, rhs = sigid} :: sigbinds'')
165 sigbinds' : sigid sigbinds'' (sigid, sigbinds'')
168 | AND sigbinds (sigbinds)
170 strbinds : strid EQUALOP strbinds'
171 (let val (def, strbinds) = strbinds'
172 in {lhs = strid, rhs = def}
176 ({lhs = strid, rhs = strid} :: strbinds'')
178 strbinds' : strid strbinds'' (strid, strbinds'')
181 | AND strbinds (strbinds)
183 basbinds : basid EQUALOP basbinds'
184 (let val (def, basbinds) = basbinds'
185 in {name = basid, def = def}
189 basbinds' : basexp basbinds'' (basexp, basbinds'')
192 | AND basbinds (basbinds)
195 basexp : basexpnode (Basexp.makeRegion'
196 (basexpnode, basexpnodeleft, basexpnoderight))
198 basexpnode : BAS basdecs END (Basexp.Bas basdecs)
199 | basid (Basexp.Var basid)
200 | LET basdecs IN basexp END (Basexp.Let (basdecs, basexp))
202 basid : id (Basid.fromSymbol id)
203 basids : basid ([basid])
204 | basid basids (basid :: basids)
205 fctid : id (Fctid.fromSymbol id)
206 sigid : id (Sigid.fromSymbol id)
207 strid : id (Strid.fromSymbol id)
208 id : ID (Symbol.fromString ID, reg (IDleft, IDright))
211 ann : STRING (STRING, reg (STRINGleft, STRINGright))
213 annPlus : ann annStar (ann::annStar)