location

package
v1.2.27 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 1 Imported by: 36

Documentation

Overview

Package location provides a standard way of recording an indexed location in some source. For instance a line in a file.

The caller can set the source and then, as the entries are processed, the index can be incremented. The content of the current location can be added along with any notes. It is also possible to construct chains of locations to reflect a series of file include directives. This chain can be checked to ensure there are no loops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Err

type Err struct {
	Msg string
	Loc L
}

Err wraps a message and a location into a single struct this allows for a more structured error message

func (Err) Error

func (e Err) Error() string

type L

type L struct {
	// contains filtered or unexported fields
}

L represents a location - a named source and the index into that source. For instance, this might be used to represent a file and a line number or a database table and a row number. You can also record the content of the location but this is not done routinely and so is only reported if it has been set. Similarly you can add a note to the location and this is only reported if it is not empty.

func New

func New(name string) *L

New returns a new instance of a location

func (L) Content added in v1.2.0

func (l L) Content() (string, bool)

Content returns the content field and the hasContent flag

func (L) Error

func (l L) Error(s string) Err

Error constructs a location Err setting the Msg to the passed value and the Loc to the location

func (L) Errorf

func (l L) Errorf(s string, args ...any) Err

Errorf constructs a location Err setting the Msg to the results of formatting the arguments and the Loc to the location

func (L) Idx

func (l L) Idx() int64

Idx returns the current index value

func (*L) Incr

func (l *L) Incr()

Incr increments the location index and marks the location as having no content

func (L) Note added in v1.2.0

func (l L) Note() string

Note returns the note field

func (*L) SetContent

func (l *L) SetContent(s string)

SetContent sets the content and marks the location as having content

func (*L) SetNote

func (l *L) SetNote(s string)

SetNote sets the note field on the location

func (L) Source added in v1.1.0

func (l L) Source() string

Source returns the named source

func (L) String

func (l L) String() string

String provides the string representing a location

type LocChain

type LocChain []L

LocChain represents a chain of locations. This might be used to record a string of included files.

func NewChain

func NewChain() LocChain

NewChain returns a new (empty but non-nil) instance of a LocChain

func (LocChain) HasLoop

func (chain LocChain) HasLoop(name string) (bool, string)

HasLoop checks to see if the name already appears in the LocChain which records the chain of sources getting to this point. If a loop is detected then this returns true and a description of the path taken to get to the loop, otherwise it returns false and an empty string.

func (LocChain) String

func (lc LocChain) String() string

String provides a string representing a LocChain

Jump to

Keyboard shortcuts

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