From e43dd849a122a59fa2c22278ddf9c9a09d1550bd Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 19 Nov 2011 10:43:57 -0500 Subject: COALESCE --- src/monoize.sml | 22 ++++++++++++++++++++++ src/urweb.grm | 10 +++++++++- src/urweb.lex | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/monoize.sml b/src/monoize.sml index e570b4cb..d18b4d2a 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -2804,6 +2804,28 @@ fun monoExp (env, st, fm) (all as (e, loc)) = fm) end + | (L.ECApp ( + (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 ( 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]; "DELETE" => (Tokens.DELETE (pos yypos, pos yypos + size yytext)); "NULL" => (Tokens.NULL (pos yypos, pos yypos + size yytext)); "IS" => (Tokens.IS (pos yypos, pos yypos + size yytext)); + "COALESCE" => (Tokens.COALESCE (pos yypos, pos yypos + size yytext)); "CONSTRAINT"=> (Tokens.CCONSTRAINT (pos yypos, pos yypos + size yytext)); "UNIQUE" => (Tokens.UNIQUE (pos yypos, pos yypos + size yytext)); -- cgit v1.2.3