Пример #1
0
    void ExecuteAction(List <string> actions)
    {
        actions.Reverse();
        List <RihaNode> finishedActionsReturns = new List <RihaNode>();

        foreach (string action in actions)
        {
            string[] words    = SplitWords(action).ToArray();
            object   isAction = EvaluateAction(action, words, finishedActionsReturns);
            if (isAction == null)
            {
                RihaNode functionNode = IsFunction(action, words);
                if (functionNode != null)
                {
                    string[]   functions      = words[0].Split('.');
                    string     methodName     = (functionNode.GetNodeType() == ValueType.GLOBAL) ? "GlobalCall" : functions[1].ToLower();
                    MethodInfo functionMethod = functionNode.GetType().GetMethod(methodName);
                    if (functionMethod != null)
                    {
                        object[] parameters;
                        if ((functionNode.GetNodeType() == ValueType.GLOBAL))
                        {
                            parameters = new object[] {
                                functions[1].ToLower(),
                                finishedActionsReturns.ToArray(),
                            };
                        }
                        else
                        {
                            parameters = new object[] {
                                finishedActionsReturns.ToArray(),
                            };
                        }
                        RihaNode returnValue = (RihaNode)functionMethod.Invoke(functionNode, parameters);
                        finishedActionsReturns.Add(returnValue);
                    }
                }
                else
                {
                    MethodInfo actionMethod = this.GetType().GetMethod(words[0].ToLower());
                    if (actionMethod != null)
                    {
                        object[] parameters = new object[] {
                            action,
                            words,
                            finishedActionsReturns.ToArray()
                        };
                        actionMethod.Invoke(this, parameters);
                    }
                }
            }
            else
            {
                finishedActionsReturns.Add(isAction == null ? null : (RihaNode)isAction);
            }
        }
    }
Пример #2
0
    public RihaNode set(RihaNode[] parameters)
    {
        RihaNode p = parameters[parameters.Length - 1];

        this.value = p.value;
        this.type  = p.GetNodeType();
        return(this);
    }
Пример #3
0
    public RihaNode equal_type(RihaNode[] parameters)
    {
        bool     ret            = false;
        RihaNode comperisonNode = parameters[parameters.Length - 1];

        if (comperisonNode.GetNodeType() == GetNodeType())
        {
            ret = true;
        }
        return(new RihaNode(ValueType.boolean, ret));
    }
Пример #4
0
 public void Add(RihaNode addNode)
 {
     if (type == ValueType.number)
     {
         float add      = addNode.GetNodeType() == ValueType.number ? RihaNode.GetNumeric(addNode.GetValue()) : 0;
         float newValue = RihaNode.GetNumeric(value) + add;
         value = newValue.ToString();
     }
     else if (type == ValueType.text)
     {
         value += addNode.GetString();
     }
     else if (type == ValueType.array)
     {
         ((List <RihaNode>)value).Add(addNode);
     }
 }
Пример #5
0
    public void scope(string action, string[] words, RihaNode[] previuseActionResult)
    {
        string setPattern = @"\s*scope\s+\w+\s*";

        if (MatchesRegex(action, setPattern))
        {
            RihaNode  value = previuseActionResult[previuseActionResult.Length - 1];
            ScopeType type  = GetScopeType(words[1]);
            if (type == ScopeType.check && value.GetNodeType() == ValueType.boolean || type == ScopeType.loop && value.GetNodeType() == ValueType.number)
            {
                scopes.Add(new RihaScope()
                {
                    type      = type,
                    parameter = value,
                    startLine = lineNumber
                });
            }
        }
    }