I'm working with Ragel to evaluate FSAs, and I want to embed a user action that runs whenever my machine finishes testing the input. I need this action to run regardless of whether or not the machine ends in an accepting state or not. I have this modified example taken from the Ragel guide that illustrates what I'm going for:
#include <string.h>
#include <stdio.h>
%%{
machine foo;
main := ( 'foo' | 'bar' ) 0 @{ res = 1; } $/{ finished = 1; };
}%%
%% write data;
int main( int argc, char **argv ) {
int cs, res = 0, finished = 0;
if ( argc > 1 ) {
char *p = argv[1];
char *pe = p + strlen(p) + 1;
char* eof = pe;
%% write init;
%% write exec;
}
printf("result = %i\n", res );
printf("finished = %i\n", finished);
return 0;
}
My goal for this example is for res to be 1 when the input is either 'foo' or 'bar', while finished is 1 no matter the input. I can't get this to work though - finished seems to be 1 when res is 1, and 0 when res is 0.
Any help would be awesome.