本文整理汇总了C#中Microsoft.VisualStudio.Package.TokenInfo.ToTextSpan方法的典型用法代码示例。如果您正苦于以下问题:C# TokenInfo.ToTextSpan方法的具体用法?C# TokenInfo.ToTextSpan怎么用?C# TokenInfo.ToTextSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.Package.TokenInfo
的用法示例。
在下文中一共展示了TokenInfo.ToTextSpan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseForDeprecatedCommands
/// <summary>
/// Parse for uses of deprecated commands.
/// </summary>
/// <param name="lines">A collection of lines to parse.</param>
/// <returns>A list of error information.</returns>
public static List<CMakeErrorInfo> ParseForDeprecatedCommands(
IEnumerable<string> lines)
{
List<CMakeErrorInfo> results = new List<CMakeErrorInfo>();
CMakeScanner scanner = new CMakeScanner();
TokenInfo tokenInfo = new TokenInfo();
int state = 0;
int lineNum = 0;
foreach (string line in lines)
{
scanner.SetSource(line, 0);
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state))
{
if (!CMakeScanner.InsideParens(state) &&
tokenInfo.Token == (int)CMakeToken.Keyword)
{
string tokenText = line.ExtractToken(tokenInfo);
CMakeCommandId id = CMakeKeywords.GetCommandId(tokenText);
if (CMakeKeywords.IsDeprecated(id))
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.DeprecatedCommand,
Span = tokenInfo.ToTextSpan(lineNum),
Warning = true
});
}
}
}
lineNum++;
}
return results;
}
示例2: ParseForBadCommands
/// <summary>
/// Parse for bad commands.
/// </summary>
/// <param name="lines">A collection of lines to parse.</param>
/// <returns>A list of error information.</returns>
public static List<CMakeErrorInfo> ParseForBadCommands(IEnumerable<string> lines)
{
List<CMakeErrorInfo> results = new List<CMakeErrorInfo>();
CMakeScanner scanner = new CMakeScanner();
TokenInfo tokenInfo = new TokenInfo();
int scannerState = 0;
int lineNum = 0;
BadCommandParseState state = BadCommandParseState.BeforeCommand;
foreach (string line in lines)
{
bool lineHasError = false;
if (state != BadCommandParseState.InsideParens)
{
state = BadCommandParseState.BeforeCommand;
}
scanner.SetSource(line, 0);
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo,
ref scannerState))
{
switch (state)
{
case BadCommandParseState.BeforeCommand:
if (tokenInfo.Token == (int)CMakeToken.Identifier ||
tokenInfo.Token == (int)CMakeToken.Keyword)
{
state = BadCommandParseState.BeforeParen;
}
else if (tokenInfo.Token != (int)CMakeToken.WhiteSpace &&
tokenInfo.Token != (int)CMakeToken.Comment &&
!lineHasError)
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.ExpectedCommand,
Span = tokenInfo.ToTextSpan(lineNum)
});
lineHasError = true;
}
break;
case BadCommandParseState.BeforeParen:
if (tokenInfo.Token == (int)CMakeToken.OpenParen)
{
state = BadCommandParseState.InsideParens;
}
else if (tokenInfo.Token != (int)CMakeToken.WhiteSpace)
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.ExpectedOpenParen,
Span = tokenInfo.ToTextSpan(lineNum)
});
lineHasError = true;
}
break;
case BadCommandParseState.InsideParens:
if (!CMakeScanner.InsideParens(scannerState))
{
state = BadCommandParseState.AfterParen;
}
break;
case BadCommandParseState.AfterParen:
if (tokenInfo.Token != (int)CMakeToken.WhiteSpace &&
tokenInfo.Token != (int)CMakeToken.Comment &&
!lineHasError)
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.ExpectedEOL,
Span = tokenInfo.ToTextSpan(lineNum)
});
lineHasError = true;
}
break;
}
}
if (state == BadCommandParseState.BeforeParen)
{
// If we reached the end of a line while looking for the opening
// parenthesis, show an error, since it must appear on the same line
// as the command name to not have a syntax error.
if (!lineHasError)
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.ExpectedOpenParen,
Span = new TextSpan()
{
iStartLine = lineNum,
iStartIndex = tokenInfo.EndIndex + 1,
iEndLine = lineNum,
iEndIndex = tokenInfo.EndIndex + 2
}
});
}
state = BadCommandParseState.BeforeCommand;
//.........这里部分代码省略.........
示例3: ParseForUnmatchedParens
/// <summary>
/// Parse for unmatched parentheses.
/// </summary>
/// <param name="lines">A collection of lines to parse.</param>
/// <returns>
/// A list of error information.
/// </returns>
public static List<CMakeErrorInfo> ParseForUnmatchedParens(
IEnumerable<string> lines)
{
List<CMakeErrorInfo> results = new List<CMakeErrorInfo>();
Stack<TextSpan> stack = new Stack<TextSpan>();
CMakeScanner scanner = new CMakeScanner();
TokenInfo tokenInfo = new TokenInfo();
int state = 0;
int lineNum = 0;
foreach (string line in lines)
{
scanner.SetSource(line, 0);
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state))
{
switch ((CMakeToken)tokenInfo.Token)
{
case CMakeToken.OpenParen:
stack.Push(tokenInfo.ToTextSpan(lineNum));
break;
case CMakeToken.CloseParen:
if (stack.Count > 0)
{
stack.Pop();
}
else
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.UnmatchedParen,
Span = tokenInfo.ToTextSpan(lineNum)
});
}
break;
}
}
lineNum++;
}
while (stack.Count > 0)
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.UnmatchedParen,
Span = stack.Pop()
});
}
return results;
}
示例4: ParseForBadVariableRefs
/// <summary>
/// Parse for syntax errors in variable references.
/// </summary>
/// <param name="lines">A collection of lines to parse.</param>
/// <returns>
/// A list of error information.
/// </returns>
public static List<CMakeErrorInfo> ParseForBadVariableRefs(IEnumerable<string> lines)
{
List<CMakeErrorInfo> results = new List<CMakeErrorInfo>();
CMakeScanner scanner = new CMakeScanner();
TokenInfo tokenInfo = new TokenInfo();
BadVariableRefParseState state = BadVariableRefParseState.NeedStart;
Stack<TextSpan> stack = new Stack<TextSpan>();
int scannerState = 0;
int lineNum = 0;
foreach (string line in lines)
{
scanner.SetSource(line, 0);
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo,
ref scannerState))
{
switch ((CMakeToken)tokenInfo.Token)
{
case CMakeToken.VariableStart:
case CMakeToken.VariableStartEnv:
case CMakeToken.VariableStartCache:
case CMakeToken.VariableStartSetEnv:
stack.Push(tokenInfo.ToTextSpan(lineNum));
state = BadVariableRefParseState.NeedName;
break;
case CMakeToken.Variable:
case CMakeToken.Identifier:
if (state == BadVariableRefParseState.NeedName)
{
state = BadVariableRefParseState.NeedEnd;
}
break;
case CMakeToken.VariableEnd:
if (state == BadVariableRefParseState.NeedEnd)
{
stack.Pop();
state = stack.Count > 0 ? BadVariableRefParseState.NeedEnd :
BadVariableRefParseState.NeedStart;
}
else if (state == BadVariableRefParseState.NeedStart)
{
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.InvalidVariableRef,
Span = tokenInfo.ToTextSpan(lineNum)
});
}
else if (state == BadVariableRefParseState.NeedName)
{
TextSpan span = stack.Pop();
span.iEndIndex = tokenInfo.EndIndex + 1;
results.Add(new CMakeErrorInfo()
{
ErrorCode = CMakeError.InvalidVariableRef,
Span = span
});
}
break;
default:
HandlePossibleBadVariableRef(ref state, tokenInfo.StartIndex,
stack, results);
break;
}
}
HandlePossibleBadVariableRef(ref state, line.Length, stack, results);
lineNum++;
}
return results;
}
示例5: ParseForGeneratorBraces
/// <summary>
/// Parse for pairs of matching braces denoting generator expressions.
/// </summary>
/// <param name="lines">A collection of lines to parse.</param>
/// <param name="lineNum">
/// The number of the line on which to find the generator expression.
/// </param>
/// <returns>A list of pairs of matching braces.</returns>
public static List<SpanPair> ParseForGeneratorBraces(IEnumerable<string> lines,
int lineNum)
{
List<SpanPair> pairs = new List<SpanPair>();
Stack<TextSpan> stack = new Stack<TextSpan>();
CMakeScanner scanner = new CMakeScanner();
TokenInfo tokenInfo = new TokenInfo();
int state = 0;
int i = 0;
foreach (string line in lines)
{
scanner.SetSource(line, 0);
if (i < lineNum)
{
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state));
}
else
{
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state))
{
switch ((CMakeToken)tokenInfo.Token)
{
case CMakeToken.GeneratorStart:
stack.Push(tokenInfo.ToTextSpan(i));
break;
case CMakeToken.GeneratorEnd:
if (stack.Count > 0)
{
pairs.Add(new SpanPair()
{
First = stack.Pop(),
Second = tokenInfo.ToTextSpan(i)
});
}
break;
case CMakeToken.Colon:
case CMakeToken.FileName:
case CMakeToken.Identifier:
case CMakeToken.Variable:
case CMakeToken.VariableEnd:
case CMakeToken.VariableStart:
case CMakeToken.VariableStartCache:
case CMakeToken.VariableStartEnv:
break;
default:
stack.Clear();
break;
}
}
}
i++;
}
return pairs;
}
示例6: ParseForParens
/// <summary>
/// Parse for pairs of matching parentheses.
/// </summary>
/// <param name="lines">A collection of lines to parse.</param>
/// <returns>A list of pairs of matching parentheses.</returns>
public static List<SpanPair> ParseForParens(IEnumerable<string> lines)
{
List<SpanPair> pairs = new List<SpanPair>();
Stack<TextSpan> stack = new Stack<TextSpan>();
CMakeScanner scanner = new CMakeScanner();
TokenInfo tokenInfo = new TokenInfo();
int state = 0;
int i = 0;
foreach (string line in lines)
{
scanner.SetSource(line, 0);
while (scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state))
{
if (tokenInfo.Token == (int)CMakeToken.OpenParen)
{
stack.Push(tokenInfo.ToTextSpan(i));
}
else if (tokenInfo.Token == (int)CMakeToken.CloseParen &&
stack.Count > 0)
{
pairs.Add(new SpanPair()
{
First = stack.Pop(),
Second = tokenInfo.ToTextSpan(i)
});
}
}
i++;
}
return pairs;
}