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 grammar27 */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 class34 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 to42 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 document72 : (fromClause) (whereClause)?73 ;74 75 //================================================76 fromClause77 : from identificationVariableDeclaration (COMMA identificationVariableDeclaration)*78 ;79 80 from81 : FROM {matchedFrom();}82 ;83 84 identificationVariableDeclaration85 : collectionMemberDeclaration86 | rangeVariableDeclaration87 ;88 89 collectionMemberDeclaration90 : identifier IN singleValuedNavigation91 ;92 93 rangeVariableDeclaration94 : abstractSchemaName (AS)? abstractSchemaIdentifier95 ;96 97 singleValuedPathExpression98 // : (singleValuedNavigation | identifier) DOT^ identifier99 : singleValuedNavigation100 ;101 102 singleValuedNavigation103 : identifier dot (identifier dot)* identifier104 ;105 106 //collectionValuedPathExpression107 // : identifier DOT^ (identifier DOT^)* identifier108 109 //================================================110 111 //from112 // : (FROM) {matchedFrom();} abstractSchemaClause (whereClause)?113 // ;114 115 //Abstract Schema116 //abstractSchemaClause117 // : abstractSchemaName (abstractSchemaVariableClause)?118 // ;119 120 abstractSchemaName121 : TEXTCHAR {matchedAbstractSchemaName();}122 ;123 124 abstractSchemaIdentifier125 : identifier {matchedAbstractSchemaIdentifier();}126 ;127 128 dot129 : DOT^ {matchedDot();}130 ;131 132 identifier133 : TEXTCHAR {matchedIdentifier();}134 ;135 136 whereClause137 : WHERE {matchedWhere();} conditionalExpression138 ;139 140 conditionalExpression141 : conditionalTerm (OR{matchedOr();} conditionalTerm {finishedOr();})*142 ;143 144 conditionalTerm145 : {conditionalTermFound();} conditionalFactor (AND{matchedAnd();} conditionalFactor {finishedAnd();})*146 ;147 148 conditionalFactor149 : conditionalTest150 ;151 152 conditionalTest153 : conditionalPrimary (isExpression (NOT)? (literalBoolean | UNKNOWN))?154 ;155 156 conditionalPrimary157 : simpleConditionalExpression158 | (LEFT_ROUND_BRACKET {matchedLeftRoundBracket();} conditionalExpression RIGHT_ROUND_BRACKET {matchedRightRoundBracket();})159 ;160 161 simpleConditionalExpression162 : comparisonLeftOperand comparisonRemainder163 ;164 165 comparisonLeftOperand166 : singleValuedPathExpression167 ;168 169 comparisonRemainder170 : equalsRemainder171 | betweenRemainder172 | likeRemainder173 | inRemainder174 | nullRemainder175 ;176 177 comparisonExpression178 : expressionOperandNotMagnitude equals expressionOperandNotMagnitude {finishedEquals();}179 | expressionOperandMagnitude comparisonOperator expressionOperandMagnitude {finishedComparisonExpression();}180 ;181 182 equalsRemainder183 : equals (stringExpression | literalNumeric | singleValuedPathExpression) {finishedEquals();}184 ;185 186 betweenRemainder187 : (NOT {matchedNot();})? ((BETWEEN {matchedBetween();}) literalNumeric) AND188 {matchedAndAfterBetween();} literalNumeric {finishedBetweenAnd();}189 ;190 191 likeRemainder192 : (NOT {matchedNot();})? (LIKE {matchedLike();}) literalString {finishedLike();}193 ;194 195 inRemainder196 : (NOT {matchedNot();})? (IN {matchedIn();})197 (LEFT_ROUND_BRACKET198 (literalString|literalNumeric)199 (COMMA (literalString|literalNumeric))*200 RIGHT_ROUND_BRACKET)201 {finishedIn();}202 ;203 204 emptyCollectionRemainder205 : IS (NOT {matchedNot();})? EMPTY {matchedEmpty();} {finishedEmpty();}206 ;207 208 nullRemainder209 : IS (NOT {matchedNot();})? NULL {matchedNull();} {finishedNull();}210 ;211 212 arithmeticExpression213 : literal214 ;215 216 stringExpression217 : literalString218 ;219 220 expressionOperandNotMagnitude221 : literalString222 | singleValuedPathExpression223 ;224 225 expressionOperandMagnitude226 : literalNumeric227 // | singleValuedReferenceExpression228 ;229 230 singleValueDesignator231 : singleValuedPathExpression232 ;233 234 singleValuedReferenceExpression235 : variableName (DOT^ variableName)?236 ;237 238 singleValuedDesignator239 : scalarExpression240 ;241 242 scalarExpression243 : arithmeticExpression244 ;245 246 variableName247 : TEXTCHAR {matchedVariableName();}248 ;249 250 isExpression251 : (IS {matchedIs();})252 ;253 254 //Literals and Low level stuff255 256 literal257 : literalNumeric258 | literalBoolean259 | literalString260 ;261 262 literalNumeric263 : NUM_INT {matchedInteger();}264 | NUM_FLOAT^ {matchedFloat();}265 ;266 267 literalBoolean268 : TRUE {matchedTRUE();}269 | FALSE {matchedFALSE();}270 ;271 272 // Added Jan 9, 2001 JED273 literalString274 : STRING_LITERAL {matchedString();}275 ;276 277 // Added 20/12/2000 JED278 comparisonOperator279 : (equals|greaterThan|greaterThanEqualTo|lessThan|lessThanEqualTo|notEqualTo)280 ;281 282 equals283 : (EQUALS) {matchedEquals();}284 ;285 286 greaterThan287 : (GREATER_THAN) {matchedGreaterThan();}288 ;289 290 greaterThanEqualTo291 : GREATER_THAN_EQUAL_TO {matchedGreaterThanEqualTo();}292 ;293 294 lessThan295 : (LESS_THAN) {matchedLessThan();}296 ;297 298 lessThanEqualTo299 : LESS_THAN_EQUAL_TO {matchedLessThanEqualTo();}300 ;301 302 notEqualTo303 : (NOT_EQUAL_TO) {matchedNotEqualTo();}304 ;305 306 // End of addition 20/12/2000 JED307 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 protected318 HEX_DIGIT319 : ('0'..'9'|'A'..'F'|'a'..'f')320 ;321 322 WS : (' ' | '\t' | '\n' | '\r')+323 { $setType(Token.SKIP); } ;324 325 LEFT_ROUND_BRACKET326 : '('327 ;328 329 RIGHT_ROUND_BRACKET330 : ')'331 ;332 333 COMMA334 : ','335 ;336 337 TEXTCHAR338 : ('a'..'z' | 'A'..'Z' | '_')+339 ;340 341 // a numeric literal342 NUM_INT343 {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 ( // hex349 // the 'e'|'E' and float suffix stuff look350 // like hex digits, hence the (...)+ doesn't351 // know when to stop: ambig. ANTLR resolves352 // it correctly by matching immediately. It353 // is therefor ok to hush warning.354 options {355 warnWhenFollowAmbig=false;356 }357 : HEX_DIGIT358 )+359 | ('0'..'7')+ // octal360 )?361 | ('1'..'9') ('0'..'9')* {isDecimal=true;} // non-zero decimal362 )363 ( ('l'|'L')364 365 // only check to see if it's a float if looks like decimal so far366 | {isDecimal}?367 ( '.' ('0'..'9')* (EXPONENT)? (FLOAT_SUFFIX)?368 | EXPONENT (FLOAT_SUFFIX)?369 | FLOAT_SUFFIX370 )371 { _ttype = NUM_FLOAT; }372 )?373 ;374 375 // a couple protected methods to assist in matching floating point numbers376 protected377 EXPONENT378 : ('e'|'E') ('+'|'-')? ('0'..'9')+379 ;380 381 382 protected383 FLOAT_SUFFIX384 : 'f'|'F'|'d'|'D'385 ;386 387 EQUALS388 : '='389 ;390 391 GREATER_THAN392 : '>'393 ;394 395 GREATER_THAN_EQUAL_TO396 : ">="397 ;398 399 LESS_THAN400 : '<'401 ;402 403 LESS_THAN_EQUAL_TO404 : "<="405 ;406 407 NOT_EQUAL_TO408 : "<>"409 ;410 411 // Added Jan 9, 2001 JED412 // string literals413 STRING_LITERAL414 : '"' (ESC|~('"'|'\\'))* '"'415 ;416 417 // Added Jan 9, 2001 JED418 // escape sequence -- note that this is protected; it can only be called419 // from another lexer rule -- it will not ever directly return a token to420 // the parser421 // There are various ambiguities hushed in this rule. The optional422 // '0'...'9' digit matches should be matched here rather than letting423 // them go back to STRING_LITERAL to be matched. ANTLR does the424 // right thing by matching immediately; hence, it's ok to shut off425 // the FOLLOW ambig warnings.426 protected427 ESC428 : '\\'429 ( 'n'430 | 'r'431 | 't'432 | 'b'433 | 'f'434 | '"'435 | '\''436 | '\\'437 | ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT438 | ('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