fix: correct #line directives in compiled templates#349
Draft
Koan-Bot wants to merge 1 commit into
Draft
Conversation
) Compound directives (IF, FOREACH, WHILE, SWITCH, TRY, WRAPPER, FILTER, VIEW, PERL) reported the END tag's line number instead of the opening keyword's line in compiled template cache files. The fix captures location() in a mid-rule grammar action (after the opening keyword's semicolon, before the block body) and prepends it to the directive's compiled output. The chunk rule skips its own location() call when the statement already carries a #line directive, avoiding duplicates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
@Koan-Bot rebase |
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.
What
Compiled templates now emit correct
#linedirectives for compound directives (IF, FOREACH, WHILE, SWITCH, TRY, WRAPPER, FILTER, VIEW, PERL).Why
Fixes GH #306. When Template Toolkit compiles templates to Perl code, compound directives reported the
ENDtag's line number instead of the opening keyword's line. For example,[% IF x == y %]on line 3 with[% END %]on line 5 would generate#line 5instead of#line 3. This made error messages and debugging point to the wrong line.How
The YACC grammar's
chunkrule calledlocation()after the entire compound directive (including its block body and END tag) was fully reduced — by which point the parser's line counter had advanced to the END line.The fix adds a mid-rule grammar action after each compound directive's opening semicolon (before the block body is parsed) that captures
location()while the line counter still points to the opening keyword. This captured#linestring is prepended to the directive's compiled output. Thechunkrule now checks if the statement already carries a#lineprefix and skips its ownlocation()call in that case.Testing
t/compile-line-numbers.twith 8 tests covering IF, FOREACH, WHILE, and nested IFCloses #306
🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 4469 insertions(+), 4256 deletions(-)
Code scan: 1 issue(s) found
lib/Template/Grammar.pm:0— 4316 lines addedTests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline