Pyparsing Question.

Ant antroy at gmail.com
Wed Nov 22 04:44:06 EST 2006


I have a home-grown Wiki that I created as an excercise, with it's own
wiki markup (actually just a clone of the Trac wiki markup). The wiki
text parser I wrote works nicely, but makes heavy use of regexes, tags
and stacks to parse the text. As such it is a bit of a mantainability
nightmare - adding new wiki constructs can be a bit painful.

So I thought I'd look into the pyparsing module, but can't find a
simple example of processing random text. For example, I want to parse
the following:

"Some random text and '''some bold text''' and some more random text"

into:

"Some random text and <strong>some bold text</strong> and some more
random text"

I have the following as a starting point:

from pyparsing import *

def parse(text):
    italics = QuotedString(quoteChar="''")

    parser = Optional(italics)

    parsed_text = parser.parseString(text)


print parse("Test this is '''bold''' but this is not.")

So if you could provide a bit of a starting point, I'd be grateful!

Cheers,




More information about the Python-list mailing list