Example #1
0
    inline bool
    tokenize_and_parse(Iterator& first, Iterator last, Lexer const& lex
      , ParserExpr const& xpr, Attribute& attr)
    {
        // Report invalid expression error as early as possible.
        // If you got an error_invalid_expression error message here,
        // then the expression (expr) is not a valid spirit qi expression.
        BOOST_SPIRIT_ASSERT_MATCH(qi::domain, ParserExpr);

        typename Lexer::iterator_type iter = lex.begin(first, last);
        return compile<qi::domain>(xpr).parse(
            iter, lex.end(), unused, unused, attr);
    }
Example #2
0
File: main.cpp Project: CCJY/coliru
int main() {
    std::cout << "Boost version: " << BOOST_LIB_VERSION << std::endl;
    std::string input = "33";

    char const* inputIt = input.c_str();
    char const* inputEnd = &input[input.size()];

    Lexer<LexerType> tokens;
    LexerType::iterator_type token = tokens.begin(inputIt, inputEnd);
    LexerType::iterator_type end = tokens.end();

    for (; token->is_valid() && token != end; ++token)
    {
        auto range = boost::get<IteratorRange>(token->value());
        std::cout << ToString(static_cast<TokenType>(token->id())) << " (" << std::string(range.begin(), range.end()) << ')' << std::endl;
    }
}
    bool test_parser(Char const* in, Parser const& p, Lexer& lex,
          Skipper const& s, bool full_match = true)
    {
        // we don't care about the result of the "what" function.
        // we only care that all parsers have it:
        boost::spirit::qi::what(p);

        std::string str (in);
        std::string::iterator it_in = str.begin();
        std::string::iterator end_in = str.end();

        typedef typename Lexer::iterator_type iterator_type;

        iterator_type iter = lex.begin(it_in, end_in);
        iterator_type end = lex.end();

        return boost::spirit::qi::phrase_parse(iter, end, p, s)
            && (!full_match || (iter == end));
    }