From f2878a20decf7174613396e0afdb86257bfe5b31 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Wed, 5 Oct 2022 17:55:07 +0100 Subject: [PATCH] [fix] improve edge case of doc locations --- src/c4/yml/parse.cpp | 11 +---------- test/test_location.cpp | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/c4/yml/parse.cpp b/src/c4/yml/parse.cpp index d7ace46f6..97ccc29b0 100644 --- a/src/c4/yml/parse.cpp +++ b/src/c4/yml/parse.cpp @@ -5546,9 +5546,7 @@ bool Parser::_location_from_node(Tree const& tree, size_t node, Location *C4_RES if(tree.is_container(node)) { if(_location_from_cont(tree, node, loc)) - { return true; - } } if(tree.type(node) != NOTYPE && level == 0) @@ -5559,9 +5557,7 @@ bool Parser::_location_from_node(Tree const& tree, size_t node, Location *C4_RES if(prev != NONE) { if(_location_from_node(tree, prev, loc, level+1)) - { return true; - } } } // try the next sibling @@ -5570,9 +5566,7 @@ bool Parser::_location_from_node(Tree const& tree, size_t node, Location *C4_RES if(next != NONE) { if(_location_from_node(tree, next, loc, level+1)) - { return true; - } } } // try the parent @@ -5581,10 +5575,7 @@ bool Parser::_location_from_node(Tree const& tree, size_t node, Location *C4_RES if(parent != NONE) { if(_location_from_node(tree, parent, loc, level+1)) - { return true; - } - C4_ERROR("7.3"); } } } @@ -5605,7 +5596,7 @@ bool Parser::_location_from_cont(Tree const& tree, size_t node, Location *C4_RES { // when a map starts, the container was set after the key csubstr k = tree.key(child); - if(node_start > k.str) + if(k.str && node_start > k.str) node_start = k.str; } } diff --git a/test/test_location.cpp b/test/test_location.cpp index 8d1742194..e05407eeb 100644 --- a/test/test_location.cpp +++ b/test/test_location.cpp @@ -275,11 +275,11 @@ null: v : v )"); _checkloc(t.rootref() , 0u, 0u, "---"); - _checkloc(t.docref(0) , 1u, 0u, "~"); + _checkloc(t.docref(0) , 1u, 0u, ""); _checkloc(t.docref(0)[0], 1u, 0u, "~"); _checkloc(t.docref(1) , 3u, 0u, "null"); _checkloc(t.docref(1)[0], 3u, 0u, "null"); - _checkloc(t.docref(2) , 0u, 0u, ""); + _checkloc(t.docref(2) , 5u, 1u, ""); _checkloc(t.docref(2)[0], 5u, 3u, ""); }