X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/a22c187b7b983dad6b0e2c34cd0ab74e95c2411b..234b917a6149413bbbeab7dccfaeab5f16e43fe1:/src/domtool.grm diff --git a/src/domtool.grm b/src/domtool.grm index 3384492..4b8405f 100644 --- a/src/domtool.grm +++ b/src/domtool.grm @@ -17,6 +17,7 @@ *) (* Parser for Domtool configuration files *) + open Ast %% @@ -25,15 +26,22 @@ open Ast %term EOF | SYMBOL of string | CSYMBOL of string - | STRING of string + | STRING of string | DOC of string | INT of int - | ARROW | DARROW | COLON | CARET | BANG | AND + | 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 %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 @@ -41,7 +49,7 @@ open Ast | elistNe of exp list | clist of exp list | typ of typ - | ctxt of context + | ctxt of pred | recd of record | recdNe of record @@ -65,10 +73,27 @@ open Ast %% -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, (expleft, expright))) + exp : apps (apps) - | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, typ, exp), (BSLASHleft, expright)) + | 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 @@ -77,6 +102,9 @@ exp : apps (apps) in (ESeq ls, (exp1left, exp2right)) end) + | 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)) @@ -85,18 +113,9 @@ 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 (let - val ls = case (#1 exp1, #1 exp2) of - (ESeq ls1, ESeq ls2) => ls1 @ ls2 - | (ESeq ls, _) => ls @ [exp2] - | (_, ESeq ls) => exp1 :: ls - | _ => [exp1, exp2] - in - (ELocal (ESeq ls, (exp1left, exp2right)), - (exp1left, exp2right)) - end) + | LET exp IN exp END (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)), + (LETleft, ENDright)) | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright)) - | CSYMBOL (EEnv CSYMBOL, (CSYMBOLleft, CSYMBOLright)) elist : ([]) | elistNe (elistNe) @@ -107,12 +126,13 @@ elistNe: exp ([exp]) typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright)) | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright)) | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright)) - | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (ctxtleft, recd2right)) + | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right)) | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty), - (ctxtleft, recdright)) + (LBRACKleft, recdright)) | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty), - (ctxtleft, ctxtright)) + (LBRACKleft, ctxtright)) | LPAREN typ RPAREN (typ) + | ctxt DARROW ctxt (TNested (ctxt1, ctxt2), (ctxt1left, ctxt2right)) recd : LBRACE RBRACE (StringMap.empty) | LBRACE recdNe RBRACE (recdNe)