Commit | Line | Data |
---|---|---|
42198578 AC |
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 *) | |
63920aa5 | 20 | |
42198578 AC |
21 | open Ast |
22 | ||
23 | %% | |
24 | %header (functor DomtoolLrValsFn(structure Token : TOKEN)) | |
25 | ||
26 | %term | |
27 | EOF | |
28 | | SYMBOL of string | CSYMBOL of string | |
234b917a | 29 | | STRING of string | DOC of string |
42198578 | 30 | | INT of int |
63920aa5 AC |
31 | | ARROW | DARROW | LARROW |
32 | | COLON | CARET | BANG | AND | |
42198578 AC |
33 | | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE |
34 | | EQ | COMMA | BSLASH | SEMI | LET | IN | END | |
a22c187b | 35 | | ROOT |
1a4e5a6c | 36 | | EXTERN | TYPE | VAL | WITH | WHERE |
42198578 AC |
37 | |
38 | %nonterm | |
234b917a AC |
39 | file of file |
40 | | decls of decl list | |
41 | | decl of decl | |
42 | | decl' of decl' | |
43 | | docOpt of string option | |
44 | | expOpt of exp option | |
42198578 AC |
45 | | exp of exp |
46 | | apps of exp | |
47 | | term of exp | |
1a4e5a6c | 48 | | sets of exp list |
42198578 AC |
49 | | elist of exp list |
50 | | elistNe of exp list | |
51 | | clist of exp list | |
52 | | typ of typ | |
63920aa5 | 53 | | ctxt of pred |
a22c187b AC |
54 | | recd of record |
55 | | recdNe of record | |
42198578 AC |
56 | |
57 | %verbose (* print summary of errors *) | |
58 | %pos int (* positions *) | |
59 | %start file | |
60 | %pure | |
61 | %eop EOF | |
62 | %noshift EOF | |
63 | ||
64 | %name Domtool | |
65 | ||
66 | %right SEMI | |
a22c187b | 67 | %nonassoc COLON |
42198578 | 68 | %nonassoc IN |
a22c187b | 69 | %right ARROW DARROW |
42198578 AC |
70 | %right COMMA |
71 | %nonassoc EQ | |
1a4e5a6c AC |
72 | %right WITH |
73 | %right WHERE | |
a22c187b AC |
74 | %right AND |
75 | %nonassoc CARET BANG | |
42198578 AC |
76 | |
77 | %% | |
78 | ||
234b917a AC |
79 | file : decls expOpt (decls, expOpt) |
80 | ||
81 | decls : ([]) | |
82 | | decl SEMI decls (decl :: decls) | |
83 | ||
84 | decl : decl' docOpt (decl', docOpt, (decl'left, docOptright)) | |
85 | ||
86 | decl' : EXTERN TYPE SYMBOL (DExternType SYMBOL) | |
87 | | EXTERN VAL SYMBOL COLON typ (DExternVal (SYMBOL, typ)) | |
88 | ||
89 | docOpt : (NONE) | |
90 | | DOC (SOME DOC) | |
91 | ||
92 | expOpt : (NONE) | |
1a4e5a6c AC |
93 | | exp (SOME (ELocal (exp, (ESkip, (expleft, expright))), |
94 | (expleft, expright))) | |
234b917a | 95 | |
42198578 AC |
96 | |
97 | exp : apps (apps) | |
1a4e5a6c AC |
98 | | apps WHERE sets END (ELocal ((ESeq sets, (setsleft, setsright)), apps), |
99 | (appsleft, ENDright)) | |
100 | | apps WITH END (EWith (apps, (ESkip, (WITHleft, ENDright))), | |
101 | (appsleft, ENDright)) | |
102 | | apps WITH exp END (EWith (apps, exp), (appsleft, ENDright)) | |
103 | | apps WHERE sets WITH END (ELocal ((ESeq sets, (setsleft, setsright)), | |
104 | (EWith (apps, (ESkip, (WITHleft, ENDright))), | |
105 | (appsleft, ENDright))), | |
106 | (appsleft, ENDright)) | |
107 | | apps WHERE sets WITH exp END (ELocal ((ESeq sets, (setsleft, setsright)), | |
108 | (EWith (apps, exp), (appsleft, ENDright))), | |
109 | (appsleft, ENDright)) | |
110 | ||
27d9de59 AC |
111 | | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, SOME typ, exp), |
112 | (BSLASHleft, expright)) | |
113 | | BSLASH SYMBOL ARROW exp (ELam (SYMBOL, NONE, exp), (BSLASHleft, expright)) | |
42198578 AC |
114 | | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright)) |
115 | | exp SEMI exp (let | |
116 | val ls = case #1 exp2 of | |
117 | ESeq ls => exp :: ls | |
118 | | _ => [exp1, exp2] | |
119 | in | |
120 | (ESeq ls, (exp1left, exp2right)) | |
121 | end) | |
234b917a | 122 | | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright)) |
1a4e5a6c AC |
123 | (*| exp WHERE exp END (ELocal (exp1, exp2), (exp1left, ENDright)) |
124 | | exp WHERE exp WITH END (EWith ((ELocal (exp1, exp2), (exp1left, ENDright)), | |
125 | (ESkip, (WITHleft, ENDright))), | |
126 | (exp1left, ENDright)) | |
127 | | exp WITH END (EWith (exp, (ESkip, (WITHleft, ENDright))), (expleft, ENDright)) | |
128 | | exp WITH exp END (EWith (exp1, exp2), (exp1left, ENDright))*) | |
42198578 AC |
129 | |
130 | apps : term (term) | |
131 | | apps term (EApp (apps, term), (appsleft, termright)) | |
132 | ||
133 | term : LPAREN exp RPAREN (exp) | |
134 | | INT (EInt INT, (INTleft, INTright)) | |
135 | | STRING (EString STRING, (STRINGleft, STRINGright)) | |
136 | | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright)) | |
1a4e5a6c | 137 | | LET exp IN exp END (ELocal (exp1, exp2), (LETleft, ENDright)) |
a22c187b | 138 | | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright)) |
42198578 | 139 | |
1a4e5a6c AC |
140 | sets : CSYMBOL EQ apps ([(ESet (CSYMBOL, apps), (CSYMBOLleft, appsright))]) |
141 | | CSYMBOL EQ apps SEMI sets ((ESet (CSYMBOL, apps), (CSYMBOLleft, appsright)) | |
142 | :: sets) | |
143 | ||
42198578 AC |
144 | elist : ([]) |
145 | | elistNe (elistNe) | |
146 | ||
147 | elistNe: exp ([exp]) | |
148 | | exp COMMA elistNe (exp :: elistNe) | |
149 | ||
150 | typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright)) | |
a22c187b AC |
151 | | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright)) |
152 | | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright)) | |
63920aa5 | 153 | | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right)) |
a22c187b | 154 | | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty), |
63920aa5 | 155 | (LBRACKleft, recdright)) |
a22c187b | 156 | | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty), |
63920aa5 | 157 | (LBRACKleft, ctxtright)) |
a22c187b | 158 | | LPAREN typ RPAREN (typ) |
1a4e5a6c | 159 | | ctxt DARROW typ (TNested (ctxt, typ), (ctxtleft, typright)) |
a22c187b AC |
160 | |
161 | recd : LBRACE RBRACE (StringMap.empty) | |
162 | | LBRACE recdNe RBRACE (recdNe) | |
163 | ||
164 | recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ)) | |
165 | | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ)) | |
166 | ||
167 | ctxt : ROOT (CRoot, (ROOTleft, ROOTright)) | |
168 | | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright)) | |
169 | | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright)) | |
170 | | BANG ctxt (CNot ctxt, (BANGleft, ctxtright)) | |
171 | | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right)) | |
172 | | LPAREN ctxt RPAREN (ctxt) |