Exemple #1
0
        public IASTNode HandleIdentifierError(IToken token, RecognitionException ex)
        {
            if (token is HqlToken)
            {
                HqlToken hqlToken = (HqlToken)token;

                // ... and the token could be an identifer and the error is
                // a mismatched token error ...
                if (hqlToken.PossibleId && (ex is MismatchedTokenException))
                {
                    MismatchedTokenException mte = (MismatchedTokenException)ex;

                    // ... and the expected token type was an identifier, then:
                    if (mte.Expecting == IDENT)
                    {
                        // Use the token as an identifier.
                        _parseErrorHandler.ReportWarning("Keyword  '"
                                                         + token.Text
                                                         + "' is being interpreted as an identifier due to: " + mte.Message);

                        // Add the token to the AST.

                        token.Type = WEIRD_IDENT;

                        input.Consume();
                        return((IASTNode)adaptor.Create(token));
                    }
                }
            }

            // Otherwise, handle the error normally.
            ReflectHelper.PreserveStackTrace(ex);
            throw ex;
        }
		public override IToken Emit()
		{
			var t = new HqlToken(input,
																state.type,
																state.channel,
																state.tokenStartCharIndex,
																CharIndex - 1) {Line = state.tokenStartLine, Text = state.text};

			Emit(t);
			return t;
		}
Exemple #3
0
        public void WeakKeywords()
        {
            int t = input.LA(1);

            switch (t)
            {
            case ORDER:
            case GROUP:
                // Case 1: Multi token keywords GROUP BY and ORDER BY
                // The next token ( LT(2) ) should be 'by'... otherwise, this is just an ident.
                if (input.LA(2) != LITERAL_by)
                {
                    input.LT(1).Type = IDENT;
                    if (log.IsDebugEnabled())
                    {
                        log.Debug("weakKeywords() : new LT(1) token - {0}", input.LT(1));
                    }
                }
                break;

            case LEFT:
            case RIGHT:
                // Support left and right functions
                if (input.LA(2) == OPEN)
                {
                    input.LT(1).Type = IDENT;
                    if (log.IsDebugEnabled())
                    {
                        log.Debug("weakKeywords() : new LT(1) token - {0}", input.LT(1));
                    }
                }
                break;

            default:
                // Case 2: The current token is after FROM and before '.'.
                if (t != IDENT && input.LA(-1) == FROM && ((input.LA(2) == DOT) || (input.LA(2) == IDENT) || (input.LA(2) == -1)))
                {
                    HqlToken hqlToken = input.LT(1) as HqlToken;
                    if (hqlToken != null && hqlToken.PossibleId)
                    {
                        hqlToken.Type = IDENT;
                        if (log.IsDebugEnabled())
                        {
                            log.Debug("weakKeywords() : new LT(1) token - {0}", input.LT(1));
                        }
                    }
                }
                break;
            }
        }
        public override IToken Emit()
        {
            var t = new HqlToken(input,
                                 state.type,
                                 state.channel,
                                 state.tokenStartCharIndex,
                                 CharIndex - 1)
            {
                Line = state.tokenStartLine, Text = state.text
            };

            Emit(t);
            return(t);
        }
Exemple #5
0
        public void WeakKeywords2()
        {
            /*
             * path
             * alias in class? path
             * in open path close
             * alias in elements open path close
             * elements open path close
             * alias in path dot elements
             */
            int t = input.LA(1);

            switch (t)
            {
            case ORDER:
            case GROUP:
                // Case 1: Multi token keywords GROUP BY and ORDER BY
                // The next token ( LT(2) ) should be 'by'... otherwise, this is just an ident.
                if (input.LA(2) != LITERAL_by)
                {
                    input.LT(1).Type = IDENT;
                    if (log.IsDebugEnabled())
                    {
                        log.Debug("weakKeywords() : new LT(1) token - {0}", input.LT(1));
                    }
                }
                break;

            default:
                // Case 2: The current token is after FROM and before '.'.
                if (t != IDENT && input.LA(-1) == FROM && input.LA(2) == DOT)
                {
                    HqlToken hqlToken = (HqlToken)input.LT(1);
                    if (hqlToken.PossibleId)
                    {
                        hqlToken.Type = IDENT;
                        if (log.IsDebugEnabled())
                        {
                            log.Debug("weakKeywords() : new LT(1) token - {0}", input.LT(1));
                        }
                    }
                }
                break;
            }
        }
Exemple #6
0
 public void HandleDotIdent()
 {
     // This handles HHH-354, where there is a strange property name in a where clause.
     // If the lookahead contains a DOT then something that isn't an IDENT...
     if (input.LA(1) == DOT && input.LA(2) != IDENT)
     {
         // See if the second lookahed token can be an identifier.
         HqlToken t = input.LT(2) as HqlToken;
         if (t != null && t.PossibleId)
         {
             // Set it!
             input.LT(2).Type = IDENT;
             if (log.IsDebugEnabled())
             {
                 log.Debug("handleDotIdent() : new LT(2) token - {0}", input.LT(1));
             }
         }
     }
 }
Exemple #7
0
        public void WeakKeywords()
        {
            int t = input.LA(1);

            switch (t)
            {
            case ORDER:
            case GROUP:
                // Case 1: Multi token keywords GROUP BY and ORDER BY
                // The next token ( LT(2) ) should be 'by'... otherwise, this is just an ident.
                if (input.LA(2) != LITERAL_by)
                {
                    input.LT(1).Type = IDENT;
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("weakKeywords() : new LT(1) token - " + input.LT(1));
                    }
                }
                break;

            default:
                // Case 2: The current token is after FROM and before '.'.
                if (t != IDENT && input.LA(-1) == FROM && ((input.LA(2) == DOT) || (input.LA(2) == IDENT) || (input.LA(2) == -1)))
                {
                    HqlToken hqlToken = (HqlToken)input.LT(1);
                    if (hqlToken.PossibleId)
                    {
                        hqlToken.Type = IDENT;
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("weakKeywords() : new LT(1) token - " + input.LT(1));
                        }
                    }
                }
                break;
            }
        }