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
6
votes
1 answer

Avoiding attribute copies with karma generators

I'm using karma to generate representations of large structs, but the structs are being copied during generation. I don't think they need to be, so was wondering how to avoid it. The quick example below prints "Copy!", as the target struct is…
aldous
  • 63
  • 4
4
votes
1 answer

Boost-spirit-karma and boost-variant "concepts" related to auto generators

I need to deserialize a std::vector> with decoration supplied by other objects. One of the things the "decoration" enables is a empty entry in the vector. I have hit a brick wall in my real implementation. However, I have managed…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
3
votes
1 answer

Boost Karma: writing a rule with boost::optional>

I am attempting to use a boost::variant within a boost::optional in a Karma generator. I've been able to reduce the problem to this: using FooVariant = boost::variant; using FooOptional = boost::optional; template
Addy
  • 2,414
  • 1
  • 23
  • 43
3
votes
1 answer

Boost karma: how does this implicit call to transform_attribute work? (or doesn't?)

I have the following piece of code that seems to work fine (I based the semantic actions on reuse parsed variable with boost karma). #include #include #include #include #include #include…
rectummelancolique
  • 2,247
  • 17
  • 13
3
votes
1 answer

How does one generate from boost karma into C++ array?

I see how karma can be used to generate into a container that manages memory, like std::string. But what about the case where a buffer (char[N]) has been pre-allocated? { using namespace boost::spirit::karma; { std::string buffer; …
user1338952
  • 3,233
  • 2
  • 27
  • 41
3
votes
1 answer

How is it possible to pass attributes to child rules in boost spirit karma

I am parsing text into an AST via qi and generates text again via karma. This is working as expected, but wants some method to pass on an attribute from one rule to another. Ported from the comments: Current Code On Coliru #include…
Dev Dev
  • 105
  • 6
3
votes
1 answer

boost spirit karma generation from a collection of struct using a member function

I am trying to use karma to generate a comma separated list of strings, from a vector of structs that contain a member function that provides the string. While I can generate single string output using phoenix::bind, and I can generate a csv output…
nostep
  • 35
  • 6
3
votes
1 answer

boost karma - generate multiple strings from one attribute

I am using a karma genarator thats consuming a vector of pairs - simular to http://boost-spirit.com/home/articles/karma-examples/output-generation-from-a-list-of-key-value-pairs-using-spirit-karma/ i built an example to show my problem following…
Rick
  • 33
  • 5
3
votes
1 answer

C++ boost::spirit::karma rule for variants

I have a boost::variant in my program that takes types of double, uint16_t, std::string, etc. I'm storing these and I'd like to use boost::karma to generate/print them out. I'm new to boost::spirit, but I understand it works well with variants. What…
Kevin
  • 16,549
  • 8
  • 60
  • 74
3
votes
1 answer

Generate string if boolean attribute is true (karma counterpart to qi::matches)

Imagine we want to parse and generate simple C++ member function declarations with Boost.Spirit. The Qi grammar might look like this: function_ %= type_ > id_ > "()" > matches["const"]; That means, whether the function is const is stored in a…
purpleKarrot
  • 156
  • 8
3
votes
1 answer

Boost Karma - non consuming predicate

I need to print a std::complex but omitting imaginary part if it's equal zero. So I have a rule with two productions: karma::rule()> complexRule = '(' << double_ << ", " double_ << ')' | double_ <<…
MarekR
  • 2,410
  • 1
  • 14
  • 10
3
votes
1 answer

reuse parsed variable with boost karma

I have a code base which is quite equivalent to the code below. I try to generate a text file with two times the content of a variable. I feel that the answer is in semantic actions and _a and _val but cannot manage to get through even with the…
Quanteek
  • 254
  • 2
  • 11
3
votes
2 answers

Generating default value when none is found

I have an input vector that can have any size between empty and 3 elements. I want the generated string to always be 3 floats separated by spaces, where a default value is used if there aren't enough elements in the vector. So far I've managed to…
Krienie
  • 611
  • 1
  • 6
  • 14
3
votes
1 answer

Use karma to generate output for a vector of pointers

I'm having some trouble using karma to generate output for a struct that is held in a vector of boost::shared_ptrs. I've got a small test case using ints that doesn't compile. I was thinking I could use the deref_iterator customization point to…
Epimetheus
  • 1,119
  • 1
  • 10
  • 19
2
votes
1 answer

Semantic actor with boost::spirit::karma::lit

Help me please find a solution to a seeming simple problem. I need generate a string from a container in a form index=value. For example: seq = { 10, 20, 30 } output = "1=10&2=20&3=30" But I found no way to do so with the boost::spirit::karma…
sliser
  • 1,645
  • 11
  • 15
1
2 3 4