Skip to content

Commit 552598e

Browse files
committed
flow seq comments working with round trips
set -xe ; cd ~/proj/rapidyaml/ ; export C4_EXTERN_DIR=`pwd`/build/extern ; export CTEST_PARALLEL_LEVEL=`nproc` ; function cm() { cmany "$@" -V RYML_DEV=ON -t Debug -V RYML_VALGRIND=OFF -V RYML_BUILD_BENCHMARKS=OFF -V CMAKE_C_COMPILER_LAUNCHER=ccache -V CMAKE_CXX_COMPILER_LAUNCHER=ccache ; } ; cm rtg ryml-test-engine_9_comments_2_flow_seq -v comm-dbg -ta ' --gtest_filter=**5*.round* '
1 parent 84046ea commit 552598e

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/c4/yml/event_handler_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ struct EventHandlerTree : public EventHandlerStack<EventHandlerTree, EventHandle
598598
void add_comment(csubstr txt, CommentType_e type)
599599
{
600600
NodeData * d = m_curr->tr_data;
601-
_c4dbgpf("node[{}]: comment! [{}]~~~{}~~~", m_tree->id(d), txt.len, txt);
601+
_c4dbgpf("node[{}]: comment! type={} txt=[{}]~~~{}~~~", m_tree->id(d), type, txt.len, txt);
602602
if(type == COMM_VAL_BRACKET_TRAILING || type == COMM_VAL_BRACKET_LEADING)
603603
{
604604
_RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent && m_parent->tr_data->m_type.is_flow());

src/c4/yml/parse_engine.def.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,12 +4772,17 @@ void ParseEngine<EventHandler>::_maybe_handle_leading_comment(CommentType_e curr
47724772
{
47734773
if(m_pending_comment.type != COMM_NONE)
47744774
{
4775+
bool leading_exists = (m_evt_handler->m_curr->leading_comments & COMM_LEADING);
47754776
_RYML_ASSERT_BASIC_(m_evt_handler->m_stack.m_callbacks, m_pending_comment.type == COMM_LEADING);
4776-
CommentType_e actual = (m_evt_handler->m_curr->leading_comments & COMM_LEADING) ? current : COMM_LEADING;
4777+
CommentType_e actual = leading_exists ? current : COMM_LEADING;
4778+
_c4dbgpf("pending leading comment! context={} leading_exists={} actual={}", current, leading_exists, actual);
47774779
_apply_pending_comment(COMM_LEADING, actual);
47784780
m_evt_handler->m_curr->leading_comments |= actual;
47794781
}
4780-
m_evt_handler->m_curr->leading_comments |= COMM_LEADING;
4782+
else if(current & (COMM_VAL_LEADING2|COMM_VAL_ANCHOR_LEADING))
4783+
{
4784+
m_evt_handler->m_curr->leading_comments |= COMM_LEADING;
4785+
}
47814786
}
47824787
#endif // RYML_WITH_COMMENTS
47834788

test/test_engine_9_comments_2_flow_seq.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ COMMENT_TEST(FlowSeqWithTagAndAnchor5,
783783
"=COMM #[LEADING] 1" "\n"
784784
"+DOC" "\n"
785785
"+SEQ []" "\n"
786-
"=COMM #[VAL_ANCHOR_LEADING] 5" "\n"
786+
"=COMM #[LEADING] 5" "\n"
787787
"=COMM #[VAL_LEADING2] 7" "\n"
788788
"=VAL &a <!atag> :a" "\n"
789789
"=COMM #[VAL_BRACKET_LEADING] 9" "\n"
@@ -798,7 +798,7 @@ COMMENT_TEST(FlowSeqWithTagAndAnchor5,
798798
___(ps.begin_doc());
799799
___(ps.begin_seq_val_flow());
800800
___(ps.set_val_tag("!atag"));
801-
___(ps.add_comment(" 5", COMM_VAL_ANCHOR_LEADING));
801+
___(ps.add_comment(" 5", COMM_LEADING));
802802
___(ps.set_val_anchor("a"));
803803
___(ps.add_comment(" 7", COMM_VAL_LEADING2));
804804
___(ps.set_val_scalar_plain("a"));

test/test_lib/test_engine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void test_engine_tree_from_yaml(EngineEvtTestCase const& test_case, std::string
173173
std::string copy = yaml;
174174
parser.parse_in_place_ev("(testyaml)", to_substr(copy));
175175
#ifdef RYML_DBG
176-
print_tree(tree);
176+
print_tree("parsed_tree", tree);
177177
#endif
178178
std::string actual = emitrs_yaml<std::string>(tree);
179179
_c4dbgpf("~~~\n{}~~~\n", actual);
@@ -186,15 +186,18 @@ void test_engine_roundtrip_from_yaml(EngineEvtTestCase const& test_case, std::st
186186
return;
187187
csubstr filename = "(testyaml)";
188188
std::string copy = yaml;
189-
Tree parsed_tree = parse_in_place(filename, to_substr(copy), test_case.opts);
189+
const Tree parsed_tree = parse_in_place(filename, to_substr(copy), test_case.opts);
190+
#ifdef RYML_DBG
191+
print_tree("parsed_tree", parsed_tree);
192+
#endif
190193
{
191194
SCOPED_TRACE("invariants_after_parse");
192195
test_invariants(parsed_tree);
193196
}
194197
const std::string parsed_tree_emitted = emitrs_yaml<std::string>(parsed_tree);
195198
EXPECT_EQ(test_case.expected_emitted, parsed_tree_emitted);
196199
std::string emitted0_copy = parsed_tree_emitted;
197-
Tree after_roundtrip = parse_in_place(filename, to_substr(emitted0_copy), test_case.opts);
200+
const Tree after_roundtrip = parse_in_place(filename, to_substr(emitted0_copy), test_case.opts);
198201
{
199202
SCOPED_TRACE("invariants_after_roundtrip");
200203
test_invariants(after_roundtrip);

0 commit comments

Comments
 (0)