예제 #1
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            TokenStream <RToken> tokens = context.Tokens;

            Debug.Assert(tokens.CurrentToken.TokenType == RTokenType.OpenSquareBracket ||
                         tokens.CurrentToken.TokenType == RTokenType.OpenDoubleSquareBracket);

            this.LeftBrackets = RParser.ParseToken(context, this);

            RTokenType terminatingTokenType = RParser.GetTerminatingTokenType(this.LeftBrackets.Token.TokenType);

            this.Arguments = new ArgumentList(terminatingTokenType);
            this.Arguments.Parse(context, this);

            if (tokens.CurrentToken.TokenType == terminatingTokenType)
            {
                this.RightBrackets = RParser.ParseToken(context, this);
                return(base.Parse(context, parent));
            }
            else
            {
                context.AddError(new MissingItemParseError(ParseErrorType.CloseSquareBracketExpected, tokens.PreviousToken));
            }


            return(true);
        }
예제 #2
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            TokenStream <RToken> tokens = context.Tokens;

            Debug.Assert(context.Tokens.CurrentToken.TokenType == RTokenType.Identifier ||
                         context.Tokens.CurrentToken.TokenType == RTokenType.String);

            this.Identifier = RParser.ParseToken(context, this);
            this.EqualsSign = RParser.ParseToken(context, this);

            if (context.Tokens.CurrentToken.TokenType != RTokenType.Comma && context.Tokens.CurrentToken.TokenType != RTokenType.CloseBrace)
            {
                Expression exp = new Expression(inGroup: true);
                if (exp.Parse(context, this))
                {
                    this.DefaultValue = exp;
                }
            }
            else
            {
                this.DefaultValue = new NullExpression();
            }

            return(base.Parse(context, parent));
        }
예제 #3
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            TokenStream <RToken> tokens = context.Tokens;

            Debug.Assert(tokens.CurrentToken.TokenType == RTokenType.OpenBrace);
            this.OpenBrace = RParser.ParseToken(context, this);

            this.Arguments = new ArgumentList(RTokenType.CloseBrace);
            bool argumentsParsed = this.Arguments.Parse(context, this);

            if (argumentsParsed)
            {
                if (tokens.CurrentToken.TokenType == RTokenType.CloseBrace)
                {
                    this.CloseBrace = RParser.ParseToken(context, this);
                }
            }

            if (!argumentsParsed || this.CloseBrace == null)
            {
                CalculateVirtualEnd(context);
            }

            if (this.CloseBrace == null)
            {
                context.AddError(new MissingItemParseError(ParseErrorType.CloseBraceExpected, tokens.PreviousToken));
            }

            return(base.Parse(context, parent));
        }
예제 #4
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            if (context.Tokens.CurrentToken.TokenType == RTokenType.Comma)
            {
                this.Comma = RParser.ParseToken(context, this);
            }

            return(base.Parse(context, parent));
        }
예제 #5
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            Debug.Assert(context.Tokens.CurrentToken.TokenType == RTokenType.Keyword);

            this.Keyword = RParser.ParseKeyword(context, this);
            this.Text    = context.TextProvider.GetText(this.Keyword);

            bool result = base.Parse(context, parent);

            if (context.Tokens.CurrentToken.TokenType == RTokenType.Semicolon)
            {
                this.Semicolon = RParser.ParseToken(context, this);
            }

            return(result);
        }
예제 #6
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            Debug.Assert(context.Tokens.CurrentToken.TokenType == RTokenType.Operator);

            OperatorType  = TokenOperator.GetOperatorType(context.TextProvider.GetText(context.Tokens.CurrentToken));
            OperatorToken = RParser.ParseToken(context, this);
            Associativity = OperatorAssociativity.GetAssociativity(OperatorType);

            // If operator is preceded by an operator, it is then unary
            // Look back two tokens since operator parsing already consumed its token.
            if (IsUnary || IsUnaryOperator(context.Tokens, context.TextProvider, OperatorType, -2))
            {
                OperatorType  = Operator.GetUnaryForm(OperatorType);
                IsUnary       = true;
                Associativity = Associativity.Right;
            }
            return(base.Parse(context, parent));
        }
