#[derive(Debug, Clone)]
pub struct GrammarRecipe {
pub name: &'static str,
pub repo: &'static str,
pub subpath: Option<&'static str>,
pub rev: Option<&'static str>,
}
pub fn builtin_recipes() -> Vec<GrammarRecipe> {
vec![
GrammarRecipe {
name: "rust",
repo: "https://github.com/tree-sitter/tree-sitter-rust",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "python",
repo: "https://github.com/tree-sitter/tree-sitter-python",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "go",
repo: "https://github.com/tree-sitter/tree-sitter-go",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "javascript",
repo: "https://github.com/tree-sitter/tree-sitter-javascript",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "typescript",
repo: "https://github.com/tree-sitter/tree-sitter-typescript",
subpath: Some("typescript"),
rev: None,
},
GrammarRecipe {
name: "tsx",
repo: "https://github.com/tree-sitter/tree-sitter-typescript",
subpath: Some("tsx"),
rev: None,
},
GrammarRecipe {
name: "toml",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-toml",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "kotlin",
repo: "https://github.com/fwcd/tree-sitter-kotlin",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "c",
repo: "https://github.com/tree-sitter/tree-sitter-c",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "cpp",
repo: "https://github.com/tree-sitter/tree-sitter-cpp",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "java",
repo: "https://github.com/tree-sitter/tree-sitter-java",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "bash",
repo: "https://github.com/tree-sitter/tree-sitter-bash",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "json",
repo: "https://github.com/tree-sitter/tree-sitter-json",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "yaml",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-yaml",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "markdown",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-markdown",
subpath: Some("tree-sitter-markdown"),
rev: None,
},
GrammarRecipe {
name: "html",
repo: "https://github.com/tree-sitter/tree-sitter-html",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "css",
repo: "https://github.com/tree-sitter/tree-sitter-css",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "lua",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-lua",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "ruby",
repo: "https://github.com/tree-sitter/tree-sitter-ruby",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "zig",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-zig",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "sql",
repo: "https://github.com/DerekStride/tree-sitter-sql",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "dockerfile",
repo: "https://github.com/camdencheek/tree-sitter-dockerfile",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "make",
repo: "https://github.com/alemuller/tree-sitter-make",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "hcl",
repo: "https://github.com/MichaHoffmann/tree-sitter-hcl",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "diff",
repo: "https://github.com/the-mikedavis/tree-sitter-diff",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "vue",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-vue",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "svelte",
repo: "https://github.com/Himujjal/tree-sitter-svelte",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "haskell",
repo: "https://github.com/scherna/tree-sitter-haskell",
subpath: None,
rev: Some("6f6485f337bd7b8d6673a39edd490ac6a460a67b"),
},
GrammarRecipe {
name: "elixir",
repo: "https://github.com/elixir-lang/tree-sitter-elixir",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "nix",
repo: "https://github.com/nix-community/tree-sitter-nix",
subpath: None,
rev: None,
},
GrammarRecipe {
name: "c-sharp",
repo: "https://github.com/tree-sitter/tree-sitter-c-sharp",
subpath: None,
rev: Some("b5eb5742f6a7e9438bee22ce8026d6b927be2cd7"),
},
GrammarRecipe {
name: "swift",
repo: "https://github.com/alex-pinkus/tree-sitter-swift",
subpath: None,
rev: Some("aca5a52aa3cab858944d3c02701ccf5b2d8fd0f9"),
},
GrammarRecipe {
name: "php",
repo: "https://github.com/tree-sitter/tree-sitter-php",
subpath: Some("php"),
rev: Some("v0.24.2"),
},
GrammarRecipe {
name: "dart",
repo: "https://github.com/UserNobody14/tree-sitter-dart",
subpath: None,
rev: Some("80e23c07b64494f7e21090bb3450223ef0b192f4"),
},
GrammarRecipe {
name: "ocaml",
repo: "https://github.com/tree-sitter/tree-sitter-ocaml",
subpath: Some("grammars/ocaml"),
rev: Some("91708deb10cb4fe68ab3c50891426b9967dbf35a"),
},
GrammarRecipe {
name: "graphql",
repo: "https://github.com/bkegley/tree-sitter-graphql",
subpath: None,
rev: Some("5e66e961eee421786bdda8495ed1db045e06b5fe"),
},
GrammarRecipe {
name: "fish",
repo: "https://github.com/ram02z/tree-sitter-fish",
subpath: None,
rev: Some("70640c0696abde32622afc43291a385681afbd32"),
},
GrammarRecipe {
name: "julia",
repo: "https://github.com/tree-sitter/tree-sitter-julia",
subpath: None,
rev: Some("12a3aede757bc7fbdfb1909507c7a6fddd31df37"),
},
GrammarRecipe {
name: "gleam",
repo: "https://github.com/gleam-lang/tree-sitter-gleam",
subpath: None,
rev: Some("99ec4101504452c488b7c835fb65cfef75b090b7"),
},
GrammarRecipe {
name: "scala",
repo: "https://github.com/tree-sitter/tree-sitter-scala",
subpath: None,
rev: Some("b931fcc338390925eb893d70ad070033f5856ccf"),
},
GrammarRecipe {
name: "odin",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-odin",
subpath: None,
rev: Some("d2ca8efb4487e156a60d5bd6db2598b872629403"),
},
GrammarRecipe {
name: "proto",
repo: "https://github.com/treywood/tree-sitter-proto",
subpath: None,
rev: Some("e9f6b43f6844bd2189b50a422d4e2094313f6aa3"),
},
GrammarRecipe {
name: "cmake",
repo: "https://github.com/uyha/tree-sitter-cmake",
subpath: None,
rev: Some("fe48221d4d9842d916d66b5e71ab3c6307ec28b3"),
},
GrammarRecipe {
name: "xml",
repo: "https://github.com/tree-sitter-grammars/tree-sitter-xml",
subpath: Some("xml"),
rev: Some("0d9a8099c963ed53e183425c1b47fa2622c8eaf7"),
},
]
}
impl GrammarRecipe {
pub fn from_config(name: &str, source: &str, rev: Option<&str>, subpath: Option<&str>) -> Self {
fn leak(s: &str) -> &'static str {
Box::leak(s.to_owned().into_boxed_str())
}
GrammarRecipe {
name: leak(name),
repo: leak(source),
subpath: subpath.map(leak),
rev: rev.map(leak),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn find(name: &str) -> Option<GrammarRecipe> {
builtin_recipes().into_iter().find(|r| r.name == name)
}
#[test]
fn builtin_catalog_contains_rust() {
assert!(find("rust").is_some());
}
#[test]
fn typescript_and_tsx_share_repo_with_subpaths() {
let ts = find("typescript").unwrap();
let tsx = find("tsx").unwrap();
assert_eq!(ts.repo, tsx.repo);
assert_eq!(ts.subpath, Some("typescript"));
assert_eq!(tsx.subpath, Some("tsx"));
}
#[test]
fn unknown_recipe_is_none() {
assert!(find("does-not-exist").is_none());
}
#[test]
fn from_config_builds_owned_recipe() {
let r = GrammarRecipe::from_config(
"foolang",
"https://example.com/tree-sitter-foolang",
Some("abc123"),
Some("sub"),
);
assert_eq!(r.name, "foolang");
assert_eq!(r.repo, "https://example.com/tree-sitter-foolang");
assert_eq!(r.rev, Some("abc123"));
assert_eq!(r.subpath, Some("sub"));
}
}