How to look ahead

Jason Garber jason.gar... at
Mon Jan 28 22:09:16 UTC 2008

Hello Ragel users,
I'm working on SuperRedCloth (a Ragel implementation of RedCloth that
why the lucky stiff started awhile back).  I've run into some trouble
and could use some help.

In the inline scanner, we want the dimension rule to parse "1 x 2."
and then the formatter outputs it as "1 × 2."  As it was:

dim = ( digit+ >A %{ STORE(x) } " x " digit+ >A %{ STORE(y) } ) >X ;

(where A registers the start of the string to capture and STORE
captures it.  See
if you need more context.)

But, since it was in a scanner and it had to entertain the possibility
that the pattern was starting over (I assume), the STORE(y) action
would never happen, so you'd get "1 × ."

Assuming you can't have leaving actions at the end of a pattern in a
scanner, I considered (with the help of Johan Sørensen) looking ahead
for a digit but not consuming it, so with "1 x 2." the "1 x" is handed
to the formatter and the rest is handled by the default pattern (not
stored).  This gives the additional advantage of being able to parse
something like "1 x 2 x 3 x 4."

The question is, how to look ahead?  I've tried all kinds of things
with fhold, p--, etc., but it seems I'm at the limit of my Ragel
comprehension.  Or is there a better way than look-ahead?

Thanks in advance!

More information about the ragel-users mailing list