From 259da54edb5c433d2a30813bddcf05425c8e681b Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 20 Jul 2020 19:52:11 +0900 Subject: [PATCH] refactor: always use vector in location `location` and `region` have a (shared_ptr to the) container of TOML contents. Those take a template argument to allow both std::vector and std::string as an interanal container. But since those are internal feature, i.e. it should not be used by a user directly, this template can be removed by re-writing a parser a bit. This introduces a complexity to toml11 error reporting system, so I'm removing this. First, remove all the location from the parser. Then the template argument can be removed because everyone uses std::vector now. --- toml/parser.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 586a0fd..333f3d1 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -510,7 +510,7 @@ parse_ml_literal_string(location& loc) const auto first = loc.iter(); if(const auto token = lex_ml_literal_string::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto open = lex_ml_literal_string_open::invoke(inner_loc); if(!open) @@ -573,7 +573,7 @@ parse_literal_string(location& loc) const auto first = loc.iter(); if(const auto token = lex_literal_string::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto open = lex_apostrophe::invoke(inner_loc); if(!open) @@ -646,7 +646,7 @@ parse_local_date(location& loc) const auto first = loc.iter(); if(const auto token = lex_local_date::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto y = lex_date_fullyear::invoke(inner_loc); if(!y || inner_loc.iter() == inner_loc.end() || *inner_loc.iter() != '-') @@ -696,7 +696,7 @@ parse_local_time(location& loc) const auto first = loc.iter(); if(const auto token = lex_local_time::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto h = lex_time_hour::invoke(inner_loc); if(!h || inner_loc.iter() == inner_loc.end() || *inner_loc.iter() != ':') @@ -785,7 +785,7 @@ parse_local_datetime(location& loc) const auto first = loc.iter(); if(const auto token = lex_local_date_time::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto date = parse_local_date(inner_loc); if(!date || inner_loc.iter() == inner_loc.end()) { @@ -830,7 +830,7 @@ parse_offset_datetime(location& loc) const auto first = loc.iter(); if(const auto token = lex_offset_date_time::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto datetime = parse_local_datetime(inner_loc); if(!datetime || inner_loc.iter() == inner_loc.end()) { @@ -903,7 +903,7 @@ parse_key(location& loc) if(const auto token = lex_dotted_key::invoke(loc)) { const auto reg = token.unwrap(); - location inner_loc(loc.name(), reg.str()); + location> inner_loc(loc.name(), reg.vec()); std::vector keys; while(inner_loc.iter() != inner_loc.end()) @@ -1182,7 +1182,7 @@ template bool is_valid_forward_table_definition(const Value& fwd, Iterator key_first, Iterator key_curr, Iterator key_last) { - location def("internal", detail::get_region(fwd).str()); + location> def("internal", detail::get_region(fwd).vec()); if(const auto tabkeys = parse_table_key(def)) { // table keys always contains all the nodes from the root. @@ -1736,7 +1736,7 @@ parse_table_key(location& loc) { if(auto token = lex_std_table::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto open = lex_std_table_open::invoke(inner_loc); if(!open || inner_loc.iter() == inner_loc.end()) @@ -1798,7 +1798,7 @@ parse_array_table_key(location& loc) { if(auto token = lex_array_table::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); const auto open = lex_array_table_open::invoke(inner_loc); if(!open || inner_loc.iter() == inner_loc.end()) @@ -1970,7 +1970,7 @@ result parse_toml_file(location& loc) >; if(const auto token = lex_first_comments::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + location> inner_loc(loc.name(), token.unwrap().vec()); while(inner_loc.iter() != inner_loc.end()) { maybe::invoke(inner_loc); // remove ws if exists