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