| 1 | (* HCoop Domtool (http://hcoop.sourceforge.net/) |
| 2 | * Copyright (c) 2006, Adam Chlipala |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | *) |
| 18 | |
| 19 | (* Parser for Domtool configuration files *) |
| 20 | |
| 21 | open Ast |
| 22 | |
| 23 | %% |
| 24 | %header (functor DomtoolLrValsFn(structure Token : TOKEN)) |
| 25 | |
| 26 | %term |
| 27 | EOF |
| 28 | | SYMBOL of string | CSYMBOL of string |
| 29 | | STRING of string |
| 30 | | INT of int |
| 31 | | ARROW | DARROW | LARROW |
| 32 | | COLON | CARET | BANG | AND |
| 33 | | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE |
| 34 | | EQ | COMMA | BSLASH | SEMI | LET | IN | END |
| 35 | | ROOT |
| 36 | |
| 37 | %nonterm |
| 38 | file of exp |
| 39 | | exp of exp |
| 40 | | apps of exp |
| 41 | | term of exp |
| 42 | | elist of exp list |
| 43 | | elistNe of exp list |
| 44 | | clist of exp list |
| 45 | | typ of typ |
| 46 | | ctxt of pred |
| 47 | | recd of record |
| 48 | | recdNe of record |
| 49 | |
| 50 | %verbose (* print summary of errors *) |
| 51 | %pos int (* positions *) |
| 52 | %start file |
| 53 | %pure |
| 54 | %eop EOF |
| 55 | %noshift EOF |
| 56 | |
| 57 | %name Domtool |
| 58 | |
| 59 | %right SEMI |
| 60 | %nonassoc COLON |
| 61 | %nonassoc IN |
| 62 | %right ARROW DARROW |
| 63 | %right COMMA |
| 64 | %nonassoc EQ |
| 65 | %right AND |
| 66 | %nonassoc CARET BANG |
| 67 | |
| 68 | %% |
| 69 | |
| 70 | file : exp (exp) |
| 71 | |
| 72 | exp : apps (apps) |
| 73 | | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, SOME typ, exp), |
| 74 | (BSLASHleft, expright)) |
| 75 | | BSLASH SYMBOL ARROW exp (ELam (SYMBOL, NONE, exp), (BSLASHleft, expright)) |
| 76 | | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright)) |
| 77 | | exp SEMI exp (let |
| 78 | val ls = case #1 exp2 of |
| 79 | ESeq ls => exp :: ls |
| 80 | | _ => [exp1, exp2] |
| 81 | in |
| 82 | (ESeq ls, (exp1left, exp2right)) |
| 83 | end) |
| 84 | | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright)) |
| 85 | |
| 86 | apps : term (term) |
| 87 | | apps term (EApp (apps, term), (appsleft, termright)) |
| 88 | |
| 89 | term : LPAREN exp RPAREN (exp) |
| 90 | | INT (EInt INT, (INTleft, INTright)) |
| 91 | | STRING (EString STRING, (STRINGleft, STRINGright)) |
| 92 | | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright)) |
| 93 | | LET exp IN exp END (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)), |
| 94 | (LETleft, ENDright)) |
| 95 | | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright)) |
| 96 | |
| 97 | elist : ([]) |
| 98 | | elistNe (elistNe) |
| 99 | |
| 100 | elistNe: exp ([exp]) |
| 101 | | exp COMMA elistNe (exp :: elistNe) |
| 102 | |
| 103 | typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright)) |
| 104 | | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright)) |
| 105 | | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright)) |
| 106 | | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right)) |
| 107 | | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty), |
| 108 | (LBRACKleft, recdright)) |
| 109 | | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty), |
| 110 | (LBRACKleft, ctxtright)) |
| 111 | | LPAREN typ RPAREN (typ) |
| 112 | |
| 113 | recd : LBRACE RBRACE (StringMap.empty) |
| 114 | | LBRACE recdNe RBRACE (recdNe) |
| 115 | |
| 116 | recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ)) |
| 117 | | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ)) |
| 118 | |
| 119 | ctxt : ROOT (CRoot, (ROOTleft, ROOTright)) |
| 120 | | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright)) |
| 121 | | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright)) |
| 122 | | BANG ctxt (CNot ctxt, (BANGleft, ctxtright)) |
| 123 | | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right)) |
| 124 | | LPAREN ctxt RPAREN (ctxt) |