Skip to content

Commit

Permalink
feat: add Tact language
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota committed Aug 25, 2024
1 parent 8ec77dc commit 79d6e49
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion sample_files/compare.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down Expand Up @@ -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 -

Expand Down
19 changes: 19 additions & 0 deletions sample_files/tact_1.tact
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 7 additions & 0 deletions sample_files/tact_2.tact
Original file line number Diff line number Diff line change
@@ -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 }
}
4 changes: 4 additions & 0 deletions src/parse/guess_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub(crate) enum Language {
Solidity,
Sql,
Swift,
Tact,
Toml,
TypeScript,
TypeScriptTsx,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -362,6 +364,7 @@ pub(crate) fn language_globs(language: Language) -> Vec<glob::Pattern> {
Solidity => &["*.sol"],
Sql => &["*.sql", "*.pgsql"],
Swift => &["*.swift"],
Tact => &["*.tact"],
Toml => &[
"*.toml",
"Cargo.lock",
Expand Down Expand Up @@ -540,6 +543,7 @@ fn from_emacs_mode_header(src: &str) -> Option<Language> {
"solidity" => Some(Solidity),
"sql" => Some(Sql),
"swift" => Some(Swift),
"tact" => Some(Tact),
"toml" => Some(Toml),
"tuareg" => Some(OCaml),
"typescript" => Some(TypeScript),
Expand Down
15 changes: 15 additions & 0 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions vendored_parsers/highlights/tact.scm
1 change: 1 addition & 0 deletions vendored_parsers/tree-sitter-tact-src

0 comments on commit 79d6e49

Please sign in to comment.