From 047a1ae14c75ce08ca04e67452eaebf89a1076d9 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 8 Feb 2020 12:58:01 +0100 Subject: Fix syntax errors --- grammer.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'grammer.cpp') 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 -- cgit v1.2.3