Fix indentation in GPL headers
[hcoop/domtool2.git] / src / domtool.grm
index 102349e..cd899e1 100644 (file)
@@ -14,7 +14,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*)
+ *)
 
 (* Parser for Domtool configuration files *)
 
 
 (* Parser for Domtool configuration files *)
 
@@ -26,19 +26,26 @@ open Ast
 %term 
    EOF
  | SYMBOL of string | CSYMBOL of string
 %term 
    EOF
  | SYMBOL of string | CSYMBOL of string
- | STRING of string
+ | STRING of string | DOC of string
  | INT of int
  | ARROW | DARROW | LARROW
  | COLON | CARET | BANG | AND
  | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
  | EQ | COMMA | BSLASH | SEMI | LET | IN | END
  | ROOT
  | INT of int
  | ARROW | DARROW | LARROW
  | COLON | CARET | BANG | AND
  | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
  | EQ | COMMA | BSLASH | SEMI | LET | IN | END
  | ROOT
+ | EXTERN | TYPE | VAL | WITH | WHERE
 
 %nonterm 
 
 %nonterm 
-   file of exp
+   file of file
+ | decls of decl list
+ | decl of decl
+ | decl' of decl'
+ | docOpt of string option
+ | expOpt of exp option
  | exp of exp
  | apps of exp
  | term of exp
  | exp of exp
  | apps of exp
  | term of exp
+ | sets of exp list
  | elist of exp list
  | elistNe of exp list
  | clist of exp list
  | elist of exp list
  | elistNe of exp list
  | clist of exp list
@@ -62,15 +69,48 @@ open Ast
 %right ARROW DARROW
 %right COMMA
 %nonassoc EQ
 %right ARROW DARROW
 %right COMMA
 %nonassoc EQ
+%right WITH
+%right WHERE
 %right AND
 %nonassoc CARET BANG
 
 %%
 
 %right AND
 %nonassoc CARET BANG
 
 %%
 
-file   : exp                               (exp)
+file   : decls expOpt                      (decls, expOpt)
+
+decls  :                                   ([])
+       | decl SEMI decls                   (decl :: decls)
+
+decl   : decl' docOpt                      (decl', docOpt, (decl'left, docOptright))
+
+decl'  : EXTERN TYPE SYMBOL                (DExternType SYMBOL)
+       | EXTERN VAL SYMBOL COLON typ       (DExternVal (SYMBOL, typ))
+
+docOpt :                                   (NONE)
+       | DOC                               (SOME DOC)
+
+expOpt :                                   (NONE)
+       | exp                               (SOME (ELocal (exp, (ESkip, (expleft, expright))),
+                                                 (expleft, expright)))
+
 
 exp    : apps                              (apps)
 
 exp    : apps                              (apps)
-       | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, typ, exp), (BSLASHleft, expright))
+       | apps WHERE sets END               (ELocal ((ESeq sets, (setsleft, setsright)), apps),
+                                           (appsleft, ENDright))
+       | apps WITH END                     (EWith (apps, (ESkip, (WITHleft, ENDright))),
+                                           (appsleft, ENDright))
+       | apps WITH exp END                 (EWith (apps, exp), (appsleft, ENDright))
+       | apps WHERE sets WITH END          (ELocal ((ESeq sets, (setsleft, setsright)),
+                                                   (EWith (apps, (ESkip, (WITHleft, ENDright))),
+                                                    (appsleft, ENDright))),
+                                           (appsleft, ENDright))
+       | apps WHERE sets WITH exp END      (ELocal ((ESeq sets, (setsleft, setsright)),
+                                                   (EWith (apps, exp), (appsleft, ENDright))),
+                                           (appsleft, ENDright))
+
+       | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, SOME typ, exp),
+                                                         (BSLASHleft, expright))
+       | BSLASH SYMBOL ARROW exp           (ELam (SYMBOL, NONE, exp), (BSLASHleft, expright))
        | CSYMBOL EQ exp                    (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
        | exp SEMI exp                      (let
                                                val ls = case #1 exp2 of
        | CSYMBOL EQ exp                    (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
        | exp SEMI exp                      (let
                                                val ls = case #1 exp2 of
@@ -79,7 +119,13 @@ exp    : apps                              (apps)
                                            in
                                                (ESeq ls, (exp1left, exp2right))
                                            end)
                                            in
                                                (ESeq ls, (exp1left, exp2right))
                                            end)
-       | SYMBOL LARROW CSYMBOL SEMI exp    (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright)) 
+       | SYMBOL LARROW CSYMBOL SEMI exp    (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright))
+       (*| exp WHERE exp END                 (ELocal (exp1, exp2), (exp1left, ENDright))
+       | exp WHERE exp WITH END            (EWith ((ELocal (exp1, exp2), (exp1left, ENDright)),
+                                                  (ESkip, (WITHleft, ENDright))),
+                                           (exp1left, ENDright))
+       | exp WITH END                      (EWith (exp, (ESkip, (WITHleft, ENDright))), (expleft, ENDright))
+       | exp WITH exp END                  (EWith (exp1, exp2), (exp1left, ENDright))*)
 
 apps   : term                              (term)
        | apps term                         (EApp (apps, term), (appsleft, termright))
 
 apps   : term                              (term)
        | apps term                         (EApp (apps, term), (appsleft, termright))
@@ -88,10 +134,13 @@ term   : LPAREN exp RPAREN                 (exp)
        | INT                               (EInt INT, (INTleft, INTright))
        | STRING                            (EString STRING, (STRINGleft, STRINGright))
        | LBRACK elist RBRACK               (EList elist, (LBRACKleft, RBRACKright))
        | INT                               (EInt INT, (INTleft, INTright))
        | STRING                            (EString STRING, (STRINGleft, STRINGright))
        | LBRACK elist RBRACK               (EList elist, (LBRACKleft, RBRACKright))
-       | LET exp IN exp END                (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)),
-                                                   (LETleft, ENDright))
+       | LET exp IN exp END                (ELocal (exp1, exp2), (LETleft, ENDright))
        | SYMBOL                            (EVar SYMBOL, (SYMBOLleft, SYMBOLright))
 
        | SYMBOL                            (EVar SYMBOL, (SYMBOLleft, SYMBOLright))
 
+sets   : CSYMBOL EQ apps                   ([(ESet (CSYMBOL, apps), (CSYMBOLleft, appsright))])
+       | CSYMBOL EQ apps SEMI sets         ((ESet (CSYMBOL, apps), (CSYMBOLleft, appsright))
+                                           :: sets)
+
 elist  :                                   ([])
        | elistNe                           (elistNe)
 
 elist  :                                   ([])
        | elistNe                           (elistNe)
 
@@ -107,6 +156,7 @@ typ    : SYMBOL                            (TBase SYMBOL, (SYMBOLleft, SYMBOLrig
        | LBRACK ctxt RBRACK                (TAction (ctxt, StringMap.empty, StringMap.empty),
                                            (LBRACKleft, ctxtright))
        | LPAREN typ RPAREN                 (typ)
        | LBRACK ctxt RBRACK                (TAction (ctxt, StringMap.empty, StringMap.empty),
                                            (LBRACKleft, ctxtright))
        | LPAREN typ RPAREN                 (typ)
+       | ctxt DARROW typ                   (TNested (ctxt, typ), (ctxtleft, typright))
 
 recd   : LBRACE RBRACE                     (StringMap.empty)
        | LBRACE recdNe RBRACE              (recdNe)
 
 recd   : LBRACE RBRACE                     (StringMap.empty)
        | LBRACE recdNe RBRACE              (recdNe)