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

How to insert a character at the beginning of a string attribute in spirit qi

I have the following rule: rule t_ffind, t_sim, t_hash, t_state; t_ffind = hold[(attr('$') >> t_sim >> t_hash >> t_state)] | t_sim; which means that I could find t_sim alone or followed by t_hash and…
nihil
  • 85
  • 1
  • 8
1
vote
1 answer

Boost Spirit Qi: Compile error on slight rule change

I'm writing a little compiler just for fun and I'm using Boost Spirit Qi to describe my grammar. Now I want to make a minor change in the grammar to prepare some further additions. Unfortunately these changes won't compile and I would like to…
1
vote
1 answer

Spirit Grammar For Path Verificiation

I am trying to write a simple grammar using boost spirit to validate that a string is a valid directory. I am using these tutorials since this is the first grammar I have…
joshu
  • 463
  • 8
  • 18
1
vote
2 answers

Boost Spirit auto-rule problem

I'm using attribute propagation to construct a syntax tree for a toy language. I've hit a problem at the definition of my if statement, it's hard to tell from the error message but I think the rhs attribute isn't collapsing into the expected…
1
vote
1 answer

Boost Spirit - Trimming spaces between last character and separator

Boost Spirit newcomer here. I have a string in the form of "Key:Value\r\nKey2:Value2\r\n" that I'm trying to parse. In that specific form, it's trivial to parse with Boost Spirit. However, in order to be more robust, I also need to handle cases such…
XanderLo
  • 35
  • 4
1
vote
1 answer

Why doesn't my boost::spirit rule compile for parsing a list of lists?

I'm trying to write a parser for Open Inventor .iv files using boost::spirit. I have the following struct for VertexProperty nodes: struct VertexProperty { std::vector > vertices; std::vector > normals; …
stix
  • 1,140
  • 13
  • 36
1
vote
1 answer

Boost.Spirit - How to use repeat to parse into a struct?

I'm trying to make a little program to parse the cpu usage info from /proc/stat using Boost.Spirit. It is mostly working, but I can't get my grammar to compile when using repeat. What am I missing? The whole code: #include #include…
Aaron Wright
  • 328
  • 2
  • 11
1
vote
1 answer

Mandatory boost::spirit::qi::attr(0) in rule is beeing skipped

I am struggeling with the implementation of a rule where all elements are part of a list of sorts. The types of elements can not be mixed. This is valid: 1/1/ 2/2/ 3/3/ and should be parsed with a mandatory zero like 1/1/0 2/2/0 3/3/0 The example…
Johannes
  • 6,490
  • 10
  • 59
  • 108
1
vote
3 answers

parsing 3 floats for glm::vec3 using boost::spirit::qi (error_invalid_expression)

I can parse one float and print it. (test1, test2) Somehow I am unable to build a rule that parses three floats. My final goal is to parse three floats and save them to a glm::vec3. My rule seems to be incorrect: qi::lexeme[qi::float_ << ' ' <<…
Johannes
  • 6,490
  • 10
  • 59
  • 108
1
vote
2 answers

How can I convert from qi::double_ to string?

I am using spiri::qi to parse a text and pushing what I parse into a vector, for the most part its fine since they are mostly names and addresses, but there are also some numbers that I am parsing with double_, but once I push it to the…
nihil
  • 85
  • 1
  • 8
1
vote
1 answer

boost spirit qi parser failed in release and pass in debug

#include #include #include #include #include #include using namespace boost::spirit; int main() { std::string s; std::getline(std::cin, s); auto specialtxt =…
ganesh
  • 171
  • 1
  • 2
  • 13
1
vote
1 answer

Boost Spirit Visual C++ compiler error, fine with GCC

I am having a problem getting the following live demo code to compile under visual C++ (2015). The code works fine in GCC as demonstrated here. Could someone please help me resolve this issue. I'm quite new to boost spirit qi parsing and with all…
johnco3
  • 2,401
  • 4
  • 35
  • 67
1
vote
1 answer

Rolling back changes in alternative parsers in qi spirit

I'm having some trouble using the alternative parser, I need the parser to rollback changes if the first option failed. I tried using hold[] but I get the error that it "could not deduce template argument" I'm trying to parse an AST, and I'm storing…
kaladin
  • 55
  • 4
1
vote
1 answer

boost::spirit arithmetic formulas parser fails to compile

I am trying to write a spirit parser for arithmetic expression which fills an abstract syntax tree. The parser compiles if I am not trying to fill the AST, but fails (with one 24K error) in the current version. I am using clang++ 3.5.0 with…
David Lehavi
  • 1,186
  • 7
  • 16
1
vote
1 answer

segmentation fault with trivial spirit parser

I've been using spirit::qi quite often for the past several months. However, this time I got a segfault that I really can't make any sense out of. I have reduced it to an extremely minimal test case, the grammar definition is 12 lines of code. This…
Chris Beck
  • 15,614
  • 4
  • 51
  • 87