2015-11-20 12:00:49 -08:00
|
|
|
#ifndef RUNTIME_LANGUAGE_H_
|
|
|
|
|
#define RUNTIME_LANGUAGE_H_
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-01-04 17:33:34 -08:00
|
|
|
#include "./subtree.h"
|
2018-05-17 17:59:50 -07:00
|
|
|
#include "tree_sitter/parser.h"
|
2015-11-20 12:00:49 -08:00
|
|
|
|
2018-04-06 09:35:17 -07:00
|
|
|
#define ts_builtin_sym_error_repeat (ts_builtin_sym_error - 1)
|
|
|
|
|
|
2016-06-21 07:28:04 -07:00
|
|
|
typedef struct {
|
|
|
|
|
const TSParseAction *actions;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t action_count;
|
2016-06-21 07:28:04 -07:00
|
|
|
bool is_reusable;
|
|
|
|
|
} TableEntry;
|
|
|
|
|
|
2016-11-14 10:35:33 -08:00
|
|
|
void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol, TableEntry *);
|
2016-06-21 07:28:04 -07:00
|
|
|
|
2016-11-14 10:35:33 -08:00
|
|
|
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol);
|
2016-02-25 17:36:09 -08:00
|
|
|
|
2016-12-20 17:06:20 -08:00
|
|
|
static inline bool ts_language_is_symbol_external(const TSLanguage *self, TSSymbol symbol) {
|
|
|
|
|
return 0 < symbol && symbol < self->external_token_count + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 07:28:04 -07:00
|
|
|
static inline const TSParseAction *ts_language_actions(const TSLanguage *self,
|
|
|
|
|
TSStateId state,
|
|
|
|
|
TSSymbol symbol,
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t *count) {
|
2016-06-21 07:28:04 -07:00
|
|
|
TableEntry entry;
|
|
|
|
|
ts_language_table_entry(self, state, symbol, &entry);
|
|
|
|
|
*count = entry.action_count;
|
|
|
|
|
return entry.actions;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 15:48:35 -08:00
|
|
|
static inline bool ts_language_has_actions(const TSLanguage *self,
|
|
|
|
|
TSStateId state,
|
|
|
|
|
TSSymbol symbol) {
|
|
|
|
|
TableEntry entry;
|
|
|
|
|
ts_language_table_entry(self, state, symbol, &entry);
|
|
|
|
|
return entry.action_count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_language_has_reduce_action(const TSLanguage *self,
|
|
|
|
|
TSStateId state,
|
|
|
|
|
TSSymbol symbol) {
|
|
|
|
|
TableEntry entry;
|
|
|
|
|
ts_language_table_entry(self, state, symbol, &entry);
|
|
|
|
|
return entry.action_count > 0 && entry.actions[0].type == TSParseActionTypeReduce;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 08:36:06 -08:00
|
|
|
static inline TSStateId ts_language_next_state(const TSLanguage *self,
|
|
|
|
|
TSStateId state,
|
|
|
|
|
TSSymbol symbol) {
|
2018-04-06 09:35:17 -07:00
|
|
|
if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) {
|
2016-11-14 08:36:06 -08:00
|
|
|
return 0;
|
|
|
|
|
} else if (symbol < self->token_count) {
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t count;
|
2016-11-14 10:35:33 -08:00
|
|
|
const TSParseAction *actions = ts_language_actions(self, state, symbol, &count);
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
TSParseAction action = actions[count - 1];
|
|
|
|
|
if (action.type == TSParseActionTypeShift || action.type == TSParseActionTypeRecover) {
|
2017-07-21 10:17:54 -07:00
|
|
|
return action.params.state;
|
2016-11-14 10:35:33 -08:00
|
|
|
}
|
2016-11-14 08:36:06 -08:00
|
|
|
}
|
2016-11-14 10:35:33 -08:00
|
|
|
return 0;
|
2016-11-14 08:36:06 -08:00
|
|
|
} else {
|
|
|
|
|
return self->parse_table[state * self->symbol_count + symbol];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 22:03:48 -08:00
|
|
|
static inline const bool *
|
|
|
|
|
ts_language_enabled_external_tokens(const TSLanguage *self,
|
|
|
|
|
unsigned external_scanner_state) {
|
2016-12-20 17:06:20 -08:00
|
|
|
if (external_scanner_state == 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
2016-12-21 11:24:41 -08:00
|
|
|
return self->external_scanner.states + self->external_token_count * external_scanner_state;
|
2016-12-20 17:06:20 -08:00
|
|
|
}
|
2016-12-02 22:03:48 -08:00
|
|
|
}
|
|
|
|
|
|
2017-07-14 10:19:58 -07:00
|
|
|
static inline const TSSymbol *
|
2017-07-31 11:45:24 -07:00
|
|
|
ts_language_alias_sequence(const TSLanguage *self, unsigned id) {
|
2017-07-14 10:19:58 -07:00
|
|
|
return id > 0 ?
|
2017-07-31 11:45:24 -07:00
|
|
|
self->alias_sequences + id * self->max_alias_sequence_length :
|
2017-07-14 10:19:58 -07:00
|
|
|
NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-20 12:00:49 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // RUNTIME_LANGUAGE_H_
|