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 typedef uint16_t TSStateId
;
18 #ifndef TREE_SITTER_API_H_
19 typedef uint16_t TSSymbol
;
20 typedef uint16_t TSFieldId
;
21 typedef struct TSLanguage TSLanguage
;
41 typedef struct TSLexer TSLexer
;
45 TSSymbol result_symbol
;
46 void (*advance
)(TSLexer
*, bool);
47 void (*mark_end
)(TSLexer
*);
48 uint32_t (*get_column
)(TSLexer
*);
49 bool (*is_at_included_range_start
)(const TSLexer
*);
50 bool (*eof
)(const TSLexer
*);
54 TSParseActionTypeShift
,
55 TSParseActionTypeReduce
,
56 TSParseActionTypeAccept
,
57 TSParseActionTypeRecover
,
71 int16_t dynamic_precedence
;
72 uint16_t production_id
;
79 uint16_t external_lex_state
;
92 uint32_t symbol_count
;
95 uint32_t external_token_count
;
97 uint32_t large_state_count
;
98 uint32_t production_id_count
;
100 uint16_t max_alias_sequence_length
;
101 const uint16_t *parse_table
;
102 const uint16_t *small_parse_table
;
103 const uint32_t *small_parse_table_map
;
104 const TSParseActionEntry
*parse_actions
;
105 const char * const *symbol_names
;
106 const char * const *field_names
;
107 const TSFieldMapSlice
*field_map_slices
;
108 const TSFieldMapEntry
*field_map_entries
;
109 const TSSymbolMetadata
*symbol_metadata
;
110 const TSSymbol
*public_symbol_map
;
111 const uint16_t *alias_map
;
112 const TSSymbol
*alias_sequences
;
113 const TSLexMode
*lex_modes
;
114 bool (*lex_fn
)(TSLexer
*, TSStateId
);
115 bool (*keyword_lex_fn
)(TSLexer
*, TSStateId
);
116 TSSymbol keyword_capture_token
;
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);
126 const TSStateId
*primary_state_ids
;
133 #define START_LEXER() \
134 bool result = false; \
140 lexer->advance(lexer, skip); \
143 lookahead = lexer->lookahead;
145 #define ADVANCE(state_value) \
147 state = state_value; \
151 #define SKIP(state_value) \
154 state = state_value; \
158 #define ACCEPT_TOKEN(symbol_value) \
160 lexer->result_symbol = symbol_value; \
161 lexer->mark_end(lexer);
163 #define END_STATE() return result;
169 #define SMALL_STATE(id) id - LARGE_STATE_COUNT
173 #define ACTIONS(id) id
175 #define SHIFT(state_value) \
178 .type = TSParseActionTypeShift, \
179 .state = state_value \
183 #define SHIFT_REPEAT(state_value) \
186 .type = TSParseActionTypeShift, \
187 .state = state_value, \
192 #define SHIFT_EXTRA() \
195 .type = TSParseActionTypeShift, \
200 #define REDUCE(symbol_val, child_count_val, ...) \
203 .type = TSParseActionTypeReduce, \
204 .symbol = symbol_val, \
205 .child_count = child_count_val, \
212 .type = TSParseActionTypeRecover \
215 #define ACCEPT_INPUT() \
217 .type = TSParseActionTypeAccept \
224 #endif // TREE_SITTER_PARSER_H_