Exemplo n.º 1
0
        private void CalculateVirtualEnd(ParseContext context)
        {
            int position = this.Arguments.Count > 0 ? this.Arguments.End : this.OpenBrace.End;

            if (!context.Tokens.IsEndOfStream())
            {
                TokenStream <RToken> tokens = context.Tokens;

                // Walk through tokens allowing numbers, identifiers and operators
                // as part of the function signature. Stop at keywords (except 'if'),
                // or curly braces.
                int i = tokens.Position;
                _virtualEnd = 0;

                for (; i < tokens.Length; i++)
                {
                    RToken token = tokens[i];

                    if (token.TokenType == RTokenType.Keyword || RParser.IsListTerminator(context, RTokenType.OpenBrace, token))
                    {
                        _virtualEnd = token.Start;
                        break;
                    }
                }
            }

            if (_virtualEnd == 0)
            {
                _virtualEnd = context.TextProvider.Length;
            }
        }
Exemplo n.º 2
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            while (!context.Tokens.IsEndOfStream())
            {
                if (context.Tokens.CurrentToken.TokenType == _terminatingTokenType)
                {
                    break;
                }

                if (RParser.IsListTerminator(context, RParser.GetOpeningTokenType(_terminatingTokenType), context.Tokens.CurrentToken))
                {
                    AddStubArgument(context);
                    break;
                }

                var item = this.CreateItem(this, context);
                if (item != null)
                {
                    var currentPosition = context.Tokens.Position;
                    if (item.Parse(context, this))
                    {
                        _arguments.Add(item);
                    }
                    else
                    {
                        // Item could not be parser. We attempt to recover by
                        // walking forward and finding the nearest comma
                        // that can be used as a terminator for this argument.
                        if (!AddErrorArgument(context, currentPosition))
                        {
                            // Failed to figure out the recovery point
                            break;
                        }
                    }
                }
                else
                {
                    AddStubArgument(context);
                    break; // unexpected item
                }
            }

            if (_arguments.Count > 0 && _arguments[_arguments.Count - 1].Comma != null)
            {
                AddStubArgument(context);
            }

            // Do not include empty list in the tree since
            // it has no positioning information.
            if (_arguments.Count > 1 || (_arguments.Count == 1 && !(_arguments[0] is StubArgument)))
            {
                return(base.Parse(context, parent));
            }

            return(true);
        }
Exemplo n.º 3
0
        private int TryFindNextArgument(ParseContext context, int startPosition)
        {
            for (var i = startPosition; i < context.Tokens.Length; i++)
            {
                var token = context.Tokens[i];
                if (token.TokenType == RTokenType.Comma || token.TokenType == RTokenType.CloseBrace)
                {
                    return(i);
                }

                if (RParser.IsListTerminator(context, RTokenType.OpenBrace, token))
                {
                    break;
                }
            }

            return(-1);
        }