lex

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2016 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const EOF = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckRune

type CheckRune func(r rune) bool

type ItemType

type ItemType int

ItemType is used to set the type of a token. These constants can be defined in the file containing state functions. Note that their value should be >= 5.

const (
	ItemEOF   ItemType = iota
	ItemError          // error
)

type Lexer

type Lexer struct {
	// NOTE: Using a text scanner wouldn't work because it's designed for parsing
	// Golang. It won't keep track of start position, or allow us to retrieve
	// slice from [start:pos]. Better to just use normal string.
	Input       string    // string being scanned.
	Start       int       // start position of this item.
	Pos         int       // current position of this item.
	Width       int       // width of last rune read from input.
	Items       chan item // channel of scanned items.
	Depth       int       // nesting of {}
	FilterDepth int       // nesting of () inside filter directive.
	Mode        int       // mode based on information so far.
}

func (*Lexer) AcceptRun

func (l *Lexer) AcceptRun(c CheckRune)

func (*Lexer) AcceptUntil

func (l *Lexer) AcceptUntil(c CheckRune)

func (*Lexer) Backup

func (l *Lexer) Backup()

func (*Lexer) Emit

func (l *Lexer) Emit(t ItemType)

Emit emits the item with it's type information.

func (*Lexer) Errorf

func (l *Lexer) Errorf(format string, args ...interface{}) StateFn

Errorf returns the error state function.

func (*Lexer) Ignore

func (l *Lexer) Ignore()

func (*Lexer) Init

func (l *Lexer) Init(input string)

func (*Lexer) Next

func (l *Lexer) Next() (result rune)

Next reads the next rune from the Input, sets the Width and advances Pos.

func (*Lexer) Peek

func (l *Lexer) Peek() rune

type StateFn

type StateFn func(*Lexer) StateFn

stateFn represents the state of the scanner as a function that returns the next state.

Jump to

Keyboard shortcuts

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