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
0 answers

boost::qi evaluate result by last sequential item

I have rather complicated expression parser with strict type checking. So my expression rule declared to return effective type-index. Like that: qi::rule < Iterator, type_index_t, skipper> set_expression, expression,…
Dewfy
  • 23,277
  • 13
  • 73
  • 121
0
votes
1 answer

Is there any way to compose separately compiled boost::spirit::qi grammars?

Boost Spirit Qi parser grammars are wonderful, and I use them for small things all the time. However, there are times when I would like to be able to compose separate grammars. This is easy to do all-in-one in a single compile by #including the…
wjl
  • 7,519
  • 2
  • 32
  • 41
0
votes
0 answers

C++ Boost::Spirit parsing complex boolean expressions and constructing an equivalent tree

Our input expressions are similar to this (even more complex): ( ( ?var1 <= (?var2 + 125) && ?var1 > (?var2 + 10) ) || !(?var1 == ?var3) ) Note: variables are always started by either '?' or '_' Our desired output: || …
user12790203
0
votes
1 answer

Is it possible to use Boost.Spirit V2.x without Boost.Fusion?

Is it really necessary to wrap structs/classes with Boost.Fusion in order to use them with Boost.Spirit V2.x (especially Boost.Spirit.Qi)? I would much rather use semantic actions to assign to members. If my memory serves me well, this is the way it…
kloffy
  • 2,928
  • 2
  • 25
  • 34
0
votes
1 answer

How to combine Boost.Spirit customization points with Nabialek?

First things first: I'm using the default C++ language standard for MS Visual Studio 2017 (v15.19.11), C++14, along with Boost v1.65.1 I have an input file formatted like this: IterName SomeName IterDesc Some Description COLUMNS…
textral
  • 1,029
  • 8
  • 13
0
votes
0 answers

Boost Spirit sequential key value parser

Is there a better way of doing this with Spirit? I'm parsing a sequential series of key value pairs, with some line endings and other cruft in between. The format is not so consistent that I can just pull key values pairs out with a single rule. So…
flatline
  • 42,083
  • 4
  • 31
  • 38
0
votes
1 answer

How do I forward declare a boost::spirit rule?

Here's a very simple boost::spirit example demonstrating an issue I'm running into - when I compile it, I get 'parsers::parseTest': redefinition; multiple initialization - how do I forward declare a rule? Using 2.5.2 if it matters. #include…
Carbon
  • 3,828
  • 3
  • 24
  • 51
0
votes
1 answer

lambda not accepted in boost spirit's lazy arguments

eps accepts a lazy argument that evaluates bool. I've been using eps with pheonix objects like eps(_r1 == 0) >> something, and it has worked. However, when I use a lambda function for more complex expression that can't be expressed in a pheonix…
Inbae Jeong
  • 4,053
  • 25
  • 38
0
votes
1 answer

qi::rule doesn't parse input string

I have a strange trouble: qi::rule str = +alnum; // will not parse given input //param = "WELL" >> space >> str >> ((space >> no_case[control]) || (space >> no_case[limit])) >> space >> qi::eol; // will parse given input…
Sergey Miryanov
  • 1,820
  • 16
  • 29
0
votes
1 answer

boost spirit expectation failure

I want to parse a vector of the following struct: BOOST_FUSION_ADAPT_STRUCT( event_model::OTNDescriptor, (int32_t, qualifier) (int32_t, ordinal) (std::string, name) (int32_t, type) ) My grammer looks as follows: struct…
0
votes
1 answer

Boost.Spirit: porting string pairs from Qi to X3

I have the following working Qi code: struct query_grammar : public boost::spirit::qi::grammar()> { query_grammar() : query_grammar::base_type(query) { query = pair >> *(boost::spirit::qi::lit('&') >>…
0
votes
1 answer

qi::parse boost change begin iterator

Do function below change iterator which first point to s.begin() and after point to s.begin() + 1? I'm right? #include #include #include using namespace boost::spirit; int main() { std::string…
21koizyd
  • 1,843
  • 12
  • 25
0
votes
0 answers

Getting Boost.Spirit to handle optional elements

I have an AST element defined roughly as struct Something { boost::optional foo; string bar; } in my parsing code, I parse it as -(identifier >> ':') >> type Now, here's the problem: if I feed the parser the string hello:world,…
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
0
votes
1 answer

Boost Spirit grammar custom attribute

Attempting to learn Boost::Spirit and want to tackle a simple example for c-style identifiers. The grammar below doesn't compile claiming 'incompatible_start_rule'. The goal is for this grammar to return a string instead of a vector of strings, as…
Alex Court
  • 148
  • 11
0
votes
1 answer

International double parsing

I have a text with numbers like "25,6 km/h". I tried to parse it with boost spirit qi. numeric_value_expression = qi::double_ >> "km" >> -(string("/")) >> "h"; But this works only for US-formatted numbers like "25.6 km/h" not with commas. Is there…