本文整理汇总了C#中Scanner.GetNext方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.GetNext方法的具体用法?C# Scanner.GetNext怎么用?C# Scanner.GetNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.GetNext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBatches
/// <summary>
/// Generates Transact-SQL batches, suitable for execution, from the text of a
/// Transact-SQL script.
/// </summary>
/// <param name="scriptSql">Transact-SQL script text</param>
/// <returns>Collection of Batch objects for each batch in the supplied script</returns>
public static IEnumerable<Batch> GetBatches(string scriptSql)
{
/* This method could be rewritten to use the new `Parser.ParseSql` class method. */
ParseOptions parseOptions = new ParseOptions();
Scanner scanner = new Scanner(parseOptions);
int state = 0,
start,
end,
lastTokenEnd = -1,
token;
bool isPairMatch, isExecAutoParamHelp;
List<Batch> batches = new List<Batch>();
StringBuilder nextBatchSql = new StringBuilder();
scanner.SetSource(scriptSql, 0);
while ((token = scanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != (int)Tokens.EOF)
{
if ((Tokens)token == Tokens.LEX_BATCH_SEPERATOR)
{
nextBatchSql.Append(scriptSql.Substring(lastTokenEnd + 1, start - lastTokenEnd + 1 - 1 - 1));
batches.Add(new Batch(nextBatchSql.ToString()));
#if NET35
nextBatchSql = new StringBuilder();
#else
nextBatchSql.Clear();
#endif
}
else
{
nextBatchSql.Append(scriptSql.Substring(lastTokenEnd + 1, end - lastTokenEnd + 1 - 1));
}
lastTokenEnd = end;
}
#if NET35
if (!String.IsNullOrEmpty(nextBatchSql.ToString().Trim()))
#else
if (!String.IsNullOrWhiteSpace(nextBatchSql.ToString()))
#endif
batches.Add(new Batch(nextBatchSql.ToString()));
return batches;
}
示例2: ParseSql
public static IEnumerable<TokenInfo> ParseSql(string sql)
{
ParseOptions parseOptions = new ParseOptions();
Scanner scanner = new Scanner(parseOptions);
int state = 0,
start,
end,
lastTokenEnd = -1,
token;
bool isPairMatch, isExecAutoParamHelp;
List<TokenInfo> tokens = new List<TokenInfo>();
StringBuilder nextBatchSql = new StringBuilder();
scanner.SetSource(sql, 0);
while ((token = scanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != (int)Tokens.EOF)
{
TokenInfo tokenInfo =
new TokenInfo()
{
Start = start,
End = end,
IsPairMatch = isPairMatch,
IsExecAutoParamHelp = isExecAutoParamHelp,
Sql = sql.Substring(start, end - start + 1),
Token = (Tokens)token,
};
tokens.Add(tokenInfo);
lastTokenEnd = end;
}
return tokens;
}
示例3: ParseItems
private void ParseItems()
{
Scanner scanner = new Scanner();
scanner.SetSource(source, 0);
int state=0,start,end;
int tokenType = -1;
while (tokenType != ((int)Tokens.EOF)) {
tokenType = scanner.GetNext(ref state, out start, out end);
if (tokenType == (int)Tokens.LCASEIDENT || tokenType == (int)Tokens.OUTACTION) {
string channel = scanner.yytext.Replace("_", "");
if (!channels.Contains(channel)) {
channels.Add(channel);
}
} else if (tokenType == (int)Tokens.PROC) {
if (!processes.Contains(scanner.yytext)) {
processes.Add(scanner.yytext);
}
} else if (tokenType == (int)Tokens.FULLCLASS) {
if (!importedClasses.Contains(scanner.yytext)) {
importedClasses.Add(scanner.yytext);
}
}
}
}
示例4: ValidateBreakpointLocation
public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
{
if (pCodeSpan != null) {
pCodeSpan[0].iStartLine = line;
pCodeSpan[0].iEndLine = line;
List<TokenInfo> tokens = new List<TokenInfo>();
if (buffer != null) {
int length;
buffer.GetLengthOfLine(line, out length);
IVsTextLines lines = (IVsTextLines)buffer;
string text;
lines.GetLineText(line, 0, line, length, out text);
Scanner scanner = new Scanner();
scanner.SetSource(text, 0);
int state = 0, start, end;
int tokenType = -1;
while (tokenType != ((int)Tokens.EOF)) {
tokenType = scanner.GetNext(ref state, out start, out end);
tokens.Add(new TokenInfo(start, end, tokenType, scanner.yytext));
}
for (int i = 0; i < tokens.Count; i++) {
TokenInfo t = tokens[i];
if (t.type == (int)Tokens.OUTACTION
|| t.type == (int)Tokens.METHOD
|| t.type == (int)Tokens.LCASEIDENT
|| (t.type == (int)Tokens.NUMBER && t.text == "0")) {
pCodeSpan[0].iStartIndex = t.start;
pCodeSpan[0].iEndIndex = t.end + 1;
return Microsoft.VisualStudio.VSConstants.S_OK;
} else if (t.type == (int)Tokens.PROC) {
//Just a heuristic, if there is a '=' somewhere after this, then we don't want it
//Most likely it is Foo = proc or Foo(x,y,z) = proc and we don't want to highlight that
bool canUseProc = true;
for (int j = i + 1; j < tokens.Count; j++) {
if (tokens[j].type == (int)'=') {
i = j;
canUseProc = false;
break;
}
}
if (canUseProc) {
pCodeSpan[0].iStartIndex = t.start;
pCodeSpan[0].iEndIndex = t.end + 1;
return Microsoft.VisualStudio.VSConstants.S_OK;
}
}
}
}
}
return Microsoft.VisualStudio.VSConstants.S_FALSE;
}
示例5: ReplaceNonBreakingSpaces
public static string ReplaceNonBreakingSpaces(string scriptSql)
{
/* This method could be rewritten to use the new `Parser.ParseSql` class method. */
ParseOptions parseOptions = new ParseOptions();
Scanner scanner = new Scanner(parseOptions);
int state = 0,
start,
end,
lastTokenEnd = -1,
token;
bool isPairMatch, isExecAutoParamHelp;
StringBuilder newScriptSql = new StringBuilder();
scanner.SetSource(scriptSql, 0);
while ((token = scanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != (int)Tokens.EOF)
{
newScriptSql.Append(scriptSql.Substring(lastTokenEnd + 1, start - lastTokenEnd - 1));
string tokenSubstring = scriptSql.Substring(start, end - start + 1);
if ((Tokens)token != Tokens.TOKEN_STRING)
{
newScriptSql.Append(tokenSubstring.Replace('\xA0', '\x20'));
}
else
{
newScriptSql.Append(tokenSubstring);
}
lastTokenEnd = end;
}
if (lastTokenEnd + 1 < scriptSql.Length)
newScriptSql.Append(scriptSql.Substring(lastTokenEnd + 1));
return newScriptSql.ToString();
}