Skip to content

Commit

Permalink
add support for Salesforce Apex
Browse files Browse the repository at this point in the history
  • Loading branch information
rody committed Oct 6, 2023
1 parent b818b47 commit 05d78ca
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-sql-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-sfapex",
src_dir: "vendored_parsers/tree-sitter-sfapex-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-swift",
src_dir: "vendored_parsers/tree-sitter-swift-src",
Expand Down
1 change: 1 addition & 0 deletions manual/src/languages_supported.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ with `difft --list-languages`.
| Language | Parser Used |
|-----------------|---------------------------------------------------------------------------------------------|
| Ada | [briot/tree-sitter-ada](https://github.com/briot/tree-sitter-ada) |
| Apex | [aheber/tree-sitter-sfapex](https://github.com/aheber/tree-sitter-sfapex) |
| Bash | [tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) |
| C | [tree-sitter/tree-sitter-c](https://github.com/tree-sitter/tree-sitter-c) |
| C++ | [tree-sitter/tree-sitter-cpp](https://github.com/tree-sitter/tree-sitter-cpp) |
Expand Down
10 changes: 10 additions & 0 deletions sample_files/apex_after.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @description diffstatic test file
*/
public with sharing class MyClass extends OtherClass implements MyInterface {
private static final Integer A_CONSTANT = 0;

public void doSomething(Object param1, Object param2) {
System.debug('Hello world!');
}
}
14 changes: 14 additions & 0 deletions sample_files/apex_before.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @description diffstatic test file
*/
public with sharing class MyClass extends OtherClass
implements MyInterface {

private static final Integer A_CONSTANT = 0;

public void doSomething(Object param1,
Object param2) {

System.debug('Hello world!');
}
}
3 changes: 3 additions & 0 deletions sample_files/compare.expected
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ sample_files/ada_before.adb sample_files/ada_after.adb
sample_files/added_line_before.txt sample_files/added_line_after.txt
5996d2f9cc7c1e3acfdeafcf0f5e43c1 -

sample_files/apex_before.cls sample_files/apex_after.cls
fde5c2cb739fb8bb42a592f64190137e -

sample_files/b2_math_before.h sample_files/b2_math_after.h
e1391702d8059d127110017bf6e9ef85 -

Expand Down
3 changes: 3 additions & 0 deletions src/parse/guess_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use strum::{EnumIter, IntoEnumIterator};
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter)]
pub enum Language {
Ada,
Apex,
Bash,
C,
Clojure,
Expand Down Expand Up @@ -104,6 +105,7 @@ pub fn language_override_from_name(name: &str) -> Option<LanguageOverride> {
pub fn language_name(language: Language) -> &'static str {
match language {
Ada => "Ada",
Apex => "Apex",
Bash => "Bash",
C => "C",
Clojure => "Clojure",
Expand Down Expand Up @@ -215,6 +217,7 @@ pub fn language_globs(language: Language) -> Vec<glob::Pattern> {
"zshenv",
"zshrc",
],
Apex => &["*.cls", "*.apexc", "*.trigger"],
C => &["*.c"],
Clojure => &[
"*.bb", "*.boot", "*.clj", "*.cljc", "*.clje", "*.cljs", "*.cljx", "*.edn", "*.joke",
Expand Down
25 changes: 25 additions & 0 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct TreeSitterConfig {

extern "C" {
fn tree_sitter_ada() -> ts::Language;
fn tree_sitter_apex() -> ts::Language;
fn tree_sitter_bash() -> ts::Language;
fn tree_sitter_c() -> ts::Language;
fn tree_sitter_c_sharp() -> ts::Language;
Expand Down Expand Up @@ -145,6 +146,30 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
sub_languages: vec![],
}
}
Apex => {
let language = unsafe { tree_sitter_apex() };
TreeSitterConfig {
language,
atom_nodes: vec![
"string_literal",
"null_literal",
"boolean",
"int",
"decimal_floating_point_literal",
"date_literal",
"currency_literal",
]
.into_iter()
.collect(),
delimiter_tokens: vec![("[", "]"), ("(", ")"), ("{", "}")],
highlight_query: ts::Query::new(
language,
include_str!("../../vendored_parsers/highlights/apex.scm"),
)
.unwrap(),
sub_languages: vec![],
}
}
Bash => {
let language = unsafe { tree_sitter_bash() };
TreeSitterConfig {
Expand Down
1 change: 1 addition & 0 deletions translation/zh-CN/manual-zh-CN/src/languages_supported.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| 语言 | 使用的解析器 |
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Bash | [tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) |
| Apex | [aheber/tree-sitter-sfapex](https://github.com/aheber/tree-sitter-sfapex) |
| C | [tree-sitter/tree-sitter-c](https://github.com/tree-sitter/tree-sitter-c) |
| C++ | [tree-sitter/tree-sitter-cpp](https://github.com/tree-sitter/tree-sitter-cpp) |
| C# | [tree-sitter/tree-sitter-c-sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) |
Expand Down
Loading

0 comments on commit 05d78ca

Please sign in to comment.