The class for the if keyword. Basic syntax: if ( CONDITION ) STATEMENT
Inheritance: BodyKeyword
Exemple #1
0
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var kw = new IfKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);
            var index = engine.Advance(Token.Length).Skip().Pointer;
            var chars = engine.Characters;

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

            if (chars[index] == '(')
            {
                var ln = engine.CurrentLine;
                var col = engine.CurrentColumn;
                kw.Condition = engine.Advance().ParseStatement(')', e => new YAMPBracketNotClosedError(ln, col));

                if (kw.Condition.Container == null || !kw.Condition.Container.HasContent)
                {
                    engine.AddError(new YAMPIfArgumentsMissing(engine), kw);
                }

                kw.Body = engine.ParseStatement();
            }
            else
            {
                engine.AddError(new YAMPIfArgumentsMissing(engine), kw);
            }

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

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

            if (chars[index] == '(')
            {
                var ln  = engine.CurrentLine;
                var col = engine.CurrentColumn;
                kw.Condition = engine.Advance().ParseStatement(')', e => new YAMPBracketNotClosedError(ln, col));

                if (kw.Condition.Container == null || !kw.Condition.Container.HasContent)
                {
                    engine.AddError(new YAMPIfArgumentsMissing(engine), kw);
                }

                kw.Body = engine.ParseStatement();
            }
            else
            {
                engine.AddError(new YAMPIfArgumentsMissing(engine), kw);
            }

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