public static IExpression TryEvaluate(this INode self, EvaluationParameters parameters) {
     if (self == null)
         return null;
     if (self.Flags.HasFlag(NodeFlags.IsExpression))
         return ((IExpressionNode)self).Evaluate(parameters);
     return new Expressions.GenericExpression(self);
 }
        public IExpression EvaluateGenericElement(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            GenericTagEvaluator eval;

            _GenericTagEvaluators.TryGetValue(element.Tag, out eval);
            return((eval ?? DefaultGenericTagEvaluator)(parameters, element));
        }
        protected virtual IExpression EvaluateTime(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            /* Appears to set values for an input time.
             * - 222 / DEh  Year
             * - 221 / DDh  Month
             * - 220 / DCh  Day of week
             * - 219 / DBh  Day of month
             * - 218 / DAh  Hour
             * - 217 / D9h  Minute
             */

            IExpression argEval = element.Arguments.First().TryEvaluate(parameters);
            int         argInt  = ToInteger(argEval);

            DateTime utcTime   = EorzeaDateTime.Zero.AddSeconds(argInt);
            DateTime localTime = utcTime.ToLocalTime();

            parameters.TopLevelParameters[0xDE] = localTime.Year;
            parameters.TopLevelParameters[0xDD] = localTime.Month;
            parameters.TopLevelParameters[0xDC] = 1 + (int)localTime.DayOfWeek;
            parameters.TopLevelParameters[0xDB] = localTime.Day;
            parameters.TopLevelParameters[0xDA] = localTime.Hour;
            parameters.TopLevelParameters[0xD9] = localTime.Minute;

            return(GenericExpression.Empty);
        }
        protected virtual IExpression EvaluateSheet(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            IExpression[] evalArgs = element.Arguments.Select(_ => _.TryEvaluate(parameters)).ToArray();
            if (evalArgs.Length < 2)
            {
                throw new InvalidOperationException();
            }
            string sheetName = evalArgs[0].ToString();
            int    rowKey    = ToInteger(evalArgs[1]);
            int    colKey    = 0;

            if (evalArgs.Length > 2)
            {
                colKey = ToInteger(evalArgs[2]);
            }

            XivRow row   = Data.GetSheet(sheetName)[rowKey];
            object value = row[colKey];

            if (value is INode)
            {
                EvaluationParameters innerParams = new EvaluationParameters(parameters);
                innerParams.InputParameters.Clear();
                for (int i = 3; i < evalArgs.Length; ++i)
                {
                    innerParams.InputParameters[i - 2] = evalArgs[i];
                }


                value = EvaluationHelper.TryEvaluate((INode)value, innerParams);
            }

            return(new GenericExpression(new ObjectWithDisplay(value, row)));
        }
        protected virtual IExpression EvaluateTwoDigitValue(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            IExpression eval   = element.Content.TryEvaluate(parameters);
            int         intVal = ToInteger(eval);

            return(new GenericExpression(intVal.ToString("D2")));
        }
        protected virtual IExpression EvaluateDefaultGenericElement(EvaluationParameters parameters, GenericElement element)
        {
            List <IExpression> items = new List <IExpression>();
            bool hasArgs             = element.Arguments.Any();

            items.Add(new GenericExpression(StringTokens.TagOpen + element.Tag.ToString()));
            if (hasArgs)
            {
                items.Add(new SurroundedExpression(StringTokens.ArgumentsOpen, new ExpressionCollection(element.Arguments.Select(_ => _.TryEvaluate(parameters)))
                {
                    Separator = StringTokens.ArgumentsSeperator
                }, StringTokens.ArgumentsClose));
            }

            if (element.Content == null)
            {
                items.Add(new GenericExpression(StringTokens.ElementClose + StringTokens.TagClose));
            }
            else
            {
                items.Add(new GenericExpression(StringTokens.TagClose));
                items.Add(element.Content.TryEvaluate(parameters));
                items.Add(new GenericExpression(StringTokens.TagOpen + StringTokens.ElementClose + element.Tag.ToString() + StringTokens.TagClose));
            }

            return(new ExpressionCollection(items));
        }
Example #7
0
        public bool Compare(EvaluationParameters parameters, DecodeExpressionType comparisonType, INode left, INode right)
        {
            var evalLeft  = left.TryEvaluate(parameters);
            var evalRight = right.TryEvaluate(parameters);

            switch (comparisonType)
            {
            case DecodeExpressionType.GreaterThanOrEqualTo: {
                var iLeft  = ToInteger(evalLeft);
                var iRight = ToInteger(evalRight);
                return(iLeft >= iRight);
            }

            case DecodeExpressionType.LessThanOrEqualTo: {
                var iLeft  = ToInteger(evalLeft);
                var iRight = ToInteger(evalRight);
                return(iLeft <= iRight);
            }

            case DecodeExpressionType.Equal:
                return(ExpressionsEqual(evalLeft, evalRight));

            case DecodeExpressionType.NotEqual:
                return(!ExpressionsEqual(evalLeft, evalRight));

            default:
                throw new NotSupportedException();
            }
        }
        protected virtual IExpression EvaluateZeroPaddedValue(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            IExpression lenEval = element.Arguments.First().TryEvaluate(parameters);
            int         len     = ToInteger(lenEval);
            IExpression eval    = element.Content.TryEvaluate(parameters);
            int         intVal  = ToInteger(eval);

            return(new GenericExpression(intVal.ToString("D" + len.ToString())));
        }
 public EvaluationParameters(EvaluationParameters copyFrom)
 {
     if (copyFrom == null)
         throw new ArgumentNullException("copyFrom");
     _FunctionProvider = copyFrom.FunctionProvider;
     _TopLevelParameters = new Parameters.ParameterBase(copyFrom.TopLevelParameters);
     _Parameters.Add(DecodeExpressionType.IntegerParameter, new Parameters.ParameterBase(copyFrom._Parameters[DecodeExpressionType.IntegerParameter]));
     _Parameters.Add(DecodeExpressionType.PlayerParameter, new Parameters.PlayerParameters(copyFrom._Parameters[DecodeExpressionType.PlayerParameter]));
     _Parameters.Add(DecodeExpressionType.StringParameter, new Parameters.ParameterBase(copyFrom._Parameters[DecodeExpressionType.StringParameter]));
     _Parameters.Add(DecodeExpressionType.ObjectParameter, new Parameters.ObjectParameters(copyFrom._Parameters[DecodeExpressionType.ObjectParameter]));
 }
 public static IExpression TryEvaluate(this INode self, EvaluationParameters parameters)
 {
     if (self == null)
     {
         return(null);
     }
     if (self.Flags.HasFlag(NodeFlags.IsExpression))
     {
         return(((IExpressionNode)self).Evaluate(parameters));
     }
     return(new Expressions.GenericExpression(self));
 }
