Mercurial > urweb
comparison src/lacweb.grm @ 230:87d41ac28b30
ORDER BY
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 21 Aug 2008 15:50:08 -0400 |
parents | 016d71e878c1 |
children | eadeea528f75 |
comparison
equal
deleted
inserted
replaced
229:016d71e878c1 | 230:87d41ac28b30 |
---|---|
28 (* Grammar for Laconic/Web programs *) | 28 (* Grammar for Laconic/Web programs *) |
29 | 29 |
30 open Source | 30 open Source |
31 | 31 |
32 val s = ErrorMsg.spanOf | 32 val s = ErrorMsg.spanOf |
33 val dummy = ErrorMsg.dummySpan | |
33 | 34 |
34 fun capitalize "" = "" | 35 fun capitalize "" = "" |
35 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE) | 36 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE) |
36 | 37 |
37 fun entable t = | 38 fun entable t = |
159 | 160 |
160 | XML_BEGIN of string | XML_END | 161 | XML_BEGIN of string | XML_END |
161 | NOTAGS of string | 162 | NOTAGS of string |
162 | BEGIN_TAG of string | END_TAG of string | 163 | BEGIN_TAG of string | END_TAG of string |
163 | 164 |
164 | SELECT | FROM | AS | CWHERE | GROUP | BY | HAVING | 165 | SELECT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING |
165 | UNION | INTERSECT | EXCEPT | 166 | UNION | INTERSECT | EXCEPT |
166 | TRUE | FALSE | CAND | OR | NOT | 167 | TRUE | FALSE | CAND | OR | NOT |
167 | NE | LT | LE | GT | GE | 168 | NE | LT | LE | GT | GE |
168 | 169 |
169 %nonterm | 170 %nonterm |
240 | wopt of exp | 241 | wopt of exp |
241 | groupi of group_item | 242 | groupi of group_item |
242 | groupis of group_item list | 243 | groupis of group_item list |
243 | gopt of group_item list option | 244 | gopt of group_item list option |
244 | hopt of exp | 245 | hopt of exp |
246 | obopt of exp | |
247 | obexps of exp | |
245 | 248 |
246 | 249 |
247 %verbose (* print summary of errors *) | 250 %verbose (* print summary of errors *) |
248 %pos int (* positions *) | 251 %pos int (* positions *) |
249 %start file | 252 %start file |
653 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright)) | 656 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright)) |
654 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright)) | 657 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright)) |
655 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright)) | 658 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright)) |
656 | LBRACE eexp RBRACE (eexp) | 659 | LBRACE eexp RBRACE (eexp) |
657 | 660 |
658 query : query1 (let | 661 query : query1 obopt (let |
659 val loc = s (query1left, query1right) | 662 val loc = s (query1left, query1right) |
660 in | 663 |
661 (EApp ((EVar (["Basis"], "sql_query"), loc), query1), loc) | 664 val re = (ERecord [((CName "Rows", loc), |
665 query1), | |
666 ((CName "OrderBy", loc), | |
667 obopt)], loc) | |
668 in | |
669 (EApp ((EVar (["Basis"], "sql_query"), loc), re), loc) | |
662 end) | 670 end) |
663 | 671 |
664 query1 : SELECT select FROM tables wopt gopt hopt | 672 query1 : SELECT select FROM tables wopt gopt hopt |
665 (let | 673 (let |
666 val loc = s (SELECTleft, tablesright) | 674 val loc = s (SELECTleft, tablesright) |
794 s (LBRACEleft, RBRACEright))) | 802 s (LBRACEleft, RBRACEright))) |
795 | LPAREN sqlexp RPAREN (sqlexp) | 803 | LPAREN sqlexp RPAREN (sqlexp) |
796 | 804 |
797 wopt : (sql_inject (EVar (["Basis"], "True"), | 805 wopt : (sql_inject (EVar (["Basis"], "True"), |
798 EVar (["Basis"], "sql_bool"), | 806 EVar (["Basis"], "sql_bool"), |
799 ErrorMsg.dummySpan)) | 807 dummy)) |
800 | CWHERE sqlexp (sqlexp) | 808 | CWHERE sqlexp (sqlexp) |
801 | 809 |
802 groupi : tident DOT fident (GField (tident, fident)) | 810 groupi : tident DOT fident (GField (tident, fident)) |
803 | 811 |
804 groupis: groupi ([groupi]) | 812 groupis: groupi ([groupi]) |
807 gopt : (NONE) | 815 gopt : (NONE) |
808 | GROUP BY groupis (SOME groupis) | 816 | GROUP BY groupis (SOME groupis) |
809 | 817 |
810 hopt : (sql_inject (EVar (["Basis"], "True"), | 818 hopt : (sql_inject (EVar (["Basis"], "True"), |
811 EVar (["Basis"], "sql_bool"), | 819 EVar (["Basis"], "sql_bool"), |
812 ErrorMsg.dummySpan)) | 820 dummy)) |
813 | HAVING sqlexp (sqlexp) | 821 | HAVING sqlexp (sqlexp) |
822 | |
823 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), dummy), | |
824 (CWild (KRecord (KRecord (KType, dummy), dummy), dummy), dummy)), | |
825 dummy) | |
826 | ORDER BY obexps (obexps) | |
827 | |
828 obexps : sqlexp (let | |
829 val loc = s (sqlexpleft, sqlexpright) | |
830 | |
831 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), loc), | |
832 (CWild (KRecord (KRecord (KType, loc), loc), loc), loc)), | |
833 loc) | |
834 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc), | |
835 sqlexp), loc) | |
836 in | |
837 (EApp (e, e'), loc) | |
838 end) | |
839 | sqlexp COMMA obexps (let | |
840 val loc = s (sqlexpleft, obexpsright) | |
841 | |
842 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc), | |
843 sqlexp), loc) | |
844 in | |
845 (EApp (e, obexps), loc) | |
846 end) |