Documentation
¶
Overview ¶
Package position implements a struct that describes where a sequence of characters is located in a file.
Index ¶
- Variables
- type Interface
- type Location
- func JoinLocationOfCollection[Element LocationInterface](collection []Element) *Location
- func JoinLocationOfLastElement[Element LocationInterface](left *Location, rightCollection []Element) *Location
- func LocationOfLastElement[Element LocationInterface](collection []Element) *Location
- func NewLocation(filename string, span *Span) *Location
- func NewLocationWithParent(filename string, span *Span, parent *Location) *Location
- func SpliceLocation(target, current *Location, unqoute bool) *Location
- func (l *Location) Copy() *Location
- func (l *Location) Equal(other *Location) bool
- func (l *Location) HumanString(style bool, colorizer colorizer.Colorizer, accentColor *color.Color) (string, error)
- func (l *Location) HumanStringWithSource(source string, style bool, colorizer colorizer.Colorizer, ...) (string, error)
- func (l *Location) HumanStringWithSourceMap(style bool, colorizer colorizer.Colorizer, accentColor *color.Color, ...) (string, error)
- func (left *Location) Join(right *Location) *Location
- func (left *Location) JoinSpan(right *Span) *Location
- func (l *Location) RelFilename() string
- func (l *Location) String() string
- type LocationInterface
- type Position
- type Span
- func JoinSpanOfCollection[Element SpanInterface](collection []Element) *Span
- func JoinSpanOfLastElement[Element SpanInterface](left *Span, rightCollection []Element) *Span
- func NewSpan(startPos, endPos *Position) *Span
- func NewSpanFromPosition(pos *Position) *Span
- func SpanOfLastElement[Element SpanInterface](collection []Element) *Span
- type SpanInterface
Constants ¶
This section is empty.
Variables ¶
var Default = New(0, 1, 1)
var DefaultLocation = NewLocation("<main>", DefaultSpan)
var DefaultSpan = NewSpanFromPosition(Default)
var Zero = New(0, 0, 0)
var ZeroLocation = NewLocation("", ZeroSpan)
var ZeroSpan = NewSpanFromPosition(Zero)
Functions ¶
This section is empty.
Types ¶
type Location ¶
Describes an arbitrary source position in a particular file. Lines and columns must be > 0.
func JoinLocationOfCollection ¶
func JoinLocationOfCollection[Element LocationInterface](collection []Element) *Location
Join the position of the first element of a collection with the last one.
func JoinLocationOfLastElement ¶
func JoinLocationOfLastElement[Element LocationInterface](left *Location, rightCollection []Element) *Location
Joins the given position with the last element of the given collection.
func LocationOfLastElement ¶
func LocationOfLastElement[Element LocationInterface](collection []Element) *Location
Retrieve the location of the last element of a collection.
func NewLocation ¶
Create a new location with a given position.
func NewLocationWithParent ¶
Create a new location with a given position.
func SpliceLocation ¶
func (*Location) HumanString ¶
func (l *Location) HumanString(style bool, colorizer colorizer.Colorizer, accentColor *color.Color) (string, error)
Return a string representation of this error that can be presented to humans.
Reads the content of the file using the OS.
func (*Location) HumanStringWithSource ¶
func (l *Location) HumanStringWithSource(source string, style bool, colorizer colorizer.Colorizer, accentColor *color.Color) (string, error)
Return a string representation of this error that can be presented to humans.
Uses the given source string instead of reading the content of the file.
func (*Location) HumanStringWithSourceMap ¶
func (l *Location) HumanStringWithSourceMap(style bool, colorizer colorizer.Colorizer, accentColor *color.Color, sourceMap map[string]string) (string, error)
Return a string representation of this error that can be presented to humans.
Tries to fetch the source from the provided map (keys are filepaths, values are source strings). If there is no entry for the required filepath it tries to read the file through the OS.
func (*Location) Join ¶
Join two locations into one. Works properly when the receiver is nil or the argument is nil.
func (*Location) JoinSpan ¶
Join two locations into one. Works properly when the receiver is nil or the argument is nil.
func (*Location) RelFilename ¶
Returns a path to the file that is relative to the current working directory. if it's impossible to get the working directory or the file path cannot be transformed into a relative one, the original file path is returned instead.
type LocationInterface ¶
Represents something that contains a location.
type Position ¶
type Position struct {
ByteOffset int // Index of the first byte of the source code fragment
Line int // Source line number where the fragment starts
Column int // Source column number where the fragment starts
}
Position describes an arbitrary source code position. Lines and columns must be > 0.
type Span ¶
Represents a span of text in a string/file.
func JoinSpanOfCollection ¶
func JoinSpanOfCollection[Element SpanInterface](collection []Element) *Span
Join the position of the first element of a collection with the last one.
func JoinSpanOfLastElement ¶
func JoinSpanOfLastElement[Element SpanInterface](left *Span, rightCollection []Element) *Span
Joins the given position with the last element of the given collection.
func NewSpanFromPosition ¶
Create a new span from a single position.
func SpanOfLastElement ¶
func SpanOfLastElement[Element SpanInterface](collection []Element) *Span
Retrieve the position of the last element of a collection.
type SpanInterface ¶
Represents something that contains a span.