Mercurial > urweb
diff src/lacweb.grm @ 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.grm Thu Aug 21 14:45:31 2008 -0400 +++ b/src/lacweb.grm Thu Aug 21 15:27:04 2008 -0400 @@ -129,6 +129,15 @@ (EApp (e, sqlexp), loc) end +fun sql_relop (oper, sqlexp1, sqlexp2, loc) = + let + val e = (EVar (["Basis"], "sql_relop"), loc) + val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc) + val e = (EApp (e, sqlexp1), loc) + in + (EApp (e, sqlexp2), loc) + end + %% %header (functor LacwebLrValsFn(structure Token : TOKEN)) @@ -153,6 +162,7 @@ | BEGIN_TAG of string | END_TAG of string | SELECT | FROM | AS | CWHERE | GROUP | BY | HAVING + | UNION | INTERSECT | EXCEPT | TRUE | FALSE | CAND | OR | NOT | NE | LT | LE | GT | GE @@ -247,6 +257,7 @@ %nonassoc DARROW %nonassoc COLON %nonassoc DCOLON TCOLON +%left UNION INTERSECT EXCEPT %right COMMA %right OR %right CAND @@ -644,7 +655,11 @@ | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright)) | LBRACE eexp RBRACE (eexp) -query : query1 (query1) +query : query1 (let + val loc = s (query1left, query1right) + in + (EApp ((EVar (["Basis"], "sql_query"), loc), query1), loc) + end) query1 : SELECT select FROM tables wopt gopt hopt (let @@ -691,7 +706,7 @@ (CRecord tabs, loc)), loc) end - val e = (EVar (["Basis"], "sql_query"), loc) + val e = (EVar (["Basis"], "sql_query1"), loc) val re = (ERecord [((CName "From", loc), (ERecord tables, loc)), ((CName "Where", loc), @@ -708,6 +723,9 @@ in e end) + | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right))) + | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right))) + | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right))) tables : table ([table]) | table COMMA tables (table :: tables) @@ -748,6 +766,9 @@ | FLOAT (sql_inject (EPrim (Prim.Float FLOAT), EVar (["Basis"], "sql_float"), s (FLOATleft, FLOATright))) + | STRING (sql_inject (EPrim (Prim.String STRING), + EVar (["Basis"], "sql_string"), + s (STRINGleft, STRINGright))) | tident DOT fident (let val loc = s (tidentleft, fidentright)