[ragel-users] how to match beginning and end of payload.

Timothy Goddard tim at goddard.net.nz
Sat Mar 24 01:14:32 UTC 2012


Hi Ming,

Once you write any* (equivalent to regexp .*) then there could be anything in 
there, including the expression "b". It will never truly leave that machine as 
however much input you provide and however many "b"s in encounters, you could 
still be in the any* bit - an unlimited length sequence of any characters. 
This is the same as regular expression behaviour, but can have unexpected 
effects when actions are mixed in to the state machine.

What you usually want to do is to say that the expression stops on the first 
"b" - it matches the shortest possible sequence for any*. You can do this 
either by excluding "b" from the matched characters, or embedding a priority. 
The way to do this would be:

"a" any* :>> "b"

The :>> is an embedded priority operator - leaves the machine before it as 
soon as the machine after it accepts (is matched). In this case, it says that 
if we see a "b", assume that the any* bit is complete.

Cheers,

Tim

On Saturday 24 March 2012 09:30:59 Ming Fu wrote:
> Hi,
> 
> I was trying to write a ragel equivalent of regular expression /^a.*b$/.
> Basically matching input that start with 'a' and end with 'b'. The
> document did not specifically say the $ of regular expression is supported.
> 
> If I write something like:
> 
> my_pattern = ( a ) > { if (*pe == 'b' )
>                                           action_match;
>                                       else
>                                           action_no_match ;
>                                     };
> 
> main := my_pattern | some_other_patterns;
> 
> 
> what kind of action will cause the my_pattern to reach the final state
> of the successful match of main?
> 
> Best Regards,
> Ming
> 
> 
> 
> 
> _______________________________________________
> ragel-users mailing list
> ragel-users at complang.org
> http://www.complang.org/mailman/listinfo/ragel-users

_______________________________________________
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