Documentation
¶
Index ¶
- type LexFn
- type Lexer
- func (l *Lexer) Accept(valid string) bool
- func (l *Lexer) AcceptFunc(fn RuneCheck)
- func (l *Lexer) AcceptRun(valid string)
- func (l *Lexer) AcceptRunFunc(fn RuneCheck)
- func (l *Lexer) AcceptUntil(delims string)
- func (l *Lexer) AcceptUntilUnescaped(delims string)
- func (l *Lexer) Backup()
- func (l *Lexer) Emit(t Token)
- func (l *Lexer) Ignore()
- func (l *Lexer) Next() rune
- func (l *Lexer) Peek() rune
- func (l *Lexer) Run(initial LexFn) []Token
- type RuneCheck
- type TextToken
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LexFn ¶
A LexFn does the meat of the work. It accepts a pointer to a Lexer, manipulates its state in some way, e.g. accepts runes and emits tokens, and then returns a new LexFn to deal with the next stage of the lexing - or nil if no lexing is left to be done.
type Lexer ¶
type Lexer struct { Text string // The raw input text Pos int // The current byte offset in the text Width int // The width of the current rune in bytes Cur rune // The rune at the current position Prev rune // The rune at the previous position Tokens []Token // The tokens that have been emitted TokenStart int // The starting position of the current token }
Lexer holds the state for lexing statements
func (*Lexer) AcceptFunc ¶
AcceptFunc accepts a rune if the provided runeCheck function returns true
func (*Lexer) AcceptRunFunc ¶
AcceptRunFunc continually accepts runes for as long as the runeCheck function returns true
func (*Lexer) AcceptUntil ¶
AcceptUntil accepts runes until it hits a delimiter rune contained in the provided string
func (*Lexer) AcceptUntilUnescaped ¶
AcceptUntilUnescaped accepts runes until it hits a delimiter rune contained in the provided string, unless that rune was escaped with a backslash
func (*Lexer) Backup ¶
func (l *Lexer) Backup()
Backup moves the lexer back one rune can only be used once per call of next()
func (*Lexer) Emit ¶
Emit adds the current token to the token slice and moves the tokenStart pointer to the current position
type RuneCheck ¶
RuneCheck is a function that determines if a rune is valid or not when using AcceptFunc or AcceptRunFunc. Some functions in the standard library, such as unicode.IsNumber() meet this interface already.