X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/234b917a6149413bbbeab7dccfaeab5f16e43fe1..2e96b9d42f6d2619f961c753ac3bbc9ba57c5147:/src/domtool.grm diff --git a/src/domtool.grm b/src/domtool.grm index 4b8405f..ca9ff3a 100644 --- a/src/domtool.grm +++ b/src/domtool.grm @@ -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. -*) + *) (* Parser for Domtool configuration files *) @@ -31,9 +31,9 @@ open Ast | ARROW | DARROW | LARROW | COLON | CARET | BANG | AND | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE - | EQ | COMMA | BSLASH | SEMI | LET | IN | END + | EQ | COMMA | BSLASH | BSLASHBSLASH | SEMI | LET | IN | END | ROOT - | EXTERN | TYPE | VAL | WITH + | EXTERN | TYPE | VAL | WITH | WHERE | CONTEXT %nonterm file of file @@ -45,6 +45,7 @@ open Ast | 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 @@ -68,32 +69,53 @@ open Ast %right ARROW DARROW %right COMMA %nonassoc EQ +%right WITH +%right WHERE %right AND %nonassoc CARET BANG %% -file : decls expOpt (decls, expOpt) +file : docOpt decls expOpt (docOpt, decls, expOpt) decls : ([]) - | decl SEMI decls (decl :: decls) + | decl decls (decl :: decls) -decl : decl' docOpt (decl', docOpt, (decl'left, docOptright)) +decl : decl' SEMI docOpt (decl', docOpt, (decl'left, docOptright)) decl' : EXTERN TYPE SYMBOL (DExternType SYMBOL) | EXTERN VAL SYMBOL COLON typ (DExternVal (SYMBOL, typ)) + | VAL SYMBOL EQ exp (DVal (SYMBOL, NONE, exp)) + | VAL SYMBOL COLON typ EQ exp (DVal (SYMBOL, SOME typ, exp)) + | CONTEXT CSYMBOL (DContext CSYMBOL) docOpt : (NONE) | DOC (SOME DOC) expOpt : (NONE) - | exp (SOME (ELocal exp, (expleft, expright))) + | exp (SOME (ELocal (exp, (ESkip, (expleft, expright))), + (expleft, expright))) exp : apps (apps) + | 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)) + | BSLASHBSLASH SYMBOL COLON ctxt ARROW exp (EALam (SYMBOL, ctxt, exp), + (BSLASHBSLASHleft, expright)) | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright)) | exp SEMI exp (let val ls = case #1 exp2 of @@ -102,9 +124,8 @@ exp : apps (apps) in (ESeq ls, (exp1left, exp2right)) end) + | exp SEMI (exp) | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright)) - | apps WITH END (EWith (apps, (ESkip, (WITHleft, ENDright))), (appsleft, ENDright)) - | apps WITH exp END (EWith (apps, exp), (appsleft, ENDright)) apps : term (term) | apps term (EApp (apps, term), (appsleft, termright)) @@ -113,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)) - | 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)) +sets : CSYMBOL EQ apps ([(ESet (CSYMBOL, apps), (CSYMBOLleft, appsright))]) + | CSYMBOL EQ apps SEMI sets ((ESet (CSYMBOL, apps), (CSYMBOLleft, appsright)) + :: sets) + elist : ([]) | elistNe (elistNe) @@ -132,7 +156,7 @@ typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLrig | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty), (LBRACKleft, ctxtright)) | LPAREN typ RPAREN (typ) - | ctxt DARROW ctxt (TNested (ctxt1, ctxt2), (ctxt1left, ctxt2right)) + | ctxt DARROW typ (TNested (ctxt, typ), (ctxtleft, typright)) recd : LBRACE RBRACE (StringMap.empty) | LBRACE recdNe RBRACE (recdNe)