Documentation ¶
Index ¶
- Constants
- Variables
- type Cursor
- func (c *Cursor) FindMatch(token *Token) *TokenMatch
- func (c *Cursor) HasMore() bool
- func (c *Cursor) MatchAfterOptional(optional *Token, candidates ...*Token) *TokenMatch
- func (c *Cursor) MatchAny(candidates ...*Token) *TokenMatch
- func (c *Cursor) MatchOne(token *Token) *TokenMatch
- func (c *Cursor) NewError(expectedTokens ...*Token) error
- func (c *Cursor) TokenMatch(token *Token, matchSize int) *TokenMatch
- type Matcher
- type Token
- type TokenMatch
- func (m *TokenMatch) Bool(cursor *Cursor) (bool, error)
- func (m *TokenMatch) Byte(cursor *Cursor) byte
- func (m *TokenMatch) Bytes(cursor *Cursor) []byte
- func (m *TokenMatch) ContainsRune(cursor *Cursor, r rune) bool
- func (m *TokenMatch) Float(cursor *Cursor) (float64, error)
- func (m *TokenMatch) Int(cursor *Cursor) (int64, error)
- func (m *TokenMatch) SetToken(token *Token, cursor int, size int)
- func (m *TokenMatch) Text(cursor *Cursor) string
- func (m *TokenMatch) UnquotedText(cursor *Cursor) string
Constants ¶
const ( //EOF end of file token EOF = -1 //Invalid invalid token Invalid = -2 )
Variables ¶
var AsString = func(data []byte) string { return string(data) }
AsString converts bytes to string
var AsZeroAllocString = func(data []byte) string { return string(data) }
AsZeroAllocString converts bytes to string, In this package I do not any unsafe dependency But if you need zero allocation override AsZeroAllocString = usage.ByteSlice2String
var EOFToken = NewToken(EOF, "EOF", nil)
EOFToken
var InvalidToken = NewToken(Invalid, "Invalid", nil)
InvalidToken represents invalid token
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
type Cursor struct { Path string Input []byte InputSize int Pos int OnError func(err error, cur *Cursor, destNode interface{}) error // contains filtered or unexported fields }
Cursor represents a location
func (*Cursor) FindMatch ¶
func (c *Cursor) FindMatch(token *Token) *TokenMatch
FindMatch tries to find a token match in the cursor
func (*Cursor) MatchAfterOptional ¶
func (c *Cursor) MatchAfterOptional(optional *Token, candidates ...*Token) *TokenMatch
MatchAfterOptional matcher first candidate after optional token lastMatch
func (*Cursor) MatchAny ¶
func (c *Cursor) MatchAny(candidates ...*Token) *TokenMatch
MatchAny matches the first of the candidates
func (*Cursor) MatchOne ¶
func (c *Cursor) MatchOne(token *Token) *TokenMatch
MatchOne tries to lastMatch a candidate, it returns a lastMatch.
func (*Cursor) TokenMatch ¶
func (c *Cursor) TokenMatch(token *Token, matchSize int) *TokenMatch
TokenMatch returns updated lastMatch
type Matcher ¶
type Matcher interface { //TokenMatch matches input starting from offset, it return number of characters matched Match(cursor *Cursor) (matched int) }
Matcher represents a matcher, that matches input from offset position, it returns number of bytes matched.
type TokenMatch ¶
TokenMatch represents a token match
func (*TokenMatch) Bool ¶
func (m *TokenMatch) Bool(cursor *Cursor) (bool, error)
Bool return matched bool value
func (*TokenMatch) Bytes ¶
func (m *TokenMatch) Bytes(cursor *Cursor) []byte
Matched return matched fragment
func (*TokenMatch) ContainsRune ¶
func (m *TokenMatch) ContainsRune(cursor *Cursor, r rune) bool
Contains return true if lastMatch data contains rune
func (*TokenMatch) Float ¶
func (m *TokenMatch) Float(cursor *Cursor) (float64, error)
Float return matched float value
func (*TokenMatch) Int ¶
func (m *TokenMatch) Int(cursor *Cursor) (int64, error)
Int return matched int value
func (*TokenMatch) SetToken ¶
func (m *TokenMatch) SetToken(token *Token, cursor int, size int)
SetToken sets token
func (*TokenMatch) Text ¶
func (m *TokenMatch) Text(cursor *Cursor) string
Matched return matched fragment
func (*TokenMatch) UnquotedText ¶
func (m *TokenMatch) UnquotedText(cursor *Cursor) string
MatchedUnquoted return matched unquoted fragment