Skip to content

Conversation

dvmarcilio
Copy link

Exposing statement_list productions so we can match child nodes of a block in a single capture without using quantifiers.

In Polyglot Piranha, we have the remove_unnecessary_nested_block which needs to match the contents of a block in a single multi-line capture.
This is made possible by capturing (statement_list) @nested.statements in the query below.
Polyglot Piranha then replaces @nested.block with @nested.statements.

(
    (block
        (statement_list
            (((_) "\\n"?)* @pre)
            ((block
                (statement_list) @nested.statements
            ) @nested.block)
            (((_) "\\n"?)* @post)
        ) @outer.stmt_list
    ) @outer.block
)

Checklist:

  • All tests pass in CI.
  • There are sufficient tests for the new fix/feature.
  • Grammar rules have not been renamed unless absolutely necessary.
  • The conflicts section hasn't grown too much.
  • The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).

@dvmarcilio dvmarcilio force-pushed the expose_statement_list branch from f2b5f28 to 8f80719 Compare December 19, 2022 12:00
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