src

package
Version: v0.0.0-...-e410d2a Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2017 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pos

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

A Pos encodes a source position consisting of a (line, column) number pair and a position base. A zero Pos is a ready to use "unknown" position (nil position base and zero line number).

The (line, column) values refer to a position in a file independent of any position base ("absolute" position). Line numbers start at 1, column values start at 0 and are byte offsets from the beginning of the line.

The position base is used to determine the "relative" position, that is the filename and line number relative to the position base. If the base refers to the current file, there is no difference between absolute and relative positions. If it refers to a //line pragma, a relative position is relative to that pragma. A position base in turn contains the position at which it was introduced in the current file.

var NoPos Pos

NoPos is a valid unknown position.

func MakePos

func MakePos(base *PosBase, line, col uint) Pos

MakePos creates a new Pos value with the given base, and (file-absolute) line and column.

func (Pos) AbsFilename

func (p Pos) AbsFilename() string

AbsFilename() returns the absolute filename recorded with the position's base.

func (Pos) After

func (p Pos) After(q Pos) bool

After reports whether the position p comes after q in the source. For positions in different files, ordering is by filename.

func (Pos) Base

func (p Pos) Base() *PosBase

Base returns the position base.

func (Pos) Before

func (p Pos) Before(q Pos) bool

Before reports whether the position p comes before q in the source. For positions in different files, ordering is by filename.

func (Pos) Col

func (x Pos) Col() uint

func (Pos) Filename

func (p Pos) Filename() string

Filename returns the name of the actual file containing this position.

func (Pos) IsKnown

func (p Pos) IsKnown() bool

IsKnown reports whether the position p is known. A position is known if it either has a non-nil position base, or a non-zero line number.

func (Pos) Line

func (x Pos) Line() uint

func (Pos) RelFilename

func (p Pos) RelFilename() string

RelFilename returns the filename recorded with the position's base.

func (Pos) RelLine

func (p Pos) RelLine() uint

RelLine returns the line number relative to the positions's base.

func (Pos) String

func (p Pos) String() string

type PosBase

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

A PosBase encodes a filename and base line number. Typically, each file and line pragma introduce a PosBase. A nil *PosBase is a ready to use file PosBase for an unnamed file with line numbers starting at 1.

func NewFileBase

func NewFileBase(filename, absFilename string) *PosBase

NewFileBase returns a new *PosBase for a file with the given (relative and absolute) filenames.

func NewLinePragmaBase

func NewLinePragmaBase(pos Pos, filename string, line uint) *PosBase

NewLinePragmaBase returns a new *PosBase for a line pragma of the form

//line filename:line

at position pos.

func (*PosBase) AbsFilename

func (b *PosBase) AbsFilename() string

AbsFilename returns the absolute filename recorded with the base. If b == nil, the result is the empty string.

func (*PosBase) Filename

func (b *PosBase) Filename() string

Filename returns the filename recorded with the base. If b == nil, the result is the empty string.

func (*PosBase) Line

func (b *PosBase) Line() uint

Line returns the line number recorded with the base. If b == nil, the result is 0.

func (*PosBase) Pos

func (b *PosBase) Pos() *Pos

Pos returns the position at which base is located. If b == nil, the result is the zero position.

type PosTable

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

A PosTable tracks Pos -> XPos conversions and vice versa. Its zero value is a ready-to-use PosTable.

func (*PosTable) Pos

func (t *PosTable) Pos(p XPos) Pos

Pos returns the corresponding Pos for the given p. If p cannot be translated via t, the function panics.

func (*PosTable) XPos

func (t *PosTable) XPos(pos Pos) XPos

XPos returns the corresponding XPos for the given pos, adding pos to t if necessary.

type XPos

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

XPos is a more compact representation of Pos.

var NoXPos XPos

NoXPos is a valid unknown position.

func (XPos) After

func (p XPos) After(q XPos) bool

After reports whether the position p comes after q in the source. For positions with different bases, ordering is by base index.

func (XPos) Before

func (p XPos) Before(q XPos) bool

Before reports whether the position p comes before q in the source. For positions with different bases, ordering is by base index.

func (XPos) Col

func (x XPos) Col() uint

func (XPos) IsKnown

func (p XPos) IsKnown() bool

IsKnown reports whether the position p is known. XPos.IsKnown() matches Pos.IsKnown() for corresponding positions.

func (XPos) Line

func (x XPos) Line() uint

Source Files

Jump to

Keyboard shortcuts

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