Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
d15b8699
Commit
d15b8699
authored
Dec 19, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate range parsing into the INI parser
parent
bda7b361
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
11 deletions
+35
-11
libcaf_core/caf/detail/parser/read_ini.hpp
libcaf_core/caf/detail/parser/read_ini.hpp
+8
-6
libcaf_core/caf/detail/parser/read_number_or_timespan.hpp
libcaf_core/caf/detail/parser/read_number_or_timespan.hpp
+20
-4
libcaf_core/test/detail/parser/read_ini.cpp
libcaf_core/test/detail/parser/read_ini.cpp
+7
-1
No files found.
libcaf_core/caf/detail/parser/read_ini.hpp
View file @
d15b8699
...
@@ -71,8 +71,9 @@ void read_ini_comment(State& ps, Consumer&&) {
...
@@ -71,8 +71,9 @@ void read_ini_comment(State& ps, Consumer&&) {
// clang-format on
// clang-format on
}
}
template
<
class
State
,
class
Consumer
>
template
<
class
State
,
class
Consumer
,
class
InsideList
=
std
::
false_type
>
void
read_ini_value
(
State
&
ps
,
Consumer
&&
consumer
);
void
read_ini_value
(
State
&
ps
,
Consumer
&&
consumer
,
InsideList
inside_list
=
{});
template
<
class
State
,
class
Consumer
>
template
<
class
State
,
class
Consumer
>
void
read_ini_list
(
State
&
ps
,
Consumer
&&
consumer
)
{
void
read_ini_list
(
State
&
ps
,
Consumer
&&
consumer
)
{
...
@@ -85,7 +86,7 @@ void read_ini_list(State& ps, Consumer&& consumer) {
...
@@ -85,7 +86,7 @@ void read_ini_list(State& ps, Consumer&& consumer) {
transition
(
before_value
,
"
\t\n
"
)
transition
(
before_value
,
"
\t\n
"
)
transition
(
done
,
']'
,
consumer
.
end_list
())
transition
(
done
,
']'
,
consumer
.
end_list
())
fsm_epsilon
(
read_ini_comment
(
ps
,
consumer
),
before_value
,
';'
)
fsm_epsilon
(
read_ini_comment
(
ps
,
consumer
),
before_value
,
';'
)
fsm_epsilon
(
read_ini_value
(
ps
,
consumer
),
after_value
)
fsm_epsilon
(
read_ini_value
(
ps
,
consumer
,
std
::
true_type
{}
),
after_value
)
}
}
state
(
after_value
)
{
state
(
after_value
)
{
transition
(
after_value
,
"
\t\n
"
)
transition
(
after_value
,
"
\t\n
"
)
...
@@ -183,8 +184,8 @@ void read_ini_uri(State& ps, Consumer&& consumer) {
...
@@ -183,8 +184,8 @@ void read_ini_uri(State& ps, Consumer&& consumer) {
// clang-format on
// clang-format on
}
}
template
<
class
State
,
class
Consumer
>
template
<
class
State
,
class
Consumer
,
class
InsideList
>
void
read_ini_value
(
State
&
ps
,
Consumer
&&
consumer
)
{
void
read_ini_value
(
State
&
ps
,
Consumer
&&
consumer
,
InsideList
inside_list
)
{
// clang-format off
// clang-format off
start
();
start
();
state
(
init
)
{
state
(
init
)
{
...
@@ -192,7 +193,8 @@ void read_ini_value(State& ps, Consumer&& consumer) {
...
@@ -192,7 +193,8 @@ void read_ini_value(State& ps, Consumer&& consumer) {
fsm_epsilon
(
read_atom
(
ps
,
consumer
),
done
,
'\''
)
fsm_epsilon
(
read_atom
(
ps
,
consumer
),
done
,
'\''
)
fsm_epsilon
(
read_number
(
ps
,
consumer
),
done
,
'.'
)
fsm_epsilon
(
read_number
(
ps
,
consumer
),
done
,
'.'
)
fsm_epsilon
(
read_bool
(
ps
,
consumer
),
done
,
"ft"
)
fsm_epsilon
(
read_bool
(
ps
,
consumer
),
done
,
"ft"
)
fsm_epsilon
(
read_number_or_timespan
(
ps
,
consumer
),
done
,
"0123456789+-"
)
fsm_epsilon
(
read_number_or_timespan
(
ps
,
consumer
,
inside_list
),
done
,
"0123456789+-"
)
fsm_epsilon
(
read_ini_uri
(
ps
,
consumer
),
done
,
'<'
)
fsm_epsilon
(
read_ini_uri
(
ps
,
consumer
),
done
,
'<'
)
fsm_transition
(
read_ini_list
(
ps
,
consumer
.
begin_list
()),
done
,
'['
)
fsm_transition
(
read_ini_list
(
ps
,
consumer
.
begin_list
()),
done
,
'['
)
fsm_transition
(
read_ini_map
(
ps
,
consumer
.
begin_map
()),
done
,
'{'
)
fsm_transition
(
read_ini_map
(
ps
,
consumer
.
begin_map
()),
done
,
'{'
)
...
...
libcaf_core/caf/detail/parser/read_number_or_timespan.hpp
View file @
d15b8699
...
@@ -42,19 +42,34 @@ namespace caf::detail::parser {
...
@@ -42,19 +42,34 @@ namespace caf::detail::parser {
/// Reads a number or a duration, i.e., on success produces an `int64_t`, a
/// Reads a number or a duration, i.e., on success produces an `int64_t`, a
/// `double`, or a `timespan`.
/// `double`, or a `timespan`.
template
<
class
State
,
class
Consumer
>
template
<
class
State
,
class
Consumer
,
class
EnableRange
=
std
::
false_type
>
void
read_number_or_timespan
(
State
&
ps
,
Consumer
&
consumer
)
{
void
read_number_or_timespan
(
State
&
ps
,
Consumer
&
consumer
,
EnableRange
enable_range
=
{})
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
struct
interim_consumer
{
struct
interim_consumer
{
size_t
invocations
=
0
;
Consumer
*
outer
=
nullptr
;
variant
<
none_t
,
int64_t
,
double
>
interim
;
variant
<
none_t
,
int64_t
,
double
>
interim
;
void
value
(
int64_t
x
)
{
void
value
(
int64_t
x
)
{
interim
=
x
;
switch
(
++
invocations
)
{
case
1
:
interim
=
x
;
break
;
case
2
:
CAF_ASSERT
(
holds_alternative
<
int64_t
>
(
interim
));
outer
->
value
(
get
<
int64_t
>
(
interim
));
interim
=
none
;
[[
fallthrough
]];
default:
outer
->
value
(
x
);
}
}
}
void
value
(
double
x
)
{
void
value
(
double
x
)
{
interim
=
x
;
interim
=
x
;
}
}
};
};
interim_consumer
ic
;
interim_consumer
ic
;
ic
.
outer
=
&
consumer
;
auto
has_int
=
[
&
]
{
return
holds_alternative
<
int64_t
>
(
ic
.
interim
);
};
auto
has_int
=
[
&
]
{
return
holds_alternative
<
int64_t
>
(
ic
.
interim
);
};
auto
has_dbl
=
[
&
]
{
return
holds_alternative
<
double
>
(
ic
.
interim
);
};
auto
has_dbl
=
[
&
]
{
return
holds_alternative
<
double
>
(
ic
.
interim
);
};
auto
get_int
=
[
&
]
{
return
get
<
int64_t
>
(
ic
.
interim
);
};
auto
get_int
=
[
&
]
{
return
get
<
int64_t
>
(
ic
.
interim
);
};
...
@@ -66,10 +81,11 @@ void read_number_or_timespan(State& ps, Consumer& consumer) {
...
@@ -66,10 +81,11 @@ void read_number_or_timespan(State& ps, Consumer& consumer) {
consumer
.
value
(
get_int
());
consumer
.
value
(
get_int
());
}
}
});
});
static
constexpr
std
::
true_type
enable_float
=
std
::
true_type
{};
// clang-format off
// clang-format off
start
();
start
();
state
(
init
)
{
state
(
init
)
{
fsm_epsilon
(
read_number
(
ps
,
ic
),
has_number
)
fsm_epsilon
(
read_number
(
ps
,
ic
,
enable_float
,
enable_range
),
has_number
)
}
}
term_state
(
has_number
)
{
term_state
(
has_number
)
{
epsilon_if
(
has_int
(),
has_integer
)
epsilon_if
(
has_int
(),
has_integer
)
...
...
libcaf_core/test/detail/parser/read_ini.cpp
View file @
d15b8699
...
@@ -126,8 +126,9 @@ some-other-bool=false
...
@@ -126,8 +126,9 @@ some-other-bool=false
some-list=[
some-list=[
; here we have some list entries
; here we have some list entries
123,
123,
1..3,
23 ; twenty-three!
23 ; twenty-three!
,
,
2..4..2,
"abc",
"abc",
'def', ; some comment and a trailing comma
'def', ; some comment and a trailing comma
]
]
...
@@ -179,7 +180,12 @@ const auto ini0_log = make_log(
...
@@ -179,7 +180,12 @@ const auto ini0_log = make_log(
"key: some-list"
,
"key: some-list"
,
"["
,
"["
,
"value (integer): 123"
,
"value (integer): 123"
,
"value (integer): 1"
,
"value (integer): 2"
,
"value (integer): 3"
,
"value (integer): 23"
,
"value (integer): 23"
,
"value (integer): 2"
,
"value (integer): 4"
,
"value (string):
\"
abc
\"
"
,
"value (string):
\"
abc
\"
"
,
"value (atom): 'def'"
,
"value (atom): 'def'"
,
"]"
,
"]"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment