Class TSourceToken
- Namespace
- gudusoft.gsqlparser
- Assembly
- gudusoft.gsqlparser.dll
Represents a source token which is the basic syntactical unit of SQL.
All parse tree nodes including one or more tokens.
A list of source token will be available after parse or tokenize the input SQL.
TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvoracle);
sqlparser.sqltext = "select col from t";
int ret = sqlparser.parse();
// this will geneate a list of tokens only, no parse tree node is available.
// int ret = sqlparser.tokenizeSqltext();
if (ret == 0){
for(int i=0;i<sqlparser.sourcetokenlist.size();i++){
TSourceToken st = sqlparser.sourcetokenlist.get(i);
System.out.println(st.tokentype.toString()+" "+st.toString());
}
}else{
System.out.println(sqlparser.getErrormessage());
}
}
Get a list of source tokens after call parse()
or just call tokenizeSqltext() if you only
need to access tokens of input SQL without generating full parse tree nodes.
tokencode is the unique id represents one kind of token.
The most important type of whitespace,
return,
and tokentype
public class TSourceToken
- Inheritance
-
TSourceToken
- Inherited Members
Constructors
TSourceToken()
public TSourceToken()
TSourceToken(string)
public TSourceToken(string s)
Parameters
sstring
Fields
astext
Text representation for current token.
public string astext
Field Value
columnNo
the column number of the first character for current token.
public long columnNo
Field Value
container
Container for current token, this is the reference to TSourceTokenList
public TSourceTokenList container
Field Value
dolqstart
public string dolqstart
Field Value
lineNo
the line number of the first character for current token.
public long lineNo
Field Value
offset
Token's offset from the beginning of the input query.
<pre><code class="lang-csharp">public void testOffset(){
TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvoracle);
sqlparser.sqltext = "select f from t\n" +
"where f>1\n";
assertTrue(sqlparser.parse() == 0);
for (int i=0;i<sqlparser.sourcetokenlist.size();i++){
TSourceToken st = sqlparser.sourcetokenlist.get(i);
String textFromOffset = sqlparser.sqltext.toString().substring((int)st.offset,(int)st.offset+st.toString().length());
assertTrue(st.toString().equalsIgnoreCase(textFromOffset));
}
}
}</code></pre>
public long offset
Field Value
posinlist
Index of this token in the container, start from 0
public void testPosinList(){
TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvoracle);
sqlparser.sqltext = "select f from t\n" +
"where f>1\n";
assertTrue(sqlparser.parse() == 0);
for (int i=0;i<sqlparser.sourcetokenlist.size();i++){
assertTrue(i == sqlparser.sourcetokenlist.get(i).posinlist);
}
}
}
public int posinlist
Field Value
stmt
position in activeTokenList, start from 0
public TCustomSqlStatement stmt
Field Value
tag
public int tag
Field Value
tokencode
Unique id of this token used by parser internally. check available value start from cmtslashstar
public int tokencode
Field Value
tokenstatus
public ETokenStatus tokenstatus
Field Value
tokentype
check available value in ETokenType
public ETokenType tokentype
Field Value
Properties
AllowRewrite
During the process of building AST by the parser, this value is false This value turns to true after user call TCustomSqlStatement.ReWriteInit() manually.
public bool AllowRewrite { get; set; }
Property Value
AlternativeToken
public virtual TSourceToken AlternativeToken { get; set; }
Property Value
Changed
Node include this token was modified if it's true. Only allowed to set to true when AllowRewrite is true
public bool Changed { get; set; }
Property Value
DbObjType
public virtual EDbObjectType DbObjType { get; set; }
Property Value
Dbvendor
public virtual EDbVendor Dbvendor { get; set; }
Property Value
Gsqlparser
public virtual TGSqlParser Gsqlparser { get; set; }
Property Value
LinkToken
public virtual TSourceToken LinkToken { get; set; }
Property Value
NextTokenInChain
public TSourceToken NextTokenInChain { get; set; }
Property Value
PrevTokenInChain
public TSourceToken PrevTokenInChain { get; set; }
Property Value
ReplaceToken
public virtual TSourceToken ReplaceToken { get; set; }
Property Value
String
set new string of this token
public virtual string String { get; set; }
Property Value
TextWithoutQuoted
public virtual string TextWithoutQuoted { get; }
Property Value
TokensAfter
public virtual TSourceTokenList TokensAfter { get; }
Property Value
TokensBefore
public virtual TSourceTokenList TokensBefore { get; }
Property Value
nodesEndWithThisToken
source token can be end token of one or more parse tree nodes NodesEndWithThisToken includes all those parse tree nodes
public List<TParseTreeNode> nodesEndWithThisToken { get; }
Property Value
nodesStartFromThisToken
source token can be start token of one or more parse tree nodes, NodesStartFromThisToken includes those parse tree nodes.
public List<TParseTreeNode> nodesStartFromThisToken { get; }
Property Value
Methods
ToString()
Original text for current token.
public override string ToString()
Returns
- string
Original token text.
firstTokenOfLine()
public virtual bool firstTokenOfLine()
Returns
isnonsolidtoken()
Is current token a solid token or not.
public virtual bool isnonsolidtoken()
Returns
- bool
true if it's a non-solid token.
isnonsolidtoken(ETokenType)
Token except ttwhitespace,ttreturn,ttsimplecomment,ttbracketedcomment is solid token.
public static bool isnonsolidtoken(ETokenType tokentype)
Parameters
tokentypeETokenType
Returns
- bool
True if token type is not one of ttwhitespace,ttreturn,ttsimplecomment,ttbracketedcomment
issolidtoken()
Is current token a non-solid token or not.
public virtual bool issolidtoken()
Returns
- bool
true if it's a solid token.
lastTokenOfLine()
public virtual bool lastTokenOfLine()
Returns
nextSolidToken()
public virtual TSourceToken nextSolidToken()
Returns
prevSolidToken()
public virtual TSourceToken prevSolidToken()
Returns
removeMyFromTokenList()
public virtual int removeMyFromTokenList()
Returns
searchToken(int, int)
public virtual TSourceToken searchToken(int targetTokenCode, int range)
Parameters
Returns
searchToken(string, int)
public virtual TSourceToken searchToken(string targetTokenText, int range)
Parameters
Returns
searchTokenAfterObjectName()
Search token after an object.
return new scott.func(x1); current token is new, then call searchTokenAfterObjectName will return ( token.
public virtual TSourceToken searchTokenAfterObjectName()
Returns
- TSourceToken
solid token after an object name
searchTokenAtTheEndOfSameLine()
public TSourceToken searchTokenAtTheEndOfSameLine()
Returns
setLinkToken(TSourceToken)
public void setLinkToken(TSourceToken st)
Parameters
stTSourceToken
toScript()
public string toScript()
Returns
toStringDebug()
public virtual string toStringDebug()
Returns
toUnQuotedString()
public virtual string toUnQuotedString()