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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
open Lexeme;;
open LutErrors
open Parsing;;
open LutParser;;
open LutLexer;;
open Syntaxe;;
open Format;;
let lexemize_lut infile = (
let inchannel =
Lexeme.set_current_file infile;
open_in infile
in
let lexbuf = Lexing.from_channel inchannel in
let tk = ref (LutLexer.lexer lexbuf) in (
while !tk <> TK_EOF do
match (token_code !tk) with
( co , lxm) -> (
printf "file %s line %3d col %2d to %2d : %15s = \"%s\"\n"
lxm.file lxm.line lxm.cstart lxm.cend co lxm.str ;
);
tk := (LutLexer.lexer lexbuf)
done
);
close_in inchannel
)
let read_lut_res = Hashtbl.create 1
let reinit_parser () = Hashtbl.clear read_lut_res
let rec read_lut files =
try Hashtbl.find read_lut_res files
with Not_found ->
let res = aux ([],Syntaxe.empty_package()) files in
Hashtbl.add read_lut_res files res;
res
and
aux (handled,pack) files =
match files with
| [] -> pack
| infile::rest ->
let infile = if Filename.is_relative infile then
Filename.concat (Sys.getcwd()) infile
else
infile
in
if List.mem infile handled then
aux (handled,pack) rest
else
let cpack =
if (Verbose.level ()) > 0 then (
Printf.eprintf "Opening file %s \n" infile;
flush stderr
);
let inchannel =
Lexeme.set_current_file infile;
open_in infile
in
let lexbuf = Lexing.from_channel inchannel in
try LutParser.lutFileTop LutLexer.lexer lexbuf
with Parse_error -> (
print_compile_error (Lexeme.last_made ()) "syntax error";
exit 1
)
in
let pack = union cpack pack in
aux (infile::handled, pack) (cpack.pck_included_files_to_handle@rest)