-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attempt to add initial support for elixir (#593)
Co-authored-by: Morgante Pell <[email protected]>
- Loading branch information
Showing
110 changed files
with
456,370 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use crate::language::{fields_for_nodes, Field, MarzanoLanguage, NodeTypes, SortId, TSLanguage}; | ||
use grit_util::Language; | ||
use marzano_util::node_with_source::NodeWithSource; | ||
use std::sync::OnceLock; | ||
|
||
static NODE_TYPES_STRING: &str = | ||
include_str!("../../../resources/node-types/elixir-node-types.json"); | ||
|
||
static NODE_TYPES: OnceLock<Vec<Vec<Field>>> = OnceLock::new(); | ||
static LANGUAGE: OnceLock<TSLanguage> = OnceLock::new(); | ||
|
||
#[cfg(not(feature = "builtin-parser"))] | ||
fn language() -> TSLanguage { | ||
unimplemented!( | ||
"tree-sitter parser must be initialized before use when [builtin-parser] is off." | ||
) | ||
} | ||
|
||
#[cfg(feature = "builtin-parser")] | ||
fn language() -> TSLanguage { | ||
tree_sitter_elixir::language().into() | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct Elixir { | ||
node_types: &'static [Vec<Field>], | ||
metavariable_sort: SortId, | ||
comment_sort: SortId, | ||
language: &'static TSLanguage, | ||
} | ||
|
||
impl Elixir { | ||
pub(crate) fn new(lang: Option<TSLanguage>) -> Self { | ||
let language = LANGUAGE.get_or_init(|| lang.unwrap_or_else(language)); | ||
let node_types = NODE_TYPES.get_or_init(|| fields_for_nodes(language, NODE_TYPES_STRING)); | ||
let metavariable_sort = language.id_for_node_kind("grit_metavariable", true); | ||
let comment_sort = language.id_for_node_kind("comment", true); | ||
Self { | ||
node_types, | ||
metavariable_sort, | ||
comment_sort, | ||
language, | ||
} | ||
} | ||
pub(crate) fn is_initialized() -> bool { | ||
LANGUAGE.get().is_some() | ||
} | ||
} | ||
|
||
impl NodeTypes for Elixir { | ||
fn node_types(&self) -> &[Vec<Field>] { | ||
self.node_types | ||
} | ||
} | ||
|
||
impl Language for Elixir { | ||
use_marzano_delegate!(); | ||
|
||
fn language_name(&self) -> &'static str { | ||
"Elixir" | ||
} | ||
|
||
fn snippet_context_strings(&self) -> &[(&'static str, &'static str)] { | ||
&[ | ||
("", ""), | ||
("do GRIT_VARIABLE\n", "\nend"), | ||
("case GRIT_VARIABLE\n", "\nend"), | ||
("{", "}"), | ||
("[", "]"), | ||
] | ||
} | ||
|
||
fn comment_prefix(&self) -> &'static str { | ||
"#" | ||
} | ||
|
||
fn make_single_line_comment(&self, text: &str) -> String { | ||
format!("# {}\n", text) | ||
} | ||
} | ||
|
||
impl<'a> MarzanoLanguage<'a> for Elixir { | ||
fn get_ts_language(&self) -> &TSLanguage { | ||
self.language | ||
} | ||
|
||
fn is_comment_sort(&self, id: SortId) -> bool { | ||
id == self.comment_sort | ||
} | ||
|
||
fn metavariable_sort(&self) -> SortId { | ||
self.metavariable_sort | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
resources/language-metavariables/tree-sitter-elixir/.clang-format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AlignArrayOfStructures: Left | ||
BasedOnStyle: LLVM | ||
IndentCaseLabels: true | ||
IndentGotoLabels: true | ||
IndentPPDirectives: AfterHash | ||
IndentWidth: 2 | ||
KeepEmptyLinesAtTheStartOfBlocks: false | ||
SeparateDefinitionBlocks: Always | ||
SortIncludes: CaseInsensitive | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterLogicalNot: false | ||
SpaceBeforeCaseColon: false |
Oops, something went wrong.