本文整理汇总了C#中SyntaxNodeOrToken类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNodeOrToken类的具体用法?C# SyntaxNodeOrToken怎么用?C# SyntaxNodeOrToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxNodeOrToken类属于命名空间,在下文中一共展示了SyntaxNodeOrToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSpan
private static TextSpan CreateSpan(SyntaxTokenList startOpt, SyntaxNodeOrToken startFallbackOpt, SyntaxNodeOrToken endOpt)
{
Debug.Assert(startFallbackOpt != default(SyntaxNodeOrToken) || endOpt != default(SyntaxNodeOrToken));
int startPos;
if (startOpt.Count > 0)
{
startPos = startOpt.First().SpanStart;
}
else if (startFallbackOpt != default(SyntaxNodeOrToken))
{
startPos = startFallbackOpt.SpanStart;
}
else
{
startPos = endOpt.SpanStart;
}
int endPos;
if (endOpt != default(SyntaxNodeOrToken))
{
endPos = GetEndPosition(endOpt);
}
else
{
endPos = GetEndPosition(startFallbackOpt);
}
return TextSpan.FromBounds(startPos, endPos);
}
示例2: Create
public static PatternCapture Create(PatternVariable variable, SyntaxNodeOrToken startNodeOrToken, SyntaxNodeOrToken endNodeOrToken)
{
Debug.Assert(endNodeOrToken.Parent != startNodeOrToken.Parent,
$"{nameof(endNodeOrToken)}.{nameof(endNodeOrToken.Parent)} must match {nameof(startNodeOrToken)}", nameof(endNodeOrToken));
return new PatternCapture(variable, startNodeOrToken, endNodeOrToken);
}
示例3: PatternSearchResult
private PatternSearchResult(PatternSearch search, Document document, SyntaxNodeOrToken nodeOrToken, ImmutableArray<PatternCapture> captures)
{
Search = search;
Document = document;
NodeOrToken = nodeOrToken;
Captures = captures;
}
示例4: SyntaxNodeOrTokenListItem
public SyntaxNodeOrTokenListItem(SyntaxNodeOrToken syntaxNodeOrToken)
{
_lineSpan = syntaxNodeOrToken.GetLocation().GetLineSpan();
Content = $"{_lineSpan}: {syntaxNodeOrToken.Kind()} {Truncate(syntaxNodeOrToken.ToString())}";
ToolTip = syntaxNodeOrToken.ToString();
}
示例5: GetRebuiltNodes
/// <summary>
/// Returns the nodes in the new tree that do not share the same underlying
/// representation in the old tree. These may be entirely new nodes or rebuilt nodes.
/// </summary>
/// <param name="oldNode"></param>
/// <param name="newNode"></param>
/// <returns></returns>
internal static IEnumerable<SyntaxNodeOrToken> GetRebuiltNodes(SyntaxNodeOrToken oldNode, SyntaxNodeOrToken newNode)
{
var hashSet = new HashSet<InternalSyntax.SyntaxNode>();
GatherNodes(oldNode.UnderlyingNode.ToGreen(), hashSet);
var stack = new Stack<ChildSyntaxList.Enumerator>();
if (!hashSet.Contains(newNode.UnderlyingNode.ToGreen()))
{
yield return newNode;
stack.Push(newNode.Children.GetEnumerator());
}
while (stack.Count > 0)
{
var newc = stack.Pop();
if (newc.MoveNext())
{
stack.Push(newc); // put enumerator changes back on stack..
newNode = newc.Current;
if (!hashSet.Contains(newNode.UnderlyingNode.ToGreen()))
{
yield return newNode;
stack.Push(newNode.Children.GetEnumerator());
}
}
}
}
示例6: 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);
}
示例7: Run
public override Match Run(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.Kind() != _kind)
return Match.NoMatch;
return nodeOrToken.AsToken().ValueText == _text ? Match.Success : Match.NoMatch;
}
示例8: GatherNodes
private static void GatherNodes(SyntaxNodeOrToken node, HashSet<GreenNode> hashSet)
{
hashSet.Add(node.UnderlyingNode);
foreach (var child in node.ChildNodesAndTokens())
{
GatherNodes(child, hashSet);
}
}
示例9: 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);
}
}
示例10: Create
public static PatternSearchResult Create(PatternSearch search, Document document, SyntaxNodeOrToken nodeOrToken, ImmutableArray<PatternCapture> captures)
{
if (search == null)
throw new ArgumentNullException(nameof(search));
if (document == null)
throw new ArgumentNullException(nameof(document));
return new PatternSearchResult(search, document, nodeOrToken, captures);
}
示例11: ClassifyNodeOrToken
private void ClassifyNodeOrToken(SyntaxNodeOrToken nodeOrToken)
{
if (nodeOrToken.IsToken)
{
ClassifyToken(nodeOrToken.AsToken());
return;
}
ClassifyNode(nodeOrToken.AsNode());
}
示例12: WalkTreeRangeKeepLevelAndParent
private static IEnumerable<ParsedToken> WalkTreeRangeKeepLevelAndParent(SyntaxNodeOrToken currentRoot, int blockLevel, SyntaxNode upperStatementNode, SyntaxNode immediateStatementNode, Range range)
{
if (!currentRoot.IsLeafNode)
{
SyntaxNode syntaxNode = (SyntaxNode)currentRoot;
SyntaxNode nextUpperStatementNode = immediateStatementNode;
SyntaxNode nextImmediateStatementNode = syntaxNode;
if (SyntaxKind.TableConstructorExp != syntaxNode.Kind &&
SyntaxKind.TableConstructorArg != syntaxNode.Kind &&
!StatKinds.Contains(syntaxNode.Kind))
{
nextImmediateStatementNode = immediateStatementNode;
nextUpperStatementNode = upperStatementNode;
}
if (nextUpperStatementNode == null)
{
nextUpperStatementNode = nextImmediateStatementNode;
}
if ((syntaxNode.Kind == SyntaxKind.BlockNode && nextImmediateStatementNode != null) ||
syntaxNode.Kind == SyntaxKind.FieldList)
{
blockLevel++;
}
foreach (SyntaxNodeOrToken node in syntaxNode.Children)
{
foreach (ParsedToken parsedToken in WalkTreeRangeKeepLevelAndParent(node,
blockLevel,
nextUpperStatementNode, nextImmediateStatementNode,
range))
{
yield return parsedToken;
}
}
}
else
{
Token token = currentRoot as Token;
if (token != null && token.Kind != SyntaxKind.MissingToken && token.Start >= range.Start)
{
if (token.FullStart > range.End)
{
yield break;
}
yield return new ParsedToken(token, blockLevel, upperStatementNode, immediateStatementNode);
}
}
}
示例13: GetId
public string GetId(SyntaxNodeOrToken node)
{
if (names.ContainsKey(node))
{
return names[node];
}
else
{
return "Ast_" + String.Join("_", identities[node]);
}
}
示例14: GetRebuiltNodes
private static void GetRebuiltNodes(SyntaxNodeOrToken newNode, HashSet<GreenNode> hashSet, ArrayBuilder<SyntaxNodeOrToken> nodes)
{
if (hashSet.Contains(newNode.UnderlyingNode))
{
return;
}
nodes.Add(newNode);
foreach (var child in newNode.ChildNodesAndTokens())
{
GetRebuiltNodes(child, hashSet, nodes);
}
}
示例15: TryGetNextInSpan
public bool TryGetNextInSpan(ref /*readonly*/ TextSpan span, out SyntaxNodeOrToken value)
{
value = default(SyntaxNodeOrToken);
while (stack[stackPtr].TryMoveNextAndGetCurrent(ref value))
{
if (IsInSpan(ref span, value.FullSpan))
{
return true;
}
}
stackPtr--;
return false;
}