Repository navigation
Expand file tree
/
Copy pathlangs.rs
More file actions
147 lines (143 loc) · 7.25 KB
/
Copy pathlangs.rs
File metadata and controls
147 lines (143 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! 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 ();
}
// Vendored scala grammar (build.rs-compiled C — the wasm and these sources are
// the v0.26.2 release; see grammars/scala and the scala checklist).
extern "C" {
fn tree_sitter_scala() -> *const ();
}
// Vendored dart grammar (build.rs-compiled C — UserNobody14 0038280; the
// crates.io crate is a different-lineage fork; see grammars/dart).
extern "C" {
fn tree_sitter_dart() -> *const ();
}
// Vendored swift grammar (build.rs-compiled C — crate 0.7.4's src/ with the
// scanner patch the wasm needs; see grammars/swift and
// docs/grammars/tree-sitter-swift.md).
extern "C" {
fn tree_sitter_swift() -> *const ();
}
// Vendored nix grammar (build.rs-compiled C — 3d0173d regenerated at ABI 15,
// the generation the vendored wasm was built from; see grammars/nix and the
// nix checklist).
extern "C" {
fn tree_sitter_nix() -> *const ();
}
// Vendored vbnet grammar (build.rs-compiled C — govindbanura@538b708 plus
// docs/grammars/tree-sitter-vbnet.patch, regenerated; the shipped wasm
// rebuilds byte-identical from the same sources; see grammars/vbnet).
extern "C" {
fn tree_sitter_vbnet() -> *const ();
}
// Vendored terraform grammar (build.rs-compiled C — tree-sitter-hcl v1.2.0's
// terraform dialect; see grammars/terraform and the terraform checklist).
extern "C" {
fn tree_sitter_terraform() -> *const ();
}
/// Languages this kernel binary can extract (reported by contractInfo;
/// TS-side routing policy decides what actually routes).
pub const LANGUAGES: [&str; 23] = [
"typescript", "tsx", "javascript", "jsx", "java", "python", "go", "c", "cpp", "rust",
"csharp", "ruby", "php", "swift", "kotlin", "r", "lua", "luau", "scala", "dart",
"nix",
"vbnet",
"terraform",
];
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.4's src/ (#3212), the sources the vendored wasm is
// built from (table identity by construction; see grammars.ts),
// compiled in build.rs with the same scanner patch.
"swift" => {
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_swift) }.into())
}
// R7b: fwcd main@d6af96d (#3410), vendored C compiled in build.rs
// (no crate carries it).
"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()),
// R7b batch 4: vendored C compiled in build.rs, now the v0.26.2
// release (#1823), kept byte-identical with the vendored wasm.
"scala" => {
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_scala) }.into())
}
// UserNobody14 0038280 vendored C compiled in build.rs, the sources
// the vendored wasm is built from (#3270).
"dart" => {
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_dart) }.into())
}
// nix-community 3d0173d regenerated at ABI 15 (tree-sitter-cli
// 0.25.10), vendored C compiled in build.rs — the parser.c the
// vendored wasm was built from (nix checklist §Grammar prep).
"nix" => {
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_nix) }.into())
}
// govindbanura 538b708 + this repo's patch, generated with
// tree-sitter-cli 0.25.10, vendored C compiled in build.rs — the
// sources the shipped wasm rebuilds byte-identical from.
"vbnet" => {
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_vbnet) }.into())
}
// tree-sitter-hcl v1.2.0's terraform dialect, vendored C compiled in
// build.rs: no crate carries the dialect (crates.io tree-sitter-hcl
// is 1.1.0 and HCL-only). parser.c is the tag's grammar regenerated
// at ABI 14, as upstream's npm release built the shipped wasm.
"terraform" => {
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_terraform) }.into())
}
_ => None,
}
}