Forum: Redcloth divide and conquer

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gaspard B. (Guest)
on 2009-06-18 16:02
(Received via mailing list)
Hi list (and Jason) !

I have a prototype parser that uses a Regexp based "Divide and
Conquer" pattern to parse textile:

This parser currently only parses simple 'list', 'strong', 'em' and
'bold' but it is very easy to extend and adapt.

To give you an idea of how this thing works:

1. take a string
2. try to match first regular expression from context (if you are in
:main and :main => [:p, :bold], the first regexp is defined by :p =>
3. if the pattern matches, insert a placeholder and scan matched text
in the new context (:p).
4. when you cannot match (no more re in context list), unfold by
expanding text to an S-expression tree


"hello _em and *strong*_"

match regular expression associated with :em
=> "hello @@=9347=@@"

scan matched content in :em context
=> "em and *strong*" matches :strong
=> "em and @@=9350=@@"

no match in "strong"

expand in :strong context ==> [:strong, "strong"]
expand in :em context     ==> [:em, "em and ", [:strong, "strong"]]
expand in :main              ==> [:main, "hello ", [:em, "em and ",
[:strong, "strong"]]]

Let me know what you think.

This topic is locked and can not be replied to.