From 79d6e493ea8e3a2d6507bea2a3363181d0302684 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:26:03 +0200 Subject: [PATCH] feat: add Tact language --- build.rs | 5 +++++ sample_files/compare.expected | 5 ++++- sample_files/tact_1.tact | 19 +++++++++++++++++++ sample_files/tact_2.tact | 7 +++++++ src/parse/guess_language.rs | 4 ++++ src/parse/tree_sitter_parser.rs | 15 +++++++++++++++ vendored_parsers/highlights/tact.scm | 1 + vendored_parsers/tree-sitter-tact-src | 1 + 8 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 sample_files/tact_1.tact create mode 100644 sample_files/tact_2.tact create mode 120000 vendored_parsers/highlights/tact.scm create mode 120000 vendored_parsers/tree-sitter-tact-src diff --git a/build.rs b/build.rs index 9575bafecb..22ce89b28f 100644 --- a/build.rs +++ b/build.rs @@ -343,6 +343,11 @@ fn main() { src_dir: "vendored_parsers/tree-sitter-swift-src", extra_files: vec!["scanner.c"], }, + TreeSitterParser { + name: "tree-sitter-tact", + src_dir: "vendored_parsers/tree-sitter-tact-src", + extra_files: vec![], + }, TreeSitterParser { name: "tree-sitter-toml", src_dir: "vendored_parsers/tree-sitter-toml-src", diff --git a/sample_files/compare.expected b/sample_files/compare.expected index c9b961d241..18a3765cb4 100644 --- a/sample_files/compare.expected +++ b/sample_files/compare.expected @@ -29,7 +29,7 @@ sample_files/change_outer_1.el sample_files/change_outer_2.el 2b9334a4cc72da63bba28eff958f0038 - sample_files/chinese_1.po sample_files/chinese_2.po -bc93dffd067b6da1916388557b7ffbaf - +6092be4601bed143674c944483e656a7 - sample_files/clojure_1.clj sample_files/clojure_2.clj 453785e11dbee818ea0e8cac78c8be47 - @@ -262,6 +262,9 @@ sample_files/tab_1.c sample_files/tab_2.c sample_files/tab_1.txt sample_files/tab_2.txt a17e978720fe4c1b25614402910cc695 - +sample_files/tact_1.tact sample_files/tact_2.tact +9bec3d72e558297ee7ad18fa83d1e565 - + sample_files/tailwind_1.css sample_files/tailwind_2.css 95129d12808d15e32ea726eba1832d4d - diff --git a/sample_files/tact_1.tact b/sample_files/tact_1.tact new file mode 100644 index 0000000000..a72733ccc8 --- /dev/null +++ b/sample_files/tact_1.tact @@ -0,0 +1,19 @@ +// this trait has to be imported +import "@stdlib/deploy"; + +// the Deployable trait adds a default receiver for the "Deploy" message +contract Counter with Deployable { + val: Int as uint32; + + init() { + self.val = 0; + } + + receive("increment") { + self.val = self.val + 1; + } + + get fun value(): Int { + return self.val; + } +} diff --git a/sample_files/tact_2.tact b/sample_files/tact_2.tact new file mode 100644 index 0000000000..bfe78efa83 --- /dev/null +++ b/sample_files/tact_2.tact @@ -0,0 +1,7 @@ +import "@stdlib/deploy"; +contract Counter with Deployable { + val: Int as uint32; + init() { self.val = 0 } + receive("inc") { self.val += 1 } + get fun val(): Int { return self.val } +} diff --git a/src/parse/guess_language.rs b/src/parse/guess_language.rs index 5f0fb1d348..30b560d630 100644 --- a/src/parse/guess_language.rs +++ b/src/parse/guess_language.rs @@ -74,6 +74,7 @@ pub(crate) enum Language { Solidity, Sql, Swift, + Tact, Toml, TypeScript, TypeScriptTsx, @@ -167,6 +168,7 @@ pub(crate) fn language_name(language: Language) -> &'static str { Solidity => "Solidity", Sql => "SQL", Swift => "Swift", + Tact => "Tact", Toml => "TOML", TypeScript => "TypeScript", TypeScriptTsx => "TypeScript TSX", @@ -362,6 +364,7 @@ pub(crate) fn language_globs(language: Language) -> Vec { Solidity => &["*.sol"], Sql => &["*.sql", "*.pgsql"], Swift => &["*.swift"], + Tact => &["*.tact"], Toml => &[ "*.toml", "Cargo.lock", @@ -540,6 +543,7 @@ fn from_emacs_mode_header(src: &str) -> Option { "solidity" => Some(Solidity), "sql" => Some(Sql), "swift" => Some(Swift), + "tact" => Some(Tact), "toml" => Some(Toml), "tuareg" => Some(OCaml), "typescript" => Some(TypeScript), diff --git a/src/parse/tree_sitter_parser.rs b/src/parse/tree_sitter_parser.rs index 3ad5bc7191..f7a4373407 100644 --- a/src/parse/tree_sitter_parser.rs +++ b/src/parse/tree_sitter_parser.rs @@ -115,6 +115,7 @@ extern "C" { fn tree_sitter_solidity() -> ts::Language; fn tree_sitter_sql() -> ts::Language; fn tree_sitter_swift() -> ts::Language; + fn tree_sitter_tact() -> ts::Language; fn tree_sitter_toml() -> ts::Language; fn tree_sitter_tsx() -> ts::Language; fn tree_sitter_typescript() -> ts::Language; @@ -1083,6 +1084,20 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig { sub_languages: vec![], } } + Tact => { + let language = unsafe { tree_sitter_tact() }; + TreeSitterConfig { + language, + atom_nodes: vec!["string"].into_iter().collect(), + delimiter_tokens: vec![("{", "}"), ("(", ")"), ("<", ">")], + highlight_query: ts::Query::new( + language, + include_str!("../../vendored_parsers/highlights/tact.scm"), + ) + .unwrap(), + sub_languages: vec![], + } + } Toml => { let language = unsafe { tree_sitter_toml() }; TreeSitterConfig { diff --git a/vendored_parsers/highlights/tact.scm b/vendored_parsers/highlights/tact.scm new file mode 120000 index 0000000000..2519774ded --- /dev/null +++ b/vendored_parsers/highlights/tact.scm @@ -0,0 +1 @@ +../tree-sitter-tact/queries/highlights.scm \ No newline at end of file diff --git a/vendored_parsers/tree-sitter-tact-src b/vendored_parsers/tree-sitter-tact-src new file mode 120000 index 0000000000..6296ecf246 --- /dev/null +++ b/vendored_parsers/tree-sitter-tact-src @@ -0,0 +1 @@ +tree-sitter-tact/src \ No newline at end of file