]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/src/automath/autLexer.mll
Matitaweb: layout change in the matitaweb inteface, in order to allow better
[helm.git] / helm / software / lambda-delta / src / automath / autLexer.mll
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
13    module L  = Log
14    module G  = Options
15    module AP = AutParser
16    
17    let out s = if !G.debug_lexer then L.warn s else ()
18
19 (* This turns an Automath identifier into an XML nmtoken *)
20    let quote id =
21       let l = String.length id in
22       let rec aux i =
23          if i < l then begin
24             if id.[i] = '\'' || id.[i] = '`' then id.[i] <- '_';
25             aux (succ i)
26          end else
27             id
28       in
29       aux 0
30 }
31
32 let LC  = ['#' '%']
33 let OC  = "{"
34 let CC  = "}"
35 let SPC = [' ' '\t' '\n']+
36 let NL  = "\n"
37 let ID  = ['0'-'9' 'A'-'Z' 'a'-'z' '_' '\'' '`']+
38
39 rule line_comment = parse
40    | NL  { () }
41    | OC  { block_comment lexbuf; line_comment lexbuf }
42    | _   { line_comment lexbuf }
43    | eof { () } 
44 and block_comment = parse
45    | CC  { () }
46    | OC  { block_comment lexbuf; block_comment lexbuf }
47    | LC  { line_comment lexbuf; block_comment lexbuf  }
48    | _   { block_comment lexbuf }
49 and token = parse
50    | SPC      { token lexbuf } 
51    | LC       { line_comment lexbuf; token lexbuf  }
52    | OC       { block_comment lexbuf; token lexbuf }
53    | "_E"     { out "E"; AP.E         }
54    | "'_E'"   { out "E"; AP.E         }
55    | "---"    { out "EB"; AP.EB       }
56    | "'eb'"   { out "EB"; AP.EB       }
57    | "EB"     { out "EB"; AP.EB       }
58    | "--"     { out "EXIT"; AP.EXIT   }
59    | "PN"     { out "PN"; AP.PN       }
60    | "'pn'"   { out "PN"; AP.PN       }
61    | "PRIM"   { out "PN"; AP.PN       }
62    | "'prim'" { out "PN"; AP.PN       }
63    | "???"    { out "PN"; AP.PN       }
64    | "PROP"   { out "PROP"; AP.PROP   }
65    | "'prop'" { out "PROP"; AP.PROP   }
66    | "TYPE"   { out "TYPE"; AP.TYPE   }
67    | "'type'" { out "TYPE"; AP.TYPE   }
68    | ID       { out "ID"; 
69                    let s = Lexing.lexeme lexbuf in
70                    if !G.unquote then AP.IDENT s else AP.IDENT (quote s)
71               }
72    | ":="     { out "DEF"; AP.DEF     }
73    | "("      { out "OP"; AP.OP       }
74    | ")"      { out "CP"; AP.CP       }
75    | "["      { out "OB"; AP.OB       }
76    | "]"      { out "CB"; AP.CB       }
77    | "<"      { out "OA"; AP.OA       }
78    | ">"      { out "CA"; AP.CA       }
79    | "@"      { out "AT"; AP.AT       }
80    | "~"      { out "TD"; AP.TD       }
81    | "\""     { out "QT"; AP.QT       }
82    | ":"      { out "CN"; AP.CN       }   
83    | ","      { out "CM"; AP.CM       }
84    | ";"      { out "SC"; AP.SC       }
85    | "."      { out "FS"; AP.FS       }   
86    | "+"      { out "PLUS"; AP.PLUS   }
87    | "-"      { out "MINUS"; AP.MINUS }
88    | "*"      { out "TIMES"; AP.TIMES }
89    | "="      { out "DEF"; AP.DEF     }
90    | eof      { out "EOF"; AP.EOF     }