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