Skip to content
This repository
Newer
Older
100644 60 lines (53 sloc) 2.27 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (*
19 * This file is a standalone parser for the opa syntax
20 * It is meant for debugging/profiling the parser
21 *)
22
23 let show = ref false
24 let show_pos = ref false
25 let stop = ref false
26 let files = ref []
27 let () =
28 Arg.parse
29 ["--show", Arg.Set show, "show the parse tree"
30 ;"--pos", Arg.Set show_pos, "show the positions when printing"
31 ;"--stop", Arg.Set stop, "stop at the first file containing a parse error"]
32 (fun s -> files := s :: !files)
33 (Printf.sprintf "Usage: %s [options] files" Sys.argv.(0))
34
35 let () = OManager.CompilerAsLib.at_exit { OManager.at_exit = fun _ -> raise Exit }
36
37 let () =
38 let code = ref 0 in
39 let printer = if !show_pos then OpaPrint.string_and_pos else OpaPrint.string in
40 let ppenv = Pprocess.fill_with_sysenv Pprocess.empty_env in
41 let ppenv = Pprocess.add_env "OPA_VERSION" "S3" ppenv in
42 let ppopt = Pprocess.default_options ppenv in
43 let process = (Pprocess.process Pplang.opa_description ppopt) in
44 List.iter
45 (fun filename ->
46 match File.content_opt filename with
47 | None -> Printf.printf "%s is not a file, ignoring it\n%!" filename
48 | Some content ->
49 try
50 let content = process content in
51 let ast = OpaParser.code ~cache:false ~filename content in
52 if !show then Format.printf "%s:@\n%a@." filename printer#code ast;
53 Printf.printf "Parsed %s successfully\n%!" filename
54 with
55 | Exit ->
56 (* the error message has been printed already *)
57 incr code;
58 if !stop then exit !code
59 ) (List.rev !files);
60 exit (min 255 !code)
Something went wrong with that request. Please try again.