예제 #1
0
 public LambdaNode(FunctionParametersNode parameters, AstNode body, bool isSimple, int nodeIndex)
     : base(SyntaxKind.LambdaFunctionDefinitionExpression, null, null, nodeIndex)
 {
     Parameters            = parameters;
     Body                  = body;
     this.HasCurlyBrackets = body is BlockNode;
     this.IsSimple         = isSimple;
 }
예제 #2
0
 internal FunctionNode(string name, FunctionParametersNode parameters, int nodeIndex)
     : base(SyntaxKind.FunctionDefinitionExpression, "EXTERN", name, nodeIndex)
 {
     Name       = name;
     Parameters = parameters;
     IsExtern   = true;
     if (Parameters != null)
     {
         Parameters.Parent = this;
     }
 }
예제 #3
0
        public static FunctionParametersNode Parameters(ParameterNode[] parameters)
        {
            // if (parameters)

            var result = new FunctionParametersNode(_nodeIndex++);

            foreach (var p in parameters)
            {
                result.AddChild(p);
            }

            return(result);
        }
예제 #4
0
 internal FunctionNode(string name, FunctionParametersNode parameters, AstNode body, int nodeIndex)
     : base(SyntaxKind.FunctionDefinitionExpression, null, name, nodeIndex)
 {
     Name       = name;
     Parameters = parameters;
     Body       = body;
     if (body != null)
     {
         Body.Parent = this;
     }
     if (Parameters != null)
     {
         Parameters.Parent = this;
     }
 }
예제 #5
0
 internal FunctionNode(string name, XzaarType returnType, FunctionParametersNode parameters, int nodeIndex)
     : base(SyntaxKind.FunctionDefinitionExpression, "EXTERN", name, nodeIndex)
 {
     this.returnType = returnType;
     if (this.returnType != null)
     {
         this.Type = this.returnType.Name;
     }
     Name       = name;
     Parameters = parameters;
     IsExtern   = true;
     if (Parameters != null)
     {
         Parameters.Parent = this;
     }
 }
예제 #6
0
 internal FunctionNode(string name, XzaarType returnType, FunctionParametersNode parameters, AstNode body, int nodeIndex)
     : base(SyntaxKind.FunctionDefinitionExpression, null, name, nodeIndex)
 {
     this.returnType = returnType;
     if (this.returnType != null)
     {
         this.Type = this.returnType.Name;
     }
     Name       = name;
     Parameters = parameters;
     Body       = body;
     if (body != null)
     {
         Body.Parent = this;
     }
     if (Parameters != null)
     {
         Parameters.Parent = this;
     }
 }
예제 #7
0
        public static FunctionParametersNode Parameters(AstNode parameters)
        {
            // if (parameters)
            var r = parameters as FunctionParametersNode;

            if (r != null)
            {
                return(r);
            }

            var result = new FunctionParametersNode(_nodeIndex++);
            var count  = parameters.Children.Count;

            for (int i = 0; i < count; i += 2)
            {
                var type    = parameters[i];
                var isArray = parameters[i + 1].Kind == SyntaxKind.ArrayIndexExpression;
                if (isArray)
                {
                    type.Value += "[]";
                    i++;
                }

                var name = parameters[i + 1];
                result.AddChild(AstNode.Parameter(name, type));

                if (count > 2 && i + 2 < count)
                {
                    var value = parameters[i + 2].Value;
                    if (value?.ToString() != ",")
                    {
                        throw new ExpressionException($"Unexpected character '{value}' found in function parameter declaration");
                    }
                    i++; // skip separator
                }
            }

            return(result);
        }
예제 #8
0
 public static FunctionNode ExternFunction(string name, string returnType, FunctionParametersNode parameters)
 {
     // var functionParametersNode = Parameters(argumentsExpression);
     return(new FunctionNode(name, XzaarType.GetType(returnType), parameters, _nodeIndex++));
 }
예제 #9
0
 public static FunctionNode Function(string name, string returnType, FunctionParametersNode argumentsExpression, AstNode bodyExpression)
 {
     return(new FunctionNode(name, XzaarType.GetType(returnType), argumentsExpression, bodyExpression, _nodeIndex++));
 }
예제 #10
0
 public static FunctionNode Function(string name, FunctionParametersNode argumentsExpression)
 {
     return(new FunctionNode(name, argumentsExpression, null, _nodeIndex++));
 }
예제 #11
0
 public static LambdaNode Lambda(FunctionParametersNode paremeterExpression, AstNode bodyExpression)
 {
     return(new LambdaNode(paremeterExpression, bodyExpression, false, _nodeIndex++));
 }