Skip to content

Commit

Permalink
cue/token: relative positions apply before, not after, a token
Browse files Browse the repository at this point in the history
Maximilian Gaß correctly points out that the cue/format package
follows relative positions before printing a token, and he's right.
I also confirmed that the token scanner also builds relative positions
based on the kind of whitespace it found leading up to each token.

While here, fix a typo.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I2eae7f628a4e585e966e029d9d78c7fe3be89539
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1186143
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mvdan committed Apr 26, 2024
1 parent fb9961a commit 1dda583
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cue/token/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ const (
// not rendered at all.
Elided

// NoSpace indicates there is no whitespace after this token.
// NoSpace indicates there is no whitespace before this token.
NoSpace

// Blank means there is horizontal space after this token.
// Blank means there is horizontal space before this token.
Blank

// Newline means there is a single newline after this token.
// Newline means there is a single newline before this token.
Newline

// NewSection means there are two or more newlines after this token.
// NewSection means there are two or more newlines before this token.
NewSection

relMask = 0xf
Expand Down Expand Up @@ -175,7 +175,7 @@ func (p Pos) IsValid() bool {
}

// IsNewline reports whether the relative information suggests this node should
// be printed on a new lien.
// be printed on a new line.
func (p Pos) IsNewline() bool {
return p.RelPos() >= Newline
}
Expand Down

0 comments on commit 1dda583

Please sign in to comment.