summaryrefslogtreecommitdiff
path: root/internal/jsonparse/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/jsonparse/parse.go')
-rw-r--r--internal/jsonparse/parse.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/jsonparse/parse.go b/internal/jsonparse/parse.go
index 1c35533..6432d75 100644
--- a/internal/jsonparse/parse.go
+++ b/internal/jsonparse/parse.go
@@ -525,6 +525,21 @@ func (par *Parser) HandleEOF() (RuneType, error) {
}
}
+// IsAtBarrier returns whether a read-barrier has been reached and the
+// next HandleRune call would definitely return RuneTypeEOF.
+func (par *Parser) IsAtBarrier() bool {
+ return par.initialized &&
+ // HandleRune wouldn't return early with an error.
+ !par.closed &&
+ par.err == nil &&
+ // The current (sub-)parser has reached its end, and
+ len(par.stack) == 0 &&
+ // there is a barrier, and
+ len(par.barriers) > 0 &&
+ // that barrier would definitely return RuneTypeEOF.
+ !par.barriers[len(par.barriers)-1].allowWS
+}
+
// HandleRune feeds a Unicode rune to the Parser.
//
// An error is returned if and only if the RuneType is RuneTypeError.