Questions tagged [boost-spirit-karma]

Any question related to boost spirit generators, which are part of the karma sub-library of the spirit Library. It is the pending tag of boost-spirit-qi dedicated to parsers (as opposed to generators)

For more information, the best is to look at boost spirit documentation

karma is the part of the boost spirit Library dedicated to generators. Generators are objects used to format information to be printed, according to a predefined formatting rule (which could be called a grammar). In the boost spirit Library, generators are opposed to parsers, which are reading printed information according to a given grammar.

51 questions
2
votes
1 answer

Make reordered tuple from vector of tuple with use spirit::karma

#include #include #include #include //------------------------------------------------------------------------- #include #include…
2
votes
1 answer

boost::spirit::karma alternative generator with boost::variant consisting a string and string alias

I have a boost::variant consisting out of several types, including string type aliases and a string type. The string type aliases work as aspected with the boost::spirit::qi alternative parser, but the boost::spirit::karma alternative generator does…
Superlokkus
  • 4,731
  • 1
  • 25
  • 57
2
votes
1 answer

Inconsistent Generator directive column behavior in boost karma

I am writing a karma generator to generate a HTML page and I am experiencing inconsistent behavior while using column directive. It could very well be my understanding of how it works. Basically I am generating a grid which requires me to insert…
user48833
  • 35
  • 4
2
votes
1 answer

boost::spirit::karma grammar: Comma delimited output from struct with optionals attributes

I need a comma delimited output from a struct with optionals. For example, if I have this struct: MyStruct { boost::optional one; boost::optional two; boost::optional three; }; An output like: { "string", 1,…
Emi
  • 23
  • 4
2
votes
1 answer

Is it possible to reuse a Spirit Qi grammar as a Spirit Karma grammar?

I have a Qi grammar definition that I use to parse an input. Later I have a Karma generator to output in a way that should be similar to the input. Is this possible at all? It seem that a parser grammar can be transformed into a generator grammar…
alfC
  • 14,261
  • 4
  • 67
  • 118
2
votes
1 answer

Can I do versatile mathematical (AST) pattern matching and manipulation with Boost.Spirit?

I was looking into pattern matching in C++, and among things like Mach7, which seems to be a functional approach to the problem, and the more general Visitor Pattern, which seems to be the lowest common denominator: it can do everything but excels…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
2
votes
1 answer

boost spirit karma real generator performance

I was checking boost spirit karma generator performance when I was somewhat surprised by performance degradation when using policy for real numbers. Live on Coliru The code was taken from boost spirit and a couple of test functions were added.…
kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
2
votes
1 answer

Boost.Spirit.Karma set precision

I'm starting to use the Karma generate feature to convert double to char with a sprintf like functionality. For that I'm using the following example: template class double3_policy : public boost::spirit::karma::real_policies
Montes
  • 340
  • 2
  • 8
2
votes
1 answer

Boost Spirit Karma equivalent to Qi matches

What is the equivalent to boost::spirit::qi::matches in boost::spirit::karma? For example I want to generate a literal "array" only if a boolean flag is set true.
Baradé
  • 1,290
  • 1
  • 15
  • 35
2
votes
1 answer

boost::spirit::karma alternative selection based on properties of the input

I'm trying to write a boost::spirit::karma generator where some of the output depends on non-trivial properties of the input values. The actual problem is part of a larger grammar, but this example has the same properties as several of the other…
Michael Berg
  • 433
  • 2
  • 7
2
votes
2 answers

How to tel a boost::karma::rule not to consume its attribute without providing a valid generator?

Say we have the following source code: #include #include #include #include namespace karma = boost::spirit::karma; template struct grammar :…
Jean-Bernard Jansen
  • 7,544
  • 2
  • 20
  • 17
2
votes
1 answer

boost::spirit::karma Generator Semantic Actions in rules

This has been plaguing me for hours, and I do not understand how to make it work. I simply want to do something each time a rule is used, in this example increment a counter. If I do not explicitly specify the rule but use it in the call to…
Xoph
  • 459
  • 2
  • 10
2
votes
3 answers

boost::spirit::karma output of string in quotation marks

I am trying to escape a string in quotation marks using boost::spirit::karma. This works fine if it's just a string. However, for a string in a boost::variant in a std::vector, it does not. Just printing the string does work however, I do not…
Xoph
  • 459
  • 2
  • 10
2
votes
2 answers

Boost:Spirit:Karma: How to get current position of output?

I want to generate some formatted output. For this some indention is needed. So at some point during generation I would like to get the current position, to have the following lines indented with that amount. Here is a minimal example. Please…
Mike M
  • 2,263
  • 3
  • 17
  • 31
2
votes
1 answer

How to access data of nested objects in boost::spirit::karma?

In an ItemList containing lists of Item objects, how do I access the Item objects in the generator? The following sample code compiles on VC9 (with boost include and link directories set apropriately). I don't know how to set up…
foraidt
  • 5,519
  • 5
  • 52
  • 80