summaryrefslogtreecommitdiff
path: root/decode_scan.go
diff options
context:
space:
mode:
Diffstat (limited to 'decode_scan.go')
-rw-r--r--decode_scan.go71
1 files changed, 12 insertions, 59 deletions
diff --git a/decode_scan.go b/decode_scan.go
index 7911c01..fcf47ff 100644
--- a/decode_scan.go
+++ b/decode_scan.go
@@ -31,8 +31,7 @@ type runeTypeScanner struct {
// The returned error is a *ReadError, a *SyntaxError, or nil.
// An EOF condition is represented as one of:
//
-// end of value but not file: (_, >0, RuneTypeEOF, nil)
-// end of both value and file: (_, 0, RuneTypeEOF, nil)
+// end of value: (_, 0, RuneTypeEOF, nil)
// end of file in middle of value: (_, 0, RuneTypeError, &DecodeSyntaxError{Offset: offset: Err: io.ErrUnexepctedEOF})
// end of file at start of value: (_, 0, RuneTypeError, &DecodeSyntaxError{Offset: offset: Err: io.EOF})
func (sc *runeTypeScanner) ReadRuneType() (rune, int, jsonparse.RuneType, error) {
@@ -59,8 +58,14 @@ func (sc *runeTypeScanner) ReadRuneType() (rune, int, jsonparse.RuneType, error)
} else {
sc.rErr = nil
}
- if sc.rType == jsonparse.RuneTypeSpace {
+ switch sc.rType {
+ case jsonparse.RuneTypeSpace:
goto again
+ case jsonparse.RuneTypeEOF:
+ sc.offset -= int64(sc.rSize)
+ sc.rRune = 0
+ sc.rSize = 0
+ _ = sc.inner.UnreadRune()
}
case io.EOF:
sc.rType, err = sc.parser.HandleEOF()
@@ -122,65 +127,13 @@ func (sc *runeTypeScanner) PopReadBarrier() {
} else {
sc.rErr = nil
}
- case sc.rType == jsonparse.RuneTypeEOF && sc.rSize > 0:
- // re-figure the rType and rErr
- var err error
- sc.rType, err = sc.parser.HandleRune(sc.rRune)
- if err != nil {
- sc.rErr = &DecodeSyntaxError{
- Offset: sc.offset - int64(sc.rSize),
- Err: err,
- }
- } else {
- sc.rErr = nil
- }
- // tell it to use that rType and rErr
- _ = sc.UnreadRune() // we set it up to always succeed
- case sc.rType == jsonparse.RuneTypeEOF:
- // re-figure the rType and rErr
- var err error
- sc.rType, err = sc.parser.HandleEOF()
- if err != nil {
- sc.rErr = &DecodeSyntaxError{
- Offset: sc.offset,
- Err: err,
- }
- } else {
- sc.rErr = nil
- }
+ case sc.rTypeOK && sc.rType == jsonparse.RuneTypeEOF:
+ sc.rTypeOK = false // forget the sticky EOF
}
}
func (sc *runeTypeScanner) Reset() {
sc.parser.Reset()
- switch {
- case sc.repeat:
- // re-figure the rType and rErr
- var err error
- sc.rType, err = sc.parser.HandleRune(sc.rRune)
- if err != nil {
- sc.rErr = &DecodeSyntaxError{
- Offset: sc.offset - int64(sc.rSize),
- Err: err,
- }
- } else {
- sc.rErr = nil
- }
- case sc.rType == jsonparse.RuneTypeEOF && sc.rSize > 0:
- // re-figure the rType and rErr
- var err error
- sc.rType, err = sc.parser.HandleRune(sc.rRune)
- if err != nil {
- sc.rErr = &DecodeSyntaxError{
- Offset: sc.offset - int64(sc.rSize),
- Err: err,
- }
- } else {
- sc.rErr = nil
- }
- // tell it to use that rType and rErr
- _ = sc.UnreadRune() // we set it up to always succeed
- default:
- sc.rTypeOK = false
- }
+ sc.rTypeOK = false // forget any sticky errors/EOF
+ sc.repeat = false // feed the rune (if any) through the parser again
}