Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CommonSyntaxNodeOrTokenExtensions.cs « Util « CSharpBinding « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b99585496fb0e23dc115006492ed79cfc6217e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace ICSharpCode.NRefactory6.CSharp
{
	static class CommonSyntaxNodeOrTokenExtensions
	{
		public static IEnumerable<SyntaxNodeOrToken> DepthFirstTraversal(this SyntaxNodeOrToken node)
		{
			var stack = new Stack<SyntaxNodeOrToken>();
			stack.Push(node);

			while (!stack.IsEmpty())
			{
				var current = stack.Pop();

				yield return current;

				if (current.IsNode)
				{
					foreach (var child in current.ChildNodesAndTokens().Reverse())
					{
						stack.Push(child);
					}
				}
			}
		}
	}
}