Skip to content

Add Go syntax highlighting - #230

Open
eas4ai wants to merge 2 commits into
tempestphp:mainfrom
eas4ai:add-go-highlighting
Open

eas4ai wants to merge 2 commits into
tempestphp:mainfrom
eas4ai:add-go-highlighting

Conversation

@eas4ai

@eas4ai eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Register go and golang
  • Highlight comments, strings and raw strings, runes, numbers, keywords, built-in and declared types, constants, functions, operators, and punctuation
  • Add focused tests and a benchmark fixture

This is a clean resubmission of the closed #222, based directly on main and independent of the Rust PR: no core changes and no visual test harness, only the language, its registration, tests, and the benchmark fixture.

Verification

  • vendor/bin/php-cs-fixer fix --allow-risky=yes — no remaining changes
  • vendor/bin/phpstan analyse src tests — no errors
  • vendor/bin/phpunit — 854 tests, 1,113 assertions
  • vendor/bin/phpbench run tests/Bench/HighlighterBench.php --variant='^go$' --report=aggregate — 115.26 μs (±0.66%)

Screenshot

Go syntax highlighting in dark mode

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Benchmark Results

Comparison of add-go-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.27% 39.514168μs -1.25% ±1.21% +162.74%
HighlighterBench benchParse bash 100 5 2.136mb +0.27% 113.990959μs +1.15% ±0.71% +6.16%
HighlighterBench benchParse bbcode 100 5 2.092mb +0.27% 40.910763μs -0.19% ±1.15% -30.22%
HighlighterBench benchParse blade 100 5 2.775mb +0.20% 572.203836μs +0.94% ±1.33% +47.93%
HighlighterBench benchParse css 100 5 2.123mb +0.27% 77.604442μs +1.18% ±0.73% -51.17%
HighlighterBench benchParse diff 100 5 2.127mb +0.27% 51.161096μs +1.47% ±0.87% +30.07%
HighlighterBench benchParse dockerfile 100 5 2.097mb +0.27% 49.316849μs -1.14% ±1.29% +23.60%
HighlighterBench benchParse dotenv 100 5 2.108mb +0.27% 42.745773μs +0.95% ±0.25% -65.54%
HighlighterBench benchParse gdscript 100 5 2.203mb +0.26% 185.577221μs +0.77% ±0.30% -80.78%
HighlighterBench benchParse go 100 5 ERR 81.897710μs +0.00% ±1.22% +0.00%
HighlighterBench benchParse graphql 100 5 2.123mb +0.27% 84.467378μs -0.50% ±1.41% -4.66%
HighlighterBench benchParse html 100 5 2.127mb +0.27% 64.124971μs +1.05% ±0.97% -51.90%
HighlighterBench benchParse http 100 5 2.096mb +0.27% 13.719863μs +0.89% ±0.66% -21.28%
HighlighterBench benchParse ini 100 5 2.112mb +0.27% 47.699315μs +0.23% ±1.28% +53.05%
HighlighterBench benchParse javascript 100 5 2.191mb +0.26% 148.780117μs -0.56% ±1.86% +244.70%
HighlighterBench benchParse json 100 5 2.166mb +0.26% 132.277710μs +0.65% ±1.16% +53.14%
HighlighterBench benchParse markdown 100 5 2.114mb +0.27% 42.180352μs +1.71% ±2.27% +354.66%
HighlighterBench benchParse nginx 100 5 2.178mb +0.26% 149.048356μs +2.22% ±0.54% -35.60%
HighlighterBench benchParse php 100 5 2.469mb +0.23% 385.218787μs +0.76% ±0.21% -37.91%
HighlighterBench benchParse python 100 5 2.367mb +0.24% 232.179785μs +2.11% ±0.30% -82.73%
HighlighterBench benchParse ruby 100 5 2.413mb +0.24% 131.887593μs +1.25% ±0.60% +16.69%
HighlighterBench benchParse scss 100 5 2.139mb +0.27% 102.723679μs +0.33% ±0.52% -11.32%
HighlighterBench benchParse sema 100 5 2.307mb +0.25% 118.651233μs +0.20% ±1.42% +153.65%
HighlighterBench benchParse sql 100 5 2.138mb +0.27% 89.181918μs +1.90% ±1.31% +53.61%
HighlighterBench benchParse svelte 100 5 2.412mb +0.24% 564.965479μs +1.38% ±1.36% +36.82%
HighlighterBench benchParse swift 100 5 2.185mb +0.26% 140.071272μs +3.07% ±0.77% -6.46%
HighlighterBench benchParse terminal 100 5 2.133mb +0.27% 102.810978μs +1.45% ±0.69% -14.88%
HighlighterBench benchParse terraform 100 5 2.138mb +0.27% 97.112857μs +1.57% ±0.55% -49.65%
HighlighterBench benchParse typescript 100 5 2.563mb +0.22% 136.825890μs +1.48% ±0.74% -40.09%
HighlighterBench benchParse txt 100 5 2.067mb +0.27% 4.922583μs -0.47% ±2.44% +73.17%
HighlighterBench benchParse twig 100 5 19.245mb +0.03% 840.199256μs -1.61% ±0.50% -67.22%
HighlighterBench benchParse vue 100 5 2.420mb +0.23% 214.670705μs +0.36% ±0.23% -60.24%
HighlighterBench benchParse xml 100 5 2.141mb +0.26% 98.475479μs -0.21% ±0.45% -75.25%
HighlighterBench benchParse yaml 100 5 2.199mb +0.26% 178.044247μs +1.28% ±0.36% -71.34%
HighlighterBench benchParse jsx 100 5 2.135mb +0.27% 29.014892μs +3.06% ±0.55% -65.40%
HighlighterBench benchParse tsx 100 5 2.219mb +0.26% 41.426047μs +2.09% ±1.16% +110.70%

Generated by phpbench against commit 94d0a6c

@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 attribute testing on the pattern classes themselves? Just look at any other language to know how it's done

@eas4ai

eas4ai commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Added #[PatternTest] attributes to all 8 Go pattern classes.

Verified locally: vendor/bin/phpunit — 871 tests, 1,130 assertions; PHPStan reports no errors.

@eas4ai
eas4ai force-pushed the add-go-highlighting branch from adb166c to 32bd9fa Compare October 20, 2026 10:35
@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 Go changes and pattern tests are unchanged apart from fitting the updated registration and benchmark lists.

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

@eas4ai
eas4ai force-pushed the add-go-highlighting branch from 32bd9fa to 94d0a6c Compare October 20, 2026 10:39
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