[ragel-users] How to look ahead

Adrian Thurston thurs... at cs.queensu.ca
Wed Jan 30 04:06:06 UTC 2008


Hey Jason,

Generally I do lookahead by moving p backwards. This should work even in
scanner actions (requires a recent version of Ragel). Can you give some
code that doesn't do what you expect? I don't understand exactly what
you're trying to do.

Adrian

Jason Garber wrote:
> 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
> http://code.whytheluckystiff.net/redcloth/browser/branches/superredcloth/ext/superredcloth_scan/superredcloth_inline.rl
> 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!
> Jason Garber
> > 
> 



More information about the ragel-users mailing list