2020#include " json_traits.hpp"
2121#include " key1.hpp"
2222#include " object.hpp"
23- #include " phase1_stuff .hpp"
23+ #include " phase1_mode .hpp"
2424#include " reference2.hpp"
2525#include " reverse.hpp"
2626
2727namespace tao ::config::internal
2828{
2929 template < typename T >
30- bool phase1_append ( concat& c, const key1& path, const T& thing, const bool implicit );
30+ bool phase1_append ( concat& c, const key1& path, const T& thing, const phase1_mode mode );
3131
3232 template < typename T >
33- bool phase1_append_star ( concat& c, const pegtl::position& p, const key1& path, const T& thing, const bool implicit )
33+ bool phase1_append_star ( concat& c, const pegtl::position& p, const key1& path, const T& thing, const phase1_mode mode )
3434 {
3535 c.back_ensure_kind ( entry_kind::concat, p );
36- return phase1_append ( c.concat .back ().get_concat (), path, thing, implicit );
36+ return phase1_append ( c.concat .back ().get_concat (), path, thing, mode );
3737 }
3838
3939 template < typename T >
40- bool phase1_append_name ( concat& c, const pegtl::position& p, const std::string& name, const key1& path, const T& thing, const bool implicit )
40+ bool phase1_append_name ( concat& c, const pegtl::position& p, const std::string& name, const key1& path, const T& thing, const phase1_mode mode )
4141 {
4242 c.back_ensure_kind ( entry_kind::object, p );
4343 const auto pair = c.concat .back ().get_object ().object .try_emplace ( name, p );
44- pair.first ->second .implicit = implicit && ( pair.second || pair.first ->second .implicit );
45- return phase1_append ( pair.first ->second , path, thing, implicit );
44+ pair.first ->second .implicit = ( mode == phase1_mode:: implicit ) && ( pair.second || pair.first ->second .implicit );
45+ return phase1_append ( pair.first ->second , path, thing, mode );
4646 }
4747
4848 template < typename T >
49- bool phase1_append_index ( concat& c, const pegtl::position& p, const std::size_t index, const key1& path, const T& thing, const bool implicit )
49+ bool phase1_append_index ( concat& c, const pegtl::position& p, const std::size_t index, const key1& path, const T& thing, const phase1_mode mode )
5050 {
5151 std::size_t n = index;
5252
@@ -58,7 +58,7 @@ namespace tao::config::internal
5858 throw pegtl::parse_error ( " cannot index (across) reference" , p );
5959 case entry_kind::array:
6060 if ( e.get_array ().array .size () > n ) {
61- return phase1_append ( *std::next ( e.get_array ().array .begin (), n ), path, thing, implicit );
61+ return phase1_append ( *std::next ( e.get_array ().array .begin (), n ), path, thing, mode );
6262 }
6363 n -= e.get_array ().array .size ();
6464 continue ;
@@ -72,23 +72,23 @@ namespace tao::config::internal
7272 }
7373
7474 template < typename T >
75- bool phase1_append_append ( concat& c, const pegtl::position& p, const std::uint64_t g, const key1& path, const T& thing, const bool implicit )
75+ bool phase1_append_append ( concat& c, const pegtl::position& p, const std::uint64_t g, const key1& path, const T& thing, const phase1_mode mode )
7676 {
7777 c.back_ensure_kind ( entry_kind::array, p );
7878 auto & a = c.concat .back ().get_array ();
7979 if ( g > c.generation ) {
8080 c.generation = g;
8181 concat& d = a.array .emplace_back ( p );
8282 d.remove = false ; // TODO: Make consistent with entry::expand()?
83- return phase1_append ( d, path, thing, implicit );
83+ return phase1_append ( d, path, thing, mode );
8484 }
8585 assert ( !a.array .empty () );
8686
87- return phase1_append ( a.array .back (), path, thing, implicit );
87+ return phase1_append ( a.array .back (), path, thing, mode );
8888 }
8989
9090 template < typename T >
91- bool phase1_append ( concat& c, const key1& path, const T& thing, const bool implicit )
91+ bool phase1_append ( concat& c, const key1& path, const T& thing, const phase1_mode mode )
9292 {
9393 if ( path.empty () ) {
9494 thing ( c );
@@ -98,26 +98,26 @@ namespace tao::config::internal
9898
9999 switch ( part.kind () ) {
100100 case key1_kind::star:
101- return phase1_append_star ( c, part.position , pop_front ( path ), thing, implicit );
101+ return phase1_append_star ( c, part.position , pop_front ( path ), thing, mode );
102102 case key1_kind::name:
103- return phase1_append_name ( c, part.position , part.get_name (), pop_front ( path ), thing, implicit );
103+ return phase1_append_name ( c, part.position , part.get_name (), pop_front ( path ), thing, mode );
104104 case key1_kind::index:
105- return phase1_append_index ( c, part.position , part.get_index (), pop_front ( path ), thing, implicit );
105+ return phase1_append_index ( c, part.position , part.get_index (), pop_front ( path ), thing, mode );
106106 case key1_kind::append:
107- return phase1_append_append ( c, part.position , part.get_generation (), pop_front ( path ), thing, implicit );
107+ return phase1_append_append ( c, part.position , part.get_generation (), pop_front ( path ), thing, mode );
108108 }
109109 throw std::logic_error ( " code should be unreachable" ); // LCOV_EXCL_LINE
110110 }
111111
112112 template < typename T >
113- void phase1_append ( object& o, const key1& path, const T& thing, const bool implicit )
113+ void phase1_append ( object& o, const key1& path, const T& thing, const phase1_mode mode )
114114 {
115115 assert ( !path.empty () );
116116
117117 const std::string& name = path.front ().get_name (); // TODO: Error message if other type.
118118 const auto pair = o.object .try_emplace ( name, path.front ().position );
119- pair.first ->second .implicit = implicit && ( pair.second || pair.first ->second .implicit );
120- phase1_append ( pair.first ->second , pop_front ( path ), thing, implicit );
119+ pair.first ->second .implicit = ( mode == phase1_mode:: implicit ) && ( pair.second || pair.first ->second .implicit );
120+ phase1_append ( pair.first ->second , pop_front ( path ), thing, mode );
121121 }
122122
123123} // namespace tao::config::internal
0 commit comments