summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--grammer.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/grammer.cpp b/grammer.cpp
index 8a4f6b7..4118733 100644
--- a/grammer.cpp
+++ b/grammer.cpp
@@ -210,19 +210,22 @@ void Compiler::RemoveLastNode()
index_t node_id = node.node_id;
if (node_id == root_node_id) { // No parent -> remove root
- if (node.child_ids().empty()) { // No children -> now empty
+ if (node.child_ids.empty()) { // No children -> now empty
clear();
- } else if (node.child_ids().size() == 1) { // One child: removing possible
- root_node_id = node.child_ids()[0];
+ } else if (node.child_ids.size() == 1) { // One child: removing possible
+ if (!ChildIdIsToken(node.child_ids[0])) {
+ nodes[node.child_ids[0]].parent_node_id = node.child_ids[0];
+ root_node_id = node.child_ids[0];
+ }
nodes.pop_back();
} else
throw std::runtime_error("Backtrack not possible: Root not empty"); // ICE
- } else if (node.child_ids().empty()) { // No children -> remove leaf
+ } else if (node.child_ids.empty()) { // No children -> remove leaf
// We have a parent, otherwise we would have taken previous branch
TreeNode& parent {nodes[node.parent_node_id]};
- if (parent.child_ids().empty() || parent.child_ids().last() != node_id)
+ if (parent.child_ids.empty() || parent.child_ids.last() != node_id)
throw std::runtime_error("Backtrack: Bad child nodes"); // ICE
- parent.childs_ids().pop_back();
+ parent.childs_ids.pop_back();
nodes.pop_back();
} else { // In the middle
throw std::runtime_error("Backtrack in the middle of the tree."); // ICE