On Mon, 03 Dec 2012 22:18:30 Solomon Gibbs wrote:
> This is a general question -- the JPEG example just happens to be a
> simple illustration.
> 
> If I don't do lookahead, then every APP0 segment type (JFIF, EXIF,
> unknown, etc.) will be entered; I will then have to do everything in
> finishing transitions or implement logic to roll back everything
> except the segment that succeeds. This also rules out the possibility
> of seeking the input to a different location based on the content of
> the segment.
> 
> Generally, it seems like lookahead should produce a simpler, faster,
> machine.

If you need lookahead, Ragel might not be the best option. If you know it's 
fed in particular ways (all data at once / whole blocks only / etc) then you 
might be able to do this, but Ragel itself only assumes it has the current 
character available when choosing a transition.

If these are reliably "tagged" somehow then you can embed priorities 
which make a decision when they recognise the tag:

general = (...) $ (my_alternatives, 0);
specific1 = "tag1" @ (my_alternatives, 1) (...);
specific2 = "tag2" @ (my_alternatives, 1) (...);

main = general | specific1 | specific2;

That would abandon the general case as soon as a tag is recognised. If you 
can work without lookahead, it will be faster.
_______________________________________________
ragel-users mailing list
ragel-users@complang.org
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to