annotate src/urweb.lex @ 1896:adc24ad31fc2

Getting more specific about 'src' in EXTRA_DIST
author Adam Chlipala <adam@chlipala.net>
date Thu, 21 Nov 2013 14:59:33 -0500
parents 146ec8e90063
children 403f0cc65b9c
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_']*;
adam@1840 180 xmlid = [A-Za-z][A-Za-z0-9-_]*;
adamc@316 181 cid = [A-Z][A-Za-z0-9_]*;
adam@1432 182 ws = [\ \t\012\r];
adamc@14 183 intconst = [0-9]+;
adamc@14 184 realconst = [0-9]+\.[0-9]*;
adam@1366 185 notags = ([^<{\n(]|(\([^\*<{\n]))+;
adam@1285 186 xcom = ([^\-]|(-[^\-]))+;
adamc@1098 187 oint = [0-9][0-9][0-9];
adamc@1098 188 xint = x[0-9a-fA-F][0-9a-fA-F];
adamc@1 189
adamc@1 190 %%
adamc@1 191
adam@1283 192 <INITIAL,COMMENT,XMLTAG>
adam@1283 193 \n => (newline yypos;
adamc@91 194 continue ());
adamc@91 195 <XML> \n => (newline yypos;
adamc@91 196 Tokens.NOTAGS (yytext, yypos, yypos + size yytext));
adamc@1 197
adamc@1 198 <INITIAL> {ws}+ => (lex ());
adamc@1 199
adamc@1 200 <INITIAL> "(*" => (YYBEGIN COMMENT;
adam@1283 201 commentOut := (fn () => YYBEGIN INITIAL);
adamc@54 202 enterComment (pos yypos);
adamc@1 203 continue ());
adam@1283 204 <XML> "(*" => (YYBEGIN COMMENT;
adam@1283 205 commentOut := (fn () => YYBEGIN XML);
adam@1283 206 enterComment (pos yypos);
adam@1283 207 continue ());
adam@1283 208 <XMLTAG> "(*" => (YYBEGIN COMMENT;
adam@1283 209 commentOut := (fn () => YYBEGIN XMLTAG);
adam@1283 210 enterComment (pos yypos);
adam@1283 211 continue ());
adam@1283 212 <INITIAL,XML,XMLTAG>
adam@1283 213 "*)" => (ErrorMsg.errorAt' (pos yypos, pos yypos) "Unbalanced comments";
adamc@1 214 continue ());
adamc@1 215
adamc@54 216 <COMMENT> "(*" => (enterComment (pos yypos);
adamc@1 217 continue ());
adam@1283 218 <COMMENT> "*)" => (exitComment ();
adamc@1 219 continue ());
adamc@1 220
adam@1284 221 <XML> "<!--" {xcom} "-->" => (continue ());
adam@1284 222
adamc@838 223 <STRING,CHAR> "\\\"" => (str := #"\"" :: !str; continue());
adamc@838 224 <STRING,CHAR> "\\'" => (str := #"'" :: !str; continue());
adamc@838 225 <STRING,CHAR> "\\n" => (str := #"\n" :: !str; continue());
adamc@1128 226 <STRING,CHAR> "\\\\" => (str := #"\\" :: !str; continue());
adamc@838 227 <STRING,CHAR> "\\t" => (str := #"\t" :: !str; continue());
adamc@838 228 <STRING,CHAR> "\n" => (newline yypos;
adamc@838 229 str := #"\n" :: !str; continue());
adamc@1098 230 <STRING,CHAR> "\\" {oint} => (case StringCvt.scanString (Int.scan StringCvt.OCT)
adamc@1098 231 (String.extract (yytext, 1, NONE)) of
adamc@1098 232 NONE => ErrorMsg.errorAt' (pos yypos, pos yypos) "Illegal string escape"
adamc@1098 233 | SOME n => str := chr n :: !str;
adamc@1098 234 continue());
adamc@1098 235 <STRING,CHAR> "\\" {xint} => (case StringCvt.scanString (Int.scan StringCvt.HEX)
adamc@1098 236 (String.extract (yytext, 2, NONE)) of
adamc@1098 237 NONE => ErrorMsg.errorAt' (pos yypos, pos yypos) "Illegal string escape"
adamc@1098 238 | SOME n => str := chr n :: !str;
adamc@1098 239 continue());
adamc@838 240
adamc@821 241 <INITIAL> "#\"" => (YYBEGIN CHAR; strEnder := #"\""; strStart := pos yypos; str := []; continue());
adamc@838 242
adamc@821 243 <CHAR> . => (let
adamc@821 244 val ch = String.sub (yytext, 0)
adamc@821 245 in
adamc@821 246 if ch = !strEnder then
adamc@821 247 let
adamc@821 248 val s = String.implode (List.rev (!str))
adamc@821 249 in
adamc@821 250 YYBEGIN INITIAL;
adamc@821 251 if size s = 1 then
adamc@821 252 Tokens.CHAR (String.sub (s, 0), !strStart, pos yypos + 1)
adamc@821 253 else
adamc@821 254 (ErrorMsg.errorAt' (yypos, yypos)
adamc@821 255 "Character constant is zero or multiple characters";
adamc@821 256 continue ())
adamc@821 257 end
adamc@821 258 else
adamc@821 259 (str := ch :: !str;
adamc@821 260 continue ())
adamc@821 261 end);
adamc@821 262
adamc@229 263 <INITIAL> "\"" => (YYBEGIN STRING; strEnder := #"\""; strStart := pos yypos; str := []; continue());
adamc@229 264 <INITIAL> "'" => (YYBEGIN STRING; strEnder := #"'"; strStart := pos yypos; str := []; continue());
adamc@838 265
adamc@229 266 <STRING> . => (let
adamc@229 267 val ch = String.sub (yytext, 0)
adamc@229 268 in
adamc@229 269 if ch = !strEnder then
adamc@229 270 (if !xmlString then
adamc@229 271 (xmlString := false; YYBEGIN XMLTAG)
adamc@229 272 else
adamc@229 273 YYBEGIN INITIAL;
adamc@229 274 Tokens.STRING (String.implode (List.rev (!str)), !strStart, pos yypos + 1))
adamc@229 275 else
adamc@229 276 (str := ch :: !str;
adamc@229 277 continue ())
adamc@229 278 end);
adamc@14 279
adamc@360 280 <INITIAL> "<" {id} "/>"=>(let
adamc@360 281 val tag = String.substring (yytext, 1, size yytext - 3)
adamc@360 282 in
adamc@360 283 Tokens.XML_BEGIN_END (tag, yypos, yypos + size yytext)
adamc@360 284 end);
adamc@91 285 <INITIAL> "<" {id} ">"=> (let
adamc@91 286 val tag = String.substring (yytext, 1, size yytext - 2)
adamc@91 287 in
adamc@91 288 YYBEGIN XML;
adamc@91 289 xmlTag := tag :: (!xmlTag);
adamc@91 290 Tokens.XML_BEGIN (tag, yypos, yypos + size yytext)
adamc@91 291 end);
adamc@91 292 <XML> "</" {id} ">" => (let
adamc@91 293 val id = String.substring (yytext, 2, size yytext - 3)
adamc@91 294 in
adamc@91 295 case !xmlTag of
adamc@91 296 id' :: rest =>
adamc@91 297 if id = id' then
adamc@91 298 (YYBEGIN INITIAL;
adamc@91 299 xmlTag := rest;
adamc@91 300 Tokens.XML_END (yypos, yypos + size yytext))
adamc@91 301 else
adamc@91 302 Tokens.END_TAG (id, yypos, yypos + size yytext)
adamc@91 303 | _ =>
adamc@91 304 Tokens.END_TAG (id, yypos, yypos + size yytext)
adamc@91 305 end);
adamc@91 306
adamc@91 307 <XML> "<" {id} => (YYBEGIN XMLTAG;
adamc@91 308 Tokens.BEGIN_TAG (String.extract (yytext, 1, NONE),
adamc@91 309 yypos, yypos + size yytext));
adamc@91 310
adamc@91 311 <XMLTAG> "/" => (Tokens.DIVIDE (yypos, yypos + size yytext));
adamc@91 312 <XMLTAG> ">" => (YYBEGIN XML;
adamc@91 313 Tokens.GT (yypos, yypos + size yytext));
adamc@91 314
adamc@91 315 <XMLTAG> {ws}+ => (lex ());
adamc@91 316
adam@1840 317 <XMLTAG> {xmlid} => (Tokens.SYMBOL (yytext, yypos, yypos + size yytext));
adamc@91 318 <XMLTAG> "=" => (Tokens.EQ (yypos, yypos + size yytext));
adamc@91 319
adamc@91 320 <XMLTAG> {intconst} => (case Int64.fromString yytext of
adamc@91 321 SOME x => Tokens.INT (x, yypos, yypos + size yytext)
adamc@91 322 | NONE => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 323 ("Expected int, received: " ^ yytext);
adamc@91 324 continue ()));
adamc@91 325 <XMLTAG> {realconst} => (case Real.fromString yytext of
adamc@91 326 SOME x => Tokens.FLOAT (x, yypos, yypos + size yytext)
adamc@91 327 | NONE => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 328 ("Expected float, received: " ^ yytext);
adamc@91 329 continue ()));
adamc@91 330 <XMLTAG> "\"" => (YYBEGIN STRING;
adamc@1069 331 xmlString := true; strEnder := #"\"";
adamc@104 332 strStart := yypos; str := []; continue ());
adamc@91 333
adamc@91 334 <XMLTAG> "{" => (YYBEGIN INITIAL;
adamc@91 335 pushLevel (fn () => YYBEGIN XMLTAG);
adamc@91 336 Tokens.LBRACE (yypos, yypos + 1));
adamc@91 337 <XMLTAG> "(" => (YYBEGIN INITIAL;
adamc@91 338 pushLevel (fn () => YYBEGIN XMLTAG);
adamc@91 339 Tokens.LPAREN (yypos, yypos + 1));
adamc@91 340
adamc@91 341 <XMLTAG> . => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 342 ("illegal XML tag character: \"" ^ yytext ^ "\"");
adamc@91 343 continue ());
adamc@91 344
adamc@91 345 <XML> "{" => (YYBEGIN INITIAL;
adamc@91 346 pushLevel (fn () => YYBEGIN XML);
adamc@91 347 Tokens.LBRACE (yypos, yypos + 1));
adamc@91 348
adamc@763 349 <XML> {notags} => (Tokens.NOTAGS (unescape (yypos, yypos + size yytext) yytext, yypos, yypos + size yytext));
adamc@91 350
adam@1366 351 <XML> "(" => (Tokens.NOTAGS ("(", yypos, yypos + size yytext));
adam@1366 352
adamc@91 353 <XML> . => (ErrorMsg.errorAt' (yypos, yypos)
adamc@91 354 ("illegal XML character: \"" ^ yytext ^ "\"");
adamc@91 355 continue ());
adamc@91 356
adamc@82 357 <INITIAL> "()" => (Tokens.UNIT (pos yypos, pos yypos + size yytext));
adamc@54 358 <INITIAL> "(" => (Tokens.LPAREN (pos yypos, pos yypos + size yytext));
adamc@54 359 <INITIAL> ")" => (Tokens.RPAREN (pos yypos, pos yypos + size yytext));
adamc@54 360 <INITIAL> "[" => (Tokens.LBRACK (pos yypos, pos yypos + size yytext));
adamc@54 361 <INITIAL> "]" => (Tokens.RBRACK (pos yypos, pos yypos + size yytext));
adamc@110 362 <INITIAL> "{" => (enterBrace ();
adamc@110 363 Tokens.LBRACE (pos yypos, pos yypos + size yytext));
adamc@110 364 <INITIAL> "}" => (exitBrace ();
adamc@110 365 Tokens.RBRACE (pos yypos, pos yypos + size yytext));
adamc@1 366
adamc@623 367 <INITIAL> "-->" => (Tokens.KARROW (pos yypos, pos yypos + size yytext));
adamc@54 368 <INITIAL> "->" => (Tokens.ARROW (pos yypos, pos yypos + size yytext));
adamc@623 369 <INITIAL> "==>" => (Tokens.DKARROW (pos yypos, pos yypos + size yytext));
adamc@54 370 <INITIAL> "=>" => (Tokens.DARROW (pos yypos, pos yypos + size yytext));
adamc@54 371 <INITIAL> "++" => (Tokens.PLUSPLUS (pos yypos, pos yypos + size yytext));
adamc@149 372 <INITIAL> "--" => (Tokens.MINUSMINUS (pos yypos, pos yypos + size yytext));
adamc@493 373 <INITIAL> "---" => (Tokens.MINUSMINUSMINUS (pos yypos, pos yypos + size yytext));
adamc@674 374 <INITIAL> "^" => (Tokens.CARET (pos yypos, pos yypos + size yytext));
adamc@1 375
adamc@842 376 <INITIAL> "&&" => (Tokens.ANDALSO (pos yypos, pos yypos + size yytext));
adamc@842 377 <INITIAL> "||" => (Tokens.ORELSE (pos yypos, pos yypos + size yytext));
adamc@842 378
adamc@54 379 <INITIAL> "=" => (Tokens.EQ (pos yypos, pos yypos + size yytext));
adamc@219 380 <INITIAL> "<>" => (Tokens.NE (pos yypos, pos yypos + size yytext));
adamc@219 381 <INITIAL> "<" => (Tokens.LT (pos yypos, pos yypos + size yytext));
adamc@219 382 <INITIAL> ">" => (Tokens.GT (pos yypos, pos yypos + size yytext));
adamc@219 383 <INITIAL> "<=" => (Tokens.LE (pos yypos, pos yypos + size yytext));
adamc@219 384 <INITIAL> ">=" => (Tokens.GE (pos yypos, pos yypos + size yytext));
adamc@54 385 <INITIAL> "," => (Tokens.COMMA (pos yypos, pos yypos + size yytext));
adam@1306 386 <INITIAL> ":::_" => (Tokens.TCOLONWILD (pos yypos, pos yypos + size yytext));
adamc@54 387 <INITIAL> ":::" => (Tokens.TCOLON (pos yypos, pos yypos + size yytext));
adam@1302 388 <INITIAL> "::_" => (Tokens.DCOLONWILD (pos yypos, pos yypos + size yytext));
adamc@54 389 <INITIAL> "::" => (Tokens.DCOLON (pos yypos, pos yypos + size yytext));
adamc@54 390 <INITIAL> ":" => (Tokens.COLON (pos yypos, pos yypos + size yytext));
adamc@174 391 <INITIAL> "..." => (Tokens.DOTDOTDOT (pos yypos, pos yypos + size yytext));
adamc@54 392 <INITIAL> "." => (Tokens.DOT (pos yypos, pos yypos + size yytext));
adamc@54 393 <INITIAL> "$" => (Tokens.DOLLAR (pos yypos, pos yypos + size yytext));
adamc@54 394 <INITIAL> "#" => (Tokens.HASH (pos yypos, pos yypos + size yytext));
adamc@54 395 <INITIAL> "__" => (Tokens.UNDERUNDER (pos yypos, pos yypos + size yytext));
adamc@54 396 <INITIAL> "_" => (Tokens.UNDER (pos yypos, pos yypos + size yytext));
adamc@84 397 <INITIAL> "~" => (Tokens.TWIDDLE (pos yypos, pos yypos + size yytext));
adamc@156 398 <INITIAL> "|" => (Tokens.BAR (pos yypos, pos yypos + size yytext));
adamc@195 399 <INITIAL> "*" => (Tokens.STAR (pos yypos, pos yypos + size yytext));
adamc@243 400 <INITIAL> "<-" => (Tokens.LARROW (pos yypos, pos yypos + size yytext));
adamc@243 401 <INITIAL> ";" => (Tokens.SEMI (pos yypos, pos yypos + size yytext));
adamc@629 402 <INITIAL> "!" => (Tokens.BANG (pos yypos, pos yypos + size yytext));
adamc@1 403
adamc@389 404 <INITIAL> "+" => (Tokens.PLUS (pos yypos, pos yypos + size yytext));
adamc@389 405 <INITIAL> "-" => (Tokens.MINUS (pos yypos, pos yypos + size yytext));
adamc@389 406 <INITIAL> "/" => (Tokens.DIVIDE (yypos, yypos + size yytext));
adamc@389 407 <INITIAL> "%" => (Tokens.MOD (pos yypos, pos yypos + size yytext));
adamc@403 408 <INITIAL> "@" => (Tokens.AT (pos yypos, pos yypos + size yytext));
adamc@389 409
adamc@54 410 <INITIAL> "con" => (Tokens.CON (pos yypos, pos yypos + size yytext));
adamc@54 411 <INITIAL> "type" => (Tokens.LTYPE (pos yypos, pos yypos + size yytext));
adamc@156 412 <INITIAL> "datatype" => (Tokens.DATATYPE (pos yypos, pos yypos + size yytext));
adamc@156 413 <INITIAL> "of" => (Tokens.OF (pos yypos, pos yypos + size yytext));
adamc@54 414 <INITIAL> "val" => (Tokens.VAL (pos yypos, pos yypos + size yytext));
adamc@123 415 <INITIAL> "rec" => (Tokens.REC (pos yypos, pos yypos + size yytext));
adamc@123 416 <INITIAL> "and" => (Tokens.AND (pos yypos, pos yypos + size yytext));
adamc@242 417 <INITIAL> "fun" => (Tokens.FUN (pos yypos, pos yypos + size yytext));
adamc@54 418 <INITIAL> "fn" => (Tokens.FN (pos yypos, pos yypos + size yytext));
adamc@621 419 <INITIAL> "map" => (Tokens.MAP (pos yypos, pos yypos + size yytext));
adamc@170 420 <INITIAL> "case" => (Tokens.CASE (pos yypos, pos yypos + size yytext));
adamc@190 421 <INITIAL> "if" => (Tokens.IF (pos yypos, pos yypos + size yytext));
adamc@190 422 <INITIAL> "then" => (Tokens.THEN (pos yypos, pos yypos + size yytext));
adamc@190 423 <INITIAL> "else" => (Tokens.ELSE (pos yypos, pos yypos + size yytext));
adamc@1 424
adamc@842 425
adamc@54 426 <INITIAL> "structure" => (Tokens.STRUCTURE (pos yypos, pos yypos + size yytext));
adamc@54 427 <INITIAL> "signature" => (Tokens.SIGNATURE (pos yypos, pos yypos + size yytext));
adamc@54 428 <INITIAL> "struct" => (Tokens.STRUCT (pos yypos, pos yypos + size yytext));
adam@1590 429 <INITIAL> "sig" => (if yypos <= 2 then initialSig () else (); Tokens.SIG (pos yypos, pos yypos + size yytext));
adamc@446 430 <INITIAL> "let" => (Tokens.LET (pos yypos, pos yypos + size yytext));
adamc@446 431 <INITIAL> "in" => (Tokens.IN (pos yypos, pos yypos + size yytext));
adamc@54 432 <INITIAL> "end" => (Tokens.END (pos yypos, pos yypos + size yytext));
adamc@54 433 <INITIAL> "functor" => (Tokens.FUNCTOR (pos yypos, pos yypos + size yytext));
adamc@54 434 <INITIAL> "where" => (Tokens.WHERE (pos yypos, pos yypos + size yytext));
adamc@58 435 <INITIAL> "include" => (Tokens.INCLUDE (pos yypos, pos yypos + size yytext));
adamc@58 436 <INITIAL> "open" => (Tokens.OPEN (pos yypos, pos yypos + size yytext));
adamc@88 437 <INITIAL> "constraint"=> (Tokens.CONSTRAINT (pos yypos, pos yypos + size yytext));
adamc@88 438 <INITIAL> "constraints"=> (Tokens.CONSTRAINTS (pos yypos, pos yypos + size yytext));
adamc@109 439 <INITIAL> "export" => (Tokens.EXPORT (pos yypos, pos yypos + size yytext));
adamc@203 440 <INITIAL> "table" => (Tokens.TABLE (pos yypos, pos yypos + size yytext));
adamc@338 441 <INITIAL> "sequence" => (Tokens.SEQUENCE (pos yypos, pos yypos + size yytext));
adamc@754 442 <INITIAL> "view" => (Tokens.VIEW (pos yypos, pos yypos + size yytext));
adamc@211 443 <INITIAL> "class" => (Tokens.CLASS (pos yypos, pos yypos + size yytext));
adamc@459 444 <INITIAL> "cookie" => (Tokens.COOKIE (pos yypos, pos yypos + size yytext));
adamc@718 445 <INITIAL> "style" => (Tokens.STYLE (pos yypos, pos yypos + size yytext));
adamc@1075 446 <INITIAL> "task" => (Tokens.TASK (pos yypos, pos yypos + size yytext));
adamc@1199 447 <INITIAL> "policy" => (Tokens.POLICY (pos yypos, pos yypos + size yytext));
adamc@30 448
adamc@54 449 <INITIAL> "Type" => (Tokens.TYPE (pos yypos, pos yypos + size yytext));
adamc@54 450 <INITIAL> "Name" => (Tokens.NAME (pos yypos, pos yypos + size yytext));
adamc@82 451 <INITIAL> "Unit" => (Tokens.KUNIT (pos yypos, pos yypos + size yytext));
adamc@1 452
adamc@204 453 <INITIAL> "SELECT" => (Tokens.SELECT (pos yypos, pos yypos + size yytext));
adamc@993 454 <INITIAL> "DISTINCT" => (Tokens.DISTINCT (pos yypos, pos yypos + size yytext));
adamc@204 455 <INITIAL> "FROM" => (Tokens.FROM (pos yypos, pos yypos + size yytext));
adamc@204 456 <INITIAL> "AS" => (Tokens.AS (pos yypos, pos yypos + size yytext));
adamc@209 457 <INITIAL> "WHERE" => (Tokens.CWHERE (pos yypos, pos yypos + size yytext));
adamc@339 458 <INITIAL> "SQL" => (Tokens.SQL (pos yypos, pos yypos + size yytext));
adamc@226 459 <INITIAL> "GROUP" => (Tokens.GROUP (pos yypos, pos yypos + size yytext));
adamc@230 460 <INITIAL> "ORDER" => (Tokens.ORDER (pos yypos, pos yypos + size yytext));
adamc@226 461 <INITIAL> "BY" => (Tokens.BY (pos yypos, pos yypos + size yytext));
adamc@227 462 <INITIAL> "HAVING" => (Tokens.HAVING (pos yypos, pos yypos + size yytext));
adamc@231 463 <INITIAL> "LIMIT" => (Tokens.LIMIT (pos yypos, pos yypos + size yytext));
adamc@231 464 <INITIAL> "OFFSET" => (Tokens.OFFSET (pos yypos, pos yypos + size yytext));
adamc@232 465 <INITIAL> "ALL" => (Tokens.ALL (pos yypos, pos yypos + size yytext));
adamc@1071 466 <INITIAL> "SELECT1" => (Tokens.SELECT1 (pos yypos, pos yypos + size yytext));
adamc@209 467
adamc@749 468 <INITIAL> "JOIN" => (Tokens.JOIN (pos yypos, pos yypos + size yytext));
adamc@749 469 <INITIAL> "INNER" => (Tokens.INNER (pos yypos, pos yypos + size yytext));
adamc@749 470 <INITIAL> "CROSS" => (Tokens.CROSS (pos yypos, pos yypos + size yytext));
adamc@751 471 <INITIAL> "OUTER" => (Tokens.OUTER (pos yypos, pos yypos + size yytext));
adamc@750 472 <INITIAL> "LEFT" => (Tokens.LEFT (pos yypos, pos yypos + size yytext));
adamc@751 473 <INITIAL> "RIGHT" => (Tokens.RIGHT (pos yypos, pos yypos + size yytext));
adamc@751 474 <INITIAL> "FULL" => (Tokens.FULL (pos yypos, pos yypos + size yytext));
adamc@749 475
adamc@229 476 <INITIAL> "UNION" => (Tokens.UNION (pos yypos, pos yypos + size yytext));
adamc@229 477 <INITIAL> "INTERSECT" => (Tokens.INTERSECT (pos yypos, pos yypos + size yytext));
adamc@229 478 <INITIAL> "EXCEPT" => (Tokens.EXCEPT (pos yypos, pos yypos + size yytext));
adamc@229 479
adamc@209 480 <INITIAL> "TRUE" => (Tokens.TRUE (pos yypos, pos yypos + size yytext));
adamc@209 481 <INITIAL> "FALSE" => (Tokens.FALSE (pos yypos, pos yypos + size yytext));
adamc@220 482 <INITIAL> "AND" => (Tokens.CAND (pos yypos, pos yypos + size yytext));
adamc@220 483 <INITIAL> "OR" => (Tokens.OR (pos yypos, pos yypos + size yytext));
adamc@220 484 <INITIAL> "NOT" => (Tokens.NOT (pos yypos, pos yypos + size yytext));
adamc@204 485
adamc@235 486 <INITIAL> "COUNT" => (Tokens.COUNT (pos yypos, pos yypos + size yytext));
adamc@236 487 <INITIAL> "AVG" => (Tokens.AVG (pos yypos, pos yypos + size yytext));
adamc@236 488 <INITIAL> "SUM" => (Tokens.SUM (pos yypos, pos yypos + size yytext));
adamc@236 489 <INITIAL> "MIN" => (Tokens.MIN (pos yypos, pos yypos + size yytext));
adamc@236 490 <INITIAL> "MAX" => (Tokens.MAX (pos yypos, pos yypos + size yytext));
adam@1776 491 <INITIAL> "RANK" => (Tokens.RANK (pos yypos, pos yypos + size yytext));
adam@1778 492 <INITIAL> "PARTITION" => (Tokens.PARTITION (pos yypos, pos yypos + size yytext));
adam@1778 493 <INITIAL> "OVER" => (Tokens.OVER (pos yypos, pos yypos + size yytext));
adamc@235 494
kkallio@1572 495 <INITIAL> "IF" => (Tokens.CIF (pos yypos, pos yypos + size yytext));
kkallio@1572 496 <INITIAL> "THEN" => (Tokens.CTHEN (pos yypos, pos yypos + size yytext));
kkallio@1572 497 <INITIAL> "ELSE" => (Tokens.CELSE (pos yypos, pos yypos + size yytext));
kkallio@1572 498
adamc@268 499 <INITIAL> "ASC" => (Tokens.ASC (pos yypos, pos yypos + size yytext));
adamc@268 500 <INITIAL> "DESC" => (Tokens.DESC (pos yypos, pos yypos + size yytext));
adam@1682 501 <INITIAL> "RANDOM" => (Tokens.RANDOM (pos yypos, pos yypos + size yytext));
adamc@268 502
adamc@302 503 <INITIAL> "INSERT" => (Tokens.INSERT (pos yypos, pos yypos + size yytext));
adamc@302 504 <INITIAL> "INTO" => (Tokens.INTO (pos yypos, pos yypos + size yytext));
adamc@302 505 <INITIAL> "VALUES" => (Tokens.VALUES (pos yypos, pos yypos + size yytext));
adamc@302 506 <INITIAL> "UPDATE" => (Tokens.UPDATE (pos yypos, pos yypos + size yytext));
adamc@302 507 <INITIAL> "SET" => (Tokens.SET (pos yypos, pos yypos + size yytext));
adamc@302 508 <INITIAL> "DELETE" => (Tokens.DELETE (pos yypos, pos yypos + size yytext));
adamc@467 509 <INITIAL> "NULL" => (Tokens.NULL (pos yypos, pos yypos + size yytext));
adamc@470 510 <INITIAL> "IS" => (Tokens.IS (pos yypos, pos yypos + size yytext));
adam@1602 511 <INITIAL> "COALESCE" => (Tokens.COALESCE (pos yypos, pos yypos + size yytext));
kkallio@1607 512 <INITIAL> "LIKE" => (Tokens.LIKE (pos yypos, pos yypos + size yytext));
adamc@302 513
adamc@704 514 <INITIAL> "CONSTRAINT"=> (Tokens.CCONSTRAINT (pos yypos, pos yypos + size yytext));
adamc@704 515 <INITIAL> "UNIQUE" => (Tokens.UNIQUE (pos yypos, pos yypos + size yytext));
adamc@714 516 <INITIAL> "CHECK" => (Tokens.CHECK (pos yypos, pos yypos + size yytext));
adamc@707 517 <INITIAL> "PRIMARY" => (Tokens.PRIMARY (pos yypos, pos yypos + size yytext));
adamc@709 518 <INITIAL> "FOREIGN" => (Tokens.FOREIGN (pos yypos, pos yypos + size yytext));
adamc@707 519 <INITIAL> "KEY" => (Tokens.KEY (pos yypos, pos yypos + size yytext));
adamc@709 520 <INITIAL> "ON" => (Tokens.ON (pos yypos, pos yypos + size yytext));
adamc@709 521 <INITIAL> "NO" => (Tokens.NO (pos yypos, pos yypos + size yytext));
adamc@709 522 <INITIAL> "ACTION" => (Tokens.ACTION (pos yypos, pos yypos + size yytext));
adamc@709 523 <INITIAL> "RESTRICT" => (Tokens.RESTRICT (pos yypos, pos yypos + size yytext));
adamc@709 524 <INITIAL> "CASCADE" => (Tokens.CASCADE (pos yypos, pos yypos + size yytext));
adamc@709 525 <INITIAL> "REFERENCES"=> (Tokens.REFERENCES (pos yypos, pos yypos + size yytext));
adamc@709 526
adamc@709 527 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext));
adamc@704 528
adamc@441 529 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext));
adamc@441 530
adamc@54 531 <INITIAL> {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext));
adamc@54 532 <INITIAL> {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext));
adamc@1 533
adamc@14 534 <INITIAL> {intconst} => (case Int64.fromString yytext of
adamc@120 535 SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext)
adamc@120 536 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos)
adamc@120 537 ("Expected int, received: " ^ yytext);
adamc@120 538 continue ()));
adamc@14 539 <INITIAL> {realconst} => (case Real64.fromString yytext of
adamc@54 540 SOME x => Tokens.FLOAT (x, pos yypos, pos yypos + size yytext)
adamc@54 541 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos)
adamc@14 542 ("Expected float, received: " ^ yytext);
adamc@14 543 continue ()));
adamc@14 544
adamc@1 545 <COMMENT> . => (continue());
adamc@1 546
adamc@54 547 <INITIAL> . => (ErrorMsg.errorAt' (pos yypos, pos yypos)
adamc@1 548 ("illegal character: \"" ^ yytext ^ "\"");
adamc@1 549 continue ());