$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: hartmut.kaiser_at_[hidden]
Date: 2008-04-20 22:01:32
Author: hkaiser
Date: 2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
New Revision: 44669
URL: http://svn.boost.org/trac/boost/changeset/44669
Log:
Spirit.Qi: Added ~ for eoi and eol, added corresponding tests
Added:
   trunk/boost/spirit/home/qi/auxiliary/primitives.hpp   (contents, props changed)
   trunk/libs/spirit/test/qi/end.cpp   (contents, props changed)
Removed:
   trunk/boost/spirit/home/qi/char/primitives.hpp
Text files modified: 
   trunk/boost/spirit/home/qi/auxiliary.hpp              |     1                                         
   trunk/boost/spirit/home/qi/auxiliary/meta_grammar.hpp |    41 +++++++++++++++++++++++++++++++++++++++ 
   trunk/boost/spirit/home/qi/char.hpp                   |     1                                         
   trunk/boost/spirit/home/qi/char/meta_grammar.hpp      |     7 -----                                   
   trunk/libs/spirit/test/qi/char.cpp                    |    32 -------------------------------         
   5 files changed, 42 insertions(+), 40 deletions(-)
Modified: trunk/boost/spirit/home/qi/auxiliary.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/auxiliary.hpp	(original)
+++ trunk/boost/spirit/home/qi/auxiliary.hpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -13,6 +13,7 @@
 #include <boost/spirit/home/qi/auxiliary/lazy.hpp>
 #include <boost/spirit/home/qi/auxiliary/functor.hpp>
 #include <boost/spirit/home/qi/auxiliary/functor_director.hpp>
+#include <boost/spirit/home/qi/auxiliary/primitives.hpp>
 #include <boost/spirit/home/qi/auxiliary/meta_grammar.hpp>
 
 #endif
Modified: trunk/boost/spirit/home/qi/auxiliary/meta_grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/auxiliary/meta_grammar.hpp	(original)
+++ trunk/boost/spirit/home/qi/auxiliary/meta_grammar.hpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -30,6 +30,13 @@
     struct lazy_parser;
     struct functor_director;
 
+    struct eol_director;
+    struct eoi_director;
+
+    template <typename Positive>
+    struct negated_end_director;
+
+    ///////////////////////////////////////////////////////////////////////////
     template <typename Expr, typename Enable>
     struct is_valid_expr;
 
@@ -41,7 +48,7 @@
     ///////////////////////////////////////////////////////////////////////////
 
     // none, eps and eps(f)
-    struct auxiliary_meta_grammar
+    struct auxiliary_meta_grammar1
       : proto::or_<
             meta_grammar::empty_terminal_rule<
                 qi::domain, tag::none, none>
@@ -60,6 +67,38 @@
     {
     };
 
+    // eol, eoi
+    struct auxiliary_end_meta_grammar
+      : proto::or_<
+            meta_grammar::terminal_rule<qi::domain, tag::eol, eol_director>
+          , meta_grammar::terminal_rule<qi::domain, tag::eoi, eoi_director>
+        >
+    {
+    };
+
+    struct negated_auxiliary_end_meta_grammar
+      : proto::or_<
+            auxiliary_end_meta_grammar
+          , meta_grammar::compose_single<
+                proto::unary_expr<
+                    proto::tag::complement
+                  , negated_auxiliary_end_meta_grammar
+                >
+              , qi::domain
+              , negated_end_director<mpl::_>
+            >
+        >
+    {
+    };
+
+    struct auxiliary_meta_grammar
+      : proto::or_<
+            auxiliary_meta_grammar1
+          , negated_auxiliary_end_meta_grammar
+        >
+    {
+    };
+
     ///////////////////////////////////////////////////////////////////////////
     //  These specializations non-intrusively hooks into the RD meta-grammar.
     //  (see qi/meta_grammar.hpp)
