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