Exemplo n.º 1
0
        bool Function(ElementBaseJson func, out FunctionExpression expr)
        {
            if (!Match(Kw(func.Name), false))
            {
                expr = null;
                return(false);
            }

            // Get the parameter values.
            List <ITTEExpression> values = new List <ITTEExpression>();

            if (Match("("))
            {
                int currentParameter = 0;
                do
                {
                    ElementParameter parameter = null;
                    if (func.Parameters != null && currentParameter < func.Parameters.Length)
                    {
                        parameter = func.Parameters[currentParameter];
                    }

                    // Variable reference
                    if (parameter != null && parameter.IsVariableReference)
                    {
                        // Match the variable parameter.
                        if (!Identifier(out string identifier))
                        {
                            throw new Exception("Failed to retrieve identifier of variable parameter.");
                        }

                        AddIfOmitted(identifier, parameter.VariableReferenceIsGlobal.Value);
                        values.Add(new AnonymousVariableExpression(identifier, parameter.VariableReferenceIsGlobal.Value));
                    }
                    // Enumerator
                    else if (parameter?.Type != null && ElementRoot.Instance.TryGetEnum(parameter.Type, out var enumerator))
                    {
                        // Match enum member
                        foreach (var member in enumerator.Members.OrderByDescending(m => m.Name.Length))
                        {
                            if (Match(Kw(member.DecompileName()), false))
                            {
                                values.Add(new ConstantEnumeratorExpression(member));
                                break;
                            }
                        }
                    }
                    // Normal parameter
                    else
                    {
                        if (ContainExpression(out ITTEExpression value))
                        {
                            values.Add(value);
                        }
                    }

                    // Increment the current parameter.
                    currentParameter++;
                }while (Match(","));
                Match(")");
            }

            expr = new FunctionExpression(func, values.ToArray());
            return(true);
        }
 public FunctionExpression(ElementBaseJson function, ITTEExpression[] values)
 {
     Function = function;
     Values   = values;
 }