Skip to content

Raise rule coverage of popular grammar samples to 90% - #153

Merged
ryangjchandler merged 2 commits into
3.xfrom
raise-popular-sample-coverage
Nov 4, 2026
Merged

ryangjchandler merged 2 commits into
3.xfrom
raise-popular-sample-coverage

Conversation

@ryangjchandler

Copy link
Copy Markdown
Collaborator

Extends the compatibility samples for the most widely used languages so meta/compatibility.php exercises at least 90% of each grammar's rules, and regenerates COMPATIBILITY.md.

The existing sample content is unchanged; new code is appended (plus a shebang at the top of a few files). It's mostly realistic, idiomatic code. A few samples end with a short, commented block of invalid code to cover the grammar's "illegal" rules.

Grammar Rule coverage Grammar Rule coverage
JavaScript 42.3 → 93.6% Swift 52.9 → 90.5%
TypeScript 51.5 → 93.8% Kotlin 64.6 → 95.4%
TSX 57.7 → 93.1% Dart 67.0 → 94.3%
JSX 43.8 → 93.4% Scala 73.5 → 92.3%
Python 50.0 → 92.0% Lua 77.9 → 91.9%
Java 82.2 → 92.5% SQL 64.4 → 90.4%
C# 61.7 → 94.6% HTML 32.9 → 98.8%
C 43.3 → 90.2% CSS 74.2 → 95.5%
PHP 47.0 → 96.8% SCSS 73.2 → 91.1%
Go 47.9 → 91.1% JSON 56.5 → 100%
Ruby 49.2 → 93.9% YAML 32.3 → 96.8%
C++ 26.7 → 67.1% Markdown 33.8 → 97.7%
Shell 63.6 → 87.2%

Rust was already at 92.6%.

C++ and Shell can't reach 90% under this metric: 152 C++ rules and 21 Shell rules are never included anywhere in their grammars (ceilings of 83.8% and 89.2%). C++ also loses 39 constructor/destructor rules, and Shell a name() ( … ) body rule, to Phiki bugs.

Script fix

With the larger samples, meta/vscode-textmate-samples.js crashed with fail to memory allocation from vscode-oniguruma, because one registry held compiled scanners for all 227 grammars. It now creates and disposes a registry per grammar. On the original samples its output is byte-identical to before.

Phiki bugs the new samples expose

Totals moved from 92.6% → 93.1% (Oniguruma) and 95.5% → 96.2% (PCRE), but PCRE-identical grammars dropped from 167 to 163:

  • Ruby: %w|…| / %^…^ percent literals aren't recognised; the captured delimiter seems to be put into the end regex unescaped.
  • HTML: attributes and children inside <svg>/<math> are mis-scoped; those rules have a nested repository that Phiki doesn't appear to use when resolving includes.
  • Scala: the empty XML tag rule (<p></p>) never matches; its regex has a backreference inside a lookahead.
  • Swift: the closing # of #/…/# regex literals falls outside the regex scope.
  • Oniguruma only (JS/JSX/TS/TSX): using / await using declarations never close, so the scope leaks to the end of the file. Those snippets sit last in each sample.

ampagent and others added 2 commits November 4, 2026 19:17
One registry for every grammar exhausted vscode-oniguruma's WASM heap once
the samples grew. Disposing each grammar's registry keeps memory bounded and
produces byte-identical tokens for the existing samples.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a3c3-f9f7-7045-8283-061347f1edec
Co-authored-by: Ryan Chandler <ryan@ryangjchandler.co.uk>
Extend the samples for 25 widely used languages so each matches at least 90%
of its grammar's rules, except C++ (67.1%) and Shell (87.2%), whose grammars
contain rules that are never included. Regenerate COMPATIBILITY.md.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a3c3-f9f7-7045-8283-061347f1edec
Co-authored-by: Ryan Chandler <ryan@ryangjchandler.co.uk>
@ryangjchandler
ryangjchandler merged commit 58c19af into 3.x Nov 4, 2026
3 of 4 checks passed
@ryangjchandler
ryangjchandler deleted the raise-popular-sample-coverage branch November 4, 2026 19:24
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