Skip to content

Unicode Gauntlet vs tree-sitter: the international text foundation, side by side - #3953

Merged
squid-protocol merged 1 commit into
mainfrom
feat/unicode-gauntlet-vs-treesitter
Sep 28, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
feat/unicode-gauntlet-vs-treesitter

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of epic #3811 (Tours the Globe): how GitGalaxy's international text foundation compares with tree-sitter on the same cells, under the same oracle.

What it measures

tests/tools/unicode_gauntlet_vs_treesitter.py reuses every Unicode Gauntlet cell (language × script × encoding, including line endings) and GitGalaxy's scans of them. It then applies the gauntlet's metamorphic oracle, facts(T(seed)) == T(facts(seed)), to the one channel both engines produce: the multiset of function names in the files tree-sitter can read. Each engine is compared with its own reading of the cell's reference, so to pass a cell it must find the same number of functions with every name whole. Three readings:

  • GitGalaxy: the gauntlet's own scan (master DB function_data).
  • tree-sitter (raw): the file's raw bytes go to the grammar, which is how tree-sitter-based tools consume files. Functions are extracted with tree_sitter_accuracy_audit's NODE_MAPS / _get_node_name. A name that isn't valid UTF-8 is recorded as broken, with its bytes. It is never decoded with a lossy handler.
  • tree-sitter + decode: the file is decoded with the cell's true encoding (EBCDIC split into FB-80 records) and re-encoded as UTF-8. This is the best a careful integrator could do, and it separates byte-pipeline failures from grammar failures.

Methodology and caveats

  • Attemptable cells are cells where the language has a NODE_MAPS entry and a grammar, and both engines pass a control: on the UTF-8 seed they find every function in keyword-rosetta's hand-verified expected_function_nodes. Controls: GitGalaxy 29/29 languages, tree-sitter 27/29 (fortran misses 3 functions and objective-c's .h files read as C find 0, so both are excluded as control-fail).
  • Dart is excluded (not-legal). The Dart spec allows only ASCII letters in identifiers, but the gauntlet's legality.json lists Dart as a Unicode-identifier language, so its non-ASCII cells aren't valid programs. tree-sitter-dart correctly refuses them. GitGalaxy "passing" them only shows it is more permissive than the compiler. This is a flaw in the gauntlet's legality table, not an engine bug. I did not fix it here.
  • I did not check each spec's rules on combining marks (Mn/Mc: Devanagari, Tamil, NFD). Kotlin's grammar lists only L* letters and Nd digits, so some of tree-sitter-kotlin's Devanagari/Tamil/NFD failures may be the grammar rejecting code that kotlinc would reject too. The Han/Hangul failures (Lo letters) in Haskell and Kotlin are real grammar gaps.
  • The oracle is GitGalaxy's own design, and the renamed units are the functions GitGalaxy found in the seed. The controls guard tree-sitter's side of that.
  • GitGalaxy decodes Shift-JIS, GB18030 and EBCDIC because the gauntlet declares the code page (--source-encoding). cp1252 is undeclared. ts-decode gets the same knowledge of the true encoding; ts-raw gets none.
  • Only function names are compared: no parameter counts, classes or other channels. gauntlet_all_channels_pass in results.json carries GitGalaxy's full verdict, which was 2725/2725.
  • 635 cells are ts-no-grammar (no NODE_MAPS entry): the whole mainframe seed (COBOL, PL/I, JCL, HLASM, CSD, so every EBCDIC cell), groovy, scheme, sqlite, ada, yaml and others. I didn't write new node maps.

Headline: --full run, 2725 cells, 1881 attemptable, 398 s wall with --jobs 8

engine pass
GitGalaxy 1881/1881 (100.0%)
tree-sitter (raw bytes) 846/1881 (45.0%)
tree-sitter + decode 1789/1881 (95.1%)

tree-sitter beat GitGalaxy on no cell.

By encoding (GitGalaxy / ts-raw / ts-decode): utf-8 100 / 95.0 / 95.0 · utf-8-sig 100 / 95.0 / 95.0 · crlf 100 / 95.0 / 95.0 · utf-16 100 / 0 / 95.0 · utf-16-be 100 / 0 / 95.0 · cp1252 100 / 0 / 100 · shift_jis 100 / 0 / 97.2 · gb18030 100 / 0 / 94.4.

What still fails after decoding is the grammar: Devanagari and Tamil 83%, Han, Hangul and NFD 89%. Examples: tree-sitter-haskell and tree-sitter-scala cut probebranchनाम to probebranchन, tree-sitter-kotlin returns just म, and tree-sitter-haskell and tree-sitter-kotlin drop 名前. Raw failures: cp1252 éèç comes through as invalid UTF-8 bytes; UTF-16 files give 0 functions or phantom 1-letter names; GB18030 and Shift-JIS produce cut or missing names.

