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

Simple Line, escaped elements with different type

i want to parse the following line with boost::spirit 0 "a" "b" "c" I've created my rules like this: qi::rule escaped_ = qi::char_('"') >> *(qi::char_ - qi::char_('"')) >> qi::char_('"'); int…
Roby
  • 2,011
  • 4
  • 28
  • 55
1
vote
0 answers

Parser rule is not filling values in Vector properly

Here is my code std::ifstream ifs("f:/test.txt"); std::string line; //In header in my code static std::vector v_BF_Char; static std::vector v_Begin_BF_Range; static std::multimap
user3528635
1
vote
1 answer

parsing into std::vector with Spirit Qi, getting segfaults or assert failures

I am using Spirit Qi as my parser, to parse mathematical expressions into an expression tree. I keep track of such things as the types of the symbols which are encountered as I parse, and which must be declared in the text I am parsing. Namely, I…
ofloveandhate
  • 199
  • 1
  • 10
1
vote
1 answer

boost::spirit::qi difference parser behavior

I'm trying to understand the behavior of Qi's Difference Parsers. With something like this: ruleA = ruleAa | ruleAb | ruleAc ; ruleB = ruleA - ruleAc ; I was imagining that the parser would match ruleB iff the input matches ruleAa or ruleAb. In…
pt3dNyc
  • 369
  • 1
  • 16
1
vote
1 answer

Support implied AND operation in boost spirit boolean expression parser

I have a parser, which parses boolean expressions. How I should modify it to support "implied-And" e.g "A1 A2" which must be parsed as A1 and A2? I've tried to change the "and_" rule to support it, but it started to treat "xor" as a variable even if…
1
vote
2 answers

Specify a charset without intepreting ranges

I'm quite puzzled with parsing strings when I have to define in rule the minus and it is just a minus character and not a range of characters between two endpoints. For example, when you write a rule to percent encode a string of characters you…
kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
1
vote
1 answer

Splitting string using boost spirit

Is it a good idea? For a reason I thought it should be faster than boost's tokenizer or split. however most of the time I'm stuck in the boost::spirit::compile template struct ValueList : bsq::grammar
kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
1
vote
1 answer

Getting compilation errors while binding a rule production to my struct members

Writing Qi grammar with Phoenix bind I got a compilation error like boost/spirit/home/support/context.hpp(180): error C2338: index_is_out_of_bounds here >> ruleHandId_[phx::bind(&parseContext::handId_, qi::_r1) = qi::_1]; I just havent too much…
1
vote
0 answers

How to convert boost::wave::cpplexer::lex_token to a number inside boost spirit semantic rule?

I have a Spirit's qi::primitive_parser descendant that returns a lex_token<>: struct TokenParser : boost::spirit::qi::primitive_parser { TokenParser(boost::wave::token_id _id) : id(_id) {} template
facetus
  • 1,091
  • 6
  • 20
1
vote
1 answer

how to use list syntax with defaults spirit

I am attempting to parse comma separated integers, with possible blanks. For instance, 1,2,,3,,-1 should be parsed as {1,2,n,3,n,-1} where is n is some constant. The expression, (int_ | eps) % ',' works when n == 0. More specifically, the…
Nick
  • 931
  • 6
  • 17
1
vote
1 answer

boost qi::phrase_parse reads only first element

I've implemented simple ascii parser using boost::spirit. target ascii file looks like n 0 23 45 10.0 0.5 ..... n-1 x y ..... but it returns in measure_list only 1 element if I am trying to read ASCII as a simple vector instead of…
Mike
  • 43
  • 1
  • 5
1
vote
1 answer

Destructor gets called when using phoenix construct

I'm working on a Boost Spirit Qi project that uses phoenix::construct to create an object that has a pointer to another object. I noticed that using phoenix::construct calls the destructor at some point (I'm guessing at the end of the function). Why…
amura.cxg
  • 2,348
  • 3
  • 21
  • 44
1
vote
1 answer

Boost Spirit Expression parser with custom expression class

I'm working on a test project that will ideally be built into a larger project (wanting to build my own scripting language for fun) in the future that parses expressions into a tree structure using my custom classes. My expected result is an…
amura.cxg
  • 2,348
  • 3
  • 21
  • 44
1
vote
1 answer

Why can't I seem to use qi locals as the semantic predicate to eps?

When using qi::locals, a local parameter doesn't seem like it can be used as the semantic predicate to eps. Here is a stripped down fictional example: #include #include namespace qi…
md5i
  • 3,018
  • 1
  • 18
  • 32
1
vote
1 answer

Followup: Using boost::spirit::qi to parse numbers with separators

This is a followup question to Using boost::spirit::qi to parse numbers with separators. Following sehe's very good suggestions, I managed to get number parsing to work. I then attempted to update it to have a secondary parser which handled…
md5i
  • 3,018
  • 1
  • 18
  • 32