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
08b9088f
Commit
08b9088f
authored
May 23, 2018
by
Dominik Charousset
Committed by
Dominik Charousset
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scaffold for INI parser
parent
a1fd9491
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
0 deletions
+183
-0
libcaf_core/caf/detail/parser/fsm.hpp
libcaf_core/caf/detail/parser/fsm.hpp
+5
-0
libcaf_core/caf/detail/parser/read_ini.hpp
libcaf_core/caf/detail/parser/read_ini.hpp
+103
-0
libcaf_core/test/read_ini.cpp
libcaf_core/test/read_ini.cpp
+75
-0
No files found.
libcaf_core/caf/detail/parser/fsm.hpp
View file @
08b9088f
...
...
@@ -90,6 +90,11 @@
} \
}
// Unconditionally jumps to target for any input.
#define any_input(target) \
ch = ps.next(); \
goto s_##target;
#define invalid_input(predicate, error_code) \
if (predicate(ch)) { \
ps.code = error_code; \
...
...
libcaf_core/caf/detail/parser/read_ini.hpp
0 → 100644
View file @
08b9088f
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <ctype.h>
#include "caf/detail/parser/ec.hpp"
#include "caf/detail/parser/fsm.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/read_atom.hpp"
#include "caf/detail/parser/read_number_or_timespan.hpp"
#include "caf/detail/parser/read_string.hpp"
#include "caf/detail/scope_guard.hpp"
namespace
caf
{
namespace
detail
{
namespace
parser
{
/// Reads an INI formateed input and produces a series of key/value pairs.
template
<
class
Iterator
,
class
Sentinel
,
class
Consumer
>
void
read_ini
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&
consumer
)
{
using
std
::
swap
;
std
::
string
tmp
;
auto
is_alnum_or_dash
=
[](
char
x
)
{
return
isalnum
(
x
)
||
x
==
'-'
||
x
==
'_'
;
};
bool
in_section
=
false
;
auto
begin_section
=
[
&
]
{
if
(
in_section
)
consumer
.
end_section
();
else
in_section
=
true
;
std
::
string
section_key
;
swap
(
tmp
,
section_key
);
consumer
.
begin_section
(
std
::
move
(
section_key
));
};
auto
g
=
make_scope_guard
([
&
]
{
if
(
in_section
)
consumer
.
end_section
();
});
start
();
term_state
(
init
)
{
input
(
is_char
<
' '
>
,
init
)
input
(
is_char
<
'\t'
>
,
init
)
input
(
is_char
<
';'
>
,
leading_comment
)
input
(
is_char
<
'['
>
,
start_section
)
}
// A comment before the first section starts. Jumps back to init after
// hitting newline.
term_state
(
leading_comment
)
{
input
(
is_char
<
'\n'
>
,
init
)
any_input
(
leading_comment
)
}
// Read the section key after reading an '['.
state
(
start_section
)
{
input
(
is_char
<
' '
>
,
start_section
)
input
(
is_char
<
'\t'
>
,
start_section
)
action
(
isalpha
,
read_section_name
,
tmp
=
ch
)
}
state
(
read_section_name
)
{
action
(
is_alnum_or_dash
,
read_section_name
,
tmp
+=
ch
)
epsilon
(
close_section
)
}
// Wait for the closing ']', preceded by any number of whitespaces.
state
(
close_section
)
{
input
(
is_char
<
' '
>
,
close_section
)
input
(
is_char
<
'\t'
>
,
close_section
)
action
(
is_char
<
']'
>
,
dispatch
,
begin_section
())
}
// Dispatches to read sections, comments, or key/value pairs.
term_state
(
dispatch
)
{
input
(
is_char
<
' '
>
,
dispatch
)
input
(
is_char
<
'\t'
>
,
dispatch
)
input
(
is_char
<
'\n'
>
,
dispatch
)
input
(
is_char
<
'['
>
,
read_section_name
)
input
(
is_char
<
';'
>
,
comment
)
}
term_state
(
comment
)
{
input
(
is_char
<
'\n'
>
,
dispatch
)
any_input
(
comment
)
}
fin
();
}
}
// namespace parser
}
// namespace detail
}
// namespace caf
libcaf_core/test/read_ini.cpp
0 → 100644
View file @
08b9088f
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include <string>
#include <vector>
#include "caf/config.hpp"
#define CAF_SUITE read_ini
#include "caf/test/dsl.hpp"
#include "caf/detail/parser/read_ini.hpp"
using
namespace
caf
;
namespace
{
using
log_type
=
std
::
vector
<
std
::
string
>
;
struct
test_consumer
{
log_type
log
;
void
begin_section
(
std
::
string
name
)
{
name
.
insert
(
0
,
"begin section: "
);
log
.
emplace_back
(
std
::
move
(
name
));
}
void
end_section
()
{
log
.
emplace_back
(
"end section"
);
}
};
struct
fixture
{
expected
<
log_type
>
parse
(
std
::
string
str
,
bool
expect_success
=
true
)
{
detail
::
parser
::
state
<
std
::
string
::
iterator
>
res
;
test_consumer
f
;
res
.
i
=
str
.
begin
();
res
.
e
=
str
.
end
();
detail
::
parser
::
read_ini
(
res
,
f
);
if
(
res
.
code
==
detail
::
parser
::
ec
::
success
!=
expect_success
)
CAF_FAIL
(
"unexpected parser result state"
);
return
std
::
move
(
f
.
log
);
}
};
template
<
class
...
Ts
>
log_type
make_log
(
Ts
&&
...
xs
)
{
return
log_type
{
std
::
forward
<
Ts
>
(
xs
)...};
}
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
read_ini_tests
,
fixture
)
CAF_TEST
(
empty
inits
)
{
CAF_CHECK_EQUAL
(
parse
(
";foo"
),
make_log
());
CAF_CHECK_EQUAL
(
parse
(
"[foo]"
),
make_log
(
"begin section: foo"
,
"end section"
));
}
CAF_TEST_FIXTURE_SCOPE_END
()
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