mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-09-19 07:34:57 +08:00
47dfdf305c
R7b batch 4 #2 (docs/design/lua-luau-kernel-port-checklist.md is the authoritative quirk list). ONE walker for both dialects (ccpp precedent) — the differences are exactly four: luau's type_definition aliases, the `export `-slice isExported hook, the return-type signature suffix, and the grammar handle. Grammar prep is kernel-side only, no wasm change: lua is the SECOND vendored-grammar-C language (the vendored wasm is the v0.4.1 tag, a revision not on crates.io — tag artifacts compiled via build.rs, shas pinned); luau is a plain crate pin =1.2.0 whose tarball is sha-identical to the tag (the swift tag≠crate divergence does not recur). Grammar-parity rows replace the bump gate entirely. Preserved bug-for-bug (all probe-pinned): the require/visitNode-hook ASYMMETRIES (top-level requires — including inside top-level if/for/while — mint import nodes while the identical body-level statement emits `calls "require"`; top-level `local x = foo()` initializers are invisible while global `x = foo()` calls emit), the BFS string-win inside require args (`require(script:WaitForChild("Kid"))` → import Kid) and Roblox instance paths, receiver-QN methods (`M.sub.deep::chained`, `_G::installed`, stack-QN nested globals like `render::leakedGlobal`), the raw-text callee world (colon forms with `self` never stripped, bracket callees, newline-glued chains byte-verbatim, the `(handler)` paren-conversion), LUA_SPEC function-as-value capture with the `M.cb = cb` param-storage skip and first-occurrence dedupe, LuaDoc `---` keeping a leading `- ` plus `--!strict` joining docstring chains (block-comment docstrings keep interior CRLF bytes), variable nodes at the IDENTIFIER with positional value pairing, duplicate same-(kind,name,line) ids, and the lua↔luau isExported wire divergence (lua functions: flag absent; luau functions: present-false; methods: absent in both; variables: present-false in both; `export type`: true). Gates: parity sweeps first-run 0-diff on kong/lazy.nvim/lua-resty-core (lua) + lune/Fusion (luau) — 1,734 clean files byte-parity, deferrals 1/0/0/3/8 matching the survey's both-arm predictions exactly (kong's 1 = a deliberately invalid fixture; luau's = grammar-inherent generic type packs and default type params); full-init dumps byte-identical kernel-vs-wasm ×4 (kong 157,650 dump lines); kernel-lua-parity suite (both torture fixtures + in-memory CRLF variants + glue-chain, duplicate-id, and cross-dialect defer pins + kernel-arm wire-flag pins); full suite 2,647 green ×2 with CODEGRAPH_KERNEL_EXPECT=1. DEFAULT_ROUTED += lua, luau (18 langs). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
79 lines
4.1 KiB
Rust
79 lines
4.1 KiB
Rust
//! Grammar registry: codegraph `Language` string → native tree-sitter grammar.
|
|
//!
|
|
//! Mirrors the wasm side's `WASM_GRAMMAR_FILES` mapping (src/extraction/
|
|
//! grammars.ts): `tsx` and `jsx` reuse another language's grammar exactly the
|
|
//! way the wasm map does. The kernel-grammar-parity test asserts each entry is
|
|
//! built from the SAME grammar revision as the vendored wasm — bump the crate
|
|
//! and the wasm together.
|
|
//!
|
|
//! (R1 shipped a generic `.scm`-query emitter here; R2 replaced it with the
|
|
//! bespoke per-language walker — see tsjs/ and the migration plan §3a — because
|
|
//! extraction parity needs logic queries can't express. New languages add a
|
|
//! grammar entry + a walker module.)
|
|
|
|
use tree_sitter::Language;
|
|
|
|
// Vendored kotlin grammar (build.rs-compiled C — no usable crate exists;
|
|
// see grammars/kotlin and the kotlin checklist §Grammar prep).
|
|
extern "C" {
|
|
fn tree_sitter_kotlin() -> *const ();
|
|
}
|
|
// Vendored lua grammar (build.rs-compiled C — the wasm's v0.4.1 revision is
|
|
// not on crates.io; see grammars/lua and the lua-luau checklist).
|
|
extern "C" {
|
|
fn tree_sitter_lua() -> *const ();
|
|
}
|
|
|
|
/// Languages this kernel binary can extract (reported by contractInfo;
|
|
/// TS-side routing policy decides what actually routes).
|
|
pub const LANGUAGES: [&str; 18] = [
|
|
"typescript", "tsx", "javascript", "jsx", "java", "python", "go", "c", "cpp", "rust",
|
|
"csharp", "ruby", "php", "swift", "kotlin", "r", "lua", "luau",
|
|
];
|
|
|
|
pub fn grammar_for(language: &str) -> Option<Language> {
|
|
match language {
|
|
"typescript" => Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into()),
|
|
"tsx" => Some(tree_sitter_typescript::LANGUAGE_TSX.into()),
|
|
"javascript" | "jsx" => Some(tree_sitter_javascript::LANGUAGE.into()),
|
|
"java" => Some(tree_sitter_java::LANGUAGE.into()),
|
|
"python" => Some(tree_sitter_python::LANGUAGE.into()),
|
|
"go" => Some(tree_sitter_go::LANGUAGE.into()),
|
|
// `.metal`/`.cu`/`.cuh` map to language 'cpp' at detectLanguage, so the
|
|
// dialects ride this grammar too (their blanking pre-passes stay
|
|
// TS-side — the route point applies preParse before the kernel call).
|
|
"c" => Some(tree_sitter_c::LANGUAGE.into()),
|
|
"cpp" => Some(tree_sitter_cpp::LANGUAGE.into()),
|
|
// R7b: v0.24.2, sha-matched with the vendored wasm (grammars.ts).
|
|
"rust" => Some(tree_sitter_rust::LANGUAGE.into()),
|
|
// R7b: 0.23.5, table-identical to the vendored ABI-15 wasm (#717;
|
|
// verified against the crates.io tarball — csharp checklist header).
|
|
"csharp" => Some(tree_sitter_c_sharp::LANGUAGE.into()),
|
|
// R7b: v0.23.1, sha-matched with the vendored wasm (grammars.ts).
|
|
// Content bump only — the tag's parser.c is still ABI 14.
|
|
"ruby" => Some(tree_sitter_ruby::LANGUAGE.into()),
|
|
// R7b: v0.24.2, the full HTML-interleaving variant — LANGUAGE_PHP,
|
|
// NEVER LANGUAGE_PHP_ONLY (which errors on leading HTML).
|
|
"php" => Some(tree_sitter_php::LANGUAGE_PHP.into()),
|
|
// R7b: crate 0.7.3 — the vendored wasm is built from this crate's own
|
|
// tarball src/ (table identity by construction; see grammars.ts).
|
|
"swift" => Some(tree_sitter_swift::LANGUAGE.into()),
|
|
// R7b: fwcd 0.3.8, vendored C compiled in build.rs (crate unusable).
|
|
"kotlin" => {
|
|
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_kotlin) }.into())
|
|
}
|
|
// R7b batch 4: crate =1.2.0, sha-identical to the r-lib v1.2.0 tag
|
|
// the vendored wasm was built from (r checklist §Grammar prep).
|
|
"r" => Some(tree_sitter_r::LANGUAGE.into()),
|
|
// R7b batch 4: v0.4.1 vendored C compiled in build.rs (revision not
|
|
// on crates.io — the wasm is the v0.4.1 tag, table-identical).
|
|
"lua" => {
|
|
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_lua) }.into())
|
|
}
|
|
// R7b batch 4: crate =1.2.0, sha-identical to the v1.2.0 tag the
|
|
// vendored wasm was built from (lua-luau checklist §Grammar prep).
|
|
"luau" => Some(tree_sitter_luau::LANGUAGE.into()),
|
|
_ => None,
|
|
}
|
|
}
|