annotate src/urweb.lex @ 1808:90ebfac7e1a3

Better error message for funky command lines
author Adam Chlipala <adam@chlipala.net>
date Sat, 18 Aug 2012 13:51:41 -0400
parents 818d4097e2ed
children 146ec8e90063
rev   line source
adamc@763 1 (* -*- mode: sml-lex -*- *)
adamc@763 2
adamc@763 3 (* Copyright (c) 2008-2009, Adam Chlipala
adamc@1 4 * All rights reserved.
adamc@1 5 *
adamc@1 6 * Redistribution and use in source and binary forms, with or without
adamc@1 7 * modification, are permitted provided that the following conditions are met:
adamc@1 8 *
adamc@1 9 * - Redistributions of source code must retain the above copyright notice,
adamc@1 10 * this list of conditions and the following disclaimer.
adamc@1 11 * - Redistributions in binary form must reproduce the above copyright notice,
adamc@1 12 * this list of conditions and the following disclaimer in the documentation
adamc@1 13 * and/or other materials provided with the distribution.
adamc@1 14 * - The names of contributors may not be used to endorse or promote products
adamc@1 15 * derived from this software without specific prior written permission.
adamc@1 16 *
adamc@1 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
adamc@1 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
adamc@1 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
adamc@1 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
adamc@1 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
adamc@1 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
adamc@1 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
adamc@1 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
adamc@1 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
adamc@1 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
adamc@1 27 * POSSIBILITY OF SUCH DAMAGE.
adamc@1 28 *)
adamc@1 29
adamc@244 30 (* Lexing info for Ur/Web programs *)
adamc@1 31
adamc@1 32 type pos = int
adamc@1 33 type svalue = Tokens.svalue
adamc@1 34 type ('a,'b) token = ('a,'b) Tokens.token
adamc@1 35 type lexresult = (svalue,pos) Tokens.token
adamc@1 36
adam@1283 37 val commentOut = ref (fn () => ())
adam@1283 38
adamc@1 39 local
adamc@1 40 val commentLevel = ref 0
adamc@1 41 val commentPos = ref 0
adamc@1 42 in
adam@1741 43 fun reset () =
adam@1741 44 (commentLevel := 0;
adam@1741 45 commentPos := 0)
adam@1741 46
adamc@1 47 fun enterComment pos =
adamc@1 48 (if !commentLevel = 0 then
adamc@1 49 commentPos := pos
adamc@1 50 else
adamc@1 51 ();
adamc@1 52 commentLevel := !commentLevel + 1)
adamc@1 53
adamc@1 54 fun exitComment () =
adamc@1 55 (ignore (commentLevel := !commentLevel - 1);
adam@1283 56 if !commentLevel = 0 then
adam@1283 57 !commentOut ()
adam@1283 58 else
adam@1283 59 ())
adamc@1 60
adamc@1 61 fun eof () =
adamc@1 62 let
adamc@1 63 val pos = ErrorMsg.lastLineStart ()
adamc@1 64 in
adamc@1 65 if !commentLevel > 0 then
adamc@1 66 ErrorMsg.errorAt' (!commentPos, !commentPos) "Unterminated comment"
adamc@1 67 else
adamc@1 68 ();
adamc@1 69 Tokens.EOF (pos, pos)
adamc@1 70 end
adamc@1 71 end
adamc@1 72
adamc@229 73 val strEnder = ref #"\""
adamc@14 74 val str = ref ([] : char list)
adamc@14 75 val strStart = ref 0
adamc@14 76
adamc@54 77 local
adamc@54 78 val initSig = ref false
adamc@54 79 val offset = ref 0
adamc@54 80 in
adamc@54 81
adamc@54 82 fun initialSig () = initSig := true
adamc@54 83
adamc@54 84 fun pos yypos = yypos - !offset
adamc@54 85
adamc@54 86 fun newline yypos =
adamc@54 87 if !initSig then
adamc@54 88 (initSig := false;
adamc@54 89 offset := yypos + 1)
adamc@54 90 else
adamc@54 91 ErrorMsg.newline (pos yypos)
adamc@54 92
adamc@54 93 end
adamc@54 94
adamc@91 95 val xmlTag = ref ([] : string list)
adamc@91 96 val xmlString = ref true
adamc@91 97 val braceLevels = ref ([] : ((unit -> unit) * int) list)
adamc@91 98
adamc@91 99 fun pushLevel s = braceLevels := (s, 1) :: (!braceLevels)
adamc@91 100
adamc@91 101 fun enterBrace () =
adamc@91 102 case !braceLevels of
adamc@91 103 (s, i) :: rest => braceLevels := (s, i+1) :: rest
adamc@91 104 | _ => ()
adamc@91 105
adamc@91 106 fun exitBrace () =
adamc@91 107 case !braceLevels of
adamc@91 108 (s, i) :: rest =>
adamc@91 109 if i = 1 then
adamc@91 110 (braceLevels := rest;
adamc@91 111 s ())
adamc@91 112 else
adamc@91 113 braceLevels := (s, i-1) :: rest
adamc@91 114 | _ => ()
adamc@91 115
adam@1741 116 fun initialize () = (reset ();
adam@1741 117 xmlTag := [];
adamc@91 118 xmlString := false)
adamc@91 119
adamc@54 120
adam@1592 121 structure StringMap = BinaryMapFn(struct
adam@1592 122 type ord_key = string
adam@1592 123 val compare = String.compare
adam@1592 124 end)
adam@1592 125
adam@1592 126 val entities = foldl (fn ((key, value), entities) => StringMap.insert (entities, key, value))
adam@1592 127 StringMap.empty Entities.all
adam@1592 128
adamc@763 129 fun unescape loc s =
adamc@763 130 let
adamc@763 131 fun process (s, acc) =
adamc@763 132 let
adamc@763 133 val (befor, after) = Substring.splitl (fn ch => ch <> #"&") s
adamc@763 134 in
adamc@763 135 if Substring.size after = 0 then
adamc@763 136 Substring.concat (rev (s :: acc))
adamc@763 137 else
adamc@763 138 let
adamc@763 139 val after = Substring.slice (after, 1, NONE)
adamc@763 140 val (befor', after') = Substring.splitl (fn ch => ch <> #";") after
adamc@763 141 in
adamc@763 142 if Substring.size after' = 0 then
adamc@763 143 (ErrorMsg.errorAt' loc "Missing ';' after '&'";
adamc@763 144 "")
adamc@763 145 else
adamc@763 146 let
adamc@763 147 val pre = befor
adamc@763 148 val code = befor'
adamc@763 149 val s = Substring.slice (after', 1, NONE)
adamc@763 150
adamc@763 151 val special =
adamc@763 152 if Substring.size code > 0 andalso Substring.sub (code, 0) = #"#"
adamc@763 153 andalso CharVectorSlice.all Char.isDigit (Substring.slice (code, 1, NONE)) then
adamc@763 154 let
adamc@763 155 val code = Substring.string (Substring.slice (code, 1, NONE))
adamc@763 156 in
adam@1592 157 Option.map Utf8.encode (Int.fromString code)
adamc@763 158 end
adam@1592 159 else
adam@1592 160 Option.map Utf8.encode (StringMap.find (entities, Substring.string code))
adamc@763 161 in
adamc@763 162 case special of
adamc@763 163 NONE => (ErrorMsg.errorAt' loc ("Unsupported XML character entity "
adamc@763 164 ^ Substring.string code);
adamc@763 165 "")
adam@1592 166 | SOME sp => process (s, Substring.full sp :: pre :: acc)
adamc@763 167 end
adamc@763 168 end
adamc@763 169 end
adamc@763 170 in
adamc@763 171 process (Substring.full s, [])
adamc@763 172 end
adamc@763 173
adamc@1 174 %%
adamc@244 175 %header (functor UrwebLexFn(structure Tokens : Urweb_TOKENS));
adamc@1 176 %full
adamc@821 177 %s COMMENT STRING CHAR XML XMLTAG;
adamc@1 178
adamc@48 179 id = [a-z_][A-Za-z0-9_']*;
adamc@316 180 cid = [A-Z][A-Za-z0-9_]*;
adam@1432 181 ws = [\ \t\012\r];
adamc@14 182 intconst = [0-9]+;
adamc@14 183 realconst = [0-9]+\.[0-9]*;
adam@1366 184 notags = ([^<{\n(]|(\([^\*<{\n]))+;
adam@1285 185 xcom = ([^\-]|(-[^\-]))+;
adamc@1098 186 oint = [0-9][0-9][0-9];
adamc@1098 187 xint = x[0-9a-fA-F][0-9a-fA-F];
adamc@1 188
adamc@1 189 %%
adamc@1 190
adam@1283 191 <INITIAL,COMMENT,XMLTAG>
adam@1283 192 \n => (newline yypos;
adamc@91 193 continue ());
adamc@91 194 <XML> \n => (newline yypos;
adamc@91 195 Tokens.NOTAGS (yytext, yypos, yypos + size yytext));
adamc@1 196
adamc@1 197 <INITIAL> {ws}+ => (lex ());
adamc@1 198
adamc@1 199 <INITIAL> "(*" => (YYBEGIN COMMENT;
adam@1283 200 commentOut := (fn () => YYBEGIN INITIAL);
adamc@54 201 enterComment (pos yypos);
adamc@1 202 continue ());
adam@1283 203 <XML> "(*" => (YYBEGIN COMMENT;
adam@1283 204 commentOut := (fn () => YYBEGIN XML);
adam@1283 205 enterComment (pos yypos);
adam@1283 206 continue ());
adam@1283 207 <XMLTAG> "(*" => (YYBEGIN COMMENT;
adam@1283 208 commentOut := (fn () => YYBEGIN XMLTAG);
adam@1283 209 enterComment (pos yypos);
adam@1283 210 continue ());
adam@1283 211 <INITIAL,XML,XMLTAG>
adam@1283 212 "*)" => (ErrorMsg.errorAt' (pos yypos, pos yypos) "Unbalanced comments";
adamc@1 213 continue ());
adamc@1 214
adamc@54 215 <COMMENT> "(*" => (enterComment (pos yypos);
adamc@1 216 continue ());
adam@1283 217 <COMMENT> "*)" => (exitComment ();
adamc@1 218 continue ());
adamc@1 219
adam@1284 220 <XML> "<!--" {xcom} "-->" => (continue ());
adam@1284 221
adamc@838 222 <STRING,CHAR> "\\\"" => (str := #"\"" :: !str; continue());
adamc@838 223 <STRING,CHAR> "\\'" => (str := #"'" :: !str; continue());
adamc@838 224 <STRING,CHAR> "\\n" => (str := #"\n" :: !str; continue());
adamc@1128 225 <STRING,CHAR> "\\\\" => (str := #"\\" :: !str; continue());
adamc@838 226 <STRING,CHAR> "\\t" => (str := #"\t" :: !str; continue());
adamc@838 227 <STRING,CHAR> "\n" => (newline yypos;
adamc@838 228 str := #"\n" :: !str; continue());
adamc@1098 229 <STRING,CHAR> "\\" {oint} => (case StringCvt.scanString (Int.scan StringCvt.OCT)
adamc@1098 230 (String.extract (yytext, 1, NONE)) of
adamc@1098 231 NONE => ErrorMsg.errorAt' (pos yypos, pos yypos) "Illegal string escape"
adamc@1098 232 | SOME n => str := chr n :: !str;
adamc@1098 233 continue());
adamc@1098 234 <STRING,CHAR> "\\" {xint} => (case StringCvt.scanString (Int.scan StringCvt.HEX)
adamc@1098 235 (String.extract (yytext, 2, NONE)) of
adamc@1098 236 NONE => ErrorMsg.errorAt' (pos yypos, pos yypos) "Illegal string escape"
adamc@1098 237 | SOME n => str := chr n :: !str;
adamc@1098 238 continue());
adamc@838 239
adamc@821 240 <INITIAL> "#\"" => (YYBEGIN CHAR; strEnder := #"\""; strStart := pos yypos; str := []; continue());
adamc@838 241
adamc@821 242 <CHAR> . => (let
adamc@821 243 val ch = String.sub (yytext, 0)
adamc@821 244 in
adamc@821 245 if ch = !strEnder then
adamc@821 246 let
adamc@821 247 val s = String.implode (List.rev (!str))
adamc@821 248 in
adamc@821 249 YYBEGIN INITIAL;
adamc@821 250 if size s = 1 then
adamc@821 251 Tokens.CHAR (String.sub (s, 0), !strStart, pos yypos + 1)
adamc@821 252 else
adamc@821 253 (ErrorMsg.errorAt' (yypos, yypos)
adamc@821 254 "Character constant is zero or multiple characters";
adamc@821 255 continue ())
adamc@821 256 end
adamc@821 257 else
adamc@821 258 (str := ch :: !str;
adamc@821 259 continue ())
adamc@821 260 end);
adamc@821 261
adamc@229 262 <INITIAL> "\"" => (YYBEGIN STRING; strEnder := #"\""; strStart := pos yypos; str := []; continue());
adamc@229 263 <INITIAL> "'" => (YYBEGIN STRING; strEnder := #"'"; strStart := pos yypos; str := []; continue());
adamc@838 264
adamc@229 265 <STRING> . => (let
adamc@229 266 val ch = String.sub (yytext, 0)
adamc@229 267 in
adamc@229 268 if ch = !strEnder then
adamc@229 269 (if !xmlString then
adamc@229 270 (xmlString := false; YYBEGIN XMLTAG)
adamc@229 271 else
adamc@229 272 YYBEGIN INITIAL;
adamc@229 273 Tokens.STRING (String.implode (List.rev (!str)), !strStart, pos yypos + 1))
adamc@229 274 else
adamc@229 275 (str := ch :: !str;
adamc@229 276 continue ())
adamc@229 277 end);
adamc@14 278
adamc@360 279 <INITIAL> "<" {id} "/>"=>(let
adamc@360 280 val tag = String.substring (yytext, 1, size yytext - 3)
adamc@360 281 in
adamc@360 282 Tokens.XML_BEGIN_END (tag, yypos, yypos + size yytext)
adamc@360 283 end);
adamc@91 284 <INITIAL> "<" {id} ">"=> (let
adamc@91 285 val tag = String.substring (yytext, 1, size yytext - 2)
adamc@91 286 in
adamc@91 287 YYBEGIN XML;
adamc@91 288 xmlTag := tag :: (!xmlTag);
adamc@91 289 Tokens.XML_BEGIN (tag, yypos, yypos + size yytext)
adamc@91 290 end);
adamc@91 291 <XML> "</" {id} ">" => (let
adamc@91 292 val id = String.substring (yytext, 2, size yytext - 3)
adamc@91 293 in
adamc@91 294 case !xmlTag of
adamc@91 295 id' :: rest =>
adamc@91 296 if id = id' then
adamc@91 297 (YYBEGIN INITIAL;
adamc@91 298 xmlTag := rest;
adamc@91 299 Tokens.XML_END (yypos, yypos + size yytext))
adamc@91 300 else
adamc@91 301 Tokens.END_TAG (id, yypos, yypos + size yytext)
adamc@91 302 | _ =>
adamc@91 303 Tokens.END_TAG (id, yypos, yypos + size yytext)
adamc@91 304 end);
adamc@91 305
adamc@91 306 <XML> "<" {id} => (YYBEGIN XMLTAG;
adamc@91 307 Tokens.BEGIN_TAG (String.extract (yytext, 1, NONE),
adamc@91 308 yypos, yypos + size yytext));
adamc@91 309
adamc@91 310 <XMLTAG> "/" => (Tokens.DIVIDE (yypos, yypos + size yytext));
adamc@91 311 <XMLTAG> ">" => (YYBEGIN XML;
adamc@91 312 Tokens.GT (yypos, yypos + size yytext));
adamc@91 313
adamc@91 314 <XMLTAG> {ws}+ => (lex ());
adamc@91 315
adamc@91 316 <XMLTAG> {id} => (Tokens.SYMBOL (yytext, yypos, yypos + size yytext));
adamc@91 317 <XMLTAG> "=" => (Tokens.EQ (yypos, yypos + size yytext));
adamc@91 318
adamc@91 319 <XMLTAG> {intconst} => (case Int64.fromString yytext of
adamc@91 320 SOME x => Tokens.INT (x, yypos, yypos + size yytext)
adamc@91 321 | NONE => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 322 ("Expected int, received: " ^ yytext);
adamc@91 323 continue ()));
adamc@91 324 <XMLTAG> {realconst} => (case Real.fromString yytext of
adamc@91 325 SOME x => Tokens.FLOAT (x, yypos, yypos + size yytext)
adamc@91 326 | NONE => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 327 ("Expected float, received: " ^ yytext);
adamc@91 328 continue ()));
adamc@91 329 <XMLTAG> "\"" => (YYBEGIN STRING;
adamc@1069 330 xmlString := true; strEnder := #"\"";
adamc@104 331 strStart := yypos; str := []; continue ());
adamc@91 332
adamc@91 333 <XMLTAG> "{" => (YYBEGIN INITIAL;
adamc@91 334 pushLevel (fn () => YYBEGIN XMLTAG);
adamc@91 335 Tokens.LBRACE (yypos, yypos + 1));
adamc@91 336 <XMLTAG> "(" => (YYBEGIN INITIAL;
adamc@91 337 pushLevel (fn () => YYBEGIN XMLTAG);
adamc@91 338 Tokens.LPAREN (yypos, yypos + 1));
adamc@91 339
adamc@91 340 <XMLTAG> . => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 341 ("illegal XML tag character: \"" ^ yytext ^ "\"");
adamc@91 342 continue ());
adamc@91 343
adamc@91 344 <XML> "{" => (YYBEGIN INITIAL;
adamc@91 345 pushLevel (fn () => YYBEGIN XML);
adamc@91 346 Tokens.LBRACE (yypos, yypos + 1));
adamc@91 347
adamc@763 348 <XML> {notags} => (Tokens.NOTAGS (unescape (yypos, yypos + size yytext) yytext, yypos, yypos + size yytext));
adamc@91 349
adam@1366 350 <XML> "(" => (Tokens.NOTAGS ("(", yypos, yypos + size yytext));
adam@1366 351
adamc@91 352 <XML> . => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 353 ("illegal XML character: \"" ^ yytext ^ "\"");
adamc@91 354 continue ());
adamc@91 355
adamc@82 356 <INITIAL> "()" => (Tokens.UNIT (pos yypos, pos yypos + size yytext));
adamc@54 357 <INITIAL> "(" => (Tokens.LPAREN (pos yypos, pos yypos + size yytext));
adamc@54 358 <INITIAL> ")" => (Tokens.RPAREN (pos yypos, pos yypos + size yytext));
adamc@54 359 <INITIAL> "[" => (Tokens.LBRACK (pos yypos, pos yypos + size yytext));
adamc@54 360 <INITIAL> "]" => (Tokens.RBRACK (pos yypos, pos yypos + size yytext));
adamc@110 361 <INITIAL> "{" => (enterBrace ();
adamc@110 362 Tokens.LBRACE (pos yypos, pos yypos + size yytext));
adamc@110 363 <INITIAL> "}" => (exitBrace ();
adamc@110 364 Tokens.RBRACE (pos yypos, pos yypos + size yytext));
adamc@1 365
adamc@623 366 <INITIAL> "-->" => (Tokens.KARROW (pos yypos, pos yypos + size yytext));
adamc@54 367 <INITIAL> "->" => (Tokens.ARROW (pos yypos, pos yypos + size yytext));
adamc@623 368 <INITIAL> "==>" => (Tokens.DKARROW (pos yypos, pos yypos + size yytext));
adamc@54 369 <INITIAL> "=>" => (Tokens.DARROW (pos yypos, pos yypos + size yytext));
adamc@54 370 <INITIAL> "++" => (Tokens.PLUSPLUS (pos yypos, pos yypos + size yytext));
adamc@149 371 <INITIAL> "--" => (Tokens.MINUSMINUS (pos yypos, pos yypos + size yytext));
adamc@493 372 <INITIAL> "---" => (Tokens.MINUSMINUSMINUS (pos yypos, pos yypos + size yytext));
adamc@674 373 <INITIAL> "^" => (Tokens.CARET (pos yypos, pos yypos + size yytext));
adamc@1 374
adamc@842 375 <INITIAL> "&&" => (Tokens.ANDALSO (pos yypos, pos yypos + size yytext));
adamc@842 376 <INITIAL> "||" => (Tokens.ORELSE (pos yypos, pos yypos + size yytext));
adamc@842 377
adamc@54 378 <INITIAL> "=" => (Tokens.EQ (pos yypos, pos yypos + size yytext));
adamc@219 379 <INITIAL> "<>" => (Tokens.NE (pos yypos, pos yypos + size yytext));
adamc@219 380 <INITIAL> "<" => (Tokens.LT (pos yypos, pos yypos + size yytext));
adamc@219 381 <INITIAL> ">" => (Tokens.GT (pos yypos, pos yypos + size yytext));
adamc@219 382 <INITIAL> "<=" => (Tokens.LE (pos yypos, pos yypos + size yytext));
adamc@219 383 <INITIAL> ">=" => (Tokens.GE (pos yypos, pos yypos + size yytext));
adamc@54 384 <INITIAL> "," => (Tokens.COMMA (pos yypos, pos yypos + size yytext));
adam@1306 385 <INITIAL> ":::_" => (Tokens.TCOLONWILD (pos yypos, pos yypos + size yytext));
adamc@54 386 <INITIAL> ":::" => (Tokens.TCOLON (pos yypos, pos yypos + size yytext));
adam@1302 387 <INITIAL> "::_" => (Tokens.DCOLONWILD (pos yypos, pos yypos + size yytext));
adamc@54 388 <INITIAL> "::" => (Tokens.DCOLON (pos yypos, pos yypos + size yytext));
adamc@54 389 <INITIAL> ":" => (Tokens.COLON (pos yypos, pos yypos + size yytext));
adamc@174 390 <INITIAL> "..." => (Tokens.DOTDOTDOT (pos yypos, pos yypos + size yytext));
adamc@54 391 <INITIAL> "." => (Tokens.DOT (pos yypos, pos yypos + size yytext));
adamc@54 392 <INITIAL> "$" => (Tokens.DOLLAR (pos yypos, pos yypos + size yytext));
adamc@54 393 <INITIAL> "#" => (Tokens.HASH (pos yypos, pos yypos + size yytext));
adamc@54 394 <INITIAL> "__" => (Tokens.UNDERUNDER (pos yypos, pos yypos + size yytext));
adamc@54 395 <INITIAL> "_" => (Tokens.UNDER (pos yypos, pos yypos + size yytext));
adamc@84 396 <INITIAL> "~" => (Tokens.TWIDDLE (pos yypos, pos yypos + size yytext));
adamc@156 397 <INITIAL> "|" => (Tokens.BAR (pos yypos, pos yypos + size yytext));
adamc@195 398 <INITIAL> "*" => (Tokens.STAR (pos yypos, pos yypos + size yytext));
adamc@243 399 <INITIAL> "<-" => (Tokens.LARROW (pos yypos, pos yypos + size yytext));
adamc@243 400 <INITIAL> ";" => (Tokens.SEMI (pos yypos, pos yypos + size yytext));
adamc@629 401 <INITIAL> "!" => (Tokens.BANG (pos yypos, pos yypos + size yytext));
adamc@1 402
adamc@389 403 <INITIAL> "+" => (Tokens.PLUS (pos yypos, pos yypos + size yytext));
adamc@389 404 <INITIAL> "-" => (Tokens.MINUS (pos yypos, pos yypos + size yytext));
adamc@389 405 <INITIAL> "/" => (Tokens.DIVIDE (yypos, yypos + size yytext));
adamc@389 406 <INITIAL> "%" => (Tokens.MOD (pos yypos, pos yypos + size yytext));
adamc@403 407 <INITIAL> "@" => (Tokens.AT (pos yypos, pos yypos + size yytext));
adamc@389 408
adamc@54 409 <INITIAL> "con" => (Tokens.CON (pos yypos, pos yypos + size yytext));
adamc@54 410 <INITIAL> "type" => (Tokens.LTYPE (pos yypos, pos yypos + size yytext));
adamc@156 411 <INITIAL> "datatype" => (Tokens.DATATYPE (pos yypos, pos yypos + size yytext));
adamc@156 412 <INITIAL> "of" => (Tokens.OF (pos yypos, pos yypos + size yytext));
adamc@54 413 <INITIAL> "val" => (Tokens.VAL (pos yypos, pos yypos + size yytext));
adamc@123 414 <INITIAL> "rec" => (Tokens.REC (pos yypos, pos yypos + size yytext));
adamc@123 415 <INITIAL> "and" => (Tokens.AND (pos yypos, pos yypos + size yytext));
adamc@242 416 <INITIAL> "fun" => (Tokens.FUN (pos yypos, pos yypos + size yytext));
adamc@54 417 <INITIAL> "fn" => (Tokens.FN (pos yypos, pos yypos + size yytext));
adamc@621 418 <INITIAL> "map" => (Tokens.MAP (pos yypos, pos yypos + size yytext));
adamc@170 419 <INITIAL> "case" => (Tokens.CASE (pos yypos, pos yypos + size yytext));
adamc@190 420 <INITIAL> "if" => (Tokens.IF (pos yypos, pos yypos + size yytext));
adamc@190 421 <INITIAL> "then" => (Tokens.THEN (pos yypos, pos yypos + size yytext));
adamc@190 422 <INITIAL> "else" => (Tokens.ELSE (pos yypos, pos yypos + size yytext));
adamc@1 423
adamc@842 424
adamc@54 425 <INITIAL> "structure" => (Tokens.STRUCTURE (pos yypos, pos yypos + size yytext));
adamc@54 426 <INITIAL> "signature" => (Tokens.SIGNATURE (pos yypos, pos yypos + size yytext));
adamc@54 427 <INITIAL> "struct" => (Tokens.STRUCT (pos yypos, pos yypos + size yytext));
adam@1590 428 <INITIAL> "sig" => (if yypos <= 2 then initialSig () else (); Tokens.SIG (pos yypos, pos yypos + size yytext));
adamc@446 429 <INITIAL> "let" => (Tokens.LET (pos yypos, pos yypos + size yytext));
adamc@446 430 <INITIAL> "in" => (Tokens.IN (pos yypos, pos yypos + size yytext));
adamc@54 431 <INITIAL> "end" => (Tokens.END (pos yypos, pos yypos + size yytext));
adamc@54 432 <INITIAL> "functor" => (Tokens.FUNCTOR (pos yypos, pos yypos + size yytext));
adamc@54 433 <INITIAL> "where" => (Tokens.WHERE (pos yypos, pos yypos + size yytext));
adamc@58 434 <INITIAL> "include" => (Tokens.INCLUDE (pos yypos, pos yypos + size yytext));
adamc@58 435 <INITIAL> "open" => (Tokens.OPEN (pos yypos, pos yypos + size yytext));
adamc@88 436 <INITIAL> "constraint"=> (Tokens.CONSTRAINT (pos yypos, pos yypos + size yytext));
adamc@88 437 <INITIAL> "constraints"=> (Tokens.CONSTRAINTS (pos yypos, pos yypos + size yytext));
adamc@109 438 <INITIAL> "export" => (Tokens.EXPORT (pos yypos, pos yypos + size yytext));
adamc@203 439 <INITIAL> "table" => (Tokens.TABLE (pos yypos, pos yypos + size yytext));
adamc@338 440 <INITIAL> "sequence" => (Tokens.SEQUENCE (pos yypos, pos yypos + size yytext));
adamc@754 441 <INITIAL> "view" => (Tokens.VIEW (pos yypos, pos yypos + size yytext));
adamc@211 442 <INITIAL> "class" => (Tokens.CLASS (pos yypos, pos yypos + size yytext));
adamc@459 443 <INITIAL> "cookie" => (Tokens.COOKIE (pos yypos, pos yypos + size yytext));
adamc@718 444 <INITIAL> "style" => (Tokens.STYLE (pos yypos, pos yypos + size yytext));
adamc@1075 445 <INITIAL> "task" => (Tokens.TASK (pos yypos, pos yypos + size yytext));
adamc@1199 446 <INITIAL> "policy" => (Tokens.POLICY (pos yypos, pos yypos + size yytext));
adamc@30 447
adamc@54 448 <INITIAL> "Type" => (Tokens.TYPE (pos yypos, pos yypos + size yytext));
adamc@54 449 <INITIAL> "Name" => (Tokens.NAME (pos yypos, pos yypos + size yytext));
adamc@82 450 <INITIAL> "Unit" => (Tokens.KUNIT (pos yypos, pos yypos + size yytext));
adamc@1 451
adamc@204 452 <INITIAL> "SELECT" => (Tokens.SELECT (pos yypos, pos yypos + size yytext));
adamc@993 453 <INITIAL> "DISTINCT" => (Tokens.DISTINCT (pos yypos, pos yypos + size yytext));
adamc@204 454 <INITIAL> "FROM" => (Tokens.FROM (pos yypos, pos yypos + size yytext));
adamc@204 455 <INITIAL> "AS" => (Tokens.AS (pos yypos, pos yypos + size yytext));
adamc@209 456 <INITIAL> "WHERE" => (Tokens.CWHERE (pos yypos, pos yypos + size yytext));
adamc@339 457 <INITIAL> "SQL" => (Tokens.SQL (pos yypos, pos yypos + size yytext));
adamc@226 458 <INITIAL> "GROUP" => (Tokens.GROUP (pos yypos, pos yypos + size yytext));
adamc@230 459 <INITIAL> "ORDER" => (Tokens.ORDER (pos yypos, pos yypos + size yytext));
adamc@226 460 <INITIAL> "BY" => (Tokens.BY (pos yypos, pos yypos + size yytext));
adamc@227 461 <INITIAL> "HAVING" => (Tokens.HAVING (pos yypos, pos yypos + size yytext));
adamc@231 462 <INITIAL> "LIMIT" => (Tokens.LIMIT (pos yypos, pos yypos + size yytext));
adamc@231 463 <INITIAL> "OFFSET" => (Tokens.OFFSET (pos yypos, pos yypos + size yytext));
adamc@232 464 <INITIAL> "ALL" => (Tokens.ALL (pos yypos, pos yypos + size yytext));
adamc@1071 465 <INITIAL> "SELECT1" => (Tokens.SELECT1 (pos yypos, pos yypos + size yytext));
adamc@209 466
adamc@749 467 <INITIAL> "JOIN" => (Tokens.JOIN (pos yypos, pos yypos + size yytext));
adamc@749 468 <INITIAL> "INNER" => (Tokens.INNER (pos yypos, pos yypos + size yytext));
adamc@749 469 <INITIAL> "CROSS" => (Tokens.CROSS (pos yypos, pos yypos + size yytext));
adamc@751 470 <INITIAL> "OUTER" => (Tokens.OUTER (pos yypos, pos yypos + size yytext));
adamc@750 471 <INITIAL> "LEFT" => (Tokens.LEFT (pos yypos, pos yypos + size yytext));
adamc@751 472 <INITIAL> "RIGHT" => (Tokens.RIGHT (pos yypos, pos yypos + size yytext));
adamc@751 473 <INITIAL> "FULL" => (Tokens.FULL (pos yypos, pos yypos + size yytext));
adamc@749 474
adamc@229 475 <INITIAL> "UNION" => (Tokens.UNION (pos yypos, pos yypos + size yytext));
adamc@229 476 <INITIAL> "INTERSECT" => (Tokens.INTERSECT (pos yypos, pos yypos + size yytext));
adamc@229 477 <INITIAL> "EXCEPT" => (Tokens.EXCEPT (pos yypos, pos yypos + size yytext));
adamc@229 478
adamc@209 479 <INITIAL> "TRUE" => (Tokens.TRUE (pos yypos, pos yypos + size yytext));
adamc@209 480 <INITIAL> "FALSE" => (Tokens.FALSE (pos yypos, pos yypos + size yytext));
adamc@220 481 <INITIAL> "AND" => (Tokens.CAND (pos yypos, pos yypos + size yytext));
adamc@220 482 <INITIAL> "OR" => (Tokens.OR (pos yypos, pos yypos + size yytext));
adamc@220 483 <INITIAL> "NOT" => (Tokens.NOT (pos yypos, pos yypos + size yytext));
adamc@204 484
adamc@235 485 <INITIAL> "COUNT" => (Tokens.COUNT (pos yypos, pos yypos + size yytext));
adamc@236 486 <INITIAL> "AVG" => (Tokens.AVG (pos yypos, pos yypos + size yytext));
adamc@236 487 <INITIAL> "SUM" => (Tokens.SUM (pos yypos, pos yypos + size yytext));
adamc@236 488 <INITIAL> "MIN" => (Tokens.MIN (pos yypos, pos yypos + size yytext));
adamc@236 489 <INITIAL> "MAX" => (Tokens.MAX (pos yypos, pos yypos + size yytext));
adam@1776 490 <INITIAL> "RANK" => (Tokens.RANK (pos yypos, pos yypos + size yytext));
adam@1778 491 <INITIAL> "PARTITION" => (Tokens.PARTITION (pos yypos, pos yypos + size yytext));
adam@1778 492 <INITIAL> "OVER" => (Tokens.OVER (pos yypos, pos yypos + size yytext));
adamc@235 493
kkallio@1572 494 <INITIAL> "IF" => (Tokens.CIF (pos yypos, pos yypos + size yytext));
kkallio@1572 495 <INITIAL> "THEN" => (Tokens.CTHEN (pos yypos, pos yypos + size yytext));
kkallio@1572 496 <INITIAL> "ELSE" => (Tokens.CELSE (pos yypos, pos yypos + size yytext));
kkallio@1572 497
adamc@268 498 <INITIAL> "ASC" => (Tokens.ASC (pos yypos, pos yypos + size yytext));
adamc@268 499 <INITIAL> "DESC" => (Tokens.DESC (pos yypos, pos yypos + size yytext));
adam@1682 500 <INITIAL> "RANDOM" => (Tokens.RANDOM (pos yypos, pos yypos + size yytext));
adamc@268 501
adamc@302 502 <INITIAL> "INSERT" => (Tokens.INSERT (pos yypos, pos yypos + size yytext));
adamc@302 503 <INITIAL> "INTO" => (Tokens.INTO (pos yypos, pos yypos + size yytext));
adamc@302 504 <INITIAL> "VALUES" => (Tokens.VALUES (pos yypos, pos yypos + size yytext));
adamc@302 505 <INITIAL> "UPDATE" => (Tokens.UPDATE (pos yypos, pos yypos + size yytext));
adamc@302 506 <INITIAL> "SET" => (Tokens.SET (pos yypos, pos yypos + size yytext));
adamc@302 507 <INITIAL> "DELETE" => (Tokens.DELETE (pos yypos, pos yypos + size yytext));
adamc@467 508 <INITIAL> "NULL" => (Tokens.NULL (pos yypos, pos yypos + size yytext));
adamc@470 509 <INITIAL> "IS" => (Tokens.IS (pos yypos, pos yypos + size yytext));
adam@1602 510 <INITIAL> "COALESCE" => (Tokens.COALESCE (pos yypos, pos yypos + size yytext));
kkallio@1607 511 <INITIAL> "LIKE" => (Tokens.LIKE (pos yypos, pos yypos + size yytext));
adamc@302 512
adamc@704 513 <INITIAL> "CONSTRAINT"=> (Tokens.CCONSTRAINT (pos yypos, pos yypos + size yytext));
adamc@704 514 <INITIAL> "UNIQUE" => (Tokens.UNIQUE (pos yypos, pos yypos + size yytext));
adamc@714 515 <INITIAL> "CHECK" => (Tokens.CHECK (pos yypos, pos yypos + size yytext));
adamc@707 516 <INITIAL> "PRIMARY" => (Tokens.PRIMARY (pos yypos, pos yypos + size yytext));
adamc@709 517 <INITIAL> "FOREIGN" => (Tokens.FOREIGN (pos yypos, pos yypos + size yytext));
adamc@707 518 <INITIAL> "KEY" => (Tokens.KEY (pos yypos, pos yypos + size yytext));
adamc@709 519 <INITIAL> "ON" => (Tokens.ON (pos yypos, pos yypos + size yytext));
adamc@709 520 <INITIAL> "NO" => (Tokens.NO (pos yypos, pos yypos + size yytext));
adamc@709 521 <INITIAL> "ACTION" => (Tokens.ACTION (pos yypos, pos yypos + size yytext));
adamc@709 522 <INITIAL> "RESTRICT" => (Tokens.RESTRICT (pos yypos, pos yypos + size yytext));
adamc@709 523 <INITIAL> "CASCADE" => (Tokens.CASCADE (pos yypos, pos yypos + size yytext));
adamc@709 524 <INITIAL> "REFERENCES"=> (Tokens.REFERENCES (pos yypos, pos yypos + size yytext));
adamc@709 525
adamc@709 526 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext));
adamc@704 527
adamc@441 528 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext));
adamc@441 529
adamc@54 530 <INITIAL> {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext));
adamc@54 531 <INITIAL> {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext));
adamc@1 532
adamc@14 533 <INITIAL> {intconst} => (case Int64.fromString yytext of
adamc@120 534 SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext)
adamc@120 535 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos)
adamc@120 536 ("Expected int, received: " ^ yytext);
adamc@120 537 continue ()));
adamc@14 538 <INITIAL> {realconst} => (case Real64.fromString yytext of
adamc@54 539 SOME x => Tokens.FLOAT (x, pos yypos, pos yypos + size yytext)
adamc@54 540 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos)
adamc@14 541 ("Expected float, received: " ^ yytext);
adamc@14 542 continue ()));
adamc@14 543
adamc@1 544 <COMMENT> . => (continue());
adamc@1 545
adamc@54 546 <INITIAL> . => (ErrorMsg.errorAt' (pos yypos, pos yypos)
adamc@1 547 ("illegal character: \"" ^ yytext ^ "\"");
adamc@1 548 continue ());