Skip to content

Add Java and Kotlin syntax highlighting - #232

Merged
brendt merged 2 commits into
tempestphp:mainfrom
eas4ai:add-java-kotlin-highlighting
Oct 26, 2026
Merged

brendt merged 2 commits into
tempestphp:mainfrom
eas4ai:add-java-kotlin-highlighting

Conversation

@eas4ai

@eas4ai eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Register java for Java and kotlin / kt / kts for Kotlin
  • Highlight packages and imports, annotations, comments and doc comments, strings, numbers, keywords, built-in and declared types, classes and other declarations, literals, callables, lambdas, operators, and punctuation
  • Reuse the shared C-like comment and operator patterns under src/Languages/CLike/ (the same files as in the C/C++ PR, so this PR also stands alone)
  • Add focused tests and benchmark fixtures for both languages

This is a clean resubmission of the closed #224, based directly on main: no core changes and no visual test harness.

Verification

  • vendor/bin/php-cs-fixer fix --allow-risky=yes — no remaining changes
  • vendor/bin/phpstan analyse src tests — no errors
  • vendor/bin/phpunit — 889 tests, 1,162 assertions
  • vendor/bin/phpbench run tests/Bench/HighlighterBench.php --variant='^(java|kotlin)$' --report=aggregate — Java 230.69 μs, Kotlin 211.01 μs

Screenshots

Java

Java syntax highlighting

Kotlin

Kotlin syntax highlighting

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Benchmark Results

Comparison of add-java-kotlin-highlighting against main (3d96482ee77208c8e445d4f68667918c7f440f62).

Open to see the benchmark results
benchmark subject set revs its mem_peak mode rstdev
HighlighterBench benchParse apache 100 5 2.105mb +0.53% 54.642798μs +1.31% ±1.22% -32.90%
HighlighterBench benchParse bash 100 5 2.136mb +0.52% 155.772877μs -4.66% ±1.65% -3.77%
HighlighterBench benchParse bbcode 100 5 2.092mb +0.54% 56.891252μs +1.59% ±3.25% +319.98%
HighlighterBench benchParse blade 100 5 2.775mb +0.40% 767.175616μs +2.13% ±2.13% +776.52%
HighlighterBench benchParse css 100 5 2.123mb +0.53% 111.693659μs +4.63% ±2.66% +678.24%
HighlighterBench benchParse diff 100 5 2.127mb +0.53% 73.232955μs +9.91% ±2.71% +439.46%
HighlighterBench benchParse dockerfile 100 5 2.097mb +0.53% 68.767202μs +5.46% ±3.37% +309.24%
HighlighterBench benchParse dotenv 100 5 2.108mb +0.53% 58.755753μs +0.81% ±2.16% +190.79%
HighlighterBench benchParse gdscript 100 5 2.203mb +0.51% 255.982877μs +2.12% ±0.92% +148.22%
HighlighterBench benchParse graphql 100 5 2.123mb +0.53% 113.991233μs -0.05% ±2.32% +266.63%
HighlighterBench benchParse html 100 5 2.127mb +0.53% 91.779941μs +5.82% ±3.16% +554.22%
HighlighterBench benchParse http 100 5 2.096mb +0.53% 17.760450μs +0.42% ±1.05% +73.54%
HighlighterBench benchParse ini 100 5 2.112mb +0.53% 71.501781μs +9.02% ±1.67% -32.29%
HighlighterBench benchParse java 100 5 ERR 252.551937μs +0.00% ±2.12% +0.00%
HighlighterBench benchParse javascript 100 5 2.191mb +0.51% 227.242564μs +7.90% ±1.98% +120.63%
HighlighterBench benchParse json 100 5 2.166mb +0.52% 184.184775μs +2.27% ±1.03% -41.56%
HighlighterBench benchParse kotlin 100 5 ERR 216.946986μs +0.00% ±1.38% +0.00%
HighlighterBench benchParse markdown 100 5 2.114mb +0.53% 57.187397μs +1.34% ±1.29% -21.70%
HighlighterBench benchParse nginx 100 5 2.178mb +0.51% 209.572603μs +2.40% ±1.60% +27.31%
HighlighterBench benchParse php 100 5 2.469mb +0.45% 642.837260μs +2.13% ±1.05% -31.35%
HighlighterBench benchParse python 100 5 2.367mb +0.47% 351.879276μs +5.87% ±2.25% -3.18%
HighlighterBench benchParse ruby 100 5 2.413mb +0.46% 188.035068μs -0.15% ±2.30% +7.98%
HighlighterBench benchParse scss 100 5 2.139mb +0.52% 139.672329μs -3.21% ±2.53% +48.43%
HighlighterBench benchParse sema 100 5 2.307mb +0.49% 180.247221μs +5.49% ±1.94% -28.34%
HighlighterBench benchParse sql 100 5 2.138mb +0.52% 128.899589μs +7.70% ±1.81% -4.06%
HighlighterBench benchParse svelte 100 5 2.412mb +0.46% 866.354129μs +1.62% ±0.79% -59.87%
HighlighterBench benchParse swift 100 5 2.185mb +0.51% 209.144286μs +7.11% ±2.48% +67.28%
HighlighterBench benchParse terminal 100 5 2.133mb +0.53% 152.839824μs +3.66% ±0.37% -84.53%
HighlighterBench benchParse terraform 100 5 2.138mb +0.52% 144.608258μs +9.77% ±1.80% +615.17%
HighlighterBench benchParse typescript 100 5 2.563mb +0.44% 198.048904μs +4.84% ±2.73% +395.16%
HighlighterBench benchParse txt 100 5 2.067mb +0.54% 6.876654μs +7.15% ±1.35% -47.32%
HighlighterBench benchParse twig 100 5 19.245mb +0.06% 1,201.936360μs +10.48% ±1.15% +598.38%
HighlighterBench benchParse vue 100 5 2.420mb +0.46% 343.473973μs +8.35% ±1.19% +245.81%
HighlighterBench benchParse xml 100 5 2.141mb +0.52% 148.589667μs +9.76% ±0.94% +162.39%
HighlighterBench benchParse yaml 100 5 2.199mb +0.51% 253.601429μs +3.32% ±2.40% +696.49%
HighlighterBench benchParse jsx 100 5 2.135mb +0.52% 41.847182μs +10.46% ±1.31% +2.28%
HighlighterBench benchParse tsx 100 5 2.219mb +0.50% 55.493288μs -2.38% ±2.33% -4.85%

Generated by phpbench against commit 9c4dee8

@brendt brendt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add pattern tests please? Look at any other language pattern to see how they work.

@eas4ai

eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Added #[PatternTest] attributes to all 23 pattern classes in this PR: 5 shared C-like patterns, 8 Java patterns, and 10 Kotlin patterns.

Verified locally before pushing: vendor/bin/phpunit — 937 tests, 1,210 assertions; vendor/bin/phpstan analyse src tests — no errors; PHP-CS-Fixer clean.

@eas4ai
eas4ai force-pushed the add-java-kotlin-highlighting branch from ab05be4 to 0422a25 Compare October 20, 2026 10:36
@eas4ai

eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main to resolve the conflicts in src/Highlighter.php and tests/Bench/HighlighterBench.php after the recent language merges. The Java and Kotlin changes and pattern tests are unchanged apart from fitting the updated registration and benchmark lists.

Verified locally after the rebase: vendor/bin/phpunit — 1233 tests, 1763 assertions; PHPStan reports no errors. GitHub now reports this PR as mergeable with all checks passing.

@eas4ai
eas4ai force-pushed the add-java-kotlin-highlighting branch from 0422a25 to 9c4dee8 Compare October 20, 2026 10:39
@brendt
brendt merged commit 0bae935 into tempestphp:main Oct 26, 2026
5 checks passed
@brendt

brendt commented Oct 26, 2026

Copy link
Copy Markdown
Member

🫡 yessir!

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