[ragel-users] Actions embedded into unexpected transitions?

Adrian Thurston thurston at complang.org
Fri Jan 23 22:07:03 UTC 2009


Hi Dmitry,

This is a common mistake when people start with Ragel. Leaving actions 
require one character of lookahead, or, if they should be executed at 
the end of the input, for you to tell the machine that there is no more 
input by setting eof = pe.

Adrian

Dmitry Marakasov wrote:
> Hi!
> 
> I have a question about transition action embedding. It behaves
> not the way I expect, so I'm obviously missing something. Here's
> a simple example:
> 
> %%{
>     machine foo;
>     write data nofinal;
> 
>     a = 'a'+
>         > { printf("> a\n"); }
>         % { printf("< a\n"); }
>     ;
> 
>     b = a 'b'+
>         > { printf("> b\n"); }
>         % { printf("< b\n"); }
>     ;
> 
>     main := b+;
> }%%
> 
> When I run it on a string 'aabbaabb', it prints
> 
>> a
> < a
>> b
> < b
>> a
> < a
>> b
> 
> While I obviously expect
> 
>> b
>> a
> < a
> < b
>> b
>> a
> < a
> < b
> 
> because you can't enter 'a' rules not entering 'b' rule. Missing
> last transition is not a huge problem, but the order is essential.
> 
> Is there a trick to make it behave the way I want, or I do I not
> understand something fundamental?
> 




More information about the ragel-users mailing list