Пример #1
0
 public FunctionExpression(String name, TupleDeclarationExpression arguments, TypeName returnType, BlockExpression body, Visibility visibility = Visibility.None)
 {
     this.name       = name;
     this.arguments  = arguments;
     this.returnType = returnType;
     this.body       = body;
     this.visibility = visibility;
 }
Пример #2
0
        public static Expression functionDeclaration(Parser p, Expression left, Token t)
        {
            if (left is VariableReferenceExpression)
            {
                Expression arguments = roundBacketRouter(p, t);
                if (arguments is VariableDeclarationExpression)
                {
                    arguments = new TupleDeclarationExpression(new List <VariableDeclarationExpression>()
                    {
                        arguments as VariableDeclarationExpression
                    });
                }

                if (arguments is TupleDeclarationExpression)
                {
                    p.skip(TokenType.Dash);
                    p.skip(TokenType.RightAngleBracket);
                    TypeName   returnType = DashParslets.getTypeName(p);
                    Expression body       = p.parseExpression(0);
                    if (body is BlockExpression)
                    {
                        return(new FunctionExpression((left as VariableReferenceExpression).name,
                                                      arguments as TupleDeclarationExpression,
                                                      returnType,
                                                      body as BlockExpression));
                    }
                    else
                    {
                        throw new Exception("Function has invalid body!");
                    }
                }
                else
                {
                    if (!(arguments is TupleDefinitionExpression))
                    {
                        arguments = new TupleDefinitionExpression(new List <Expression>()
                        {
                            arguments
                        });
                    }
                    return(new FunctionCallExpression((left as VariableReferenceExpression).name, arguments as TupleDefinitionExpression));
                }
            }
            else
            {
                throw new Exception("Function has invalid name!");
            }
        }
Пример #3
0
        public void TupleDeclaration()
        {
            Expression expression        = parseExpression("(a -> int, b -> FakeClass1, c-> FakeClass2, d -> String)");
            TupleDeclarationExpression a = assertTypeAndCast <TupleDeclarationExpression>(expression);

            Assert.AreEqual(4, a.members.Count);

            Assert.AreEqual("a", a.members[0].name);
            Assert.AreEqual("int", a.members[0].typeName.name);
            Assert.IsNotInstanceOfType(a.members[0].typeName, typeof(GenericTypeName));
            Assert.AreEqual("b", a.members[1].name);
            Assert.AreEqual("FakeClass1", a.members[1].typeName.name);
            Assert.IsNotInstanceOfType(a.members[1].typeName, typeof(GenericTypeName));
            Assert.AreEqual("c", a.members[2].name);
            Assert.AreEqual("FakeClass2", a.members[2].typeName.name);
            Assert.IsNotInstanceOfType(a.members[2].typeName, typeof(GenericTypeName));
            Assert.AreEqual("d", a.members[3].name);
            Assert.AreEqual("String", a.members[3].typeName.name);
            Assert.IsNotInstanceOfType(a.members[3].typeName, typeof(GenericTypeName));
        }
 public TupleDeclarationAssignmentExpression(TupleDeclarationExpression names, Expression values)
 {
     this.names  = names;
     this.values = values;
 }
 public AnonymousFunctionExpression(TupleDeclarationExpression arguments, TypeName returnType, BlockExpression body)
 {
     this.arguments  = arguments;
     this.returnType = returnType;
     this.body       = body;
 }