Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ERB/EJS Grammar #61

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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 @@ -38,6 +38,7 @@
8E87F9542A4B7DC1008C7E13 /* TreeSitterScala in Frameworks */ = {isa = PBXBuildFile; productRef = 8E87F9532A4B7DC1008C7E13 /* TreeSitterScala */; };
8ED0560A2A4DBE6E00829B80 /* TreeSitterTypeScript in Frameworks */ = {isa = PBXBuildFile; productRef = 8ED056092A4DBE6E00829B80 /* TreeSitterTypeScript */; };
8EFA0B742A559F4C00021CE9 /* TreeSitterSQL in Frameworks */ = {isa = PBXBuildFile; productRef = 8EFA0B732A559F4C00021CE9 /* TreeSitterSQL */; };
9D01902E2BEA98B2001DFE97 /* TreeSitterEmbeddedTemplate in Frameworks */ = {isa = PBXBuildFile; productRef = 9D01902D2BEA98B2001DFE97 /* TreeSitterEmbeddedTemplate */; };
9D6E74512A2B9B2A0070701E /* TreeSitterOCaml in Frameworks */ = {isa = PBXBuildFile; productRef = 9D6E74502A2B9B2A0070701E /* TreeSitterOCaml */; };
9D7399242A5A245000CEF6E8 /* TreeSitterAgda in Frameworks */ = {isa = PBXBuildFile; productRef = 9D7399232A5A245000CEF6E8 /* TreeSitterAgda */; };
9D7399272A5A2B5300CEF6E8 /* TreeSitterJulia in Frameworks */ = {isa = PBXBuildFile; productRef = 9D7399262A5A2B5300CEF6E8 /* TreeSitterJulia */; };
Expand Down Expand Up @@ -83,6 +84,7 @@
9D7399272A5A2B5300CEF6E8 /* TreeSitterJulia in Frameworks */,
8E74B41D2A4C88ED003A9550 /* TreeSitterHTML in Frameworks */,
8ED0560A2A4DBE6E00829B80 /* TreeSitterTypeScript in Frameworks */,
9D01902E2BEA98B2001DFE97 /* TreeSitterEmbeddedTemplate in Frameworks */,
28B3F05A290C36E5000CD04D /* TreeSitterRust in Frameworks */,
28AAB6AE29CA57D40087654B /* TreeSitterDart in Frameworks */,
28171CB829814CD800523F1C /* TreeSitterObjC in Frameworks */,
Expand Down Expand Up @@ -208,6 +210,7 @@
8E7B0EA82A5D9BB60040DDAB /* TreeSitterTOML */,
9D920B972A93B248004E4451 /* TreeSitterJSDoc */,
6C0B93A72B5DD95500323006 /* TreeSitterCSS */,
9D01902D2BEA98B2001DFE97 /* TreeSitterEmbeddedTemplate */,
);
productName = "CodeLanguages-Container";
productReference = 28B3F00C290C207D000CD04D /* CodeLanguages_Container.framework */;
Expand Down Expand Up @@ -275,6 +278,7 @@
8E7B0EA72A5D9BB60040DDAB /* XCRemoteSwiftPackageReference "tree-sitter-toml" */,
9D920B962A93B248004E4451 /* XCRemoteSwiftPackageReference "tree-sitter-jsdoc" */,
6C0B93A62B5DD95500323006 /* XCRemoteSwiftPackageReference "tree-sitter-css" */,
9D01902C2BEA98B2001DFE97 /* XCRemoteSwiftPackageReference "tree-sitter-embedded-template" */,
);
productRefGroup = 28B3F00D290C207D000CD04D /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -764,6 +768,14 @@
kind = branch;
};
};
9D01902C2BEA98B2001DFE97 /* XCRemoteSwiftPackageReference "tree-sitter-embedded-template" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tree-sitter/tree-sitter-embedded-template.git";
requirement = {
branch = master;
kind = branch;
};
};
9D6E744F2A2B9B2A0070701E /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tree-sitter/tree-sitter-ocaml.git";
Expand Down Expand Up @@ -973,6 +985,11 @@
package = 8EFA0B722A559F4C00021CE9 /* XCRemoteSwiftPackageReference "tree-sitter-sql" */;
productName = TreeSitterSQL;
};
9D01902D2BEA98B2001DFE97 /* TreeSitterEmbeddedTemplate */ = {
isa = XCSwiftPackageProductDependency;
package = 9D01902C2BEA98B2001DFE97 /* XCRemoteSwiftPackageReference "tree-sitter-embedded-template" */;
productName = TreeSitterEmbeddedTemplate;
};
9D6E74502A2B9B2A0070701E /* TreeSitterOCaml */ = {
isa = XCSwiftPackageProductDependency;
package = 9D6E744F2A2B9B2A0070701E /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
"revision" : "11426c5fd20eef360d5ecaf10729191f6bc5d715"
}
},
{
"identity" : "tree-sitter-embedded-template",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tree-sitter/tree-sitter-embedded-template.git",
"state" : {
"branch" : "master",
"revision" : "ffbf64942c334933ee7982e144557b6efb76d0b9"
}
},
{
"identity" : "tree-sitter-go",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern TSLanguage *tree_sitter_css();
extern TSLanguage *tree_sitter_dart();
extern TSLanguage *tree_sitter_dockerfile();
extern TSLanguage *tree_sitter_elixir();
extern TSLanguage *tree_sitter_embedded_template();
extern TSLanguage *tree_sitter_go();
extern TSLanguage *tree_sitter_gomod();
extern TSLanguage *tree_sitter_haskell();
Expand Down
Binary file modified CodeLanguagesContainer.xcframework.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/SwiftTreeSitter.git",
"state" : {
"revision" : "2599e95310b3159641469d8a21baf2d3d200e61f",
"version" : "0.8.0"
"revision" : "df25a52f72ebc5b50ae20d26d1363793408bb28b",
"version" : "0.7.1"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ In order to add support for additional languages we have a complete guide on how
| [Dart](https://github.com/lukepistrol/tree-sitter-dart/tree/feature/spm) | ✅ | ✅ |
| [Dockerfile](https://github.com/camdencheek/tree-sitter-dockerfile) | ✅ | ✅ |
| [Elixir](https://github.com/elixir-lang/tree-sitter-elixir) | ✅ | ✅ |
| [ERB, EJS](https://github.com/tree-sitter/tree-sitter-embedded-template) | | |
| [ERB, EJS](https://github.com/tree-sitter/tree-sitter-embedded-template) | | |
| [Go](https://github.com/tree-sitter/tree-sitter-go) | ✅ | ✅ |
| [Haskell](https://github.com/tree-sitter/tree-sitter-haskell) | ✅ | ✅ |
| [HTML](https://github.com/tree-sitter/tree-sitter-html) | ✅ | ✅ |
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 @@ -21,7 +21,9 @@ public extension CodeLanguage {
.css,
.dart,
.dockerfile,
.ejs,
.elixir,
.erb,
.go,
.goMod,
.haskell,
Expand Down Expand Up @@ -131,6 +133,16 @@ public extension CodeLanguage {
rangeCommentStrings: ("", "")
)

/// A language structure for `EJS`
static let ejs: CodeLanguage = .init(
id: .ejs,
tsName: "embedded-template",
extensions: ["ejs"],
lineCommentString: "",
rangeCommentStrings: ("", ""),
highlights: ["injections-ejs"]
)

/// A language structure for `Elixir`
static let elixir: CodeLanguage = .init(
id: .elixir,
Expand All @@ -142,6 +154,16 @@ public extension CodeLanguage {
highlights: ["injections"]
)

/// A language structure for `ERB`
static let erb: CodeLanguage = .init(
id: .erb,
tsName: "embedded-template",
extensions: ["erb"],
lineCommentString: "",
rangeCommentStrings: ("", ""),
highlights: ["injections-erb"]
)

/// A language structure for `Go`
static let go: CodeLanguage = .init(
id: .go,
Expand Down
4 changes: 4 additions & 0 deletions Sources/CodeEditLanguages/CodeLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ public struct CodeLanguage {
return tree_sitter_dart()
case .dockerfile:
return tree_sitter_dockerfile()
case .ejs:
return tree_sitter_embedded_template()
case .elixir:
return tree_sitter_elixir()
case .erb:
return tree_sitter_embedded_template()
case .go:
return tree_sitter_go()
case .goMod:
Expand Down
9 changes: 9 additions & 0 deletions Sources/CodeEditLanguages/Documentation.docc/CodeLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- CSS
- Dart
- Dockerfile
- EJS
- Elixir
- ERB
- Go
- Go Mod
- Haskell
Expand Down Expand Up @@ -84,7 +86,9 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- ``css``
- ``dart``
- ``dockerfile``
- ``ejs``
- ``elixir``
- ``erb``
- ``go``
- ``goMod``
- ``haskell``
Expand All @@ -100,15 +104,20 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- ``markdown``
- ``markdownInline``
- ``objc``
- ``ocaml``
- ``ocamlInterface``
- ``perl``
- ``php``
- ``python``
- ``regex``
- ``ruby``
- ``rust``
- ``scala``
- ``sql``
- ``swift``
- ``toml``
- ``tsx``
- ``typescript``
- ``verilog``
- ``yaml``
- ``zig``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ let query = TreeSitterModel.shared.swiftQuery
- ``cssQuery``
- ``dartQuery``
- ``dockerfileQuery``
- ``ejsQuery``
- ``elixirQuery``
- ``erbQuery``
- ``goQuery``
- ``goModQuery``
- ``haskellQuery``
Expand All @@ -58,11 +60,14 @@ let query = TreeSitterModel.shared.swiftQuery
- ``ocamlInterfaceQuery``
- ``phpQuery``
- ``pythonQuery``
- ``regexQuery``
- ``rubyQuery``
- ``rustQuery``
- ``scalaQuery``
- ``sqlQuery``
- ``swiftQuery``
- ``tomlQuery``
- ``tsxQuery``
- ``typescriptQuery``
- ``yamlQuery``
- ``zigQuery``
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(comment_directive) @comment

[
"<%#"
"<%"
"<%="
"<%_"
"<%-"
"%>"
"-%>"
"_%>"
] @keyword
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
((content) @injection.content
(#set! injection.language "html")
(#set! injection.combined))

((code) @injection.content
(#set! injection.language "javascript")
(#set! injection.combined))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
((content) @injection.content
(#set! injection.language "html")
(#set! injection.combined))

((code) @injection.content
(#set! injection.language "ruby")
(#set! injection.combined))
2 changes: 2 additions & 0 deletions Sources/CodeEditLanguages/TreeSitterLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public enum TreeSitterLanguage: String {
case css
case dart
case dockerfile
case ejs
case elixir
case erb
case go
case goMod
case haskell
Expand Down
14 changes: 14 additions & 0 deletions Sources/CodeEditLanguages/TreeSitterModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public class TreeSitterModel {
return dartQuery
case .dockerfile:
return dockerfileQuery
case .ejs:
return ejsQuery
case .elixir:
return elixirQuery
case .erb:
return erbQuery
case .go:
return goQuery
case .goMod:
Expand Down Expand Up @@ -142,11 +146,21 @@ public class TreeSitterModel {
return queryFor(.dockerfile)
}()

/// Query for `EJS` files.
public private(set) lazy var ejsQuery: Query? = {
return queryFor(.ejs)
}()

/// Query for `Elixir` files.
public private(set) lazy var elixirQuery: Query? = {
return queryFor(.elixir)
}()

/// Query for `ERB` files.
public private(set) lazy var erbQuery: Query? = {
return queryFor(.erb)
}()

/// Query for `Go` files.
public private(set) lazy var goQuery: Query? = {
return queryFor(.go)
Expand Down
38 changes: 38 additions & 0 deletions Tests/CodeEditLanguagesTests/CodeEditLanguagesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,25 @@ final class CodeEditLanguagesTests: XCTestCase {
XCTAssertNotEqual(query?.patternCount, 0)
}

// MARK: - EJS

func test_CodeLanguageEJS() throws {
let url = URL(fileURLWithPath: "~/path/to/file.ejs")
let language = CodeLanguage.detectLanguageFrom(url: url)

XCTAssertEqual(language.id, .ejs)
}

func test_FetchQueryEJS() throws {
var language = CodeLanguage.ejs
language.resourceURL = bundleURL

let data = try Data(contentsOf: language.queryURL!)
let query = try? Query(language: language.language!, data: data)
XCTAssertNotNil(query)
XCTAssertNotEqual(query?.patternCount, 0)
}

// MARK: - Elixir

func test_CodeLanguageElixir() throws {
Expand All @@ -202,6 +221,25 @@ final class CodeEditLanguagesTests: XCTestCase {
XCTAssertNotEqual(query?.patternCount, 0)
}

// MARK: - ERB

func test_CodeLanguageERB() throws {
let url = URL(fileURLWithPath: "~/path/to/file.erb")
let language = CodeLanguage.detectLanguageFrom(url: url)

XCTAssertEqual(language.id, .erb)
}

func test_FetchQueryERB() throws {
var language = CodeLanguage.erb
language.resourceURL = bundleURL

let data = try Data(contentsOf: language.queryURL!)
let query = try? Query(language: language.language!, data: data)
XCTAssertNotNil(query)
XCTAssertNotEqual(query?.patternCount, 0)
}

// MARK: - Go

func test_CodeLanguageGo() throws {
Expand Down
Loading