]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/automath/autProcess.ml
c6ef561f0b26c49bf189ff1b984f841b11ced4fb
[helm.git] / helm / software / lambda-delta / 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    iao      : int;  (* implicit context after opening section *)
19    iar      : int;  (* implicit context after reopening section *)
20    iac      : int   (* implicit context after closing section *)
21 }
22
23 (* internal functions *******************************************************)
24
25 let proc_section f st = function
26    | Some (true, _)  -> f {st with opening = true} 
27    | Some (false, _) -> f {st with reopening = true} 
28    | None            -> f {st with closing = true} 
29
30 let proc_context f st =
31    f {st with opening = false; reopening = false; closing = false} 
32
33 let proc_proper 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    proc_context f st
38
39 let proc_item f st item = match item with
40    | A.Section section -> proc_section f st section item
41    | A.Context _       -> proc_context f st item  
42    | _                 -> proc_proper f st item
43
44 (* interface functions ******************************************************)
45
46 let initial_status = {
47    opening = false; reopening = false; closing = false;
48    iao = 0; iar = 0; iac = 0
49 }
50
51 let process_item = proc_item
52
53 let get_counters f st = f st.iao st.iar st.iac