private void MoveToNextToken() { this.prevTokenTrailingTrivia = this.currentToken.GetTrailingTrivia(); this.currentToken = default(SyntaxToken); if (this.blendedTokens != null) { this.currentNode = default(BlendedNode); } this.tokenOffset++; }
private void MoveToNextToken() { _prevTokenTrailingTrivia = _currentToken.GetTrailingTrivia(); _currentToken = default(SyntaxToken); if (_blendedTokens != null) { _currentNode = default(BlendedNode); } _tokenOffset++; }
protected void Reset(ref ResetPoint point) { var offset = point.Position - _firstToken; Debug.Assert(offset >= 0); if (offset >= _tokenCount) { // Re-fetch tokens to the position in the reset point PeekToken(offset - _tokenOffset); // Re-calculate new offset in case tokens got shifted to the left while we were peeking. offset = point.Position - _firstToken; } _mode = point.Mode; Debug.Assert(offset >= 0 && offset < _tokenCount); _tokenOffset = offset; _currentToken = null; _currentNode = default(BlendedNode); _prevTokenTrailingTrivia = point.PrevTokenTrailingTrivia; if (_blendedTokens != null) { // look forward for slots not holding a token for (int i = _tokenOffset; i < _tokenCount; i++) { if (_blendedTokens[i].Token == null) { // forget anything after and including any slot not holding a token _tokenCount = i; if (_tokenCount == _tokenOffset) { FetchCurrentToken(); } break; } } } }
protected SyntaxParser( Lexer lexer, LexerMode mode, CSharp.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]; } #if !XSHARP // 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(); } #endif }
protected GreenNode EatNode() { // we will fail anyways. Assert is just to catch that earlier. Debug.Assert(this.blendedTokens != null); // remember result var result = CurrentNode.Green; // store possible non-token in token sequence if (this.tokenOffset >= this.blendedTokens.Length) { this.AddTokenSlot(); } this.blendedTokens[this.tokenOffset++] = this.currentNode; this.tokenCount = this.tokenOffset; // forget anything after this slot // erase current state this.currentNode = default(BlendedNode); this.currentToken = default(SyntaxToken); return(result); }
protected void Reset(ref ResetPoint point) { this.mode = point.Mode; var offset = point.Position - this.firstToken; Debug.Assert(offset >= 0 && offset < this.tokenCount); this.tokenOffset = offset; this.currentToken = default(SyntaxToken); this.currentNode = default(BlendedNode); this.prevTokenTrailingTrivia = point.PrevTokenTrailingTrivia; if (this.blendedTokens != null) { // look forward for slots not holding a token for (int i = this.tokenOffset; i < this.tokenCount; i++) { if (this.blendedTokens[i].Token == null) { // forget anything after and including any slot not holding a token this.tokenCount = i; break; } } } }
private bool TryTakeOldNodeOrToken( bool asToken, out BlendedNode blendedNode) { // If we're asking for tokens, then first move down to our first token. (if we're // already at a token, then this won't do anything). if (asToken) { this.oldTreeCursor = this.oldTreeCursor.MoveToFirstToken(); } // See if we're actually able to reuse this node or token. If not, our caller will // move the cursor to the next appropriate position and will try again. var currentNodeOrToken = this.oldTreeCursor.CurrentNodeOrToken; if (!CanReuse(currentNodeOrToken)) { blendedNode = default(BlendedNode); return false; } // We can reuse this node or token. Move us forward in the new text, and move to the // next sibling. this.newPosition += currentNodeOrToken.FullWidth; this.oldTreeCursor = this.oldTreeCursor.MoveToNextSibling(); this.newDirectives = currentNodeOrToken.ApplyDirectives(this.newDirectives); this.oldDirectives = currentNodeOrToken.ApplyDirectives(this.oldDirectives); blendedNode = CreateBlendedNode( node: (CSharp.CSharpSyntaxNode)currentNodeOrToken.AsNode(), token: (InternalSyntax.SyntaxToken)currentNodeOrToken.AsToken().Node); return true; }