Rizin
unix-like reverse engineering framework and cli tools
api.h
Go to the documentation of this file.
1 #ifndef TREE_SITTER_API_H_
2 #define TREE_SITTER_API_H_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stdint.h>
11 #include <stdbool.h>
12 
13 /****************************/
14 /* Section - ABI Versioning */
15 /****************************/
16 
24 #define TREE_SITTER_LANGUAGE_VERSION 14
25 
30 #define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13
31 
32 /*******************/
33 /* Section - Types */
34 /*******************/
35 
38 typedef struct TSLanguage TSLanguage;
39 typedef struct TSParser TSParser;
40 typedef struct TSTree TSTree;
41 typedef struct TSQuery TSQuery;
42 typedef struct TSQueryCursor TSQueryCursor;
43 
44 typedef enum {
48 
49 typedef enum {
53 } TSSymbolType;
54 
55 typedef struct {
58 } TSPoint;
59 
60 typedef struct {
65 } TSRange;
66 
67 typedef struct {
68  void *payload;
69  const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
71 } TSInput;
72 
73 typedef enum {
76 } TSLogType;
77 
78 typedef struct {
79  void *payload;
80  void (*log)(void *payload, TSLogType, const char *);
81 } TSLogger;
82 
83 typedef struct {
90 } TSInputEdit;
91 
92 typedef struct {
94  const void *id;
95  const TSTree *tree;
96 } TSNode;
97 
98 typedef struct {
99  const void *tree;
100  const void *id;
102 } TSTreeCursor;
103 
104 typedef struct {
108 
109 typedef enum {
110  TSQuantifierZero = 0, // must match the array initialization value
115 } TSQuantifier;
116 
117 typedef struct {
122 } TSQueryMatch;
123 
124 typedef enum {
129 
130 typedef struct {
134 
135 typedef enum {
143 } TSQueryError;
144 
145 /********************/
146 /* Section - Parser */
147 /********************/
148 
152 TSParser *ts_parser_new(void);
153 
158 
169 bool ts_parser_set_language(TSParser *self, const TSLanguage *language);
170 
174 const TSLanguage *ts_parser_language(const TSParser *self);
175 
198  TSParser *self,
199  const TSRange *ranges,
201 );
202 
211  const TSParser *self,
213 );
214 
254  TSParser *self,
255  const TSTree *old_tree,
256  TSInput input
257 );
258 
266  TSParser *self,
267  const TSTree *old_tree,
268  const char *string,
270 );
271 
279  TSParser *self,
280  const TSTree *old_tree,
281  const char *string,
284 );
285 
295 void ts_parser_reset(TSParser *self);
296 
305 
310 
318 void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag);
319 
323 const size_t *ts_parser_cancellation_flag(const TSParser *self);
324 
332 void ts_parser_set_logger(TSParser *self, TSLogger logger);
333 
337 TSLogger ts_parser_logger(const TSParser *self);
338 
345 void ts_parser_print_dot_graphs(TSParser *self, int file);
346 
347 /******************/
348 /* Section - Tree */
349 /******************/
350 
357 TSTree *ts_tree_copy(const TSTree *self);
358 
362 void ts_tree_delete(TSTree *self);
363 
367 TSNode ts_tree_root_node(const TSTree *self);
368 
372 const TSLanguage *ts_tree_language(const TSTree *);
373 
381 void ts_tree_edit(TSTree *self, const TSInputEdit *edit);
382 
398  const TSTree *old_tree,
399  const TSTree *new_tree,
401 );
402 
406 void ts_tree_print_dot_graph(const TSTree *, FILE *);
407 
408 /******************/
409 /* Section - Node */
410 /******************/
411 
415 const char *ts_node_type(TSNode);
416 
421 
426 
431 
436 
441 
448 char *ts_node_string(TSNode);
449 
455 bool ts_node_is_null(TSNode);
456 
463 
469 
475 
480 
485 
490 
496 
502 
507 
514 
521 
526  TSNode self,
527  const char *field_name,
528  uint32_t field_name_length
529 );
530 
538 
544 
550 
555 
560 
567 
574 
584 void ts_node_edit(TSNode *, const TSInputEdit *);
585 
589 bool ts_node_eq(TSNode, TSNode);
590 
591 /************************/
592 /* Section - TreeCursor */
593 /************************/
594 
603 
608 
613 
618 
626 
634 
642 
650 
658 
668 
670 
671 /*******************/
672 /* Section - Query */
673 /*******************/
674 
687  const TSLanguage *language,
688  const char *source,
689  uint32_t source_len,
690  uint32_t *error_offset,
691  TSQueryError *error_type
692 );
693 
697 void ts_query_delete(TSQuery *);
698 
705 
713 
731  const TSQuery *self,
732  uint32_t pattern_index,
734 );
735 
737  const TSQuery *self,
738  uint32_t byte_offset
739 );
740 
746 const char *ts_query_capture_name_for_id(
747  const TSQuery *,
748  uint32_t id,
750 );
751 
757  const TSQuery *,
758  uint32_t pattern_id,
759  uint32_t capture_id
760 );
761 
762 const char *ts_query_string_value_for_id(
763  const TSQuery *,
764  uint32_t id,
766 );
767 
775 void ts_query_disable_capture(TSQuery *, const char *, uint32_t);
776 
784 
808 
813 
818 
833 
840 
849 
857  TSQueryCursor *,
859  uint32_t *capture_index
860 );
861 
862 /**********************/
863 /* Section - Language */
864 /**********************/
865 
870 
874 const char *ts_language_symbol_name(const TSLanguage *, TSSymbol);
875 
880  const TSLanguage *self,
881  const char *string,
883  bool is_named
884 );
885 
890 
895 
900 
908 
917 
918 /**********************************/
919 /* Section - Global Configuration */
920 /**********************************/
921 
938 void ts_set_allocator(
939  void *(*new_malloc)(size_t),
940  void *(*new_calloc)(size_t, size_t),
941  void *(*new_realloc)(void *, size_t),
942  void (*new_free)(void *)
943 );
944 
945 #ifdef __cplusplus
946 }
947 #endif
948 
949 #endif // TREE_SITTER_API_H_
void ts_query_cursor_exec(TSQueryCursor *, const TSQuery *, TSNode)
Definition: query.c:2859
TSNode ts_node_descendant_for_byte_range(TSNode, uint32_t, uint32_t)
Definition: node.c:644
bool ts_node_has_changes(TSNode)
Definition: node.c:453
TSQuantifier ts_query_capture_quantifier_for_id(const TSQuery *, uint32_t pattern_id, uint32_t capture_id)
Definition: query.c:2717
const char * ts_node_type(TSNode)
Definition: node.c:420
void ts_tree_edit(TSTree *self, const TSInputEdit *edit)
Definition: tree.c:44
TSLogger ts_parser_logger(const TSParser *self)
Definition: parser.c:1775
TSRange * ts_tree_get_changed_ranges(const TSTree *old_tree, const TSTree *new_tree, uint32_t *length)
Definition: tree.c:78
TSNode ts_node_child_by_field_id(TSNode, TSFieldId)
Definition: node.c:500
TSTree * ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input)
Definition: parser.c:1844
void ts_query_cursor_set_match_limit(TSQueryCursor *, uint32_t)
Definition: query.c:2855
TSQueryError
Definition: api.h:135
@ TSQueryErrorLanguage
Definition: api.h:142
@ TSQueryErrorSyntax
Definition: api.h:137
@ TSQueryErrorNodeType
Definition: api.h:138
@ TSQueryErrorNone
Definition: api.h:136
@ TSQueryErrorField
Definition: api.h:139
@ TSQueryErrorStructure
Definition: api.h:141
@ TSQueryErrorCapture
Definition: api.h:140
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *)
Definition: tree_cursor.c:206
TSNode ts_node_first_named_child_for_byte(TSNode, uint32_t)
Definition: node.c:640
TSQueryPredicateStepType
Definition: api.h:124
@ TSQueryPredicateStepTypeString
Definition: api.h:127
@ TSQueryPredicateStepTypeDone
Definition: api.h:125
@ TSQueryPredicateStepTypeCapture
Definition: api.h:126
void ts_parser_delete(TSParser *parser)
Definition: parser.c:1725
void ts_tree_cursor_delete(TSTreeCursor *)
Definition: tree_cursor.c:94
const TSRange * ts_parser_included_ranges(const TSParser *self, uint32_t *length)
Definition: parser.c:1819
TSLogType
Definition: api.h:73
@ TSLogTypeLex
Definition: api.h:75
@ TSLogTypeParse
Definition: api.h:74
const char * ts_query_string_value_for_id(const TSQuery *, uint32_t id, uint32_t *length)
Definition: query.c:2726
void ts_tree_print_dot_graph(const TSTree *, FILE *)
Definition: tree.c:103
TSNode ts_node_named_child(TSNode, uint32_t)
Definition: node.c:496
bool ts_node_is_extra(TSNode)
Definition: node.c:438
TSNode ts_node_next_named_sibling(TSNode)
Definition: node.c:624
uint32_t ts_node_start_byte(TSNode)
Definition: node.c:36
char * ts_node_string(TSNode)
Definition: node.c:426
TSNode ts_node_child(TSNode, uint32_t)
Definition: node.c:492
uint32_t ts_node_named_child_count(TSNode)
Definition: node.c:611
void ts_parser_reset(TSParser *self)
Definition: parser.c:1823
void ts_tree_cursor_reset(TSTreeCursor *, TSNode)
Definition: tree_cursor.c:76
const char * ts_node_field_name_for_child(TSNode, uint32_t)
Definition: node.c:572
bool ts_node_is_null(TSNode)
Definition: node.c:434
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *)
Definition: query.c:2847
TSQuery * ts_query_new(const TSLanguage *language, const char *source, uint32_t source_len, uint32_t *error_offset, TSQueryError *error_type)
Definition: query.c:2546
uint32_t ts_query_string_count(const TSQuery *)
Definition: query.c:2705
uint64_t ts_parser_timeout_micros(const TSParser *self)
Definition: parser.c:1803
const TSLanguage * ts_tree_language(const TSTree *)
Definition: tree.c:40
TSTree * ts_tree_copy(const TSTree *self)
Definition: tree.c:21
uint32_t ts_query_pattern_count(const TSQuery *)
Definition: query.c:2697
const size_t * ts_parser_cancellation_flag(const TSParser *self)
Definition: parser.c:1795
void ts_query_cursor_set_byte_range(TSQueryCursor *, uint32_t, uint32_t)
Definition: query.c:2876
TSNode ts_node_prev_named_sibling(TSNode)
Definition: node.c:632
TSNode ts_node_prev_sibling(TSNode)
Definition: node.c:628
TSNode ts_node_child_by_field_name(TSNode self, const char *field_name, uint32_t field_name_length)
Definition: node.c:589
TSSymbol ts_node_symbol(TSNode)
Definition: node.c:414
TSQuantifier
Definition: api.h:109
@ TSQuantifierZeroOrMore
Definition: api.h:112
@ TSQuantifierZeroOrOne
Definition: api.h:111
@ TSQuantifierZero
Definition: api.h:110
@ TSQuantifierOneOrMore
Definition: api.h:114
@ TSQuantifierOne
Definition: api.h:113
void ts_tree_delete(TSTree *self)
Definition: tree.c:26
void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout)
Definition: parser.c:1807
uint16_t TSFieldId
Definition: api.h:37
void ts_node_edit(TSNode *, const TSInputEdit *)
Definition: node.c:676
bool ts_parser_set_included_ranges(TSParser *self, const TSRange *ranges, uint32_t length)
Definition: parser.c:1811
void ts_query_cursor_delete(TSQueryCursor *)
Definition: query.c:2839
uint32_t ts_query_start_byte_for_pattern(const TSQuery *, uint32_t)
Definition: query.c:2747
TSPoint ts_node_start_point(TSNode)
Definition: node.c:40
TSFieldId ts_language_field_id_for_name(const TSLanguage *, const char *, uint32_t)
Definition: language.c:119
const char * ts_language_symbol_name(const TSLanguage *, TSSymbol)
Definition: language.c:59
void ts_query_disable_capture(TSQuery *, const char *, uint32_t)
Definition: query.c:2785
bool ts_query_cursor_next_match(TSQueryCursor *, TSQueryMatch *match)
Definition: query.c:3690
bool ts_node_is_missing(TSNode)
Definition: node.c:449
bool ts_node_eq(TSNode, TSNode)
Definition: node.c:430
int64_t ts_tree_cursor_goto_first_child_for_point(TSTreeCursor *, TSPoint)
Definition: tree_cursor.c:168
void ts_query_cursor_remove_match(TSQueryCursor *, uint32_t id)
Definition: query.c:3715
uint16_t TSSymbol
Definition: api.h:36
uint32_t ts_query_cursor_match_limit(const TSQueryCursor *)
Definition: query.c:2851
TSTreeCursor ts_tree_cursor_new(TSNode)
Definition: tree_cursor.c:70
TSInputEncoding
Definition: api.h:44
@ TSInputEncodingUTF16
Definition: api.h:46
@ TSInputEncodingUTF8
Definition: api.h:45
TSNode ts_tree_root_node(const TSTree *self)
Definition: tree.c:36
uint32_t ts_language_version(const TSLanguage *)
Definition: language.c:10
bool ts_tree_cursor_goto_parent(TSTreeCursor *)
Definition: tree_cursor.c:239
void ts_parser_set_logger(TSParser *self, TSLogger logger)
Definition: parser.c:1779
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *)
Definition: tree_cursor.c:479
TSQueryCursor * ts_query_cursor_new(void)
Definition: query.c:2820
bool ts_parser_set_language(TSParser *self, const TSLanguage *language)
Definition: parser.c:1754
uint32_t ts_node_child_count(TSNode)
Definition: node.c:602
TSTree * ts_parser_parse_string_encoding(TSParser *self, const TSTree *old_tree, const char *string, uint32_t length, TSInputEncoding encoding)
Definition: parser.c:1954
bool ts_node_has_error(TSNode)
Definition: node.c:457
int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *, uint32_t)
Definition: tree_cursor.c:128
void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag)
Definition: parser.c:1799
TSNode ts_node_first_child_for_byte(TSNode, uint32_t)
Definition: node.c:636
const char * ts_language_field_name_for_id(const TSLanguage *, TSFieldId)
Definition: language.c:107
uint32_t ts_query_capture_count(const TSQuery *)
Definition: query.c:2701
uint32_t ts_node_end_byte(TSNode)
Definition: node.c:406
bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, uint32_t byte_offset)
Definition: query.c:2754
TSParser * ts_parser_new(void)
Definition: parser.c:1704
const char * ts_query_capture_name_for_id(const TSQuery *, uint32_t id, uint32_t *length)
Definition: query.c:2709
TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *)
Definition: tree_cursor.c:431
bool ts_node_is_named(TSNode)
Definition: node.c:442
bool ts_query_cursor_next_capture(TSQueryCursor *, TSQueryMatch *match, uint32_t *capture_index)
Definition: query.c:3746
void ts_set_allocator(void *(*new_malloc)(size_t), void *(*new_calloc)(size_t, size_t), void *(*new_realloc)(void *, size_t), void(*new_free)(void *))
Definition: alloc.c:37
TSSymbolType
Definition: api.h:49
@ TSSymbolTypeAuxiliary
Definition: api.h:52
@ TSSymbolTypeRegular
Definition: api.h:50
@ TSSymbolTypeAnonymous
Definition: api.h:51
uint32_t ts_language_symbol_count(const TSLanguage *)
Definition: language.c:6
void ts_query_disable_pattern(TSQuery *, uint32_t)
Definition: query.c:2801
const TSQueryPredicateStep * ts_query_predicates_for_pattern(const TSQuery *self, uint32_t pattern_index, uint32_t *length)
Definition: query.c:2734
TSNode ts_node_parent(TSNode)
Definition: node.c:461
TSTree * ts_parser_parse_string(TSParser *self, const TSTree *old_tree, const char *string, uint32_t length)
Definition: parser.c:1945
TSNode ts_node_named_descendant_for_point_range(TSNode, TSPoint, TSPoint)
Definition: node.c:668
void ts_parser_print_dot_graphs(TSParser *self, int file)
Definition: parser.c:1783
TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol)
Definition: language.c:93
TSNode ts_tree_cursor_current_node(const TSTreeCursor *)
Definition: tree_cursor.c:262
TSSymbol ts_language_symbol_for_name(const TSLanguage *self, const char *string, uint32_t length, bool is_named)
Definition: language.c:74
void ts_query_cursor_set_point_range(TSQueryCursor *, TSPoint, TSPoint)
Definition: query.c:2888
uint32_t ts_language_field_count(const TSLanguage *)
Definition: language.c:14
TSNode ts_node_descendant_for_point_range(TSNode, TSPoint, TSPoint)
Definition: node.c:660
TSNode ts_node_next_sibling(TSNode)
Definition: node.c:620
TSPoint ts_node_end_point(TSNode)
Definition: node.c:410
void ts_query_delete(TSQuery *)
Definition: query.c:2677
const TSLanguage * ts_parser_language(const TSParser *self)
Definition: parser.c:1750
const char * ts_tree_cursor_current_field_name(const TSTreeCursor *)
Definition: tree_cursor.c:469
TSNode ts_node_named_descendant_for_byte_range(TSNode, uint32_t, uint32_t)
Definition: node.c:652
bool ts_tree_cursor_goto_first_child(TSTreeCursor *)
Definition: tree_cursor.c:101
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
const char * source
Definition: lz4.h:699
string FILE
Definition: benchmark.py:21
@ field_name
Definition: parser.c:1737
uint16_t TSFieldId
Definition: parser.h:20
uint16_t TSSymbol
Definition: parser.h:19
unsigned short uint16_t
Definition: sftypes.h:30
long int64_t
Definition: sftypes.h:32
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
uint32_t old_end_byte
Definition: api.h:85
uint32_t start_byte
Definition: api.h:84
uint32_t new_end_byte
Definition: api.h:86
TSPoint old_end_point
Definition: api.h:88
TSPoint start_point
Definition: api.h:87
TSPoint new_end_point
Definition: api.h:89
Definition: api.h:67
TSInputEncoding encoding
Definition: api.h:70
void * payload
Definition: api.h:68
Definition: api.h:78
void * payload
Definition: api.h:79
Definition: api.h:92
const TSTree * tree
Definition: api.h:95
const void * id
Definition: api.h:94
Definition: api.h:55
uint32_t row
Definition: api.h:56
uint32_t column
Definition: api.h:57
TSNode node
Definition: api.h:105
uint32_t index
Definition: api.h:106
const TSQueryCapture * captures
Definition: api.h:121
uint32_t id
Definition: api.h:118
uint16_t capture_count
Definition: api.h:120
uint16_t pattern_index
Definition: api.h:119
TSQueryPredicateStepType type
Definition: api.h:131
uint32_t value_id
Definition: api.h:132
Definition: query.c:270
Definition: api.h:60
TSPoint end_point
Definition: api.h:62
uint32_t start_byte
Definition: api.h:63
TSPoint start_point
Definition: api.h:61
uint32_t end_byte
Definition: api.h:64
const void * tree
Definition: api.h:99
const void * id
Definition: api.h:100
Definition: tree.h:15
Definition: gzappend.c:170
Definition: gzlog.c:289
Definition: engine.c:71
uv_timer_t timeout
Definition: main.c:9
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)