예제 #7
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            Debug.Assert(context.Tokens.CurrentToken.TokenType == RTokenType.Operator);

            _operatorType      = TokenOperator.GetOperatorType(context.TextProvider.GetText(context.Tokens.CurrentToken));
            this.OperatorToken = RParser.ParseToken(context, this);
            this.Association   = OperatorAssociation.GetAssociation(_operatorType);

            bool isUnary;

            _precedence = this.GetCurrentOperatorPrecedence(context, this.OperatorType, out isUnary);

            if (!_isUnary)
            {
                _isUnary = isUnary;
            }

            return(base.Parse(context, parent));
        }
예제 #8
0
파일: Statement.cs 프로젝트: zachwieja/RTVS
        protected bool ParseSemicolon(ParseContext context, IAstNode parent)
        {
            if (!context.Tokens.IsEndOfStream())
            {
                if (!context.Tokens.IsLineBreakAfter(context.TextProvider, context.Tokens.Position - 1))
                {
                    if (context.Tokens.CurrentToken.TokenType == RTokenType.Semicolon)
                    {
                        this.Semicolon = RParser.ParseToken(context, this);
                    }
                    else
                    {
                        context.AddError(new ParseError(ParseErrorType.UnexpectedToken, ErrorLocation.Token, context.Tokens.CurrentToken));
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #9
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            TokenStream <RToken> tokens = context.Tokens;

            Debug.Assert(tokens.CurrentToken.TokenType == RTokenType.OpenBrace);
            this.OpenBrace = RParser.ParseToken(context, this);

            this.Content = new Expression(inGroup: true);
            this.Content.Parse(context, this);

            if (tokens.CurrentToken.TokenType == RTokenType.CloseBrace)
            {
                this.CloseBrace = RParser.ParseToken(context, this);
            }
            else
            {
                context.AddError(new MissingItemParseError(ParseErrorType.CloseBraceExpected, tokens.PreviousToken));
            }

            return(base.Parse(context, parent));
        }
예제 #10
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            TokenStream <RToken> tokens = context.Tokens;

            Debug.Assert(tokens.CurrentToken.TokenType == RTokenType.Keyword);
            this.Keyword = RParser.ParseKeyword(context, this);
            this.Text    = context.TextProvider.GetText(this.Keyword);

            if (tokens.CurrentToken.TokenType == RTokenType.OpenBrace)
            {
                this.OpenBrace = RParser.ParseToken(context, this);

                this.Arguments = new ArgumentList(RTokenType.CloseBrace);
                this.Arguments.Parse(context, this);

                if (tokens.CurrentToken.TokenType == RTokenType.CloseBrace)
                {
                    this.CloseBrace = RParser.ParseToken(context, this);
                    this.Scope      = RParser.ParseScope(context, this, allowsSimpleScope: true, terminatingKeyword: null);
                    if (this.Scope != null)
                    {
                        return(base.Parse(context, parent));
                    }
                    else
                    {
                        context.AddError(new ParseError(ParseErrorType.FunctionBodyExpected, ErrorLocation.Token, tokens.PreviousToken));
                    }
                }
                else
                {
                    context.AddError(new ParseError(ParseErrorType.CloseBraceExpected, ErrorLocation.Token, tokens.CurrentToken));
                }
            }
            else
            {
                context.AddError(new ParseError(ParseErrorType.OpenBraceExpected, ErrorLocation.Token, tokens.CurrentToken));
            }

            return(false);
        }
예제 #11
0
파일: Scope.cs 프로젝트: 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));
        }
예제 #12
0
 public override bool Parse(ParseContext context, IAstNode parent)
 {
     this.Semicolon = RParser.ParseToken(context, this);
     return(base.Parse(context, parent));
 }
예제 #13
0
 public override bool Parse(ParseContext context, IAstNode parent)
 {
     EllipsisToken = RParser.ParseToken(context, this);
     return(base.Parse(context, parent));
 }