[ create a new paste ] login | about

Link: http://codepad.org/seeuSbmP    [ raw code | fork ]

C++, pasted on Mar 29:
// Test case based on solution discussed here:
// http://thread.gmane.org/gmane.comp.parsers.spirit.general/24684/focus=24688

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/vector.hpp>

namespace qi = boost::spirit::qi;

template <typename Iterator>
bool test_parse(Iterator& first, Iterator last)
{
    typedef boost::fusion::vector<int, int, int> parts;

    qi::rule<Iterator, parts(), qi::space_type> r1 =
        qi::int_
    >>  "."
    >>  qi::int_
    >>  (
            (
                    qi::lit(".")
                >>  qi::int_
                >>  qi::lit(".")
                >>  qi::int_
            )
        |   (
                    qi::attr(0)
                >>  qi::attr(0)
            )
        )
    ;

    return phrase_parse(first, last, r1, qi::space);
}

///////////////////////////////////////////////////////////////////////////////
int main()
{
    std::string str;
    while (getline(std::cin, str))
    {
        if (str.empty() || str[0] == 'q' || str[0] == 'Q')
            break;

        std::string::const_iterator iter = str.begin();
        std::string::const_iterator end = str.end();
        bool r = test_parse(iter, end);

        if (r && iter == end)
        {
            std::cout << "Parsing succeeded\n";
        }
        else
        {
            std::cout << "Parsing failed\n";
        }
    }

    std::cout << "Bye... :-) \n\n";
    return 0;
}


Create a new paste based on this one


Comments: