tree-sitter/src/runtime/document.cpp

41 lines
1 KiB
C++
Raw Normal View History

2014-02-18 09:07:00 -08:00
#include "tree_sitter/runtime.h"
2014-01-07 21:50:32 -08:00
struct ts_document {
ts_parse_fn *parse_fn;
2014-01-07 21:50:32 -08:00
const char **symbol_names;
const ts_tree *tree;
size_t error_count;
ts_tree **errors;
2014-01-07 21:50:32 -08:00
};
ts_document * ts_document_make() {
return new ts_document();
2014-01-07 21:50:32 -08:00
}
2014-02-20 18:38:31 -08:00
void ts_document_free(ts_document *document) {
delete document;
}
void ts_document_set_parser(ts_document *document, ts_parse_config config) {
2014-01-08 18:35:16 -08:00
document->parse_fn = config.parse_fn;
document->symbol_names = config.symbol_names;
2014-01-07 21:50:32 -08:00
}
void ts_document_set_input_string(ts_document *document, const char *text) {
const ts_tree * result = document->parse_fn(text);
document->tree = result;
document->errors = NULL;
2014-01-07 21:50:32 -08:00
}
const ts_tree * ts_document_tree(const ts_document *document) {
2014-01-07 21:50:32 -08:00
return document->tree;
}
const char * ts_document_string(const ts_document *document) {
if (document->error_count > 0) {
return ts_tree_error_string(document->errors[0], document->symbol_names);
} else {
return ts_tree_string(document->tree, document->symbol_names);
}
2014-01-07 21:50:32 -08:00
}