Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/flexi_cfg/config/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct STRING : peg::seq<peg::one<'"'>, peg::plus<peg::not_one<'"'>>, peg::one<'
struct EXPRESSION : peg::seq<Eo, math::expression, Ec> {};

template <typename Element>
struct LIST_CONTENT_ : peg::list<Element, peg::seq<COMMA, TAIL>, peg::space> { using element = Element; };
struct LIST_CONTENT_ : peg::list_tail<Element, peg::seq<COMMA, TAIL>, peg::space> { using element = Element; };

template <typename Content>
// TODO: Figure out how to support 'peg::if_must<>' here instead of 'peg::seq<>' so that we can get
Expand Down
18 changes: 11 additions & 7 deletions tests/config_grammar_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ const std::vector<std::string> list_test_cases = {
"[$(ref.var2), $(ref.var1), 3.456]",
// Verify that a mix of variables, expressions and numbers is supported
R"([$(ref.var2), {{ 2^14 - 1}}, 0.32])",

// Verify that a list with a trailing comma is supported
"[0x123, 0Xabc, 0xA1B2F9,]",
// Verify that a list of lists with a trailing comma is supported
"[[1, 2, 3], [4, 5, 6,], [7, 8, 9],]",
// Verify that a list with a trailing comma and a trailing comment is supported
R"([
0x123, # Another comment here with a comma,
0Xabc, 0xA1B2F9, # a trailing comma and a trailingcomment
# comment
])",
};

TEST(ConfigGrammar, LIST) {
Expand Down Expand Up @@ -437,13 +448,6 @@ TEST(ConfigGrammar, LIST) {
EXPECT_THROW(ret.emplace(runTest<peg::must<flexi_cfg::config::LIST, peg::eolf>>(content)),
flexi_cfg::config::InvalidTypeException);
}
{
// Fails due to the trailing comma
const std::string content = "[0x123, 0Xabc, 0xA1B2F9,]";
std::optional<RetType> ret;
EXPECT_THROW(ret.emplace(runTest<peg::must<flexi_cfg::config::LIST, peg::eolf>>(content)),
tao::pegtl::parse_error);
}
{
// Fails due to containing a VAR
const std::string content = "[0x123, $VAR, 0xA1B2F9,]";
Expand Down
Loading