Skip to content

Commit

Permalink
allow visitor to visit primitives at the root level
Browse files Browse the repository at this point in the history
  • Loading branch information
daggaz committed Jan 19, 2025
1 parent cbc9111 commit 27f0614
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/json_stream/visitor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from json_stream.base import StreamingJSONObject, StreamingJSONList, StreamingJSONBase
from json_stream.iterators import ensure_file
from json_stream.select_tokenizer import default_tokenizer
from json_stream.tokenizer import TokenType


def _visit(obj, visitor, path):
Expand All @@ -22,6 +23,9 @@ def _visit(obj, visitor, path):
def visit(fp_or_iterator, visitor, tokenizer=default_tokenizer):
fp = ensure_file(fp_or_iterator)
token_stream = tokenizer(fp)
_, token = next(token_stream)
obj = StreamingJSONBase.factory(token, token_stream, persistent=False)
token_type, token = next(token_stream)
if token_type == TokenType.OPERATOR:
obj = StreamingJSONBase.factory(token, token_stream, persistent=False)
else:
obj = token
_visit(obj, visitor, ())

0 comments on commit 27f0614

Please sign in to comment.