location

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 8

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.

	// JSONOptions specifies options for marshaling and unmarshalling of locations
	JSONOptions astJSON.Options
}

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) 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) 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 ...interface{}) 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 ...interface{}) string

Format returns a formatted string prefixed with the location information.

func (*Location) MarshalJSON added in v0.57.0

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

func (*Location) String

func (loc *Location) String() string

func (*Location) Wrapf

func (loc *Location) Wrapf(err error, f string, a ...interface{}) 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