changeset 303:7204fab29486

Parsing UPDATE
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 14:15:16 -0400
parents bc89dfdbc495
children 148ba06f3e67
files lib/basis.urs src/urweb.grm tests/update.ur
diffstat 3 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/basis.urs	Sun Sep 07 14:07:10 2008 -0400
+++ b/lib/basis.urs	Sun Sep 07 14:15:16 2008 -0400
@@ -210,7 +210,8 @@
         -> dml
 
 val update : changed ::: {Type} -> unchanged ::: {Type} -> changed ~ unchanged
-        -> $changed
+        -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc =>
+                [nm = sql_exp [T = changed ++ unchanged] [] [] t] ++ acc) [] changed)
         -> sql_table (changed ++ unchanged)
         -> sql_exp [T = changed ++ unchanged] [] [] bool
         -> dml
--- a/src/urweb.grm	Sun Sep 07 14:07:10 2008 -0400
+++ b/src/urweb.grm	Sun Sep 07 14:15:16 2008 -0400
@@ -283,6 +283,7 @@
  | texp of exp
  | fields of con list
  | sqlexps of exp list
+ | fsets of (con * exp) list
 
 
 %verbose                                (* print summary of errors *)
@@ -747,6 +748,16 @@
                                                  ();
                                              (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
                                          end)
+       | LPAREN UPDATE texp SET fsets CWHERE sqlexp RPAREN
+                                        (let
+                                             val loc = s (LPARENleft, RPARENright)
+
+                                             val e = (EVar (["Basis"], "update"), loc)
+                                             val e = (EApp (e, (ERecord fsets, loc)), loc)
+                                             val e = (EApp (e, texp), loc)
+                                         in
+                                             (EApp (e, sqlexp), loc)
+                                         end)
 
        | UNDER                          (EWild, s (UNDERleft, UNDERright))
 
@@ -759,6 +770,9 @@
 sqlexps: sqlexp                         ([sqlexp])
        | sqlexp COMMA sqlexps           (sqlexp :: sqlexps)
 
+fsets  : fident EQ sqlexp               ([(fident, sqlexp)])
+       | fident EQ sqlexp COMMA fsets   ((fident, sqlexp) :: fsets)
+
 idents : ident                          ([ident])
        | ident DOT idents               (ident :: idents)
 
--- a/tests/update.ur	Sun Sep 07 14:07:10 2008 -0400
+++ b/tests/update.ur	Sun Sep 07 14:15:16 2008 -0400
@@ -1,5 +1,5 @@
 table t1 : {A : int, B : string, C : float, D : bool}
 
 fun main () : transaction page =
-        () <- dml (update {B = "6", C = 7.0} t1 (WHERE T.A = 5));
+        () <- dml (UPDATE t1 SET B = '6', C = 7.0 WHERE T.A = 5);
         return <html><body>Updated.</body></html>