本文整理汇总了C#中Tokenizer.AllTokens方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.AllTokens方法的具体用法?C# Tokenizer.AllTokens怎么用?C# Tokenizer.AllTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.AllTokens方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClassificationsFromCobraTokenizer
/// <summary>
/// Gets the classifications from <see cref="VisualCobraTokenizer"/>.
/// </summary>
/// <param name="span">The span to get classifications from.</param>
/// <param name="tokenizer">The tokenizer to use.</param>
/// <returns>A list of <see cref="ClassificationSpan"/> objects representing the classifications
/// in <paramref name="span"/>.</returns>
private static List<ClassificationSpan> GetClassificationsFromCobraTokenizer(
SnapshotSpan span, Tokenizer tokenizer)
{
// TODO Tried parallelising, but I'm not sure it's safe in combination with "previous".
var classifications = new List<ClassificationSpan>();
IToken previous = null;
foreach (IToken tok in tokenizer.AllTokens())
{
if (tok.IsKeyword)
{
AddSpanToClassifications(span, classifications, tok, _cobraKeywordClassificationType);
}
else
{
switch (tok.Which)
{
case "STRING_SINGLE":
case "STRING_DOUBLE":
case "CHAR":
case "CHAR_LIT_SINGLE":
AddSpanToClassifications(span, classifications, tok, _cobraStringClassificationType);
break;
case "ID": // Note "CLASS" is the class keyword, not "a class"
if (IsClass(tok))
{
AddSpanToClassifications(span, classifications, tok, _cobraClassClassificationType);
}
break;
case "QUESTION":
if (IsClass(previous))
{
// add another char to cover the ? on the end of a nillable class
AddSpanToClassifications(span, classifications, tok, _cobraClassClassificationType);
}
break;
case "COMMENT":
AddSpanToClassifications(span, classifications, tok, _cobraCommentClassificationType);
break;
}
previous = tok;
}
}
return classifications;
}