input

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStartOfFile = errors.New("SOF")

ErrStartOfFile is the error used when we've retreated to the start of the file and can't retreat any further.

Functions

This section is empty.

Types

type Buffer

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

func NewBuffer

func NewBuffer(size int) *Buffer

func NewBufferFromString

func NewBufferFromString(s string, size int) *Buffer

func (*Buffer) Append

func (b *Buffer) Append(runes ...rune) error

func (*Buffer) At

func (b *Buffer) At(i int) rune

func (*Buffer) Collect

func (b *Buffer) Collect() (s string)

func (*Buffer) CollectSlice

func (b *Buffer) CollectSlice(max int) (s string)

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) Peek

func (b *Buffer) Peek() string

type Position

type Position struct {
	Index int64
	Line  int
	Col   int
	// contains filtered or unexported fields
}

Position represents the character position within a text file.

func NewPosition

func NewPosition(line int, col int) Position

NewPosition creates a Position to represent the character position within a text file.

func (*Position) Advance

func (p *Position) Advance(r rune)

Advance advances the position by a line if the rune is'\n', does nothing if the rune is '\r' and advances by a col character if the rune is anything else.

func (*Position) Eq

func (p *Position) Eq(cmp Position) bool

Eq compares two positions and returns true if they are equal.

func (*Position) Retreat

func (p *Position) Retreat(r rune)

Retreat decreases the position by a line if the rune is'\n', does nothing if the rune is '\r' and decreases by a col character if the rune is anything else.

func (*Position) String

func (p *Position) String() string

String creates a string representation of the position.

type Stream

type Stream struct {
	// Input holds the Reader being scanned.
	Input io.RuneReader
	// Buffer is the space currently being searched for tokens to avoid seeking the input stream.
	// When a token match is found, the buffer is emptied.
	Buffer *Buffer
	// Start represents the start position of the lexer against the Input, e.g.
	// if we've lexed 124 runes already, that's where we're starting from.
	Start int64
	// Current represents the current position of the lexer. We might have lexed
	// 124 runes and have read 3 more runes without yet emitting a token, so current would
	// be 124+3=127
	Current int64
	// CurrentRune is the current rune at the cursor.
	CurrentRune rune
	// contains filtered or unexported fields
}

Stream defines a lexical scanner over a stream.

func New

func New(input io.RuneReader) *Stream

New creates a new parser input from a buffered reader.

func NewFromString

func NewFromString(input string) *Stream

NewFromString creates a new parser input from an input string.

func NewWithBufferSize added in v0.0.48

func NewWithBufferSize(input io.RuneReader, size int) *Stream

NewWithBufferSize allows the buffer to be sized appropriately for the input. There's no need to allocate more than the length of the input as the buffer.

func (*Stream) Advance

func (l *Stream) Advance() (r rune, err error)

Advance reads a rune from the Input and sets the current position.

func (*Stream) Collect

func (l *Stream) Collect() string

Collect returns the value of the consumed buffer and updates the position of the stream to the current position.

func (*Stream) Index

func (l *Stream) Index() int64

Index returns the current index position within the stream.

func (*Stream) Peek

func (l *Stream) Peek() (rune, error)

Peek reads a rune from the Input, then sets the current position back.

func (*Stream) PeekN

func (l *Stream) PeekN(n int) (s string, err error)

PeekN reads a number of runes from the Input, then sets the current position back.

func (*Stream) Position

func (l *Stream) Position() (line, column int)

Position returns the current position within the stream.

func (*Stream) Retreat

func (l *Stream) Retreat() (r rune, err error)

Retreat steps back a rune.

func (*Stream) String

func (l *Stream) String() string

type StringRuneReader

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

StringRuneReader allows a string to be read rune-by-rune. It allocates slightly less variables than NewBufferString or NewReader.

func (*StringRuneReader) ReadRune

func (sr *StringRuneReader) ReadRune() (r rune, size int, err error)

ReadRune reads a rune from the underlying string.

Jump to

Keyboard shortcuts

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