Example #1
0
        public void TestEmptyString()
        {
            var res = SExprParser.Parse("");

            Assert.IsType <SExpr>(res);
            Assert.Empty(res);
        }
Example #2
0
        public void TestCompilerData(string compilerName, Dictionary <string, object> pairs)
        {
            var field    = typeof(ILFile).GetField(compilerName);
            var compiler = (Compiler <Expr, string>)field.GetValue(null);

            foreach (var kvp in pairs)
            {
                var parsed = SExprParser.Parse(kvp.Key);
                compiler.Generate();
                var name = compiler.Name;
                var res  = compiler.Compile(parsed[0]);
                if (kvp.Value is string s)
                {
                    Assert.True(res.HasValue, $"Result from \"{kvp.Key}\" in {compilerName} has no value with error: {res.Error}");
                    Assert.Equal(s, res.Value);
                }
                else if (kvp.Value is bool b)
                {
                    if (b)
                    {
                        Assert.True(res.HasValue, $"Result has no value with error: {res.Error}");
                        Assert.Equal(kvp.Key, res.Value);
                    }
                    else
                    {
                        Assert.False(res.HasValue, $"Result has value: {res.Value} in {compilerName}");
                    }
                }
            }
        }
Example #3
0
    public static LNode Parse(UString sexpr, string filename = "", IMessageSink msgs = null)
    {
        var lexer           = LesLanguageService.Value.Tokenize(sexpr, filename, msgs);
        var withoutComments = new WhitespaceFilter(lexer).Buffered();
        var parser          = new SExprParser(withoutComments, lexer.SourceFile, msgs);

        return(parser.Atom());
    }
Example #4
0
        public void TestSingleOperator(string input, string output)
        {
            var res = SExprParser.Parse(input);

            Assert.Single(res, output);
            Assert.IsType <Operator>(res[0]);
            Assert.NotEqual(TextSpan.None, res[0].TextSpan);
        }
Example #5
0
        public void SExprTest()
        {
            LNode @using = SExprParser.Parse("(#import (. System Collections))");

            Console.WriteLine(EcsLanguageService.Value.Print(@using));
            LNode assign = SExprParser.Parse("(= x (+ x 2))");

            Console.WriteLine(EcsLanguageService.Value.Print(assign));
        }
Example #6
0
        public void TestSingleInt(string input, long output)
        {
            var res = SExprParser.Parse(input);

            Console.WriteLine(res.ToString());
            Assert.IsType <JEM.Model.IntConstant>(res[0]);
            Assert.Single(res, output);
            Assert.NotEqual(TextSpan.None, res[0].TextSpan);
        }
Example #7
0
        public void TestEmptySExpr(string input)
        {
            var res = SExprParser.Parse(input);

            Assert.IsType <SExpr>(res);
            Assert.Single(res);
            Assert.IsType <SExpr>(res[0]);
            Assert.Empty(res.As <SExpr>()[0].As <SExpr>());
            Assert.NotEqual(TextSpan.None, res[0].TextSpan);
        }
Example #8
0
        public static void Main(string[] args)
        {
            AntlrInputStream    ain    = new AntlrInputStream("(a b cd ef (ged))");
            SExprLexer          lexer  = new SExprLexer(ain);
            BufferedTokenStream tokens = new BufferedTokenStream(lexer);

            tokens.Fill();
            SExprParser parser = new SExprParser(tokens);

            Console.WriteLine(parser.main());
        }
Example #9
0
        public void TestAllTogether()
        {
            // have to do this in the test because attributes dont understand objects
            Dictionary <string, SExpr> cases = new Dictionary <string, SExpr>()
            {
                [""]  = new SExpr(),
                ["a"] = new SExpr(new Symbol("a")),
                ["(a \"bc\" 123)"] = new SExpr(new SExpr(new Symbol("a"), new StringConstant("bc", false), new IntConstant(123))),
                ["(a \'bc\' 123)"] = new SExpr(new SExpr(new Symbol("a"), new StringConstant("bc", true), new IntConstant(123))),
                ["(* & [])"]       = new SExpr(new SExpr(new Operator("*"), new Operator("&"), new Operator("[]"))),
                ["(() () ())"]     = new SExpr(new SExpr(new SExpr(), new SExpr(), new SExpr())),
                ["(( (a) ))"]      = new SExpr(new SExpr(new SExpr(new SExpr(new Symbol("a"))))),
                ["1:10"]           = new SExpr(new IntConstant(1), new Operator(":"), new IntConstant(10)),
                ["<T U>"]          = new SExpr(new Operator("<"), new Symbol("T"), new Symbol("U"), new Operator(">")),
                ["(.line 1:10)"]   = new SExpr(new SExpr(new Symbol(".line"), new IntConstant(1), new Operator(":"), new IntConstant(10)))
            };

            foreach (var keyValuePair in cases)
            {
                var res = SExprParser.Parse(keyValuePair.Key);
                Assert.Equal(keyValuePair.Value, res);
                Assert.NotEqual(TextSpan.None, res.TextSpan);
            }
        }