root/trunk/ProjectFortress/src/com/sun/fortress/parser/Parameter.rats @ 2230

Revision 2230, 11.9 KB (checked in by nbeckman, 17 months ago)

[parser] Fixed spelling.

Line 
1/*******************************************************************************
2    Copyright 2008 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16 ******************************************************************************/
17
18/*
19 * Definition of Fortress parameters.
20 */
21module com.sun.fortress.parser.Parameter(NoNewlineHeader, MayNewlineHeader,
22                                         Type, Expr, Identifier, Keyword,
23                                         Symbol, Spacing);
24
25import NoNewlineHeader;
26import MayNewlineHeader;
27import Type;
28import Expr;
29import Identifier;
30import Keyword;
31import Symbol;
32import Spacing;
33
34/* ValParam ::= BindId | ( (w Params)? w ) */
35List<Param> ValParam =
36     a1:BindId
37     { yyValue = FortressUtil.<Param, NormalParam>mkList(NodeFactory.makeParam(a1)); }
38   / openparen a1:(w Params)? w closeparen
39     { if (a1 == null) yyValue = FortressUtil.emptyParams();
40       else            yyValue = a1;
41     };
42
43/* AbsValParam ::= ( (w AbsParams)? w ) | Type */
44List<Param> AbsValParam =
45     openparen a1:(w AbsParams)? w closeparen
46     { if (a1 == null) yyValue = FortressUtil.emptyParams();
47       else            yyValue = a1;
48     }
49   / a1:Type
50     { yyValue = FortressUtil.<Param, NormalParam>mkList(NodeFactory.makeAbsParam(a1)); };
51
52/* Params ::=
53     (Param w , w)* (Varargs w , w)? Keyword (w , w Keyword)*
54   | (Param w , w)*  Varargs
55   |  Param (w , w Param)*
56 */
57List<Param> Params =
58     <ErrorProduction1>
59     (Param w comma w)+ (Keyword w comma w)+ Varargs
60     { yyValue = syntaxError(createSpan(yyStart,yyCount),
61                             "Varargs parameters should come before keyword parameters.");
62     }
63   / <ErrorProduction2>
64     Varargs w comma w (Keyword w comma w)+ Param (w comma w Param)*
65     { yyValue = syntaxError(createSpan(yyStart,yyCount),
66                             "Normal parameters should come before varargs parameters and keyword parameters.");
67     }
68   / <ErrorProduction3>
69     Varargs (w comma w Param)+ (w comma w Keyword)*
70     { yyValue = syntaxError(createSpan(yyStart,yyCount),
71                             "Normal parameters should come before varargs parameters.");
72     }
73   / a1s:(Param w comma w)* a2:(Varargs w comma w)? a3:Keyword
74       a4s:(w comma w Keyword)*
75     { yyValue = FortressUtil.<Param, NormalParam>mkList(a1s.list());
76       if (a2 != null) yyValue.add(a2);
77       yyValue.add(a3);
78       yyValue.addAll(a4s.list());
79     }
80   / a1s:(Param w comma w)* a2:Varargs
81     { yyValue = FortressUtil.<Param, NormalParam>mkList(a1s.list(), a2); }
82   / a1:Param a2s:(w comma w Param)*
83     { yyValue = FortressUtil.<Param, NormalParam>mkList(a1, a2s.list()); };
84
85/* AbsParams ::=
86     (AbsParam w , w)* (Varargs w , w)? Keyword (w , w Keyword)*
87   | (AbsParam w , w)*  Varargs
88   |  AbsParam (w , w AbsParam)*
89 */
90List<Param> AbsParams =
91     <ErrorProduction1>
92     (AbsParam w comma w)+ (Keyword w comma w)+ Varargs
93     { yyValue = syntaxError(createSpan(yyStart,yyCount),
94                             "Varargs parameters should come before keyword parameters.");
95     }
96   / <ErrorProduction2>
97     Varargs w comma w (Keyword w comma w)+ AbsParam (w comma w AbsParam)*
98     { yyValue = syntaxError(createSpan(yyStart,yyCount),
99                             "Normal parameters should come before varargs parameters and keyword parameters.");
100     }
101   / <ErrorProduction3>
102     Varargs (w comma w AbsParam)+ (w comma w Keyword)*
103     { yyValue = syntaxError(createSpan(yyStart,yyCount),
104                             "Normal parameters should come before varargs parameters.");
105     }
106   / a1s:(AbsParam w comma w)* a2:(Varargs w comma w)? a3:Keyword
107       a4s:(w comma w Keyword)*
108     { yyValue = FortressUtil.<Param, NormalParam>mkList(a1s.list());
109       if (a2 != null) yyValue.add(a2);
110       yyValue.add(a3);
111       yyValue.addAll(a4s.list());
112     }
113   / a1s:(AbsParam w comma w)* a2:Varargs
114     { yyValue = FortressUtil.<Param, NormalParam>mkList(a1s.list(), a2); }
115   / a1:AbsParam a2s:(w comma w AbsParam)*
116     { yyValue = FortressUtil.<Param, NormalParam>mkList(a1, a2s.list()); };
117
118/* Varargs ::= BindId w : w Type w ... */
119VarargsParam VarargsParam = a1:BindId w colon w a2:Type w ellipses
120     { yyValue = NodeFactory.makeVarargsParam(a1, a2); };
121VarargsParam Varargs = VarargsParam ;
122
123/* Keyword ::= Param w = w Expr */
124Param Keyword = a1:Param w equals w a2:Expr
125     { yyValue = NodeFactory.makeParam(a1, a2); };
126
127/* Param ::= BindId (w IsType)? */
128NormalParam PlainParam =
129     a1:BindId a2:(w IsType)?
130     { if (a2 != null) yyValue = NodeFactory.makeParam(a1, a2);
131       else            yyValue = NodeFactory.makeParam(a1);
132     };
133NormalParam Param = PlainParam ;
134
135/* AbsParam ::= BindId w IsType | Type */
136NormalParam AbsPlainParam =
137     a1:BindId w a2:IsType
138     { yyValue = NodeFactory.makeParam(a1, a2); }
139   / a1:Type
140     { yyValue = NodeFactory.makeAbsParam(a1); };
141NormalParam AbsParam = AbsPlainParam ;
142
143/* OpHeaderFront ::=
144     opr (w BIG)? w ({ w |-> | LeftEncloser | Encloser) (w StaticParams)?
145     (w Params)? w (RightEncloser | Encloser)
146   | opr w ValParam w (Op | ExponentOp) (w StaticParams)?
147   | opr (w BIG)? w (Op | ^ | Encloser | SUM | PROD) (w StaticParams)? w ValParam
148 */
149FnHeaderFront OpHeaderFront =
150     <Enclosing> opr big:(w BIG)? w
151     opa1:("{" w "|->"
152           {yyValue=NodeFactory.makeOpEnclosing(createSpan(yyStart,yyCount),
153                                                "{|->");}
154         / LeftEncloser
155         / Encloser)
156     opa2:(w StaticParams)? opa3:(w Params)? w opa4:(RightEncloser / Encloser)
157     { IdOrOpOrAnonymousName name;
158       Span span = createSpan(yyStart,yyCount);
159       Op leftOp = (Op)opa1;
160       String left  = leftOp.getText();
161       String right = opa4.getText();
162       if (PrecedenceMap.ONLY.matchedBrackets(left, right) ||
163           left.equals("{|->") && right.equals("}")) {
164           if (big != null) {
165               leftOp = NodeFactory.makeOpBig(leftOp.getSpan(), "BIG " + left);
166               opa4 = NodeFactory.makeOpBig(opa4.getSpan(), "BIG " + right);
167           }
168           name = new Enclosing(span, leftOp, opa4);
169       } else
170           name = syntaxError(leftOp.getSpan(),
171                              "Mismatched enclosing operator definition: " +
172                              left + " and " + right);
173       if (opa2 == null) opa2 = FortressUtil.emptyStaticParams();
174       if (opa3 == null) opa3 = FortressUtil.emptyParams();
175       yyValue = new FnHeaderFront(name, opa2, opa3);
176     }
177   / opr w a1:ValParam w a2:(Op / ExponentOp) a3:(w StaticParams)?
178     { Span span = createSpan(yyStart,yyCount);
179       if (a3 == null)
180           yyValue = new FnHeaderFront(NodeFactory.makeOpPostfix(a2), a1);
181       else
182           yyValue = new FnHeaderFront(NodeFactory.makeOpPostfix(a2), a3, a1);
183     }
184   / opr big:(w BIG)? w
185     a1:(Op
186        / caret {yyValue=NodeFactory.makeOpUnknown(createSpan(yyStart,yyCount),
187                                                   "^");}
188        / Encloser
189        / SUM  {yyValue=NodeFactory.makeOpBig(createSpan(yyStart,yyCount),
190                                              "BIG +");}
191        / PROD {yyValue=NodeFactory.makeOpBig(createSpan(yyStart,yyCount),
192                                              "BIG juxtaposition");})
193     a2:(w StaticParams)? w a3:ValParam
194     { Span span = createSpan(yyStart,yyCount);
195       Op op = (Op)a1;
196       if (big != null)
197           op = NodeFactory.makeOpBig(op.getSpan(), "BIG " + op.getText());
198       else if (op.getText().equals("BIG +") ||
199                op.getText().equals("BIG juxtaposition")) {
200           op = op;
201       } else if (a3.size() == 0) { // nofix
202           op = NodeFactory.makeOpNofix(op);
203       } else if (NodeUtil.isMultifix(a3)) { // multifix
204           op = NodeFactory.makeOpMultifix(op);
205       } else if (a3.size() == 1) { // prefix
206           op = NodeFactory.makeOpPrefix(op);
207       } else if (a3.size() == 2) { // infix
208           op = NodeFactory.makeOpInfix(op);
209       } else { // error
210           op = syntaxError(op.getSpan(),
211                            "Operator fix is invalid in its declaration.");
212       }
213       if (a2 == null) yyValue = new FnHeaderFront(op, a3);
214       else            yyValue = new FnHeaderFront(op, a2, a3);
215     };
216
217/* AbsOpHeaderFront ::=
218     opr (w BIG)? w ({ w |-> | LeftEncloser | Encloser) (w StaticParams)?
219     (w AbsParams)? w (RightEncloser | Encloser)
220   | opr w AbsValParam w (Op | ExponentOp) (w StaticParams)?
221   | opr (w BIG)? w (Op | ^ | Encloser | SUM | PROD) (w StaticParams)? w AbsValParam
222 */
223FnHeaderFront AbsOpHeaderFront =
224     <Enclosing> opr big:(w BIG)? w
225     opa1:("{" w "|->"
226           {yyValue=NodeFactory.makeOpEnclosing(createSpan(yyStart,yyCount),
227                                                "{|->");}
228         / LeftEncloser
229         / Encloser)
230     opa2:(w StaticParams)? opa3:(w AbsParams)? w opa4:(RightEncloser / Encloser)
231     { IdOrOpOrAnonymousName name;
232       Span span = createSpan(yyStart,yyCount);
233       Op leftOp = (Op)opa1;
234       String left  = leftOp.getText();
235       String right = opa4.getText();
236       if (PrecedenceMap.ONLY.matchedBrackets(left, right) ||
237           left.equals("{|->") && right.equals("}")) {
238           if (big != null) {
239               leftOp = NodeFactory.makeOpBig(leftOp.getSpan(), "BIG " + left);
240               opa4 = NodeFactory.makeOpBig(opa4.getSpan(), "BIG " + right);
241           }
242           name = new Enclosing(span, leftOp, opa4);
243       } else
244           name = syntaxError(leftOp.getSpan(),
245                              "Mismatched enclosing operator definition: " +
246                              left + " and " + right);
247       if (opa2 == null) opa2 = FortressUtil.emptyStaticParams();
248       if (opa3 == null) opa3 = FortressUtil.emptyParams();
249       yyValue = new FnHeaderFront(name, opa2, opa3);
250     }
251   / opr w a1:AbsValParam w a2:(Op / ExponentOp) a3:(w StaticParams)?
252     { Span span = createSpan(yyStart,yyCount);
253       if (a3 == null)
254           yyValue = new FnHeaderFront(NodeFactory.makeOpPostfix(a2), a1);
255       else
256           yyValue = new FnHeaderFront(NodeFactory.makeOpPostfix(a2), a3, a1);
257     }
258   / opr big:(w BIG)? w
259     a1:(Op
260        / caret {yyValue=NodeFactory.makeOpUnknown(createSpan(yyStart,yyCount),
261                                                   "^");}
262        / Encloser
263        / SUM  {yyValue=NodeFactory.makeOpBig(createSpan(yyStart,yyCount),
264                                              "BIG +");}
265        / PROD {yyValue=NodeFactory.makeOpBig(createSpan(yyStart,yyCount),
266                                              "BIG juxtaposition");})
267     a2:(w StaticParams)? w a3:AbsValParam
268     { Span span = createSpan(yyStart,yyCount);
269       Op op = (Op)a1;
270       if (big != null)
271           op = NodeFactory.makeOpBig(op.getSpan(), "BIG " + op.getText());
272       else if (op.getText().equals("BIG +") ||
273                op.getText().equals("BIG juxtaposition")) {
274           op = op;
275       } else if (a3.size() == 0) { // nofix
276           op = NodeFactory.makeOpNofix(op);
277       } else if (NodeUtil.isMultifix(a3)) { // multifix
278           op = NodeFactory.makeOpMultifix(op);
279       } else if (a3.size() == 1) { // prefix
280           op = NodeFactory.makeOpPrefix(op);
281       } else if (a3.size() == 2) { // infix
282           op = NodeFactory.makeOpInfix(op);
283       } else { // error
284           op = syntaxError(op.getSpan(),
285                            "Operator fix is invalid in its declaration.");
286       }
287       if (a2 == null) yyValue = new FnHeaderFront(op, a3);
288       else            yyValue = new FnHeaderFront(op, a2, a3);
289     };
Note: See TracBrowser for help on using the browser.