Skip to content

fix: match a line continuation at the end of input in the scanner - #363

Open
WillLillis wants to merge 6 commits into
masterfrom
fix_eof
Open

WillLillis wants to merge 6 commits into
masterfrom
fix_eof

Conversation

@WillLillis

Copy link
Copy Markdown
Member

The '\0' alternative in line_continuation matched the end of input
in some lex states and not others, so a trailing \ was a line
continuation in some places and an error in others. CPython rejects a
line continuation at the end of a file, so this drops the alternative.


This update is being done to account for tree-sitter/tree-sitter#6146.

The `'\0'` alternative in `line_continuation` matched the end of input
in some lex states and not others, so a trailing `\` was a line
continuation in some places and an error in others. `eof()` cannot
replace it, because an extra cannot end with `eof()`.

The external scanner already reads a `\` before the end of input while
it looks for the end of a line. List `line_continuation` as an external
token, so that the scanner returns it there, after any indent, dedent or
new line. The token itself now always ends with a new line.
`_simple_statement` and `_compound_statement` have been inlined since
before the grammar had supertypes, so the parser never had either
symbol to report as one.
The Node binding test requires tree-sitter, but it was only an optional
peer dependency, which npm does not install.
@WillLillis WillLillis changed the title fix: require a newline after a line continuation fix: match a line continuation at the end of input in the scanner Dec 2, 2026
@wetneb

wetneb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for all those fixes on grammars, @WillLillis :)
As you can see this one hasn't been actively maintained for a while now. I have integrated your contribution in our fork tree-sitter-python-orchard, as I try to do for all good PRs I notice on this repo.

I think it should be possible for downstream grammars (starlark, snakemake) to switch to our version of the Python grammar, but I'd be happy to look into adapting our publishing workflow if that's not the case.

This branch has not been deployed

No deployments
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.

3 participants