2014-02-18 09:07:00 -08:00
|
|
|
#include "tree_sitter/runtime.h"
|
2014-01-07 21:50:32 -08:00
|
|
|
|
2014-02-20 13:30:43 -08:00
|
|
|
struct ts_document {
|
|
|
|
|
ts_parse_fn *parse_fn;
|
2014-01-07 21:50:32 -08:00
|
|
|
const char **symbol_names;
|
2014-02-24 18:42:54 -08:00
|
|
|
const ts_tree *tree;
|
|
|
|
|
size_t error_count;
|
|
|
|
|
ts_tree **errors;
|
2014-01-07 21:50:32 -08:00
|
|
|
};
|
|
|
|
|
|
2014-02-20 13:30:43 -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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 13:30:43 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-02-27 13:30:11 -08:00
|
|
|
void ts_document_set_input_string(ts_document *document, const char *text) {
|
2014-02-24 18:42:54 -08:00
|
|
|
const ts_tree * result = document->parse_fn(text);
|
|
|
|
|
document->tree = result;
|
|
|
|
|
document->errors = NULL;
|
2014-01-07 21:50:32 -08:00
|
|
|
}
|
|
|
|
|
|
2014-02-24 18:42:54 -08:00
|
|
|
const ts_tree * ts_document_tree(const ts_document *document) {
|
2014-01-07 21:50:32 -08:00
|
|
|
return document->tree;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 13:30:43 -08:00
|
|
|
const char * ts_document_string(const ts_document *document) {
|
2014-02-24 18:42:54 -08:00
|
|
|
if (document->error_count > 0) {
|
|
|
|
|
return ts_tree_error_string(document->errors[0], document->symbol_names);
|
2014-01-11 17:59:45 -08:00
|
|
|
} else {
|
2014-02-20 13:30:43 -08:00
|
|
|
return ts_tree_string(document->tree, document->symbol_names);
|
2014-01-11 17:59:45 -08:00
|
|
|
}
|
2014-01-07 21:50:32 -08:00
|
|
|
}
|