public override LuaValue Evaluate(LuaTable enviroment)
        {
            LuaTable table = new LuaTable();

            foreach (Field field in this.FieldList)
            {
                NameValue nameValue = field as NameValue;
                if (nameValue != null)
                {
                    table.SetNameValue(nameValue.Name, nameValue.Value.Evaluate(enviroment));
                    continue;
                }

                KeyValue keyValue = field as KeyValue;
                if (keyValue != null)
                {
                    table.SetKeyValue(
                        keyValue.Key.Evaluate(enviroment),
                        keyValue.Value.Evaluate(enviroment));
                    continue;
                }

                ItemValue itemValue = field as ItemValue;
                if (itemValue != null)
                {
                    table.AddValue(itemValue.Value.Evaluate(enviroment));
                    continue;
                }
            }

            return(table);
        }
Esempio n. 2
0
        private NameValue ParseNameValue(out bool success)
        {
            var reskey = new Tuple<int, string>(position, "NameValue");
            if (ParsingResults.ContainsKey(reskey))
            {
                var parsingResult = ParsingResults[reskey];
                success = parsingResult.Item2;
                position = parsingResult.Item3;
                return parsingResult.Item1 as NameValue;
            }

            int errorCount = Errors.Count;
            NameValue nameValue = new NameValue();
            int start_position = position;

            nameValue.Name = ParseName(out success);
            if (!success)
            {
                position = start_position;
                ParsingResults[reskey] = new Tuple<object, bool, int>(nameValue, success, position);return nameValue;
            }

            ParseSpOpt(out success);

            MatchTerminal('=', out success);
            if (!success)
            {
                Error("Failed to parse '=' of NameValue.");
                position = start_position;
                ParsingResults[reskey] = new Tuple<object, bool, int>(nameValue, success, position);return nameValue;
            }

            ParseSpOpt(out success);

            nameValue.Value = ParseExpr(out success);
            if (!success)
            {
                Error("Failed to parse Value of NameValue.");
                position = start_position;
            }

            if (success) { ClearError(errorCount); }
            ParsingResults[reskey] = new Tuple<object, bool, int>(nameValue, success, position);
            return nameValue;
        }