102349e2a94a19b462c3b3241d7deb8f27914562
[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
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, typ, exp), (BSLASHleft, expright))
74 | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
75 | exp SEMI exp (let
76 val ls = case #1 exp2 of
77 ESeq ls => exp :: ls
78 | _ => [exp1, exp2]
79 in
80 (ESeq ls, (exp1left, exp2right))
81 end)
82 | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright))
83
84 apps : term (term)
85 | apps term (EApp (apps, term), (appsleft, termright))
86
87 term : LPAREN exp RPAREN (exp)
88 | INT (EInt INT, (INTleft, INTright))
89 | STRING (EString STRING, (STRINGleft, STRINGright))
90 | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright))
91 | LET exp IN exp END (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)),
92 (LETleft, ENDright))
93 | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright))
94
95 elist : ([])
96 | elistNe (elistNe)
97
98 elistNe: exp ([exp])
99 | exp COMMA elistNe (exp :: elistNe)
100
101 typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright))
102 | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright))
103 | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright))
104 | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right))
105 | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty),
106 (LBRACKleft, recdright))
107 | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty),
108 (LBRACKleft, ctxtright))
109 | LPAREN typ RPAREN (typ)
110
111 recd : LBRACE RBRACE (StringMap.empty)
112 | LBRACE recdNe RBRACE (recdNe)
113
114 recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ))
115 | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ))
116
117 ctxt : ROOT (CRoot, (ROOTleft, ROOTright))
118 | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright))
119 | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright))
120 | BANG ctxt (CNot ctxt, (BANGleft, ctxtright))
121 | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right))
122 | LPAREN ctxt RPAREN (ctxt)