Esempio n. 1
0
File: If.cs Progetto: Microsoft/RTVS
        public override bool Parse(ParseContext context, IAstNode parent) {
            // First parse base which should pick up keyword, braces, inner
            // expression and either full or simple (single statement) scope
            if (!base.Parse(context, parent)) {
                return false;
            }

            // At this point we should be either at 'else' token or 
            // at the next statement. In the latter case we are done.
            TokenStream<RToken> tokens = context.Tokens;

            if (tokens.CurrentToken.IsKeywordText(context.TextProvider, "else")) {
                bool allowLineBreak = AllowLineBreakBeforeElse(context);
                if (!allowLineBreak) {
                    // Verify that there is no line break before the 'else'
                    if (context.Tokens.IsLineBreakAfter(context.TextProvider, tokens.Position - 1)) {
                        context.AddError(new ParseError(ParseErrorType.UnexpectedToken, ErrorLocation.Token, tokens.CurrentToken));
                        return true;
                    }
                }
                this.Else = new KeywordScopeStatement(allowsSimpleScope: true);
                return this.Else.Parse(context, this);
            }

            // Not at 'else' so we are done here
            return true;
        }
Esempio n. 2
0
File: If.cs Progetto: xoriath/RTVS
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            // First parse base which should pick up keyword, braces, inner
            // expression and either full or simple (single statement) scope
            if (!base.Parse(context, parent))
            {
                return(false);
            }

            // At this point we should be either at 'else' token or
            // at the next statement. In the latter case we are done.
            TokenStream <RToken> tokens = context.Tokens;

            if (tokens.CurrentToken.IsKeywordText(context.TextProvider, "else"))
            {
                bool allowLineBreak = AllowLineBreakBeforeElse(context);
                if (!allowLineBreak)
                {
                    // Verify that there is no line break before the 'else'
                    if (context.Tokens.IsLineBreakAfter(context.TextProvider, tokens.Position - 1))
                    {
                        context.AddError(new ParseError(ParseErrorType.UnexpectedToken, ErrorLocation.Token, tokens.CurrentToken));
                        return(true);
                    }
                }
                this.Else = new KeywordScopeStatement(allowsSimpleScope: true);
                return(this.Else.Parse(context, this));
            }

            // Not at 'else' so we are done here
            return(true);
        }