int parse_int_number_main()
{
	namespace qi = boost::spirit::qi;
	
	using qi::parse;
	using qi::phrase_parse;
	using qi::int_;
	using qi::double_;
	using qi::ascii::space;
	using qi::_1;
	using boost::phoenix::ref;
	using boost::phoenix::push_back;
	char * a = "(12e2,12223)";
	char * a_end = a+strlen(a) ;
	char * b = "(1233)";
	char * b_end = b+strlen(b);
	char * c = "1  , 2,3,4,5,6,7,8,10,13";
	char * c_end = b+strlen(b) ;
	int n = 0;

	std::vector<int> iv;

	phrase_parse(c,c_end, int_%',', space, iv);
	std::ostream_iterator <int> oi(std::cout, ",");
	boost::copy(iv,oi);
	std::cout<<"\n";
	return 0;
}
예제 #2
0
bool parse_dasharray(Iterator first, Iterator last, std::vector<double>& dasharray)
{
    using qi::double_;
    using qi::phrase_parse;
    using qi::_1;
    using qi::lit;
    using qi::char_;
#if BOOST_VERSION > 104200
    using qi::no_skip;
#else
    using qi::lexeme;
#endif
    using phoenix::push_back;
    // SVG
    // dasharray ::= (length | percentage) (comma-wsp dasharray)?
    // no support for 'percentage' as viewport is unknown at load_map
    //
    bool r = phrase_parse(first, last,
                          (double_[push_back(phoenix::ref(dasharray), _1)] %
#if BOOST_VERSION > 104200
                          no_skip[char_(", ")]
#else
                          lexeme[char_(", ")]
#endif
                          | lit("none")),
                          qi::ascii::space);
    if (first != last)
    {
        return false;
    }
    return r;
}
예제 #3
0
파일: main.cpp 프로젝트: CCJY/coliru
int main()
{
    namespace spirit = boost::spirit;
    namespace qi = spirit::qi;
    namespace phoenix = boost::phoenix;
    namespace ascii = spirit::ascii;

    using qi::rule;
    using qi::int_;
    using qi::_1;
    using qi::_val;
    using qi::phrase_parse;
    using boost::shared_ptr;
    using boost::make_shared;

    shared_ptr<int> x = make_shared<int>(123);

    std::cout << *x << std::endl;

    rule<
    std::string::const_iterator
    , shared_ptr<int>()
    , ascii::space_type
    > int_rule_ = int_[_val = new int(_1)];

    shared_ptr<int> subject_;

    std::string text_ = "12345";

    auto result_ = phrase_parse(text_.cbegin(), text_.cend(), int_rule_, ascii::space, subject_);

    std::cout << (result_ ? "passed" : "failed") << *subject_ << std::endl;
}
예제 #4
0
    bool parse_numbers( Iterator first, Iterator last, vector<double> &v )
    {
      using qi::double_;
      using qi::phrase_parse;
      using qi::_1;
      using ascii::space;
      using phoenix::push_back;

      bool r( phrase_parse( first, last,
              (
               double_[ push_back( phoenix::ref( v ), _1 ) ] % ','
              ),
                            space ) );
      return ( first == last ? r : false );
    }
예제 #5
0
파일: test.cpp 프로젝트: cchd0001/gld_work
    bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
    {
        using qi::double_;
        using qi::phrase_parse;
        using qi::_1;
        using ascii::space;

        bool r = phrase_parse(first, last,

            //  Begin grammar
            (
                double_ % ','
            )
            ,
            //  End grammar

            space, v);

        if (first != last) // fail if we did not get a full match
            return false;
        return r;
    }
예제 #6
0
파일: parse.cpp 프로젝트: JohnReid/STEME
optional< p_value_test_case >
parse_IC_line( Iterator first, Iterator last )
{
    using qi::double_;
    using qi::_1;
    using qi::uint_;
    using qi::phrase_parse;
    using ascii::space;
    using boost::phoenix::ref;

    optional< p_value_test_case > result;

    /// Will look like "N=2; IC=1.57184,1.57184,1.57184,1.22985,1.22985,1.57184,1.57184,1.22985"
    size_t N;
    if( phrase_parse( first, last, "N=" >> uint_ >> "; IC=", space, N ) ) {
    	result.reset( p_value_test_case( N ) );
        if( ! phrase_parse( first, last, double_ % ",", space, result->ICs ) ) {
        	result = optional< p_value_test_case >(); // reset
        }
    }

    return result;
}
예제 #7
0
    bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
    {
        using qi::double_;
        using qi::phrase_parse;
        using qi::_1;
        using ascii::space;
        using phoenix::push_back;
        using phoenix::ref;

        bool r = phrase_parse(first, last,

            //  Begin grammar
            (
                double_[push_back(ref(v), _1)] % ','
            )
            ,
            //  End grammar

            space);

        if (first != last) // fail if we did not get a full match
            return false;
        return r;
    }