Commit 9c5bb7bc authored by Dominik Charousset's avatar Dominik Charousset

Add exit statements to terminal states

parent dc9979fa
...@@ -50,17 +50,6 @@ ...@@ -50,17 +50,6 @@
goto s_unexpected_eof; \ goto s_unexpected_eof; \
e_##name : e_##name :
/// Defines a terminal state in the FSM.
#define term_state(name) \
CAF_FSM_EVAL_MISMATCH_EC \
} \
{ \
static constexpr auto mismatch_ec = caf::pec::trailing_character; \
s_##name : \
if (ch == '\0') \
goto s_fin; \
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 are supposed to contain epsilon transitions only.
#define unstable_state(name) \ #define unstable_state(name) \
...@@ -79,6 +68,31 @@ ...@@ -79,6 +68,31 @@
ps.code = caf::pec::success; \ ps.code = caf::pec::success; \
return; return;
/// Defines a terminal state in the FSM.
#define CAF_TERM_STATE_IMPL1(name) \
CAF_FSM_EVAL_MISMATCH_EC \
} \
{ \
static constexpr auto mismatch_ec = caf::pec::trailing_character; \
s_##name : \
if (ch == '\0') \
goto s_fin; \
e_##name :
/// Defines a terminal state in the FSM.
#define CAF_TERM_STATE_IMPL2(name, exit_statement) \
CAF_FSM_EVAL_MISMATCH_EC \
} \
{ \
static constexpr auto mismatch_ec = caf::pec::trailing_character; \
s_##name : \
if (ch == '\0') { \
exit_statement; \
goto s_fin; \
} \
e_##name :
#define CAF_TRANSITION_IMPL1(target) \ #define CAF_TRANSITION_IMPL1(target) \
ch = ps.next(); \ ch = ps.next(); \
goto s_##target; goto s_##target;
...@@ -193,6 +207,11 @@ ...@@ -193,6 +207,11 @@
#ifdef CAF_MSVC #ifdef CAF_MSVC
/// Defines a terminal state in the FSM.
#define term_state(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_TERM_STATE_IMPL, __VA_ARGS__)(__VA_ARGS__), \
CAF_PP_EMPTY())
/// Transitions to target state if a predicate (optional argument 1) holds for /// Transitions to target state if a predicate (optional argument 1) holds for
/// the current token and executes an action (optional argument 2) before /// the current token and executes an action (optional argument 2) before
/// entering the new state. /// entering the new state.
...@@ -223,6 +242,10 @@ ...@@ -223,6 +242,10 @@
#else // CAF_MSVC #else // CAF_MSVC
/// Defines a terminal state in the FSM.
#define term_state(...) \
CAF_PP_OVERLOAD(CAF_TERM_STATE_IMPL, __VA_ARGS__)(__VA_ARGS__)
/// Transitions to target state if a predicate (optional argument 1) holds for /// Transitions to target state if a predicate (optional argument 1) holds for
/// the current token and executes an action (optional argument 2) before /// the current token and executes an action (optional argument 2) before
/// entering the new state. /// entering the new state.
......
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