{"id":15023675,"url":"https://github.com/faveod/ruby-tree-sitter","last_synced_at":"2025-08-09T17:25:58.587Z","repository":{"id":37095560,"uuid":"500838779","full_name":"Faveod/ruby-tree-sitter","owner":"Faveod","description":"Ruby bindings for tree-sitter","archived":false,"fork":false,"pushed_at":"2025-01-22T13:59:07.000Z","size":581,"stargazers_count":48,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T00:05:47.700Z","etag":null,"topics":["parser","ruby","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Faveod.png","metadata":{"files":{"readme":"README.md","changelog":"News.md","contributing":"docs/Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-07T12:51:09.000Z","updated_at":"2025-04-01T23:01:37.000Z","dependencies_parsed_at":"2024-01-19T19:48:59.448Z","dependency_job_id":"f62d3f33-aab2-47fb-959a-140d0c975856","html_url":"https://github.com/Faveod/ruby-tree-sitter","commit_stats":{"total_commits":589,"total_committers":7,"mean_commits":84.14285714285714,"dds":0.02376910016977929,"last_synced_commit":"b72ddff50912c7c6fc1f359a2a9ce6813f9a556e"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Faveod%2Fruby-tree-sitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Faveod%2Fruby-tree-sitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Faveod%2Fruby-tree-sitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Faveod%2Fruby-tree-sitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Faveod","download_url":"https://codeload.github.com/Faveod/ruby-tree-sitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266563,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","ruby","tree-sitter"],"created_at":"2024-09-24T19:59:19.494Z","updated_at":"2025-04-05T00:05:54.887Z","avatar_url":"https://github.com/Faveod.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ruby tree-sitter bindings\n\n[![docs](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/publish-docs.yml/badge.svg)](https://faveod.github.io/ruby-tree-sitter)\n[![rubygems.org](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/publish.yml/badge.svg)](https://rubygems.org/gems/ruby_tree_sitter)\n[![ci](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/ci.yml/badge.svg)](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/ci.yml)\n\u003c!--\n[![valgrind](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/valgrind.yml/badge.svg)](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/valgrind.yml)\n[![asan/ubsan](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/asan.yml/badge.svg)](https://github.com/Faveod/ruby-tree-sitter/actions/workflows/asan.yml)\n--\u003e\n\nRuby bindings for [tree-sitter](https://github.com/tree-sitter/tree-sitter).\n\nThe [official bindings](https://github.com/tree-sitter/ruby-tree-sitter) are\nvery old, unmaintained, and don't work with modern `tree-sitter` APIs.\n\n\n## Usage\n\n### TreeSitter API\n\nThe TreeSitter API is a low-level Ruby binding for tree-sitter.\n\n``` ruby\nrequire 'tree_sitter'\n\nparser = TreeSitter::Parser.new\nlanguage = TreeSitter::Language.load('javascript', 'path/to/libtree-sitter-javascript.{so,dylib}')\n# Or simply\nlanguage = TreeSitter.lang('javascript')\n# Which will try to look in your local directory and the system for installed parsers.\n# See TreeSitter::Mixin::Language#lib_dirs\n\nsrc = \"[1, null]\"\n\nparser.language = language\n\ntree = parser.parse_string(nil, src)\nroot = tree.root_node\n\nroot.each do |child|\n  # ...\nend\n```\n\nThe main philosophy behind the TreeSitter bindings is to do a 1:1 mapping between\ntree-sitter's `C` API and `Ruby`, which makes it easier to experiment and port\nideas from different languages/bindings.\n\nBut it feels like writing some managed `C` with `Ruby`, and that's why we provide\na high-level API ([TreeStand](#treestand-api)) as well.\n\n### TreeStand API\n\nThe TreeStand API is a high-level Ruby wrapper for the [TreeSitter](#treesitter-api) bindings. It\nmakes it easier to configure the parsers, and work with the underlying syntax tree.\n```ruby\nrequire 'tree_stand'\n\nTreeStand.configure do\n  config.parser_path = \"path/to/parser/folder/\"\nend\n\nsql_parser = TreeStand::Parser.new(\"sql\")\nruby_parser = TreeStand::Parser.new(\"ruby\")\n```\n\nTreeStand provides an idiomatic Ruby interface to work with tree-sitter parsers.\n\n## Dependencies\n\nThis gem is a binding for `tree-sitter`, and comes with a pre-built version\nof `tree-sitter` bundled with it, so you can start using it without any\nspecial configuration.\n\nWe support the following platforms:\n\n- `aarch64-linux-gnu`\n- `aarch64-linux-musl`\n- `arm-linux-gnu`\n- `arm-linux-musl`\n- `x86_64-linux-gnu`\n- `x86_64-linux-musl`\n- `x86-linux-musl`\n- `arm64-darwin`\n- `x86_64-darwin`\n\n(see [Build from source](docs/Contributing.md#build-from-source)).\n\nYou can either install `tree-sitter` from source or through your go-to package manager.\n\n### Linux\n\n`ubuntu \u003e= 22.04`\n\n```console\nsudo apt install libtree-sitter-dev\n```\n\n`arch`\n\n```console\nsudo pacman -S tree-sitter\n```\n\n### MacOS\n\n```console\nsudo port install tree-sitter\n```\n\nor\n\n```console\nbrew install tree-sitter\n```\n\n## Install\n\nFrom [rubygems](https://rubygems.org/gems/ruby_tree_sitter), in your `Gemfile`:\n\n```ruby\ngem 'ruby_tree_sitter', '~\u003e 1.6'\n```\n\nOr manually:\n\n```sh\ngem install ruby_tree_sitter\n```\n\nOr from `git` sources, which will compile on installation:\n\n```ruby\ngem 'ruby_tree_sitter', git: 'https://github.com/Faveod/ruby-tree-sitter'\n```\n\n### Enable system libraries\n\nTo install with `--enable-sys-libs`, you can either:\n\n```sh\ngem install ruby_tree_sitter --platform=ruby -- --enable-sys-libs\n```\n\nOr via bundle:\n\n```sh\nbundle config force_ruby_platform true\nbundle config set build.ruby_tree_sitter --enable-sys-libs\n```\n\n### No compilation\n\nIf you don't want to install from `rubygems`, `git`, or if you don't want to\ncompile on install, then download a native gem from this repository's\n[releases](https://github.com/Faveod/ruby-tree-sitter/releases), or you can\ncompile it yourself (see [Build from source](docs/Contributing.md#build-from-source) .)\n\nIn that case, you'd have to point your `Gemfile` to the `gem` as such:\n\n``` ruby\ngem 'tree_sitter', path: 'path/to/native/tree_sitter.gem'\n```\n\n⚠️ We're currently missing a lot of platforms and architectures. Cross-build\nwill come back in the near future.\n\n### Parsers\n\nYou will have to install parsers yourself, either by:\n\n1. Downloading and building from source.\n1. Downloading from your package manager, if available.\n1. Downloading a pre-built binary from\n   [Faveod/tree-sitter-parsers](https://github.com/Faveod/tree-sitter-parsers)\n   which supports numerous architectures.\n\n### Utilities\n\n`ruby_tree_sitter` ships with some useful utility programs to help work with parsers \u0026 queries.\n\n#### `rbts`\n\n```sh\n$ rbts --source SOURCE --query QUERY --parser PARSER\n```\n\nWatches a source and a query file and prints the matches when one of the files are updated. Uses [entr](https://github.com/eradman/entr), if available, otherwise [watch(1)](https://man7.org/linux/man-pages/man1/watch.1.html) is used by default or if --watch is specified.\n\nSee `rbts --help` for more information.\n\n## Examples\n\nSee `examples` directory.\n\n## Development\n\nSee [`docs/Contributing.md`](docs/Contributing.md).\n\n## 🚧 👷‍♀️ Notes 👷 🚧\n\nSince we're doing a 1:1 mapping between the `tree-sitter` API and the bindings,\nyou need to be extra-careful when playing with the provided objects.  Some of\nthem have their underlying `C` data-structure automatically freed, so you might\nget yourself in undesirable situations if you don't pay attention to what you're\ndoing.\n\nWe're only talking about `Tree`, `TreeCursor`, `Query`, and `QueryCursor`.  Just\ndon't copy them left and right, and then expect them to work without\n`SEGFAULT`ing and creating a black-hole in your living-room.  Assume that you\nhave to work locally with them. If you get a `SEGFAULT`, you can debug the\nnative `C` code using `gdb`.  You can read more on `SEGFAULT`s\n[here](docs/SIGSEGV.md), and debugging [here](docs/Contributing#Debugging.md).\n\nThat said, we do aim at providing an idiomatic `Ruby` interface.  It should also\nprovide a _safer_ interface, where you don't have to worry about when and how\nresources are freed.\n\nTo See a full list of the ruby-specific APIs, see [here](lib/README.md).\n\n## Sponsors\n\n- \u003ca href=\"https://faveod.com\"\u003ehttps://faveod.com\u003c/a\u003e\n\n\u003ca href=\"https://faveod.com\"\u003e\n  \u003cimg src=\"img/faveod.jpg\" width=\"66%\" /\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaveod%2Fruby-tree-sitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaveod%2Fruby-tree-sitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaveod%2Fruby-tree-sitter/lists"}