Exemplo n.º 1
0
        public void LiteralTests()
        {
            string           txt         = "1";
            AntlrInputStream inputStream = new AntlrInputStream(txt);
            BogieLangLexer   lexer       = new BogieLangLexer(inputStream);

            lexer.AddErrorListener(new ParserErrorHandler <int>());
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            parser.AddErrorListener(new ParserErrorHandler <object>());
            BogieLangParser.LiteralContext literalContext = parser.literal();
            BogieLangBaseVisitor <object>  visitor        = new BogieLangBaseVisitor <object>();

            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "1.0";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "false";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "\"asd8 99asd\"";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }
Exemplo n.º 2
0
        public void LiteralTests()
        {
            string            txt               = "1";
            AntlrInputStream  inputStream       = new AntlrInputStream(txt);
            BogieLangLexer    lexer             = new BogieLangLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            BogieLangParser.LiteralContext literalContext = parser.literal();
            BogieLangBaseVisitor <object>  visitor        = new BogieLangBaseVisitor <object>();

            visitor.Visit(literalContext);
            Literal literal = Literal.Compile(literalContext);

            Assert.True(literal.Execute() is int);
            Assert.True((int)literal.Execute() == 1);


            txt         = "1.0";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            literal = Literal.Compile(literalContext);
            Assert.True(literal.Execute() is double);
            Assert.True((double)literal.Execute() == 1.0);


            txt         = "false";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
            literal = Literal.Compile(literalContext);
            Assert.True(literal.Execute() is bool);
            Assert.True((bool)literal.Execute() == false);


            txt         = "\"asd8 99asd\"";
            inputStream = new AntlrInputStream(txt);
            lexer       = new BogieLangLexer(inputStream);
            lexer.AddErrorListener(new ParserErrorHandler <int>());
            commonTokenStream = new CommonTokenStream(lexer);
            parser            = new BogieLangParser(commonTokenStream);
            parser.AddErrorListener(new ParserErrorHandler <object>());
            literalContext = parser.literal();
            visitor        = new BogieLangBaseVisitor <object>();
            visitor.Visit(literalContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
            literal = Literal.Compile(literalContext);
            Assert.True(literal.Execute() is string);
            Assert.True((string)literal.Execute() == "asd8 99asd");
        }