]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/bin/recomm/recommLexer.mll
update in ground
[helm.git] / matita / matita / contribs / lambdadelta / bin / recomm / recommLexer.mll
1 {
2   module EP = RecommParser
3
4   let debug = ref false
5
6   let keys = [|
7     "Note";
8   |]
9
10   let heads = [|
11     "Advanced";
12     "Basic";
13     "Constructions";
14     "Forward";
15     "Destructions";
16     "Eliminations";
17     "Eliminators";
18     "Equalities";
19     "Helper";
20     "Inversion";
21     "Inversions";
22     "Iterators";
23     "Main";
24     "Properties";
25   |]
26
27   let str c = String.make 1 c
28
29   let nl lexbuf = Lexing.new_line lexbuf
30
31   let is_uppercase_ascii s =
32     let rec aux i =
33        if i < 0 then true else
34        if 'a' <= s.[i] && s.[i] <= 'z' then false else
35        aux (pred i)  
36     in
37     aux (String.length s - 1)
38
39   let disambiguate_word s =
40     if is_uppercase_ascii s then EP.CW s else
41     if Array.mem s keys then EP.KW s else
42     if Array.mem s heads then EP.HW s else
43     EP.SW s
44
45   let log s =
46     if !debug then Printf.eprintf "lezer: %s\n" s
47
48   let log_s s =
49     if !debug then Printf.eprintf "lexer: %S\n" s
50
51   let log_c c =
52     if !debug then Printf.eprintf "lexer: %C\n" c
53 }
54
55 let CR = "\r"
56 let SP = " "
57 let NL = "\n"
58 let SR = "*"
59 let OP = "(*"
60 let CP = SR* "*)"  
61 let PP = CP SP* OP
62 let WF = ['A'-'Z' 'a'-'z']
63 let WB = ['A'-'Z' 'a'-'z' '_' '-']*
64 let WD = WF WB
65
66 rule src_token = parse
67   | CR       { src_token lexbuf                   } 
68   | NL  as c { log "NL"; nl lexbuf; EP.NL (str c) }
69   | SP+ as s { log "SP"; EP.SP s                  }
70   | PP  as s { log "PP"; EP.PP s                  }
71   | OP  as s { log "OP"; EP.OP s                  }
72   | CP  as s { log "CP"; EP.CP s                  }
73   | SR  as c { log "SR"; EP.SR (str c)            }
74   | WD  as s { log_s s ; disambiguate_word s      }
75   | _   as c { log_c c ; EP.OT (str c)            }
76   | eof      { log "EF"; EP.EF                    }