1 (* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2006, Adam Chlipala
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.
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.
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.
19 (* Parser for Domtool configuration files *)
24 %header (functor DomtoolLrValsFn(structure Token : TOKEN))
28 | SYMBOL of string | CSYMBOL of string
29 | STRING of string | DOC of string
31 | ARROW | DARROW | LARROW
32 | COLON | CARET | BANG | AND
33 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
34 | EQ | COMMA | BSLASH | SEMI | LET | IN | END
36 | EXTERN | TYPE | VAL | WITH | WHERE
43 | docOpt of string option
44 | expOpt of exp option
57 %verbose (* print summary of errors *)
58 %pos int (* positions *)
79 file : decls expOpt (decls, expOpt)
82 | decl SEMI decls (decl :: decls)
84 decl : decl' docOpt (decl', docOpt, (decl'left, docOptright))
86 decl' : EXTERN TYPE SYMBOL (DExternType SYMBOL)
87 | EXTERN VAL SYMBOL COLON typ (DExternVal (SYMBOL, typ))
88 | VAL SYMBOL EQ exp (DVal (SYMBOL, NONE, exp))
89 | VAL SYMBOL COLON typ EQ exp (DVal (SYMBOL, SOME typ, exp))
95 | exp (SOME (ELocal (exp, (ESkip, (expleft, expright))),
100 | apps WHERE sets END (ELocal ((ESeq sets, (setsleft, setsright)), apps),
101 (appsleft, ENDright))
102 | apps WITH END (EWith (apps, (ESkip, (WITHleft, ENDright))),
103 (appsleft, ENDright))
104 | apps WITH exp END (EWith (apps, exp), (appsleft, ENDright))
105 | apps WHERE sets WITH END (ELocal ((ESeq sets, (setsleft, setsright)),
106 (EWith (apps, (ESkip, (WITHleft, ENDright))),
107 (appsleft, ENDright))),
108 (appsleft, ENDright))
109 | apps WHERE sets WITH exp END (ELocal ((ESeq sets, (setsleft, setsright)),
110 (EWith (apps, exp), (appsleft, ENDright))),
111 (appsleft, ENDright))
113 | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, SOME typ, exp),
114 (BSLASHleft, expright))
115 | BSLASH SYMBOL ARROW exp (ELam (SYMBOL, NONE, exp), (BSLASHleft, expright))
116 | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
118 val ls = case #1 exp2 of
122 (ESeq ls, (exp1left, exp2right))
124 | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright))
125 (*| exp WHERE exp END (ELocal (exp1, exp2), (exp1left, ENDright))
126 | exp WHERE exp WITH END (EWith ((ELocal (exp1, exp2), (exp1left, ENDright)),
127 (ESkip, (WITHleft, ENDright))),
128 (exp1left, ENDright))
129 | exp WITH END (EWith (exp, (ESkip, (WITHleft, ENDright))), (expleft, ENDright))
130 | exp WITH exp END (EWith (exp1, exp2), (exp1left, ENDright))*)
133 | apps term (EApp (apps, term), (appsleft, termright))
135 term : LPAREN exp RPAREN (exp)
136 | INT (EInt INT, (INTleft, INTright))
137 | STRING (EString STRING, (STRINGleft, STRINGright))
138 | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright))
139 | LET exp IN exp END (ELocal (exp1, exp2), (LETleft, ENDright))
140 | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright))
142 sets : CSYMBOL EQ apps ([(ESet (CSYMBOL, apps), (CSYMBOLleft, appsright))])
143 | CSYMBOL EQ apps SEMI sets ((ESet (CSYMBOL, apps), (CSYMBOLleft, appsright))
150 | exp COMMA elistNe (exp :: elistNe)
152 typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright))
153 | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright))
154 | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright))
155 | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right))
156 | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty),
157 (LBRACKleft, recdright))
158 | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty),
159 (LBRACKleft, ctxtright))
160 | LPAREN typ RPAREN (typ)
161 | ctxt DARROW typ (TNested (ctxt, typ), (ctxtleft, typright))
163 recd : LBRACE RBRACE (StringMap.empty)
164 | LBRACE recdNe RBRACE (recdNe)
166 recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ))
167 | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ))
169 ctxt : ROOT (CRoot, (ROOTleft, ROOTright))
170 | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright))
171 | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright))
172 | BANG ctxt (CNot ctxt, (BANGleft, ctxtright))
173 | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right))
174 | LPAREN ctxt RPAREN (ctxt)