Skip to content

Commit

Permalink
markdown and markdown inline
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Feb 11, 2024
1 parent 743ddc5 commit 9c8a9ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ default = [
"javascript",
"json",
"lua",
"markdown-tree-sitter-markdown",
"markdown",
"markdown-inline",
"python",
"rust",
"toml",
Expand All @@ -56,7 +57,8 @@ java = []
javascript = []
json = []
lua = []
markdown-tree-sitter-markdown = []
markdown = []
markdown-inline = []
python = []
rust = []
toml = []
Expand Down
31 changes: 26 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ use std::{
process::Command,
};

fn resolve_lang_src(base: &Path, prefix: Option<&str>, lang: String) -> (String, PathBuf) {
if let Some(prefix) = prefix {
let nested = base.join(format!("tree-sitter-{prefix}-{lang}"));
if nested.exists() {
return (format!("{prefix}_{lang}"), nested.join("src"));
}
}

let nested = base.join(format!("tree-sitter-{lang}"));
if nested.exists() {
return (lang, nested.join("src"));
}

let nested = base.join(&lang);
if nested.exists() {
return (lang, nested.join("src"));
}

(lang, base.join("src"))
}

#[derive(Debug)]
struct Sitter {
path: PathBuf,
Expand All @@ -20,21 +41,21 @@ impl Sitter {
let sitter = match feature.split_once('-') {
Some((dir, lang)) => {
let path = PathBuf::from(format!("sitters/tree-sitter-{dir}"));
let src = path.join(lang).join("src");
let (lang, src) = resolve_lang_src(&path, Some(dir), lang.to_owned());

Self {
path,
src,
path,
lang: lang.to_owned(),
version: OnceCell::new(),
}
}
None => {
let lang = feature;
let path = PathBuf::from(format!("sitters/tree-sitter-{lang}"));
let path = PathBuf::from(format!("sitters/tree-sitter-{feature}"));
let (lang, src) = resolve_lang_src(&path, None, feature);

Self {
src: path.join("src"),
src,
path,
lang,
version: OnceCell::new(),
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pepegsit!(javascript, "javascript", "/lang_javascript.rs");
pepegsit!(json, "json", "/lang_json.rs");
pepegsit!(lua, "lua", "/lang_lua.rs");
pepegsit!(markdown, "markdown", "/lang_markdown.rs");
pepegsit!(
markdown_inline,
"markdown-inline",
"/lang_markdown_inline.rs"
);
pepegsit!(python, "python", "/lang_python.rs");
pepegsit!(rust, "rust", "/lang_rust.rs");
pepegsit!(toml, "toml", "/lang_toml.rs");
Expand Down

0 comments on commit 9c8a9ba

Please sign in to comment.