SetPointer() private method

Sets the character pointer to a new position.
private SetPointer ( Int32 newPosition ) : ParseEngine
newPosition System.Int32 The new position of the character pointer ptr.
return ParseEngine
Ejemplo n.º 1
0
        public override Expression Scan(ParseEngine engine)
        {
            var index = engine.Pointer;
            var chars = engine.Characters;

            if (ParseEngine.IsIdentifierStart(chars[index]))
            {
                index++;

                while (index < chars.Length && ParseEngine.IsIdentifierPart(chars[index]))
                {
                    index++;
                }

                var name = new String(chars, engine.Pointer, index - engine.Pointer);

                if (engine.UseKeywords)
                {
                    var keyword = engine.Elements.FindKeywordExpression(name, engine);

                    if (keyword != null)
                    {
                        return(keyword);
                    }
                }

                var exp = new SymbolExpression(engine, name);
                engine.SetPointer(index);
                return(exp);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var kw = new LetKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);
            engine.Advance(Token.Length);
            kw.Length = engine.Pointer - start;
            engine.Skip();
            start = engine.Pointer;
            kw.name = engine.Elements.FindExpression<SymbolExpression>().Scan(engine) as SymbolExpression;

            if (kw.name == null)
            {
                engine.AddError(new YAMPVariableNameMissing(engine), kw);
                return kw;
            }

            engine.SetPointer(start);
            return kw;
        }
