Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
6CE117FC2CEA7CF80082D393 /* TreeSitterDart in Frameworks */ = {isa = PBXBuildFile; productRef = 6CE117FB2CEA7CF80082D393 /* TreeSitterDart */; };
6CEC70FE29C3A85000B61C7A /* TreeSitterRegex in Frameworks */ = {isa = PBXBuildFile; productRef = 6CEC70FD29C3A85000B61C7A /* TreeSitterRegex */; };
6CF2B8412CE978F100CBE5D1 /* TreeSitterDart in Frameworks */ = {isa = PBXBuildFile; productRef = 6CF2B8402CE978F100CBE5D1 /* TreeSitterDart */; };
76BC51E22F03A6D50030E59A /* TreeSitterR in Frameworks */ = {isa = PBXBuildFile; productRef = 76BC51E12F03A6D50030E59A /* TreeSitterR */; };
76BC51E52F03ACB50030E59A /* TreeSitterXML in Frameworks */ = {isa = PBXBuildFile; productRef = 76BC51E42F03ACB50030E59A /* TreeSitterXML */; };
8E74B41D2A4C88ED003A9550 /* TreeSitterHTML in Frameworks */ = {isa = PBXBuildFile; productRef = 8E74B41C2A4C88ED003A9550 /* TreeSitterHTML */; };
8E7B0EA92A5D9BB60040DDAB /* TreeSitterTOML in Frameworks */ = {isa = PBXBuildFile; productRef = 8E7B0EA82A5D9BB60040DDAB /* TreeSitterTOML */; };
8E7B8ABD2A5D916F00CFC1A7 /* TreeSitterPython in Frameworks */ = {isa = PBXBuildFile; productRef = 8E7B8ABC2A5D916F00CFC1A7 /* TreeSitterPython */; };
Expand Down Expand Up @@ -67,6 +69,7 @@
285BF67329AAA45B00641989 /* TreeSitterLua in Frameworks */,
8E87F9542A4B7DC1008C7E13 /* TreeSitterScala in Frameworks */,
6CE117F92CEA7BDC0082D393 /* TreeSitterDart in Frameworks */,
76BC51E22F03A6D50030E59A /* TreeSitterR in Frameworks */,
2846B262296BA1CF005F60B6 /* TreeSitterDockerfile in Frameworks */,
9D73992A2A5A30A400CEF6E8 /* TreeSitterPerl in Frameworks */,
9D6E74512A2B9B2A0070701E /* TreeSitterOCaml in Frameworks */,
Expand All @@ -80,6 +83,7 @@
28B9F7AA290DDAC900245748 /* TreeSitterBash in Frameworks */,
28B3F030290C35F9000CD04D /* TreeSitterCPP in Frameworks */,
28B3F04E290C3698000CD04D /* TreeSitterJSON in Frameworks */,
76BC51E52F03ACB50030E59A /* TreeSitterXML in Frameworks */,
28B3F033290C3608000CD04D /* TreeSitterCSharp in Frameworks */,
28B3F03F290C364D000CD04D /* TreeSitterGoMod in Frameworks */,
28B3F063290C372D000CD04D /* TreeSitterZig in Frameworks */,
Expand Down Expand Up @@ -204,6 +208,8 @@
6CF2B8402CE978F100CBE5D1 /* TreeSitterDart */,
6CE117F82CEA7BDC0082D393 /* TreeSitterDart */,
6CE117FB2CEA7CF80082D393 /* TreeSitterDart */,
76BC51E12F03A6D50030E59A /* TreeSitterR */,
76BC51E42F03ACB50030E59A /* TreeSitterXML */,
);
productName = "CodeLanguages-Container";
productReference = 28B3F00C290C207D000CD04D /* CodeLanguages_Container.framework */;
Expand Down Expand Up @@ -271,6 +277,8 @@
6C0B93A62B5DD95500323006 /* XCRemoteSwiftPackageReference "tree-sitter-css" */,
6C7CA2AB2CE9743E006D9D9A /* XCRemoteSwiftPackageReference "tree-sitter-objc" */,
6CE117FA2CEA7CF80082D393 /* XCRemoteSwiftPackageReference "tree-sitter-dart" */,
76BC51E02F03A6D50030E59A /* XCRemoteSwiftPackageReference "tree-sitter-r" */,
76BC51E32F03ACB50030E59A /* XCRemoteSwiftPackageReference "tree-sitter-xml" */,
);
productRefGroup = 28B3F00D290C207D000CD04D /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -712,6 +720,22 @@
kind = branch;
};
};
76BC51E02F03A6D50030E59A /* XCRemoteSwiftPackageReference "tree-sitter-r" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/r-lib/tree-sitter-r/";
requirement = {
branch = main;
kind = branch;
};
};
76BC51E32F03ACB50030E59A /* XCRemoteSwiftPackageReference "tree-sitter-xml" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tree-sitter-grammars/tree-sitter-xml";
requirement = {
branch = master;
kind = branch;
};
};
8E74B41B2A4C88ED003A9550 /* XCRemoteSwiftPackageReference "tree-sitter-html" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tree-sitter/tree-sitter-html.git";
Expand Down Expand Up @@ -947,6 +971,16 @@
isa = XCSwiftPackageProductDependency;
productName = TreeSitterDart;
};
76BC51E12F03A6D50030E59A /* TreeSitterR */ = {
isa = XCSwiftPackageProductDependency;
package = 76BC51E02F03A6D50030E59A /* XCRemoteSwiftPackageReference "tree-sitter-r" */;
productName = TreeSitterR;
};
76BC51E42F03ACB50030E59A /* TreeSitterXML */ = {
isa = XCSwiftPackageProductDependency;
package = 76BC51E32F03ACB50030E59A /* XCRemoteSwiftPackageReference "tree-sitter-xml" */;
productName = TreeSitterXML;
};
8E74B41C2A4C88ED003A9550 /* TreeSitterHTML */ = {
isa = XCSwiftPackageProductDependency;
package = 8E74B41B2A4C88ED003A9550 /* XCRemoteSwiftPackageReference "tree-sitter-html" */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern TSLanguage *tree_sitter_ocaml_interface();
extern TSLanguage *tree_sitter_perl();
extern TSLanguage *tree_sitter_php();
extern TSLanguage *tree_sitter_python();
extern TSLanguage *tree_sitter_r();
extern TSLanguage *tree_sitter_regex();
extern TSLanguage *tree_sitter_ruby();
extern TSLanguage *tree_sitter_rust();
Expand All @@ -60,6 +61,7 @@ extern TSLanguage *tree_sitter_toml();
extern TSLanguage *tree_sitter_tsx();
extern TSLanguage *tree_sitter_typescript();
extern TSLanguage *tree_sitter_verilog();
extern TSLanguage *tree_sitter_xml();
extern TSLanguage *tree_sitter_yaml();
extern TSLanguage *tree_sitter_zig();

Expand Down
Binary file modified CodeLanguagesContainer.xcframework.zip
Binary file not shown.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ In order to add support for additional languages we have a complete guide on how
| [Perl](https://github.com/ganezdragon/tree-sitter-perl) | ✅ | _not available_ |
| [PHP](https://github.com/tree-sitter/tree-sitter-php) | ✅ | ✅ |
| [Python](https://github.com/tree-sitter/tree-sitter-python) | ✅ | ✅ |
| [R](https://github.com/r-lib/tree-sitter-r) | ✅ | ✅ |
| [Regex](https://github.com/tree-sitter/tree-sitter-regex) | ✅ | ✅ |
| [Ruby](https://github.com/mattmassicotte/tree-sitter-ruby) | ✅ | ✅ |
| [Rust](https://github.com/tree-sitter/tree-sitter-rust) | ✅ | ✅ |
Expand All @@ -82,9 +83,28 @@ In order to add support for additional languages we have a complete guide on how
| [TOML](https://github.com/cengelbart39/tree-sitter-toml/tree/feature/spm) | ✅ | ✅ |
| [TypeScript/TSX](https://github.com/tree-sitter/tree-sitter-typescript) | ✅ | ✅ |
| [Verilog](https://github.com/tree-sitter/tree-sitter-verilog) | ✅ | _not available_ |
| [XML](https://github.com/tree-sitter-grammars/tree-sitter-xml) | ✅ | ✅ |
| [YAML](https://github.com/tree-sitter-grammars/tree-sitter-yaml.git) | ✅ | ✅ |
| [Zig](https://github.com/tree-sitter-grammars/tree-sitter-zig.git) | ✅ | ✅ |

## Building the Framework

When adding new languages, you need to rebuild the binary framework using `./build_framework.sh`.

### Troubleshooting

If the build script fails with:
```
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
```

Run this command to point to your Xcode installation:
```bash
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
```

Then run `./build_framework.sh` again.

## Related Repositories

<table>
Expand Down
22 changes: 22 additions & 0 deletions Sources/CodeEditLanguages/CodeLanguage+Definitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public extension CodeLanguage {
.perl,
.php,
.python,
.r,
.regex,
.ruby,
.rust,
Expand All @@ -52,6 +53,7 @@ public extension CodeLanguage {
.tsx,
.typescript,
.verilog,
.xml,
.yaml,
.zig
]
Expand Down Expand Up @@ -354,6 +356,17 @@ public extension CodeLanguage {
additionalIdentifiers: ["python2", "python3"]
)

/// A language structure for `R`
static let r: CodeLanguage = .init(
id: .r,
tsName: "r",
extensions: ["r", "R"],
lineCommentString: "#",
rangeCommentStrings: ("", ""),
documentationCommentStrings: [.single("#'")],
additionalIdentifiers: ["Rscript"]
)

/// A language structure for `Regex`
static let regex: CodeLanguage = .init(
id: .regex,
Expand Down Expand Up @@ -462,6 +475,15 @@ public extension CodeLanguage {
highlights: ["folds", "injections"]
)

/// A language structure for `XML`
static let xml: CodeLanguage = .init(
id: .xml,
tsName: "xml",
extensions: ["xml", "xsl", "xslt", "xsd", "svg", "plist"],
lineCommentString: "",
rangeCommentStrings: ("<!--", "-->")
)

/// A language structure for `YAML`
static let yaml: CodeLanguage = .init(
id: .yaml,
Expand Down
4 changes: 4 additions & 0 deletions Sources/CodeEditLanguages/CodeLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public struct CodeLanguage {
return tree_sitter_php()
case .python:
return tree_sitter_python()
case .r:
return tree_sitter_r()
case .regex:
return tree_sitter_regex()
case .ruby:
Expand All @@ -165,6 +167,8 @@ public struct CodeLanguage {
return tree_sitter_typescript()
case .verilog:
return tree_sitter_verilog()
case .xml:
return tree_sitter_xml()
case .yaml:
return tree_sitter_yaml()
case .zig:
Expand Down
32 changes: 32 additions & 0 deletions Sources/CodeEditLanguages/Resources/tree-sitter-r/describe.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(call
function: [
(identifier) @parent_function
(namespace_operator
lhs: (identifier) @parent_pkg (#eq? @parent_pkg "testthat")
rhs: (identifier) @parent_function
)
] (#eq? @parent_function "describe")
arguments: (arguments
(argument
value: (string) @parent_desc
)
(argument
value: (braced_expression
body: (call
function: [
(identifier) @function
(namespace_operator
lhs: (identifier) @pkg (#eq? @pkg "testthat")
rhs: (identifier) @function
)
] (#eq? @function "it")
arguments: (arguments
(argument
value: (string) @desc
)
)
) @call
)
)
)
) @parent_call
112 changes: 112 additions & 0 deletions Sources/CodeEditLanguages/Resources/tree-sitter-r/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
; highlights.scm

; Literals

(integer) @number
(float) @number
(complex) @number

(string) @string
(string (string_content (escape_sequence) @string.escape))

; Comments

(comment) @comment

; Operators

[
"?" ":=" "=" "<-" "<<-" "->" "->>"
"~" "|>" "||" "|" "&&" "&"
"<" "<=" ">" ">=" "==" "!="
"+" "-" "*" "/" "::" ":::"
"**" "^" "$" "@" ":" "!"
"special"
] @operator

; Punctuation

[
"(" ")"
"{" "}"
"[" "]"
"[[" "]]"
] @punctuation.bracket

(comma) @punctuation.delimiter

; Variables

(identifier) @variable

; Functions

(binary_operator
lhs: (identifier) @function
operator: "<-"
rhs: (function_definition)
)

(binary_operator
lhs: (identifier) @function
operator: "="
rhs: (function_definition)
)

; Calls

(call function: (identifier) @function)

; Parameters

(parameters (parameter name: (identifier) @variable.parameter))
(arguments (argument name: (identifier) @variable.parameter))

; Namespace

(namespace_operator lhs: (identifier) @namespace)

(call
function: (namespace_operator rhs: (identifier) @function)
)

; Keywords

(function_definition name: "function" @keyword.function)
(function_definition name: "\\" @operator)

[
"in"
(return)
(next)
(break)
] @keyword

[
"if"
"else"
] @conditional

[
"while"
"repeat"
"for"
] @repeat

[
(true)
(false)
] @boolean

[
(null)
(inf)
(nan)
(na)
(dots)
(dot_dot_i)
] @constant.builtin

; Error

(ERROR) @error
Loading