token

package
v0.0.0-...-797e501 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Explain

func Explain(err error) string

Explain takes the given wrapped error chain and explains it, if it can.

Types

type ErrDetail

type ErrDetail struct {
	Node    Node
	Message string
}

func NewErrDetail

func NewErrDetail(node Node, msg string) ErrDetail

type Node

type Node interface {
	Begin() Pos
	End() Pos
}

Node contains access to the start and end positions of a token.

func NewFileNode

func NewFileNode(filename string) Node

NewFileNode returns a fake node which just points to 1:1 of the file, whatever that is.

func NewNode

func NewNode(begin, end Pos) Node

type Pos

type Pos struct {
	// File contains the absolute file path.
	File string
	// Offset in bytes
	Offset int
	// Line denotes the one-based line number in the denoted File.
	Line int
	// Col denotes the one-based column number in the denoted Line.
	Col int
}

A Pos describes a resolved position within a file.

func (Pos) After

func (p Pos) After(other Pos) bool

func (Pos) String

func (p Pos) String() string

String returns the content in the "file:line:col" format.

type PosError

type PosError struct {
	Details []ErrDetail
	Cause   error
	Hint    string
}

PosError represents a very specific positional error with a lot of explaining noise. Use Explain.

func NewPosError

func NewPosError(node Node, msg string, details ...ErrDetail) *PosError

NewPosError creates a new PosError with the given root cause and optional details.

func (*PosError) Error

func (p *PosError) Error() string

func (PosError) Explain

func (p PosError) Explain() string

Explain returns a multi-line text suited to be printed into the console.

func (*PosError) SetCause

func (p *PosError) SetCause(err error) *PosError

func (*PosError) SetHint

func (p *PosError) SetHint(str string) *PosError

func (*PosError) Unwrap

func (p *PosError) Unwrap() error

type Position

type Position struct {
	BeginPos, EndPos Pos
}

func (Position) After

func (d Position) After(other Position) bool

After returns true, if this position end is beyond the other position begin.

func (Position) Begin

func (d Position) Begin() Pos

func (Position) End

func (d Position) End() Pos

func (*Position) SetBegin

func (d *Position) SetBegin(filename string, line, col int)

func (*Position) SetEnd

func (d *Position) SetEnd(filename string, line, col int)

type String

type String struct {
	Position
	Val string
}

A String holds a positional value.

func Lines

func Lines(filename string, r io.ByteReader) ([]String, error)

Lines parses the given bytes and returns the correct located string for each line.

func NewString

func NewString(val string) String

NewString just creates a new string.

func (String) GoString

func (s String) GoString() string

GoString returns a positional information with the string.

func (String) Locate

func (s String) Locate(filename string, offset, line, col int) String

Locate creates a new string with the applied position, assuming this string is ever in a single line.

func (String) String

func (s String) String() string

String just returns the value.

func (String) TrimSpace

func (s String) TrimSpace() String

TrimSpace returns a new string with the retro-fitted positions.

func (String) Value

func (s String) Value() string

Value of this string.

Jump to

Keyboard shortcuts

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