Added: trunk/boost/spirit/home/qi/auxiliary/primitives.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/qi/auxiliary/primitives.hpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -0,0 +1,165 @@
+/*=============================================================================
+    Copyright (c) 2001-2008 Hartmut Kaiser
+
+    Distributed under the Boost Software License, Version 1.0. (See accompanying
+    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#if !defined(BOOST_SPIRIT_PRIMITIVES_APR_18_2008_0751PM)
+#define BOOST_SPIRIT_PRIMITIVES_APR_18_2008_0751PM
+
+#include <boost/mpl/bool.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace spirit { namespace qi
+{
+    ///////////////////////////////////////////////////////////////////////////
+    //  the end_director_base is a base class for various end parsers
+    ///////////////////////////////////////////////////////////////////////////
+    template <typename Parser, typename StoreIterator = mpl::false_>
+    struct end_director_base
+    {
+        typedef mpl::false_ stores_iterator;
+        
+        template <typename Component, typename Context, typename Iterator>
+        struct attribute
+        {
+            typedef unused_type type;
+        };
+
+        template <
+            typename Component
+          , typename Iterator, typename Context
+          , typename Skipper, typename Attribute>
+        static bool parse(
+            Component const& component
+          , Iterator& first, Iterator const& last
+          , Context& context, Skipper const& skipper
+          , Attribute& attr)
+        {
+            qi::skip(first, last, skipper);
+            return Parser::test(first, last);
+        }
+
+        // subclasses are required to implement test:
+
+        template <typename Iterator>
+        bool test(Iterator& first, Iterator const& last);
+    };
+    
+    ///////////////////////////////////////////////////////////////////////////
+    //  same as end_director_base above, but stores iterator
+    ///////////////////////////////////////////////////////////////////////////
+    template <typename Parser>
+    struct end_director_base<Parser, mpl::true_>
+    {
+        typedef mpl::true_ stores_iterator;
+
+        template <typename Component, typename Context, typename Iterator>
+        struct attribute
+        {
+            typedef unused_type type;
+        };
+
+        template <
+            typename Component
+          , typename Iterator, typename Context
+          , typename Skipper, typename Attribute>
+        static bool parse(
+            Component const& component
+          , Iterator& first, Iterator const& last
+          , Context& context, Skipper const& skipper
+          , Attribute& attr)
+        {
+            qi::skip(first, last, skipper);
+
+            Iterator it = first;
+            if (!Parser::test(it, last))
+                return false;
+
+            first = it;
+            return true;
+        }
+
+        // subclasses are required to implement test:
+
+        template <typename Iterator>
+        bool test(Iterator& first, Iterator const& last);
+    };
+    
+    ///////////////////////////////////////////////////////////////////////////
+    //  ~eoi, ~eol: 'not end of line' or 'not end of input'
+    template <typename Positive>
+    struct negated_end_director 
+      : end_director_base<
+            negated_end_director<Positive>, 
+            typename Positive::director::stores_iterator
+        >
+    {
+        template <typename Iterator>
+        static bool test (Iterator& first, Iterator const& last)
+        {
+            return !Positive::director::test(first, last);
+        }
+
+        template <typename Component>
+        static std::string what(Component const&component)
+        {
+            return "not " + 
+                Positive::director::what(fusion::at_c<0>(component.elements));
+        }
+    };
+
+    ///////////////////////////////////////////////////////////////////////////
+    //  eoi: end of input
+    struct eoi_director : end_director_base<eoi_director>
+    {
+        template <typename Iterator>
+        static bool test (Iterator& first, Iterator const& last)
+        {
+            return first == last;
+        }
+        
+        template <typename Component>
+        static std::string what(Component const&)
+        {
+            return "eoi";
+        }
+    };
+    
+    
+    ///////////////////////////////////////////////////////////////////////////
+    //  the eol_director matches line endings
+    ///////////////////////////////////////////////////////////////////////////
+    struct eol_director : end_director_base<eol_director, mpl::true_>
+    {
+        template <typename Iterator>
+        static bool test (Iterator& first, Iterator const& last)
+        {
+            bool matched = false;
+            if (first != last && *first == '\r')    // CR
+            {
+                matched = true;
+                ++first;
+            }
+            if (first != last && *first == '\n')    // LF
+            {
+                matched = true;
+                ++first;
+            }
+            return matched;
+        }
+
+        template <typename Component>
+        static std::string what(Component const&)
+        {
+            return "eol";
+        }
+    };
+    
+///////////////////////////////////////////////////////////////////////////////
+}}}
+
+#endif
+
+
Modified: trunk/boost/spirit/home/qi/char.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/char.hpp	(original)
+++ trunk/boost/spirit/home/qi/char.hpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -10,7 +10,6 @@
 #include <boost/spirit/home/qi/char/char_parser.hpp>
 #include <boost/spirit/home/qi/char/char.hpp>
 #include <boost/spirit/home/qi/char/char_class.hpp>
-#include <boost/spirit/home/qi/char/primitives.hpp>
 #include <boost/spirit/home/qi/char/meta_grammar.hpp>
 
 #endif
Modified: trunk/boost/spirit/home/qi/char/meta_grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/char/meta_grammar.hpp	(original)
+++ trunk/boost/spirit/home/qi/char/meta_grammar.hpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -40,12 +40,9 @@
     template <typename Tag>
     struct char_class;
 
-    struct eol_director;
-    struct eoi_director;
-
-    ///////////////////////////////////////////////////////////////////////////
     struct char_meta_grammar;
 
+    ///////////////////////////////////////////////////////////////////////////
     template <typename Expr, typename Enable>
     struct is_valid_expr;
 
@@ -350,8 +347,6 @@
               , qi::domain
               , char_class<mpl::_>
             >
-          , meta_grammar::terminal_rule<qi::domain, tag::eol, eol_director>
-          , meta_grammar::terminal_rule<qi::domain, tag::eoi, eoi_director>
         >
     {};
 
Deleted: trunk/boost/spirit/home/qi/char/primitives.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/char/primitives.hpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
+++ (empty file)
@@ -1,101 +0,0 @@
-/*=============================================================================
-    Copyright (c) 2001-2008 Hartmut Kaiser
-
-    Distributed under the Boost Software License, Version 1.0. (See accompanying
-    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-==============================================================================*/
-
-#if !defined(BOOST_SPIRIT_PRIMITIVES_APR_17_2008_0751PM)
-#define BOOST_SPIRIT_PRIMITIVES_APR_17_2008_0751PM
-
-///////////////////////////////////////////////////////////////////////////////
-namespace boost { namespace spirit { namespace qi
-{
-    ///////////////////////////////////////////////////////////////////////////
-    //  the eol_director matches line endings
-    ///////////////////////////////////////////////////////////////////////////
-    struct eol_director
-    {
-        template <typename Component, typename Context, typename Iterator>
-        struct attribute
-        {
-            typedef unused_type type;
-        };
-
-        template <
-            typename Component
-          , typename Iterator, typename Context
-          , typename Skipper, typename Attribute>
-        static bool parse(
-            Component const& component
-          , Iterator& first, Iterator const& last
-          , Context& context, Skipper const& skipper
-          , Attribute& attr)
-        {
-            qi::skip(first, last, skipper);
-
-            Iterator it = first;
-
-            bool matched = false;
-            if (it != last && *it == '\r')    // CR
-            {
-                matched = true;
-                ++it;
-            }
-            if (it != last && *it == '\n')    // LF
-            {
-                matched = true;
-                ++it;
-            }
-            if (!matched)
-                return false;
-                
-            first = it;
-            return true;
-        }
-
-        template <typename Component>
-        static std::string what(Component const&)
-        {
-            return "eol";
-        }
-    };
-    
-    ///////////////////////////////////////////////////////////////////////////
-    //  the eoi_director matches the end of the input
-    ///////////////////////////////////////////////////////////////////////////
-    struct eoi_director
-    {
-        template <typename Component, typename Context, typename Iterator>
-        struct attribute
-        {
-            typedef unused_type type;
-        };
-
-        template <
-            typename Component
-          , typename Iterator, typename Context
-          , typename Skipper, typename Attribute>
-        static bool parse(
-            Component const& component
-          , Iterator& first, Iterator const& last
-          , Context& context, Skipper const& skipper
-          , Attribute& attr)
-        {
-            qi::skip(first, last, skipper);
-            return first == last;
-        }
-
-        template <typename Component>
-        static std::string what(Component const&)
-        {
-            return "eoi";
-        }
-    };
-    
-///////////////////////////////////////////////////////////////////////////////
-}}}
-
-#endif
-
-
Modified: trunk/libs/spirit/test/qi/char.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/char.cpp	(original)
+++ trunk/libs/spirit/test/qi/char.cpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -23,8 +23,6 @@
     using namespace boost::spirit::ascii;
     using boost::spirit::char_;
     using boost::spirit::wchar;
