Skip to content

Conversation

@zharinov
Copy link
Member

@zharinov zharinov commented Jan 4, 2026

Summary

Adds suppressive captures (@_ and @_name syntax) for matching patterns structurally without contributing to output.

Changes

  • Parser: New SuppressiveCapture token (@_[a-zA-Z0-9_]*) with is_suppressive() AST method
  • Type inference: Suppressive captures return TypeFlow::Void (no fields created)
  • Bytecode: SuppressBegin/SuppressEnd opcodes bracket suppressed regions
  • VM: suppress_depth counter skips effect emission when > 0, restored on backtrack
  • Trace: Shows for entering/exiting suppression, for suppressed effects

Example

Func = (function_declaration
  name: (identifier) @name
  parameters: (formal_parameters) @_   ; match but don't capture
  body: (statement_block) @body)

Output only includes name and body, not the parameters.

Testing

  • 5 new engine tests covering nested, sibling, and definition-call scenarios
  • 6 new lexer tests for token recognition
  • All 722 tests pass

Suppressive captures match structurally but don't contribute to output.

Syntax:
- @_ : anonymous suppressive (bare underscore)
- @_name : named suppressive (underscore prefix)

Implementation:
- Lexer: SuppressiveCapture token (@_[a-zA-Z0-9_]*)
- Parser: handled in try_parse_capture()
- Compiler: SuppressBegin/SuppressEnd effects bracket inner
- VM: depth counter skips effects when depth > 0
- Trace: diamond symbols for suppressed effects

Also unifies capture token lexing:
- Regular captures (@name) now single CaptureToken (was At + Id)
- Symmetric with SuppressiveCapture
- Simplifies parser, call sites strip @ with [1..]
@zharinov zharinov force-pushed the feat/suppressive-captures branch from 448a728 to 51c38e7 Compare January 4, 2026 11:55
@zharinov zharinov changed the title feat: add suppressive captures (@_ syntax) feat: add suppressive captures (@_ syntax) Jan 4, 2026
@zharinov zharinov merged commit a9e7521 into master Jan 4, 2026
4 checks passed
@zharinov zharinov deleted the feat/suppressive-captures branch January 4, 2026 11:58
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