The for keyword with the corresponding loop construct. Basic syntax: for ( INIT ; CONDITION ; END ) STATEMENT
Inheritance: BreakableKeyword
Ejemplo n.º 1
0
        public override Expression Scan(ParseEngine engine)
        {
            var kw    = new ForKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);
            var start = engine.Pointer;
            var index = engine.Advance(Token.Length).Skip().Pointer;
            var chars = engine.Characters;

            if (index == chars.Length)
            {
                kw.Length = engine.Pointer - start;
                engine.AddError(new YAMPForArgumentsMissing(engine));
                return(kw);
            }

            if (chars[index] == '(')
            {
                var ln  = engine.CurrentLine;
                var col = engine.CurrentColumn;
                kw.Initialization    = engine.Advance().ParseStatement();
                kw.Condition         = engine.ParseStatement();
                kw.Condition.IsMuted = false;
                kw.End = engine.ParseStatement(')', e => new YAMPBracketNotClosedError(ln, col));
                SetMarker(engine);
                kw.Body = engine.ParseStatement();
                UnsetMarker(engine);
            }
            else
            {
                engine.AddError(new YAMPForArgumentsMissing(engine));
            }

            kw.Length = engine.Pointer - start;
            return(kw);
        }
Ejemplo n.º 2
0
        public override Expression Scan(ParseEngine engine)
        {
            var kw = new ForKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);
            var start = engine.Pointer;
            var index = engine.Advance(Token.Length).Skip().Pointer;
            var chars = engine.Characters;

            if (index == chars.Length)
            {
                kw.Length = engine.Pointer - start;
                engine.AddError(new YAMPForArgumentsMissing(engine));
                return kw;
            }
            else if (chars[index] == '(')
            {
                var ln = engine.CurrentLine;
                var col = engine.CurrentColumn;
                kw.Initialization = engine.Advance().ParseStatement();
                kw.Condition = engine.ParseStatement();
                kw.Condition.IsMuted = false;
                kw.End = engine.ParseStatement(')', e => new YAMPBracketNotClosedError(ln, col));
                SetMarker(engine);
                kw.Body = engine.ParseStatement();
                UnsetMarker(engine);
            }
            else
            {
                engine.AddError(new YAMPForArgumentsMissing(engine));
            }

            kw.Length = engine.Pointer - start;
            return kw;
        }