2015-11-20 12:00:49 -08:00
|
|
|
#ifndef RUNTIME_LANGUAGE_H_
|
|
|
|
|
#define RUNTIME_LANGUAGE_H_
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "tree_sitter/parser.h"
|
2016-05-09 14:31:44 -07:00
|
|
|
#include "runtime/tree.h"
|
2015-11-20 12:00:49 -08:00
|
|
|
|
2016-06-21 07:28:04 -07:00
|
|
|
typedef struct {
|
|
|
|
|
const TSParseAction *actions;
|
|
|
|
|
size_t action_count;
|
|
|
|
|
bool is_reusable;
|
|
|
|
|
bool depends_on_lookahead;
|
|
|
|
|
} TableEntry;
|
|
|
|
|
|
|
|
|
|
void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol,
|
|
|
|
|
TableEntry *);
|
|
|
|
|
|
2016-02-25 17:36:09 -08:00
|
|
|
bool ts_language_symbol_is_in_progress(const TSLanguage *, TSStateId, TSSymbol);
|
|
|
|
|
|
2016-06-21 07:28:04 -07:00
|
|
|
static inline const TSParseAction *ts_language_actions(const TSLanguage *self,
|
|
|
|
|
TSStateId state,
|
|
|
|
|
TSSymbol symbol,
|
|
|
|
|
size_t *count) {
|
|
|
|
|
TableEntry entry;
|
|
|
|
|
ts_language_table_entry(self, state, symbol, &entry);
|
|
|
|
|
*count = entry.action_count;
|
|
|
|
|
return entry.actions;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 14:11:08 -07:00
|
|
|
static inline const TSParseAction *ts_language_last_action(
|
|
|
|
|
const TSLanguage *self, TSStateId state, TSSymbol symbol) {
|
2016-06-21 07:28:04 -07:00
|
|
|
TableEntry entry;
|
|
|
|
|
ts_language_table_entry(self, state, symbol, &entry);
|
2016-06-21 22:53:48 -07:00
|
|
|
if (entry.action_count)
|
|
|
|
|
return &entry.actions[entry.action_count - 1];
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
2016-06-21 07:28:04 -07:00
|
|
|
}
|
2015-11-20 12:00:49 -08:00
|
|
|
|
2016-11-14 08:36:06 -08:00
|
|
|
static inline TSStateId ts_language_next_state(const TSLanguage *self,
|
|
|
|
|
TSStateId state,
|
|
|
|
|
TSSymbol symbol) {
|
|
|
|
|
if (symbol == ts_builtin_sym_error) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (symbol < self->token_count) {
|
|
|
|
|
const TSParseAction *action = ts_language_last_action(self, state, symbol);
|
|
|
|
|
if (action && (action->type == TSParseActionTypeShift || action->type == TSParseActionTypeRecover)) {
|
|
|
|
|
return action->params.to_state;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return self->parse_table[state * self->symbol_count + symbol];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 07:28:04 -07:00
|
|
|
static inline bool ts_language_is_reusable(const TSLanguage *self,
|
|
|
|
|
TSStateId state, TSSymbol symbol) {
|
|
|
|
|
TableEntry entry;
|
|
|
|
|
ts_language_table_entry(self, state, symbol, &entry);
|
|
|
|
|
return entry.is_reusable;
|
|
|
|
|
}
|
2016-03-07 20:06:46 -08:00
|
|
|
|
2016-05-09 14:31:44 -07:00
|
|
|
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol);
|
|
|
|
|
|
2015-11-20 12:00:49 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // RUNTIME_LANGUAGE_H_
|