1 |
|
(* |
2 |
|
* Parser for CM description files. |
3 |
|
* |
4 |
|
* (C) 1999 Lucent Technologies, Bell Laboratories |
5 |
|
* |
6 |
|
* Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp) |
7 |
|
*) |
8 |
signature CMPARSE = sig |
signature CMPARSE = sig |
9 |
val parse : AbsPath.t -> CMSemant.group option |
val parse : AbsPath.t -> CMSemant.group option |
10 |
end |
end |
25 |
structure Lex = CMLex |
structure Lex = CMLex |
26 |
structure LrParser = LrParser) |
structure LrParser = LrParser) |
27 |
|
|
28 |
fun parse filename = let |
fun parse group = let |
29 |
val currentDir = AbsPath.dir filename |
|
30 |
val filename = AbsPath.name filename |
(* recParse returns a group (not an option) |
31 |
|
* and re-raises LrParser.ParseError. |
32 |
|
* This exception will be handled by the surrounding |
33 |
|
* call to parse. |
34 |
|
* This function is used to parse aliases and sub-groups. *) |
35 |
|
fun recParse p = |
36 |
|
case parse p of |
37 |
|
NONE => raise LrParser.ParseError |
38 |
|
| SOME res => res |
39 |
|
|
40 |
|
fun doMember (p, c) = |
41 |
|
CMSemant.member recParse { sourcepath = p, |
42 |
|
group = group, |
43 |
|
class = c } |
44 |
|
|
45 |
|
val currentDir = AbsPath.dir group |
46 |
|
val context = AbsPath.relativeContext (AbsPath.dir group) |
47 |
|
val filename = AbsPath.name group |
48 |
val stream = TextIO.openIn filename |
val stream = TextIO.openIn filename |
49 |
val errcons = |
val errcons = |
50 |
{ linewidth = !P.linewidth, flush = P.flush, consumer = P.say } |
{ linewidth = !P.linewidth, flush = P.flush, consumer = P.say } |
116 |
val (parseResult, _) = |
val (parseResult, _) = |
117 |
CMParse.parse (lookAhead, tokenStream, |
CMParse.parse (lookAhead, tokenStream, |
118 |
fn (s,p1,p2) => error (p1, p2) s, |
fn (s,p1,p2) => error (p1, p2) s, |
119 |
(currentDir, error)) |
(context, error, recParse, doMember)) |
120 |
in |
in |
121 |
TextIO.closeIn stream; |
TextIO.closeIn stream; |
122 |
SOME parseResult |
SOME parseResult |