You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/binding_rust/README.md
+15-26Lines changed: 15 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
8
8
Rust bindings to the [Tree-sitter][] parsing library.
9
9
10
-
###Basic Usage
10
+
## Basic Usage
11
11
12
12
First, create a parser:
13
13
@@ -17,38 +17,25 @@ use tree_sitter::{Parser, Language};
17
17
letmutparser=Parser::new();
18
18
```
19
19
20
-
Tree-sitter languages consist of generated C code. To make sure they're properly compiled and linked, you can create a [build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html) like the following (assuming `tree-sitter-javascript` is in your root directory):
Add the `cc` crate to your `Cargo.toml` under `[build-dependencies]`:
37
21
38
22
```toml
39
23
[build-dependencies]
40
24
cc="*"
41
25
```
42
26
43
-
To then use languages from rust, you must declare them as `extern "C"` functions and invoke them with `unsafe`. Then you can assign them to the parser.
Once 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:
55
+
Once you have a syntax tree, you can update it when your source code changes.
56
+
Passing in the previous edited tree makes `parse` run much more quickly:
69
57
70
58
```rust
71
59
letnew_source_code="fn test(a: u32) {}"
@@ -84,7 +72,8 @@ let new_tree = parser.parse(new_source_code, Some(&tree));
84
72
85
73
### Text Input
86
74
87
-
The source code to parse can be provided either as a string, a slice, a vector, or as a function that returns a slice. The text can be encoded as either UTF8 or UTF16:
75
+
The source code to parse can be provided either as a string, a slice, a vector,
76
+
or as a function that returns a slice. The text can be encoded as either UTF8 or UTF16:
0 commit comments