Rizin
unix-like reverse engineering framework and cli tools
parser.h
Go to the documentation of this file.
1 #ifndef TREE_SITTER_PARSER_H_
2 #define TREE_SITTER_PARSER_H_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <stdbool.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 
12 #define ts_builtin_sym_error ((TSSymbol)-1)
13 #define ts_builtin_sym_end 0
14 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
15 
17 
18 #ifndef TREE_SITTER_API_H_
21 typedef struct TSLanguage TSLanguage;
22 #endif
23 
24 typedef struct {
26  uint8_t child_index;
27  bool inherited;
29 
30 typedef struct {
31  uint16_t index;
34 
35 typedef struct {
36  bool visible;
37  bool named;
38  bool supertype;
40 
41 typedef struct TSLexer TSLexer;
42 
43 struct TSLexer {
46  void (*advance)(TSLexer *, bool);
47  void (*mark_end)(TSLexer *);
50  bool (*eof)(const TSLexer *);
51 };
52 
53 typedef enum {
59 
60 typedef union {
61  struct {
62  uint8_t type;
64  bool extra;
65  bool repetition;
66  } shift;
67  struct {
68  uint8_t type;
69  uint8_t child_count;
70  TSSymbol symbol;
71  int16_t dynamic_precedence;
72  uint16_t production_id;
73  } reduce;
74  uint8_t type;
76 
77 typedef struct {
78  uint16_t lex_state;
79  uint16_t external_lex_state;
80 } TSLexMode;
81 
82 typedef union {
84  struct {
85  uint8_t count;
86  bool reusable;
87  } entry;
89 
90 struct TSLanguage {
101  const uint16_t *parse_table;
105  const char * const *symbol_names;
106  const char * const *field_names;
111  const uint16_t *alias_map;
112  const TSSymbol *alias_sequences;
113  const TSLexMode *lex_modes;
114  bool (*lex_fn)(TSLexer *, TSStateId);
117  struct {
118  const bool *states;
119  const TSSymbol *symbol_map;
120  void *(*create)(void);
121  void (*destroy)(void *);
122  bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
123  unsigned (*serialize)(void *, char *);
124  void (*deserialize)(void *, const char *, unsigned);
127 };
128 
129 /*
130  * Lexer Macros
131  */
132 
133 #define START_LEXER() \
134  bool result = false; \
135  bool skip = false; \
136  bool eof = false; \
137  int32_t lookahead; \
138  goto start; \
139  next_state: \
140  lexer->advance(lexer, skip); \
141  start: \
142  skip = false; \
143  lookahead = lexer->lookahead;
144 
145 #define ADVANCE(state_value) \
146  { \
147  state = state_value; \
148  goto next_state; \
149  }
150 
151 #define SKIP(state_value) \
152  { \
153  skip = true; \
154  state = state_value; \
155  goto next_state; \
156  }
157 
158 #define ACCEPT_TOKEN(symbol_value) \
159  result = true; \
160  lexer->result_symbol = symbol_value; \
161  lexer->mark_end(lexer);
162 
163 #define END_STATE() return result;
164 
165 /*
166  * Parse Table Macros
167  */
168 
169 #define SMALL_STATE(id) id - LARGE_STATE_COUNT
170 
171 #define STATE(id) id
172 
173 #define ACTIONS(id) id
174 
175 #define SHIFT(state_value) \
176  {{ \
177  .shift = { \
178  .type = TSParseActionTypeShift, \
179  .state = state_value \
180  } \
181  }}
182 
183 #define SHIFT_REPEAT(state_value) \
184  {{ \
185  .shift = { \
186  .type = TSParseActionTypeShift, \
187  .state = state_value, \
188  .repetition = true \
189  } \
190  }}
191 
192 #define SHIFT_EXTRA() \
193  {{ \
194  .shift = { \
195  .type = TSParseActionTypeShift, \
196  .extra = true \
197  } \
198  }}
199 
200 #define REDUCE(symbol_val, child_count_val, ...) \
201  {{ \
202  .reduce = { \
203  .type = TSParseActionTypeReduce, \
204  .symbol = symbol_val, \
205  .child_count = child_count_val, \
206  __VA_ARGS__ \
207  }, \
208  }}
209 
210 #define RECOVER() \
211  {{ \
212  .type = TSParseActionTypeRecover \
213  }}
214 
215 #define ACCEPT_INPUT() \
216  {{ \
217  .type = TSParseActionTypeAccept \
218  }}
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif // TREE_SITTER_PARSER_H_
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
Definition: arm_il32.c:190
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 count
Definition: sflib.h:98
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
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
Definition: sflib.h:97
int type
Definition: mipsasm.c:17
@ field_id
Definition: parser.c:1736
uint16_t TSStateId
Definition: parser.h:16
uint16_t TSFieldId
Definition: parser.h:20
TSParseActionType
Definition: parser.h:53
@ TSParseActionTypeAccept
Definition: parser.h:56
@ TSParseActionTypeShift
Definition: parser.h:54
@ TSParseActionTypeRecover
Definition: parser.h:57
@ TSParseActionTypeReduce
Definition: parser.h:55
uint16_t TSSymbol
Definition: parser.h:19
unsigned short uint16_t
Definition: sftypes.h:30
int int32_t
Definition: sftypes.h:33
unsigned int uint32_t
Definition: sftypes.h:29
short int16_t
Definition: sftypes.h:34
unsigned char uint8_t
Definition: sftypes.h:31
const bool * states
Definition: parser.h:118
uint32_t large_state_count
Definition: parser.h:97
const TSLexMode * lex_modes
Definition: parser.h:113
const TSParseActionEntry * parse_actions
Definition: parser.h:104
uint32_t production_id_count
Definition: parser.h:98
const char *const * field_names
Definition: parser.h:106
const TSSymbol * alias_sequences
Definition: parser.h:112
const TSFieldMapSlice * field_map_slices
Definition: parser.h:107
const char *const * symbol_names
Definition: parser.h:105
const TSSymbol * symbol_map
Definition: parser.h:119
uint16_t max_alias_sequence_length
Definition: parser.h:100
uint32_t token_count
Definition: parser.h:94
uint32_t alias_count
Definition: parser.h:93
const uint32_t * small_parse_table_map
Definition: parser.h:103
unsigned(* serialize)(void *, char *)
Definition: parser.h:123
void(* deserialize)(void *, const char *, unsigned)
Definition: parser.h:124
void(* destroy)(void *)
Definition: parser.h:121
uint32_t symbol_count
Definition: parser.h:92
const TSFieldMapEntry * field_map_entries
Definition: parser.h:108
const uint16_t * parse_table
Definition: parser.h:101
const TSSymbol * public_symbol_map
Definition: parser.h:110
const TSStateId * primary_state_ids
Definition: parser.h:126
struct TSLanguage::@436 external_scanner
bool(* scan)(void *, TSLexer *, const bool *symbol_whitelist)
Definition: parser.h:122
const TSSymbolMetadata * symbol_metadata
Definition: parser.h:109
const uint16_t * alias_map
Definition: parser.h:111
uint32_t field_count
Definition: parser.h:99
TSSymbol keyword_capture_token
Definition: parser.h:116
uint32_t version
Definition: parser.h:91
bool(* lex_fn)(TSLexer *, TSStateId)
Definition: parser.h:114
uint32_t state_count
Definition: parser.h:96
const uint16_t * small_parse_table
Definition: parser.h:102
bool(* keyword_lex_fn)(TSLexer *, TSStateId)
Definition: parser.h:115
uint32_t external_token_count
Definition: parser.h:95
Definition: parser.h:43
void(* advance)(TSLexer *, bool)
Definition: parser.h:46
int32_t lookahead
Definition: parser.h:44
uint32_t(* get_column)(TSLexer *)
Definition: parser.h:48
bool(* eof)(const TSLexer *)
Definition: parser.h:50
TSSymbol result_symbol
Definition: parser.h:45
bool(* is_at_included_range_start)(const TSLexer *)
Definition: parser.h:49
void(* mark_end)(TSLexer *)
Definition: parser.h:47
Definition: zipcmp.c:77
Definition: dis.h:43
#define bool
Definition: sysdefs.h:146