For me, it is only slightly better: I think that for helping understanding and maintenance, the automaton state transitions should be all clear and loud in just one place, so I would really like to see a single common structure:
if (is "if") switch on all states; else if (is "elif") switch on all states; else if (is "else") switch on all states; else if (is "endif") switch on all states;
And minimal necessary error handling around that.
v20: attempt at implementing the switch-on-all-states style.