module F = Filename
module P = Printf
+
module U = NUri
module C = Cps
module L = Log
module Y = Time
module G = Options
module H = Hierarchy
-module O = Output
module E = Entity
+module O = Output
module S = Status
module DO = CrgOutput
module TD = TxtCrg
module BO = BrgOutput
module BR = BrgReduction
module BU = BrgUntrusted
+module BG = BrgGrafite
module ZD = BagCrg
module ZO = BagOutput
module ZT = BagType
dc : DO.counters;
bc : BO.counters;
zc : ZO.counters;
+ och: out_channel option;
}
let level = 0
-let bag_error s msg =
- L.error ZO.specs (L.Warn s :: msg)
+let bag_error st s msg =
+ L.error st.kst.S.lenv ZO.specs (L.Warn s :: msg)
-let brg_error s msg =
- L.error BR.specs (L.Warn s :: msg)
+let brg_error st s msg =
+ L.error st.kst.S.lenv BR.specs (L.Warn s :: msg)
let initial_status () = {
kst = S.initial_status ();
dc = DO.initial_counters;
bc = BO.initial_counters;
zc = ZO.initial_counters;
+ och = None;
}
let refresh_status st = {st with
| G.Brg -> BO.print_counters C.start st.bc
| G.Bag -> ZO.print_counters C.start st.zc
-let xlate_entity entity = match !G.kernel, entity with
+let xlate_entity st entity = match !G.kernel, entity with
| G.Brg, CrgEntity e ->
let f e = (BrgEntity e) in E.xlate f BD.brg_of_crg e
| G.Bag, CrgEntity e ->
- let f e = (BagEntity e) in E.xlate f ZD.bag_of_crg e
+ let f e = (BagEntity e) in E.xlate f (ZD.bag_of_crg st.kst.S.lenv) e
| _, entity -> entity
let pp_progress e =
let f _ na u =
let s = U.string_of_uri u in
- let err () = L.warn 2 (P.sprintf "<%s>" s) in
- let f i = L.warn 2 (P.sprintf "[%u] <%s>" i s) in
- E.apix err f na
+ L.warn 2 (P.sprintf "[%u] <%s>" na.E.n_apix s)
in
match e with
| CrgEntity e -> E.common f e
| BagEntity e -> {st with zc = ZO.count_entity C.start st.zc e}
| CrgEntity e -> {st with dc = DO.count_entity C.start st.dc e}
-let export_entity = function
- | CrgEntity e -> XL.export_entity XD.export_term e
- | BrgEntity e -> XL.export_entity BO.export_term e
- | BagEntity e -> XL.export_entity ZO.export_term e
+let export_entity st = function
+ | CrgEntity e -> XL.export_entity (XD.export_term st.kst.S.lenv) e
+ | BrgEntity e -> XL.export_entity (BO.export_term st.kst.S.lenv) e
+ | BagEntity e -> XL.export_entity (ZO.export_term st.kst.S.lenv) e
let type_check st k =
- let brg_err msg = brg_error "Type Error" msg; failwith "Interrupted" in
- let bag_err msg = bag_error "Type Error" msg; failwith "Interrupted" in
+ let brg_err msg = brg_error st "Type Error" msg; failwith "Interrupted" in
+ let bag_err msg = bag_error st "Type Error" msg; failwith "Interrupted" in
let ok _ _ = st in
match k with
| BrgEntity entity -> BU.type_check brg_err ok st.kst entity
| CrgEntity _ -> st
let validate st k =
- let brg_err msg = brg_error "Validation Error" msg; failwith "Interrupted" in
+ let brg_err msg = brg_error st "Validation Error" msg; failwith "Interrupted" in
let ok _ = st in
match k with
- | BrgEntity entity -> BU.validate brg_err ok st.kst entity
+ | BrgEntity entity ->
+ let st = BU.validate brg_err ok st.kst entity in
+ begin match st.och with
+ | None -> st
+ | Some och ->
+ if BG.output_entity st.kst.S.lenv och entity then st
+ else begin L.warn level "Matita exportation stopped"; {st with och = None} end
+ end
| BagEntity _ -> st
| CrgEntity _ -> st
let process_2 st entity =
let st = if !G.summary then count_entity st entity else st in
- if !export then export_entity entity;
+ if !export then export_entity st entity;
if !G.stage >= 3 then
let f = if !version then validate else type_check in
f st entity
let process_1 st entity =
if !G.trace >= 3 then pp_progress entity;
let st = if !G.summary then count_entity st entity else st in
- if !export && !G.stage = 1 then export_entity entity;
- if !G.stage >= 2 then process_2 st (xlate_entity entity) else st
+ if !export && !G.stage = 1 then export_entity st entity;
+ if !G.stage >= 2 then process_2 st (xlate_entity st entity) else st
let process_0 st entity =
let f st entity =
| AutEntity e ->
let err ast = {st with ast = ast} in
let g ast e = process_1 {st with ast = ast} (CrgEntity e) in
- AD.crg_of_aut err g st.ast e
+ AD.crg_of_aut err g st.kst st.ast e
| TxtEntity e ->
let crr tst = {st with tst = tst} in
let d tst e = process_1 {st with tst = tst} (CrgEntity e) in
st, input
let main =
- let version_string = "Helena 0.8.2 M - November 2014" in
- let print_version () = L.warn level (version_string ^ "\n"); exit 0 in
+ let print_version () = L.warn level (G.version_string ^ "\n"); exit 0 in
let set_hierarchy s =
if H.set_graph s then () else
L.warn level (P.sprintf "Unknown type hierarchy: %s" s)
| s -> L.warn level (P.sprintf "Unknown kernel version: %s" s)
in
let set_trace i =
- if !G.trace = 0 && i > 0 then Y.gmtime version_string;
+ if !G.trace = 0 && i > 0 then Y.gmtime G.version_string;
if !G.trace > 0 && i = 0 then Y.utime_stamp "at exit";
G.trace := i;
if i <= 1 then G.summary := false;
let set_preprocess () =
if !G.trace >= 2 then begin preprocess := true; G.summary := true end
in
- let set_stage i = G.stage := i in
- let set_xdir s = G.xdir := s in
- let set_root s = root := s in
let clear_options () =
export := false; preprocess := false;
root := "";
let cover = F.concat !root base_name in
if !G.stage <= 1 then G.kernel := G.Crg;
G.cover := cover;
+ if !G.ma_preamble <> "" then st := {!st with och = Some (BG.open_out base_name)};
let sst, input = process (refresh_status !st) name in
- st := sst;
+ st := begin match sst.och with
+ | None -> sst
+ | Some och -> BG.close_out och; {sst with och = None}
+ end;
if !G.trace >= 2 then Y.utime_stamp "processed";
if !G.summary then begin
AO.print_counters C.start !st.ac;
if !G.trace >= 1 then Y.utime_stamp "at exit"
in
let help =
- "Usage: helena [ -LPVXcdgiopqtx1 | -Ts <number> | -O <dir> | -hkr <string> ]* [ <file> ]*\n\n" ^
- "Trace levels: 0 just errors (default), 1 time stamps, 2 processed files, \
- 3 typing information, 4 reduction information\n\n" ^
+ "Usage: helena [ -LPVXdgilopqtx1 | -Ts <number> | -MO <dir> | -m <file> | -ahkr <string> ]* [ <file> ]*\n\n" ^
+ "Trace levels: 0 just errors (default), 1 time stamps, 2 processed files, 3 typing information,\n" ^
+ " 4 conversion information, 5 reduction information, 6 level disambiguation\n\n" ^
"Stages: 0 parsing, 1 to intermediate, 2 to untrusted, 3 to trusted (default)\n"
in
let help_L = " show lexer debug information" in
+ let help_M = "<dir> set location of output directory (Grafite) to <dir> (default: current directory)" in
let help_O = "<dir> set location of output directory (XML) to <dir> (default: current directory)" in
let help_P = " show parser debug information" in
let help_T = "<number> set trace level (see above)" in
let help_V = " show version information" in
let help_X = " clear options" in
- let help_c = " read/write conversion constraints" in
+ let help_a = "<string> set prefix of numeric identifiers (default: empty)" in
let help_d = " show summary information (requires trace >= 2)" in
let help_g = " always expand global definitions" in
let help_h = "<string> set type hierarchy (default: \"Z1\")" in
let help_i = " show local references by index" in
let help_k = "<string> set kernel version (default: \"brg\")" in
- let help_o = " activate sort inclusion" in
- let help_p = " preprocess source" in
+ let help_l = " disambiguate binders level (Automath)" in
+ let help_m = "<file> export kernel entities (Grafite) setting location of preamble to <file> (default: empty)" in
+ let help_o = " activate sort inclusion (default: false)" in
+ let help_p = " preprocess source (Automath)" in
let help_q = " disable quotation of identifiers" in
let help_r = "<string> set initial segment of URI hierarchy (default: empty)" in
let help_s = "<number> set translation stage (see above)" in
let help_1 = " parse files with streaming policy" in
at_exit exit;
Arg.parse [
- ("-L", Arg.Set G.debug_lexer, help_L);
- ("-O", Arg.String set_xdir, help_O);
- ("-P", Arg.Set G.debug_parser, help_P);
+ ("-L", Arg.Set G.debug_lexer, help_L);
+ ("-M", Arg.String ((:=) G.ma_dir), help_M);
+ ("-O", Arg.String ((:=) G.xdir), help_O);
+ ("-P", Arg.Set G.debug_parser, help_P);
("-T", Arg.Int set_trace, help_T);
("-V", Arg.Unit print_version, help_V);
("-X", Arg.Unit clear_options, help_X);
- ("-c", Arg.Set G.cc, help_c);
+ ("-a", Arg.String ((:=) G.alpha), help_a);
("-d", Arg.Unit set_summary, help_d);
("-g", Arg.Set G.expand, help_g);
("-h", Arg.String set_hierarchy, help_h);
("-i", Arg.Set G.indexes, help_i);
("-k", Arg.String set_kernel, help_k);
+ ("-l", Arg.Set G.cc, help_l);
+ ("-m", Arg.String ((:=) G.ma_preamble), help_m);
("-o", Arg.Set G.si, help_o);
("-p", Arg.Unit set_preprocess, help_p);
("-q", Arg.Set G.unquote, help_q);
- ("-r", Arg.String set_root, help_r);
- ("-s", Arg.Int set_stage, help_s);
+ ("-r", Arg.String ((:=) root), help_r);
+ ("-s", Arg.Int ((:=) G.stage), help_s);
("-t", Arg.Clear version, help_t);
("-x", Arg.Set export, help_x);
("-1", Arg.Set streaming, help_1);