Microsoft.R.Core.AST.Operators.FunctionCall.Parse C# (CSharp) Method

Parse() public method

public Parse ( ParseContext context, IAstNode parent ) : bool
context Microsoft.R.Core.Parser.ParseContext
parent IAstNode
return bool
        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);
        }

Usage Example

Ejemplo n.º 1
0
        private OperationType HandleOpenBrace(ParseContext context, out ParseErrorType errorType) {
            TokenStream<RToken> tokens = context.Tokens;
            errorType = ParseErrorType.None;

            // Separate expression from function call. In case of 
            // function call previous token is either closing indexer 
            // brace or closing function brace. Identifier with brace 
            // is handled up above. 
            // Indentifier followed by a brace needs to be analyzed
            // so we can tell between previous expression that ended
            // with identifier and identifier that is a function name:
            //
            //      a <- 2*b
            //      (expression)
            //
            // in this case b is not a function name. Similarly,
            //
            //      a <- 2*b[1]
            //      (expression)
            //
            // is not a function call operator over b[1].

            if (_operators.Count > 1 || _operands.Count > 0) {
                // We are not in the beginning of the expression
                if (tokens.PreviousToken.TokenType == RTokenType.CloseBrace ||
                    tokens.PreviousToken.TokenType == RTokenType.CloseSquareBracket ||
                    tokens.PreviousToken.TokenType == RTokenType.CloseDoubleSquareBracket ||
                    tokens.PreviousToken.IsVariableKind()) {
                    FunctionCall functionCall = new FunctionCall();
                    functionCall.Parse(context, null);

                    errorType = HandleFunctionOrIndexer(functionCall);
                    return OperationType.Function;
                }
            }

            Group group = new Group();
            group.Parse(context, null);

            _operands.Push(group);
            return OperationType.Operand;
        }
All Usage Examples Of Microsoft.R.Core.AST.Operators.FunctionCall::Parse