Beispiel #1
0
        Arguments getArguments()
        {
            var builder = new CodeBuilder();

            builder.Argument(indexes);
            return(builder.Arguments);
        }
Beispiel #2
0
        Arguments getArguments(Value value)
        {
            var builder = new CodeBuilder();

            builder.Argument(indexes);
            builder.ValueAsArgument(value);
            return(builder.Arguments);
        }
Beispiel #3
0
        static Arguments convertArguments(Arguments arguments)
        {
            var patternParameterParser = new PatternParameterListParser();

            if (patternParameterParser.Parse(arguments.ArgumentsBlock))
            {
                var list    = patternParameterParser.List;
                var builder = new CodeBuilder();
                foreach (var parameter in list)
                {
                    builder.Argument(parameter.Comparisand);
                }

                return(builder.Arguments);
            }

            return(arguments);
        }
Beispiel #4
0
        public bool Parse(Block block)
        {
            var variable = new Variable();

            condition = null;
            Multi     = true;

            string bindingName;

            if (block.Count == 0)
            {
                bindingName = "";
                list.Add(getParameter(0, new Any(), ref bindingName));
                return(true);
            }

            var addingToCondition = false;

            bindingName = "";
            foreach (var verb in block.AsAdded)
            {
                if (addingToCondition)
                {
                    condition.Add(verb);
                    continue;
                }

                switch (verb)
                {
                case Push push:
                    var value = push.Value;
                    switch (value)
                    {
                    case Variable variable1:
                        var name = variable1.Name;
                        value = name == "_" ? (Value) new Any() : new Placeholder(name);
                        break;

                    case Block arrayBlock when arrayBlock.AsAdded.Any(v => v is AppendToArray):
                        value = ReplacePlaceholders(arrayBlock);

                        break;
                    }

                    list.Add(getParameter(list.Count, value, ref bindingName));
                    break;

                case PushArrayLiteral pushArrayLiteral:
                    var array = pushArrayLiteral.Array;
                    list.Add(getParameter(list.Count, array, ref bindingName));
                    break;

                case FunctionInvoke functionInvoke:
                {
                    var functionName = functionInvoke.FunctionName;
                    var arguments    = functionInvoke.Arguments;
                    var innerParser  = new PatternParameterListParser();
                    if (innerParser.Parse(arguments.ArgumentsBlock))
                    {
                        var sublist = innerParser.List;
                        var builder = new CodeBuilder();
                        foreach (var parameter in sublist)
                        {
                            builder.Argument(parameter.Comparisand);
                        }

                        builder.FunctionInvoke(functionName);
                        list.Add(getParameter(list.Count, builder.Block, ref bindingName));
                    }

                    break;
                }

                case CreateLambda createLambda:
                    var closure = (Lambda)createLambda.Evaluate();
                    list.Add(getParameter(list.Count, closure, ref bindingName));
                    break;

                case SendMessage sendMessage when variable != null:
                {
                    var variableName = variable.Name;
                    var arguments    = sendMessage.Arguments;
                    removeLastParameter(list, ref bindingName);
                    var innerParser = new PatternParameterListParser();
                    if (innerParser.Parse(arguments.ArgumentsBlock))
                    {
                        var sublist = innerParser.List;
                        var builder = new CodeBuilder();
                        foreach (var parameter in sublist)
                        {
                            builder.Argument(parameter.Comparisand);
                        }

                        builder.Variable(variableName);
                        builder.SendMessage(sendMessage.Message, builder.Arguments);
                        list.Add(getParameter(list.Count, builder.Block, ref bindingName));
                    }

                    break;
                }

                case SendMessageToClass sendMessageToClass:
                {
                    var arguments   = sendMessageToClass.Arguments;
                    var innerParser = new PatternParameterListParser();
                    if (innerParser.Parse(arguments.ArgumentsBlock))
                    {
                        var sublist = innerParser.List;
                        var builder = new CodeBuilder();
                        foreach (var parameter in sublist)
                        {
                            builder.Argument(parameter.Comparisand);
                        }

                        builder.SendMessageToClass(sendMessageToClass.Message, builder.Arguments);
                        list.Add(getParameter(list.Count, builder.Block, ref bindingName));
                    }

                    break;
                }

                case Bind _ when variable != null:
                    list.RemoveAt(list.Count - 1);
                    bindingName = variable.Name;
                    break;

                case CreateSet createSet:
                    list.Add(getParameter(list.Count, createSet.Create(), ref bindingName));
                    break;

                case If _:
                    addingToCondition = true;
                    condition         = new Block();
                    break;

                case ToList toList:
                    var newlist = ReplacePlaceholdersInList(toList.Block);
                    list.Add(getParameter(list.Count, newlist, ref bindingName));
                    break;
                }
            }

            if (condition != null)
            {
                condition.AutoRegister = false;
            }
            return(true);
        }