X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/42198578566be256bbdebf22757f41edef4aa6ee..63920aa5296a85edd9d734a65be22d9911358df2:/src/domtool.grm diff --git a/src/domtool.grm b/src/domtool.grm index 79d13a1..102349e 100644 --- a/src/domtool.grm +++ b/src/domtool.grm @@ -17,6 +17,7 @@ *) (* Parser for Domtool configuration files *) + open Ast %% @@ -27,10 +28,11 @@ open Ast | SYMBOL of string | CSYMBOL of string | STRING of string | INT of int - | ARROW | DARROW | COLON + | ARROW | DARROW | LARROW + | COLON | CARET | BANG | AND | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE | EQ | COMMA | BSLASH | SEMI | LET | IN | END - + | ROOT %nonterm file of exp @@ -41,6 +43,9 @@ open Ast | elistNe of exp list | clist of exp list | typ of typ + | ctxt of pred + | recd of record + | recdNe of record %verbose (* print summary of errors *) %pos int (* positions *) @@ -52,17 +57,20 @@ open Ast %name Domtool %right SEMI +%nonassoc COLON %nonassoc IN -%right ARROW +%right ARROW DARROW %right COMMA %nonassoc EQ +%right AND +%nonassoc CARET BANG %% file : exp (exp) exp : apps (apps) - | BSLASH SYMBOL COLON typ ARROW exp (ELam (SYMBOL, typ, exp), (BSLASHleft, expright)) + | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, typ, exp), (BSLASHleft, expright)) | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright)) | exp SEMI exp (let val ls = case #1 exp2 of @@ -71,6 +79,7 @@ exp : apps (apps) in (ESeq ls, (exp1left, exp2right)) end) + | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright)) apps : term (term) | apps term (EApp (apps, term), (appsleft, termright)) @@ -79,15 +88,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 - (ESeq ls, (exp1left, exp2right)) - end) + | LET exp IN exp END (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)), + (LETleft, ENDright)) + | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright)) elist : ([]) | elistNe (elistNe) @@ -96,3 +99,24 @@ elistNe: exp ([exp]) | exp COMMA elistNe (exp :: elistNe) 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), (LBRACKleft, recd2right)) + | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty), + (LBRACKleft, recdright)) + | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty), + (LBRACKleft, ctxtright)) + | LPAREN typ RPAREN (typ) + +recd : LBRACE RBRACE (StringMap.empty) + | LBRACE recdNe RBRACE (recdNe) + +recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ)) + | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ)) + +ctxt : ROOT (CRoot, (ROOTleft, ROOTright)) + | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright)) + | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright)) + | BANG ctxt (CNot ctxt, (BANGleft, ctxtright)) + | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right)) + | LPAREN ctxt RPAREN (ctxt)