Exemplo n.º 1
0
        private void ProcessBlocks()
        {
            while (true)
            {
                // Get the precise position of the begining of the line
                var lineText = lineReader.ReadLine();

                // If this is the end of file and the last line is empty
                if (lineText.Text is null)
                {
                    if (trackTrivia)
                    {
                        Block?lastBlock = blockProcessor.LastBlock;
                        if (lastBlock is null && document.Count == 0)
                        {
                            // this means we have unassigned characters
                            var noBlocksFoundBlock         = new EmptyBlock(null);
                            List <StringSlice> linesBefore = blockProcessor.UseLinesBefore();
                            noBlocksFoundBlock.LinesAfter = new List <StringSlice>();
                            noBlocksFoundBlock.LinesAfter.AddRange(linesBefore);
                            document.Add(noBlocksFoundBlock);
                        }
                        else if (lastBlock != null && blockProcessor.LinesBefore != null)
                        {
                            // this means we're out of lines, but still have unassigned empty lines.
                            // thus, we'll assign the empty unsassigned lines to the last block
                            // of the document.
                            var rootMostContainerBlock = Block.FindRootMostContainerParent(lastBlock);
                            rootMostContainerBlock.LinesAfter ??= new List <StringSlice>();
                            var linesBefore = blockProcessor.UseLinesBefore();
                            rootMostContainerBlock.LinesAfter.AddRange(linesBefore);
                        }
                    }
                    break;
                }
                blockProcessor.ProcessLine(lineText);
            }