[ragel-users] Searching a buffer

Adrian Thurston thurston at complang.org
Mon Apr 20 23:10:17 UTC 2009

There's no best way, you just have to choose one that works for you. The 
alternative to the two methods you tried is to manually run the machine 
( A | B | C ) at every position in the input. As soon as it fails it 
will stop so you won't get N^2 running time. This is very much like 
using a scanner. You'll have to keep data around though. You can't do 
that on one pass of the data for the same reason you need to do some 
management of ts, te, etc. for a scanner.


Smelly Pooh wrote:
> Hi,
> What's the best way to search a buffer for a list of patterns using ragel?
> I've tried:
> search = A | B | C;
> main := any* search;
> which works ok but generates a lot of states.
> I've also tried using a scanner like:
> main := |*
>     A;
>     B;
>     C;
>     any;
> *|;
> which also works and generates much fewer states, but I'm not interested 
> in writing extra code to handle te, ts, eof etc.
> ------------------------------------------------------------------------
> _______________________________________________
> 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