Exemplo n.º 1
0
        public KirinValue Load()
        {
            if (this.Raw == null)
            {
                if (FiMHelper.IsTypeArray(this.Type))
                {
                    this._Value = FiMHelper.GetDefaultValue(this.Type);
                }
                else
                {
                    if (this.ForcedType == null)
                    {
                        throw new FiMException("Value is null");
                    }
                    this._Value = FiMHelper.GetDefaultValue((KirinVariableType)this.ForcedType);
                }
            }
            else
            {
                string raw = this.Raw;

                var eType = FiMHelper.DeclarationType.Determine(" " + raw, out string eKeyword, false);
                if (eType != KirinVariableType.UNKNOWN)
                {
                    raw = raw.Substring(eKeyword.Length);
                    this.ForceType(eType);
                }

                if (this.ForcedType != null)
                {
                    eType = (KirinVariableType)this.ForcedType;
                }

                object value;
                if (KirinLiteral.TryParse(raw, out object lResult))
                {
                    value = lResult;
                }
                else
                {
                    value = KirinValue.Evaluate(Class, raw, out var returnedType, ForcedType);
                    this.ForceType(returnedType);
                }

                if (eType != KirinVariableType.UNKNOWN && FiMHelper.AsVariableType(value) != eType)
                {
                    throw new FiMException("Expected " + eType.AsNamedString() + ", got " + FiMHelper.AsVariableType(value));
                }
                this._Value = value;
            }
            return(this);
        }
Exemplo n.º 2
0
        public override object Execute(FiMClass reportClass)
        {
            var variable = reportClass.GetVariable(this.RawVariable);

            if (variable == null)
            {
                throw new Exception("Variable " + this.RawVariable + " does not exist");
            }
            if (FiMHelper.IsTypeArray(variable.Type))
            {
                throw new Exception("Cannot input into an array");
            }


            string prompt = "";

            if (!string.IsNullOrWhiteSpace(this.PromptString))
            {
                prompt = this.PromptString;
            }
            string input = reportClass.Report.Input(prompt, this.RawVariable);

            if (variable.Type == KirinVariableType.STRING)
            {
                input = $"\"{input}\"";
            }
            else if (variable.Type == KirinVariableType.CHAR)
            {
                input = $"'{input}'";
            }

            if (!KirinLiteral.TryParse(input, out object value))
            {
                throw new Exception("Invalid input " + input);
            }
            if (FiMHelper.AsVariableType(value) != variable.Type)
            {
                throw new Exception("Input type doesnt match variable type");
            }

            variable.Value = value;

            return(null);
        }