Documentation ¶
Index ¶
- Variables
- type InvalidCharacterError
- type Parser
- func (par *Parser) HandleEOF() (RuneType, error)
- func (par *Parser) HandleRune(c rune, isRune bool) (RuneType, error)
- func (par *Parser) IsAtBarrier() bool
- func (par *Parser) PopBarrier()
- func (par *Parser) PushReadBarrier()
- func (par *Parser) PushWriteBarrier()
- func (par *Parser) Reset()
- func (par *Parser) StackIsEmpty() bool
- func (par *Parser) StackSize() int
- type RuneType
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type InvalidCharacterError ¶ added in v0.3.8
func (*InvalidCharacterError) Error ¶ added in v0.3.8
func (e *InvalidCharacterError) Error() string
type Parser ¶
type Parser struct { // Setting MaxError to a value greater than 0 causes // HandleRune to return ErrParserExceededMaxDepth if // objects/arrays become nested more deeply than this. MaxDepth int // contains filtered or unexported fields }
Parser is the low-level JSON parser that powers both *Decoder and *ReEncoder.
func (*Parser) HandleEOF ¶
HandleEOF feeds EOF to the Parser. The returned RuneType is either RuneTypeEOF or RuneTypeError.
An error is returned if and only if the RuneType is RuneTypeError. Returns io/fs.ErrClosed if .HandleEOF() has previously been called (and .Reset() has not been called since).
Once RuneTypeError or RuneTypeEOF has been returned, it will keep being returned from both .HandleRune(c) and .HandleEOF() until .Reset() is called.
RuneTypeEOF indicates that a complete JSON document has been read.
func (*Parser) HandleRune ¶
HandleRune feeds a Unicode rune to the Parser.
An error is returned if and only if the RuneType is RuneTypeError. Returns io/fs.ErrClosed if .HandleEOF() has previously been called (and .Reset() has not been called since).
Once RuneTypeError or RuneTypeEOF has been returned, it will keep being returned from both .HandleRune(c) and .HandleEOF() until .Reset() is called.
RuneTypeEOF indicates that the rune cannot be appended to the JSON document; a new JSON document must be started in order to process that rune.
func (*Parser) IsAtBarrier ¶ added in v0.3.7
IsAtBarrier returns whether a read-barrier has been reached and the next HandleRune call would definitely return RuneTypeEOF.
func (*Parser) PopBarrier ¶
func (par *Parser) PopBarrier()
PopBarrier reverses a call to PushReadBarrier or PushWriteBarrier.
func (*Parser) PushReadBarrier ¶
func (par *Parser) PushReadBarrier()
PushReadBarrier causes the parser to emit EOF once the end of the element that is started by the current top-of-stack is reached (which means that it will reject whitespace between the end of the element and EOF), until this is un-done with PopBarrier. It essentially turns the parser in to a sub-parser.
PushReadBarrier may only be called at the beginning of an element, whether that be
- runeTypeAny
- RuneTypeObjectBeg
- RuneTypeArrayBeg
- RuneTypeStringBeg
- RuneTypeNumberIntNeg, RuneTypeNumberIntZero, RuneTypeNumberIntDig
- RuneTypeTrueT
- RuneTypeFalseF
- RuneTypeNullN
func (*Parser) PushWriteBarrier ¶
func (par *Parser) PushWriteBarrier()
PushWriteBarrier causes the parser to emit EOF once the end of the about-to-start element is reached and any trailing whitespace has been exhausted, until this is un-done with PopBarrier. It essentially turns the parser in to a sub-parser.
PushWriteBarrier may only be called at the places where an element of any type may start:
- runeTypeAny for top-level and object-value elements
- RuneTypeArrayBeg for array-item elements
PushWriteBarrier signals intent to write an element; if it is called in a place where an element is optional (at the beginning of an array), it becomes a syntax error to not write the element.
type RuneType ¶
type RuneType uint8
RuneType is the classification of a rune when parsing JSON input. A Parser, rather than grouping runes into tokens and classifying tokens, classifies runes directly.
const ( RuneTypeError RuneType = iota RuneTypeSpace // whitespace RuneTypeObjectBeg // '{' RuneTypeObjectColon // ':' RuneTypeObjectComma // ',' RuneTypeObjectEnd // '}' RuneTypeArrayBeg // '[' RuneTypeArrayComma // ',' RuneTypeArrayEnd // ']' RuneTypeStringBeg // opening '"' RuneTypeStringChar // normal character RuneTypeStringEsc // backslash RuneTypeStringEsc1 // single-char after a backslash RuneTypeStringEscU // \uABCD : u RuneTypeStringEscUA // \uABCD : A RuneTypeStringEscUB // \uABCD : B RuneTypeStringEscUC // \uABCD : C RuneTypeStringEscUD // \uABCD : D RuneTypeStringEnd // closing '"' RuneTypeNumberIntNeg RuneTypeNumberIntZero // leading zero only; non-leading zeros are IntDig, not IntZero RuneTypeNumberIntDig RuneTypeNumberFracDot RuneTypeNumberFracDig RuneTypeNumberExpE RuneTypeNumberExpSign RuneTypeNumberExpDig RuneTypeTrueT RuneTypeTrueR RuneTypeTrueU RuneTypeTrueE RuneTypeFalseF RuneTypeFalseA RuneTypeFalseL RuneTypeFalseS RuneTypeFalseE RuneTypeNullN RuneTypeNullU RuneTypeNullL1 RuneTypeNullL2 RuneTypeEOF )
func (RuneType) IsNumber ¶
IsNumber returns whether the RuneType is one of the RuneTypeNumberXXX values.