Ejemplo n.º 1
0
        public override bool Parse(ParseContext context, IAstNode parent) {
            _statement = Statement.Create(context, this, _terminatingKeyword);
            if (_statement != null) {
                if (_statement.Parse(context, this)) {
                    return base.Parse(context, parent);
                }
            }

            return false;
        }
Ejemplo n.º 2
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            _statement = Statement.Create(context, this, _terminatingKeyword);
            if (_statement != null)
            {
                if (_statement.Parse(context, this))
                {
                    return(base.Parse(context, parent));
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
Archivo: Scope.cs Proyecto: Fooway/RTVS
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            TokenStream <RToken> tokens = context.Tokens;
            RToken currentToken         = tokens.CurrentToken;

            context.Scopes.Push(this);

            if (!(this is GlobalScope) && currentToken.TokenType == RTokenType.OpenCurlyBrace)
            {
                this.OpenCurlyBrace = RParser.ParseToken(context, this);
            }

            while (!tokens.IsEndOfStream())
            {
                currentToken = context.Tokens.CurrentToken;

                switch (currentToken.TokenType)
                {
                case RTokenType.CloseCurlyBrace:
                    if (this.OpenCurlyBrace != null)
                    {
                        this.CloseCurlyBrace = RParser.ParseToken(context, this);
                    }
                    else
                    {
                        context.AddError(new ParseError(ParseErrorType.UnexpectedToken, ErrorLocation.Token, currentToken));
                        context.Tokens.MoveToNextToken();
                    }
                    break;

                case RTokenType.OpenCurlyBrace:
                    IScope scope = new Scope(string.Empty);
                    scope.Parse(context, this);
                    break;

                default:
                    IStatement statement = Statement.Create(context, this, null);
                    if (statement != null)
                    {
                        if (statement.Parse(context, this))
                        {
                            this.statements.Add(statement);
                        }
                        else
                        {
                            statement = null;
                        }
                    }

                    if (statement == null)
                    {
                        if (!context.TextProvider.IsNewLineBeforePosition(context.Tokens.CurrentToken.Start))
                        {
                            // try recovering at the next line or past nearest
                            // semicolon or closing curly brace
                            tokens.MoveToNextLine(context.TextProvider,
                                                  (TokenStream <RToken> ts) => {
                                return(ts.CurrentToken.TokenType == RTokenType.Semicolon ||
                                       ts.NextToken.TokenType == RTokenType.CloseCurlyBrace);
                            });
                        }
                        else
                        {
                            tokens.MoveToNextToken();
                        }
                    }
                    break;
                }

                if (this.CloseCurlyBrace != null)
                {
                    break;
                }
            }

            context.Scopes.Pop();

            if (this.OpenCurlyBrace != null && this.CloseCurlyBrace == null)
            {
                context.AddError(new MissingItemParseError(ParseErrorType.CloseCurlyBraceExpected, context.Tokens.PreviousToken));
            }

            // TODO: process content and fill out declared variables
            // and functions and get data to the classifier for colorization.
            return(base.Parse(context, parent));
        }