#[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,
},
]
}
pub fn find_recipe(name: &str) -> Option<GrammarRecipe> {
builtin_recipes().into_iter().find(|r| r.name == name)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn builtin_catalog_contains_rust() {
assert!(find_recipe("rust").is_some());
}
#[test]
fn typescript_and_tsx_share_repo_with_subpaths() {
let ts = find_recipe("typescript").unwrap();
let tsx = find_recipe("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_recipe("does-not-exist").is_none());
}
}