location

package
v1.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package location defines locations in Rego source code.

Index

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

func NewLocation(text []byte, file string, row int, col int) *Location

NewLocation returns a new Location object.

func (*Location) AppendText added in v1.13.0

func (loc *Location) AppendText(buf []byte) ([]byte, error)

func (*Location) Compare

func (loc *Location) Compare(other *Location) int

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

func (loc *Location) End() (row, col int)

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) Equal

func (loc *Location) Equal(other *Location) bool

Equal checks if two locations are equal to each other.

func (*Location) Errorf

func (loc *Location) Errorf(f string, a ...any) error

Errorf returns a new error value with a message formatted to include the location info (e.g., line, column, filename, etc.)

func (*Location) Format

func (loc *Location) Format(f string, a ...any) string

Format returns a formatted string prefixed with the location information.

func (*Location) HasFile added in v1.18.0

func (loc *Location) HasFile() bool

HasFile reports whether loc carries a non-empty File. Safe to call on a nil receiver.

func (*Location) MarshalJSON

func (loc *Location) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of loc.

func (*Location) MarshalJSONTo added in v1.19.0

func (loc *Location) MarshalJSONTo(e *jsontext.Encoder) (err error)

func (*Location) String

func (loc *Location) String() string

func (*Location) StringLength added in v1.13.0

func (loc *Location) StringLength() (n int)

func (*Location) Wrapf

func (loc *Location) Wrapf(err error, f string, a ...any) error

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.)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL