parser: drain all leftover buffers between blocks#383
Merged
priv-kweihmann merged 1 commit intoJun 13, 2026
Conversation
A comment or 'def' block peeks the line that terminates it and returns
it as a leftover buffer for the main loop to re-process. When that
leftover is itself a comment/'def' block, re-processing produces a
second leftover -- but the loop only drained one level ('if nextbuf:'),
so the second leftover was glued onto the next raw line instead.
In practice this misparsed an 'addhandler' line followed by its
'python ...() {}' event handler when the handler was preceded by two or
more 'def' helper blocks: the handler merged with the 'addhandler' line
and its body spilled out as loose Items instead of a single Function.
Drain the leftover buffer fully ('while nextbuf:'). Adds a regression
test covering a handler that follows two 'def' helper blocks.
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Owner
|
Thx for this fix - and yeah feel free to do cleanup changes at any time |
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.
A comment or
defblock peeks the line that terminates it and returns it as aleftover buffer for the main loop to re-process. When that leftover is itself a
comment/
defblock, re-processing produces a second leftover — but the looponly drained one level (
if nextbuf:), so the second leftover was glued ontothe next raw line instead.
In practice this misparsed an
addhandlerline followed by itspython ...() {}event handler when the handler was preceded by two or moredefhelper blocks: the handler merged with theaddhandlerline and its bodyspilled out as loose
Items instead of a singleFunction.Drain the leftover buffer fully (
while nextbuf:). Adds a regression testcovering a handler that follows two
defhelper blocks; the full suite (178tests) passes.
Note: with this change the
line = nextbuf + lineglue in the same loop is nowalways a no-op (the buffer is fully drained before the next raw line is read).
I left it in place to keep this fix minimal, but it could be removed in a
follow-up cleanup if you prefer.