Start building AST in parser
This commit is contained in:
parent
5813816179
commit
614e497ac4
12 changed files with 262 additions and 50 deletions
34
src/runtime/document.c
Normal file
34
src/runtime/document.c
Normal 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>";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue