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
Then, you can call `ts_parser_parse` again, passing in the old tree. This will create a new tree that internally shares structure with the old tree.
238
238
239
+
## Multi-language Documents
240
+
241
+
Sometimes, different parts of a file may be written in different languages. For example, templating languages like [EJS](http://ejs.co) and [ERB](https://ruby-doc.org/stdlib-2.5.1/libdoc/erb/rdoc/ERB.html) allow you to generate HTML by writing a mixture of HTML and another language like JavaScript or Ruby.
242
+
243
+
Tree-sitter handles these types of documents by allowing you to create a syntax tree based on the text in certain *ranges* of a file.
244
+
245
+
```c
246
+
typedef struct {
247
+
TSPoint start_point;
248
+
TSPoint end_point;
249
+
uint32_t start_byte;
250
+
uint32_t end_byte;
251
+
} TSRange;
252
+
253
+
void ts_parser_set_included_ranges(
254
+
TSParser *self,
255
+
const TSRange *ranges,
256
+
uint32_t range_count
257
+
);
258
+
```
259
+
260
+
For example, consider this ERB document:
261
+
262
+
```erb
263
+
<ul>
264
+
<% people.each do |person| %>
265
+
<li><%= person.name %></li>
266
+
<% end %>
267
+
</ul>
268
+
```
269
+
270
+
Conceptually, it can be represented by three syntax trees with overlapping ranges: an ERB syntax tree, a Ruby syntax tree, and an HTML syntax tree. You could generate these syntax trees as follows:
271
+
272
+
```c
273
+
#include<string.h>
274
+
#include<tree_sitter/runtime.h>
275
+
276
+
// These functions are each implemented in their own repo.
0 commit comments