]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/automath/autProcess.ml
update in helena
[helm.git] / helm / software / helena / src / automath / autProcess.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.              
9      \ /   This software is distributed as is, NO WARRANTY.              
10       V_______________________________________________________________ *)
11
12 module A = Aut
13
14 type status = {
15    opening  : bool; (* just opened section *)
16    reopening: bool; (* just reopened section *)
17    closing  : bool; (* just closed section *)
18    explicit : bool; (* just found explicit context *)
19    block    : bool; (* just found block opener *)
20    iao      : int;  (* implicit context after opening section *)
21    iar      : int;  (* implicit context after reopening section *)
22    iac      : int;  (* implicit context after closing section *)
23    iag      : int   (* implicit context after global statement *)
24 }
25
26 (* internal functions *******************************************************)
27
28 IFDEF PREPROCESS THEN
29
30 let orc_reset f st =
31    f {st with opening = false; reopening = false; closing = false}
32
33 let orc_count f st =
34    let st = if st.opening then {st with iao = succ st.iao} else st in
35    let st = if st.reopening then {st with iar = succ st.iar} else st in
36    let st = if st.closing then {st with iac = succ st.iac} else st in
37    f st
38
39 let exp_count f st =
40    let st = 
41       if st.explicit || st.block then st else {st with iag = succ st.iag} 
42    in
43    f st
44
45 let proc_section f st = function
46    | Some (true, _)  -> f {st with opening = true} 
47    | Some (false, _) -> f {st with reopening = true} 
48    | None            -> f {st with closing = true}
49
50 let proc_context f st =
51    orc_reset f {st with explicit = true}
52
53 let proc_block f st =
54    orc_count (orc_reset f) {st with explicit = false; block = true}
55
56 let proc_global f st =
57    let f st = 
58       orc_count (orc_reset f) {st with explicit = false; block = false}
59    in
60    exp_count f st
61
62 let proc_command f st command = match command with
63    | A.Section section -> proc_section f st section command
64    | A.Context _       -> proc_context f st command  
65    | A.Block _         -> proc_block f st command
66    | A.Decl _          -> proc_global f st command
67    | A.Def _           -> proc_global f st command
68
69 END
70
71 (* interface functions ******************************************************)
72
73 let initial_status () = {
74    opening = false; reopening = false; closing = false; 
75    explicit = false; block = false;
76    iao = 0; iar = 0; iac = 0; iag = 0
77 }
78
79 let get_counters f st = f st.iao st.iar st.iac st.iag
80
81 IFDEF PREPROCESS THEN
82
83 let process_command = proc_command
84
85 END