Boost logo

Boost :

Subject: [boost] [Spirit] Creating a simple text format parser
From: Kisso Bajslovski (ylisaren_at_[hidden])
Date: 2008-11-21 09:55:02

I'm trying to create a simple parser to format a text input, Spirit seems to
fit the bill nicely for my needs, but I'm having a few problems. First of
all while the documentation is rather large, it would be sweet with some
more small examples for a few small but as different as possible grammars.
There's some already hidden in the docs at various places, it would be sweet
if there was a section in the manual with all the code examples gathered.

Anyway, on to my little problem. I'm trying to create a grammar which is
fairly close to HTML in one regard, consider the following:

Some default text <font=Arial><color=FFFFFF>some white arial text</font>
some white text with default font</color> some text with default settings

So basically I need to create a rule which when encountering a tag pushes it
onto a stack, and later on pops it when the matching closing tag is found,
clearing its states. I have got a bit into that part, even if I would love
some suggestions on it still if anyone have done something similar in
Spirit. But the real problem actually is with the text which isn't a tag. I
use anychar_p for that at the moment to capture it with a simple semantic
action. The problem is that anychar_p just retrieves a single character,
when I'd like to actually get it in the form of a string instead. To render
it 1 char at the time is highly inefficient. I could use some global string
to which I accumulate the chars and then let the tags check it and render
its contents, but that seems hackish at best. For a parser such as this, is
there a better way perhaps?


Boost list run by bdawes at, gregod at, cpdaniel at, john at