-    using boost::spirit::eol;
-    using boost::spirit::eoi;
     
     {
         BOOST_TEST(test("x", 'x'));
@@ -116,36 +114,6 @@
         BOOST_TEST((test("x", char_(val('x')))));
         BOOST_TEST((test("h", char_(val('a'), val('n')))));
     }
-
-    {   // eol
-        BOOST_TEST(test("\r", eol));
-        BOOST_TEST(test("\r\n", eol));
-        BOOST_TEST(test("\n", eol));
-        BOOST_TEST(!test("\b", eol));
-
-        BOOST_TEST(test("   \r", eol, char_(' ')));
-        BOOST_TEST(test("   \r\n", eol, char_(' ')));
-        BOOST_TEST(test("   \n", eol, char_(' ')));
-        BOOST_TEST(!test("   \b", eol, char_(' ')));
-
-        BOOST_TEST(test(L"\r", eol));
-        BOOST_TEST(test(L"\r\n", eol));
-        BOOST_TEST(test(L"\n", eol));
-        BOOST_TEST(!test(L"\b", eol));
-
-        BOOST_TEST(test(L"   \r", eol, wchar(L' ')));
-        BOOST_TEST(test(L"   \r\n", eol, wchar(L' ')));
-        BOOST_TEST(test(L"   \n", eol, wchar(L' ')));
-        BOOST_TEST(!test(L"   \b", eol, wchar(L' ')));
-    }
-    
-    {   // eoi
-        BOOST_TEST(test("", eoi));
-        BOOST_TEST(!test("a", eoi));
-
-        BOOST_TEST(test("   ", eoi, space));
-        BOOST_TEST(!test("   a", eoi, space));
-    }
     
     return boost::report_errors();
 }
