1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5

6
namespace TurnerSoftware.RobotsExclusionTools.Tokenization
7
{
8
	public static class Extensions
9
	{
10
		public static bool MoveTo(this IEnumerator<Token> tokenEnumerator, TokenType tokenType)
11 1
		{
12 1
			return MoveTo(tokenEnumerator, t => t.TokenType == tokenType, t => false);
13 1
		}
14

15
		public static bool MoveTo(this IEnumerator<Token> tokenEnumerator, TokenType tokenType, string tokenValue)
16 1
		{
17 1
			return MoveTo(tokenEnumerator, t => t.TokenType == tokenType && t.Value == tokenValue, t => false);
18 1
		}
19
		
20
		public static bool MoveTo(this IEnumerator<Token> tokenEnumerator, IEnumerable<TokenType> anyOfTheseTypes)
21 1
		{
22 1
			return MoveTo(tokenEnumerator, t => anyOfTheseTypes.Contains(t.TokenType), t => false);
23 1
		}
24

25
		public static bool StepOverTo(this IEnumerator<Token> tokenEnumerator, TokenType tokenType, TokenType steppingToken)
26 1
		{
27 1
			return MoveTo(
28 1
				tokenEnumerator,
29 1
				t => t.TokenType == tokenType,
30 1
				t => steppingToken != t.TokenType
31 1
			);
32 1
		}
33

34
		private static bool MoveTo(IEnumerator<Token> tokenEnumerator, Func<Token, bool> stopMovingWhen, Func<Token, bool> stopEarlyWhen)
35 1
		{
36 1
			while (tokenEnumerator.MoveNext())
37 1
			{
38 1
				if (stopMovingWhen(tokenEnumerator.Current))
39 1
				{
40 1
					return true;
41
				}
42

43 1
				if (stopEarlyWhen(tokenEnumerator.Current))
44 1
				{
45 1
					return false;
46
				}
47 1
			}
48

49 1
			return false;
50 1
		}
51
	}
52
}

Read our documentation on viewing source code .

Loading