Skip to content

Commit

Permalink
cleanup and improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Mar 30, 2024
1 parent 1508b0e commit f58d9af
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 176 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ c4_add_library(ryml
c4/yml/emit.hpp
c4/yml/event_handler_tree.hpp
c4/yml/filter_processor.hpp
c4/yml/fwd.hpp
c4/yml/export.hpp
c4/yml/node.hpp
c4/yml/node.cpp
Expand Down
24 changes: 24 additions & 0 deletions src/c4/yml/fwd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _C4_YML_FWD_HPP_
#define _C4_YML_FWD_HPP_

/** @file fwd.hpp forward declarations */

namespace c4 {
namespace yml {

struct NodeScalar;
struct NodeInit;
struct NodeData;
struct NodeType;
class NodeRef;
class ConstNodeRef;
class Tree;
struct ReferenceResolver;
template<class EventHandler> class ParseEngine;
struct EventHandlerTree;
using Parser = ParseEngine<EventHandlerTree>;

} // namespace c4
} // namespace yml

#endif /* _C4_YML_FWD_HPP_ */
157 changes: 142 additions & 15 deletions src/c4/yml/parse_engine.def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ void ParseEngine<EventHandler>::_skipchars(const char (&chars)[N])
_line_progressed(pos);
}

template<class EventHandler>
void ParseEngine<EventHandler>::_maybe_skip_comment()
{
csubstr s = m_state->line_contents.rem.triml(' ');
if(s.begins_with('#'))
{
_c4dbgpf("comment was '{}'", s);
_line_progressed(m_state->line_contents.rem.len);
}
}

template<class EventHandler>
bool ParseEngine<EventHandler>::_maybe_scan_following_colon() noexcept
{
Expand Down Expand Up @@ -1361,6 +1372,135 @@ void ParseEngine<EventHandler>::_save_indentation()

//-----------------------------------------------------------------------------

template<class EventHandler>
void ParseEngine<EventHandler>::_end_map_blck()
{
_c4dbgp("mapblck: end");
if(has_any(RKCL|RVAL))
{
_c4dbgp("mapblck: set missing val");
_handle_annotations_before_blck_val_scalar();
m_evt_handler->set_val_scalar_plain({});
}
else if(has_any(QMRK))
{
_c4dbgp("mapblck: set missing keyval");
_handle_annotations_before_blck_key_scalar();
m_evt_handler->set_key_scalar_plain({});
_handle_annotations_before_blck_val_scalar();
m_evt_handler->set_val_scalar_plain({});
}
m_evt_handler->end_map();
}

template<class EventHandler>
void ParseEngine<EventHandler>::_end_seq_blck()
{
if(has_any(RVAL))
{
_c4dbgp("seqblck: set missing val");
_handle_annotations_before_blck_val_scalar();
m_evt_handler->set_val_scalar_plain({});
}
m_evt_handler->end_seq();
}

template<class EventHandler>
void ParseEngine<EventHandler>::_end2_map()
{
_c4dbgp("map: end");
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_any(RMAP));
if(has_any(BLCK))
{
_end_map_blck();
}
else
{
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_none(FLOW));
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_any(USTY));
m_evt_handler->_pop();
}
}

template<class EventHandler>
void ParseEngine<EventHandler>::_end2_seq()
{
_c4dbgp("seq: end");
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_any(RSEQ));
if(has_any(BLCK))
{
_end_seq_blck();
}
else
{
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_none(FLOW));
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_any(USTY));
m_evt_handler->_pop();
}
}

template<class EventHandler>
void ParseEngine<EventHandler>::_begin2_doc()
{
m_doc_empty = true;
add_flags(RDOC);
m_evt_handler->begin_doc();
m_evt_handler->m_curr->indref = 0; // ?
}

template<class EventHandler>
void ParseEngine<EventHandler>::_begin2_doc_expl()
{
m_doc_empty = true;
add_flags(RDOC);
m_evt_handler->begin_doc_expl();
m_evt_handler->m_curr->indref = 0; // ?
}

template<class EventHandler>
void ParseEngine<EventHandler>::_end2_doc()
{
_c4dbgp("doc: end");
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_any(RDOC));
if(m_doc_empty)
{
_c4dbgp("doc was empty; add empty val");
m_evt_handler->set_val_scalar_plain({});
}
m_evt_handler->end_doc();
}

template<class EventHandler>
void ParseEngine<EventHandler>::_end2_doc_expl()
{
_c4dbgp("doc: end");
if(m_doc_empty)
{
_c4dbgp("doc: no children; add empty val");
m_evt_handler->set_val_scalar_plain({});
}
m_evt_handler->end_doc_expl();
}

template<class EventHandler>
void ParseEngine<EventHandler>::_maybe_begin_doc()
{
if(has_none(RDOC))
{
_c4dbgp("doc must be started");
_begin2_doc();
}
}
template<class EventHandler>
void ParseEngine<EventHandler>::_maybe_end_doc()
{
if(has_any(RDOC))
{
_c4dbgp("doc must be finished");
_end2_doc();
}
}

template<class EventHandler>
void ParseEngine<EventHandler>::_end_doc_suddenly__pop()
{
Expand Down Expand Up @@ -1540,19 +1680,6 @@ void ParseEngine<EventHandler>::_handle_indentation_pop_from_block_map()
}


//-----------------------------------------------------------------------------
template<class EventHandler>
void ParseEngine<EventHandler>::_maybe_skip_comment()
{
csubstr s = m_state->line_contents.rem.triml(' ');
if(s.begins_with('#'))
{
_c4dbgpf("comment was '{}'", s);
_line_progressed(m_state->line_contents.rem.len);
}
}


//-----------------------------------------------------------------------------
template<class EventHandler>
typename ParseEngine<EventHandler>::ScannedScalar ParseEngine<EventHandler>::_scan_scalar_squot()
Expand Down Expand Up @@ -5637,7 +5764,7 @@ bool ParseEngine<EventHandler>::_handle_seq_block()
if(_finished_file())
{
_c4dbgp("seqblck: finish!");
_end2_seq_blck();
_end_seq_blck();
goto seqblck_finish;
}
_c4dbgnextline();
Expand Down Expand Up @@ -6783,7 +6910,7 @@ bool ParseEngine<EventHandler>::_handle_map_block()
if(_finished_file())
{
_c4dbgp("mapblck: file finished!");
_end2_map_blck();
_end_map_blck();
goto mapblck_finish;
}
_c4dbgnextline();
Expand Down
Loading

0 comments on commit f58d9af

Please sign in to comment.