Skip to content

parser: drain all leftover buffers between blocks#383

Merged
priv-kweihmann merged 1 commit into
priv-kweihmann:mainfrom
otavio:parser-drain-leftover-buffers
Jun 13, 2026
Merged

parser: drain all leftover buffers between blocks#383
priv-kweihmann merged 1 commit into
priv-kweihmann:mainfrom
otavio:parser-drain-leftover-buffers

Conversation

@otavio

@otavio otavio commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

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; the full suite (178
tests) passes.

Note: with this change the line = nextbuf + line glue in the same loop is now
always 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.

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>
@priv-kweihmann priv-kweihmann merged commit 54b7357 into priv-kweihmann:main Jun 13, 2026
5 checks passed
@priv-kweihmann

Copy link
Copy Markdown
Owner

Thx for this fix - and yeah feel free to do cleanup changes at any time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants