Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make children of match_statement a case_block #148

Closed
wants to merge 2 commits into from

Conversation

theHamsta
Copy link
Contributor

@theHamsta theHamsta commented Jan 28, 2022

@dcreager the children of all other indent blocks use the block node. It would be more consistent when match_statement would use the same or should there be a new name for the alternatives?

This would be more consistent for the use in queries: https://github.com/nvim-treesitter/nvim-treesitter/pull/2389/files

@dcreager
Copy link
Contributor

That's a great catch! I do think it makes sense to use the same name here. You can always use (match_statement (block)) as your query if you only want to pull put blocks from a match statement and not from any other statement type.

@dcreager
Copy link
Contributor

Hmm, actually now I think I reconsider — the arms of a match aren't a list of statements, so this would break the invariant that the contents of a block are the same "kind" of CST, no matter where it appears. Am I getting that right? If so, I think it makes sense for the child of case to be block, but to choose something else for the children of match. Your resulting folding query would end up as:

(match_statement (case_clause) @fold)
(case_clause (block) @fold)

That's not "consistent" in the sense of every fold being a block — but I think it's also accurate to say that not every fold in Python is a block, right?

@maxbrunsfeld
Copy link
Contributor

Maybe call the indented part something different, like a match_block?

@dcreager
Copy link
Contributor

dcreager commented Jan 28, 2022

It's called case_block in the language spec.

Also, it looks like it was too permissive to lump the pattern nonterminals in with the expression nonterminals. That causes the following to be accepted by the parser, even though it's invalid Python:

x as y

@dcreager
Copy link
Contributor

Also, it looks like it was too permissive to lump the pattern nonterminals in with the expression nonterminals. That causes the following to be accepted by the parser, even though it's invalid Python:

(To clarify, this was not meant to suggest that separating expressions and patterns should be part of this PR!)

@theHamsta theHamsta changed the title chore: make children of match_statement a block chore: make children of match_statement a case_block Jan 28, 2022
@theHamsta theHamsta force-pushed the match-block branch 3 times, most recently from d8521fa to 73986e4 Compare February 8, 2022 23:11
@amaanq
Copy link
Member

amaanq commented Jul 11, 2023

Can you rebase @theHamsta

@theHamsta
Copy link
Contributor Author

theHamsta commented Aug 4, 2023

@amaanq upstream has updated to expose $._match_block as $.block. This was the original intention of this PR. In the official Python grammar, this special case of block is called a $.case_block. Should the alias be removed and $._match_block be exposed as $.case_block or just keep the more generic $.block which many queries are using.

For me personally, closing would be fine.

amaanq and others added 2 commits August 4, 2023 12:57
This change is to follow the naming of the official Python grammar.
@theHamsta
Copy link
Contributor Author

The unnecessary conflict can still be removed.

@theHamsta theHamsta closed this Aug 4, 2023
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.

4 participants