Simplify parser#10
Merged
aaronkison merged 2 commits intomasterfrom Feb 4, 2025
Merged
Conversation
41b9ecf to
4adc120
Compare
4adc120 to
7ff3dc5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I found the existing implementation to be too difficult to understand and reason. Hopefully this takes a giant leap into making it more sensible.
This was motivated by me initially seeing a potential problem, that is if the parser skips all empty chunks then it'll never trigger the
is_last_recordand potentially try to read off the edge of the stream. After rewriting it, it makes more sense as it just detects if the stream ended early (complete chunks end with a RS, and.split(RS, -1)adds a''at the end of the records to ensure it misses that condition. It's structurally backwards, but functions correctly.Essentially, it performs in two modes:
RSit treats it as a complete recordRSafter it, it first checks if its valid json. If its valid json, it returns it, otherwise it stores it in a buffer and waits for the next parse to add it to the buffer and continueI decided to make those modes more explicit in the logic. As the modes only apply to the last record in the list, we first process all the records normally first and only treat the final one specially.