Skip to content

Commit

Permalink
Migrate from ColinH/testing/config.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Oct 24, 2018
1 parent 9060b5a commit da3b55c
Show file tree
Hide file tree
Showing 56 changed files with 3,388 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
build
private
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# The Art of C++
# Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey
# Please see LICENSE for license or visit https://github.com/taocpp/config

CXXSTD = -std=c++17
CPPFLAGS = -pedantic -I../json/include -Iinclude
CXXFLAGS = -Wall -Wextra -Werror -O3

SOURCES := $(shell find src -name '*.cpp')
DEPENDS := $(SOURCES:%.cpp=build/%.d)
BINARIES := $(SOURCES:%.cpp=build/%)

TESTFILES := $(shell find tests -name '*.config')
TESTCASES := $(TESTFILES:%.config=%)

.PHONY: all test

all: test $(BINARIES)

test: build/src/test/config/tests
build/src/test/config/tests $(TESTCASES)

build/%.d: %.cpp Makefile
@mkdir -p $(@D)
$(CXX) $(CXXSTD) $(CPPFLAGS) -MM -MQ $@ $< -o $@

build/%: %.cpp build/%.d
$(CXX) $(CXXSTD) $(CPPFLAGS) $(CXXFLAGS) $< -o $@

-include $(DEPENDS)
145 changes: 143 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,143 @@
# config
C++17 JSON-based header-only config reader library
# The Art of C++ / Config

[The Art of C++](https://taocpp.github.io/) / Config is a C++17 header-only library that reads config files in [JSON](https://tools.ietf.org/html/rfc8259) and [JAXN](https://github.com/stand-art/jaxn) syntax with extensions and produces a single [JSON Value](https://github.com/taocpp/json) as result.

## Features

* JAXN data model
* JSON data model
* Binary data
* All double values
* Based on JAXN syntax
* Based on JSON syntax
* Commas are optional
* JAXN comments
* Other small extensions
* Phase 1 features
* Copy sub-sections
* Include other config files
* Read other files as value
* Invoke shell commands
* Access environment variables
* Phase 2 features
* Reference sub-values
* Value addition or concatenation
* File position information (TODO)
* ...

## Example

```
# JAXN comments...
/*
...Shell and C and C++-style comments.
*/
// Regular object member
foo : 41
// Alternative syntax
bar = 43
// Overwrite earlier values
foo : 42
// Nested object member
a.b.c.d = 44
// Include other config file
(include "other.config")
// Include into sub-object
a.b.c = {
(include "other.config")
}
// Add or overwrite a value
a.b.c.d = "hallo"
// Copy sub-section
d.e = (copy a.b.c)
// Value addition
sum = 1 + 2 + 3
// Commas are optional
comma : {
array : [
[ 1 2 3 ],
[ 1, 2, 3 ],
[ 1, 2, 3, ]
]
object : [
{ a : 1 b : 2 c : 3 },
{ a : 1, b : 2, c : 3 },
{ a : 1, b : 2, c : 3, }
]
}
// Array concatenation
array = [ 1 2 3 ] + [ 4 5 6 ]
// Concatenate later
array += [ 7 8 9 ]
// Add new last element to array
array.- = 10
// Shell commands
user = (shell "echo '[ 1 2 3 ]'")
// Environment variables
user = (env "USER")
// Multi-line strings
greeting = """
Hello,
World!
"""
// Nested references
j = 1
a.b.c = 40
i = "b"
j += (a.(i).c) + 1 // now j is 42
// Delete some values
(delete bar)
(delete comma.object.1.*)
// ...more...
```

## Status

This library is still very much under development and not ready for general use.

That said, the features that are implemented are generally functional and stable...

Currently only compiles with our [JSON library](https://github.com/taocpp/json) checked out next to it.

## License

The Art of C++ / Config is certified [Open Source] software.
It may be used for any purpose, including commercial purposes, at absolutely no cost.
It is distributed under the terms of the [MIT license] reproduced here.

> Copyright (c) 2015-2018 Dr. Colin Hirsch and Daniel Frey
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## Contact

The Art of C++ / Config is part of [The Art of C++](https://taocpp.github.io/).

For questions and suggestions about The Art of C++ / Config please contact the authors at `taocpp(at)icemx.net`.
14 changes: 14 additions & 0 deletions include/tao/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/config/

#ifndef TAO_CONFIG_HPP
#define TAO_CONFIG_HPP

#include "config/value.hpp"

#include "config/check_file.hpp"
#include "config/parse_file.hpp"
#include "config/parse_files.hpp"
#include "config/to_stream.hpp"

#endif
40 changes: 40 additions & 0 deletions include/tao/config/annotation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/config/

#ifndef TAO_CONFIG_ANNOTATION_HPP
#define TAO_CONFIG_ANNOTATION_HPP

#include "external/json.hpp"

namespace tao
{
namespace config
{
struct annotation
{
config::pointer pointer;
config::position position;

// TODO: Can we use binding::object without these functions?

std::size_t line() const noexcept
{
return position.line();
}

std::size_t byte_in_line() const noexcept
{
return position.byte_in_line();
}

const std::string& source() const noexcept
{
return position.source();
}
};

} // namespace config

} // namespace tao

#endif
24 changes: 24 additions & 0 deletions include/tao/config/check_file.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/config/

#ifndef TAO_CONFIG_CHECK_FILE_HPP
#define TAO_CONFIG_CHECK_FILE_HPP

#include "internal/grammar.hpp"
#include "internal/pegtl.hpp"

namespace tao
{
namespace config
{
inline void check_file( const std::string& filename )
{
json_pegtl::file_input in( filename );
json_pegtl::parse< internal::grammar >( in );
}

} // namespace config

} // namespace tao

#endif
23 changes: 23 additions & 0 deletions include/tao/config/external/json.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/config/

#ifndef TAO_CONFIG_EXTERNAL_JSON_HPP
#define TAO_CONFIG_EXTERNAL_JSON_HPP

#include <tao/json.hpp>

#include <tao/json/contrib/position.hpp>
#include <tao/json/contrib/traits.hpp>

namespace tao
{
namespace config
{
using pointer = json::pointer;
using position = json::position;

} // namespace config

} // namespace tao

#endif
10 changes: 10 additions & 0 deletions include/tao/config/external/pegtl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/config/

#ifndef TAO_CONFIG_EXTERNAL_PEGTL_HPP
#define TAO_CONFIG_EXTERNAL_PEGTL_HPP

#include <tao/json/external/pegtl.hpp>
#include <tao/json/external/pegtl/analyze.hpp>

#endif
Loading

0 comments on commit da3b55c

Please sign in to comment.