Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Jun 20, 2024
1 parent 9d93794 commit c06e8d8
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/ferrite-core/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl TreeSitterConfig {
highlight_query: &str,
injection_query: &str,
locals_query: &str,
indent_query: &str,
) -> Self {
Self {
name: name.into(),
Expand All @@ -29,6 +30,7 @@ impl TreeSitterConfig {
highlight_query,
injection_query,
locals_query,
indent_query,
)
.unwrap(),
),
Expand Down Expand Up @@ -111,6 +113,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/rust/highlights.scm"),
include_str!("../../../queries/rust/injections.scm"),
include_str!("../../../queries/rust/locals.scm"),
include_str!("../../../queries/rust/indents.scm"),
),
#[cfg(feature = "lang-json")]
"json" => TreeSitterConfig::new(
Expand All @@ -119,6 +122,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/json/highlights.scm"),
"",
"",
"",
),
#[cfg(feature = "lang-c")]
"c" => TreeSitterConfig::new(
Expand All @@ -127,6 +131,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/c/highlights.scm"),
include_str!("../../../queries/c/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-cpp")]
"cpp" => TreeSitterConfig::new(
Expand All @@ -135,6 +140,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/cpp/highlights.scm"),
include_str!("../../../queries/cpp/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-cmake")]
"cmake" => TreeSitterConfig::new(
Expand All @@ -143,6 +149,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/cmake/highlights.scm"),
include_str!("../../../queries/cmake/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-css")]
"css" => TreeSitterConfig::new(
Expand All @@ -151,6 +158,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/css/highlights.scm"),
include_str!("../../../queries/css/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-glsl")]
"glsl" => TreeSitterConfig::new(
Expand All @@ -159,6 +167,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/glsl/highlights.scm"),
"",
"",
"",
),
#[cfg(feature = "lang-html")]
"html" => TreeSitterConfig::new(
Expand All @@ -167,6 +176,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/html/highlights.scm"),
include_str!("../../../queries/html/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-md")]
"markdown" => TreeSitterConfig::new(
Expand All @@ -175,6 +185,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/markdown/highlights.scm"),
include_str!("../../../queries/markdown/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-python")]
"python" => TreeSitterConfig::new(
Expand All @@ -183,6 +194,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/python/highlights.scm"),
include_str!("../../../queries/python/injections.scm"),
include_str!("../../../queries/python/locals.scm"),
"",
),
#[cfg(feature = "lang-toml")]
"toml" => TreeSitterConfig::new(
Expand All @@ -191,6 +203,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/toml/highlights.scm"),
include_str!("../../../queries/toml/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-xml")]
"xml" => TreeSitterConfig::new(
Expand All @@ -199,6 +212,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/xml/highlights.scm"),
include_str!("../../../queries/xml/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-yaml")]
"yaml" => TreeSitterConfig::new(
Expand All @@ -207,6 +221,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/yaml/highlights.scm"),
include_str!("../../../queries/yaml/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-c-sharp")]
"c-sharp" => TreeSitterConfig::new(
Expand All @@ -215,6 +230,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/c-sharp/highlights.scm"),
include_str!("../../../queries/c-sharp/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-bash")]
"bash" => TreeSitterConfig::new(
Expand All @@ -223,6 +239,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/bash/highlights.scm"),
include_str!("../../../queries/bash/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-fish")]
"fish" => TreeSitterConfig::new(
Expand All @@ -231,6 +248,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/fish/highlights.scm"),
include_str!("../../../queries/fish/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-comment")]
"comment" => TreeSitterConfig::new(
Expand All @@ -239,6 +257,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/comment/highlights.scm"),
"",
"",
"",
),
#[cfg(feature = "lang-javascript")]
"javascript" => TreeSitterConfig::new(
Expand All @@ -247,6 +266,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/javascript/highlights.scm"),
include_str!("../../../queries/javascript/injections.scm"),
include_str!("../../../queries/javascript/locals.scm"),
"",
),
#[cfg(feature = "lang-ron")]
"ron" => TreeSitterConfig::new(
Expand All @@ -255,6 +275,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/ron/highlights.scm"),
include_str!("../../../queries/ron/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-fortran")]
"fortran" => TreeSitterConfig::new(
Expand All @@ -263,6 +284,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/fortran/highlights.scm"),
include_str!("../../../queries/fortran/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-zig")]
"zig" => TreeSitterConfig::new(
Expand All @@ -271,6 +293,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/zig/highlights.scm"),
include_str!("../../../queries/zig/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-hyprlang")]
"hyprlang" => TreeSitterConfig::new(
Expand All @@ -279,6 +302,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/hyprlang/highlights.scm"),
include_str!("../../../queries/hyprlang/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-go")]
"go" => TreeSitterConfig::new(
Expand All @@ -287,6 +311,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/go/highlights.scm"),
include_str!("../../../queries/go/injections.scm"),
include_str!("../../../queries/go/locals.scm"),
"",
),
#[cfg(feature = "lang-typescript")]
"typescript" => TreeSitterConfig::new(
Expand All @@ -295,6 +320,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/typescript/highlights.scm"),
include_str!("../../../queries/typescript/injections.scm"),
include_str!("../../../queries/typescript/locals.scm"),
"",
),
#[cfg(feature = "lang-ini")]
"ini" => TreeSitterConfig::new(
Expand All @@ -303,6 +329,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/ini/highlights.scm"),
"",
"",
"",
),
#[cfg(feature = "lang-diff")]
"diff" => TreeSitterConfig::new(
Expand All @@ -311,6 +338,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/diff/highlights.scm"),
"",
"",
"",
),
#[cfg(feature = "lang-git-config")]
"git-config" => TreeSitterConfig::new(
Expand All @@ -319,6 +347,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/git-config/highlights.scm"),
"",
"",
"",
),
#[cfg(feature = "lang-git-commit")]
"git-commit" => TreeSitterConfig::new(
Expand All @@ -327,6 +356,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/git-commit/highlights.scm"),
include_str!("../../../queries/git-commit/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-rebase")]
"git-rebase" => TreeSitterConfig::new(
Expand All @@ -335,6 +365,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/git-rebase/highlights.scm"),
include_str!("../../../queries/git-rebase/injections.scm"),
"",
"",
),
#[cfg(feature = "lang-dockerfile")]
"dockerfile" => TreeSitterConfig::new(
Expand All @@ -343,6 +374,7 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
include_str!("../../../queries/dockerfile/highlights.scm"),
include_str!("../../../queries/dockerfile/injections.scm"),
"",
"",
),
_ => return None,
})
Expand Down
5 changes: 5 additions & 0 deletions crates/ferrite-core/src/language/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub struct HighlightConfiguration {
pub language: Language,
pub query: &'static Query,
combined_injections_query: &'static Option<Query>,
indent_query: &'static Query,
locals_pattern_index: usize,
highlights_pattern_index: usize,
non_local_variable_patterns: Vec<bool>,
Expand Down Expand Up @@ -321,6 +322,7 @@ impl HighlightConfiguration {
highlights_query: &str,
injection_query: &str,
locals_query: &str,
indents_query: &str,
) -> Result<Self, QueryError> {
// Concatenate the query strings, keeping track of the start offset of each section.
let mut query_source = String::new();
Expand All @@ -347,6 +349,8 @@ impl HighlightConfiguration {
}
}

let indent_query = Query::new(language, indents_query)?;

// Construct a separate query just for dealing with the 'combined injections'.
// Disable the combined injection patterns in the main query.
let mut combined_injections_query = Query::new(language, injection_query)?;
Expand Down Expand Up @@ -401,6 +405,7 @@ impl HighlightConfiguration {
language,
query: Box::leak(Box::new(query)),
combined_injections_query: Box::leak(Box::new(combined_injections_query)),
indent_query: Box::leak(Box::new(indent_query)),
locals_pattern_index,
highlights_pattern_index,
non_local_variable_patterns,
Expand Down
Loading

0 comments on commit c06e8d8

Please sign in to comment.