Run it

python tests/tools/unicode_gauntlet_vs_treesitter.py --out DIR [--full] [--only python kotlin] [--jobs 8]

It writes DIR/results.json (per cell: each reading's verdict and first difference), DIR/summary.json (chart-ready engine × script / encoding / language pass rates) and DIR/report.md. The default is the gauntlet's sampled plan; --full runs every (script, encoding) pair. tests/tools/test_unicode_gauntlet_vs_treesitter.py skips cleanly without tree_sitter_language_pack. It covers the pure parts and runs a small real run (python, java and lua × French × UTF-8, UTF-16 and cp1252), asserting that python|french|cp1252 fails tree-sitter raw and passes both GitGalaxy and ts-decode.

The only change to unicode_gauntlet.py is an optional cells_out hook on run(). No engine code changed. pr_gates.py --fast passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TmgE1CwLgaqxqKEgQn5Dw5

tests/tools/unicode_gauntlet_vs_treesitter.py runs the gauntlet's metamorphic oracle on the
function-name channel for three readings of every cell: GitGalaxy (the gauntlet's own scans),
tree-sitter on the raw file bytes, and tree-sitter after decoding with the cell's true encoding.
Cells count only where tree-sitter has a grammar + node map and both engines pass a control
against keyword-rosetta's hand-verified answer key; Dart's non-ASCII renames are excluded as
illegal programs. Writes results.json, summary.json (chart-ready) and report.md.

unicode_gauntlet.run() gains an optional cells_out hook so the comparison reuses the same estates
and scans instead of re-planning them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TmgE1CwLgaqxqKEgQn5Dw5
Comment on lines +428 to +431
"- The oracle is the gauntlet's own metamorphic design, `facts(T(seed)) == T(facts(seed))`, applied to one "
"channel: the multiset of function names (case-folded, as the gauntlet compares) in the files tree-sitter "
"reads. Each engine is compared with ITSELF on the cell's reference, so a construct an extractor misses on "
"both sides cancels out; only what the script or the encoding changes counts.",
Comment on lines +432 to +434
"- The gauntlet (and so the rename list) was designed around GitGalaxy: the renamed units are the functions "
"GitGalaxy found in the seed. Controls guard the other side: a language counts only where tree-sitter finds "
"every function keyword-rosetta's hand-verified answer key lists on the UTF-8 seed.",
Comment on lines +435 to +437
"- tree-sitter's side is its raw reading through tree_sitter_accuracy_audit's NODE_MAPS / `_get_node_name` -- "
"not the audit's reconciled ground truth. A language absent from NODE_MAPS is `ts-no-grammar` even when the "
"pack has a grammar (objective-c, cobol, ...), because writing node maps here would be a new extractor.",
Comment on lines +438 to +440
"- `ts-raw` hands tree-sitter the file's bytes, as tree-sitter-based tools do. It has no notion of a BOM, "
"UTF-16 or a legacy code page; `ts-decode` shows what a careful integrator gets by decoding first. A name "
"whose bytes are not UTF-8 is recorded as broken, never decoded with a lossy handler.",
Comment on lines +441 to +443
"- GitGalaxy decodes Shift-JIS, GB18030 and EBCDIC cells because the scan DECLARES the page "
"(`--source-encoding`, as the gauntlet runs them); cp1252 is undeclared (its fallback is what those cells "
"test). `ts-decode` gets the same knowledge of the true encoding; `ts-raw` gets none.",
Comment on lines +444 to +448
"- Legality: the renames follow the gauntlet's legality.json. Dart is excluded (`not-legal`): its spec allows "
"ASCII letters only, so a grammar refusing `probeBranch名前` is correct. Other languages' rules for combining "
"marks (Mn / Mc: Devanagari, Tamil, NFD) were NOT checked against each spec here -- Kotlin's grammar names "
"only L* letters and Nd digits, so some of tree-sitter-kotlin's Devanagari / Tamil / NFD failures may be "
"the grammar rejecting code its compiler would too. Han / Hangul (Lo letters) are legal where Unicode is.",
Comment on lines +450 to +451
"- Parameter counts, classes and the other channels are not compared; `gauntlet_all_channels_pass` in "
"results.json carries GitGalaxy's full gauntlet verdict for reference.",
Comment on lines +452 to +453
"- The default plan samples two encodings per script (the gauntlet's CI plan); `--full` runs every "
"(script, encoding) pair, including cp1252.",
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 3f8bdb6 into main Sep 28, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the feat/unicode-gauntlet-vs-treesitter branch September 28, 2026 02:07
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