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

when I should choose boost spirit attr_cast over semantic action

That's it the title say it all. In the context of boost spirit qi, I do not understand when attr_cast will be preferable over semantic action that converts the value, say: [_val = convert(_1)]
gsf
  • 6,612
  • 7
  • 35
  • 64
1
vote
1 answer

the logical not operator not working in boost::spirit::qi

if in a qi::grammar I use this base rule expression = (boost::spirit::ascii::string("aaa")); it will parse "aaa" and nothing else when I use this one ( notice the ! ) it parses nothing at all while I expect it to be successful on everything but…
user2346536
1
vote
1 answer

Boost Spirit grammar eol

I am trying to parse files of the following form: // comment bla bla [sectionname] key = value key2=value2 // comment key = value [anothersection] ... using the following code. Unfortunately, it reports the last eol as an error although all eols…
Baradé
  • 1,290
  • 1
  • 15
  • 35
1
vote
2 answers

Parsing imperial values using boost spirit (qi)

I'm a spirit beginner I'd like to parse an imperial string value into a struct using spirit. The input should accept following syntaxes: 5'3"1/2 5'1/2 3"1/2 the struct imp_constant looks like this, please note stream operator below,…
loic
  • 185
  • 1
  • 7
1
vote
0 answers

Is there a way to specify a prefix for a symbol table lookup with boost qi symbols

I have a curious case I'm working with right now, where the I need to use the same symbol table in two different contexts. In the case of a "J" command, I'd like to only look at elements of the symbol table that begin with a particular prefix, but…
jkerian
  • 16,497
  • 3
  • 46
  • 59
1
vote
1 answer

Compatiblity of the rule attributes

I'm trying to write a parser, that reads in a text file with Variable-Declaration and -Instantiations and that constructs a Variable-Table, which contains all declared variables with their associated values. The file looks like the following: int a…
user1861174
  • 507
  • 1
  • 5
  • 14
1
vote
0 answers

Result of parsing a boost::spirit grammar with sub-expressions

I'm trying to get into boost spirit 2, but the following code does not work as expected: template struct my_grammar : qi::grammar { my_grammar() : my_grammar::base_type(time_literal) { …
1
vote
2 answers

Filter the synthesized attribute through a std::map in a boost spirit semantic action

I have a case where I'd like to filter the value that comes up as a synthesized attribute inside of a rule through a std::map. The map is pre-generated and will not change during the parsing. The nature of the map and the real parser means that the…
jkerian
  • 16,497
  • 3
  • 46
  • 59
1
vote
1 answer

Boost::spirit with fabric methods in a rule

I am using boost::spirit for constructing a parser for a simple script language. In a rule, I want to use a call to a fabric method to create a new object which is the return value of this rule. The rule is qi::rule
CppChris
  • 1,226
  • 9
  • 14
1
vote
2 answers

access violation when parsing spirit rule with `alias()`

I try to parse the string "1-2" using a grammar that is constructed with the following rules: spirit::qi::rule op1 = "-"; spirit::qi::rule op2 =…
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
1
vote
1 answer

compile error when trying to parse to utree

I'm trying to parse a string to a utree using the following code: void Parse(const std::string& testString, const MyGrammar& parser) { char const* first = testString.c_str(); char const* last = &first[testString.size()]; …
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
1
vote
1 answer

How to ignore a token attribute from spirit::Lex when using spirit::qi?

When I use this qi grammar accepting tokens from Lex: pair %= token(ID_MARKER) >> ':' >> atom >> ',' >> atom ; in conjunction with this fusion/tuple mapping to assist in the capture: BOOST_FUSION_ADAPT_STRUCT( …
kfmfe04
  • 14,936
  • 14
  • 74
  • 140
1
vote
1 answer

why does this boost::spirit::qi rule not work?

I have a grammar that defines the following rules: constantValue = qi::token(ID_FLOAT) | qi::token(ID_INTEGER); postfixExpression = primaryExpression | (postfixExpression >> qi::token(ID_OPENBRACKET) >> qi::token(ID_INTEGER) >>…
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
1
vote
0 answers

access tuple as back element of vector by boost :: phoenix used in boost :: qi grammar

How do I access tuple as back element of vector by boost::phoenix used in grammar. I want to set 2nd element of tuple of the back element of vector (which was added earlier) for example typedef boost::tuple
1
vote
1 answer

boost::spirit::qi why doesn't recursive parser work as expected?

I'd like the grammar below to parse input such as a_end a_b_end a_b_c_end but it only parses a_end and fails on anything with more than one _. Here is the grammar: template < typename Iterator > struct recursive_parser : qi::grammar< Iterator > { …
Epimetheus
  • 1,119
  • 1
  • 10
  • 19