langs.rs 1.2 KB

123456789101112131415161718192021222324252627
  1. //! Grammar registry: codegraph `Language` string → native tree-sitter grammar.
  2. //!
  3. //! Mirrors the wasm side's `WASM_GRAMMAR_FILES` mapping (src/extraction/
  4. //! grammars.ts): `tsx` and `jsx` reuse another language's grammar exactly the
  5. //! way the wasm map does. The kernel-grammar-parity test asserts each entry is
  6. //! built from the SAME grammar revision as the vendored wasm — bump the crate
  7. //! and the wasm together.
  8. //!
  9. //! (R1 shipped a generic `.scm`-query emitter here; R2 replaced it with the
  10. //! bespoke per-language walker — see tsjs/ and the migration plan §3a — because
  11. //! extraction parity needs logic queries can't express. New languages add a
  12. //! grammar entry + a walker module.)
  13. use tree_sitter::Language;
  14. /// Languages this kernel binary can extract (reported by contractInfo;
  15. /// TS-side routing policy decides what actually routes).
  16. pub const LANGUAGES: [&str; 4] = ["typescript", "tsx", "javascript", "jsx"];
  17. pub fn grammar_for(language: &str) -> Option<Language> {
  18. match language {
  19. "typescript" => Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into()),
  20. "tsx" => Some(tree_sitter_typescript::LANGUAGE_TSX.into()),
  21. "javascript" | "jsx" => Some(tree_sitter_javascript::LANGUAGE.into()),
  22. _ => None,
  23. }
  24. }