Inheritance: IDisposable
Beispiel #1
0
        public void ParseNegativeInteger()
        {
            Lexer lexer = new Lexer("-42");

            var token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(TokenType.Operator, token.TokenType);
            Assert.AreEqual("-", token.Value);

            token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("42", token.Value);
            Assert.AreEqual(TokenType.Integer, token.TokenType);

            Assert.IsNull(lexer.NextToken());
        }
Beispiel #2
0
        public void ParseIntegerWithDotAndName()
        {
            Lexer lexer = new Lexer("42.foo");

            var token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(TokenType.Integer, token.TokenType);
            Assert.AreEqual("42", token.Value);

            token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(".", token.Value);
            Assert.AreEqual(TokenType.Delimiter, token.TokenType);

            token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(TokenType.Name, token.TokenType);
            Assert.AreEqual("foo", token.Value);

            Assert.IsNull(lexer.NextToken());
        }
Beispiel #3
0
 public Parser(Lexer lexer)
 {
     this.lexer = lexer;
 }
Beispiel #4
0
        private static void ParseTokens(string text, TokenType type)
        {
            Lexer lexer = new Lexer(text);
            string[] values = text.Split(' ');
            Token token;

            foreach (string value in values)
            {
                token = lexer.NextToken();

                Assert.IsNotNull(token);

                Assert.AreEqual(type, token.TokenType);
                Assert.AreEqual(value, token.Value);
            }

            Assert.IsNull(lexer.NextToken());
        }
Beispiel #5
0
        private static void ParseToken(string text, TokenType type, string value)
        {
            using (Lexer lexer = new Lexer(text))
            {
                Token token = lexer.NextToken();

                Assert.IsNotNull(token);

                Assert.AreEqual(type, token.TokenType);
                Assert.AreEqual(value, token.Value);

                Assert.IsNull(lexer.NextToken());
            }
        }
Beispiel #6
0
        private static void ParseNameTokens(string text, params string[] values)
        {
            Lexer lexer = new Lexer(text);
            Token token;

            foreach (string value in values)
            {
                token = lexer.NextToken();

                Assert.IsNotNull(token);

                Assert.AreEqual(TokenType.Name, token.TokenType);
                Assert.AreEqual(value, token.Value);
            }

            Assert.IsNull(lexer.NextToken());
        }
Beispiel #7
0
        public void PushTwoToken2()
        {
            Lexer lexer = new Lexer(string.Empty);
            Token token = new Token() { TokenType = TokenType.Name, Value = "name" };
            Token token2 = new Token() { TokenType = TokenType.Name, Value = "name2" };

            lexer.PushToken(token);
            lexer.PushToken(token2);

            Assert.AreEqual(token2, lexer.NextToken());
            Assert.AreEqual(token, lexer.NextToken());
        }
Beispiel #8
0
        public void PushToken()
        {
            Lexer lexer = new Lexer("");
            Token token = new Token() { TokenType = TokenType.Name, Value = "name" };

            lexer.PushToken(token);

            Assert.AreEqual(token, lexer.NextToken());
        }