|
Boost : |
Subject: Re: [boost] [spirit][karma] In-place modification of previously parsed content?
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2009-08-19 14:44:27
> I wonder if it is possible to modify previously parsed content using
> Karma. An example is some text like:
>
> coordinate (1, 4.15, 1.49, 0.81) // some comment 1
> coordinate (1, -19, 4, -1) // some comment 2
>
> Now suppose the numbers are all parsed, and I change the 0.81 to 71.44.
> I want to update the text accordingly:
>
> coordinate (1, 4.15, 1.49, 71.44) // some comment 2
> coordinate (1, -19, 4, -1) // some comment 2
>
> Note how the overall formatting and comments are preserved. The text
> could contain lots of other strings etc. and they would be all left
> untouched. This part - the preservation - is the hard one, and I ask,
> is this possible using Karma?
If Spirit.Qi is for turning unstructured input (most often text/character
streams) into structured (internal) data (most often called parsing) then
Spirit.Karma is for doing the opposite: turning structured (internal) data
into unstructured (external) text/character streams (some people call it
unparsing, we call it generating). Both Qi and Karma use similar grammars to
describe the format of the external representation while using C++ data
structures as the internal representation.
So the answer to your question is: as long as you have/create a format
description for your external textual representation it is possible to use
Karma to generate text matching the required format from your internal data.
See here for a more elaborate higher level description:
http://tinyurl.com/nca9pk.
HTH
Regards Hartmut
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk