{"id":13762485,"url":"https://github.com/tree-sitter/rust-tree-sitter","last_synced_at":"2025-09-29T12:31:48.713Z","repository":{"id":146732791,"uuid":"133870330","full_name":"tree-sitter/rust-tree-sitter","owner":"tree-sitter","description":"Rust bindings to Tree-sitter","archived":true,"fork":false,"pushed_at":"2019-02-06T01:52:04.000Z","size":49,"stargazers_count":31,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-27T10:22:14.865Z","etag":null,"topics":["binding","rust","tree-sitter"],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/tree-sitter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2018-05-17T21:29:21.000Z","updated_at":"2024-09-22T05:39:30.000Z","dependencies_parsed_at":"2024-08-03T14:05:18.913Z","dependency_job_id":null,"html_url":"https://github.com/tree-sitter/rust-tree-sitter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Frust-tree-sitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Frust-tree-sitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Frust-tree-sitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Frust-tree-sitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tree-sitter","download_url":"https://codeload.github.com/tree-sitter/rust-tree-sitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234619536,"owners_count":18861456,"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":["binding","rust","tree-sitter"],"created_at":"2024-08-03T14:00:44.310Z","updated_at":"2025-09-29T12:31:48.426Z","avatar_url":"https://github.com/tree-sitter.png","language":"Rust","funding_links":[],"categories":["Language bindings"],"sub_categories":["Others"],"readme":"Rust Tree-sitter\n===========================\n\n-----\n\n:warning: This repository is *deprecated* :warning:\n\nThe Rust binding to Tree-sitter has been moved to [the main Tree-sitter repo](https://github.com/tree-sitter/tree-sitter).\n\n-----\n\n\n[![Build Status](https://travis-ci.org/tree-sitter/rust-tree-sitter.svg)](https://travis-ci.org/tree-sitter/rust-tree-sitter)\n[![Build status](https://ci.appveyor.com/api/projects/status/d0f6vqq3rflxx3y6/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/rust-tree-sitter/branch/master)\n[![Crates.io](https://img.shields.io/crates/v/tree-sitter.svg)](https://crates.io/crates/tree-sitter)\n\nRust bindings to the [Tree-sitter][] parsing library.\n\n### Basic Usage\n\nFirst, create a parser:\n\n```rust\nuse tree_sitter::{Parser, Language};\n\n// ...\n\nlet mut parser = Parser::new();\n```\n\nThen assign a language to the parser. Tree-sitter languages consist of generated C code. To use them from rust, you must declare them as `extern \"C\"` functions and invoke them with `unsafe`:\n\n```rust\nextern \"C\" { fn tree_sitter_c() -\u003e Language; }\nextern \"C\" { fn tree_sitter_rust() -\u003e Language; }\nextern \"C\" { fn tree_sitter_javascript() -\u003e Language; }\n\nlet language = unsafe { tree_sitter_rust() };\nparser.set_language(language).unwrap();\n```\n\nNow you can parse source code:\n\n```rust\nlet source_code = \"fn test() {}\";\nlet tree = parser.parse_str(source_code, None);\nlet root_node = tree.root_node();\n\nassert_eq!(root_node.kind(), \"source_file\");\nassert_eq!(root_node.start_position().column, 0);\nassert_eq!(root_node.end_position().column, 12);\n```\n\n### Editing\n\nOnce you have a syntax tree, you can update it when your source code changes. Passing in the previous edited tree makes `parse` run much more quickly:\n\n```rust\nlet new_source_code = \"fn test(a: u32) {}\"\n\ntree.edit(InputEdit {\n  start_byte: 8,\n  old_end_byte: 8,\n  new_end_byte: 14,\n  start_position: Point::new(0, 8),\n  old_end_position: Point::new(0, 8),\n  new_end_position: Point::new(0, 14),\n});\n\nlet new_tree = parser.parse_str(new_source_code, Some(\u0026tree));\n```\n\n### Text Input\n\nThe source code to parse can be provided either as a string or as a function that returns text encoded as either UTF8 or UTF16:\n\n```rust\n// Store some source code in an array of lines.\nlet lines = \u0026[\n    \"pub fn foo() {\",\n    \"  1\",\n    \"}\",\n];\n\n// Parse the source code using a custom callback. The callback is called\n// with both a byte offset and a row/column offset.\nlet tree = parser.parse_utf8(\u0026mut |_byte: u32, position: Point| -\u003e \u0026[u8] {\n    let row = position.row as usize;\n    let column = position.column as usize;\n    if row \u003c lines.len() {\n        if column \u003c lines[row].as_bytes().len() {\n            \u0026lines[row].as_bytes()[column..]\n        } else {\n            \"\\n\".as_bytes()\n        }\n    } else {\n        \u0026[]\n    }\n}, None).unwrap();\n\nassert_eq!(\n  tree.root_node().to_sexp(),\n  \"(source_file (function_item (visibility_modifier) (identifier) (parameters) (block (number_literal))))\"\n);\n```\n\n[tree-sitter]: https://github.com/tree-sitter/tree-sitter\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftree-sitter%2Frust-tree-sitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftree-sitter%2Frust-tree-sitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftree-sitter%2Frust-tree-sitter/lists"}