From ffee5c8516f3f55f82ed5bb8f0a4f340d485fa92 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 25 Jan 2023 21:05:17 -0700 Subject: Write documentation --- internal/parse.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'internal/parse.go') diff --git a/internal/parse.go b/internal/parse.go index 12d7600..895c930 100644 --- a/internal/parse.go +++ b/internal/parse.go @@ -14,10 +14,13 @@ import ( var ErrParserExceededMaxDepth = errors.New("exceeded max depth") +// 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. type RuneType uint8 const ( - RuneTypeError = RuneType(iota) + RuneTypeError RuneType = iota RuneTypeSpace // whitespace @@ -42,7 +45,7 @@ const ( RuneTypeStringEnd // closing '"' RuneTypeNumberIntNeg - RuneTypeNumberIntZero + RuneTypeNumberIntZero // leading zero only; non-leading zeros are IntDig, not IntZero RuneTypeNumberIntDig RuneTypeNumberFracDot RuneTypeNumberFracDig @@ -69,6 +72,7 @@ const ( RuneTypeEOF ) +// GoString implements fmt.GoStringer. func (t RuneType) GoString() string { str, ok := map[RuneType]string{ RuneTypeError: "RuneTypeError", @@ -128,6 +132,7 @@ func (t RuneType) GoString() string { return fmt.Sprintf("RuneType(%d)", t) } +// String implements fmt.Stringer. func (t RuneType) String() string { str, ok := map[RuneType]string{ RuneTypeError: "x", @@ -202,10 +207,14 @@ func (t RuneType) JSONType() string { }[t] } +// IsNumber returns whether the RuneType is one of the +// RuneTypeNumberXXX values. func (t RuneType) IsNumber() bool { return RuneTypeNumberIntNeg <= t && t <= RuneTypeNumberExpDig } +// Parser is the low-level JSON parser that powers both *Decoder and +// *ReEncoder. type Parser struct { // Setting MaxError to a value greater than 0 causes // HandleRune to return ErrParserExceededMaxDepth if -- cgit v1.2.3-54-g00ecf