Fix issues with queries matching a parent node with anchored children (siblings) by lucasmdjl · Pull Request #5603 · tree-sitter/tree-sitter · GitHub
Skip to content

Fix issues with queries matching a parent node with anchored children (siblings)#5603

Open
lucasmdjl wants to merge 7 commits into
tree-sitter:masterfrom
lucasmdjl:master
Open

Fix issues with queries matching a parent node with anchored children (siblings)#5603
lucasmdjl wants to merge 7 commits into
tree-sitter:masterfrom
lucasmdjl:master

Conversation

@lucasmdjl

Copy link
Copy Markdown

AI Policy

  • I have read the AI Policy and this PR complies with it.
  • If AI tools were used: I have disclosed the tool and extent of usage below.

I used claude.ai web interface for help with debugging and reasoning through debug logs, evaluating my approach and suggesting other directions to explore, and double-checking my code.

Description

This PR fixes three issues for queries that match parent node with anchored children (siblings).

The first issue was that the check for fallible steps was only considering nodes with children, which resulted in no state split being made for anchored siblings (node1) . (node2). This prevented the query from matching beyond the first occurrence. The fix was to also consider the case where the next step is at the same depth and must be matched immediately after.

The second issue was that with this type of queries where in addition the first anchored sibling had a quantifier, the deduplication logic for states was being overly aggressive, causing the state split on the first capture (with the parent) to be dropped in favor of the loopback state. This resulted in not being able to match beyond the first occurrence. The fix was to prevent the deduplication logic to drop a state that is not seeking for an immediate match for one that is seeking for an immediate match, because the one that is not seeking for an immediate match still could match later nodes.

The third issue was that with this type of queries where in addition the first anchored sibling had a quantifier and wasn't captured, the check for fallible steps was skipping splitting the state, because the next node was a passthrough node (and not an is_immediate one like in the first issue). This again prevented the query from matching beyond the first occurrence. The fix was to skip the next steps in the check for fallibility while they are passthrough steps.

The third fix would close issue #4688 .

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.

1 participant