Skip to content

WIP: Attribute system improvements + \K regex fix#423

Merged
fglock merged 4 commits intomasterfrom
feature/attribute-improvements
Apr 2, 2026
Merged

WIP: Attribute system improvements + \K regex fix#423
fglock merged 4 commits intomasterfrom
feature/attribute-improvements

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 2, 2026

Summary

Continuation of attribute system work from PR #420. This PR focuses on:

\K Regex Assertion Fix

  • Implements the \K (keep left) assertion in s/// and m// operators
  • Previously \K was silently stripped from patterns, causing incorrect substitution
  • \K now correctly preserves text before the assertion point during replacement
  • Properly adjusts $&, \``, @-, @+` for \K-affected matches
  • Skips the internal perlK capture group when populating $1, $2, etc.

Attribute Validation Restored

  • With \K fixed, handler names in decl-refs.t are no longer corrupted
  • Re-added compile-time 'Invalid attribute' error for our variables without handler
  • Re-added runtime 'Invalid attribute' error for my/state variables without handler

Test Improvements (+27 tests)

Test Before After Delta
op/attrs.t 148/159 156/159 +8
uni/attrs.t 30/35 33/35 +3
op/decl-refs.t 330/408 346/408 +16

All other attribute tests unchanged. make passes.

Next Steps (from dev/design/attributes.md)

  • Phase 3: Fix my var attribute ref identity (4 tests)
  • Phase 4: my sub attribute parsing (4 tests)
  • Phase 5: :const attribute (2 tests)
  • Phase 6: Error message improvements (7 tests)

Test plan

  • make passes (all unit tests)
  • Attribute test suite: no regressions, +27 improvements
  • Regex tests (pat.t, pat_advanced.t, regexp.t, subst.t): no regressions

Generated with Devin

fglock and others added 4 commits April 2, 2026 18:13
Implement \K (keep left) assertion in s/// and m// operators.
Previously \K was silently stripped from patterns, causing incorrect
substitution behavior. Now \K correctly preserves text before the
assertion point during replacement.

Implementation:
- RegexPreprocessorHelper: Convert \K to named capture group that marks
  the keep position
- RuntimeRegex: In substitution, replace only from \K position to match
  end instead of full match. In match, adjust match vars accordingly
- Propagate hasBackslashK flag through getReplacementRegex copies
- Adjust capture group numbering to skip the internal perlK group

With \K working, restore variable attribute validation:
- OperatorParser: Re-add compile-time error for our variables without
  MODIFY_*_ATTRIBUTES handler
- Attributes.java: Re-add runtime error for my/state variables without
  handler

Test improvements (+27 tests):
- attrs.t: 148->156 (+8), uni/attrs.t: 30->33 (+3)
- decl-refs.t: 330->346 (+16)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
When my ($x,$y) : attr is parsed, the 'attributes' annotation is
placed on the parent OperatorNode but was not propagated to individual
variable nodes during list expansion. This caused runtime attribute
dispatch to silently skip list variable declarations.

Fix in both backends:
- JVM emitter (EmitVariable.java): propagate parent attribute
  annotations to each child my/state node in list expansion
- Interpreter (BytecodeCompiler.java): call emitVarAttrsIfNeeded
  for each variable in list declarations

Test improvements (+4):
- attrs.t: 156->158 (only TODO test 155 remains)
- uni/attrs.t: 33->35/35 (fully passing)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Attribute test suite is now at 97.6% pass rate (248/254):
- attrs.t: 158/159 (only TODO test remains)
- uni/attrs.t: 35/35 (fully passing)
- attrproto.t: 51/52
- attrhand.t: 4/4

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit 0befda4 into master Apr 2, 2026
2 checks passed
@fglock fglock deleted the feature/attribute-improvements branch April 2, 2026 16:47
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