예제 #1
0
        protected override Variable Evaluate(ParsingScript script)
        {
            script.MoveForwardIf(Constants.SPACE);
            if (!script.FromPrev(Constants.RETURN.Length).Contains(Constants.RETURN))
            {
                script.Backward();
            }
            Variable result = Utils.GetItem(script);

            // If we are in Return, we are done:
            script.SetDone();
            result.IsReturn = true;

            return(result);
        }
예제 #2
0
        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 a pointer, or starting with the closing bracket:
            if (item.Length == 0 &&
                ((ch == '-' && next != '-') || ch == '&' ||
                 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);
            }

            if (ch == Constants.TERNARY_OPERATOR)
            {
                script.Backward();
                return(false);
            }
            return(true);
        }
예제 #3
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);
        }