]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql_interpreter/mQueryTLexer.mll
patched and new Gen constructor added
[helm.git] / helm / ocaml / mathql_interpreter / mQueryTLexer.mll
1 (* Copyright (C) 2000, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
27  *)
28
29
30    open MQueryTParser
31    
32    let strip s = String.sub s 1 (pred (String.length s))
33    
34    let debug = false
35    
36    let out s = if debug then prerr_endline s
37 }
38
39 let SPC   = [' ' '\t' '\n']+
40 let ALPHA = ['A'-'Z' 'a'-'z' '_']
41 let NUM   = ['0'-'9']
42 let IDEN  = ALPHA (NUM | ALPHA)*
43 let QSTR  = [^ '"' '\\']+
44 let Q     = ['\\' '^' '\"']  
45 let NQ    = [^ '\\' '^' '\"']  
46
47 rule comm_token = parse
48    | "(*"         { comm_token lexbuf; comm_token lexbuf }
49    | "*)"         { () }
50    | ['*' '(']    { comm_token lexbuf }
51    | [^ '*' '(']* { comm_token lexbuf }  
52 and string_token = parse
53    | '"'         { DQ  }
54    | '\\' Q '^'  { STR (String.sub (Lexing.lexeme lexbuf) 1 1) }
55    | '\\' NQ '^' { STR (Lexing.lexeme lexbuf) }
56    | QSTR        { STR (Lexing.lexeme lexbuf) }
57    | eof         { EOF }
58 and query_token = parse
59    | "(*"        { comm_token lexbuf; query_token lexbuf }
60    | SPC         { query_token lexbuf }
61    | '"'         { let str = qstr string_token lexbuf in
62                    out ("STR " ^ str); STR str }
63    | '('         { out "LP"; LP }
64    | ')'         { out "RP"; RP }
65    | '['         { out "LB"; LB }
66    | ']'         { out "RB"; RB }
67    | '{'         { out "LC"; LC }
68    | '}'         { out "RC"; RC }
69    | '.'         { out "FS"; FS }
70    | ','         { out "CM"; CM }
71    | ';'         { out "SC"; SC }
72    | '/'         { out "SL"; SL }
73    | ';'         { out "SC"; SC }
74    | "@" IDEN    { let id = Lexing.lexeme lexbuf in 
75                    out ("AVAR " ^ id); AVAR (strip id) }
76    | "$" IDEN    { let id = Lexing.lexeme lexbuf in 
77                    out ("SVAR " ^ id); SVAR (strip id) } 
78    | "add"       { out "ADD"   ; ADD    }
79    | "align"     { out "ALIGN" ; ALIGN  }
80    | "allbut"    { out "BUT"   ; BUT    }
81    | "and"       { out "AND"   ; AND    }
82    | "as"        { out "AS"    ; AS     }
83    | "attr"      { out "ATTR"  ; ATTR   }
84    | "be"        { out "BE"    ; BE     }
85    | "count"     { out "COUNT" ; COUNT  }
86    | "diff"      { out "DIFF"  ; DIFF   }
87    | "distr"     { out "DISTR" ; DISTR  }
88    | "else"      { out "ELSE"  ; ELSE   }
89    | "empty"     { out "EMPTY" ; EMPTY  }
90    | "eq"        { out "EQ"    ; EQ     }
91    | "ex"        { out "EX"    ; EX     }
92    | "false"     { out "FALSE" ; FALSE  }
93    | "for"       { out "FOR"   ; FOR    }
94    | "from"      { out "FROM"  ; FROM   }
95    | "gen"       { out "GEN"   ; GEN    }
96    | "if"        { out "IF"    ; IF     }
97    | "in"        { out "IN"    ; IN     }
98    | "inf"       { out "INF"   ; INF    }   
99    | "intersect" { out "INTER" ; INTER  }
100    | "inverse"   { out "INV"   ; INV    }   
101    | "istrue"    { out "IST"   ; IST    }
102    | "isfalse"   { out "ISF"   ; ISF    }
103    | "keep"      { out "KEEP"  ; KEEP   }
104    | "le"        { out "LE"    ; LE     }
105    | "let"       { out "LET"   ; LET    }
106    | "log"       { out "LOG"   ; LOG    }
107    | "lt"        { out "LT"    ; LT     }
108    | "main"      { out "MAIN"  ; MAIN   }
109    | "match"     { out "MATCH" ; MATCH  }
110    | "meet"      { out "MEET"  ; MEET   }
111    | "not"       { out "NOT"   ; NOT    }
112    | "of"        { out "OF"    ; OF     }
113    | "or"        { out "OR"    ; OR     }
114    | "pattern"   { out "PAT"   ; PAT    }
115    | "peek"      { out "PEEK"  ; PEEK   }
116    | "proj"      { out "PROJ"  ; PROJ   }
117    | "property"  { out "PROP"  ; PROP   }
118    | "read"      { out "READ"  ; READ   }
119    | "render"    { out "RENDER"; RENDER }
120    | "select"    { out "SELECT"; SELECT }
121    | "seq"       { out "SEQ"   ; SEQ    }
122    | "source"    { out "SOURCE"; SOURCE }
123    | "stat"      { out "STAT"  ; STAT   }
124    | "sub"       { out "SUB"   ; SUB    }
125    | "sup"       { out "SUP"   ; SUP    }
126    | "super"     { out "SUPER" ; SUPER  }
127    | "then"      { out "THEN"  ; THEN   }
128    | "true"      { out "TRUE"  ; TRUE   }
129    | "union"     { out "UNION" ; UNION  }
130    | "where"     { out "WHERE" ; WHERE  }
131    | "xor"       { out "XOR"   ; XOR    }
132    | eof         { out "EOF"   ; EOF    }
133    | "="         { out "BE"    ; BE     }
134    | "#"         { out "COUNT" ; COUNT  }
135    | "!"         { out "NOT"   ; NOT    }
136    | "<"         { out "LT"    ; LT     }
137    | "<="        { out "LE"    ; LE     }
138    | "=="        { out "EQ"    ; EQ     }
139    | "&&"        { out "AND"   ; AND    }
140    | "||"        { out "OR"    ; OR     }
141    | "\\/"       { out "UNION" ; UNION  }
142    | "/\\"       { out "INTER" ; INTER  }
143    | ";;"        { out "SEQ"   ; SEQ    }
144    | "begin"     { out "LP"    ; LP     }
145    | "end"       { out "RP"    ; RP     }
146 and result_token = parse
147    | SPC         { result_token lexbuf }
148    | "(*"        { comm_token lexbuf; result_token lexbuf }
149    | '"'         { let str = qstr string_token lexbuf in
150                    out ("STR " ^ str); STR str }
151    | '/'         { out "SL"  ; SL   }
152    | '{'         { out "LC"  ; LC   }
153    | '}'         { out "RC"  ; RC   }
154    | ','         { out "CM"  ; CM   }
155    | ';'         { out "SC"  ; SC   }
156    | '='         { out "BE"  ; BE   }
157    | "attr"      { out "ATTR"; ATTR }
158    | eof         { out "EOF" ; EOF  }