Start building AST in parser

This commit is contained in:
Max Brunsfeld 2014-01-07 21:50:32 -08:00
parent 5813816179
commit 614e497ac4
12 changed files with 262 additions and 50 deletions

34
src/runtime/document.c Normal file
View file

@ -0,0 +1,34 @@
#include "document.h"
struct TSDocument {
TSDocumentParseFn *parse_fn;
const char **symbol_names;
const char *text;
TSTree *tree;
};
TSDocument * TSDocumentMake() {
TSDocument *result = malloc(sizeof(TSDocument));
return result;
}
void TSDocumentSetUp(TSDocument *document, TSDocumentParseFn fn, const char **symbol_names) {
document->parse_fn = fn;
document->symbol_names = symbol_names;
}
void TSDocumentSetText(TSDocument *document, const char *text) {
document->text = text;
document->tree = document->parse_fn(document->text);
}
TSTree * TSDocumentTree(const TSDocument *document) {
return document->tree;
}
char * TSDocumentToString(const TSDocument *document) {
if (document->tree)
return TSTreeToString(document->tree, document->symbol_names);
else
return "#<null tree>";
}