Skip to content

Commit

Permalink
Simplify handling of newline characters at the end of previous items …
Browse files Browse the repository at this point in the history
…in the parse loop.

PiperOrigin-RevId: 597844010
  • Loading branch information
txtpbfmt-copybara-robot committed Jan 12, 2024
1 parent c34e10e commit 75d56e8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,21 +567,17 @@ func (p *parser) parse(isRoot bool) (result []*ast.Node, endPos ast.Position, er
return nil, ast.Position{}, err
}

// p.parse is often invoked with the index pointing at the newline character
// after the previous item. We should still report that this item starts in
// the next line.
p.consume('\n')
startPos := p.position()
if p.nextInputIs('\n') {
// p.parse is often invoked with the index pointing at the
// newline character after the previous item.
// We should still report that this item starts in the next line.
startPos.Byte++
startPos.Line++
startPos.Column = 1
}

// Read PreComments.
comments, blankLines := p.skipWhiteSpaceAndReadComments(true /* multiLine */)

// Handle blank lines.
if blankLines > 1 {
if blankLines > 0 {
if p.config.infoLevel() {
p.config.infof("blankLines: %v", blankLines)
}
Expand Down

0 comments on commit 75d56e8

Please sign in to comment.