| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | =============================================================================*/ |
| 7 | #include <boost/spirit/include/qi_skip.hpp> |
| 8 | |
| 9 | #include <boost/spirit/include/qi_char.hpp> |
| 10 | #include <boost/spirit/include/qi_lexeme.hpp> |
| 11 | #include <boost/spirit/include/qi_operator.hpp> |
| 12 | #include <boost/phoenix/core.hpp> |
| 13 | |
| 14 | #include <iostream> |
| 15 | #include "test.hpp" |
| 16 | |
| 17 | int |
| 18 | main() |
| 19 | { |
| 20 | using spirit_test::test; |
| 21 | using spirit_test::test_attr; |
| 22 | using boost::spirit::qi::skip; |
| 23 | using boost::spirit::qi::lexeme; |
| 24 | using boost::spirit::qi::lit; |
| 25 | using boost::spirit::ascii::char_; |
| 26 | using boost::spirit::ascii::space; |
| 27 | using boost::spirit::ascii::alpha; |
| 28 | |
| 29 | { |
| 30 | BOOST_TEST((test("a b c d" , skip(space)[*char_]))); |
| 31 | } |
| 32 | |
| 33 | { // test attribute |
| 34 | std::string s; |
| 35 | BOOST_TEST((test_attr("a b c d" , skip(space)[*char_], s))); |
| 36 | BOOST_TEST(s == "abcd" ); |
| 37 | } |
| 38 | |
| 39 | { // reskip |
| 40 | BOOST_TEST((test("ab c d" , lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space))); |
| 41 | BOOST_TEST((test("abcd" , lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space))); |
| 42 | BOOST_TEST(!(test("a bcd" , lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space))); |
| 43 | |
| 44 | BOOST_TEST((test("ab c d" , lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space))); |
| 45 | BOOST_TEST((test("abcd" , lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space))); |
| 46 | BOOST_TEST(!(test("a bcd" , lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space))); |
| 47 | } |
| 48 | |
| 49 | { // lazy skip |
| 50 | using boost::phoenix::val; |
| 51 | |
| 52 | BOOST_TEST((test("a b c d" , skip(val(space))[*char_]))); |
| 53 | } |
| 54 | |
| 55 | return boost::report_errors(); |
| 56 | } |
| 57 | |