79d13a134e8d8c51e2da4a1d9c64ac255c415358
[hcoop/domtool2.git] / src / domtool.grm
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 open Ast
21
22 %%
23 %header (functor DomtoolLrValsFn(structure Token : TOKEN))
24
25 %term
26 EOF
27 | SYMBOL of string | CSYMBOL of string
28 | STRING of string
29 | INT of int
30 | ARROW | DARROW | COLON
31 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
32 | EQ | COMMA | BSLASH | SEMI | LET | IN | END
33
34
35 %nonterm
36 file of exp
37 | exp of exp
38 | apps of exp
39 | term of exp
40 | elist of exp list
41 | elistNe of exp list
42 | clist of exp list
43 | typ of typ
44
45 %verbose (* print summary of errors *)
46 %pos int (* positions *)
47 %start file
48 %pure
49 %eop EOF
50 %noshift EOF
51
52 %name Domtool
53
54 %right SEMI
55 %nonassoc IN
56 %right ARROW
57 %right COMMA
58 %nonassoc EQ
59
60 %%
61
62 file : exp (exp)
63
64 exp : apps (apps)
65 | BSLASH SYMBOL COLON typ ARROW exp (ELam (SYMBOL, typ, exp), (BSLASHleft, expright))
66 | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
67 | exp SEMI exp (let
68 val ls = case #1 exp2 of
69 ESeq ls => exp :: ls
70 | _ => [exp1, exp2]
71 in
72 (ESeq ls, (exp1left, exp2right))
73 end)
74
75 apps : term (term)
76 | apps term (EApp (apps, term), (appsleft, termright))
77
78 term : LPAREN exp RPAREN (exp)
79 | INT (EInt INT, (INTleft, INTright))
80 | STRING (EString STRING, (STRINGleft, STRINGright))
81 | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright))
82 | LET exp IN exp END (let
83 val ls = case (#1 exp1, #1 exp2) of
84 (ESeq ls1, ESeq ls2) => ls1 @ ls2
85 | (ESeq ls, _) => ls @ [exp2]
86 | (_, ESeq ls) => exp1 :: ls
87 | _ => [exp1, exp2]
88 in
89 (ESeq ls, (exp1left, exp2right))
90 end)
91
92 elist : ([])
93 | elistNe (elistNe)
94
95 elistNe: exp ([exp])
96 | exp COMMA elistNe (exp :: elistNe)
97
98 typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright))