Exemplo n.º 1
0
        public void FunctionCallTests()
        {
            string            txt               = "funcCall()";
            AntlrInputStream  inputStream       = new AntlrInputStream(txt);
            BogieLangLexer    lexer             = new BogieLangLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            BogieLangParser   parser            = new BogieLangParser(commonTokenStream);

            BogieLangParser.FunctionCallContext functionCallContext = parser.functionCall();
            BogieLangBaseVisitor <object>       visitor             = new BogieLangBaseVisitor <object>();

            visitor.Visit(functionCallContext);
            FunctionCall functionCall = FunctionCall.Compile(functionCallContext);

            Assert.True(functionCall.Identifier == "funcCall");
            Assert.True(functionCall.Arguments.Count == 0);


            txt         = "funcCall(\"arg\")";
            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>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            functionCall = FunctionCall.Compile(functionCallContext);
            Assert.True(functionCall.Identifier == "funcCall");
            Assert.True(functionCall.Arguments[0].Literal.String == "arg");


            txt         = "funcCall(10.0,funcCall2())";
            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>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            functionCall = FunctionCall.Compile(functionCallContext);
            Assert.True(functionCall.Identifier == "funcCall");
            Assert.True(functionCall.Arguments[0].Literal.Real == 10.0);
            Assert.True(functionCall.Arguments[1].FunctionCall.Identifier == "funcCall2");
        }
Exemplo n.º 2
0
        public static FunctionCall Compile(BogieLangParser.FunctionCallContext functionCallContext)
        {
            FunctionCall result = new FunctionCall();

            if (functionCallContext.IDENTIFIER() != null)
            {
                result.Identifier = functionCallContext.IDENTIFIER().GetText();
            }
            if (functionCallContext.expression().Length != 0)
            {
                List <Expression> expressions = new List <Expression>();
                foreach (BogieLangParser.ExpressionContext expressionContext in functionCallContext.expression())
                {
                    expressions.Add(Expression.Compile(expressionContext, null));
                }
                result.Arguments = expressions;
            }

            return(result);
        }
Exemplo n.º 3
0
        public void FunctionCallTests()
        {
            string           txt         = "funcCall()";
            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.FunctionCallContext functionCallContext = parser.functionCall();
            BogieLangBaseVisitor <object>       visitor             = new BogieLangBaseVisitor <object>();

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


            txt         = "funcCall(\"arg\")";
            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>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "funcCall(10.0,funcCall2())";
            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>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = "funcCall(10.0,funcCall2())";
            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>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);


            txt         = " funcCall\t(10.0\n,\rfuncCall2() \n\r\t)";
            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>());
            functionCallContext = parser.functionCall();
            visitor             = new BogieLangBaseVisitor <object>();
            visitor.Visit(functionCallContext);
            Assert.True(parser.NumberOfSyntaxErrors == 0);
        }