summaryrefslogtreecommitdiff
path: root/internal/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/parse.go')
-rw-r--r--internal/parse.go13
1 files changed, 11 insertions, 2 deletions
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