Added: trunk/libs/spirit/test/qi/end.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/end.cpp	2008-04-20 22:01:31 EDT (Sun, 20 Apr 2008)
@@ -0,0 +1,78 @@
+/*=============================================================================
+    Copyright (c) 2001-2007 Joel de Guzman
+    Copyright (c) 2001-2008 Hartmut Kaiser
+
+    Distributed under the Boost Software License, Version 1.0. (See accompanying
+    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+int
+main()
+{
+    using spirit_test::test;
+    using namespace boost::spirit::qi;
+    using namespace boost::spirit::ascii;
+    using boost::spirit::char_;
+    using boost::spirit::wchar;
+    using boost::spirit::eol;
+    using boost::spirit::eoi;
+    
+    {   // eol
+        BOOST_TEST(test("\r", eol));
+        BOOST_TEST(test("\r\n", eol));
+        BOOST_TEST(test("\n", eol));
+        BOOST_TEST(!test("\b", eol));
+
+        BOOST_TEST(!test("\r", ~eol, false));
+        BOOST_TEST(!test("\r\n", ~eol, false));
+        BOOST_TEST(!test("\n", ~eol, false));
+        BOOST_TEST(test("\b", ~eol, false));
+
+        BOOST_TEST(test("\r", ~~eol));
+        BOOST_TEST(test("\r\n", ~~eol));
+        BOOST_TEST(test("\n", ~~eol));
+        BOOST_TEST(!test("\b", ~~eol));
+
+        BOOST_TEST(test("   \r", eol, char_(' ')));
+        BOOST_TEST(test("   \r\n", eol, char_(' ')));
+        BOOST_TEST(test("   \n", eol, char_(' ')));
+        BOOST_TEST(!test("   \b", eol, char_(' ')));
+
+        BOOST_TEST(test(L"\r", eol));
+        BOOST_TEST(test(L"\r\n", eol));
+        BOOST_TEST(test(L"\n", eol));
+        BOOST_TEST(!test(L"\b", eol));
+
+        BOOST_TEST(test(L"   \r", eol, wchar(L' ')));
+        BOOST_TEST(test(L"   \r\n", eol, wchar(L' ')));
+        BOOST_TEST(test(L"   \n", eol, wchar(L' ')));
+        BOOST_TEST(!test(L"   \b", eol, wchar(L' ')));
+    }
+    
+    {   // eoi
+        BOOST_TEST(test("", eoi));
+        BOOST_TEST(!test("a", eoi));
+        BOOST_TEST(test("a", ~eoi, false));
+        BOOST_TEST(!test("", ~eoi));
+        BOOST_TEST(test("", ~~eoi));
+        BOOST_TEST(!test("a", ~~eoi));
+
+        BOOST_TEST(test("   ", eoi, space));
+        BOOST_TEST(!test("   a", eoi, space));
+        BOOST_TEST(test("   a", ~eoi, space, false));
+        BOOST_TEST(!test("   ", ~eoi, space));
+        BOOST_TEST(test("   ", ~~eoi, space));
+        BOOST_TEST(!test("   a", ~~eoi, space));
+    }
+    
+    return boost::report_errors();
+}