public void ScanNumber()
        {
            var scanner = new ExpressionScanner();
            var token   = scanner.Scan("123").First();

            Assert.AreEqual(TokenType.Integer, token.Type);
            Assert.AreEqual("123", token.Lexeme);

            token = scanner.Scan("-1293281").First();

            Assert.AreEqual(TokenType.Integer, token.Type);
            Assert.AreEqual("-1293281", token.Lexeme);

            token = scanner.Scan("129.3281").First();

            Assert.AreEqual(TokenType.Float, token.Type);
            Assert.AreEqual("129.3281", token.Lexeme);

            token = scanner.Scan("-293847.2724379324").First();

            Assert.AreEqual(TokenType.Float, token.Type);
            Assert.AreEqual("-293847.2724379324", token.Lexeme);

            token = scanner.Scan("-.2724379324").First();

            Assert.AreEqual(TokenType.Float, token.Type);
            Assert.AreEqual("-.2724379324", token.Lexeme);
        }
        public void Parse()
        {
            var scanner = new ExpressionScanner();
            var parser  = new ExpressionParser();

            var tokens      = scanner.Scan("alias_by_fragment(ema(servers.srv-aps3.system.processor.total*, 50), 2, 4)");
            var expressions = parser.Parse(new TokenStream(tokens)).ToArray();

            Assert.AreEqual(1, expressions.Length);

            tokens      = scanner.Scan("summarize(alias_by_fragment(ema(servers.srv-aps3.system.processor.{total*,user*}, 50), 2, 4), 'sum', '1d', false)");
            expressions = parser.Parse(new TokenStream(tokens)).ToArray();

            Assert.AreEqual(1, expressions.Length);

            tokens = scanner.Scan(
                "aliasByNode(sortByName(servers.mow1aps13.system.network.intel*.bytes_sent_sec), 1, 5)," +
                "scale(aliasByNode(sortByName(servers.mow1aps13.system.network.intel*.bytes_received_sec), 1, 5), -1)");

            expressions = parser.Parse(new TokenStream(tokens)).ToArray();

            Assert.AreEqual(2, expressions.Length);
            Assert.IsInstanceOf <FunctionInvocationExpression>(expressions[0]);
            Assert.IsInstanceOf <FunctionInvocationExpression>(expressions[1]);
        }
        public void Expression12()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan(">=");

            result.Should().Have.SameSequenceAs(
                new Token("geq", ">=")
                );
        }
        public void Expression4()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan("2.2.3");

            result.Should().Have.SameSequenceAs(
                new Token("float", "2.2"),
                new Token("float", ".3")
                );
        }
        public void Expression7()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan("var:=10");

            result.Should().Have.SameSequenceAs(
                new Token("identifier", "var"),
                new Token("assign", ":="),
                new Token("integer", "10")
                );
        }
        public void Expression8()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan("var*10");

            result.Should().Have.SameSequenceAs(
                new Token("identifier", "var"),
                new Token("times", "*"),
                new Token("integer", "10")
                );
        }
        public void Expression15()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan(">>=<<=");

            result.Should().Have.SameSequenceAs(
                new Token("gt", ">"),
                new Token("geq", ">="),
                new Token("lt", "<"),
                new Token("leq", "<=")
                );
        }
        public void Expression5()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan("(2.5+4)");

            result.Should().Have.SameSequenceAs(
                new Token("lparen", "("),
                new Token("float", "2.5"),
                new Token("plus", "+"),
                new Token("integer", "4"),
                new Token("rparen", ")")
                );
        }
        public void Expression3()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan("2.2+2/2");

            result.Should().Have.SameSequenceAs(
                new Token("float", "2.2"),
                new Token("plus", "+"),
                new Token("integer", "2"),
                new Token("divide", "/"),
                new Token("integer", "2")
                );
        }
        public void Expression9()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan("var* /* comment */ 10");

            result.Should().Have.SameSequenceAs(
                new Token("identifier", "var"),
                new Token("times", "*"),
                new Token("white_space", " "),
                new Token("comment", "/* comment */"),
                new Token("white_space", " "),
                new Token("integer", "10")
                );
        }
        public void Expression19()
        {
            var scanner = new ExpressionScanner();
            var result  = scanner.Scan(">>=<>||&&<<===!!=");

            result.Should().Have.SameSequenceAs(
                new Token("gt", ">"),
                new Token("geq", ">="),
                new Token("neq", "<>"),
                new Token("or", "||"),
                new Token("and", "&&"),
                new Token("lt", "<"),
                new Token("leq", "<="),
                new Token("eq", "=="),
                new Token("not", "!"),
                new Token("neq", "!=")
                );
        }
        private Statement Parse(string expression)
        {
            var exprBytes = Encoding.UTF8.GetBytes(expression);

            using (var exprStream = new MemoryStream(exprBytes))
            {
                var scanner = new ExpressionScanner();
                scanner.SetSource(exprStream);
                var  parser = new ExpressionParser(scanner);
                bool parsed = parser.Parse();

                if (parsed)
                {
                    return(parser.GetStatement());
                }
                else
                {
                    return(null);
                }
            }
        }
 public void Scan()
 {
     var scanner = new ExpressionScanner();
     var tokens  = scanner.Scan("asPercent(Server01.connections.{failed,succeeded}, Server01.connections.attempted)").ToArray();
 }
 public ExpressionParser(ExpressionScanner scnr) : base(scnr)
 {
 }
 public void Expression6()
 {
     var scanner = new ExpressionScanner();
     var result  = scanner.Scan("var=10").ToArray();
 }