示例#1
0
        protected GreenNode EatNode()
        {
            // we will fail anyways. Assert is just to catch that earlier.
            Debug.Assert(_blendedTokens != null);

            // remember result
            var result = CurrentNode.Green;

            // store possible non-token in token sequence
            if (_tokenOffset >= _blendedTokens.Length)
            {
                this.AddTokenSlot();
            }

            _blendedTokens[_tokenOffset++] = _currentNode;
            _tokenCount = _tokenOffset; // forget anything after this slot

            // erase current state
            _currentNode  = default(BlendedNode);
            _currentToken = default(SyntaxToken);

            return(result);
        }
示例#2
0
        protected SyntaxParser(
            Lexer lexer,
            LexerMode mode,
            Stark.CSharpSyntaxNode oldTree,
            IEnumerable <TextChangeRange> changes,
            bool allowModeReset,
            bool preLexIfNotIncremental         = false,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            this.lexer             = lexer;
            _mode                  = mode;
            _allowModeReset        = allowModeReset;
            this.cancellationToken = cancellationToken;
            _currentNode           = default(BlendedNode);
            _isIncremental         = oldTree != null;

            if (this.IsIncremental || allowModeReset)
            {
                _firstBlender  = new Blender(lexer, oldTree, changes);
                _blendedTokens = s_blendedNodesPool.Allocate();
            }
            else
            {
                _firstBlender = default(Blender);
                _lexedTokens  = new ArrayElement <SyntaxToken> [32];
            }

            // PreLex is not cancellable.
            //      If we may cancel why would we aggressively lex ahead?
            //      Cancellations in a constructor make disposing complicated
            //
            // So, if we have a real cancellation token, do not do prelexing.
            if (preLexIfNotIncremental && !this.IsIncremental && !cancellationToken.CanBeCanceled)
            {
                this.PreLex();
            }
        }