Avalanche Error in Using Boost.Spirit.Qi

I can not understand what is wrong with my code. Boost templates make me go crazy! From all this, I can’t make heads or tails, so I just had to ask.

What happened to this?

#include <iostream>
#include <boost/lambda/lambda.hpp>
#include <boost/spirit/include/qi.hpp>

void parsePathTest(const std::string &path)
{
    namespace lambda = boost::lambda;
    using namespace boost::spirit;

    const std::string permitted = "._\\-#@a-zA-Z0-9";
    const std::string physicalPermitted = permitted + "/\\\\";
    const std::string archivedPermitted = permitted + ":{}";

    std::string physical,archived;

    // avoids non-const reference to rvalue
    std::string::const_iterator begin = path.begin(),end = path.end();

    // splits a string like "some/nice-path/while_checking:permitted#symbols.bin"
    // as physical = "some/nice-path/while_checking"
    // and archived = "permitted#symbols.bin" (if this portion exists)
    // I could barely find out the type for this expression
    auto expr
        =   ( +char_(physicalPermitted) ) [lambda::var(physical) = lambda::_1]
            >> -(
                    ':'
                    >> (
                           +char_(archivedPermitted) [lambda::var(archived) = lambda::_1]
                       )
                )
        ;

    // the error occurs in a template instantiated from here
    qi::parse(begin,end,expr);

    std::cout << physical << '\n' << archived << '\n';
}

The number of errors is huge; I would suggest people who want to help compose this on their own (believe me, the insert here is impractical). I am using the latest version of TDM-GCC (GCC 4.4.1) and Boost version 1.39.00.

As a bonus, I would like to ask two more things: whether C ++ 0x new will static_assertwork in Boost in this sense, and whether the implementation I quoted above is a good idea, or if I should use the Boost String Algorithms library. Can the latter give much better performance?

Thank.

- edit

, .

#include <iostream>
#include <boost/spirit/include/qi.hpp>

int main()
{
    using namespace boost::spirit;

    std::string str = "sample";
    std::string::const_iterator begin(str.begin()), end(str.end());

    auto expr
        =   ( +char_("a-zA-Z") )
        ;

    // the error occurs in a template instantiated from here
    if (qi::parse(begin,end,expr))
    {
        std::cout << "[+] Parsed!\n";
    }
    else
    {
        std::cout << "[-] Parsing failed.\n";
    }

    return 0;
}

- 2

, Boost (1.39), Boost 1.42 . Boost 1.42:

#include <iostream>
#include <boost/spirit/include/qi.hpp>

int main()
{
    using namespace boost::spirit;

    std::string str = "sample";
    std::string::const_iterator begin(str.begin()), end(str.end());

    auto expr
        =   ( +qi::char_("a-zA-Z") ) // notice this line; char_ is not part of 
                                     // boost::spirit anymore (or maybe I didn't 
                                     // include the right headers, but, regardless, 
                                     // khaiser said I should use qi::char_, so here 
                                     // it goes)
        ;

    // the error occurs in a template instantiated from here
    if (qi::parse(begin,end,expr))
    {
        std::cout << "[+] Parsed!\n";
    }
    else
    {
        std::cout << "[-] Parsing failed.\n";
    }

    return 0;
}

, hkaiser.

+3
1

: ) - Spirit V2, Boost V1.39 V1.40. , , Spirit V2.1 ( Boost V1.41), ( , ). Boost, , . ) boost:: lambda boost:: bind Spirit V2.x. , , , , , . boost:: phoenix. "" , . Phoenix, :

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>

namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;

std::string physical, archived;  
auto expr 
    =   ( +char_(physicalPermitted) ) [phoenix::ref(physical) = qi::_1] 
    >> -( 
            ':' 
            >> ( +char_(archivedPermitted) )[phoenix::ref(archived) = qi::_1] 
        ) 
    ; 

, Spirit:

std::string physical;
boost::optional<std::string> archived;  

qi::parse(begin, end, 
    +qi::char_(physicalPermitted) >> -(':' >> +qi::char_(archivedPermitted)),
    physical, archived);

. . , . - Magic of Attributes on Spirit.

:

static_assert: yes static_assert, , . , . , , . (, , ++), , , .

Boost String Algorithms: , , . , Boost.Tokenizer( ":" ). Spirit , , , , . , , Spirit ( ).

Boost String, Boost Tokenizer . Spirit , . , /, Spirit, Boost Regex.

+7

Source: https://habr.com/ru/post/1731791/


All Articles