diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-11-19 10:43:57 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-11-19 10:43:57 -0500 |
commit | e43dd849a122a59fa2c22278ddf9c9a09d1550bd (patch) | |
tree | b8e125a96ec1466c542b24651ef1ce4027f21193 /src | |
parent | 9a047b4f248ace0615eaf18ba130e14e49634723 (diff) |
COALESCE
Diffstat (limited to 'src')
-rw-r--r-- | src/monoize.sml | 22 | ||||
-rw-r--r-- | src/urweb.grm | 10 | ||||
-rw-r--r-- | src/urweb.lex | 1 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/monoize.sml b/src/monoize.sml index e570b4cb..d18b4d2a 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -2808,6 +2808,28 @@ fun monoExp (env, st, fm) (all as (e, loc)) = (L.ECApp ( (L.ECApp ( (L.ECApp ( + (L.EFfi ("Basis", "sql_coalesce"), _), _), + _), _), + _), _), + _), _)) => + let + val s = (L'.TFfi ("Basis", "string"), loc) + fun sc s = (L'.EPrim (Prim.String s), loc) + in + ((L'.EAbs ("x1", s, (L'.TFun (s, s), loc), + (L'.EAbs ("x1", s, s, + strcat [sc "COALESCE(", + (L'.ERel 1, loc), + sc ",", + (L'.ERel 0, loc), + sc ")"]), loc)), loc), + fm) + end + + | (L.ECApp ( + (L.ECApp ( + (L.ECApp ( + (L.ECApp ( (L.EFfi ("Basis", "sql_if_then_else"), _), _), _), _), _), _), diff --git a/src/urweb.grm b/src/urweb.grm index db8b6294..8e3fad90 100644 --- a/src/urweb.grm +++ b/src/urweb.grm @@ -244,7 +244,7 @@ fun tnamesOf (e, _) = | TRUE | FALSE | CAND | OR | NOT | COUNT | AVG | SUM | MIN | MAX | ASC | DESC - | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS + | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | CURRENT_TIMESTAMP | NE | LT | LE | GT | GE | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES @@ -1881,6 +1881,14 @@ sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", In in (EApp (e, sqlexp), loc) end) + | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN + (let + val loc = s (COALESCEright, sqlexp2right) + val e = (EVar (["Basis"], "sql_coalesce", Infer), loc) + val e = (EApp (e, sqlexp1), loc) + in + (EApp (e, sqlexp2), loc) + end) | fname LPAREN sqlexp RPAREN (let val loc = s (fnameleft, RPARENright) diff --git a/src/urweb.lex b/src/urweb.lex index a989d933..8e8b0a12 100644 --- a/src/urweb.lex +++ b/src/urweb.lex @@ -499,6 +499,7 @@ xint = x[0-9a-fA-F][0-9a-fA-F]; <INITIAL> "DELETE" => (Tokens.DELETE (pos yypos, pos yypos + size yytext)); <INITIAL> "NULL" => (Tokens.NULL (pos yypos, pos yypos + size yytext)); <INITIAL> "IS" => (Tokens.IS (pos yypos, pos yypos + size yytext)); +<INITIAL> "COALESCE" => (Tokens.COALESCE (pos yypos, pos yypos + size yytext)); <INITIAL> "CONSTRAINT"=> (Tokens.CCONSTRAINT (pos yypos, pos yypos + size yytext)); <INITIAL> "UNIQUE" => (Tokens.UNIQUE (pos yypos, pos yypos + size yytext)); |