Example #11
0
 public EvaluationParameters(EvaluationParameters copyFrom)
 {
     if (copyFrom == null)
     {
         throw new ArgumentNullException("copyFrom");
     }
     _FunctionProvider   = copyFrom.FunctionProvider;
     _TopLevelParameters = new Parameters.ParameterBase(copyFrom.TopLevelParameters);
     _Parameters.Add(DecodeExpressionType.IntegerParameter, new Parameters.ParameterBase(copyFrom._Parameters[DecodeExpressionType.IntegerParameter]));
     _Parameters.Add(DecodeExpressionType.PlayerParameter, new Parameters.PlayerParameters(copyFrom._Parameters[DecodeExpressionType.PlayerParameter]));
     _Parameters.Add(DecodeExpressionType.StringParameter, new Parameters.ParameterBase(copyFrom._Parameters[DecodeExpressionType.StringParameter]));
     _Parameters.Add(DecodeExpressionType.ObjectParameter, new Parameters.ObjectParameters(copyFrom._Parameters[DecodeExpressionType.ObjectParameter]));
 }
        protected virtual IExpression EvaluateSheetWithAttributive(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            var evalArgs = element.Arguments.Select(_ => _.TryEvaluate(parameters)).ToArray();
            if (evalArgs.Length < 3)
                throw new InvalidOperationException();

            var lang = TagToLanguageMap[element.Tag];

            var sheetName = evalArgs[0].ToString();
            var attributiveRowKey = ToInteger(evalArgs[1]);
            var rowKey = ToInteger(evalArgs[2]);

            var columnKey = 0;
            if (evalArgs.Length > 3)
                columnKey = ToInteger(evalArgs[3]);

            var attributiveColumnKey = AttributiveColumnOffsets[element.Tag];
            if (evalArgs.Length > 4)
                attributiveColumnKey += ToInteger(evalArgs[4]);

            var row = Data.GetSheet(sheetName)[rowKey];
            object value;
            if (row is Ex.IMultiRow)
                value = ((Ex.IMultiRow)row)[columnKey, lang];
            else
                value = row[columnKey];

            var attributiveRow = Data.GetSheet(AttributiveSheetName)[attributiveRowKey];
            object attributiveValue;
            if (attributiveRow is Ex.IMultiRow)
                attributiveValue = ((Ex.IMultiRow)attributiveRow)[attributiveColumnKey, lang];
            else
                attributiveValue = attributiveRow[attributiveColumnKey];

            var innerParams = new EvaluationParameters(parameters);
            innerParams.InputParameters.Clear();
            for (var i = 5; i < evalArgs.Length; ++i)
                innerParams.InputParameters[i - 2] = evalArgs[i];

            if (value is INode)
                value = EvaluationHelper.TryEvaluate((INode)value, innerParams);
            if (attributiveValue is INode)
                attributiveValue = EvaluationHelper.TryEvaluate((INode)attributiveValue, innerParams);

            return new SurroundedExpression(new ObjectWithDisplay(attributiveValue, attributiveRow), new ObjectWithDisplay(value, row), null);
        }
        public bool Compare(EvaluationParameters parameters, DecodeExpressionType comparisonType, INode left, INode right)
        {
            var evalLeft = left.TryEvaluate(parameters);
            var evalRight = right.TryEvaluate(parameters);

            switch (comparisonType) {
                case DecodeExpressionType.GreaterThanOrEqualTo: {
                        var iLeft = ToInteger(evalLeft);
                        var iRight = ToInteger(evalRight);
                        return iLeft >= iRight;
                    }
                case DecodeExpressionType.LessThanOrEqualTo: {
                        var iLeft = ToInteger(evalLeft);
                        var iRight = ToInteger(evalRight);
                        return iLeft <= iRight;
                    }
                case DecodeExpressionType.Equal:
                    return ExpressionsEqual(evalLeft, evalRight);
                case DecodeExpressionType.NotEqual:
                    return !ExpressionsEqual(evalLeft, evalRight);
                default:
                    throw new NotSupportedException();
            }
        }
        protected virtual IExpression EvaluateZeroPaddedValue(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            var lenEval = element.Arguments.First().TryEvaluate(parameters);
            var len = ToInteger(lenEval);
            var eval = element.Content.TryEvaluate(parameters);
            var intVal = ToInteger(eval);

            return new GenericExpression(intVal.ToString("D" + len.ToString()));
        }
 protected virtual IExpression EvaluateTwoDigitValue(EvaluationParameters parameters, Nodes.GenericElement element)
 {
     var eval = element.Content.TryEvaluate(parameters);
     var intVal = ToInteger(eval);
     return new GenericExpression(intVal.ToString("D2"));
 }
        protected virtual IExpression EvaluateTime(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            /* Appears to set values for an input time.
             * - 222 / DEh  Year
             * - 221 / DDh  Month
             * - 220 / DCh  Day of week
             * - 219 / DBh  Day of month
             * - 218 / DAh  Hour
             * - 217 / D9h  Minute
             */

            var argEval = element.Arguments.First().TryEvaluate(parameters);
            var argInt = ToInteger(argEval);

            var utcTime = EorzeaDateTime.Zero.AddSeconds(argInt);
            var localTime = utcTime.ToLocalTime();

            parameters.TopLevelParameters[0xDE] = localTime.Year;
            parameters.TopLevelParameters[0xDD] = localTime.Month;
            parameters.TopLevelParameters[0xDC] = 1 + (int)localTime.DayOfWeek;
            parameters.TopLevelParameters[0xDB] = localTime.Day;
            parameters.TopLevelParameters[0xDA] = localTime.Hour;
            parameters.TopLevelParameters[0xD9] = localTime.Minute;

            return GenericExpression.Empty;
        }
        protected virtual IExpression EvaluateSheetWithAttributive(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            IExpression[] evalArgs = element.Arguments.Select(_ => _.TryEvaluate(parameters)).ToArray();
            if (evalArgs.Length < 3)
            {
                throw new InvalidOperationException();
            }

            Ex.Language lang = TagToLanguageMap[element.Tag];

            string sheetName         = evalArgs[0].ToString();
            int    attributiveRowKey = ToInteger(evalArgs[1]);
            int    rowKey            = ToInteger(evalArgs[2]);

            int columnKey = 0;

            if (evalArgs.Length > 3)
            {
                columnKey = ToInteger(evalArgs[3]);
            }

            int attributiveColumnKey = AttributiveColumnOffsets[element.Tag];

            if (evalArgs.Length > 4)
            {
                attributiveColumnKey += ToInteger(evalArgs[4]);
            }

            XivRow row = Data.GetSheet(sheetName)[rowKey];
            object value;

            if (row is Ex.IMultiRow)
            {
                value = ((Ex.IMultiRow)row)[columnKey, lang];
            }
            else
            {
                value = row[columnKey];
            }

            XivRow attributiveRow = Data.GetSheet(AttributiveSheetName)[attributiveRowKey];
            object attributiveValue;

            if (attributiveRow is Ex.IMultiRow)
            {
                attributiveValue = ((Ex.IMultiRow)attributiveRow)[attributiveColumnKey, lang];
            }
            else
            {
                attributiveValue = attributiveRow[attributiveColumnKey];
            }

            EvaluationParameters innerParams = new EvaluationParameters(parameters);

            innerParams.InputParameters.Clear();
            for (int i = 5; i < evalArgs.Length; ++i)
            {
                innerParams.InputParameters[i - 2] = evalArgs[i];
            }

            if (value is INode)
            {
                value = EvaluationHelper.TryEvaluate((INode)value, innerParams);
            }
            if (attributiveValue is INode)
            {
                attributiveValue = EvaluationHelper.TryEvaluate((INode)attributiveValue, innerParams);
            }

            return(new SurroundedExpression(new ObjectWithDisplay(attributiveValue, attributiveRow), new ObjectWithDisplay(value, row), null));
        }
        protected virtual IExpression EvaluateDefaultGenericElement(EvaluationParameters parameters, GenericElement element)
        {
            var items = new List<IExpression>();
            var hasArgs = element.Arguments.Any();
            items.Add(new GenericExpression(StringTokens.TagOpen + element.Tag.ToString()));
            if (hasArgs)
                items.Add(new SurroundedExpression(StringTokens.ArgumentsOpen, new ExpressionCollection(element.Arguments.Select(_ => _.TryEvaluate(parameters))) { Separator = StringTokens.ArgumentsSeperator }, StringTokens.ArgumentsClose));

            if (element.Content == null) {
                items.Add(new GenericExpression(StringTokens.ElementClose + StringTokens.TagClose));
            } else {
                items.Add(new GenericExpression(StringTokens.TagClose));
                items.Add(element.Content.TryEvaluate(parameters));
                items.Add(new GenericExpression(StringTokens.TagOpen + StringTokens.ElementClose + element.Tag.ToString() + StringTokens.TagClose));
            }

            return new ExpressionCollection(items);
        }
        protected virtual IExpression EvaluateSheet(EvaluationParameters parameters, Nodes.GenericElement element)
        {
            var evalArgs = element.Arguments.Select(_ => _.TryEvaluate(parameters)).ToArray();
            if (evalArgs.Length < 2)
                throw new InvalidOperationException();
            var sheetName = evalArgs[0].ToString();
            var rowKey = ToInteger(evalArgs[1]);
            var colKey = 0;
            if (evalArgs.Length > 2)
                colKey = ToInteger(evalArgs[2]);

            var row = Data.GetSheet(sheetName)[rowKey];
            var value = row[colKey];
            if (value is INode) {
                var innerParams = new EvaluationParameters(parameters);
                innerParams.InputParameters.Clear();
                for (var i = 3; i < evalArgs.Length; ++i)
                    innerParams.InputParameters[i - 2] = evalArgs[i];

                value = EvaluationHelper.TryEvaluate((INode)value, innerParams);
            }

            return new GenericExpression(new ObjectWithDisplay(value, row));
        }
 public IExpression Evaluate(EvaluationParameters parameters)
 {
     return(new Expressions.ExpressionCollection(Children.Select(c => c.TryEvaluate(parameters))));
 }
 public IExpression EvaluateGenericElement(EvaluationParameters parameters, Nodes.GenericElement element)
 {
     GenericTagEvaluator eval;
     _GenericTagEvaluators.TryGetValue(element.Tag, out eval);
     return (eval ?? DefaultGenericTagEvaluator)(parameters, element);
 }