I am testing out the functionality for to- and from-state actions in Ragel. I have the following Ragel program:
ragelScaffolding.rl:
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
char *p, *pe;
int cs;
void runRagelMachine(char instructions[], int instructionLen){
p = instructions;
pe = p + instructionLen;
%%{
machine test;
action testToAction1{
puts("1");
}
action testFromAction1{
puts("f1");
}
action testToAction2{
puts("2");
}
test = (
start: (
any -> s1
),
s1: (
any -> s2
)$to(testToAction1) $from(testFromAction1),
s2: (
any -> final
)$to(testToAction2)
);
main := test;
write data;
write init;
write exec;
}%%
}
int main(){
char buf[1024];
runRagelMachine(buf, 1024);
}
I would expect this to output the following:
1
f1
2
But instead it outputs:
1
f1
1
2
f1
2
Which tells me that it runs these actions twice. I have been thinking about why this might be the case and reading the documentation, but I can't seem to figure why this is happening. This happens when compiling with Ragel 6.9 and 7 (and compiling the C with gcc). The documentation says the following:
To-state actions are executed whenever the state machine moves into the specified state, either by a natural movement over a transition or by an action-based transfer of control such as fgoto. They are executed after the in-transition’s actions but before the current character is advanced and tested against the end of the input block.
But there is nothing in there about executing actions twice. I would really appreciate any help or clarification on this matter.
Thanks in advance.