-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrictCParser.ML
45 lines (37 loc) · 1.33 KB
/
StrictCParser.ML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(*
* Copyright 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(NICTA_BSD)
*)
structure StrictCParser =
struct
structure StrictCLrVals = StrictCLrValsFun(structure Token = LrParser.Token)
structure StrictCLex = StrictCLexFun(structure Tokens = StrictCLrVals.Tokens);
structure StrictCParser =
JoinWithArg(structure LrParser = LrParser
structure ParserData = StrictCLrVals.ParserData
structure Lex = StrictCLex)
fun invoke lookahead pi lexstream = let
fun print_error (s,lpos,rpos) = Feedback.errorStr'(lpos,rpos,s)
in
(#1 (StrictCParser.parse(lookahead,lexstream,print_error,pi)), !Feedback.numErrors)
end
fun parse docpp error_lookahead (includes : string list) fname = let
val cpped_fname = docpp {includes=includes,filename=fname}
val istream = TextIO.openIn cpped_fname
val _ = Feedback.numErrors := 0 (* FIXME - global reference *)
val lexarg = StrictCLex.UserDeclarations.new_state fname
val lexer = StrictCParser.makeLexer (fn _ => inputLine istream) lexarg
val pos = #source lexarg
in
invoke error_lookahead pos lexer before
(TextIO.closeIn istream;
if cpped_fname <> fname then
OS.FileSys.remove cpped_fname
else ())
end
end;