Exemple #1
0
        public Variable GetProperty(string propName, ParsingScript script = null)
        {
            Variable result = Variable.EmptyInstance;

            int ind = propName.IndexOf('.');

            if (ind > 0)
            { // The case x = a.b.c ... is dealt here recursively
                string   varName        = propName.Substring(0, ind);
                string   actualPropName = propName.Substring(ind + 1);
                Variable property       = GetProperty(varName, script);
                result = string.IsNullOrEmpty(actualPropName) ? property :
                         property.GetProperty(actualPropName, script);
                return(result);
            }

            if (Object is ScriptObject)
            {
                ScriptObject obj   = Object as ScriptObject;
                string       match = GetActualPropertyName(propName, obj.GetProperties());
                if (!string.IsNullOrWhiteSpace(match))
                {
                    List <Variable> args = null;
                    if (script != null && script.TryPrev() == Constants.START_ARG)
                    {
                        args = script.GetFunctionArgs();
                    }
                    else if (script != null)
                    {
                        args = new List <Variable>();
                    }
                    var task = obj.GetProperty(match, args, script);
                    result = task != null ? task.Result : null;
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(GetCoreProperty(propName, script));
        }
Exemple #2
0
        private static bool StillCollecting(string item, char[] to, ParsingScript script,
                                            ref string action)
        {
            char prev = script.TryPrevPrev();
            char ch   = script.TryPrev();
            char next = script.TryCurrent();

            if (to.Contains(ch) || ch == Constants.START_ARG ||
                ch == Constants.START_GROUP ||
                next == Constants.EMPTY)
            {
                return(false);
            }

            // Case of a negative number, or starting with the closing bracket:
            if (item.Length == 0 &&
                ((ch == '-' && next != '-') || ch == Constants.END_ARRAY ||
                 ch == Constants.END_ARG))
            {
                return(true);
            }

            // Case of a scientific notation 1.2e+5 or 1.2e-5 or 1e5:
            if (Char.ToUpper(prev) == 'E' &&
                (ch == '-' || ch == '+' || Char.IsDigit(ch)) &&
                item.Length > 1 && Char.IsDigit(item[item.Length - 2]))
            {
                return(true);
            }

            // Otherwise if it's an action (+, -, *, etc.) or a space
            // we're done collecting current token.
            if ((action = Utils.ValidAction(script.FromPrev())) != null ||
                (item.Length > 0 && ch == Constants.SPACE))
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        public Variable GetEnumProperty(string propName, ParsingScript script, string baseName = "")
        {
            propName = Constants.ConvertName(propName);
            if (script.TryPrev() == Constants.START_ARG)
            {
                Variable value = Utils.GetItem(script);
                if (propName == Constants.TO_STRING)
                {
                    return(ConvertEnumToString(value));
                }
                else
                {
                    return(new Variable(m_enumMap != null && m_enumMap.ContainsKey(value.AsInt())));
                }
            }

            string[] tokens = propName.Split('.');
            if (tokens.Length > 1)
            {
                propName = tokens[0];
            }

            string match = GetActualPropertyName(propName, GetAllProperties(), baseName, this);

            Variable result = GetCoreProperty(match, script);

            if (tokens.Length > 1)
            {
                result = ConvertEnumToString(result);
                if (tokens.Length > 2)
                {
                    string rest = string.Join(".", tokens, 2, tokens.Length - 2);
                    result = result.GetProperty(rest, script);
                }
            }

            return(result);
        }
Exemple #4
0
        public static string GetToken(ParsingScript script, char [] to)

        {
            char curr = script.TryCurrent();
            char prev = script.TryPrev();

            if (!to.Contains(Constants.SPACE))
            {
                // Skip a leading space unless we are inside of quotes
                while (curr == Constants.SPACE && prev != Constants.QUOTE)
                {
                    script.Forward();
                    curr = script.TryCurrent();
                    prev = script.TryPrev();
                }
            }

            // String in quotes
            bool inQuotes = curr == Constants.QUOTE;

            if (inQuotes)
            {
                int qend = script.Find(Constants.QUOTE, script.Pointer + 1);
                if (qend == -1)
                {
                    throw new ArgumentException("Unmatched quotes in [" +
                                                script.FromPrev() + "]");
                }
                string result = script.Substr(script.Pointer + 1, qend - script.Pointer - 1);
                script.Pointer = qend + 1;
                return(result);
            }

            script.MoveForwardIf(Constants.QUOTE);

            int end = script.FindFirstOf(to);

            end = end < 0 ? script.Size() : end;

            // Skip found characters that have a backslash before.
            while (end > 0 && end + 1 < script.Size() &&
                   script.String [end - 1] == '\\')
            {
                end = script.FindFirstOf(to, end + 1);
            }

            end = end < 0 ? script.Size() : end;

            if (script.At(end - 1) == Constants.QUOTE)
            {
                end--;
            }

            string var = script.Substr(script.Pointer, end - script.Pointer);

            // \"yes\" --> "yes"
            var            = var.Replace("\\\"", "\"");
            script.Pointer = end;

            script.MoveForwardIf(Constants.QUOTE, Constants.SPACE);

            return(var);
        }