예제 #1
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!");
            }
        }
예제 #2
0
        private static Expression objectInstantiation(Parser p, Token t)
        {
            TypeName type = DashParslets.getTypeName(p);

            if (p.peek(TokenType.LeftRoundBracket))
            {
                Expression arguments = p.parseExpression(0);

                if (arguments is TupleDefinitionExpression)
                {
                    return(new ClassInstantiationExpression(type, arguments as TupleDefinitionExpression));
                }
                else
                {
                    return(new ClassInstantiationExpression(type, new TupleDefinitionExpression(new List <Expression> {
                        arguments
                    })));
                }
            }
            else
            {
                throw new Exception("Missing parameter list for class instantiation!");
            }
        }