Fix inc parsing for nodes containing ubiq tokens

This commit is contained in:
Max Brunsfeld 2014-09-03 13:17:06 -07:00
parent ad52bdc448
commit c72445d808
2 changed files with 24 additions and 2 deletions

View file

@ -131,6 +131,26 @@ describe("Document", [&]() {
});
});
describe("editing text inside a node containing a ubiquitous token", [&]() {
before_each([&]() {
ts_document_set_language(doc, ts_language_javascript());
delete reader;
reader = new SpyReader("{\nx;\n}", 3);
ts_document_set_input(doc, reader->input);
AssertThat(string(ts_node_string(ts_document_root_node(doc))), Equals(
"(DOCUMENT (program (statement_block (expression_statement (identifier)))))"));
});
it("updates the parse tree", [&]() {
insert_text(strlen("{\nx"), "y");
AssertThat(string(ts_node_string(ts_document_root_node(doc))), Equals(
"(DOCUMENT (program (statement_block (expression_statement (identifier)))))"));
});
});
describe("deleting an important part of a token", [&]() {
it("updates the parse tree, creating an error", [&]() {
delete_text(strlen("{ \"key"), 1);

View file

@ -44,8 +44,10 @@ static size_t breakdown_stack(TSParser *parser, TSInputEdit *edit) {
for (size_t i = 0; i < child_count && position < edit->position; i++) {
TSTree *child = children[i];
TSStateId state = ts_stack_top_state(stack);
TSStateId next_state =
action_for(parser->language, state, child->symbol).data.to_state;
TSParseAction action = action_for(parser->language, state, child->symbol);
TSStateId next_state = action.type == TSParseActionTypeShift ?
action.data.to_state :
state;
ts_stack_push(stack, next_state, child);
ts_tree_retain(child);
position += ts_tree_total_size(child);