Documentation
¶
Index ¶
- Constants
- type Lexer
- func (l *Lexer) Accept(valid string) bool
- func (l *Lexer) AcceptRun(valid string) (n int)
- func (l *Lexer) Backup()
- func (l *Lexer) Current() string
- func (l *Lexer) Emit(t TokenType)
- func (l *Lexer) Error(format string, args ...interface{}) StateFunc
- func (l *Lexer) Ignore()
- func (l *Lexer) Next() rune
- func (l *Lexer) NextToken() (*Token, bool)
- func (l *Lexer) Peek() rune
- func (l *Lexer) SkipWhitespace()
- func (l *Lexer) Start()
- func (l *Lexer) StartSync()
- func (l *Lexer) Tokens() <-chan Token
- type StateFunc
- type Token
- type TokenType
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer represents the lexer machine.
func New ¶
New creates a returns a lexer ready to parse the given source code.
func (*Lexer) Accept ¶
Accept receives a string containing all acceptable strings and will continue over each consecutive character in the source until a token not in the given string is encountered. This should be used to quickly pull token parts.
func (*Lexer) AcceptRun ¶
AcceptRun consumes a run of runes from the valid set.
func (*Lexer) Backup ¶
func (l *Lexer) Backup()
Backup will take the last rune read (if any) and history back. Backups can occur more than once per call to Next but you can never history past the last point a token was emitted.
func (*Lexer) Current ¶
Current returns the value being being analyzed at this moment.
func (*Lexer) Emit ¶
Emit will receive a token type and push a new token with the current analyzed value into the tokens channel.
func (*Lexer) Ignore ¶
func (l *Lexer) Ignore()
Ignore clears the history stack and then sets the current beginning position to the current position in the source which effectively ignores the section of the source being analyzed.
func (*Lexer) Next ¶
Next pulls the next rune from the Lexer and returns it, moving the position forward in the source.
func (*Lexer) NextToken ¶
NextToken returns the next token from the lexer and done
func (*Lexer) Peek ¶
Peek performs a Next operation immediately followed by a Backup returning the peeked rune.
func (*Lexer) SkipWhitespace ¶
func (l *Lexer) SkipWhitespace()
SkipWhitespace continues over all unicode whitespace.
type StateFunc ¶
StateFunc captures the movement from one state to the next.
type Token ¶
Token is returned by the lexer.
Source Files
¶
- lexer.go
- stack.go