1 (* Copyright (C) 2000, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
32 let strip s = String.sub s 1 (pred (String.length s))
36 let out s = if debug then prerr_endline s
39 let SPC = [' ' '\t' '\n']+
40 let ALPHA = ['A'-'Z' 'a'-'z' '_']
42 let IDEN = ALPHA (NUM | ALPHA)*
43 let QSTR = [^ '"' '\\']+
44 let Q = ['\\' '^' '\"']
45 let NQ = [^ '\\' '^' '\"']
47 rule comm_token = parse
48 | "(*" { comm_token lexbuf; comm_token lexbuf }
50 | ['*' '('] { comm_token lexbuf }
51 | [^ '*' '(']* { comm_token lexbuf }
52 and string_token = parse
54 | '\\' Q '^' { STR (String.sub (Lexing.lexeme lexbuf) 1 1) }
55 | '\\' NQ '^' { STR (Lexing.lexeme lexbuf) }
56 | QSTR { STR (Lexing.lexeme lexbuf) }
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 | "if" { out "IF" ; IF }
96 | "in" { out "IN" ; IN }
97 | "inf" { out "INF" ; INF }
98 | "intersect" { out "INTER" ; INTER }
99 | "inverse" { out "INV" ; INV }
100 | "istrue" { out "IST" ; IST }
101 | "isfalse" { out "ISF" ; ISF }
102 | "keep" { out "KEEP" ; KEEP }
103 | "le" { out "LE" ; LE }
104 | "let" { out "LET" ; LET }
105 | "log" { out "LOG" ; LOG }
106 | "lt" { out "LT" ; LT }
107 | "main" { out "MAIN" ; MAIN }
108 | "match" { out "MATCH" ; MATCH }
109 | "meet" { out "MEET" ; MEET }
110 | "not" { out "NOT" ; NOT }
111 | "of" { out "OF" ; OF }
112 | "or" { out "OR" ; OR }
113 | "pattern" { out "PAT" ; PAT }
114 | "peek" { out "PEEK" ; PEEK }
115 | "proj" { out "PROJ" ; PROJ }
116 | "property" { out "PROP" ; PROP }
117 | "read" { out "READ" ; READ }
118 | "render" { out "RENDER"; RENDER }
119 | "select" { out "SELECT"; SELECT }
120 | "seq" { out "SEQ" ; SEQ }
121 | "source" { out "SOURCE"; SOURCE }
122 | "stat" { out "STAT" ; STAT }
123 | "sub" { out "SUB" ; SUB }
124 | "sup" { out "SUP" ; SUP }
125 | "super" { out "SUPER" ; SUPER }
126 | "then" { out "THEN" ; THEN }
127 | "true" { out "TRUE" ; TRUE }
128 | "union" { out "UNION" ; UNION }
129 | "where" { out "WHERE" ; WHERE }
130 | "xor" { out "XOR" ; XOR }
131 | eof { out "EOF" ; EOF }
132 | "=" { out "BE" ; BE }
133 | "#" { out "COUNT" ; COUNT }
134 | "!" { out "NOT" ; NOT }
135 | "<" { out "LT" ; LT }
136 | "<=" { out "LE" ; LE }
137 | "==" { out "EQ" ; EQ }
138 | "&&" { out "AND" ; AND }
139 | "||" { out "OR" ; OR }
140 | "\\/" { out "UNION" ; UNION }
141 | "/\\" { out "INTER" ; INTER }
142 | ";;" { out "SEQ" ; SEQ }
143 | "begin" { out "LP" ; LP }
144 | "end" { out "RP" ; RP }
145 and result_token = parse
146 | SPC { result_token lexbuf }
147 | "(*" { comm_token lexbuf; result_token lexbuf }
148 | '"' { let str = qstr string_token lexbuf in
149 out ("STR " ^ str); STR str }
150 | '/' { out "SL" ; SL }
151 | '{' { out "LC" ; LC }
152 | '}' { out "RC" ; RC }
153 | ',' { out "CM" ; CM }
154 | ';' { out "SC" ; SC }
155 | '=' { out "BE" ; BE }
156 | "attr" { out "ATTR"; ATTR }
157 | eof { out "EOF" ; EOF }