tree-sitter/src/runtime/document.cpp

40 lines
1,008 B
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;
ts_error error;
ts_tree *tree;
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_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;
document->error = result.error;
2014-01-07 21:50:32 -08:00
}
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.expected_inputs != NULL) {
2014-02-20 18:38:31 -08:00
return ts_error_string(&document->error);
} else {
return ts_tree_string(document->tree, document->symbol_names);
}
2014-01-07 21:50:32 -08:00
}