Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-113-list-enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-projectx authored Nov 8, 2023
2 parents 3b85e21 + 43f1b9c commit a8585c9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
ubuntu-latest-gcc-12,
ubuntu-20.04-clang-13,
ubuntu-22.04-clang-14,
ubuntu-22.04-clang-15,
mac-os-latest
]

Expand All @@ -47,18 +48,36 @@ jobs:
compiler: clang
version: "14"

- name: ubuntu-22.04-clang-15
os: ubuntu-22.04
compiler: clang
version: "15"

- name: mac-os-latest
os: macos-latest
CC: clang
CXX: clang++

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4

- name: Install dependencies
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
# Workaround https://github.com/actions/runner-images/issues/8659
echo "matrix.name=${{ matrix.name }}"
echo "matrix.os=${{ matrix.os }}"
if [[ "${{ matrix.name }}" = "ubuntu-22.04-clang-14" ]] || [[ "${{ matrix.os }}" = "ubuntu-latest" ]] ; then
echo "Workaround for https://github.com/actions/runner-images/issues/8659"
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get update
sudo apt-get install -y --allow-downgrades libc6=2.35-0ubuntu3.4 \
libc6-dev=2.35-0ubuntu3.4 \
libstdc++6=12.3.0-1ubuntu1~22.04 \
libgcc-s1=12.3.0-1ubuntu1~22.04
fi
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
# Figure out which version of ubuntu is actually running
Expand Down Expand Up @@ -111,7 +130,7 @@ jobs:

# This must happen before the "Configure CMake" step otherwise the python version used to compile
# will be different than the one installed here.
- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
Expand All @@ -134,7 +153,7 @@ jobs:
export TEST_DIR=env
ctest -C ${{env.BUILD_TYPE}}
${{github.workspace}}/build/src/include_file_test
for i in `seq 1 13`; do
for i in `seq 1 14`; do
${{github.workspace}}/build/src/config_build ${{github.workspace}}/examples/config_example$i.cfg
done
Expand Down
3 changes: 2 additions & 1 deletion examples/config_example12.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ include config_example9.cfg
include config_example10.cfg
include_relative nested/config_nested1.cfg

dummy = 1 # This dummy variable is required because flexi_cfg cannot handle files that only consist of includes


6 changes: 6 additions & 0 deletions examples/config_example14.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file only includes other files, but defines no fields

include config_example11.cfg
include config_example1.cfg # trailing comment

# trailing comment
4 changes: 4 additions & 0 deletions examples/invalid/config_empty.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This config only has a comment, which should fail
# Even a multi-line comment is no good

# One more comment for good measure
6 changes: 4 additions & 2 deletions include/flexi_cfg/config/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ struct include_list : peg::star<INCLUDE> {};
struct INCLUDE_RELATIVE : peg::seq<TAO_PEGTL_KEYWORD("include_relative"), SP, filename::grammar, TAIL> {};
struct include_relative_list : peg::star<INCLUDE_RELATIVE> {};

struct includes : peg::seq<include_list, include_relative_list, TAIL> {};

// A single file should look like this:
//
// 1. Optional list of include files
Expand All @@ -191,10 +193,10 @@ struct include_relative_list : peg::star<INCLUDE_RELATIVE> {};
//
// but never both in the same file. The `peg::not_at<PAIR>` prevents the PAIR that might appear in a
// `STRUCTc` from being matched as a `FULLPAIR` object.
struct config_fields : peg::opt<peg::sor<peg::seq<peg::not_at<PAIR>, peg::plus<FULLPAIR>>, STRUCTc>> {};

struct CONFIG
: peg::seq<TAIL, include_list, include_relative_list,
peg::sor<peg::seq<peg::not_at<PAIR>, peg::plus<FULLPAIR>>, STRUCTc>, TAIL> {};
: peg::seq<TAIL, peg::not_at<peg::eolf>, includes, config_fields, TAIL> {};

struct grammar : peg::seq<CONFIG, peg::eolf> {};

Expand Down
2 changes: 1 addition & 1 deletion src/config_reader_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ auto main(int argc, char* argv[]) -> int {
// Read a deeply nested set of lists
const auto my_nested_list_key = "outer.deep_multi_list";
const auto out = cfg.getValue<std::vector<std::vector<std::vector<int>>>>(my_nested_list_key);
fmt::print("Value of '{}' is : \n", my_nested_list_key); // , fmt::join(out, ", "));
fmt::print("Value of '{}' is : \n", my_nested_list_key); // , fmt::join(out, ", "));
for (const auto& v0 : out) {
fmt::print("[");
for (const auto& v1 : v0) {
Expand Down
8 changes: 8 additions & 0 deletions tests/config_exception_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,11 @@ TEST_P(InvalidConfig, Exception) {
<< "Input file: " << in_file;
}
INSTANTIATE_TEST_SUITE_P(ConfigException, InvalidConfig, testing::Values("config_malformed4.cfg"));

TEST(ConfigException, EmptyConfig) {
{
const auto in_file = std::filesystem::path(EXAMPLE_DIR) / "invalid" / "config_empty.cfg";
peg::file_input in_cfg(in_file);
EXPECT_THROW(parse(in_cfg), peg::parse_error);
}
}

0 comments on commit a8585c9

Please sign in to comment.