Documentation
¶
Overview ¶
Package lex provides a base lexer to help you implement your own.
Feel free to copy this into your library (according to the license) as well as use it as a library. Both methods are possible.
Code and API based off standard library text/template/parse.
Index ¶
- Constants
- Variables
- func IsAlphaNumeric(r rune) bool
- func IsEndline(r rune) bool
- func IsQuote(r rune) bool
- func IsSpace(r rune) bool
- type Lexer
- func (l *Lexer) Accept(valid string) bool
- func (l *Lexer) AcceptBut(invalid string) bool
- func (l *Lexer) AcceptButRun(invalid string) int
- func (l *Lexer) AcceptFunc(f func(r rune) bool) bool
- func (l *Lexer) AcceptFuncRun(f func(r rune) bool) int
- func (l *Lexer) AcceptRun(valid string) int
- func (l *Lexer) Backup()
- func (l *Lexer) ColumnNumber() int
- func (l *Lexer) Consume(s string) bool
- func (l *Lexer) Dec(n int)
- func (l *Lexer) Drain()
- func (l *Lexer) Emit(t Type)
- func (l *Lexer) Errorf(format string, args ...interface{}) StateFn
- func (l *Lexer) HasPrefix(s string) bool
- func (l *Lexer) HasPrefixAfter(after int, s string) bool
- func (l *Lexer) Ignore()
- func (l *Lexer) Inc(n int)
- func (l *Lexer) Input(n int) string
- func (l *Lexer) Len() int
- func (l *Lexer) LineNumber() int
- func (l *Lexer) Name() string
- func (l *Lexer) Next() rune
- func (l *Lexer) NextToken() Token
- func (l *Lexer) Peek() rune
- func (l *Lexer) Pos() int
- func (l *Lexer) Run(fn StateFn)
- func (l *Lexer) Value() string
- type Reader
- type StateFn
- type Token
- type Type
Constants ¶
const EOF = -1
EOF is returned by Lexer.Next upon reaching end-of-file.
Variables ¶
var ( Space = " \t" Endline = "\r\n" Quote = "\"'`" )
Functions ¶
func IsAlphaNumeric ¶
Types ¶
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new Lexer and returns it.
Before calling NextToken, it should be run in a separate goroutine:
l := lex.New(name, input) go l.Run(sf) ... t := l.NextToken()
func (*Lexer) AcceptButRun ¶
AcceptButRun consumes runes as long as they are not in the invalid set. The number of bytes advanced is returned.
func (*Lexer) AcceptFunc ¶
AcceptFunc consumes the next rune if f returns true.
func (*Lexer) AcceptFuncRun ¶
AcceptFunc consumes a run of runes as long as f returns true. The number of bytes advanced is returned.
func (*Lexer) AcceptRun ¶
AcceptRun consumes a run of runes from the valid set. The number of bytes advanced is returned.
func (*Lexer) Backup ¶
func (l *Lexer) Backup()
Backup steps back one rune. Can only be called once per call of Next.
func (*Lexer) ColumnNumber ¶
ColumnNumber reports the column of the last token returned by NextToken.
func (*Lexer) Drain ¶
func (l *Lexer) Drain()
Drain drains the output so the lexing goroutine will exit. Called by the parser, not in the lexing goroutine.
func (*Lexer) Errorf ¶
Errorf returns an error token and terminates the scan by passing back a nil pointer that will be the next state, terminating l.NextToken.
func (*Lexer) HasPrefix ¶
HasPrefix returns true if the input from the current position has the prefix s. It does not consume the prefix.
func (*Lexer) HasPrefixAfter ¶
HasPrefixAfter returns true if the input from the current position plus after bytes has the prefix s. It does not consume the prefix.
func (*Lexer) Ignore ¶
func (l *Lexer) Ignore()
Ignore skips over the pending input before this point.
func (*Lexer) LineNumber ¶
LineNumber reports the line of the last token returned by NextToken.
func (*Lexer) Next ¶
Next returns the next rune in the input. If there is no more input left to read, EOF is returned.
func (*Lexer) NextToken ¶
NextToken returns the next token from the input. Called by the parser, not in the lexing goroutine.
Note: if l.Run has not been called, NextToken will block.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}