Documentation ¶
Index ¶
- Constants
- Variables
- func Parse(src *Source, lexer Lexer, precedence int) interface{}
- func String(input string, lexer Lexer) (interface{}, error)
- type InfixToken
- type Lexer
- type PrefixToken
- type Source
- func (src *Source) DeleteSavepoint()
- func (src *Source) Error() error
- func (src *Source) Expect(expect []byte) bool
- func (src *Source) Expect1(b1 byte) bool
- func (src *Source) Expect2(b1, b2 byte) bool
- func (src *Source) Expect3(b1, b2, b3 byte) bool
- func (src *Source) Expect4(b1, b2, b3, b4 byte) bool
- func (src *Source) FatalError() error
- func (src *Source) Peek() []byte
- func (src *Source) Peek1() byte
- func (src *Source) PeekAll() []byte
- func (src *Source) PeekN(n int) []byte
- func (src *Source) PeekRune() (rune, int)
- func (src *Source) PeekUtf8() []byte
- func (src *Source) Read1() byte
- func (src *Source) ReadAll() []byte
- func (src *Source) ReadByte() (byte, error)
- func (src *Source) ReadN(n int) []byte
- func (src *Source) ReportError(err error)
- func (src *Source) ResetError()
- func (src *Source) RollbackToSavepoint()
- func (src *Source) StoreSavepoint()
Constants ¶
const DefaultPrecedence = 1
DefaultPrecedence should be used when precedence does not matter
Variables ¶
var InfoLogger = log.New(ioutil.Discard, "", 0)
InfoLogger is used to print informational message, default to off
Functions ¶
Types ¶
type InfixToken ¶
type InfixToken interface {
InfixParse(src *Source, left interface{}) interface{}
}
InfixToken parse the source at infix position
type Lexer ¶
type Lexer interface { PrefixToken(src *Source) PrefixToken InfixToken(src *Source) (InfixToken, int) }
Lexer tell the current token in the head of source
type PrefixToken ¶
type PrefixToken interface {
PrefixParse(src *Source) interface{}
}
PrefixToken parse the source at prefix position
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source is generalization of io.Reader and []byte. It supports read ahead. It supports read byte by byte. It supports read unicode code point by code point (as rune or []byte). It supports savepoint and rollback.
func NewSource ¶
NewSource construct a source from io.Reader. At least one byte should be read from the io.Reader, otherwise error will be returned.
func NewSourceString ¶
NewSourceString construct a source from string. Len should >= 1.
func (*Source) DeleteSavepoint ¶
func (src *Source) DeleteSavepoint()
DeleteSavepoint delete the lastest savepoint
func (*Source) FatalError ¶
FatalError tells if the source is in fatal error condition
func (*Source) PeekN ¶
PeekN return the first N bytes in the buffer to parse. If N is longer than current buffer, it will read from reader. The cursor will not be moved.
func (*Source) ReadByte ¶
ReadByte is the same as Read1, just for implementing the io.ByteReader interface
func (*Source) ReportError ¶
ReportError set the source in error condition.
func (*Source) RollbackToSavepoint ¶
func (src *Source) RollbackToSavepoint()
RollbackToSavepoint rollback the cursor to previous savepoint. The bytes read from reader will be replayed.
func (*Source) StoreSavepoint ¶
func (src *Source) StoreSavepoint()
StoreSavepoint mark current position, and start recording. Later we can rollback to current position. Make sure there's no error, rollback will clear the error