Allow multiple top-level nodes
Now, the root node of a document is always a document node. It will often have only one child node which corresponds to the grammar's start symbol, but not always. Currently, it may have more than one child if there are ubiquitous tokens such as comments at the beginning of the document. In the future, it will also be possible be possible to have multiple for the document to have multiple children if the document is partially parsed.
This commit is contained in:
parent
9302080aa6
commit
1e79ed794b
17 changed files with 78 additions and 39 deletions
|
|
@ -177,7 +177,15 @@ int ts_parser_handle_error(TSParser *parser) {
|
|||
}
|
||||
|
||||
TSTree *ts_parser_tree_root(TSParser *parser) {
|
||||
return ts_stack_top_node(&parser->stack);
|
||||
TSStack *stack = &parser->stack;
|
||||
if (stack->size == 0)
|
||||
return NULL;
|
||||
|
||||
TSTree *tree = ts_stack_reduce(stack, ts_builtin_sym_document,
|
||||
stack->size, parser->language->hidden_symbol_flags);
|
||||
tree->options = 0;
|
||||
ts_stack_push(stack, 0, tree);
|
||||
return tree;
|
||||
}
|
||||
|
||||
TSParseAction ts_parser_next_action(TSParser *parser) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue