Documentation
¶
Overview ¶
Package location defines locations in Rego source code.
Index ¶
- type Location
- func (loc *Location) AppendText(buf []byte) ([]byte, error)
- func (loc *Location) Compare(other *Location) int
- func (loc *Location) End() (row, col int)
- func (loc *Location) Equal(other *Location) bool
- func (loc *Location) Errorf(f string, a ...any) error
- func (loc *Location) Format(f string, a ...any) string
- func (loc *Location) HasFile() bool
- func (loc *Location) MarshalJSON() ([]byte, error)
- func (loc *Location) MarshalJSONTo(e *jsontext.Encoder) (err error)
- func (loc *Location) String() string
- func (loc *Location) StringLength() (n int)
- func (loc *Location) Wrapf(err error, f string, a ...any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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) AppendText ¶ added in v1.13.0
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) End ¶ added in v1.18.0
End returns the (row, col) one past the last rune of loc.Text — an exclusive end matching the scanner's offset calculation, so [Start, End) covers the text. Columns are counted per rune. Returns (Row, Col) for empty text and (0, 0) for a nil receiver.
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) HasFile ¶ added in v1.18.0
HasFile reports whether loc carries a non-empty File. Safe to call on a nil receiver.
func (*Location) MarshalJSON ¶
MarshalJSON returns the JSON encoding of loc.