diff src/urweb.grm @ 302:bc89dfdbc495

Parsing INSERT
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 14:07:10 -0400
parents cde1ec47f3af
children 7204fab29486
line wrap: on
line diff
--- a/src/urweb.grm	Sun Sep 07 13:52:42 2008 -0400
+++ b/src/urweb.grm	Sun Sep 07 14:07:10 2008 -0400
@@ -179,6 +179,7 @@
  | TRUE | FALSE | CAND | OR | NOT
  | COUNT | AVG | SUM | MIN | MAX
  | ASC | DESC
+ | INSERT | INTO | VALUES | UPDATE | SET | DELETE
  | NE | LT | LE | GT | GE
 
 %nonterm
@@ -279,6 +280,10 @@
  | sqlint of exp
  | sqlagg of string
 
+ | texp of exp
+ | fields of con list
+ | sqlexps of exp list
+
 
 %verbose                                (* print summary of errors *)
 %pos int                                (* positions *)
@@ -725,10 +730,35 @@
        | XML_BEGIN XML_END              (EApp ((EVar (["Basis"], "cdata"), s (XML_BEGINleft, XML_ENDright)),
                                                (EPrim (Prim.String ""), s (XML_BEGINleft, XML_ENDright))),
                                          s (XML_BEGINleft, XML_ENDright))
+
        | LPAREN query RPAREN            (query)
        | LPAREN CWHERE sqlexp RPAREN    (sqlexp)
+
+       | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
+                                        (let
+                                             val loc = s (LPAREN1left, RPAREN3right)
+
+                                             val e = (EVar (["Basis"], "insert"), loc)
+                                             val e = (EApp (e, texp), loc)
+                                         in
+                                             if length fields <> length sqlexps then
+                                                 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
+                                             else
+                                                 ();
+                                             (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
+                                         end)
+
        | UNDER                          (EWild, s (UNDERleft, UNDERright))
 
+texp   : SYMBOL                         (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
+       | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
+
+fields : fident                         ([fident])
+       | fident COMMA fields            (fident :: fields)
+
+sqlexps: sqlexp                         ([sqlexp])
+       | sqlexp COMMA sqlexps           (sqlexp :: sqlexps)
+
 idents : ident                          ([ident])
        | ident DOT idents               (ident :: idents)