Commit c448f565 authored by Dominik Charousset's avatar Dominik Charousset

Fix behavior of term_state with exit statement

parent 1df50c94
...@@ -37,32 +37,31 @@ ...@@ -37,32 +37,31 @@
ps.code = caf::pec::unexpected_eof; \ ps.code = caf::pec::unexpected_eof; \
return; \ return; \
{ \ { \
static constexpr auto mismatch_ec = caf::pec::unexpected_character static_cast<void>(0); // dummy; init state closes parentheses
/// Defines a non-terminal state in the FSM. /// Defines a non-terminal state in the FSM.
#define state(name) \ #define state(name) \
CAF_FSM_EVAL_MISMATCH_EC \
} \ } \
{ \ for (;;) { \
static constexpr auto mismatch_ec = caf::pec::unexpected_character; \ /* jumps back up here if no transition matches */ \
ps.code = ch != '\n' ? caf::pec::unexpected_character \
: caf::pec::unexpected_newline; \
return; \
s_##name : \ s_##name : \
if (ch == '\0') \ if (ch == '\0') \
goto s_unexpected_eof; \ goto s_unexpected_eof; \
e_##name : e_##name :
/// Defines a state in the FSM that doesn't check for end-of-input. Unstable /// Defines a state in the FSM that doesn't check for end-of-input. Unstable
/// states are supposed to contain epsilon transitions only. /// states must make a transition and cause undefined behavior otherwise.
#define unstable_state(name) \ #define unstable_state(name) \
CAF_FSM_EVAL_MISMATCH_EC \
} \ } \
{ \ { \
static constexpr auto mismatch_ec = caf::pec::trailing_character; \
s_##name : \ s_##name : \
e_##name : e_##name :
/// Ends the definition of an FSM. /// Ends the definition of an FSM.
#define fin() \ #define fin() \
CAF_FSM_EVAL_MISMATCH_EC \
} \ } \
s_fin: \ s_fin: \
ps.code = caf::pec::success; \ ps.code = caf::pec::success; \
...@@ -70,21 +69,25 @@ ...@@ -70,21 +69,25 @@
/// Defines a terminal state in the FSM. /// Defines a terminal state in the FSM.
#define CAF_TERM_STATE_IMPL1(name) \ #define CAF_TERM_STATE_IMPL1(name) \
CAF_FSM_EVAL_MISMATCH_EC \
} \ } \
{ \ for (;;) { \
static constexpr auto mismatch_ec = caf::pec::trailing_character; \ /* jumps back up here if no transition matches */ \
ps.code = caf::pec::trailing_character; \
return; \
s_##name : \ s_##name : \
if (ch == '\0') \ if (ch == '\0') \
goto s_fin; \ goto s_fin; \
e_##name : e_##name :
/// Defines a terminal state in the FSM. /// Defines a terminal state in the FSM that runs `exit_statement` when leaving
/// the state with code `pec::success` or `pec::trailing_character`.
#define CAF_TERM_STATE_IMPL2(name, exit_statement) \ #define CAF_TERM_STATE_IMPL2(name, exit_statement) \
CAF_FSM_EVAL_MISMATCH_EC \
} \ } \
{ \ for (;;) { \
static constexpr auto mismatch_ec = caf::pec::trailing_character; \ /* jumps back up here if no transition matches */ \
ps.code = caf::pec::trailing_character; \
exit_statement; \
return; \
s_##name : \ s_##name : \
if (ch == '\0') { \ if (ch == '\0') { \
exit_statement; \ exit_statement; \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment