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.
dependencies: [
.package(url: "https://github.com/ChimeHQ/SwiftTreeSitter")
]
Remember that tree-sitter has both runtime and per-language dependencies.
This library has gone through a variety of iterations on how these dependencies should be integrated. The tree-sitter-xcframework was created to help package everything up in a way that was totally transparent.
However, it turns out that it is possible to use SPM to build the runtime and (with a little more work) the parsers too. SwiftTreeSitter currently depends on a branch I created for tree-sitter as an SPM package. But as soon as this PR is merged, it can be switched to the official repo directly.
In addition to the runtime, you'll probably also want at least one language library. They can also be built with SPM, though they are more complex. If you would like SPM support for parser that doesn't have it yet, let me know and I'll help!
Parsers available via SPM:
While SPM is nice, it isn't a requirement. You can also build them yourself directly. In fact, I've struggled with this 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.
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 supportednot-eq?
: fully supportedmatch?
: fully supportednot-match?
: fully supportedany-of?
: fully supportednot-any-of?
: fully supportedis-not?
: parsed, but not implementedPlease open up an issue if you need additional support here.
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.
link |
Stars: 91 |
Last commit: 3 hours ago |
Int
for Point
and InputEdit
to improve ergonomicsNode
and QueryCapture
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics