package location
import "github.com/open-policy-agent/opa/v1/ast/location"
Package location defines locations in Rego source code.
Index ¶
- type Location
- func NewLocation(text []byte, file string, row int, col int) *Location
- func (loc *Location) Compare(other *Location) int
- func (loc *Location) Equal(other *Location) bool
- func (loc *Location) Errorf(f string, a ...interface{}) error
- func (loc *Location) Format(f string, a ...interface{}) string
- func (loc *Location) MarshalJSON() ([]byte, error)
- func (loc *Location) String() string
- func (loc *Location) Wrapf(err error, f string, a ...interface{}) error
Types ¶
type Location ¶
type Location struct { Text []byte `json:"-"` // The original text fragment from the source. File string `json:"file"` // The name of the source file (which may be empty). Row int `json:"row"` // The line in the source. Col int `json:"col"` // The column in the row. Offset int `json:"-"` // The byte offset for the location in the source. Tabs []int `json:"-"` // The column offsets of tabs in the source. }
Location records a position in source code
func NewLocation ¶
NewLocation returns a new Location object.
func (*Location) Compare ¶
Compare returns -1, 0, or 1 to indicate if this loc is less than, equal to, or greater than the other. Comparison is performed on the file, row, and column of the Location (but not on the text.) Nil locations are greater than non-nil locations.
func (*Location) Equal ¶
Equal checks if two locations are equal to each other.
func (*Location) Errorf ¶
Errorf returns a new error value with a message formatted to include the location info (e.g., line, column, filename, etc.)
func (*Location) Format ¶
Format returns a formatted string prefixed with the location information.
func (*Location) MarshalJSON ¶
func (*Location) String ¶
func (*Location) Wrapf ¶
Wrapf returns a new error value that wraps an existing error with a message formatted to include the location info (e.g., line, column, filename, etc.)
Source Files ¶
- Version
- v1.4.2 (latest)
- Published
- May 2, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 5 hours ago –
Tools for package owners.