Questions tagged [boost-spirit-qi]

a practical, scalable parsing library for C++

Spirit.Qi is designed to be a practical parsing tool. The ability to generate a fully-working parser from a formal EBNF specification inlined in C++ significantly reduces development time.

Programmers typically approach parsing using ad hoc hacks with primitive tools such as scanf. Even regular-expression libraries (such as boost regex) or scanners (such as boost tokenizer) do not scale well when we need to write more elaborate parsers. Attempting to write even a moderately-complex parser using these tools leads to code that is hard to understand and maintain.

One prime objective is to make the tool easy to use. When one thinks of a parser generator, the usual reaction is “it must be big and complex with a steep learning curve.” Not so. Spirit is designed to be fully scalable. The library is structured in layers. This permits learning on an as-needed basis, after only learning the minimal core and basic concepts.

For development simplicity and ease in deployment, the entire library consists of only header files, with no libraries to link against or build. Just put the Spirit distribution in your include path, compile and run. Code size is very tight, essentially comparable to hand-written recursive descent code.

Have fun!

Further Reading

687 questions
1
vote
1 answer

Track input file as well as position while parsing in boost spirit qi?

I had a look at the question but however it does not quite answer my problem. I am trying to write a grammar to parse XML using Spirit Qi and I for every line I want to append the filename as well as the line number in that file. So if there are…
vishal129
  • 105
  • 9
1
vote
1 answer

Internal compiler error with Boost.Spirit

I'm trying to compile the following seemingly simple code using GCC 3.4.6 and Boost 1.43 and it's generating an internal compiler error: #include #include #include…
Haitham Gad
  • 1,529
  • 2
  • 13
  • 23
1
vote
1 answer

boost spirit qi multiple start rules

How can I define a spirit qi grammar which can have more than one starting rule? I am working on an XML grammar and I want to have 4 possible starting rules. So if I have a grammar called xml_grammar and the base_type is (A, "A"). I also want few…
vishal129
  • 105
  • 9
1
vote
1 answer

Attribute compatibility not disabled by semantic actions

I have a grammar rule that looks like this: rule expr, factor; expr = ( +( ( toks.symbol // toks.symbol attribute type is an std::string [ // I'm trying to force…
Haitham Gad
  • 1,529
  • 2
  • 13
  • 23
1
vote
1 answer

How to use attribute grammar to parse a string into classes

I like the idea of using attribute grammar to directly parse an input string and fill in a struct after adapting it to a random access sequence using BOOST_FUSION_ADAPT_STRUCT and was wondering if it's possible to adapt a class with private members…
Haitham Gad
  • 1,529
  • 2
  • 13
  • 23
1
vote
1 answer

Parsing ipv4 addresses using boost-spirit

I would like to use boost::spirit for parsing ipv4 addresses. Here is what I have tried to do: #include #include #include #include #include #include…
Allan
  • 4,562
  • 8
  • 38
  • 59
1
vote
1 answer

Error when using boost::spirit::qi::phrase_parse() with a qi::grammar

I'm doing an IRC message parser with Boost.Spirit but I'm getting a (very long) error when I try to parse an input. I've followed the "Roman Numerals" example. Also, I'm using g++4.7 with -std=c++11. The error occurs only when I call phrase_parse()…
Murilo Vasconcelos
  • 4,677
  • 24
  • 27
1
vote
1 answer

How do I assign the result of a function object to a local in a boost::spirit semantic action

Im not really sure why the following code gives me the following error in GCC 4.6.3 no match for ‘operator=’ in ‘boost::spirit::_a = boost::phoenix::function::operator()(const A0&) const [with A0 = boost::phoenix::actor >, F = make_line_impl,…
Hippiehunter
  • 967
  • 5
  • 11
0
votes
2 answers

Boost Spirit Auto Parser fails for a tuple of doubles

At the following code I am trying to use Boost Spirit Auto Parser for a sequence or two doubles, but it doesn't compile. What am I doing wrong here? // file main.cpp #include #include namespace…
Vahagn
  • 4,670
  • 9
  • 43
  • 72
0
votes
1 answer

Providing default values for parser attributes in boost::spirit

I've been implementing boost::spirit into a project and one of my challenges is to parse directly into a container of the type: map I'm almost there. The issue I've run up against is assigning the key value of the std::pair…
Joel Graff
  • 239
  • 6
  • 14
0
votes
1 answer

Unable to make grammar from rule in boost::spirit::qi

I am trying to use the Spirit library for the first time. I am enjoying it so far but I find myself unable to build a grammar from predefined rules, even when trying examples heavily inspired by the documentation! Here is the heart of my problem…
Antoine Gersant
  • 526
  • 4
  • 7
0
votes
2 answers

Class v/s struct in boost::spirit

In the boost::spirit documentation, grammars are defined by using struct. For example, template struct my_grammar : qi::grammar, ascii::space_type > { my_grammar() :…
Dilawar
  • 5,438
  • 9
  • 45
  • 58
0
votes
0 answers

Parsed boost::spirit::qi::rule in memory mapped file

I have several large logical expressions (length upto 300K) of the form - ( ( ( 1 ) and ( 5933 or 561 or 1641 ) ) or ( ( 71 or 1 or 15 or 20 ) and ( 436 ) ) or ( ( 398 or 22 or 33 ) ) ) that are parsed using Boost Spirit (as shown in the example…
0
votes
1 answer

Boost::spirit::qi parse alternative variant

I need to parse string with parameters A and B. Order of the parameters not defined. I.e. string can be present as one of the next formats A="value1",B="value2" B="value1",A="value2" Part of my code you can see below. But in that code I can parse…
0
votes
1 answer

Parsing single spaces using boost::spirit parser

I want to able to parse single spaces between terms (even there exist multiple single spaces) using this parser. I tried adding the qi::space parser to the character rule like this _character = alnum | char_("\"'| !#$%&()*+,./:;>=
r360
  • 49
  • 4