lex

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lex implements common lexing utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Line, Column int
}

type RuneScanner

type RuneScanner struct {
	Err error
	// contains filtered or unexported fields
}

func NewRuneScanner

func NewRuneScanner(r io.Reader) *RuneScanner

NewLexer creates a lexer that reads runes from r.

func (*RuneScanner) AdvanceIf

func (rs *RuneScanner) AdvanceIf(runes string, ranges ...*unicode.RangeTable) bool

AdvanceIf reads a matching rune and returns true, or else leaves rs where it was and returns false.

func (*RuneScanner) AdvanceWhile

func (rs *RuneScanner) AdvanceWhile(runes string, ranges ...*unicode.RangeTable) bool

AdvanceWhile reads matching runes until EOF or a non-matching rune is found, rewinds one step, and finally returns true if and only if at least one matching rune was found.

func (*RuneScanner) AdvanceWhileNot

func (rs *RuneScanner) AdvanceWhileNot(runes string, ranges ...*unicode.RangeTable) bool

AdvanceWhile reads non-matching runes until EOF or a matching rune is found, rewinds one step, and finally returns true if and only if at least one non-matching rune was found.

func (*RuneScanner) Clear

func (rs *RuneScanner) Clear()

func (*RuneScanner) Index

func (rs *RuneScanner) Index() int

func (*RuneScanner) Peek

func (rs *RuneScanner) Peek() rune

Peek returns the rune that would be returned from a subsequent call to Rune.

func (*RuneScanner) Position

func (rs *RuneScanner) Position(n int) Position

Position returns the position of the rune at position n within the current buffer, and supports negative indexing from the end. Panics if abs(n)>=rs.Size().

func (*RuneScanner) Rune

func (rs *RuneScanner) Rune() rune

Rune reads and returns the next available rune.

func (*RuneScanner) Runes

func (rs *RuneScanner) Runes() []rune

func (*RuneScanner) Seek

func (rs *RuneScanner) Seek(n int)

func (*RuneScanner) Unrune

func (rs *RuneScanner) Unrune()

Unrune moves backward by one in the rune buffer of runes that have been read, such that a subsequent call to Rune will re-read a rune that was read before. Panics if the rune buffer is empty.

Jump to

Keyboard shortcuts

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