Package com.alibaba.druid.sql.parser
Class Lexer
- java.lang.Object
-
- com.alibaba.druid.sql.parser.Lexer
-
- Direct Known Subclasses:
BigQueryLexer,BlinkLexer,CKLexer,DB2Lexer,H2Lexer,HiveLexer,MySqlLexer,OracleLexer,OscarLexer,PGLexer,PhoenixLexer,PrestoLexer,SnowflakeLexer,SQLServerLexer,StarRocksLexer,TDLexer
public class Lexer extends Object
- Author:
- wenshao [szujobs@hotmail.com]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLexer.CommentHandlerstatic classLexer.SavePoint
-
Field Summary
Fields Modifier and Type Field Description protected char[]bufprotected intbufPosprotected charchprotected intcommentCountprotected Lexer.CommentHandlercommentHandlerprotected List<String>commentsprotected DbTypedbTypeprotected DialectFeaturedialectFeatureprotected booleanendOfCommentprotected intfeaturesprotected longhashprotected longhashLCaseprotected booleankeepCommentsprotected booleankeepSourceLocationprotected Keywordskeywordsprotected intlineprotected intlinesprotected intmarkprotected booleannumberExpprotected intnumberSaleprotected booleanoptimizedForParameterizedprotected intposprotected intposColumnprotected intposLineprotected booleanskipCommentprotected intstartPosprotected StringstringValprotected static SymbolTablesymbols_l2Stringtextprotected TimeZonetimeZoneprotected Tokentoken
-
Constructor Summary
Constructors Constructor Description Lexer(char[] input, int inputLength, boolean skipComment)Lexer(String input)Lexer(String input, boolean skipComment)Lexer(String input, DbType dbType)Lexer(String input, Lexer.CommentHandler commentHandler)Lexer(String input, Lexer.CommentHandler commentHandler, DbType dbType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddComment(String comment)StringaddSymbol()voidarraycopy(int srcPos, char[] dest, int destPos, int length)intbp()charcharAt(int index)voidcomputeRowAndColumn()voidcomputeRowAndColumn(SQLObject x)voidconfig(SQLParserFeature feature, boolean state)charcurrent()BigDecimaldecimalValue()protected booleandialectFeatureEnabled(DialectFeature.LexerFeature feature)intgetCommentCount()Lexer.CommentHandlergetCommentHandler()List<String>getComments()DbTypegetDbType()KeywordsgetKeywords()intgetLine()intgetPosColumn()intgetPosLine()StringgetSource()TimeZonegetTimeZone()booleanhasComment()longhashLCase()StringhexString()booleanidentifierEquals(long hash_lower)booleanidentifierEquals(String text)Stringinfo()protected voidinitBuff(int size)protected voidinitDialectFeature()NumberintegerValue()booleanisAllowComment()booleanisDigit(char ch)protected static booleanisDigit2(char ch)booleanisEnabled(SQLParserFeature feature)booleanisEndOfComment()booleanisEOF()protected booleanisFirstIdentifierChar0(char ch)booleanisKeepComments()booleanisKeepSourceLocation()booleanisNegativeIntegerValue()protected booleanisSafeComment(String comment)protected voidlexError(String key, Object... args)Report an error at the given position using the provided arguments.protected KeywordsloadKeywords()Lexer.SavePointmark()Deprecated.Lexer.SavePointmarkOut()booleannextIf(Token token)booleannextIfComma()booleannextIfIdentifier(long hashCode54)booleannextIfIdentifier(String identifier)voidnextPath()voidnextToken()voidnextTokenAlias()voidnextTokenBy()voidnextTokenComma()voidnextTokenCommaValue()voidnextTokenEq()voidnextTokenForSet()voidnextTokenIdent()voidnextTokenLParen()voidnextTokenNotOrNull()protected voidnextTokenQues()voidnextTokenValue()intnextVarIndex()SQLNumberExprnumberExpr()SQLNumberExprnumberExpr(boolean negate)SQLNumberExprnumberExpr(SQLObject parent)StringnumberString()static Stringparameterize(String sql, DbType dbType)intpos()Return the current token's position: a 0-based offset from beginning of the raw input stream (before unicode translation)protected voidputChar(char ch)Append a character to sbuf.List<String>readAndResetComments()voidreset()Deprecated.voidreset(int pos)voidreset(int mark, char markChar, Token token)Deprecated.voidreset(Lexer.SavePoint savePoint)protected voidscanAlias()protected voidscanChar()voidscanComment()voidscanHexaDecimal()voidscanIdentifier()protected voidscanIdentifier0()protected voidscanLBracket()List<String>scanLineArgument()protected voidscanMultiLineComment()voidscanNumber()voidscanSharp()protected voidscanSingleLineComment()SQLTypescanSQLType()SQLTypescanSQLTypeV2()protected voidscanString()protected voidscanString2()protected voidscanString2_d()voidscanVariable()protected voidscanVariable_at()voidsetAllowComment(boolean allowComment)voidsetCommentHandler(Lexer.CommentHandler commentHandler)voidsetKeepComments(boolean keepComments)voidsetTimeZone(TimeZone timeZone)voidsetToken(Token token)voidskipToEOF()booleanskipToNextLine(int startPosition)booleanskipToNextLineOrParameter(int startPosition)StringstringVal()The value of a literal token, recorded as a string.char[]sub_chars(int offset, int count)StringsubString(int offset)StringsubString(int offset, int count)Tokentoken()Return the current token, set by nextToken().protected voidunscan()
-
-
-
Field Detail
-
symbols_l2
protected static SymbolTable symbols_l2
-
features
protected int features
-
timeZone
protected TimeZone timeZone
-
text
public final String text
-
pos
protected int pos
-
mark
protected int mark
-
numberSale
protected int numberSale
-
numberExp
protected boolean numberExp
-
ch
protected char ch
-
buf
protected char[] buf
-
bufPos
protected int bufPos
-
token
protected Token token
-
keywords
protected Keywords keywords
-
stringVal
protected String stringVal
-
hashLCase
protected long hashLCase
-
hash
protected long hash
-
commentCount
protected int commentCount
-
skipComment
protected boolean skipComment
-
commentHandler
protected Lexer.CommentHandler commentHandler
-
endOfComment
protected boolean endOfComment
-
keepComments
protected boolean keepComments
-
line
protected int line
-
lines
protected int lines
-
dbType
protected DbType dbType
-
optimizedForParameterized
protected boolean optimizedForParameterized
-
keepSourceLocation
protected boolean keepSourceLocation
-
startPos
protected int startPos
-
posLine
protected int posLine
-
posColumn
protected int posColumn
-
dialectFeature
protected DialectFeature dialectFeature
-
-
Constructor Detail
-
Lexer
public Lexer(String input)
-
Lexer
public Lexer(String input, Lexer.CommentHandler commentHandler)
-
Lexer
public Lexer(String input, Lexer.CommentHandler commentHandler, DbType dbType)
-
Lexer
public Lexer(String input, boolean skipComment)
-
Lexer
public Lexer(char[] input, int inputLength, boolean skipComment)
-
-
Method Detail
-
loadKeywords
protected Keywords loadKeywords()
-
isKeepSourceLocation
public boolean isKeepSourceLocation()
-
isKeepComments
public boolean isKeepComments()
-
setKeepComments
public void setKeepComments(boolean keepComments)
-
getCommentHandler
public Lexer.CommentHandler getCommentHandler()
-
setCommentHandler
public void setCommentHandler(Lexer.CommentHandler commentHandler)
-
charAt
public final char charAt(int index)
-
addSymbol
public final String addSymbol()
-
subString
public final String subString(int offset, int count)
-
subString
public final String subString(int offset)
-
sub_chars
public final char[] sub_chars(int offset, int count)
-
initBuff
protected void initBuff(int size)
-
arraycopy
public void arraycopy(int srcPos, char[] dest, int destPos, int length)
-
isAllowComment
public boolean isAllowComment()
-
setAllowComment
public void setAllowComment(boolean allowComment)
-
nextVarIndex
public int nextVarIndex()
-
getKeywords
public Keywords getKeywords()
-
mark
@Deprecated public Lexer.SavePoint mark()
Deprecated.
-
markOut
public Lexer.SavePoint markOut()
-
reset
public void reset(Lexer.SavePoint savePoint)
-
reset
@Deprecated public void reset()
Deprecated.
-
reset
public void reset(int pos)
-
initDialectFeature
protected void initDialectFeature()
-
scanChar
protected final void scanChar()
-
unscan
protected void unscan()
-
isEOF
public boolean isEOF()
-
lexError
protected void lexError(String key, Object... args)
Report an error at the given position using the provided arguments.
-
token
public final Token token()
Return the current token, set by nextToken().
-
nextIf
public boolean nextIf(Token token)
-
nextIfComma
public final boolean nextIfComma()
-
nextIfIdentifier
public final boolean nextIfIdentifier(String identifier)
-
nextIfIdentifier
public final boolean nextIfIdentifier(long hashCode54)
-
setToken
public void setToken(Token token)
-
getDbType
public final DbType getDbType()
-
info
public String info()
-
nextTokenComma
public final void nextTokenComma()
-
nextTokenCommaValue
public final void nextTokenCommaValue()
-
nextTokenEq
public final void nextTokenEq()
-
nextTokenLParen
public final void nextTokenLParen()
-
nextTokenValue
public final void nextTokenValue()
-
nextTokenBy
public final void nextTokenBy()
-
nextTokenNotOrNull
public final void nextTokenNotOrNull()
-
nextTokenIdent
public final void nextTokenIdent()
-
scanSQLType
public final SQLType scanSQLType()
-
scanSQLTypeV2
public final SQLType scanSQLTypeV2()
-
nextTokenAlias
public final void nextTokenAlias()
-
nextPath
public final void nextPath()
-
nextTokenForSet
public final void nextTokenForSet()
-
skipToNextLine
public final boolean skipToNextLine(int startPosition)
-
skipToNextLineOrParameter
public final boolean skipToNextLineOrParameter(int startPosition)
-
nextTokenQues
protected void nextTokenQues()
-
nextToken
public final void nextToken()
-
scanLBracket
protected void scanLBracket()
-
scanString
protected void scanString()
-
scanString2
protected final void scanString2()
-
scanString2_d
protected final void scanString2_d()
-
scanAlias
protected void scanAlias()
-
scanSharp
public void scanSharp()
-
scanVariable
public void scanVariable()
-
scanVariable_at
protected void scanVariable_at()
-
scanComment
public void scanComment()
-
scanMultiLineComment
protected void scanMultiLineComment()
-
scanSingleLineComment
protected void scanSingleLineComment()
-
scanIdentifier
public void scanIdentifier()
-
isFirstIdentifierChar0
protected boolean isFirstIdentifierChar0(char ch)
-
scanIdentifier0
protected void scanIdentifier0()
-
scanNumber
public void scanNumber()
-
scanHexaDecimal
public void scanHexaDecimal()
-
hexString
public String hexString()
-
isDigit
public final boolean isDigit(char ch)
-
isDigit2
protected static final boolean isDigit2(char ch)
-
putChar
protected final void putChar(char ch)
Append a character to sbuf.
-
pos
public final int pos()
Return the current token's position: a 0-based offset from beginning of the raw input stream (before unicode translation)
-
stringVal
public final String stringVal()
The value of a literal token, recorded as a string. For integers, leading 0x and 'l' suffixes are suppressed.
-
identifierEquals
public final boolean identifierEquals(String text)
-
identifierEquals
public final boolean identifierEquals(long hash_lower)
-
hashLCase
public final long hashLCase()
-
isNegativeIntegerValue
public final boolean isNegativeIntegerValue()
-
integerValue
public final Number integerValue()
-
bp
public int bp()
-
current
public char current()
-
reset
@Deprecated public void reset(int mark, char markChar, Token token)
Deprecated.
-
numberString
public final String numberString()
-
decimalValue
public BigDecimal decimalValue()
-
numberExpr
public SQLNumberExpr numberExpr()
-
numberExpr
public SQLNumberExpr numberExpr(SQLObject parent)
-
numberExpr
public SQLNumberExpr numberExpr(boolean negate)
-
hasComment
public boolean hasComment()
-
getCommentCount
public int getCommentCount()
-
skipToEOF
public void skipToEOF()
-
isEndOfComment
public boolean isEndOfComment()
-
isSafeComment
protected boolean isSafeComment(String comment)
-
addComment
protected void addComment(String comment)
-
getLine
public int getLine()
-
computeRowAndColumn
public void computeRowAndColumn(SQLObject x)
-
computeRowAndColumn
public void computeRowAndColumn()
-
getPosLine
public int getPosLine()
-
getPosColumn
public int getPosColumn()
-
config
public void config(SQLParserFeature feature, boolean state)
-
getTimeZone
public TimeZone getTimeZone()
-
setTimeZone
public void setTimeZone(TimeZone timeZone)
-
isEnabled
public final boolean isEnabled(SQLParserFeature feature)
-
getSource
public String getSource()
-
dialectFeatureEnabled
protected boolean dialectFeatureEnabled(DialectFeature.LexerFeature feature)
-
-