The else keyword - can (and should) only be instantiated by the if keyword. Basic syntax: else STATEMENT Can only be used after an IF or ELSE IF
Inheritance: BodyKeyword
コード例 #1
0
ファイル: ElseKeyword.cs プロジェクト: FlorianRappl/YAMP
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var kw = new ElseKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);
            kw.Body = engine.Advance(Token.Length).ParseStatement();

            if (engine.LastStatement == null)
            {
                engine.AddError(new YAMPIfRequiredError(engine), kw);
            }
            else if (engine.LastStatement.IsKeyword<IfKeyword>())
            {
                engine.LastStatement.GetKeyword<IfKeyword>().Else = kw;
            }
            else if (engine.LastStatement.IsKeyword<ElseKeyword>())
            {
                var otherwise = engine.LastStatement.GetKeyword<ElseKeyword>();

                if (otherwise.IsElseIf)
                {
                    otherwise.ElseIf.Else = kw;
                }
                else
                {
                    engine.AddError(new YAMPSingleElseError(engine), kw);
                }
            }
            else
            {
                engine.AddError(new YAMPIfRequiredError(engine), kw);
            }

            kw.Length = engine.Pointer - start;
            return kw;
        }
コード例 #2
0
ファイル: ElseKeyword.cs プロジェクト: bluntwcrackrap/YAMP
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var kw    = new ElseKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query);

            kw.Body = engine.Advance(Token.Length).ParseStatement();

            if (engine.LastStatement == null)
            {
                engine.AddError(new YAMPIfRequiredError(engine), kw);
            }
            else if (engine.LastStatement.IsKeyword <IfKeyword>())
            {
                engine.LastStatement.GetKeyword <IfKeyword>().Else = kw;
            }
            else if (engine.LastStatement.IsKeyword <ElseKeyword>())
            {
                var otherwise = engine.LastStatement.GetKeyword <ElseKeyword>();

                if (otherwise.IsElseIf)
                {
                    otherwise.ElseIf.Else = kw;
                }
                else
                {
                    engine.AddError(new YAMPSingleElseError(engine), kw);
                }
            }
            else
            {
                engine.AddError(new YAMPIfRequiredError(engine), kw);
            }

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