6 |
* Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp) |
* Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp) |
7 |
*) |
*) |
8 |
signature CMPARSE = sig |
signature CMPARSE = sig |
9 |
val parse : GeneralParams.param -> AbsPath.t -> CMSemant.group option |
val parse : |
10 |
|
GeneralParams.param -> AbsPath.t |
11 |
|
-> (CMSemant.group * GeneralParams.info) option |
12 |
end |
end |
13 |
|
|
14 |
structure CMParse :> CMPARSE = struct |
structure CMParse :> CMPARSE = struct |
32 |
val groupreg = GroupReg.new () |
val groupreg = GroupReg.new () |
33 |
val ginfo = { param = param, groupreg = groupreg } |
val ginfo = { param = param, groupreg = groupreg } |
34 |
|
|
35 |
val gc = ref AbsPathMap.empty (* the "group cache" *) |
(* The "group cache" -- we store "group options"; having |
36 |
|
* NONE registered for a group means that a previous attempt |
37 |
|
* to parse it had failed. *) |
38 |
|
val gc = ref (AbsPathMap.empty: CMSemant.group option AbsPathMap.map) |
39 |
|
|
40 |
fun mparse (group, groupstack) = |
fun mparse (group, groupstack) = |
41 |
case AbsPathMap.find (!gc, group) of |
case AbsPathMap.find (!gc, group) of |
118 |
{ sourcepath = p, class = c, |
{ sourcepath = p, class = c, |
119 |
group = (group, (p1, p2)) } |
group = (group, (p1, p2)) } |
120 |
|
|
121 |
|
(* Build the argument for the lexer; the lexer's local |
122 |
|
* state is encapsulated here to make sure the parser |
123 |
|
* is re-entrant. *) |
124 |
val lexarg = let |
val lexarg = let |
125 |
(* local state *) |
(* local state *) |
126 |
val depth = ref 0 |
val depth = ref 0 |
202 |
| [] => normal_processing () |
| [] => normal_processing () |
203 |
end |
end |
204 |
|
|
205 |
|
fun finalResult g = |
206 |
|
(SmlInfo.forgetAllBut (Reachable.reachable g); |
207 |
|
(g, ginfo)) |
208 |
in |
in |
209 |
mparse (group, []) |
Option.map finalResult (mparse (group, [])) |
210 |
end |
end |
211 |
end |
end |