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
feae89a3
Commit
feae89a3
authored
Aug 07, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parse function for atoms
parent
2cfa6ee6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
1 deletion
+26
-1
libcaf_core/caf/detail/parse.hpp
libcaf_core/caf/detail/parse.hpp
+5
-0
libcaf_core/caf/detail/parser/read_atom.hpp
libcaf_core/caf/detail/parser/read_atom.hpp
+8
-1
libcaf_core/src/parse.cpp
libcaf_core/src/parse.cpp
+5
-0
libcaf_core/test/parse.cpp
libcaf_core/test/parse.cpp
+8
-0
No files found.
libcaf_core/caf/detail/parse.hpp
View file @
feae89a3
...
...
@@ -21,6 +21,7 @@
#include <cstdint>
#include "caf/detail/parser/state.hpp"
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
namespace
caf
{
...
...
@@ -54,5 +55,9 @@ void parse(parse_state& ps, float& x);
void
parse
(
parse_state
&
ps
,
double
&
x
);
// -- CAF types ----------------------------------------------------------------
void
parse
(
parse_state
&
ps
,
atom_value
&
x
);
}
// namespace detail
}
// namespace caf
libcaf_core/caf/detail/parser/read_atom.hpp
View file @
feae89a3
...
...
@@ -41,7 +41,8 @@ namespace parser {
/// Reads a number, i.e., on success produces either an `int64_t` or a
/// `double`.
template
<
class
Iterator
,
class
Sentinel
,
class
Consumer
>
void
read_atom
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&
consumer
)
{
void
read_atom
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&&
consumer
,
bool
accept_unquoted
=
false
)
{
size_t
pos
=
0
;
char
buf
[
11
];
memset
(
buf
,
0
,
sizeof
(
buf
));
...
...
@@ -58,10 +59,12 @@ void read_atom(state<Iterator, Sentinel>& ps, Consumer& consumer) {
if
(
ps
.
code
<=
pec
::
trailing_character
)
consumer
.
value
(
atom
(
buf
));
});
// clang-format off
start
();
state
(
init
)
{
transition
(
init
,
"
\t
"
)
transition
(
read_chars
,
'\''
)
epsilon_if
(
accept_unquoted
,
read_unquoted_chars
,
is_legal
)
}
state
(
read_chars
)
{
transition
(
done
,
'\''
)
...
...
@@ -70,7 +73,11 @@ void read_atom(state<Iterator, Sentinel>& ps, Consumer& consumer) {
term_state
(
done
)
{
transition
(
done
,
"
\t
"
)
}
term_state
(
read_unquoted_chars
)
{
transition
(
read_unquoted_chars
,
is_legal
,
append
(
ch
),
pec
::
too_many_characters
)
}
fin
();
// clang-format on
}
}
// namespace parser
...
...
libcaf_core/src/parse.cpp
View file @
feae89a3
...
...
@@ -19,6 +19,7 @@
#include "caf/detail/parse.hpp"
#include "caf/detail/consumer.hpp"
#include "caf/detail/parser/read_atom.hpp"
#include "caf/detail/parser/read_floating_point.hpp"
#include "caf/detail/parser/read_signed_integer.hpp"
#include "caf/detail/parser/read_unsigned_integer.hpp"
...
...
@@ -51,5 +52,9 @@ PARSE_IMPL(float, floating_point)
PARSE_IMPL
(
double
,
floating_point
)
void
parse
(
parse_state
&
ps
,
atom_value
&
x
)
{
parser
::
read_atom
(
ps
,
make_consumer
(
x
),
true
);
}
}
// namespace detail
}
// namespace caf
libcaf_core/test/parse.cpp
View file @
feae89a3
...
...
@@ -120,3 +120,11 @@ CAF_TEST(invalid floating point numbers) {
CHECK_INVALID
(
double
,
"--0.01e10"
,
pec
::
unexpected_character
);
CHECK_INVALID
(
double
,
"++10e-10"
,
pec
::
unexpected_character
);
}
CAF_TEST
(
valid
atom
value
)
{
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"foo"
),
atom
(
"foo"
));
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"'foo'"
),
atom
(
"foo"
));
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"foooooooooo"
),
pec
::
too_many_characters
);
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"foo,bar"
),
pec
::
trailing_character
);
CAF_CHECK_EQUAL
(
read
<
atom_value
>
(
"$"
),
pec
::
unexpected_character
);
}
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