Basic type-checking
[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.
17*)
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
29 | STRING of string
30 | INT of int
63920aa5
AC
31 | ARROW | DARROW | LARROW
32 | COLON | CARET | BANG | AND
42198578
AC
33 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
34 | EQ | COMMA | BSLASH | SEMI | LET | IN | END
a22c187b 35 | ROOT
42198578
AC
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
63920aa5 46 | ctxt of pred
a22c187b
AC
47 | recd of record
48 | recdNe of record
42198578
AC
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
a22c187b 60%nonassoc COLON
42198578 61%nonassoc IN
a22c187b 62%right ARROW DARROW
42198578
AC
63%right COMMA
64%nonassoc EQ
a22c187b
AC
65%right AND
66%nonassoc CARET BANG
42198578
AC
67
68%%
69
70file : exp (exp)
71
72exp : apps (apps)
27d9de59
AC
73 | BSLASH SYMBOL COLON LPAREN typ RPAREN ARROW exp (ELam (SYMBOL, SOME typ, exp),
74 (BSLASHleft, expright))
75 | BSLASH SYMBOL ARROW exp (ELam (SYMBOL, NONE, exp), (BSLASHleft, expright))
42198578
AC
76 | CSYMBOL EQ exp (ESet (CSYMBOL, exp), (CSYMBOLleft, expright))
77 | exp SEMI exp (let
78 val ls = case #1 exp2 of
79 ESeq ls => exp :: ls
80 | _ => [exp1, exp2]
81 in
82 (ESeq ls, (exp1left, exp2right))
83 end)
63920aa5 84 | SYMBOL LARROW CSYMBOL SEMI exp (EGet (SYMBOL, CSYMBOL, exp), (SYMBOLleft, expright))
42198578
AC
85
86apps : term (term)
87 | apps term (EApp (apps, term), (appsleft, termright))
88
89term : LPAREN exp RPAREN (exp)
90 | INT (EInt INT, (INTleft, INTright))
91 | STRING (EString STRING, (STRINGleft, STRINGright))
92 | LBRACK elist RBRACK (EList elist, (LBRACKleft, RBRACKright))
63920aa5
AC
93 | LET exp IN exp END (ELocal (ESeq [exp1, exp2], (LETleft, ENDright)),
94 (LETleft, ENDright))
a22c187b 95 | SYMBOL (EVar SYMBOL, (SYMBOLleft, SYMBOLright))
42198578
AC
96
97elist : ([])
98 | elistNe (elistNe)
99
100elistNe: exp ([exp])
101 | exp COMMA elistNe (exp :: elistNe)
102
103typ : SYMBOL (TBase SYMBOL, (SYMBOLleft, SYMBOLright))
a22c187b
AC
104 | LBRACK typ RBRACK (TList typ, (LBRACKleft, RBRACKright))
105 | typ ARROW typ (TArrow (typ1, typ2), (typleft, typright))
63920aa5 106 | LBRACK ctxt RBRACK recd DARROW recd (TAction (ctxt, recd1, recd2), (LBRACKleft, recd2right))
a22c187b 107 | LBRACK ctxt RBRACK recd (TAction (ctxt, recd, StringMap.empty),
63920aa5 108 (LBRACKleft, recdright))
a22c187b 109 | LBRACK ctxt RBRACK (TAction (ctxt, StringMap.empty, StringMap.empty),
63920aa5 110 (LBRACKleft, ctxtright))
a22c187b
AC
111 | LPAREN typ RPAREN (typ)
112
113recd : LBRACE RBRACE (StringMap.empty)
114 | LBRACE recdNe RBRACE (recdNe)
115
116recdNe : CSYMBOL COLON typ (StringMap.insert (StringMap.empty, CSYMBOL, typ))
117 | CSYMBOL COLON typ COMMA recdNe (StringMap.insert (recdNe, CSYMBOL, typ))
118
119ctxt : ROOT (CRoot, (ROOTleft, ROOTright))
120 | CSYMBOL (CConst CSYMBOL, (CSYMBOLleft, CSYMBOLright))
121 | CARET ctxt (CPrefix ctxt, (CARETleft, ctxtright))
122 | BANG ctxt (CNot ctxt, (BANGleft, ctxtright))
123 | ctxt AND ctxt (CAnd (ctxt1, ctxt2), (ctxt1left, ctxt2right))
124 | LPAREN ctxt RPAREN (ctxt)