]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/automath/autLexer.mll
support axioms
[helm.git] / helm / software / lambda-delta / automath / autLexer.mll
index fa385bca44f595275cbeadf78fd39cb302230a26..51f1e7cb92513197a3619e524eab01fe4698884b 100644 (file)
 
 { 
    module L = Log
+   module O = Options
    module P = AutParser
    
    let debug = false
    let out s = if debug then L.warn s else ()
+
+(* This turns an Automath identifier into an XML nmtoken *)
+   let quote id =
+      let l = String.length id in
+      let rec aux i =
+         if i < l then begin
+            if id.[i] = '\'' || id.[i] = '`' then id.[i] <- '_';
+           aux (succ i)
+         end else
+           id
+      in
+      aux 0
 }
 
 let LC  = ['#' '%']
@@ -28,13 +41,12 @@ rule line_comment = parse
    | NL  { () }
    | OC  { block_comment lexbuf; line_comment lexbuf }
    | _   { line_comment lexbuf }
-   | eof  { () } 
+   | eof { () } 
 and block_comment = parse
    | CC  { () }
    | OC  { block_comment lexbuf; block_comment lexbuf }
    | LC  { line_comment lexbuf; block_comment lexbuf  }
    | _   { block_comment lexbuf }
-   | eof { () } 
 and token = parse
    | SPC      { token lexbuf } 
    | LC       { line_comment lexbuf; token lexbuf  }
@@ -54,7 +66,10 @@ and token = parse
    | "'prop'" { out "PROP"; P.PROP   }
    | "TYPE"   { out "TYPE"; P.TYPE   }
    | "'type'" { out "TYPE"; P.TYPE   }
-   | ID       { out "ID"; P.IDENT (Lexing.lexeme lexbuf) }   
+   | ID       { out "ID"; 
+                   let s = Lexing.lexeme lexbuf in
+                   if !O.unquote then P.IDENT s else P.IDENT (quote s)
+              }
    | ":="     { out "DEF"; P.DEF     }
    | "("      { out "OP"; P.OP       }
    | ")"      { out "CP"; P.CP       }