2016-11-15 20:30:34 +01:00
|
|
|
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
|
|
|
|
package diag
|
|
|
|
|
|
|
|
// Pos represents a position in a file.
|
|
|
|
type Pos struct {
|
2017-01-18 03:01:11 +01:00
|
|
|
Line int // a 1-based line number
|
2017-02-13 15:44:48 +01:00
|
|
|
Column int // a 1-based column number
|
2016-11-15 20:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// EmptyPos may be used when no position is needed.
|
|
|
|
var EmptyPos = Pos{0, 0}
|
|
|
|
|
2016-11-16 03:00:43 +01:00
|
|
|
// IsEmpty returns true if the Pos information is missing.
|
|
|
|
func (pos Pos) IsEmpty() bool {
|
2017-01-18 03:01:11 +01:00
|
|
|
return pos.Line == 0 && pos.Column == 0
|
2016-11-16 03:00:43 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 02:42:22 +01:00
|
|
|
// Location represents a region spanning two positions in a file.
|
|
|
|
type Location struct {
|
2017-01-18 03:01:11 +01:00
|
|
|
Start Pos // a starting position.
|
|
|
|
End *Pos // an ending position; if nil, represents a point.
|
2016-11-15 20:30:34 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 02:42:22 +01:00
|
|
|
// EmptyLocation may be used when no position information is available.
|
2017-01-18 03:01:11 +01:00
|
|
|
var EmptyLocation = Location{EmptyPos, nil}
|
2016-11-16 03:00:43 +01:00
|
|
|
|
|
|
|
// IsEmpty returns true if the Location information is missing.
|
|
|
|
func (loc Location) IsEmpty() bool {
|
2017-01-18 03:01:11 +01:00
|
|
|
return loc.Start.IsEmpty() && (loc.End == nil || loc.End.IsEmpty())
|
2016-11-16 03:00:43 +01:00
|
|
|
}
|