Fetching contributors…
Cannot retrieve contributors at this time
60 lines (52 sloc) 2.16 KB
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <>.
* This file is a standalone parser for the opa syntax
* It is meant for debugging/profiling the parser
let show = ref false
let show_pos = ref false
let stop = ref false
let files = ref []
let () =
["--show", Arg.Set show, "show the parse tree"
;"--pos", Arg.Set show_pos, "show the positions when printing"
;"--stop", Arg.Set stop, "stop at the first file containing a parse error"]
(fun s -> files := s :: !files)
(Printf.sprintf "Usage: %s [options] files" Sys.argv.(0))
let () = OManager.CompilerAsLib.at_exit { OManager.at_exit = fun _ -> raise Exit }
let () =
let code = ref 0 in
let printer = if !show_pos then OpaPrint.string_and_pos else OpaPrint.string in
let ppenv = Pprocess.fill_with_sysenv Pprocess.empty_env in
let ppopt = Pprocess.default_options ppenv in
let process = (Pprocess.process Pplang.opa_description ppopt) in
(fun filename ->
match File.content_opt filename with
| None -> Printf.printf "%s is not a file, ignoring it\n%!" filename
| Some content ->
let content = process content in
let ast = OpaParser.code ~cache:false ~filename content in
if !show then Format.printf "%s:@\n%a@." filename printer#code ast;
Printf.printf "Parsed %s successfully\n%!" filename
| Exit ->
(* the error message has been printed already *)
incr code;
if !stop then exit !code
) (List.rev !files);
exit (min 255 !code)