Skip to content

Commit

Permalink
[fix] improve edge case of doc locations
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Oct 5, 2022
1 parent f6a6949 commit ce4b930
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/c4/yml/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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");
}
}
}
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}

Expand Down

0 comments on commit ce4b930

Please sign in to comment.