boost-spirit

Example parsing error

倾然丶 夕夏残阳落幕 提交于 2019-11-27 08:25:48
问题 I'm trying to parse an example of boost spirit (2.5.2) following the example. My code is the following #include <boost\spirit\home\qi.hpp> #include <iostream> #include <string> #include <utility> int main() { // Parsing two numbers std::string input("1.0 2.0"); std::pair<double, double> p; boost::spirit::qi::phrase_parse( input.begin(), input.end(), boost::spirit::qi::double_ >> boost::spirit::qi::double_ , // Parse grammar boost::spirit::qi::space, p ); return 0; } It's almost equal to the

pass attribute to child rule in boost spirit

前提是你 提交于 2019-11-27 08:25:16
问题 I have two rules with the same attribute. Is it possible to pass the attribute of the matrix_ rule to the matrixBlock_ child rule? I want to keep the repeat directive from creating an attribute of the form vector< >. Instead it should just keep writing into the attribute of matrix_ (numBlocks's times). I tried to pass the attribute as inherited attribute to the child rule and it compiles(see below). But I get several "ghost" entries in my vector which come not from the phoenix::push_back.

Boost spirit poor performance with Alternative parser

ぐ巨炮叔叔 提交于 2019-11-27 07:50:10
问题 I already asked question about this issue. But since there were no answers i'm asking again now with full compilable source code snippet. This code snippet should be compiled with no std=c++11 option, because of some issues with boost::variant move semantic. Just 'g++ -Wall -pedantic'. In this code snippet you will find "// Comment here" line. You can comment following block till "// And here -----". If this block is uncommented, performance of this program is very poor. So the bottleneck as

boost::spirit::qi permutation parser and synthesized attributes

不想你离开。 提交于 2019-11-27 07:21:05
问题 I'm trying to put together a simple command line parser with SPIRIT without semantic actions. I'm using BOOST 1.52 but I would like to avoid using C++11 features. The grammar has the following syntax: [-p num1] [-j] [--jobs num2] str1 str2 Optional parameters can be in any order. I successfully parsed only optional parameters. Once I add the additional mandatory two string parsers it breaks. It breaks even when I try to write down the "rstart" attributes explicitly and avoid type deduction

Syntax tree empty nodes issue with Spirit Qi MiniC example

天涯浪子 提交于 2019-11-27 07:11:35
问题 Dear Spirit Qi experts. I have played around with the MiniC example in Spirit Qi, and have noticed an issue with "empty" AST nodes in the expression grammar. It will generate "expression" nodes that hold nothing but a single operand of type "expression" again. I think the issue is due to the recursive rule definitions for the operator precedence: // expression.hpp qi::rule<Iterator, ast::expression(), skipper<Iterator> > expr, equality_expr, relational_expr, logical_or_expr, logical_and_expr,

Boost.Spirit.Qi: dynamically create “difference” parser at parse time

家住魔仙堡 提交于 2019-11-27 06:29:49
问题 A "difference" parser can be created by the binary - (minus) operator: rule = qi::char_ - qi::lit("}}") or even compound differences: rule = qi::char_ - qi::lit("}}") - qi::lit("]]") But how could I generate the whole result of the difference parser at the parse time? I'm guessing it might be some kind of form like below: phoenix::function<difference_parser_impl> difference_parser; rule = qi::lazy(difference_parser(qi::char_, {"}}", "]]"})); Here, the {..., ..., ...} part would actually be a

Boost spirit memory leak

微笑、不失礼 提交于 2019-11-27 06:29:04
问题 I am writing a small program to process a big text file and do some replacements. The thing is that it never stops allocating new memory, so in the end it runs out of memory. I have reduced it to a simple program that simply counts the number of lines (see the code below) while still allocating more and more memory. I must admit that I know little about boost and boost spirit in particular. Could you please tell me what I am doing wrong? Thanks a million! #include <string> #include <iostream>

linking errors while separate parser using boost spirit x3

廉价感情. 提交于 2019-11-27 06:25:33
问题 I am currentyl trying to separate my boost spirit x3 parser into different _def and .cpp files using BOOST_SPIRIT_DEFINE/DECLARE/INSTANTIATE , but I keep getting a linking error. HERE is my parser which is separated. The linker error reads <artificial>:(.text.startup+0xbb): undefined reference to `bool kyle::parser::impl::parse_rule<__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::spirit::x3::context<boost::spirit:

boost spirit V2 qi bug associated with optimization level

有些话、适合烂在心里 提交于 2019-11-27 05:30:12
I develop my code in my spare time. Preferably in debug mode. Recently, when I tried to build release version, then I got the error (runtime, output: 1\n2\n then failure). I located the piece of code (below), which contains the error, and I found, that the error only occurs, when optimization level is -Os, -Ofast, -O2, -O3 but not -O, -O0, -O1, -Og . In release mode I am constrained in debug abilities. What is the cause of the error? What is the method to find such errors? #!/usr/bin/env bash -vex WARN="-W -Wall -Wextra" INCLUDE="-isystem /c/libs/boost-trunk" OPT="-O2" g++ -x c++ - -std=gnu+

Understanding Boost.spirit's string parser

假装没事ソ 提交于 2019-11-27 05:28:39
#include <iostream> #include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; int main () { using qi::string; std::string input("a"); std::string::iterator strbegin = input.begin(); std::string p; bool ok = qi::phrase_parse(strbegin, input.end(), ((string("a") >> string("a")) | string("a")), qi::space, p); if (ok && strbegin == input.end()) { std::cout << p << std::endl; std::cout << p.size() << std::endl; } else { std::cout << "fail" << std::endl; std::cout << std::string(strbegin, input.end()) << std::endl; } } This program outputs aa . How is it possible? Input string is a .