Ejemplo n.º 3
0
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var kw    = new LetKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);

            engine.Advance(Token.Length);
            kw.Length = engine.Pointer - start;
            engine.Skip();
            start   = engine.Pointer;
            kw.name = Elements.Instance.FindExpression <SymbolExpression>().Scan(engine) as SymbolExpression;

            if (kw.name == null)
            {
                engine.AddError(new YAMPVariableNameMissing(engine), kw);
                return(kw);
            }

            engine.SetPointer(start);
            return(kw);
        }
        public override Expression Scan(ParseEngine engine)
        {
            var start  = engine.Pointer;
            var chars  = engine.Characters;
            var ch     = chars[start];
            var isreal = false;

            if (ParseEngine.IsNumber(ch) || (ch == '.' && start + 1 < chars.Length && ParseEngine.IsNumber(chars[start + 1])))
            {
                var index  = start;
                var exp    = new NumberExpression(engine);
                var number = 0.0;
                var pow    = 0;

                if (ch != '.')
                {
                    number += ToDoubleNumber(chars[index++]);

                    while (index < chars.Length && ParseEngine.IsNumber(ch = chars[index]))
                    {
                        number *= 10.0;
                        number += ToDoubleNumber(ch);
                        index++;
                    }
                }

                if (ch == '.')
                {
                    isreal = true;
                    index++;

                    if (index < chars.Length && ParseEngine.IsNumber(chars[index]))
                    {
                        do
                        {
                            number *= 10.0;
                            number += ToDoubleNumber(chars[index++]);
                            pow++;
                        }while (index < chars.Length && ParseEngine.IsNumber(ch = chars[index]));
                    }
                }

                if (ch == 'e' || ch == 'E')
                {
                    isreal = true;
                    var epow = 0;
                    var sign = 1;
                    index++;

                    if (index < chars.Length && (chars[index] == '+' || chars[index] == '-'))
                    {
                        sign = chars[index] == '-' ? -1 : +1;
                        index++;
                    }

                    while (index < chars.Length && ParseEngine.IsNumber(ch = chars[index]))
                    {
                        epow *= 10;
                        epow += ToInt32Number(ch);
                        index++;
                    }

                    pow -= epow * sign;
                }

                var value = number / Math.Pow(10.0, pow);

                if (ch == 'i')
                {
                    exp.value = new ScalarValue(0.0, value);
                    index++;
                }
                else if (isreal)
                {
                    exp.value = new ScalarValue(value);
                }
                else
                {
                    exp.value = new ScalarValue((int)value);
                }

                exp.Length = index - start;
                engine.SetPointer(index);
                return(exp);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public override Expression Scan(ParseEngine engine)
        {
            var chars = engine.Characters;
            var start = engine.Pointer;

            if (chars[start] == '"' || (chars[start] == '@' && start + 1 < chars.Length && chars[start + 1] == '"'))
            {
                var index = start;
                var exp = new StringExpression(engine);
                var escape = false;
                var terminated = false;
                var sb = new StringBuilder();

                if (chars[index] == '@')
                {
                    index += 2;
                    exp.literal = true;
                }
                else
                {
                    index++;
                }

                while (index < chars.Length)
                {
                    if (!literal && !escape && chars[index] == '\\')
                    {
                        escape = true;
                    }
                    else if (!escape && chars[index] == '"')
                    {
                        terminated = true;
                        index++;
                        break;
                    }
                    else if (escape)
                    {
                        switch (chars[index])
                        {
                            case 't':
                                sb.Append("\t");
                                break;
                            case 'n':
                                sb.AppendLine();
                                break;
                            case '\\':
                            case '"':
                                sb.Append(chars[index]);
                                break;
                            default:
                                engine.SetPointer(index);
                                engine.AddError(new YAMPEscapeSequenceNotFoundError(engine, chars[index]), exp);
                                break;
                        }

                        escape = false;
                    }
                    else
                    {
                        sb.Append(chars[index]);
                    }

                    index++;
                }

                if (!terminated)
                {
                    engine.AddError(new YAMPStringNotTerminatedError(engine), exp);
                }

                exp.value = sb.ToString();
                exp.Length = index - start;
                engine.SetPointer(index);
                return exp;
            }

            return null;
        }
Ejemplo n.º 6
0
        public override Expression Scan(ParseEngine engine)
        {
            var chars = engine.Characters;
            var start = engine.Pointer;

            if (chars[start] == '"' || (chars[start] == '@' && start + 1 < chars.Length && chars[start + 1] == '"'))
            {
                var index      = start;
                var exp        = new StringExpression(engine);
                var escape     = false;
                var terminated = false;
                var sb         = new StringBuilder();

                if (chars[index] == '@')
                {
                    index      += 2;
                    exp.literal = true;
                }
                else
                {
                    index++;
                }

                while (index < chars.Length)
                {
                    if (!literal && !escape && chars[index] == '\\')
                    {
                        escape = true;
                    }
                    else if (!escape && chars[index] == '"')
                    {
                        terminated = true;
                        index++;
                        break;
                    }
                    else if (escape)
                    {
                        switch (chars[index])
                        {
                        case 't':
                            sb.Append("\t");
                            break;

                        case 'n':
                            sb.AppendLine();
                            break;

                        case '\\':
                        case '"':
                            sb.Append(chars[index]);
                            break;

                        default:
                            engine.SetPointer(index);
                            engine.AddError(new YAMPEscapeSequenceNotFoundError(engine, chars[index]), exp);
                            break;
                        }

                        escape = false;
                    }
                    else
                    {
                        sb.Append(chars[index]);
                    }

                    index++;
                }

                if (!terminated)
                {
                    engine.AddError(new YAMPStringNotTerminatedError(engine), exp);
                }

                exp.value  = sb.ToString();
                exp.Length = index - start;
                engine.SetPointer(index);
                return(exp);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var chars = engine.Characters;
            var ch = chars[start];
            var isreal = false;

            if (ParseEngine.IsNumber(ch) || (ch == '.' && start + 1 < chars.Length && ParseEngine.IsNumber(chars[start + 1])))
            {
                var index = start;
                var exp = new NumberExpression(engine);
                var number = 0.0;
                var pow = 0;

                if (ch != '.')
                {
                    number += ToDoubleNumber(chars[index++]);

                    while (index < chars.Length && ParseEngine.IsNumber(ch = chars[index]))
                    {
                        number *= 10.0;
                        number += ToDoubleNumber(ch);
                        index++;
                    }
                }

                if (ch == '.')
                {
                    isreal = true;
                    index++;

                    if (index < chars.Length && ParseEngine.IsNumber(chars[index]))
                    {
                        do
                        {
                            number *= 10.0;
                            number += ToDoubleNumber(chars[index++]);
                            pow++;
                        }
                        while (index < chars.Length && ParseEngine.IsNumber(ch = chars[index]));
                    }
                }

                if (ch == 'e' || ch == 'E')
                {
                    isreal = true;
                    var epow = 0;
                    var sign = 1;
                    index++;

                    if (index < chars.Length && (chars[index] == '+' || chars[index] == '-'))
                    {
                        sign = chars[index] == '-' ? -1 : +1;
                        index++;
                    }

                    while (index < chars.Length && ParseEngine.IsNumber(ch = chars[index]))
                    {
                        epow *= 10;
                        epow += ToInt32Number(ch);
                        index++;
                    }

                    pow -= epow * sign;
                }

                var value = number / Math.Pow(10.0, pow);

                if (ch == 'i')
                {
                    exp.value = new ScalarValue(0.0, value);
                    index++;
                }
                else if (isreal)
                    exp.value = new ScalarValue(value);
                else
                    exp.value = new ScalarValue((int)value);

                exp.Length = index - start;
                engine.SetPointer(index);
                return exp;
            }

            return null;
        }