input

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytePosition

type BytePosition int

BytePosition represents the byte position in a piece of code.

type Position

type Position struct {
	// LineNumber is the 0-indexed line number.
	LineNumber int

	// ColumnPosition is the 0-indexed column position on the line.
	ColumnPosition int
}

Position represents a position in an arbitrary source file.

type PositionMapper

type PositionMapper interface {
	// RunePositionToLineAndCol converts the given 0-indexed rune position under the given source file
	// into a 0-indexed line number and column position.
	RunePositionToLineAndCol(runePosition int, path Source) (int, int, error)

	// LineAndColToRunePosition converts the given 0-indexed line number and column position under the
	// given source file into a 0-indexed rune position.
	LineAndColToRunePosition(lineNumber int, colPosition int, path Source) (int, error)

	// TextForLine returns the text for the specified line number.
	TextForLine(lineNumber int, path Source) (string, error)
}

PositionMapper defines an interface for converting rune position <-> line+col position under source files.

type Source added in v1.4.0

type Source string

Source represents the path of a source file.

func (Source) PositionForRunePosition added in v1.4.0

func (is Source) PositionForRunePosition(runePosition int, mapper PositionMapper) SourcePosition

PositionForRunePosition returns a source position over this source file.

func (Source) PositionFromLineAndColumn added in v1.4.0

func (is Source) PositionFromLineAndColumn(lineNumber int, columnPosition int, mapper PositionMapper) SourcePosition

PositionFromLineAndColumn returns a source position at the given line and column in this source file.

func (Source) RangeForLineAndColPositions added in v1.4.0

func (is Source) RangeForLineAndColPositions(start Position, end Position, mapper PositionMapper) SourceRange

RangeForLineAndColPositions returns a source range over this source file.

func (Source) RangeForRunePosition added in v1.4.0

func (is Source) RangeForRunePosition(runePosition int, mapper PositionMapper) SourceRange

RangeForRunePosition returns a source range over this source file.

func (Source) RangeForRunePositions added in v1.4.0

func (is Source) RangeForRunePositions(startRune int, endRune int, mapper PositionMapper) SourceRange

RangeForRunePositions returns a source range over this source file.

type SourcePosition

type SourcePosition interface {
	// Source is the input source for this position.
	Source() Source

	// RunePosition returns the 0-indexed rune position in the source file.
	RunePosition() (int, error)

	// LineAndColumn returns the 0-indexed line number and column position in the source file.
	LineAndColumn() (int, int, error)

	// LineText returns the text of the line for this position.
	LineText() (string, error)

	// String returns a (somewhat) human-readable form of the position.
	String() string
}

SourcePosition represents a single position in a source file.

type SourcePositionMapper

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

SourcePositionMapper defines a helper struct for cached, faster lookup of rune position <-> (line, column) for a specific source file.

func CreateSourcePositionMapper

func CreateSourcePositionMapper(contents []byte) SourcePositionMapper

CreateSourcePositionMapper returns a source position mapper for the contents of a source file.

func EmptySourcePositionMapper

func EmptySourcePositionMapper() SourcePositionMapper

EmptySourcePositionMapper returns an empty source position mapper.

func (SourcePositionMapper) LineAndColToRunePosition

func (spm SourcePositionMapper) LineAndColToRunePosition(lineNumber int, colPosition int) (int, error)

LineAndColToRunePosition returns the rune position of the line number and column position in source.

func (SourcePositionMapper) RunePositionToLineAndCol

func (spm SourcePositionMapper) RunePositionToLineAndCol(runePosition int) (int, int, error)

RunePositionToLineAndCol returns the line number and column position of the rune position in source.

type SourceRange

type SourceRange interface {
	// Source is the input source for this range.
	Source() Source

	// Start is the starting position of the source range.
	Start() SourcePosition

	// End is the ending position (inclusive) of the source range. If the same as the Start,
	// this range represents a single position.
	End() SourcePosition

	// ContainsPosition returns true if the given range contains the given position.
	ContainsPosition(position SourcePosition) (bool, error)

	// AtStartPosition returns a SourceRange located only at the starting position of this range.
	AtStartPosition() SourceRange

	// String returns a (somewhat) human-readable form of the range.
	String() string
}

SourceRange represents a range inside a source file.

Jump to

Keyboard shortcuts

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