未验证 提交 5a38bd81 编写于 作者: R Roman Artiukhin 提交者: GitHub

Move HqlToken.PossibleId to HqlParser.IsPossibleId method and remove castings (#3377)

上级 7a1bf08f
......@@ -147,8 +147,8 @@ public void WeakKeywords()
// 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)
var hqlToken = input.LT(1);
if (IsPossibleId(hqlToken))
{
hqlToken.Type = IDENT;
if (log.IsDebugEnabled())
......@@ -192,8 +192,8 @@ public void WeakKeywords2()
// 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)
var hqlToken = input.LT(1);
if (IsPossibleId(hqlToken))
{
hqlToken.Type = IDENT;
if (log.IsDebugEnabled())
......@@ -290,16 +290,8 @@ public IASTNode NegateNode(IASTNode node)
}
}
public IASTNode ProcessEqualityExpression(object o)
public IASTNode ProcessEqualityExpression(IASTNode x)
{
IASTNode x = o as IASTNode;
if (x == null)
{
log.Warn("processEqualityExpression() : No expression to process!");
return null;
}
int type = x.Type;
if (type == EQ || type == NE)
{
......@@ -336,11 +328,11 @@ public void HandleDotIdent()
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)
var t = input.LT(2);
if (IsPossibleId(t))
{
// Set it!
input.LT(2).Type = IDENT;
t.Type = IDENT;
if (log.IsDebugEnabled())
{
log.Debug("handleDotIdent() : new LT(2) token - {0}", input.LT(1));
......@@ -401,37 +393,38 @@ public IASTNode ProcessMemberOf(IToken n, IASTNode p, IASTNode root)
public IASTNode HandleIdentifierError(IToken token, RecognitionException ex)
{
if (token is HqlToken)
// ... and the token could be an identifier and the error is
// a mismatched token error ...
if (IsPossibleId(token) && (ex is MismatchedTokenException mte)
// ... and the expected token type was an identifier, then:
&& mte.Expecting == IDENT)
{
HqlToken hqlToken = (HqlToken)token;
// Use the token as an identifier.
_parseErrorHandler.ReportWarning("Keyword '"
+ token.Text
+ "' is being interpreted as an identifier due to: " + mte.Message);
// ... 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.
// Add the token to the AST.
token.Type = WEIRD_IDENT;
token.Type = WEIRD_IDENT;
input.Consume();
return (IASTNode) adaptor.Create(token);
}
}
input.Consume();
return (IASTNode) adaptor.Create(token);
}
// Otherwise, handle the error normally.
ReflectHelper.PreserveStackTrace(ex);
throw ex;
}
/// <summary>
/// Indicates if the token could be an identifier.
/// </summary>
/// <param name="token"></param>
public static bool IsPossibleId(IToken token)
{
var type = token.Type;
return type >= 0 && type < possibleIds.Length && possibleIds[type];
}
}
}
......@@ -39,10 +39,9 @@ public HqlToken(IToken other)
/// <summary>
/// Indicates if the token could be an identifier.
/// </summary>
public bool PossibleId
{
get { return HqlParser.possibleIds[Type]; }
}
// Since 5.5
[Obsolete("Use HqlParser.IsPossibleId method instead.")]
public bool PossibleId => HqlParser.IsPossibleId(this);
/// <summary>
/// Returns the previous token type.
......@@ -62,7 +61,7 @@ public override string ToString()
+ Text
+ "\",<" + Type + "> previously: <" + PreviousType + ">,line="
+ Line + ",col="
+ CharPositionInLine + ",possibleID=" + PossibleId + "]";
+ CharPositionInLine + ",possibleID=" + HqlParser.IsPossibleId(this) + "]";
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册