Пример #1
0
		private Token GetCurrentToken()
		{
			if (currentToken == null)
			{
				while (scanner.InternalMoveNext())
				{
					currentToken = scanner.Current;

					var commentToken = currentToken as Comment;
					if (commentToken != null)
					{
						pendingEvents.Enqueue(new Events.Comment(commentToken.Value, commentToken.IsInline, commentToken.Start, commentToken.End));
					}
					else
					{
						break;
					}
				}
			}
			return currentToken;
		}
Пример #2
0
 private void Skip()
 {
     if (currentToken != null)
     {
         currentToken = null;
         scanner.ConsumeCurrent();
     }
 }
Пример #3
0
 private void TokenInfoParsed(Token token, TokenType type, ColorIndex color)
 {
     TokenInfo info = new TokenInfo(token.Start.Index, token.End.Index - 1, type);
     info.Color = (TokenColor)color;
     scannedTokens.Enqueue(info);
 }
Пример #4
0
 internal bool InternalMoveNext()
 {
     if (!tokenAvailable && !streamEndProduced)
     {
         FetchMoreTokens();
     }
     if (tokens.Count > 0)
     {
         current = tokens.Dequeue();
         tokenAvailable = false;
         return true;
     }
     else
     {
         current = null;
         return false;
     }
 }
Пример #5
0
 /// <summary>
 /// Consumes the current token and increments the parsed token count
 /// </summary>
 internal void ConsumeCurrent()
 {
     ++tokensParsed;
     tokenAvailable = false;
     current = null;
 }
Пример #6
0
 /// <summary>
 /// Consumes the current token and increments the parsed token count
 /// </summary>
 internal void ConsumeCurrent()
 {
     ++tokensParsed;
     tokenAvailable = false;
     previous = Current;
     Current = null;
 }
Пример #7
0
        private void AssertToken(Token expected, Token actual, int tokenNumber)
        {
            Dump.WriteLine(expected.GetType().Name);
            actual.Should().NotBeNull();
            actual.GetType().Should().Be(expected.GetType(), "Token {0} is not of the expected type", tokenNumber);

            foreach (var property in expected.GetType().GetProperties())
            {
                if (property.PropertyType != typeof(Mark) && property.CanRead)
                {
                    var value = property.GetValue(actual, null);
                    var expectedValue = property.GetValue(expected, null);
                    Dump.WriteLine("\t{0} = {1}", property.Name, value);
                    value.Should().Be(expectedValue, "Comparing property {0} in token {1}", property.Name, tokenNumber);
                }
            }
        }
Пример #8
0
 private void AssertNext(Scanner scanner, Token expected)
 {
     AssertHasNext(scanner);
     AssertCurrent(scanner, expected);
 }
Пример #9
0
        private void AssertCurrent(Scanner scanner, Token expected)
        {
            Dump.WriteLine(expected.GetType().Name);
            Assert.NotNull(scanner.Current);
            Assert.True(expected.GetType().IsAssignableFrom(scanner.Current.GetType()));

            foreach (var property in expected.GetType().GetProperties()) {
                if (property.PropertyType != typeof(Mark) && property.CanRead) {
                    var value = property.GetValue(scanner.Current, null);
                    Dump.WriteLine("\t{0} = {1}", property.Name, value);
                    Assert.Equal(property.GetValue(expected, null), value);
                }
            }
        }
Пример #10
0
 private Token GetCurrentToken()
 {
     if (currentToken == null)
     {
         if (scanner.InternalMoveNext())
         {
             currentToken = scanner.Current;
         }
     }
     return currentToken;
 }
Пример #11
0
        private void AssertCurrent(Scanner scanner, Token expected)
        {
            Console.WriteLine(expected.GetType().Name);
            Assert.IsNotNull(scanner.Current, "The current token is null.");
            Assert.IsTrue(expected.GetType().IsAssignableFrom(scanner.Current.GetType()), "The token is not of the expected type.");

            foreach (var property in expected.GetType().GetProperties()) {
                if(property.PropertyType != typeof(Mark) && property.CanRead) {
                    object value = property.GetValue(scanner.Current, null);
                    Console.WriteLine("\t{0} = {1}", property.Name, value);
                    Assert.AreEqual(property.GetValue(expected, null), value, string.Format("The property '{0}' is incorrect.", property.Name));
                }
            }
        }