Re: Proper whitespace formatting in mini_xml_karma.cpp example code

Maarten Verhage <[email protected]> Wed, 30 May 2018 13:31:48 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <AM5P192MB0131A0B1D2CB76105B8F885BBA6C0@AM5P192MB0131.EURP192.PROD.OUTLOOK.COM>
----- Original Message ----- 
From: "Seth" <[email protected]>
To: <[email protected]>
Sent: Monday, April 23, 2018 21:59
Subject: [Spirit-general] Proper whitespace formatting in mini_xml_karma.cpp 
example code


> Do you want pretty printing? Or do you want whitespace preservation, as
> you seemingly say.
>
> Regardless of the choice there, stateful pretty printing in karma isn't
> my favorite pastime. I always find that writing a visitor myself is less
> work.
>
> There's an old thread here:
> http://boost.2283326.n4.nabble.com/Indentation-on-Karma-td2677502.html
> that discusses a mechanism for inclusion in the library.
>
> Related sample directives are here:
> https://stackoverflow.com/questions/18085020/boostspiritkarma-how-to-get-current-position-of-output
> (the answers are by llonesmiz from this list, usually recommendable).
>
> I thought I'd have tackled this problem on SO myself once or twicewith
> varying degrees of success. See e.g. this answer:
> https://stackoverflow.com/a/46854802/85371 which is a followup to my
> earlier answer that didn't use Karma. The topic is similar, but about
> pretty-printing Json instead. In that answer I show how to do "the same"
> but without karma, and you can see the difference. As I remember the
> end-result wasn't as bad as I anticipated, so you might find it
> perfectly viable :) I just glanced it over and I think it didn't go all
> the way and left proper indenting as an "exercise for the reader".
>
> Hope the info helps you,
>
> Seth
>
>
>
>
>
> On 17-04-18 08:52, Maarten Verhage wrote:
>> Dear people,
>>
>> I'm using some CAD software tool that produces output that looks a bit 
>> like
>> xml. Certain values that are produced in these files are undesired in my
>> perspective. So I wish to change them automatically. Therefore I was
>> thinking that the mini_xml_karma example code of Spirit 2.5.3 is a good
>> starting point to write such an utility program. Correct?
>>
>> I've done some stuff with Spirit in the past but you still should 
>> consider
>> me a novice on this topic.
>>
>> Regarding the mini_xml_karma example code I managed to write the result 
>> to a
>> file. However the whitespace is removed from it, as was the case with the
>> original output to std::cout.
>>
>> My next objective is to generate proper whitespace. I've no need the
>> preserve the original line numbers so I can define my own formatting 
>> style
>> for this. I think something like the formatting of the "3.toyxml" file 
>> would
>> be fine. So, top hierarchy start tags should have a line feed directly 
>> after
>> it. Any line that follows should have indentation of some spaces until 
>> the
>> end tag. Subsequent start/end tags should be on the same line.
>>
>> Do you know of some example code that shows behavior like this? Or which
>> Spirit and/or Karma facilities should I be using to implement this?
>>
>> Thank you very much for your attention and time!
>>
>> Best regards,
>> Maarten Verhage
>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Spirit-general mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/spirit-general
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Spirit-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/spirit-general
>
Dear people,

I'm sorry for not responding earlier. It was pretty printing I was aiming 
for. According to Seth’s suggestion I plan to do it without karma. Once I’ve 
a parsed data structure I can manually print it out to a ostream. And indent 
based on what I encounter in this data structure.

Thanks anyways!

Maarten Verhage 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general