Type-checking goodies in place
[hcoop/zz_old/domtool2-proto.git] / src / domtool.grm
CommitLineData
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.
17*)
18
19(* Parser for Domtool configuration files *)
7d3ae99f 20
9fc2614f 21open 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
34 | EQ | COMMA | BSLASH | SEMI | LET | IN | END
ccc91989 35 | ROOT
e680130a 36 | EXTERN | TYPE | VAL | WITH
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
48 | elist of exp list
49 | elistNe of exp list
50 | clist of exp list
51 | typ of typ
7d3ae99f 52 | ctxt of pred
ccc91989 53 | recd of record
54 | recdNe of record
9fc2614f 55
56%verbose (* print summary of errors *)
57%pos int (* positions *)
58%start file
59%pure
60%eop EOF
61%noshift EOF
62
63%name Domtool
64
65%right SEMI
ccc91989 66%nonassoc COLON
9fc2614f 67%nonassoc IN
ccc91989 68%right ARROW DARROW
9fc2614f 69%right COMMA
70%nonassoc EQ
ccc91989 71%right AND
72%nonassoc CARET BANG
9fc2614f 73
74%%
75
e680130a 76file : decls expOpt (decls, expOpt)
77
78decls : ([])
79 | decl SEMI decls (decl :: decls)
80
81decl : decl' docOpt (decl', docOpt, (decl'left, docOptright))
82
83decl' : EXTERN TYPE SYMBOL (DExternType SYMBOL)
84 | EXTERN VAL SYMBOL COLON typ (DExternVal (SYMBOL, typ))
85
86docOpt : (NONE)
87 | DOC (SOME DOC)
88
89expOpt : (NONE)
90 | exp (SOME (ELocal exp, (expleft, expright)))
91
9fc2614f 92
93exp : apps (apps)
64014a03 94 | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, SOME typ, exp),
95 (BSLASHleft, expright))
96 | BSLASH SYMBOL ARROW exp (ELam (SYMBOL, NONE, exp), (BSLASHleft, expright))
9fc2614f 97 | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
98 | exp SEMI exp (let
99 val ls = case #1 exp2 of
100 ESeq ls => exp :: ls
101 | _ => [exp1, exp2]
102 in
103 (ESeq ls, (exp1left, exp2right))
104 end)
e680130a 105 | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright))
106 | apps WITH END (EWith (apps, (ESkip, (WITHleft, ENDright))), (appsleft, ENDright))
107 | apps WITH exp END (EWith (apps, exp), (appsleft, ENDright))
9fc2614f 108
109apps : term (term)
110 | apps term (EApp (apps, term), (appsleft, termright))
111
112term : LPAREN exp RPAREN (exp)
113 | INT (EInt INT, (INTleft, INTright))
114 | STRING (EString STRING, (STRINGleft, STRINGright))
115 | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright))
7d3ae99f 116 | LET exp IN exp END (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)),
117 (LETleft, ENDright))
ccc91989 118 | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright))
9fc2614f 119
120elist : ([])
121 | elistNe (elistNe)
122
123elistNe: exp ([exp])
124 | exp COMMA elistNe (exp :: elistNe)
125
126typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright))
ccc91989 127 | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright))
128 | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright))
7d3ae99f 129 | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right))
ccc91989 130 | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty),
7d3ae99f 131 (LBRACKleft, recdright))
ccc91989 132 | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty),
7d3ae99f 133 (LBRACKleft, ctxtright))
ccc91989 134 | LPAREN typ RPAREN (typ)
e680130a 135 | ctxt DARROW ctxt (TNested (ctxt1, ctxt2), (ctxt1left, ctxt2right))
ccc91989 136
137recd : LBRACE RBRACE (StringMap.empty)
138 | LBRACE recdNe RBRACE (recdNe)
139
140recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ))
141 | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ))
142
143ctxt : ROOT (CRoot, (ROOTleft, ROOTright))
144 | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright))
145 | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright))
146 | BANG ctxt (CNot ctxt, (BANGleft, ctxtright))
147 | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right))
148 | LPAREN ctxt RPAREN (ctxt)