Skip to content

Commit d60452c

Browse files
committed
Revert temporary syntax.
1 parent 3270bf2 commit d60452c

36 files changed

+380
-229
lines changed

doc/Member-Extensions.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Note that whitespace is significant within member extensions, i.e. whitespace mu
55

66
* [include](#include)
77
* [parse](#parse)
8+
* [permanent](#permanent)
89
* [schema](#schema)
10+
* [temporary](#temporary)
911

1012

1113

@@ -87,6 +89,12 @@ foo
8789

8890

8991

92+
## permanent
93+
94+
The `permanent` member extension is used to undo the effects of [`temporary`](#temporary).
95+
96+
97+
9098
## schema
9199

92100
The `schema` member extension tells the config library which [schema file](Writing-Schema-Files.cfg) the config must adhere to.
@@ -174,6 +182,56 @@ In order to "cancel" a schema checking the schema member can be used with `null`
174182

175183

176184

185+
## temporary
186+
187+
The `temporary` member extension marks a sub-tree of the JSON as temporary, meaning that it will be removed from the final resulting JSON value.
188+
This is frequently used for templates that are referenced somewhere else in the config.
189+
190+
#### Example taoCONFIG Input File
191+
192+
```
193+
(temporary template) // Can occur before...
194+
195+
template
196+
{
197+
host = "127.0.0.1"
198+
port = 6000
199+
version = 42
200+
}
201+
202+
foo = (template) +
203+
{
204+
host = "127.0.0.2"
205+
}
206+
207+
bar = (template) +
208+
{
209+
port = 6001
210+
}
211+
212+
(temporary template) // ...and/or after.
213+
214+
```
215+
216+
#### Resulting JAXN Config Data
217+
218+
```javascript
219+
{
220+
bar: {
221+
host: "127.0.0.1",
222+
port: 6001,
223+
version: 42
224+
},
225+
foo: {
226+
host: "127.0.0.2",
227+
port: 6000,
228+
version: 42
229+
}
230+
}
231+
```
232+
233+
234+
177235
Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey
178236

179237
[JAXN]: https://github.com/stand-art/jaxn

doc/Writing-Config-Files.md

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ We assume that the reader is somewhat familiar with [JSON].
2626
- [Asterisks](#asterisk)
2727
- [References](#references)
2828
- [Extensions](#extensions)
29-
- [Temporary](#temporary)
3029
- [Dotted Names](#dotted-names)
3130

3231
Please note that, for now, this document shows basic use cases for all features, but not much beyond that.
@@ -488,7 +487,6 @@ servers.*.port = 7000 // Testing
488487
```
489488

490489
Assignments using asterisks can be combined with the literal pseudo-value `delete`.
491-
Assignments and additions using asterisks can be combined with the literal pseudo-values `temporary` and `permanent`.
492490

493491

494492
## References
@@ -602,19 +600,22 @@ baz = (foo.(bar))
602600
}
603601
```
604602

605-
When referencing values marked as [temporary](#temporary) the copied value will not be marked as temporary, however any sub-values will retain their temporary status.
603+
When referencing values marked as [temporary](Member-Extensions.md#temporary) the copied value will not be marked as temporary, however any sub-values will retain their temporary status.
606604
Similarly schema definitions will be retained only for sub-values of the referenced value (TODO: Is this really what we want?)
607605

608606
#### Example taoCONFIG Input File
609607

610608
```
611-
foo = temporary +
609+
(temporary foo)
610+
(temporary foo.baz)
611+
612+
foo
612613
{
613614
bar
614615
{
615616
a = 1
616617
}
617-
baz = temporary +
618+
baz
618619
{
619620
b = 2
620621
}
@@ -680,71 +681,6 @@ Member extensions can similarly contain nested value extensions.
680681
```
681682

682683

683-
## Temporary
684-
685-
The literal pseudo-value `temporary` (and its counterpart, `permanent`) can occur anywhere one of the literal values `null`, `true` and `false` can occur, however it does not itself carry a value.
686-
Instead it marks the sub-tree of the JSON result to which it is "added" as temporary, meaning that while it is available to references it will be removed from the final resulting JSON value.
687-
688-
#### Example taoCONFIG Input File
689-
690-
```
691-
template = temporary +
692-
{
693-
host = "127.0.0.1"
694-
port = 6000
695-
version = 42
696-
}
697-
698-
foo = (template) +
699-
{
700-
host = "127.0.0.2"
701-
}
702-
703-
bar = (template) +
704-
{
705-
port = 6001
706-
}
707-
708-
template += temporary // Can also be "added" later.
709-
710-
```
711-
712-
#### Resulting JAXN Config Data
713-
714-
```javascript
715-
{
716-
bar: {
717-
host: "127.0.0.1",
718-
port: 6001,
719-
version: 42
720-
},
721-
foo: {
722-
host: "127.0.0.2",
723-
port: 6000,
724-
version: 42
725-
}
726-
}
727-
```
728-
729-
Similarly, `permanent` allows removing the marking as temporary.
730-
Arbitrary many `temporary` and `permanent` pseudo-values can be "added" to a value with the last one "winning".
731-
732-
#### Example taoCONFIG Input File
733-
734-
```
735-
foo = temporary + permanent + 42 + permanent + temporary
736-
bar = temporary + temporary + 42 + permanent + permanent
737-
```
738-
739-
#### Resulting JAXN Config Data
740-
741-
```javascript
742-
{
743-
bar: 42
744-
}
745-
```
746-
747-
748684
## Dotted Names
749685

750686
Wherever the name of an object member is expected it is also possible to use a name with multiple dot-separated components.

include/tao/config/access.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ namespace tao::config
5656
case key_kind::index:
5757
return access_index( v, k[ 0 ].get_index(), pop_front( k ) );
5858
}
59-
assert( false );
60-
std::abort();
59+
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
6160
}
6261

6362
} // namespace tao::config

include/tao/config/assign.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ namespace tao::config
5252
case key_kind::index:
5353
return assign( v, k[ 0 ].get_index(), pop_front( k ) );
5454
}
55-
assert( false );
56-
std::abort();
55+
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
5756
}
5857

5958
} // namespace tao::config

include/tao/config/internal/config_action.hpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,6 @@ namespace tao::config::internal
2424
: pegtl::nothing< Rule >
2525
{};
2626

27-
template<>
28-
struct config_action< rules::permanent >
29-
{
30-
template< typename State >
31-
static void apply0( State& st, const extension_maps& )
32-
{
33-
const auto f = []( concat& c ) { c.temporary = false; };
34-
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::implicit );
35-
}
36-
};
37-
38-
template<>
39-
struct config_action< rules::temporary >
40-
{
41-
template< typename State >
42-
static void apply0( State& st, const extension_maps& )
43-
{
44-
const auto f = []( concat& c ) { c.temporary = true; };
45-
phase1_append( st.root, st.prefix + st.suffix, f, phase1_mode::implicit );
46-
}
47-
};
48-
4927
template<>
5028
struct config_action< rules::assign_head >
5129
{

include/tao/config/internal/config_grammar.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ namespace tao::config::internal::rules
7070

7171
struct remove : pegtl::keyword< 'd', 'e', 'l', 'e', 't', 'e' > {};
7272

73-
struct permanent : pegtl::keyword< 'p', 'e', 'r', 'm', 'a', 'n', 'e', 'n', 't' > {};
74-
struct temporary : pegtl::keyword< 't', 'e', 'm', 'p', 'o', 'r', 'a', 'r', 'y' > {};
75-
76-
struct value_part : pegtl::sor< array, object, permanent, temporary, bracketed_value, jaxn_value > {};
73+
struct value_part : pegtl::sor< array, object, bracketed_value, jaxn_value > {};
7774
struct value_list : pegtl::list< value_part, pegtl::one< '+' >, jaxn::ws > {};
7875

7976
struct assign_head : pegtl::one< ':', '=' > {};

include/tao/config/internal/config_parser.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ namespace tao::config::internal
4949
{ { "include", wrap( include_function ) },
5050
{ "include?", wrap( include_if_function ) },
5151
{ "parse", wrap( member_function ) },
52+
{ "permanent", wrap( permanent_function ) },
5253
{ "schema", wrap( schema_function ) },
53-
{ "setenv", wrap( setenv_function ) } },
54+
{ "setenv", wrap( setenv_function ) },
55+
{ "temporary", wrap( temporary_function ) } },
5456
{ { "parse", wrap( value_function ) } } )
5557
{}
5658

include/tao/config/internal/member_functions.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ namespace tao::config::internal
5353
pegtl::parse_nested< rules::config_file, config_action >( p, static_cast< pegtl_input_t& >( in ), st, em );
5454
}
5555

56+
inline void permanent_function( state& st, const key1& path )
57+
{
58+
assert( st.suffix.empty() );
59+
60+
const auto f = []( concat& c ) { c.temporary = false; };
61+
phase1_append( st.root, st.prefix + path, f, phase1_mode::implicit );
62+
}
63+
5664
inline void schema_function( state& st, const std::optional< std::string >& s )
5765
{
5866
assert( st.suffix.empty() );
@@ -75,6 +83,14 @@ namespace tao::config::internal
7583
#endif
7684
}
7785

86+
inline void temporary_function( state& st, const key1& path )
87+
{
88+
assert( st.suffix.empty() );
89+
90+
const auto f = []( concat& c ) { c.temporary = true; };
91+
phase1_append( st.root, st.prefix + path, f, phase1_mode::implicit );
92+
}
93+
7894
} // namespace tao::config::internal
7995

8096
#endif

include/tao/config/internal/phase2_insert.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace tao::config::internal
2323
if( m.second.remove ) {
2424
pair.first->second.remove = true;
2525
}
26+
if( m.second.temporary ) {
27+
pair.first->second.temporary = true;
28+
}
2629
pair.first->second.concat.splice( pair.first->second.concat.begin(), m.second.concat );
2730
}
2831
}

include/tao/config/internal/phase2_replace.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ namespace tao::config::internal
126126
return;
127127
}
128128
i->set_object( star.position );
129+
129130
for( const auto& name : names ) {
130-
i->get_object().object.try_emplace( name, star );
131+
[[maybe_unused]] const auto [ j, b ] = i->get_object().object.try_emplace( name, star );
132+
assert( b && ( j->second.temporary == star.temporary ) );
131133
}
132134
++i;
133135
}
@@ -139,6 +141,7 @@ namespace tao::config::internal
139141
continue;
140142
}
141143
c.remove = s.remove;
144+
c.temporary |= s.temporary;
142145
c.concat.insert( c.concat.begin(), s.concat.begin(), s.concat.end() );
143146
}
144147
}
@@ -150,6 +153,7 @@ namespace tao::config::internal
150153
c.remove = true;
151154
c.concat.clear();
152155
}
156+
c.temporary |= s.temporary;
153157
c.concat.insert( c.concat.end(), s.concat.begin(), s.concat.end() );
154158
}
155159
}

0 commit comments

Comments
 (0)