Skip to content

fix: only end a PHP heredoc where its label starts a line - #243

Merged
brendt merged 1 commit into
tempestphp:mainfrom
sulimanbenhalim:fix/heredoc-closing-label
Oct 26, 2026
Merged

brendt merged 1 commit into
tempestphp:mainfrom
sulimanbenhalim:fix/heredoc-closing-label

Conversation

@sulimanbenhalim

Copy link
Copy Markdown

a heredoc ends at the first spot its label is followed by whitespace or ; or ) even mid-line so in

$query = <<<SQL
    SELECT * FROM Book -- runs on MySQL and SQLite
    SQL;

the sql stops at My and the rest of the block gets highlighted as php

now the closing label has to start a line after optional indentation which is the rule php's own lexer uses (checked against token_get_all()) and the foo(<<<SQL ... SQL)) case from #155 still passes

spotted it in a code block on https://dev-null.sh

@sulimanbenhalim

Copy link
Copy Markdown
Author

@brendt

brendt commented Oct 26, 2026

Copy link
Copy Markdown
Member

Nice!

@brendt
brendt merged commit ad84217 into tempestphp:main Oct 26, 2026
5 checks passed
@github-actions

Copy link
Copy Markdown

Benchmark Results

Comparison of fix/heredoc-closing-label against main (174423d7d32738a0751408ad160c180c64b01234).

Open to see the benchmark results
benchmark subject set revs its mem_peak mode rstdev
HighlighterBench benchParse apache 100 5 2.107mb 0.00% 52.586164μs +0.07% ±0.84% -14.60%
HighlighterBench benchParse bash 100 5 2.140mb 0.00% 149.077065μs +0.21% ±0.61% -44.44%
HighlighterBench benchParse bbcode 100 5 2.095mb 0.00% 54.406771μs +1.24% ±0.60% +89.34%
HighlighterBench benchParse blade 100 5 2.779mb +0.00% 729.306575μs +0.43% ±0.90% -36.98%
HighlighterBench benchParse css 100 5 2.127mb 0.00% 103.435773μs +0.89% ±0.91% +128.03%
HighlighterBench benchParse diff 100 5 2.130mb 0.00% 68.082838μs +0.24% ±1.72% +20.02%
HighlighterBench benchParse dockerfile 100 5 2.099mb 0.00% 64.344873μs +0.44% ±0.54% -32.12%
HighlighterBench benchParse dotenv 100 5 2.111mb 0.00% 56.966321μs +0.15% ±0.49% -56.46%
HighlighterBench benchParse gdscript 100 5 2.207mb 0.00% 240.087867μs -0.34% ±1.69% +120.67%
HighlighterBench benchParse graphql 100 5 2.127mb 0.00% 109.723659μs -0.03% ±0.41% -72.74%
HighlighterBench benchParse html 100 5 2.130mb 0.00% 84.004501μs +0.64% ±0.85% +0.07%
HighlighterBench benchParse http 100 5 2.099mb 0.00% 17.202740μs -0.16% ±1.09% -45.42%
HighlighterBench benchParse ini 100 5 2.115mb 0.00% 63.143562μs -0.18% ±0.79% -65.18%
HighlighterBench benchParse javascript 100 5 2.195mb 0.00% 196.080352μs +0.59% ±0.36% +135.67%
HighlighterBench benchParse json 100 5 2.171mb 0.00% 175.045479μs +0.61% ±0.48% -45.30%
HighlighterBench benchParse markdown 100 5 2.117mb 0.00% 55.025734μs -0.33% ±0.35% -54.90%
HighlighterBench benchParse nginx 100 5 2.181mb 0.00% 194.535323μs +0.37% ±0.39% -22.83%
HighlighterBench benchParse php 100 5 2.474mb +0.00% 549.500020μs -0.80% ±0.56% -0.87%
HighlighterBench benchParse python 100 5 2.374mb 0.00% 309.693386μs +0.02% ±0.18% +3.96%
HighlighterBench benchParse ruby 100 5 2.416mb 0.00% 172.632427μs +0.02% ±0.33% -0.36%
HighlighterBench benchParse scss 100 5 2.142mb 0.00% 132.340665μs -0.33% ±0.19% -64.56%
HighlighterBench benchParse sema 100 5 2.311mb 0.00% 156.152407μs +0.19% ±0.64% +48.93%
HighlighterBench benchParse sql 100 5 2.141mb 0.00% 113.926908μs -0.63% ±0.48% -3.16%
HighlighterBench benchParse svelte 100 5 2.418mb 0.00% 764.323699μs +1.76% ±0.93% +1.94%
HighlighterBench benchParse swift 100 5 2.189mb 0.00% 181.418160μs -0.52% ±0.69% -56.10%
HighlighterBench benchParse terminal 100 5 2.136mb 0.00% 134.076145μs +0.23% ±0.78% -17.85%
HighlighterBench benchParse terraform 100 5 2.141mb 0.00% 126.036086μs -3.67% ±0.68% -63.88%
HighlighterBench benchParse typescript 100 5 2.571mb 0.00% 180.241977μs +0.71% ±0.75% +24.50%
HighlighterBench benchParse txt 100 5 2.070mb 0.00% 6.309922μs -2.48% ±0.91% -67.90%
HighlighterBench benchParse twig 100 5 19.249mb 0.00% 1,093.016438μs -0.02% ±0.32% -82.23%
HighlighterBench benchParse vue 100 5 2.426mb 0.00% 281.015753μs -1.36% ±0.58% -50.97%
HighlighterBench benchParse xml 100 5 2.146mb 0.00% 132.235186μs -0.55% ±0.22% -83.24%
HighlighterBench benchParse yaml 100 5 2.202mb 0.00% 239.560039μs +0.46% ±0.43% -66.86%
HighlighterBench benchParse jsx 100 5 2.138mb 0.00% 36.901859μs +0.34% ±1.22% -27.01%
HighlighterBench benchParse tsx 100 5 2.225mb 0.00% 53.331703μs -0.57% ±1.34% +146.36%

Generated by phpbench against commit cda4ae1

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 40137151831

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 94.425%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 2888
Covered Lines: 2727
Line Coverage: 94.43%
Coverage Strength: 66.0 hits per line

💛 - Coveralls

@sulimanbenhalim
sulimanbenhalim deleted the fix/heredoc-closing-label branch October 26, 2026 16:25
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.

3 participants