diff src/lacweb.lex @ 229:016d71e878c1

Relational operators; string literals for SQL
author Adam Chlipala <adamc@hcoop.net>
date Thu, 21 Aug 2008 15:27:04 -0400
parents 524e10c91478
children 87d41ac28b30
line wrap: on
line diff
--- a/src/lacweb.lex	Thu Aug 21 14:45:31 2008 -0400
+++ b/src/lacweb.lex	Thu Aug 21 15:27:04 2008 -0400
@@ -59,6 +59,7 @@
     end
 end
 
+val strEnder = ref #"\""
 val str = ref ([] : char list)
 val strStart = ref 0
 
@@ -141,16 +142,25 @@
 <COMMENT> "*)"        => (if exitComment () then YYBEGIN INITIAL else ();
 			  continue ());
 
-<INITIAL> "\""        => (YYBEGIN STRING; strStart := pos yypos; str := []; continue());
+<INITIAL> "\""        => (YYBEGIN STRING; strEnder := #"\""; strStart := pos yypos; str := []; continue());
+<INITIAL> "'"         => (YYBEGIN STRING; strEnder := #"'"; strStart := pos yypos; str := []; continue());
 <STRING> "\\\""       => (str := #"\"" :: !str; continue());
-<STRING> "\""         => (if !xmlString then
-			  (xmlString := false; YYBEGIN XMLTAG)
-			  else
-			  YYBEGIN INITIAL;
-			  Tokens.STRING (String.implode (List.rev (!str)), !strStart, pos yypos + 1));
+<STRING> "\\'"        => (str := #"'" :: !str; continue());
 <STRING> "\n"         => (newline yypos;
 			  str := #"\n" :: !str; continue());
-<STRING> .            => (str := String.sub (yytext, 0) :: !str; continue());
+<STRING> .            => (let
+                              val ch = String.sub (yytext, 0)
+                          in
+                              if ch = !strEnder then
+                                  (if !xmlString then
+			               (xmlString := false; YYBEGIN XMLTAG)
+			           else
+			               YYBEGIN INITIAL;
+			           Tokens.STRING (String.implode (List.rev (!str)), !strStart, pos yypos + 1))
+                              else
+                                  (str := ch :: !str;
+                                   continue ())
+                          end);
 
 <INITIAL> "<" {id} ">"=> (let
 			      val tag = String.substring (yytext, 1, size yytext - 2)
@@ -299,6 +309,10 @@
 <INITIAL> "BY"        => (Tokens.BY (pos yypos, pos yypos + size yytext));
 <INITIAL> "HAVING"    => (Tokens.HAVING (pos yypos, pos yypos + size yytext));
 
+<INITIAL> "UNION"     => (Tokens.UNION (pos yypos, pos yypos + size yytext));
+<INITIAL> "INTERSECT" => (Tokens.INTERSECT (pos yypos, pos yypos + size yytext));
+<INITIAL> "EXCEPT"    => (Tokens.EXCEPT (pos yypos, pos yypos + size yytext));
+
 <INITIAL> "TRUE"      => (Tokens.TRUE (pos yypos, pos yypos + size yytext));
 <INITIAL> "FALSE"     => (Tokens.FALSE (pos yypos, pos yypos + size yytext));
 <INITIAL> "AND"       => (Tokens.CAND (pos yypos, pos yypos + size yytext));