Documentation ¶
Overview ¶
Package jlexer contains a JSON lexer implementation.
It is expected that it is mostly used with generated parser code, so the interface is tuned for a parser that knows what kind of data is expected.
Index ¶
- type Lexer
- func (r *Lexer) AddError(e error)
- func (r *Lexer) AddNonFatalError(e error)
- func (r *Lexer) Bool() bool
- func (r *Lexer) Bytes() []byte
- func (r *Lexer) Consumed()
- func (r *Lexer) Delim(c byte)
- func (r *Lexer) Error() error
- func (r *Lexer) FetchToken()
- func (r *Lexer) Float32() float32
- func (r *Lexer) Float64() float64
- func (r *Lexer) GetNonFatalErrors() []*LexerError
- func (r *Lexer) GetPos() int
- func (r *Lexer) Int() int
- func (r *Lexer) Int16() int16
- func (r *Lexer) Int16Str() int16
- func (r *Lexer) Int32() int32
- func (r *Lexer) Int32Str() int32
- func (r *Lexer) Int64() int64
- func (r *Lexer) Int64Str() int64
- func (r *Lexer) Int8() int8
- func (r *Lexer) Int8Str() int8
- func (r *Lexer) IntStr() int
- func (r *Lexer) Interface() interface{}
- func (r *Lexer) IsDelim(c byte) bool
- func (r *Lexer) IsNull() bool
- func (r *Lexer) IsStart() bool
- func (r *Lexer) Null()
- func (r *Lexer) Ok() bool
- func (r *Lexer) Raw() []byte
- func (r *Lexer) Skip()
- func (r *Lexer) SkipRecursive()
- func (r *Lexer) String() string
- func (r *Lexer) Uint() uint
- func (r *Lexer) Uint16() uint16
- func (r *Lexer) Uint16Str() uint16
- func (r *Lexer) Uint32() uint32
- func (r *Lexer) Uint32Str() uint32
- func (r *Lexer) Uint64() uint64
- func (r *Lexer) Uint64Str() uint64
- func (r *Lexer) Uint8() uint8
- func (r *Lexer) Uint8Str() uint8
- func (r *Lexer) UintStr() uint
- func (r *Lexer) UnsafeBytes() []byte
- func (r *Lexer) UnsafeString() string
- func (r *Lexer) WantColon()
- func (r *Lexer) WantComma()
- type LexerError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lexer ¶
type Lexer struct { Data []byte // Input data given to the lexer. UseMultipleErrors bool // If we want to use multiple errors. // contains filtered or unexported fields }
Lexer is a JSON lexer: it iterates over JSON tokens in a byte slice.
func (*Lexer) AddNonFatalError ¶
func (*Lexer) Consumed ¶
func (r *Lexer) Consumed()
Consumed reads all remaining bytes from the input, publishing an error if there is anything but whitespace remaining.
func (*Lexer) FetchToken ¶
func (r *Lexer) FetchToken()
FetchToken scans the input for the next token.
func (*Lexer) GetNonFatalErrors ¶
func (r *Lexer) GetNonFatalErrors() []*LexerError
func (*Lexer) Interface ¶
func (r *Lexer) Interface() interface{}
Interface fetches an interface{} analogous to the 'encoding/json' package.
func (*Lexer) IsDelim ¶
IsDelim returns true if there was no scanning error and next token is the given delimiter.
func (*Lexer) IsStart ¶
IsStart returns whether the lexer is positioned at the start of an input string.
func (*Lexer) Null ¶
func (r *Lexer) Null()
Null verifies that the next token is null and consumes it.
func (*Lexer) SkipRecursive ¶
func (r *Lexer) SkipRecursive()
SkipRecursive skips next array or object completely, or just skips a single token if not an array/object.
Note: no syntax validation is performed on the skipped data.
func (*Lexer) UnsafeBytes ¶
UnsafeBytes returns the byte slice if the token is a string literal.
func (*Lexer) UnsafeString ¶
UnsafeString returns the string value if the token is a string literal.
Warning: returned string may point to the input buffer, so the string should not outlive the input buffer. Intended pattern of usage is as an argument to a switch statement.
type LexerError ¶
LexerError implements the error interface and represents all possible errors that can be generated during parsing the JSON data.
func (*LexerError) Error ¶
func (l *LexerError) Error() string