fix: parse hashref after any operator as Constructor (GH #34) - #433
Draft
toddr-bot wants to merge 2 commits into
Draft
fix: parse hashref after any operator as Constructor (GH #34)#433toddr-bot wants to merge 2 commits into
toddr-bot wants to merge 2 commits into
Conversation
Operators like 'or', 'and', 'not', '-', '==', 'ne', '..', '+=' should
produce PPI::Structure::Constructor when followed by {}, not Block.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After any PPI::Token::Operator, a { } can only be a hash constructor
(anonymous hashref), never a code block. Previously only a handful of
operators were listed in %CURLY_CLASSES; all others fell through to the
catch-all that returned Block.
Add a type-based check: if the last significant element before { is a
PPI::Token::Operator (and -> was already handled as Subscript), return
PPI::Structure::Constructor. This covers all current and future operators
without maintaining an exhaustive list.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After any operator (e.g.
or,and,-,==,+=,..),{ }can only be an anonymous hashref (Constructor), never a code block. Previously PPI only recognized a handful of operators in%CURLY_CLASSES; all others fell through to a catch-all that returned Block.Added a type-based check in
_curly(): if the last significant element before{is aPPI::Token::Operator(and->was already handled as Subscript), returnPPI::Structure::Constructor. This covers all current and future operators without maintaining an exhaustive list.Fixes #34
Changes
Lexer.pm_curly()method after the%CURLY_CLASSESlookupppi_token_unknown.tfor hashctors after operators (Block → Constructor)"hash constructors are currently mistaken for blocks"TODO08_regression.tcoveringor,and,not,-,==,ne,..,+=Test plan
0 || {b => 1, a => 1};parses as Constructor$foo->{bar},$foo{bar},@foo{bar}) are unaffected+ *{$args}) correctly remain BlockGenerated by Kōan /fix
Quality Report
Changes: 3 files changed, 69 insertions(+), 35 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline