in src/Structure/BlockTaggerImpl/BraceParser.cs [18:89]
public Task<CodeBlock> ParseAsync(ITextSnapshot snapshot, CancellationToken token)
{
CodeBlock root = new CodeBlock(null, BlockType.Root, null, new SnapshotSpan(snapshot, 0, snapshot.Length), 0, 0);
CodeBlock parent = root;
Stack<CodeBlock> blockOpenings = new Stack<CodeBlock>();
bool leadingWhitespace = true;
int statementStart = 0;
StringBuilder currentStatement = new StringBuilder();
StringBuilder filteredStatement = new StringBuilder();
SnapshotFilter filter = new SnapshotFilter(snapshot);
while (filter.Next())
{
int position = filter.Position;
char c = filter.Character;
if (leadingWhitespace)
{
leadingWhitespace = char.IsWhiteSpace(c);
statementStart = position;
}
if (!filter.InQuote)
{
if (c == '{')
{
CodeBlock child = CreateCodeBlock(parent, currentStatement, filteredStatement, new SnapshotSpan(snapshot, position, 0), statementStart, blockOpenings.Count + 1);
blockOpenings.Push(child);
parent = child;
}
else if (c == '}')
{
if (blockOpenings.Count > 0)
{
CodeBlock child = blockOpenings.Pop();
child.SetSpan(new SnapshotSpan(snapshot, Span.FromBounds(child.Span.Start, position + 1)));
parent = child.Parent;
}
}
}
if (filter.EOS)
{
currentStatement.Length = 0;
filteredStatement.Length = 0;
leadingWhitespace = true;
}
else
{
AppendCharacter(currentStatement, c);
if (!filter.InQuote)
AppendCharacter(filteredStatement, c);
}
if (token.IsCancellationRequested)
return null;
}
while (blockOpenings.Count > 0)
{
CodeBlock child = blockOpenings.Pop();
child.SetSpan(new SnapshotSpan(snapshot, Span.FromBounds(child.Span.Start, snapshot.Length)));
}
return Task.FromResult<CodeBlock>(root);
}