@@ -147,8 +147,8 @@ public void WeakKeywords()
147
147
// Case 2: The current token is after FROM and before '.'.
148
148
if ( t != IDENT && input . LA ( - 1 ) == FROM && ( ( input . LA ( 2 ) == DOT ) || ( input . LA ( 2 ) == IDENT ) || ( input . LA ( 2 ) == - 1 ) ) )
149
149
{
150
- HqlToken hqlToken = input . LT ( 1 ) as HqlToken ;
151
- if ( hqlToken != null && hqlToken . PossibleId )
150
+ var hqlToken = input . LT ( 1 ) ;
151
+ if ( IsPossibleId ( hqlToken ) )
152
152
{
153
153
hqlToken . Type = IDENT ;
154
154
if ( log . IsDebugEnabled ( ) )
@@ -192,8 +192,8 @@ public void WeakKeywords2()
192
192
// Case 2: The current token is after FROM and before '.'.
193
193
if ( t != IDENT && input . LA ( - 1 ) == FROM && input . LA ( 2 ) == DOT )
194
194
{
195
- HqlToken hqlToken = ( HqlToken ) input . LT ( 1 ) ;
196
- if ( hqlToken . PossibleId )
195
+ var hqlToken = input . LT ( 1 ) ;
196
+ if ( IsPossibleId ( hqlToken ) )
197
197
{
198
198
hqlToken . Type = IDENT ;
199
199
if ( log . IsDebugEnabled ( ) )
@@ -290,16 +290,8 @@ public IASTNode NegateNode(IASTNode node)
290
290
}
291
291
}
292
292
293
- public IASTNode ProcessEqualityExpression ( object o )
293
+ public IASTNode ProcessEqualityExpression ( IASTNode x )
294
294
{
295
- IASTNode x = o as IASTNode ;
296
-
297
- if ( x == null )
298
- {
299
- log . Warn ( "processEqualityExpression() : No expression to process!" ) ;
300
- return null ;
301
- }
302
-
303
295
int type = x . Type ;
304
296
if ( type == EQ || type == NE )
305
297
{
@@ -336,11 +328,11 @@ public void HandleDotIdent()
336
328
if ( input . LA ( 1 ) == DOT && input . LA ( 2 ) != IDENT )
337
329
{
338
330
// See if the second lookahed token can be an identifier.
339
- HqlToken t = input . LT ( 2 ) as HqlToken ;
340
- if ( t != null && t . PossibleId )
331
+ var t = input . LT ( 2 ) ;
332
+ if ( IsPossibleId ( t ) )
341
333
{
342
334
// Set it!
343
- input . LT ( 2 ) . Type = IDENT ;
335
+ t . Type = IDENT ;
344
336
if ( log . IsDebugEnabled ( ) )
345
337
{
346
338
log . Debug ( "handleDotIdent() : new LT(2) token - {0}" , input . LT ( 1 ) ) ;
@@ -401,37 +393,38 @@ public IASTNode ProcessMemberOf(IToken n, IASTNode p, IASTNode root)
401
393
402
394
public IASTNode HandleIdentifierError ( IToken token , RecognitionException ex )
403
395
{
404
- if ( token is HqlToken )
396
+ // ... and the token could be an identifier and the error is
397
+ // a mismatched token error ...
398
+ if ( IsPossibleId ( token ) && ( ex is MismatchedTokenException mte )
399
+ // ... and the expected token type was an identifier, then:
400
+ && mte . Expecting == IDENT )
405
401
{
406
- HqlToken hqlToken = ( HqlToken ) token ;
402
+ // Use the token as an identifier.
403
+ _parseErrorHandler . ReportWarning ( "Keyword '"
404
+ + token . Text
405
+ + "' is being interpreted as an identifier due to: " + mte . Message ) ;
407
406
408
- // ... and the token could be an identifer and the error is
409
- // a mismatched token error ...
410
- if ( hqlToken . PossibleId && ( ex is MismatchedTokenException ) )
411
- {
412
- MismatchedTokenException mte = ( MismatchedTokenException ) ex ;
413
-
414
- // ... and the expected token type was an identifier, then:
415
- if ( mte . Expecting == IDENT )
416
- {
417
- // Use the token as an identifier.
418
- _parseErrorHandler . ReportWarning ( "Keyword '"
419
- + token . Text
420
- + "' is being interpreted as an identifier due to: " + mte . Message ) ;
407
+ // Add the token to the AST.
421
408
422
- // Add the token to the AST.
409
+ token . Type = WEIRD_IDENT ;
423
410
424
- token . Type = WEIRD_IDENT ;
425
-
426
- input . Consume ( ) ;
427
- return ( IASTNode ) adaptor . Create ( token ) ;
428
- }
429
- }
411
+ input . Consume ( ) ;
412
+ return ( IASTNode ) adaptor . Create ( token ) ;
430
413
}
431
-
414
+
432
415
// Otherwise, handle the error normally.
433
416
ReflectHelper . PreserveStackTrace ( ex ) ;
434
417
throw ex ;
435
418
}
419
+
420
+ /// <summary>
421
+ /// Indicates if the token could be an identifier.
422
+ /// </summary>
423
+ /// <param name="token"></param>
424
+ public static bool IsPossibleId ( IToken token )
425
+ {
426
+ var type = token . Type ;
427
+ return type >= 0 && type < possibleIds . Length && possibleIds [ type ] ;
428
+ }
436
429
}
437
430
}
0 commit comments