Fix errors in when languages have no fields

This commit is contained in:
Max Brunsfeld 2019-02-12 17:20:12 -08:00
parent 56309a1c28
commit 9f608435ee
4 changed files with 72 additions and 13 deletions

View file

@ -9,6 +9,7 @@ extern "C" {
#include "tree_sitter/parser.h"
#define ts_builtin_sym_error_repeat (ts_builtin_sym_error - 1)
#define TREE_SITTER_LANGUAGE_VERSION_WITH_FIELDS 10
typedef struct {
const TSParseAction *actions;
@ -93,6 +94,12 @@ static inline void ts_language_field_map(
const TSFieldMapEntry **start,
const TSFieldMapEntry **end
) {
if (self->version < TREE_SITTER_LANGUAGE_VERSION_WITH_FIELDS || self->field_count == 0) {
*start = NULL;
*end = NULL;
return;
}
TSFieldMapSlice slice = self->field_map_slices[production_id];
*start = &self->field_map_entries[slice.index];
*end = &self->field_map_entries[slice.index] + slice.length;