Mercurial > urweb
comparison src/lacweb.grm @ 1:4202f6eda946
Initial parsing and pretty-printing
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 26 Jan 2008 12:35:32 -0500 |
parents | |
children | 5c3cc348e9e6 |
comparison
equal
deleted
inserted
replaced
0:502c6d622477 | 1:4202f6eda946 |
---|---|
1 (* Copyright (c) 2008, Adam Chlipala | |
2 * All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are met: | |
6 * | |
7 * - Redistributions of source code must retain the above copyright notice, | |
8 * this list of conditions and the following disclaimer. | |
9 * - Redistributions in binary form must reproduce the above copyright notice, | |
10 * this list of conditions and the following disclaimer in the documentation | |
11 * and/or other materials provided with the distribution. | |
12 * - The names of contributors may not be used to endorse or promote products | |
13 * derived from this software without specific prior written permission. | |
14 * | |
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
25 * POSSIBILITY OF SUCH DAMAGE. | |
26 *) | |
27 | |
28 (* Grammar for Laconic/Web programs *) | |
29 | |
30 open Laconic | |
31 | |
32 val s = ErrorMsg.spanOf | |
33 | |
34 %% | |
35 %header (functor LacwebLrValsFn(structure Token : TOKEN)) | |
36 | |
37 %term | |
38 EOF | |
39 | SYMBOL of string | CSYMBOL of string | |
40 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE | |
41 | EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | |
42 | CON | TYPE | NAME | |
43 | ARROW | LARROW | DARROW | |
44 | FN | PLUSPLUS | DOLLAR | |
45 | |
46 %nonterm | |
47 file of decl list | |
48 | decls of decl list | |
49 | decl of decl | |
50 | |
51 | kind of kind | |
52 | kcolon of explicitness | |
53 | |
54 | cexp of con | |
55 | capps of con | |
56 | cterm of con | |
57 | ident of con | |
58 | rcon of (con * con) list | |
59 | rcone of (con * con) list | |
60 | |
61 %verbose (* print summary of errors *) | |
62 %pos int (* positions *) | |
63 %start file | |
64 %pure | |
65 %eop EOF | |
66 %noshift EOF | |
67 | |
68 %name Lacweb | |
69 | |
70 %nonassoc DARROW | |
71 %nonassoc COLON | |
72 %right COMMA | |
73 %right ARROW LARROW | |
74 %right PLUSPLUS | |
75 %nonassoc DOLLAR | |
76 %left DOT | |
77 | |
78 %% | |
79 | |
80 file : decls (decls) | |
81 | |
82 decls : ([]) | |
83 | decl decls (decl :: decls) | |
84 | |
85 decl : CON SYMBOL EQ cexp (DCon (SYMBOL, NONE, cexp), s (CONleft, cexpright)) | |
86 | CON SYMBOL DCOLON kind EQ cexp (DCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright)) | |
87 | |
88 kind : TYPE (KType, s (TYPEleft, TYPEright)) | |
89 | NAME (KName, s (NAMEleft, NAMEright)) | |
90 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright)) | |
91 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right)) | |
92 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright)) | |
93 | |
94 capps : cterm (cterm) | |
95 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright)) | |
96 | |
97 cexp : capps (capps) | |
98 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right)) | |
99 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright)) | |
100 | |
101 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right)) | |
102 | |
103 | FN SYMBOL kcolon kind DARROW cexp (CAbs (kcolon, SYMBOL, kind, cexp), s (FNleft, cexpright)) | |
104 | |
105 kcolon : DCOLON (Explicit) | |
106 | TCOLON (Implicit) | |
107 | |
108 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright)) | |
109 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright)) | |
110 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)), | |
111 s (LBRACEleft, RBRACEright)) | |
112 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright)) | |
113 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright)) | |
114 | |
115 | SYMBOL (CVar SYMBOL, s (SYMBOLleft, SYMBOLright)) | |
116 | |
117 rcon : ([]) | |
118 | ident EQ cexp ([(ident, cexp)]) | |
119 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon) | |
120 | |
121 rcone : ([]) | |
122 | ident COLON cexp ([(ident, cexp)]) | |
123 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone) | |
124 | |
125 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright)) | |
126 | SYMBOL (CVar SYMBOL, s (SYMBOLleft, SYMBOLright)) |