2014-02-15 17:00:33 -08:00
|
|
|
#include "runtime.h"
|
2014-01-07 21:50:32 -08:00
|
|
|
|
|
|
|
|
struct TSDocument {
|
2014-01-08 18:35:16 -08:00
|
|
|
TSParseFn *parse_fn;
|
2014-01-07 21:50:32 -08:00
|
|
|
const char **symbol_names;
|
|
|
|
|
const char *text;
|
2014-01-11 17:59:45 -08:00
|
|
|
TSParseError error;
|
2014-01-07 21:50:32 -08:00
|
|
|
TSTree *tree;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TSDocument * TSDocumentMake() {
|
|
|
|
|
TSDocument *result = malloc(sizeof(TSDocument));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 18:35:16 -08:00
|
|
|
void TSDocumentSetUp(TSDocument *document, TSParseConfig config) {
|
|
|
|
|
document->parse_fn = config.parse_fn;
|
|
|
|
|
document->symbol_names = config.symbol_names;
|
2014-01-07 21:50:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TSDocumentSetText(TSDocument *document, const char *text) {
|
|
|
|
|
document->text = text;
|
2014-01-08 18:35:16 -08:00
|
|
|
TSParseResult result = document->parse_fn(text);
|
|
|
|
|
document->tree = result.tree;
|
2014-01-11 17:59:45 -08:00
|
|
|
document->error = result.error;
|
2014-01-07 21:50:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSTree * TSDocumentTree(const TSDocument *document) {
|
|
|
|
|
return document->tree;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 18:35:16 -08:00
|
|
|
const char * TSDocumentToString(const TSDocument *document) {
|
2014-02-06 09:06:52 -08:00
|
|
|
if (document->error.expected_inputs != NULL) {
|
2014-01-11 17:59:45 -08:00
|
|
|
return TSParseErrorToString(&document->error, document->text, document->symbol_names);
|
|
|
|
|
} else {
|
2014-01-23 13:00:08 -08:00
|
|
|
return TSTreeToString(document->tree, document->symbol_names);
|
2014-01-11 17:59:45 -08:00
|
|
|
}
|
2014-01-07 21:50:32 -08:00
|
|
|
}
|