changeset 1607:da788bd72c9e

Add LIKE operator to SQL sublanguage.
author Karn Kallio <kkallio@eka>
date Wed, 23 Nov 2011 13:17:40 -0430
parents f4453e2402d0
children 77180224f1f9
files lib/ur/basis.urs src/elisp/urweb-mode.el src/monoize.sml src/urweb.grm src/urweb.lex
diffstat 5 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ur/basis.urs	Sun Nov 20 20:54:03 2011 -0500
+++ b/lib/ur/basis.urs	Wed Nov 23 13:17:40 2011 -0430
@@ -523,6 +523,8 @@
 val sql_gt : t ::: Type -> sql_binary t t bool
 val sql_ge : t ::: Type -> sql_binary t t bool
 
+val sql_like : sql_binary string string bool
+
 val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
                 -> sql_exp tables agg exps int
 
--- a/src/elisp/urweb-mode.el	Sun Nov 20 20:54:03 2011 -0500
+++ b/src/elisp/urweb-mode.el	Wed Nov 23 13:17:40 2011 -0430
@@ -151,7 +151,7 @@
                  "PRIMARY" "KEY" "CONSTRAINT" "UNIQUE" "CHECK"
                  "FOREIGN" "REFERENCES" "ON" "NO" "ACTION" "CASCADE" "RESTRICT" "NULL"
                  "JOIN" "INNER" "OUTER" "LEFT" "RIGHT" "FULL" "CROSS" "SELECT1"
-                 "IF" "THEN" "ELSE")
+                 "IF" "THEN" "ELSE" "COALESCE" "LIKE")
   "A regexp that matches SQL keywords.")
 
 (defconst urweb-lident-regexp "\\<[a-z_][A-Za-z0-9_']*\\>"
--- a/src/monoize.sml	Sun Nov 20 20:54:03 2011 -0500
+++ b/src/monoize.sml	Wed Nov 23 13:17:40 2011 -0430
@@ -2470,6 +2470,9 @@
           | L.EFfi ("Basis", "sql_mod") =>
             ((L'.EPrim (Prim.String "%"), loc), fm)
 
+          | L.EFfi ("Basis", "sql_like") =>
+            ((L'.EPrim (Prim.String "LIKE"), loc), fm)
+
           | L.ECApp (
             (L.ECApp (
              (L.ECApp (
--- a/src/urweb.grm	Sun Nov 20 20:54:03 2011 -0500
+++ b/src/urweb.grm	Wed Nov 23 13:17:40 2011 -0430
@@ -244,7 +244,7 @@
  | TRUE | FALSE | CAND | OR | NOT
  | COUNT | AVG | SUM | MIN | MAX
  | ASC | DESC
- | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE
+ | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE
  | CURRENT_TIMESTAMP
  | NE | LT | LE | GT | GE
  | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
@@ -1834,6 +1834,8 @@
        | sqlexp CAND sqlexp             (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
        | sqlexp OR sqlexp               (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
 
+       | sqlexp LIKE sqlexp             (sql_binary ("like", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
+
        | NOT sqlexp                     (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
        | MINUS sqlexp                   (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
 
--- a/src/urweb.lex	Sun Nov 20 20:54:03 2011 -0500
+++ b/src/urweb.lex	Wed Nov 23 13:17:40 2011 -0430
@@ -500,6 +500,7 @@
 <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> "LIKE"      => (Tokens.LIKE (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));