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-20 13:30:43 -08:00
|
|
|
ts_error error;
|
|
|
|
|
ts_tree *tree;
|
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-20 13:30:43 -08:00
|
|
|
void ts_document_set_text(ts_document *document, const char *text) {
|
|
|
|
|
ts_parse_result result = document->parse_fn(text);
|
2014-01-08 18:35:16 -08:00
|
|
|
document->tree = result.tree;
|
2014-01-11 17:59:45 -08:00
|
|
|
document->error = result.error;
|
2014-01-07 21:50:32 -08:00
|
|
|
}
|
|
|
|
|
|
2014-02-20 13:30:43 -08:00
|
|
|
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-06 09:06:52 -08:00
|
|
|
if (document->error.expected_inputs != NULL) {
|
2014-02-20 18:38:31 -08:00
|
|
|
return ts_error_string(&document->error);
|
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
|
|
|
}
|