aboutsummaryrefslogtreecommitdiff
path: root/helix-syntax/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-09 05:41:12 +0000
committerBlaž Hrastnik2020-09-09 05:41:12 +0000
commit7eac12a4bb02aaa96f63de612077a12df1d5fedc (patch)
treec54b40453427e9f029577d710ebb92325a4d4349 /helix-syntax/src
parent563e094916b6e0d3ef0fafe8141372116e35ebde (diff)
Add helix-syntax as a wrapper around tree-sitter parsers.
Diffstat (limited to 'helix-syntax/src')
-rw-r--r--helix-syntax/src/lib.rs87
1 files changed, 87 insertions, 0 deletions
diff --git a/helix-syntax/src/lib.rs b/helix-syntax/src/lib.rs
new file mode 100644
index 00000000..1ca36ca6
--- /dev/null
+++ b/helix-syntax/src/lib.rs
@@ -0,0 +1,87 @@
+use enum_iterator::IntoEnumIterator;
+use tree_sitter::Language;
+
+#[macro_export]
+macro_rules! mk_extern {
+ ( $( $name:ident ),* ) => {
+ $(
+ extern "C" { pub fn $name() -> Language; }
+ )*
+ };
+}
+
+#[macro_export]
+macro_rules! mk_enum {
+ ( $( $camel:ident ),* ) => {
+ #[derive(Clone, Debug, IntoEnumIterator, PartialEq)]
+ pub enum LANG {
+ $(
+ $camel,
+ )*
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! mk_get_language {
+ ( $( ($camel:ident, $name:ident) ),* ) => {
+ pub fn get_language(lang: &LANG) -> Language {
+ unsafe {
+ match lang {
+ $(
+ LANG::$camel => $name(),
+ )*
+ }
+ }
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! mk_get_language_name {
+ ( $( $camel:ident ),* ) => {
+ pub fn get_language_name(lang: &LANG) -> &'static str {
+ match lang {
+ $(
+ LANG::$camel => stringify!($camel),
+ )*
+ }
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! mk_langs {
+ ( $( ($camel:ident, $name:ident) ),* ) => {
+ mk_extern!($( $name ),*);
+ mk_enum!($( $camel ),*);
+ mk_get_language!($( ($camel, $name) ),*);
+ mk_get_language_name!($( $camel ),*);
+ };
+}
+
+mk_langs!(
+ // 1) Name for enum
+ // 2) tree-sitter function to call to get a Language
+ (Agda, tree_sitter_agda),
+ (Bash, tree_sitter_bash),
+ (C, tree_sitter_c),
+ (CSharp, tree_sitter_c_sharp),
+ // (Cpp, tree_sitter_cpp),
+ (Css, tree_sitter_css),
+ (Go, tree_sitter_go),
+ (Haskell, tree_sitter_haskell),
+ (Html, tree_sitter_html),
+ (Java, tree_sitter_java),
+ (Javascript, tree_sitter_javascript),
+ (Json, tree_sitter_json),
+ (Julia, tree_sitter_julia),
+ (Php, tree_sitter_php),
+ (Python, tree_sitter_python),
+ (Ruby, tree_sitter_ruby),
+ (Rust, tree_sitter_rust),
+ (Scala, tree_sitter_scala),
+ (Swift, tree_sitter_swift),
+ (Tsx, tree_sitter_tsx),
+ (Typescript, tree_sitter_typescript)
+);