From c4335771207ae7058c45e8c222d99df3682c7cc8 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 27 Jul 2024 18:26:52 +0900 Subject: [PATCH] feat: add key_format_info to basic_value ctor --- include/toml11/parser.hpp | 50 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/include/toml11/parser.hpp b/include/toml11/parser.hpp index 6d14731..c61582a 100644 --- a/include/toml11/parser.hpp +++ b/include/toml11/parser.hpp @@ -172,7 +172,7 @@ parse_boolean(location& loc, const context& ctx) // no format info for boolean boolean_format_info fmt; - return ok(basic_value(val, std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val, std::move(fmt), {}, {}, std::move(reg))); } /* ============================================================================ @@ -221,7 +221,7 @@ parse_bin_integer(location& loc, const context& ctx) const auto val = TC::parse_int(str, source_location(region(loc)), 2); if(val.is_ok()) { - return ok(basic_value(val.as_ok(), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val.as_ok(), std::move(fmt), {}, {}, std::move(reg))); } else { @@ -273,7 +273,7 @@ parse_oct_integer(location& loc, const context& ctx) const auto val = TC::parse_int(str, source_location(region(loc)), 8); if(val.is_ok()) { - return ok(basic_value(val.as_ok(), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val.as_ok(), std::move(fmt), {}, {}, std::move(reg))); } else { @@ -331,7 +331,7 @@ parse_hex_integer(location& loc, const context& ctx) const auto val = TC::parse_int(str, source_location(region(loc)), 16); if(val.is_ok()) { - return ok(basic_value(val.as_ok(), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val.as_ok(), std::move(fmt), {}, {}, std::move(reg))); } else { @@ -402,7 +402,7 @@ parse_dec_integer(location& loc, const context& ctx) fmt.suffix = sfx; } - return ok(basic_value(val.as_ok(), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val.as_ok(), std::move(fmt), {}, {}, std::move(reg))); } template @@ -667,7 +667,7 @@ parse_floating(location& loc, const context& ctx) fmt.suffix = sfx; } - return ok(basic_value(val, std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val, std::move(fmt), {}, {}, std::move(reg))); } /* ============================================================================ @@ -785,7 +785,7 @@ parse_local_date(location& loc, const context& ctx) auto fmt = std::move(std::get<1>(val_fmt_reg.unwrap())); auto reg = std::move(std::get<2>(val_fmt_reg.unwrap())); - return ok(basic_value(std::move(val), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(std::move(val), std::move(fmt), {}, {}, std::move(reg))); } // all the offset_datetime, local_datetime, local_time parses date part. @@ -954,7 +954,7 @@ parse_local_time(location& loc, const context& ctx) auto fmt = std::move(std::get<1>(val_fmt_reg.unwrap())); auto reg = std::move(std::get<2>(val_fmt_reg.unwrap())); - return ok(basic_value(std::move(val), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(std::move(val), std::move(fmt), {}, {}, std::move(reg))); } template @@ -1013,7 +1013,7 @@ parse_local_datetime(location& loc, const context& ctx) local_datetime val(std::get<0>(date_fmt_reg.unwrap()), std::get<0>(time_fmt_reg.unwrap())); - return ok(basic_value(val, std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val, std::move(fmt), {}, {}, std::move(reg))); } template @@ -1140,7 +1140,7 @@ parse_offset_datetime(location& loc, const context& ctx) std::get<0>(time_fmt_reg.unwrap())), offset); - return ok(basic_value(val, std::move(fmt), {}, std::move(reg))); + return ok(basic_value(val, std::move(fmt), {}, {}, std::move(reg))); } /* ============================================================================ @@ -1401,7 +1401,7 @@ parse_ml_basic_string(location& loc, const context& ctx) } return ok(basic_value( - std::move(val), std::move(fmt), {}, std::move(reg) + std::move(val), std::move(fmt), {}, {}, std::move(reg) )); } @@ -1481,7 +1481,7 @@ parse_basic_string(location& loc, const context& ctx) auto val = std::move(val_res.unwrap().first ); auto reg = std::move(val_res.unwrap().second); - return ok(basic_value(std::move(val), std::move(fmt), {}, std::move(reg))); + return ok(basic_value(std::move(val), std::move(fmt), {}, {}, std::move(reg))); } template @@ -1528,7 +1528,7 @@ parse_ml_literal_string(location& loc, const context& ctx) string_type val(str.begin(), str.end()); return ok(basic_value( - std::move(val), std::move(fmt), {}, std::move(reg) + std::move(val), std::move(fmt), {}, {}, std::move(reg) )); } @@ -1581,7 +1581,7 @@ parse_literal_string(location& loc, const context& ctx) auto reg = std::move(val_res.unwrap().second); return ok(basic_value( - std::move(val), std::move(fmt), {}, std::move(reg) + std::move(val), std::move(fmt), {}, {}, std::move(reg) )); } @@ -1793,6 +1793,9 @@ parse_key_value_pair(location& loc, context& ctx) // loc = first; return err(v_res.unwrap_err()); } + + // set key reg/fmt + return ok(std::make_pair(std::move(key_res.unwrap()), std::move(v_res.unwrap()))); } @@ -2049,7 +2052,7 @@ parse_array(location& loc, context& ctx) } return ok(basic_value( - std::move(val), std::move(fmt), {}, region(first, loc) + std::move(val), std::move(fmt), {}, {}, region(first, loc) )); } @@ -2206,7 +2209,7 @@ insert_value(const inserting_value_kind kind, fmt.fmt = table_format::implicit; } current_table.emplace(key, value_type( - table_type{}, fmt, std::vector{}, key_reg)); + table_type{}, fmt, std::vector{}, {}, key_reg)); assert(current_table.at(key).is_table()); current_table_ptr = std::addressof(current_table.at(key).as_table()); @@ -2353,7 +2356,8 @@ insert_value(const inserting_value_kind kind, current_table.emplace(key, value_type( array_type{ std::move(val) }, std::move(fmt), - std::vector{}, std::move(key_reg) + std::vector{}, key_format_info{}, + key_reg, key_reg )); assert( ! current_table.at(key).as_array().empty()); @@ -2604,7 +2608,7 @@ parse_inline_table(location& loc, context& ctx) } basic_value retval( - std::move(table), std::move(fmt), {}, region(first, loc)); + std::move(table), std::move(fmt), {}, {}, region(first, loc)); return ok(std::move(retval)); } @@ -3171,10 +3175,10 @@ parse_file(location& loc, context& ctx) if(loc.eof()) { - return ok(value_type(table_type(), table_format_info{}, {}, region(loc))); + return ok(value_type(table_type(), table_format_info{}, {}, {}, region(loc))); } - value_type root(table_type(), table_format_info{}, {}, region(loc)); + value_type root(table_type(), table_format_info{}, {}, {}, region(loc)); root.as_table_fmt().fmt = table_format::multiline; root.as_table_fmt().indent_type = indent_char::none; @@ -3279,7 +3283,7 @@ parse_file(location& loc, context& ctx) table_format_info fmt; fmt.fmt = table_format::multiline; fmt.indent_type = indent_char::none; - auto tab = value_type(table_type{}, std::move(fmt), std::move(com), reg); + auto tab = value_type(table_type{}, std::move(fmt), std::move(com), {}, reg); auto inserted = insert_value(inserting_value_kind::array_table, std::addressof(root.as_table()), @@ -3366,7 +3370,7 @@ parse_file(location& loc, context& ctx) table_format_info fmt; fmt.fmt = table_format::multiline; fmt.indent_type = indent_char::none; - auto tab = value_type(table_type{}, std::move(fmt), std::move(com), reg); + auto tab = value_type(table_type{}, std::move(fmt), std::move(com), {}, reg); auto inserted = insert_value(inserting_value_kind::std_table, std::addressof(root.as_table()), @@ -3441,7 +3445,7 @@ parse_impl(std::vector cs, std::string fname, const spec& s { auto src = std::make_shared>(std::move(cs)); location loc(std::move(src), std::move(fname)); - return ok(value_type(table_type(), table_format_info{}, std::vector{}, region(loc))); + return ok(value_type(table_type(), table_format_info{}, std::vector{}, {}, region(loc))); } // to simplify parser, add newline at the end if there is no LF.