[ragel-users] union operator and thread-local variables

Adrian Thurston adrian.thurston at esentire.com
Wed Oct 28 15:00:36 UTC 2009


My suggestion is to store away values as you parse and then act when you 
get to the end of a 'stamp' using a leaving action. That way only one 
action will happen, unless there is ambiguity between the forms. You can 
check for ambiguity by looking at a graphviz rendering. If you see 
transitions with both actions in them then you have ambiguity.

-Adrian

Devin Bayer wrote:
> Hello. I would like to parse a date which can be in one of 
> several forms and I want to get the number of a month in a variable.
> 
> My problem is that for some input, the month is parsed by both 
> alternatives, but I need to get the correct value. If I could 
> detect which "thread" I am in, I could throw away the other 
> values in an @lerr handler.
> 
> This machine demonstrates what I want:
> 
> %%{
>      machine test;
> 
>      action in { puts("mon begins", fpc); }
>      action out { puts("mon ends", fpc); }
>      action fail { puts("thread failed", fpc); }
> 
>      i = digit+;
>      day = i " ";
>      mon = i >in %out " ";
>      time = (i ":" i) @lerr(fail);
>      stamp
>          = day mon time
>          | mon time
>          ;
> 
>      main := stamp "\n" >{ puts("done"); };
> }%%
> 
> Is there another way to do this?
> 
> Thanks,
> Devin Bayer
> 
> _______________________________________________
> ragel-users mailing list
> ragel-users at complang.org
> http://www.complang.org/mailman/listinfo/ragel-users
> 




More information about the ragel-users mailing list