The eof action will be executed when p == pe == eof . Another important thing: when your state machine cannot match the any state, the state goes into error and the match stops, which means that you can never reach the end.
See when you type foo1 . When parsing on o everything is fine. Howerver the next character 1 cannot correspond to the state you specified, so an error occurs. You can never meet the action eof. Thus, the variable res and finish is 0.
When you type foo , everything is fine. The state can go to the end. Thus, the action of eof occurs.
You can set the action with an error to see what happens:
%%{ main := ( 'foo' | 'bar' ) 0 @{ res = 1; } $err{ printf("error : %c", fc);} $/{ finished = 1; }; }%%
And you can try this code to meet your needs:
%%{ main := (( 'foo' | 'bar' ) 0 @{ res = 1; } | any* ) $/{ finished = 1; }; }%%
source share