Boost logo

Boost-Commit :

From: joel_at_[hidden]
Date: 2008-04-28 07:15:14


Author: djowel
Date: 2008-04-28 07:15:13 EDT (Mon, 28 Apr 2008)
New Revision: 44843
URL: http://svn.boost.org/trac/boost/changeset/44843

Log:
experimental grammar/grammar_def unification
Text files modified:
   trunk/boost/spirit/home/qi/nonterminal/grammar.hpp | 64 +++++++++++++++++++++++++++++++++++++++
   trunk/boost/spirit/home/qi/nonterminal/rule.hpp | 5 ++
   2 files changed, 67 insertions(+), 2 deletions(-)

Modified: trunk/boost/spirit/home/qi/nonterminal/grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/grammar.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/grammar.hpp 2008-04-28 07:15:13 EDT (Mon, 28 Apr 2008)
@@ -24,7 +24,7 @@
             grammar<Definition>
           , typename Definition::sig_type
           , typename Definition::locals_type
- >
+ >, noncopyable
     {
         typedef typename Definition::sig_type sig_type;
         typedef typename Definition::locals_type locals_type;
@@ -103,6 +103,68 @@
         std::string name_;
     };
 
+ template <
+ typename Iterator
+ , typename T0 = unused_type
+ , typename T1 = unused_type
+ , typename T2 = unused_type
+ >
+ struct grammar_
+ : nonterminal<
+ grammar_<Iterator, T0, T1, T2>
+ , typename qi::rule<Iterator, T0, T1, T2>::sig_type
+ , typename qi::rule<Iterator, T0, T1, T2>::locals_type
+ >, noncopyable
+ {
+ typedef Iterator iterator_type;
+ typedef qi::rule<Iterator, T0, T1, T2> start_type;
+ typedef typename start_type::sig_type sig_type;
+ typedef typename start_type::locals_type locals_type;
+ typedef typename start_type::skipper_type skipper_type;
+ typedef grammar_<Iterator, T0, T1, T2> base_type;
+
+ grammar_(start_type const& start, std::string const& name_ = std::string())
+ : start(start), name_(name_) {}
+
+ std::string name() const
+ {
+ return name_;
+ }
+
+ void name(std::string const& name__)
+ {
+ name_ = name__;
+ }
+
+ std::string name_;
+ start_type const& start;
+
+ private:
+
+ template <typename Iterator_, typename Context, typename Skipper>
+ bool parse(
+ Iterator& first, Iterator const& last
+ , Context& context, Skipper const& skipper) const
+ {
+ return start.parse(first, last, context, skipper);
+ }
+
+ std::string what() const
+ {
+ if (name().empty())
+ {
+ return start.what();
+ }
+ else
+ {
+ return name();
+ }
+ }
+
+ friend struct nonterminal_director;
+ };
+
+
     ///////////////////////////////////////////////////////////////////////////
     // Generator functions helping to construct a proper grammar object
     // instance

Modified: trunk/boost/spirit/home/qi/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/rule.hpp 2008-04-28 07:15:13 EDT (Mon, 28 Apr 2008)
@@ -143,6 +143,9 @@
         template <typename Definition>
         friend struct grammar;
 
+ template <typename Iterator_, typename T0_, typename T1_, typename T2_>
+ friend struct grammar_;
+
         friend struct detail::rule_decorator;
 
         template <typename Expr, typename Auto>
@@ -170,7 +173,7 @@
         {
             // If the following line produces a compilation error stating the
             // 4th parameter is not convertible to the expected type, then you
- // probably trying to use this rule instance with a skipper which
+ // probably trying to use this rule instance with a skipper which
             // is not compatible with the skipper type used while defining the
             // type of this rule instance.
             return ptr->parse(first, last, context, skipper);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk