diff options
-rw-r--r-- | lib/basis.lig | 4 | ||||
-rw-r--r-- | src/lacweb.grm | 8 | ||||
-rw-r--r-- | src/lacweb.lex | 2 | ||||
-rw-r--r-- | tests/agg.lac | 4 |
4 files changed, 18 insertions, 0 deletions
diff --git a/lib/basis.lig b/lib/basis.lig index 746651ce..0b685301 100644 --- a/lib/basis.lig +++ b/lib/basis.lig @@ -125,6 +125,10 @@ val sql_comparison : sql_comparison -> sql_exp tables agg exps t -> sql_exp tables agg exps t -> sql_exp tables agg exps bool +val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} + -> unit -> sql_exp tables agg exps int + + (** XML *) con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type diff --git a/src/lacweb.grm b/src/lacweb.grm index c6d89bf6..e230d91e 100644 --- a/src/lacweb.grm +++ b/src/lacweb.grm @@ -169,6 +169,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) = | UNION | INTERSECT | EXCEPT | LIMIT | OFFSET | ALL | TRUE | FALSE | CAND | OR | NOT + | COUNT | NE | LT | LE | GT | GE %nonterm @@ -824,6 +825,13 @@ sqlexp : TRUE (sql_inject (EVar (["Basis"], "True"), s (LBRACEleft, RBRACEright))) | LPAREN sqlexp RPAREN (sqlexp) + | COUNT LPAREN STAR RPAREN (let + val loc = s (COUNTleft, RPARENright) + in + (EApp ((EVar (["Basis"], "sql_count"), loc), + (ERecord [], loc)), loc) + end) + wopt : (sql_inject (EVar (["Basis"], "True"), EVar (["Basis"], "sql_bool"), dummy)) diff --git a/src/lacweb.lex b/src/lacweb.lex index f67eada7..08e39c81 100644 --- a/src/lacweb.lex +++ b/src/lacweb.lex @@ -323,6 +323,8 @@ notags = [^<{\n]+; <INITIAL> "OR" => (Tokens.OR (pos yypos, pos yypos + size yytext)); <INITIAL> "NOT" => (Tokens.NOT (pos yypos, pos yypos + size yytext)); +<INITIAL> "COUNT" => (Tokens.COUNT (pos yypos, pos yypos + size yytext)); + <INITIAL> {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext)); <INITIAL> {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext)); diff --git a/tests/agg.lac b/tests/agg.lac new file mode 100644 index 00000000..7061612b --- /dev/null +++ b/tests/agg.lac @@ -0,0 +1,4 @@ +table t1 : {A : int, B : string, C : float} +table t2 : {A : float, D : int} + +val q1 = (SELECT COUNT( * ) AS N FROM t1) |