Swift wrappers for the tree-sitter incremental parsing system

What's New


  • Add some more NSRange APIs
  • ResolvingQueryCursor
  • Facility for QueryCursor to hold a reference to the Tree being queried

Build Status License Platforms


Swift wrappers for the tree-sitter incremental parsing system.

SwiftTreeSitter is fairly low-level. If you are looking a higher-level system for syntax highlighting and other syntactic operations, you might want to have a look at Neon.


Swift Package Manager

dependencies: [
    .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter")

Predicate/Directive Support

QueryMatch provides an API for getting at query predicates and directives. You are free to use/evaluate them yourself. However, there is also a ResolvingQueryCursor, which wraps a standard QueryCursor, but allows for resolution of predicates. It also provides some facilities for preloading all QueryMatch objects from the underlying QueryCursor, which can help with performance in some situations.

The following predicates are parsed and transformed into structured Predicate cases. All others are turned into the generic case.

  • eq?: fully supported
  • match?: fully supported
  • is-not?: parsed, but not implemented

Please open up an issue if you need additional support here.

Runtime/Parser Dependencies

Remember that tree-sitter has both runtime and per-language dependencies. SwiftTreeSitter now depends on tree-sitter-xcframework, which provides pre-built binaries for the runtime and some parsers. If you need support for parsers not included in that project, the best best is to try to add them!

But, that is not necessary - you can build and link parsers manually.

Note: These instructions assume a macOS target. Also, I've only tested tree-sitter down to 10.13. I suspect it will work with lower targets, but have not tried.


Check out and build tree-sitter from source.

CFLAGS="-arch arm64 -arch x86_64 -mmacosx-version-min=10.13" CXXFLAGS="-arch arm64 -arch x86_64 -mmacosx-version-min=10.13" LDFLAGS="-arch arm64 -arch x86_64 -mmacosx-version-min=10.13" make


Install it into /usr/local.

sudo make install PREFIX=/usr/local

Building Language Libraries

In addition to the runtime, you'll probably also want at least one language library. These are more complex to build than the runtime. In fact, I've struggled with them so much that I began adapting the runtime's Makefile for the parsers themselves. This is a work-in-progress. But, if the parser you'd like to use doesn't have a Makefile, let me know and I'll help get it set up.

And, if the parser does have a Makefile, then the process is identical to the runtime above.

Suggestions or Feedback

We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


  • Swift Tools 5.0.0
View More Packages from this Author


Last updated: Tue May 17 2022 19:07:23 GMT-0500 (GMT-05:00)