treesitter: add ocaml

This commit is contained in:
Maciej Jur 2024-10-01 21:05:35 +02:00
parent be2963d931
commit 618925d8ef
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
3 changed files with 221 additions and 197 deletions

22
Cargo.lock generated
View file

@ -988,6 +988,8 @@ dependencies = [
"tree-sitter-html", "tree-sitter-html",
"tree-sitter-javascript", "tree-sitter-javascript",
"tree-sitter-language", "tree-sitter-language",
"tree-sitter-md",
"tree-sitter-ocaml",
"tree-sitter-python", "tree-sitter-python",
"tree-sitter-regex", "tree-sitter-regex",
"tree-sitter-rust", "tree-sitter-rust",
@ -1788,6 +1790,26 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2545046bd1473dac6c626659cc2567c6c0ff302fc8b84a56c4243378276f7f57" checksum = "2545046bd1473dac6c626659cc2567c6c0ff302fc8b84a56c4243378276f7f57"
[[package]]
name = "tree-sitter-md"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17f968c22a01010b83fc960455ae729db08dbeb6388617d9113897cb9204b030"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-ocaml"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0534f94f006cf4d4994e964212e91d4626efcaf6769b023d3f17530399a4d6e1"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]] [[package]]
name = "tree-sitter-python" name = "tree-sitter-python"
version = "0.23.2" version = "0.23.2"

View file

@ -34,8 +34,9 @@ tree-sitter-css = "0.23"
tree-sitter-haskell = "0.23" tree-sitter-haskell = "0.23"
tree-sitter-html = "0.23" tree-sitter-html = "0.23"
tree-sitter-javascript = "0.23" tree-sitter-javascript = "0.23"
# tree-sitter-md = "0.2" tree-sitter-md = "0.3"
# tree-sitter-nix = { package = "npezza93-tree-sitter-nix", version = "0.0.2" } # tree-sitter-nix = { package = "npezza93-tree-sitter-nix", version = "0.0.2" }
tree-sitter-ocaml = "0.23.1"
tree-sitter-python = "0.23" tree-sitter-python = "0.23"
tree-sitter-regex = "0.23" tree-sitter-regex = "0.23"
tree-sitter-rust = "0.23" tree-sitter-rust = "0.23"

View file

@ -1,10 +1,9 @@
use std::collections::HashMap;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::collections::HashMap;
use tree_sitter_highlight::HighlightConfiguration; use tree_sitter_highlight::HighlightConfiguration;
use super::captures; use super::captures;
macro_rules! query { macro_rules! query {
($path:literal) => { ($path:literal) => {
include_str!(concat!( include_str!(concat!(
@ -30,37 +29,32 @@ macro_rules! merge {
macro_rules! language { macro_rules! language {
($name:expr, $lang:expr, $highlights:expr, $injections:expr, $locals:expr $(,)?) => { ($name:expr, $lang:expr, $highlights:expr, $injections:expr, $locals:expr $(,)?) => {
( ($name, {
$name, let mut config =
{ HighlightConfiguration::new($lang, $name, $highlights, $injections, $locals)
let mut config = HighlightConfiguration::new( .unwrap();
$lang,
$name,
$highlights,
$injections,
$locals,
).unwrap();
config.configure(captures::NAMES); config.configure(captures::NAMES);
config config
} })
)
}; };
} }
static EXTENSIONS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| static EXTENSIONS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
HashMap::from([ HashMap::from([
("hs", "haskell"), ("hs", "haskell"),
("js", "javascript"), ("js", "javascript"),
("md", "markdown"), ("md", "markdown"),
("mdx", "markdown"), ("mdx", "markdown"),
("ml", "ocaml"),
("mli", "ocaml_interface"),
("py", "python"), ("py", "python"),
("scm", "scheme"), ("scm", "scheme"),
("ts", "typescript"), ("ts", "typescript"),
("typescript", "javascript") ("typescript", "javascript"),
]) ])
); });
static CONFIGS: Lazy<HashMap<&'static str, HighlightConfiguration>> = Lazy::new(|| static CONFIGS: Lazy<HashMap<&'static str, HighlightConfiguration>> = Lazy::new(|| {
HashMap::from([ HashMap::from([
// ( // (
// "astro", // "astro",
@ -85,13 +79,7 @@ static CONFIGS: Lazy<HashMap<&'static str, HighlightConfiguration>> = Lazy::new(
tree_sitter_haskell::INJECTIONS_QUERY, tree_sitter_haskell::INJECTIONS_QUERY,
tree_sitter_haskell::LOCALS_QUERY, tree_sitter_haskell::LOCALS_QUERY,
), ),
language!( language!("html", tree_sitter_html::LANGUAGE.into(), "", "", "",),
"html",
tree_sitter_html::LANGUAGE.into(),
"",
"",
"",
),
language!( language!(
"javascript", "javascript",
tree_sitter_javascript::LANGUAGE.into(), tree_sitter_javascript::LANGUAGE.into(),
@ -113,20 +101,20 @@ static CONFIGS: Lazy<HashMap<&'static str, HighlightConfiguration>> = Lazy::new(
tree_sitter_javascript::INJECTIONS_QUERY, tree_sitter_javascript::INJECTIONS_QUERY,
tree_sitter_javascript::LOCALS_QUERY, tree_sitter_javascript::LOCALS_QUERY,
), ),
// language!( language!(
// "markdown", "markdown",
// tree_sitter_md::language(), tree_sitter_md::LANGUAGE.into(),
// tree_sitter_md::HIGHLIGHT_QUERY_BLOCK, tree_sitter_md::HIGHLIGHT_QUERY_BLOCK,
// tree_sitter_md::INJECTION_QUERY_BLOCK, tree_sitter_md::INJECTION_QUERY_BLOCK,
// "", "",
// ), ),
// language!( language!(
// "markdown_inline", "markdown_inline",
// tree_sitter_md::inline_language(), tree_sitter_md::INLINE_LANGUAGE.into(),
// tree_sitter_md::HIGHLIGHT_QUERY_INLINE, tree_sitter_md::HIGHLIGHT_QUERY_INLINE,
// tree_sitter_md::INJECTION_QUERY_INLINE, tree_sitter_md::INJECTION_QUERY_INLINE,
// "", "",
// ), ),
// language!( // language!(
// "nix", // "nix",
// tree_sitter_nix::language(), // tree_sitter_nix::language(),
@ -134,6 +122,20 @@ static CONFIGS: Lazy<HashMap<&'static str, HighlightConfiguration>> = Lazy::new(
// "", // "",
// "", // "",
// ), // ),
language!(
"ocaml",
tree_sitter_ocaml::LANGUAGE_OCAML.into(),
tree_sitter_ocaml::HIGHLIGHTS_QUERY,
tree_sitter_ocaml::LOCALS_QUERY,
"",
),
language!(
"ocaml_interface",
tree_sitter_ocaml::LANGUAGE_OCAML_INTERFACE.into(),
tree_sitter_ocaml::HIGHLIGHTS_QUERY,
tree_sitter_ocaml::LOCALS_QUERY,
"",
),
language!( language!(
"python", "python",
tree_sitter_python::LANGUAGE.into(), tree_sitter_python::LANGUAGE.into(),
@ -209,8 +211,7 @@ static CONFIGS: Lazy<HashMap<&'static str, HighlightConfiguration>> = Lazy::new(
], ],
), ),
]) ])
); });
pub fn get_config(name: &str) -> Option<&'static HighlightConfiguration> { pub fn get_config(name: &str) -> Option<&'static HighlightConfiguration> {
match EXTENSIONS.get(name) { match EXTENSIONS.get(name) {