position

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Abstraction of a position for use by consumers, with a basic implementation.

This interface intentionally makes no provision for updating the position. If it did, compiler implementations would incur two forms of overhead:

  • Every query operation on a Position would involve an indirection
  • Since positions are intended to be read-only, every advance of a Position would incur an allocation overhead.

The second one is the main concern, because positions are manipulated very frequently in parsers and formatters. The practical consequence is that such tools must provide their own position implementation, such as the one in reader.Pos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicPos

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

A basic position value.

This type exists primarily for testing. It can be used as a starting point, but where performance or space are important you will want a more condensed representation. The one in the reader package is an example.

func OffsetPos

func OffsetPos(nm string, line, col int, off int) *BasicPos

func Pos

func Pos(nm string, line, col int) *BasicPos

func (*BasicPos) Column

func (pos *BasicPos) Column() int

func (*BasicPos) Filename

func (pos *BasicPos) Filename() string

------------------------------------------------------------------------- Implement Position interface

func (*BasicPos) Line

func (pos *BasicPos) Line() int

func (*BasicPos) Offset

func (pos *BasicPos) Offset() int

func (*BasicPos) Raw

func (pos *BasicPos) Raw() Position

func (*BasicPos) String

func (pos *BasicPos) String() string

------------------------------------------------------------------------- Implement Stringer interface

type Position

type Position interface {
	fmt.Stringer

	Filename() string // Return the file name associated with this position.
	Line() int        // Return the line number (starting at 1) of this position.
	Column() int      // Return the column number (starting at 1) of this position.
	Offset() int      // Return the byte offset (starting at 0) of this position.
	Raw() Position    // Return aform of the position that does not take line number directives into account.
}

The position abstraction

Jump to

Keyboard shortcuts

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