traindown

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const EOFRune rune = -1

EOFRune is the end of file rune.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lexer

type Lexer struct {
	Err          error
	ErrorHandler func(e string)
	// contains filtered or unexported fields
}

Lexer is the core struct that manages state through the StateFuncs.

func NewLexer

func NewLexer(src string, start StateFunc) *Lexer

NewLexer creates a returns a Lexer.

func (Lexer) Current

func (l Lexer) Current() string

Current returns the value being being analyzed at this moment.

func (*Lexer) Emit

func (l *Lexer) Emit(t TokenType)

Emit pushes into the tokens channel a new token with the Current value.

func (*Lexer) Error

func (l *Lexer) Error(e string)

Error provides a mechanism for parsers to signal to the Lexer an error has occurred.

func (*Lexer) Ignore

func (l *Lexer) Ignore()

Ignore dumps the VCR and sets the current beginning position to the cursor.

func (*Lexer) Next

func (l *Lexer) Next() rune

Next increments to the next rune and returns the value.

func (*Lexer) NextToken

func (l *Lexer) NextToken() (*Token, bool)

NextToken returns the next token from the lexer along with a done bool.

func (*Lexer) Peek

func (l *Lexer) Peek() rune

Peek is Next + Rewind returning the rune that will come next.

func (*Lexer) Rewind

func (l *Lexer) Rewind()

Rewind pops the last rune from the VCR and sets position there guarding against rewinding into a previous token.

func (*Lexer) SetBufferSize

func (l *Lexer) SetBufferSize(s int)

SetBufferSize is a setter for the buffer capacity.

func (*Lexer) Start

func (l *Lexer) Start()

Start starts the Lexer which populates the tokens channel.

func (*Lexer) Take

func (l *Lexer) Take(chars string)

Take accepts a string of runes that it will match against to increment forward only when the current rune is in the match set.

type StateFunc

type StateFunc func(*Lexer) StateFunc

StateFunc takes in a pointer to Lexer and returns a new StateFunc.

func DateTimeState

func DateTimeState(l *Lexer) StateFunc

func IdleState

func IdleState(l *Lexer) StateFunc

func MetaKeyState

func MetaKeyState(l *Lexer) StateFunc

func MetaValueState

func MetaValueState(l *Lexer) StateFunc

func MovementState

func MovementState(l *Lexer) StateFunc

func NoteState

func NoteState(l *Lexer) StateFunc

func NumberState

func NumberState(l *Lexer) StateFunc

func ValueState

func ValueState(l *Lexer) StateFunc

TODO: Probe for movements starting with a number as well as a load like "bw"

func WhitespaceState

func WhitespaceState(l *Lexer) StateFunc

type Token

type Token struct {
	Type  TokenType
	Value string
}

Token contains a TokenType and the raw input

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int

TokenType is just the token enum for use in a Parser

const (
	DateTimeToken TokenType = iota
	FailToken
	LoadToken
	MetaKeyToken
	MetaValueToken
	MovementToken
	NoteToken
	RepToken
	SetToken
	SupersetMovementToken
)

func (TokenType) String

func (tt TokenType) String() string

Jump to

Keyboard shortcuts

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