示例#1
0
 public bool Match(XMLLuaSearchLocalAssignment req, LocalAssignment real)
 {
     Logger.Debug($"local_assignment");
     if (req.Expressions.Count != real.Values.Count)
     {
         return(false);
     }
     if (req.Names.Count != real.Names.Count)
     {
         return(false);
     }
     for (var i = 0; i < req.Expressions.Count; i++)
     {
         if (!Match(req.Expressions[i], real.Values[i]))
         {
             return(false);
         }
     }
     for (var i = 0; i < req.Names.Count; i++)
     {
         if (req.Names[i] != real.Names[i])
         {
             return(false);
         }
     }
     SetSelectionIfSelected(real.Span, req);
     return(true);
 }
示例#2
0
        public async Task ExecuteLocalAssignment(LocalAssignment assign, LuaState state, CancellationToken token = default)
        {
            for (var i = 0; i < assign.Names.Count; i++)
            {
                var var = assign.Names[i];
                var ret = i < assign.Values.Count
                    ? await _engine.EvaluateExpression(assign.Values[i], state, token).FirstAsync()
                    : LuaNil.Instance;

                state.Context.NewIndexRaw(var, ret);
            }
        }
示例#3
0
    public void Read(TProtocol iprot)
    {
        bool   isset_assignments = false;
        TField field;

        iprot.ReadStructBegin();
        while (true)
        {
            field = iprot.ReadFieldBegin();
            if (field.Type == TType.Stop)
            {
                break;
            }
            switch (field.ID)
            {
            case 1:
                if (field.Type == TType.Map)
                {
                    {
                        Assignments = new Dictionary <int, LocalAssignment>();
                        TMap _map232 = iprot.ReadMapBegin();
                        for (int _i233 = 0; _i233 < _map232.Count; ++_i233)
                        {
                            int             _key234;
                            LocalAssignment _val235;
                            _key234 = iprot.ReadI32();
                            _val235 = new LocalAssignment();
                            _val235.Read(iprot);
                            Assignments[_key234] = _val235;
                        }
                        iprot.ReadMapEnd();
                    }
                    isset_assignments = true;
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            default:
                TProtocolUtil.Skip(iprot, field.Type);
                break;
            }
            iprot.ReadFieldEnd();
        }
        iprot.ReadStructEnd();
        if (!isset_assignments)
        {
            throw new TProtocolException(TProtocolException.INVALID_DATA);
        }
    }
 public void Read (TProtocol iprot)
 {
   bool isset_assignments = false;
   TField field;
   iprot.ReadStructBegin();
   while (true)
   {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) { 
       break;
     }
     switch (field.ID)
     {
       case 1:
         if (field.Type == TType.Map) {
           {
             Assignments = new Dictionary<int, LocalAssignment>();
             TMap _map232 = iprot.ReadMapBegin();
             for( int _i233 = 0; _i233 < _map232.Count; ++_i233)
             {
               int _key234;
               LocalAssignment _val235;
               _key234 = iprot.ReadI32();
               _val235 = new LocalAssignment();
               _val235.Read(iprot);
               Assignments[_key234] = _val235;
             }
             iprot.ReadMapEnd();
           }
           isset_assignments = true;
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       default: 
         TProtocolUtil.Skip(iprot, field.Type);
         break;
     }
     iprot.ReadFieldEnd();
   }
   iprot.ReadStructEnd();
   if (!isset_assignments)
     throw new TProtocolException(TProtocolException.INVALID_DATA);
 }
示例#5
0
        internal static LuaArguments EvalBlock(Block Block, LuaContext Context, out LuaReturnStatus returned)
        {
            returned.broke    = false;
            returned.returned = false;
            LuaArguments obj = new LuaObject[] { LuaObject.Nil };

            foreach (IStatement stat in Block.Statements)
            {
                if (stat is Assignment)
                {
                    Assignment   assign = stat as Assignment;
                    LuaArguments values = null;
                    foreach (IExpression expr in assign.Expressions)
                    {
                        if (values == null)
                        {
                            values = EvalExpression(expr, Context);
                        }
                        else
                        {
                            values.Concat(EvalExpression(expr, Context));
                        }
                    }
                    for (int i = 0; i < assign.Variables.Count; i++)
                    {
                        SetAssignable(assign.Variables[i], values[i], Context);
                    }
                }
                else if (stat is LocalAssignment)
                {
                    LocalAssignment assign = stat as LocalAssignment;
                    LuaArguments    values = null;
                    foreach (IExpression expr in assign.Values)
                    {
                        if (values == null)
                        {
                            values = EvalExpression(expr, Context);
                        }
                        else
                        {
                            values.Concat(EvalExpression(expr, Context));
                        }
                    }
                    for (int i = 0; i < assign.Names.Count; i++)
                    {
                        Context.SetLocal(assign.Names[i], values[i]);
                    }
                }
                else if (stat is ReturnStat)
                {
                    ReturnStat ret = stat as ReturnStat;
                    returned.returned = true;
                    List <LuaObject> values = new List <LuaObject>();
                    int i = 0;
                    foreach (IExpression expr in ret.Expressions)
                    {
                        if (i == ret.Expressions.Count - 1)
                        {
                            values.AddRange(EvalExpression(expr, Context));
                        }
                        else
                        {
                            values.Add(EvalExpression(expr, Context)[0]);
                        }
                        i++;
                    }
                    return(values.ToArray());
                }
                else if (stat is FunctionCall)
                {
                    FunctionCall call = stat as FunctionCall;
                    EvalFunctionCall(call, Context);
                }
                else if (stat is Block)
                {
                    Block      block = stat as Block;
                    LuaContext ctx   = new LuaContext(Context);
                    obj = EvalBlock(block, ctx, out returned);
                    if (returned.returned)
                    {
                        return(obj);
                    }
                }
                else if (stat is IfStat)
                {
                    obj = EvalIf(stat as IfStat, Context, out returned);
                    if (returned.returned)
                    {
                        return(obj);
                    }
                }
                else if (stat is WhileStat)
                {
                    obj = EvalWhile(stat as WhileStat, Context, out returned);
                    if (returned.returned)
                    {
                        return(obj);
                    }
                }
                else if (stat is RepeatStat)
                {
                    obj = EvalRepeat(stat as RepeatStat, Context, out returned);
                    if (returned.returned)
                    {
                        return(obj);
                    }
                }
                else if (stat is BreakStat)
                {
                    returned.returned = false;
                    returned.broke    = true;
                    return(Lua.Return(LuaObject.Nil));
                }
                else if (stat is NumericFor)
                {
                    obj = EvalNumericFor(stat as NumericFor, Context, out returned);
                    if (returned.returned)
                    {
                        return(obj);
                    }
                }
                else
                {
                    obj = EvalGenericFor(stat as GenericFor, Context, out returned);
                    if (returned.returned)
                    {
                        return(obj);
                    }
                }
            }

            return(obj);
        }
示例#6
0
        LocalAssignment ParseLocalAssign(ParseTreeNode node)
        {
            if (node.Term.Name == "LocalAssignment")
            {
                LocalAssignment assign = new LocalAssignment();

                var child = node.ChildNodes[1];

                if (child.ChildNodes[0].Term.Name == "LocalFunction")
                {
                    child = child.ChildNodes[0];

                    var argsNode  = child.ChildNodes[2];
                    var blockNode = child.ChildNodes[3];

                    assign.Names.Add(child.ChildNodes[1].Token.ValueString);
                    var func = new FunctionDefinition();

                    if (argsNode.ChildNodes.Count > 0)
                    {
                        argsNode = argsNode.ChildNodes[0];
                        while (argsNode.ChildNodes.Count > 0)
                        {
                            var current = argsNode.ChildNodes[0];
                            var token   = current.Token ?? current.ChildNodes.FirstOrDefault()?.Token ?? throw new NullReferenceException("Could not find the token.");

                            string ident = token.ValueString;
                            func.Arguments.Add(new Argument()
                            {
                                Name = ident
                            });
                            if (argsNode.ChildNodes.Count == 1)
                            {
                                break;
                            }
                            argsNode = argsNode.ChildNodes[1];
                        }
                    }

                    func.Body = ParseBlock(blockNode);

                    assign.Values.Add(func);
                    return(assign);
                }

                var left  = child.ChildNodes[0];
                var right = child.ChildNodes[1];

                assign.Names.Add(left.ChildNodes[0].Token.ValueString);

                left = left.ChildNodes[1];

                while (left.ChildNodes.Count > 0)
                {
                    left = left.ChildNodes[0];
                    assign.Names.Add(left.ChildNodes[0].Token.ValueString);
                    left = left.ChildNodes[1];
                }

                while (right.ChildNodes.Count > 0)
                {
                    right = right.ChildNodes[0];
                    assign.Values.Add(ParseExpression(right.ChildNodes[0]));
                    right = right.ChildNodes[1];
                }

                return(assign);
            }
            throw new Exception("Invalid LocalAssignment node");
        }