本文整理汇总了C#中SyntaxNodeOrToken.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNodeOrToken.Kind方法的具体用法?C# SyntaxNodeOrToken.Kind怎么用?C# SyntaxNodeOrToken.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNodeOrToken
的用法示例。
在下文中一共展示了SyntaxNodeOrToken.Kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteSourceMap
private void WriteSourceMap(SyntaxNodeOrToken node, Position pos, string str)
{
if (node.Kind() == SyntaxKind.IdentifierName || node.Kind() == SyntaxKind.IdentifierToken || node.Kind() == SyntaxKind.ObjectCreationExpression)
{
System.Diagnostics.Debug.WriteLine($"{node} ---> [{node.Kind()} | {pos}] ---> {str}");
_sourceMapOutput.AddMapping(node, pos);
}
}
示例2: Run
public override Match Run(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.Kind() != SyntaxKind.Argument)
return Match.NoMatch;
var argument = (ArgumentSyntax) nodeOrToken.AsNode();
if (_variable.MinOccurrences == 1 && _variable.MaxOccurrences == 1)
return Match.Success.WithSyntaxNodeOrToken(argument);
var argumentList = argument.Parent as ArgumentListSyntax;
if (argumentList == null)
return Match.NoMatch;
var currentIndex = argumentList.Arguments.IndexOf(argument);
var availableCount = argumentList.Arguments.Count - currentIndex - _following;
if (availableCount == 0)
return Match.NoMatch;
var captureCount = _variable.MaxOccurrences == null
? availableCount
: Math.Min(availableCount, _variable.MaxOccurrences.Value);
if (captureCount < _variable.MinOccurrences)
return Match.NoMatch;
var endIndex = currentIndex + captureCount - 1;
var endArgument = argumentList.Arguments[endIndex];
return Match.Success.AddCapture(_variable, argument, endArgument);
}
示例3: Run
public override Match Run(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.Kind() != _kind)
return Match.NoMatch;
return nodeOrToken.AsToken().ValueText == _text ? Match.Success : Match.NoMatch;
}
示例4: SyntaxNodeOrTokenListItem
public SyntaxNodeOrTokenListItem(SyntaxNodeOrToken syntaxNodeOrToken)
{
_lineSpan = syntaxNodeOrToken.GetLocation().GetLineSpan();
Content = $"{_lineSpan}: {syntaxNodeOrToken.Kind()} {Truncate(syntaxNodeOrToken.ToString())}";
ToolTip = syntaxNodeOrToken.ToString();
}
示例5: Run
public override Match Run(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.Kind() != _syntaxKind)
return Match.NoMatch;
var result = Match.Success;
if (nodeOrToken.IsNode)
{
var node = nodeOrToken.AsNode();
var children = node.ChildNodesAndTokens();
var matcherIndex = 0;
var matchedEnd = 0;
for (var i = 0; i < children.Count; i++)
{
if (matcherIndex >= _childMatchers.Length)
return Match.NoMatch;
while (i < children.Count && children[i].Span.Start < matchedEnd)
i++;
if (i >= children.Count)
break;
var child = children[i];
var matcher = _childMatchers[matcherIndex];
var match = matcher.Run(child);
if (!match.IsMatch)
return Match.NoMatch;
// Depending on much was captured, we need to skip some matchers.
if (match.Captures.Any())
matchedEnd = match.Captures.Max(c => c.EndNodeOrToken.Span.End);
result = result.AddCaptures(match.Captures);
matcherIndex++;
}
var allMatchersUsed = matcherIndex >= _childMatchers.Length;
if (!allMatchersUsed)
return Match.NoMatch;
}
return result;
}
示例6: Run
public override Match Run(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.Kind() != SyntaxKind.IdentifierToken)
return Match.NoMatch;
var identifier = nodeOrToken.AsToken().ValueText;
var regex = _variable.Regex;
if (!string.IsNullOrEmpty(regex))
{
var regexOptions = _variable.CaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase;
if (!Regex.IsMatch(identifier, regex, regexOptions))
return Match.NoMatch;
}
return Match.Success.AddCapture(_variable, nodeOrToken);
}
示例7: Run
public override Match Run(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.Kind() != SyntaxKind.ArgumentList)
return Match.NoMatch;
var argumentList = (ArgumentListSyntax) nodeOrToken.AsNode();
if (_variable.MinOccurrences > argumentList.Arguments.Count)
return Match.NoMatch;
if (_variable.MaxOccurrences != null && _variable.MaxOccurrences < argumentList.Arguments.Count)
return Match.NoMatch;
if (argumentList.Arguments.Count == 0)
return Match.Success;
var first = argumentList.Arguments.First();
var last = argumentList.Arguments.Last();
return Match.Success.AddCapture(_variable, first, last);
}
示例8: NamedImpl
private void NamedImpl(SyntaxNodeOrToken nodeOrToken)
{
string name = null;
string astType = null;
string comments = nodeOrToken.GetLeadingTrivia().ToFullString();
string parentComments = nodeOrToken.Parent != null ? nodeOrToken.Parent.GetLeadingTrivia().ToFullString() : null;
//if this is the hightest ast node for this comment, look for 1 bang, else 2 bangs
string regex = @"@(?<ast_type>[^:\s]+):(?<name>\S+)";
Match match = Regex.Match(comments, regex);
if (match.Success)
{
name = match.Groups["name"].Value;
astType = match.Groups["ast_type"].Value;
SyntaxKind syntaxKind = (SyntaxKind)Enum.Parse(typeof(SyntaxKind), astType);
if (nodeOrToken.Kind() == syntaxKind)
{
names.Add(nodeOrToken, name);
}
}
}
示例9: CompareTreeEquivalence
private static void CompareTreeEquivalence(SyntaxNodeOrToken parsedTreeNode, SyntaxNodeOrToken incrementalTreeNode)
{
Assert.Equal(parsedTreeNode.Kind(), incrementalTreeNode.Kind());
Assert.Equal(parsedTreeNode.ChildNodesAndTokens().Count, incrementalTreeNode.ChildNodesAndTokens().Count);
for (int i = 0; i < parsedTreeNode.ChildNodesAndTokens().Count; i++)
{
CompareTreeEquivalence(parsedTreeNode.ChildNodesAndTokens()[i], incrementalTreeNode.ChildNodesAndTokens()[i]);
}
}
示例10: AssertNodesAreEquivalent
private void AssertNodesAreEquivalent(SyntaxNodeOrToken expectedNode, SyntaxNodeOrToken actualNode)
{
Assert.Equal(expectedNode.Kind(), actualNode.Kind());
Assert.Equal(expectedNode.FullSpan, actualNode.FullSpan);
Assert.Equal(expectedNode.ChildNodesAndTokens().Count, actualNode.ChildNodesAndTokens().Count);
for (var i = 0; i < expectedNode.ChildNodesAndTokens().Count; i++)
{
AssertNodesAreEquivalent(expectedNode.ChildNodesAndTokens()[i],
actualNode.ChildNodesAndTokens()[i]);
}
}
示例11: Print
private static void Print(SyntaxNodeOrToken node)
{
Debug.WriteLine("{0}(SyntaxKind.{1});", node.IsMissing ? "M" : "N", node.Kind());
}
示例12: Print
private static void Print(SyntaxNodeOrToken node)
{
if (node.Kind() == SyntaxKind.IdentifierToken && !node.IsMissing)
{
Debug.WriteLine(@"N(SyntaxKind.{0}, ""{1}"");", node.Kind(), node.ToString());
}
else
{
Debug.WriteLine("{0}(SyntaxKind.{1});", node.IsMissing ? "M" : "N", node.Kind());
}
}
示例13: IsNonZeroWidthOrIsEndOfFile
private static bool IsNonZeroWidthOrIsEndOfFile(SyntaxNodeOrToken token)
{
return token.Kind() == SyntaxKind.EndOfFileToken || token.FullWidth != 0;
}
示例14: Print
private static void Print(SyntaxNodeOrToken node)
{
switch (node.Kind())
{
case SyntaxKind.IdentifierToken:
case SyntaxKind.NumericLiteralToken:
if (node.IsMissing)
{
goto default;
}
Debug.WriteLine(@"N(SyntaxKind.{0}, ""{1}"");", node.Kind(), node.ToString());
break;
default:
Debug.WriteLine("{0}(SyntaxKind.{1});", node.IsMissing ? "M" : "N", node.Kind());
break;
}
}
示例15: CanReuse
private bool CanReuse(SyntaxNodeOrToken nodeOrToken)
{
// Zero width nodes and tokens always indicate that the parser had to do
// something tricky, so don't reuse them.
// NOTE: this is slightly different from IsMissing because of omitted type arguments
// and array size expressions.
if (nodeOrToken.FullWidth == 0)
{
return false;
}
// As of 2013/03/14, the compiler never attempts to incrementally parse a tree containing
// annotations. Our goal in instituting this restriction is to prevent API clients from
// taking a dependency on the survival of annotations.
if (nodeOrToken.ContainsAnnotations)
{
return false;
}
// We can't reuse a node or token if it intersects a changed text range.
if (this.IntersectsNextChange(nodeOrToken))
{
return false;
}
// don't reuse nodes or tokens with skipped text or diagnostics attached to them
if (nodeOrToken.ContainsDiagnostics ||
(nodeOrToken.IsToken && ((CSharpSyntaxNode)nodeOrToken.AsToken().Node).ContainsSkippedText && nodeOrToken.Parent.ContainsDiagnostics))
{
return false;
}
// fabricated tokens did not come from the lexer (likely from parser)
if (IsFabricatedToken(nodeOrToken.Kind()))
{
return false;
}
// don't reuse nodes that are incomplete. this helps cases were an incomplete node
// completes differently after a change with far look-ahead.
//
// NOTE(cyrusn): It is very unfortunate that we even need this check given that we
// have already checked for ContainsDiagnostics above. However, there is a case where we
// can have a node with a missing token *and* there are no diagnostics.
// Specifically, this happens in the REPL when you have the last statement without a
// trailing semicolon. We treat this as an ExpressionStatement with a missing
// semicolon, but we do not report errors. It would be preferable to fix that so
// that the semicolon can be optional rather than abusing the system.
if ((nodeOrToken.IsToken && nodeOrToken.AsToken().IsMissing) ||
(nodeOrToken.IsNode && IsIncomplete((CSharp.CSharpSyntaxNode)nodeOrToken.AsNode())))
{
return false;
}
if (!nodeOrToken.ContainsDirectives)
{
return true;
}
return _newDirectives.IncrementallyEquivalent(_oldDirectives);
}