lexer

package
v0.0.0-...-1c8d635 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const EOF rune = -1

EOF denotes the end of file

Variables

View Source
var EOLexToken = Token{"eolex", 0}

EOLexToken is Token to denote end of lexing

View Source
var ErrorToken = Token{"error", 0}

ErrorToken is a Token to denote error

Functions

This section is empty.

Types

type Bounds

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

Bounds represents the bounding states of lex machine

type LexState

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

LexState denotes an individual state in a pushdown automata

func NewLexState

func NewLexState(tt TokenType, typ LexStateType, isEmitter bool) *LexState

NewLexState creates a new instance of LexState

func (*LexState) AddDest

func (l *LexState) AddDest(p Path, dest *LexState)

AddDest adds a new LexState as a neighbour to this LexState

func (LexState) String

func (l LexState) String() string

String (LexState) produces a string representation of LexState

type LexStateType

type LexStateType int

LexStateType denotes the type of the state for a LexMachine

const (
	// Buffer pushes back input after consuming it
	Buffer LexStateType = 0
	// Feeder simply feeds on input
	Feeder LexStateType = 1
	// Storer stores runes to be mathced
	Storer LexStateType = 2
	// Matcher matches runes
	Matcher LexStateType = 3
)

func (LexStateType) String

func (l LexStateType) String() string

String (LexStateType) produces a string representation of a LexStateType

type Lexer

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

Lexer reperesents a lexing machine reading runes from a Reader

func NewLexer

func NewLexer(reader io.Reader, capacity int) *Lexer

NewLexer creates a new instance of Lexer from a Reader instance with a given buffer capacity.

func (*Lexer) Backup

func (l *Lexer) Backup()

Backup unreads the last read rune

func (*Lexer) Emit

func (l *Lexer) Emit(t TokenType) Token

Emit emits a token of the given TokenType

func (*Lexer) Ignore

func (l *Lexer) Ignore()

Ignore ignores the last read rune

func (*Lexer) Next

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

Next reads the next rune present in the private buffer

func (*Lexer) Peek

func (l *Lexer) Peek() rune

Peek peeks at the next rune in the buffer

func (*Lexer) Reset

func (l *Lexer) Reset()

Reset resets the lexer state

type Machine

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

Machine is a PDA which represents a lexing machine attached to the "tape reader"

func NewMachine

func NewMachine(lexer *Lexer, bounds Bounds, matcher *RuneMatcher) *Machine

NewMachine creates a new instance of lexer.Machine

func (*Machine) AttachLexer

func (m *Machine) AttachLexer(l *Lexer)

AttachLexer attaches new lexer to this machine and resets it.

func (*Machine) CanStep

func (m *Machine) CanStep() bool

CanStep states whether this machine can step over to a new state

func (*Machine) Finished

func (m *Machine) Finished() bool

Finished states whether this machine has reached the finishing state.

func (*Machine) NextToken

func (m *Machine) NextToken() (Token, error)

NextToken returns the next Token from the channel

func (*Machine) Reset

func (m *Machine) Reset()

Reset resets all the components of this machine.

func (*Machine) Step

func (m *Machine) Step() error

Step steps one LexState of the machine

type Path

type Path rune

Path denotes a link or input to traverse from the current state to the next state

const DefaultPath Path = 0

DefaultPath is the path to be taken in the event of unexpected or no input

type RuneMatcher

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

RuneMatcher is a component to keep track of matchable runes

func NewRuneMatcher

func NewRuneMatcher() *RuneMatcher

NewRuneMatcher creates a new instance of RuneMatcher

func (*RuneMatcher) EnlistMapping

func (m *RuneMatcher) EnlistMapping(r1, r2 rune)

EnlistMapping enlists a new mapping in this RuneMatcher

func (*RuneMatcher) IsMatched

func (m *RuneMatcher) IsMatched() bool

IsMatched checks whether the RuneMatcher is in matched state if its stack is completely empty

func (*RuneMatcher) Match

func (m *RuneMatcher) Match(r rune) bool

Match matches the given rune against the rune at TOS of matcher's stack

func (*RuneMatcher) Reset

func (m *RuneMatcher) Reset()

Reset resets this matcher

func (*RuneMatcher) Store

func (m *RuneMatcher) Store(r rune) bool

Store stores a rune to matched against in this RuneMatcher

type Token

type Token struct {
	Lexeme string
	Type   TokenType
}

Token represents the atomic semantic entity in a text corpus

func (Token) String

func (t Token) String() string

type TokenType

type TokenType interface{}

TokenType denotes the type of Token

Jump to

Keyboard shortcuts

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