KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > parsing > ejbql > GrammarSpecial


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.parsing.ejbql;
23
24
25 /**
26  * This class provides for versioning of the grammar
27  */

28 public class GrammarSpecial {
29     //This shows the grammar (in comment form), copied directly from "EJBQLParser.g"
30
public static void grammar() {
31
32         /*
33         // Added 20/12/2000 JED. Define the package for the class
34         header {
35         package oracle.toplink.essentials.internal.parsing.ejbql;
36         }
37
38         class EJBQLParser extends Parser;
39         options {
40         exportVocab=EJBQL;
41         k = 2; // This is the number of tokens to look ahead to
42         buildAST = true;
43         }
44
45         tokens {
46         FROM="FROM";
47         WHERE="WHERE";
48         OR="OR";
49         AND="AND";
50         TRUE="TRUE";
51         FALSE="FALSE";
52         BETWEEN="BETWEEN";
53         CONCAT="CONCAT";
54         SUBSTRING="SUBSTRING";
55         LENGTH="LENGTH";
56         LOCATE="LOCATE";
57         ABS="ABS";
58         SQRT="SQRT";
59         IS="IS";
60         UNKNOWN="UNKNOWN";
61         LIKE="LIKE";
62         NOT="NOT";
63         PERCENT="%";
64         UNDERSCORE="_";
65         IN="IN";
66         NULL="NULL";
67         EMPTY="EMPTY";
68         AS="AS";
69         }
70
71         document
72         : (fromClause) (whereClause)?
73         ;
74
75         //================================================
76         fromClause
77         : from identificationVariableDeclaration (COMMA identificationVariableDeclaration)*
78         ;
79
80         from
81         : FROM {matchedFrom();}
82         ;
83
84         identificationVariableDeclaration
85         : collectionMemberDeclaration
86         | rangeVariableDeclaration
87         ;
88
89         collectionMemberDeclaration
90         : identifier IN singleValuedNavigation
91         ;
92
93         rangeVariableDeclaration
94         : abstractSchemaName (AS)? abstractSchemaIdentifier
95         ;
96
97         singleValuedPathExpression
98         // : (singleValuedNavigation | identifier) DOT^ identifier
99         : singleValuedNavigation
100         ;
101
102         singleValuedNavigation
103         : identifier dot (identifier dot)* identifier
104         ;
105
106         //collectionValuedPathExpression
107         // : identifier DOT^ (identifier DOT^)* identifier
108
109         //================================================
110
111         //from
112         // : (FROM) {matchedFrom();} abstractSchemaClause (whereClause)?
113         // ;
114
115         //Abstract Schema
116         //abstractSchemaClause
117         // : abstractSchemaName (abstractSchemaVariableClause)?
118         // ;
119
120         abstractSchemaName
121         : TEXTCHAR {matchedAbstractSchemaName();}
122         ;
123
124         abstractSchemaIdentifier
125         : identifier {matchedAbstractSchemaIdentifier();}
126         ;
127
128         dot
129         : DOT^ {matchedDot();}
130         ;
131
132         identifier
133         : TEXTCHAR {matchedIdentifier();}
134         ;
135
136         whereClause
137         : WHERE {matchedWhere();} conditionalExpression
138         ;
139
140         conditionalExpression
141         : conditionalTerm (OR{matchedOr();} conditionalTerm {finishedOr();})*
142         ;
143
144         conditionalTerm
145         : {conditionalTermFound();} conditionalFactor (AND{matchedAnd();} conditionalFactor {finishedAnd();})*
146         ;
147
148         conditionalFactor
149         : conditionalTest
150         ;
151
152         conditionalTest
153         : conditionalPrimary (isExpression (NOT)? (literalBoolean | UNKNOWN))?
154         ;
155
156         conditionalPrimary
157         : simpleConditionalExpression
158         | (LEFT_ROUND_BRACKET {matchedLeftRoundBracket();} conditionalExpression RIGHT_ROUND_BRACKET {matchedRightRoundBracket();})
159         ;
160
161         simpleConditionalExpression
162         : comparisonLeftOperand comparisonRemainder
163         ;
164
165         comparisonLeftOperand
166         : singleValuedPathExpression
167         ;
168
169         comparisonRemainder
170         : equalsRemainder
171         | betweenRemainder
172         | likeRemainder
173         | inRemainder
174         | nullRemainder
175         ;
176
177         comparisonExpression
178         : expressionOperandNotMagnitude equals expressionOperandNotMagnitude {finishedEquals();}
179         | expressionOperandMagnitude comparisonOperator expressionOperandMagnitude {finishedComparisonExpression();}
180         ;
181
182         equalsRemainder
183         : equals (stringExpression | literalNumeric | singleValuedPathExpression) {finishedEquals();}
184         ;
185
186         betweenRemainder
187         : (NOT {matchedNot();})? ((BETWEEN {matchedBetween();}) literalNumeric) AND
188             {matchedAndAfterBetween();} literalNumeric {finishedBetweenAnd();}
189         ;
190
191         likeRemainder
192         : (NOT {matchedNot();})? (LIKE {matchedLike();}) literalString {finishedLike();}
193         ;
194
195         inRemainder
196         : (NOT {matchedNot();})? (IN {matchedIn();})
197             (LEFT_ROUND_BRACKET
198                 (literalString|literalNumeric)
199                     (COMMA (literalString|literalNumeric))*
200             RIGHT_ROUND_BRACKET)
201             {finishedIn();}
202         ;
203
204         emptyCollectionRemainder
205         : IS (NOT {matchedNot();})? EMPTY {matchedEmpty();} {finishedEmpty();}
206         ;
207
208         nullRemainder
209         : IS (NOT {matchedNot();})? NULL {matchedNull();} {finishedNull();}
210         ;
211
212         arithmeticExpression
213         : literal
214         ;
215
216         stringExpression
217         : literalString
218         ;
219
220         expressionOperandNotMagnitude
221         : literalString
222         | singleValuedPathExpression
223         ;
224
225         expressionOperandMagnitude
226         : literalNumeric
227         // | singleValuedReferenceExpression
228         ;
229
230         singleValueDesignator
231         : singleValuedPathExpression
232         ;
233
234         singleValuedReferenceExpression
235         : variableName (DOT^ variableName)?
236         ;
237
238         singleValuedDesignator
239         : scalarExpression
240         ;
241
242         scalarExpression
243         : arithmeticExpression
244         ;
245
246         variableName
247         : TEXTCHAR {matchedVariableName();}
248         ;
249
250         isExpression
251         : (IS {matchedIs();})
252         ;
253
254         //Literals and Low level stuff
255
256         literal
257         : literalNumeric
258         | literalBoolean
259         | literalString
260         ;
261
262         literalNumeric
263         : NUM_INT {matchedInteger();}
264         | NUM_FLOAT^ {matchedFloat();}
265         ;
266
267         literalBoolean
268         : TRUE {matchedTRUE();}
269         | FALSE {matchedFALSE();}
270         ;
271
272         // Added Jan 9, 2001 JED
273         literalString
274         : STRING_LITERAL {matchedString();}
275         ;
276
277         // Added 20/12/2000 JED
278         comparisonOperator
279         : (equals|greaterThan|greaterThanEqualTo|lessThan|lessThanEqualTo|notEqualTo)
280         ;
281
282         equals
283         : (EQUALS) {matchedEquals();}
284         ;
285
286         greaterThan
287         : (GREATER_THAN) {matchedGreaterThan();}
288         ;
289
290         greaterThanEqualTo
291         : GREATER_THAN_EQUAL_TO {matchedGreaterThanEqualTo();}
292         ;
293
294         lessThan
295         : (LESS_THAN) {matchedLessThan();}
296         ;
297
298         lessThanEqualTo
299         : LESS_THAN_EQUAL_TO {matchedLessThanEqualTo();}
300         ;
301
302         notEqualTo
303         : (NOT_EQUAL_TO) {matchedNotEqualTo();}
304         ;
305
306         // End of addition 20/12/2000 JED
307
308         class EJBQLLexer extends Lexer;
309         options {
310         k = 4;
311         exportVocab=EJBQL;
312         charVocabulary = '\3'..'\377';
313         caseSensitive=true;
314         }
315
316         // hexadecimal digit (again, note it's protected!)
317         protected
318         HEX_DIGIT
319         : ('0'..'9'|'A'..'F'|'a'..'f')
320         ;
321
322         WS : (' ' | '\t' | '\n' | '\r')+
323         { $setType(Token.SKIP); } ;
324
325         LEFT_ROUND_BRACKET
326         : '('
327         ;
328
329         RIGHT_ROUND_BRACKET
330         : ')'
331         ;
332
333         COMMA
334         : ','
335         ;
336
337         TEXTCHAR
338         : ('a'..'z' | 'A'..'Z' | '_')+
339         ;
340
341         // a numeric literal
342         NUM_INT
343         {boolean isDecimal=false;}
344         : '.' {_ttype = DOT;}
345                 (('0'..'9')+ (EXPONENT)? (FLOAT_SUFFIX)? { _ttype = NUM_FLOAT; })?
346         | ( '0' {isDecimal = true;} // special case for just '0'
347                 ( ('x'|'X')
348                     ( // hex
349                         // the 'e'|'E' and float suffix stuff look
350                         // like hex digits, hence the (...)+ doesn't
351                         // know when to stop: ambig. ANTLR resolves
352                         // it correctly by matching immediately. It
353                         // is therefor ok to hush warning.
354                         options {
355                             warnWhenFollowAmbig=false;
356                         }
357                     : HEX_DIGIT
358                     )+
359                 | ('0'..'7')+ // octal
360                 )?
361             | ('1'..'9') ('0'..'9')* {isDecimal=true;} // non-zero decimal
362             )
363             ( ('l'|'L')
364
365             // only check to see if it's a float if looks like decimal so far
366             | {isDecimal}?
367                 ( '.' ('0'..'9')* (EXPONENT)? (FLOAT_SUFFIX)?
368                 | EXPONENT (FLOAT_SUFFIX)?
369                 | FLOAT_SUFFIX
370                 )
371                 { _ttype = NUM_FLOAT; }
372             )?
373         ;
374
375         // a couple protected methods to assist in matching floating point numbers
376         protected
377         EXPONENT
378         : ('e'|'E') ('+'|'-')? ('0'..'9')+
379         ;
380
381
382         protected
383         FLOAT_SUFFIX
384         : 'f'|'F'|'d'|'D'
385         ;
386
387         EQUALS
388         : '='
389         ;
390
391         GREATER_THAN
392         : '>'
393         ;
394
395         GREATER_THAN_EQUAL_TO
396         : ">="
397         ;
398
399         LESS_THAN
400         : '<'
401         ;
402
403         LESS_THAN_EQUAL_TO
404         : "<="
405         ;
406
407         NOT_EQUAL_TO
408         : "<>"
409         ;
410
411         // Added Jan 9, 2001 JED
412         // string literals
413         STRING_LITERAL
414         : '"' (ESC|~('"'|'\\'))* '"'
415         ;
416
417         // Added Jan 9, 2001 JED
418         // escape sequence -- note that this is protected; it can only be called
419         // from another lexer rule -- it will not ever directly return a token to
420         // the parser
421         // There are various ambiguities hushed in this rule. The optional
422         // '0'...'9' digit matches should be matched here rather than letting
423         // them go back to STRING_LITERAL to be matched. ANTLR does the
424         // right thing by matching immediately; hence, it's ok to shut off
425         // the FOLLOW ambig warnings.
426         protected
427         ESC
428         : '\\'
429             ( 'n'
430             | 'r'
431             | 't'
432             | 'b'
433             | 'f'
434             | '"'
435             | '\''
436             | '\\'
437             | ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
438             | ('0'..'3')
439                 (
440                     options {
441                         warnWhenFollowAmbig = false;
442                     }
443                 : ('0'..'7')
444                     (
445                         options {
446                             warnWhenFollowAmbig = false;
447                         }
448                     : '0'..'7'
449                     )?
450                 )?
451             | ('4'..'7')
452                 (
453                     options {
454                         warnWhenFollowAmbig = false;
455                     }
456                 : ('0'..'9')
457                 )?
458             )
459         ;
460
461
462         */

463     }
464 }
465
Popular Tags