lexer

package
v0.0.0-...-c0f2935 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LexFn

type LexFn func(*Lexer) LexFn

type Lexer

type Lexer struct {
	Input  string
	Tokens chan lexertoken.Token
	State  LexFn

	Start int
	Pos   int
	Width int
}

func New

func New(opts ...LexerOption) (*Lexer, error)

func (*Lexer) Backup

func (l *Lexer) Backup()

Backup to the beginning of the last read token.

func (*Lexer) CurrentInput

func (l *Lexer) CurrentInput() string

Returns a slice of the current input from the current lexer start position to the current position.

func (*Lexer) Dec

func (l *Lexer) Dec()

Decrement the position

func (*Lexer) Emit

func (l *Lexer) Emit(tokenType lexertoken.TokenType)

Puts a token onto the token channel. The value of l token is read from the input based on the current lexer position.

func (*Lexer) Errorf

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

Returns a token with error information.

func (*Lexer) Ignore

func (l *Lexer) Ignore()

Ignores the current token by setting the lexer's start position to the current reading position.

func (*Lexer) Inc

func (l *Lexer) Inc()

Increment the position

func (*Lexer) InputToEnd

func (l *Lexer) InputToEnd() string

Return a slice of the input from the current lexer position to the end of the input string.

func (*Lexer) IsEOF

func (l *Lexer) IsEOF() bool

Returns the true/false if the lexer is at the end of the input stream.

func (*Lexer) IsWhitespace

func (l *Lexer) IsWhitespace() bool

Returns true/false if then next character is whitespace

func (*Lexer) Next

func (l *Lexer) Next() rune

Reads the next rune (character) from the input stream and advances the lexer position.

func (*Lexer) NextToken

func (l *Lexer) NextToken() chan lexertoken.Token

func (*Lexer) Peek

func (l *Lexer) Peek() rune

Returns the next rune in the stream, then puts the lexer position back. Basically reads the next rune without consuming it.

func (*Lexer) Run

func (l *Lexer) Run()

Starts the lexical analysis and feeding tokens into the token channel.

func (*Lexer) SetInput

func (l *Lexer) SetInput(b string)

func (*Lexer) Shutdown

func (l *Lexer) Shutdown()

Shuts down the token stream

func (*Lexer) SkipWhitespace

func (l *Lexer) SkipWhitespace()

Skips whitespace until we get something meaningful.

type LexerOption

type LexerOption func(*Lexer)

func WihInitalState

func WihInitalState(lf LexFn) LexerOption

func WithInput

func WithInput(i string) LexerOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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