1#ifndef TREE_SITTER_PARSER_H_
2#define TREE_SITTER_PARSER_H_
12#define ts_builtin_sym_error ((TSSymbol)-1)
13#define ts_builtin_sym_end 0
14#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
16#ifndef TREE_SITTER_API_H_
17typedef uint16_t TSStateId;
18typedef uint16_t TSSymbol;
19typedef uint16_t TSFieldId;
20typedef struct TSLanguage TSLanguage;
21typedef struct TSLanguageMetadata {
22 uint8_t major_version;
23 uint8_t minor_version;
24 uint8_t patch_version;
34// Used to index the field and supertype maps.
46typedef struct TSLexer TSLexer;
50 TSSymbol result_symbol;
51 void (*advance)(TSLexer *, bool);
52 void (*mark_end)(TSLexer *);
53 uint32_t (*get_column)(TSLexer *);
54 bool (*is_at_included_range_start)(const TSLexer *);
55 bool (*eof)(const TSLexer *);
56 void (*log)(const TSLexer *, const char *, ...);
60 TSParseActionTypeShift,
61 TSParseActionTypeReduce,
62 TSParseActionTypeAccept,
63 TSParseActionTypeRecover,
77 int16_t dynamic_precedence;
78 uint16_t production_id;
85 uint16_t external_lex_state;
90 uint16_t external_lex_state;
91 uint16_t reserved_word_set_id;
108 uint32_t abi_version;
109 uint32_t symbol_count;
110 uint32_t alias_count;
111 uint32_t token_count;
112 uint32_t external_token_count;
113 uint32_t state_count;
114 uint32_t large_state_count;
115 uint32_t production_id_count;
116 uint32_t field_count;
117 uint16_t max_alias_sequence_length;
118 const uint16_t *parse_table;
119 const uint16_t *small_parse_table;
120 const uint32_t *small_parse_table_map;
121 const TSParseActionEntry *parse_actions;
122 const char * const *symbol_names;
123 const char * const *field_names;
124 const TSMapSlice *field_map_slices;
125 const TSFieldMapEntry *field_map_entries;
126 const TSSymbolMetadata *symbol_metadata;
127 const TSSymbol *public_symbol_map;
128 const uint16_t *alias_map;
129 const TSSymbol *alias_sequences;
130 const TSLexerMode *lex_modes;
131 bool (*lex_fn)(TSLexer *, TSStateId);
132 bool (*keyword_lex_fn)(TSLexer *, TSStateId);
133 TSSymbol keyword_capture_token;
136 const TSSymbol *symbol_map;
137 void *(*create)(void);
138 void (*destroy)(void *);
139 bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
140 unsigned (*serialize)(void *, char *);
141 void (*deserialize)(void *, const char *, unsigned);
143 const TSStateId *primary_state_ids;
145 const TSSymbol *reserved_words;
146 uint16_t max_reserved_word_set_size;
147 uint32_t supertype_count;
148 const TSSymbol *supertype_symbols;
149 const TSMapSlice *supertype_map_slices;
150 const TSSymbol *supertype_map_entries;
151 TSLanguageMetadata metadata;
154static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
156 uint32_t size = len - index;
158 uint32_t half_size = size / 2;
159 uint32_t mid_index = index + half_size;
160 const TSCharacterRange *range = &ranges[mid_index];
161 if (lookahead >= range->start && lookahead <= range->end) {
163 } else if (lookahead > range->end) {
168 const TSCharacterRange *range = &ranges[index];
169 return (lookahead >= range->start && lookahead <= range->end);
177#define UNUSED __pragma(warning(suppress : 4101))
179#define UNUSED __attribute__((unused))
182#define START_LEXER() \
183 bool result = false; \
190 lexer->advance(lexer, skip); \
193 lookahead = lexer->lookahead;
195#define ADVANCE(state_value) \
197 state = state_value; \
201#define ADVANCE_MAP(...) \
203 static const uint16_t map[] = { __VA_ARGS__ }; \
204 for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
205 if (map[i] == lookahead) { \
206 state = map[i + 1]; \
212#define SKIP(state_value) \
215 state = state_value; \
219#define ACCEPT_TOKEN(symbol_value) \
221 lexer->result_symbol = symbol_value; \
222 lexer->mark_end(lexer);
224#define END_STATE() return result;
230#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
234#define ACTIONS(id) id
236#define SHIFT(state_value) \
239 .type = TSParseActionTypeShift, \
240 .state = (state_value) \
244#define SHIFT_REPEAT(state_value) \
247 .type = TSParseActionTypeShift, \
248 .state = (state_value), \
253#define SHIFT_EXTRA() \
256 .type = TSParseActionTypeShift, \
261#define REDUCE(symbol_name, children, precedence, prod_id) \
264 .type = TSParseActionTypeReduce, \
265 .symbol = symbol_name, \
266 .child_count = children, \
267 .dynamic_precedence = precedence, \
268 .production_id = prod_id \
274 .type = TSParseActionTypeRecover \
277#define ACCEPT_INPUT() \
279 .type = TSParseActionTypeAccept \
286#endif // TREE_SITTER_PARSER_H_
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list