[ragel-users] Ragel pointers

Wincent Colaiuta w... at wincent.com
Sat Aug 30 13:25:34 UTC 2008


El 26/8/2008, a las 1:03, Matt Reynolds escribió:

> I've tried various permutations, with some success, but this is the
> configuration that has yielded the most results.  I'm attempting to
> parse text in two passes, with the first pass catching all line-based
> formatting and the second catching any inter-line formatting.
>
> At this point, I'm just looking for some more general explanation of
> best practices for how to write parsers like this in Ragel.  I've
> followed the examples, and each time I come back to this hobby project
> I understand a little more, but I figured I'd ask if people have
> general tips (or more full fledged examples) of how to write these
> sorts of parsers in Ragel.
>
> I've looked around for other examples of wiki-text parsers and what
> not, but they're generally very complicated and very lengthy, which
> seem to go against the elegance that Ragel embodies.

I wrote a wikitext translator in C (as a Ruby extension) which uses a  
Ragel-generated lexer and a hand-coded C parser. Probably falls into  
the category of "very complicated and very lengthy" but it still may  
be worth a look:

http://git.wincent.com/wikitext.git

It's worth noting that the Ragel part, the lexer, is relatively simple  
and elegant; all of the complexity is in the parser. Compare the Ragel  
lexer:

http://git.wincent.com/wikitext.git?a=blob;f=ext/wikitext_ragel.rl

With the hand-coded C parser:

http://git.wincent.com/wikitext.git?a=blob;f=ext/parser.c

Trouble is that if you want to get into stuff like nested lists your  
code _is_ going to get pretty complicated; can't see anyway around  
that. But the payoff is that the translator is very, very fast (thanks  
to Ragel) and very, very robust. To get an idea of the kind of things  
the translator can handle check out the spec (test) suite; here's an  
example of an integration spec that includes a bit of everything:

http://git.wincent.com/wikitext.git?a=blob;f=spec/integration_spec.rb

Cheers,
Wincent





More information about the ragel-users mailing list