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

cannot construct std::string from placeholder in Boost.Spirit

I have started working on a Boost.Spirit based simple parser that will parse a C++-like file (the only C++-ish part is the built-in template types; e.g. map> name_object_map; - but this is built-in the compiler, and user…
user1150609
  • 347
  • 2
  • 10
0
votes
1 answer

Creating a reusable grammar with Spirit QI

I am newbie in C++, althouth I need to parser a SQL-like expression: country='USA' AND state='CA' AND price >= 100.0, it is just a fake example, but it's feasible. So, I tried to solve using spirit QI. Each column has a specific type: float,…
Tiago Kepe
  • 13
  • 4
0
votes
2 answers

boost::spirit qi parsing runtime error

why do I have runtime error, while parsing string whith that grammar? template struct grammar : qi::grammar { grammar() : grammar::base_type(object) { identifier =…
DmitryU
  • 31
  • 4
0
votes
1 answer

Type Name is Not Allowed

I am writing a parser, and I am trying to insert an iterator as a template. When I write template the code compiles as expected. I think I should be able to remove the default, so I want to write…
Johannes
  • 6,490
  • 10
  • 59
  • 108
0
votes
1 answer

parsing C-style relational operators with Spirit Qi

I have the following rule in my parser for parsing inequalities, which works fine: rel = sum [ _val = _1 ] >> *( ('<' >> sum [_val = _val < _1]) | ('>' >> sum [_val = _val > _1] ) ); Now I'd like to add the <= and >= operators. So I try…
Taylor
  • 5,871
  • 2
  • 30
  • 64
0
votes
2 answers

Boost::Spirit::Qi - Splitting rules into separate classes

I would like to split up my rules (productions) into separate classes. I can't find any example in Boost::Spirit::Qi for doing this. The Boost examples all show the rules in one grammar class. Here is my grammar: ::= @ (…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
0
votes
1 answer

boost spirit repetition parser behaves unexpectedly

using boost 1.57 spirit::qi under windows 7 I'm working on an ipv6 parser and must be misunderstanding how repetition parser directives work. Given the following (simplified) ipv6part = repeat(1, 4)[xdigit]; ipv6address = -(repeat(1,4)[ipv6part >>…
darnell_a
  • 61
  • 8
0
votes
2 answers

Boost Binary Endian parser not working?

I am studying how to use boost spirit Qi binary endian parser. I write a small test parser program according to here and basics examples, but it doesn't work proper. It gave me the msg:"Error:no match". Here is my code. #include…
T.T
  • 25
  • 7
0
votes
1 answer

C++ boost::spirit lexer regex

I'm doing a simple lexer/parser with boost::spirit. This is the lexer : template struct word_count_tokens : lex::lexer { word_count_tokens() { …
user1746732
0
votes
0 answers

Preserving (but skipping) Whitespace in Boost Spirit

I'm working with Boost Spirit. I've build a custom Lexer (tested and working) using Lex, and am preparing a Parser using Qi. My grammar is quite large: my lexer has approximately 120 patterns and my parser will have approximately 200…
Liam M
  • 5,306
  • 4
  • 39
  • 55
0
votes
1 answer

Same string is parsed differently

I have datetime parser and datetime array parser. datetime_ = qi::eps[at_c<0>(qi::_val) = type::datetime] >> dt_string[at_c<1>(qi::_val) = qi::_1]; dt_string = (/*qi::lit("d") >>*/ qi::int_ >> "-" >> qi::int_ >> "-" >> qi::int_…
Alexander
  • 779
  • 8
  • 17
0
votes
0 answers

spirit: uint parser: parse a number between 1..31

I use uint_parser to parse at most 2 consecutive digits. However I would like parsing to fail if the parsed integer is outside of the range [1,31]? For now, I take care of that in the semantic action. Are there recommendations re detecting errors at…
MMM
  • 910
  • 1
  • 9
  • 25
0
votes
1 answer

Get Number of Iterations?

I was wondering if there is a way to count the number of iterations that happens for a specific grammar. Effectively counting how many parameters there would be for a function. This is using the boost spirit library for parsing my own syntax, i am…
user3901459
  • 824
  • 3
  • 11
  • 18
0
votes
0 answers

Boost Spirit Qi, placeholders into function

I have a difficult time wrapping my head around the following: int main( int, char *[] ) { const string test( "1 2" ); typedef string::const_iterator iterator; auto desired = []( int a, int b ) { }; auto working = [](…
Arjan
  • 484
  • 3
  • 11
0
votes
1 answer

Implementing division operator

I'm writing a simple calculator using boost spirit. I want the division operator to throw an exception if a zero denominator is encountered. I'm thinking along the lines of term = factor [qi::_val = qi::_1] >> *(('*'…
P45 Imminent
  • 8,319
  • 4
  • 35
  • 78
1 2 3
45
46