|
Boost-Commit : |
From: joel_at_[hidden]
Date: 2008-04-27 04:41:13
Author: djowel
Date: 2008-04-27 04:41:13 EDT (Sun, 27 Apr 2008)
New Revision: 44812
URL: http://svn.boost.org/trac/boost/changeset/44812
Log:
added grammar_class
Text files modified:
trunk/boost/spirit/home/qi/nonterminal/grammar.hpp | 83 +++++++++++++++++++++++++++++++++++++--
1 files changed, 78 insertions(+), 5 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-27 04:41:13 EDT (Sun, 27 Apr 2008)
@@ -104,23 +104,96 @@
};
///////////////////////////////////////////////////////////////////////////
- // Generator functions helping to construct a proper grammar object
+ // Generator functions helping to construct a proper grammar object
// instance
///////////////////////////////////////////////////////////////////////////
template <typename Definition>
- inline grammar<Definition>
+ inline grammar<Definition>
make_parser(Definition const& def)
{
return grammar<Definition>(def);
}
-
+
template <typename Definition, typename Start>
- inline grammar<Definition>
+ inline grammar<Definition>
make_parser(Definition const& def, Start const& start)
{
return grammar<Definition>(def, start);
}
-
+
+ ///////////////////////////////////////////////////////////////////////////
+ // The grammar_class template
+ ///////////////////////////////////////////////////////////////////////////
+ template <template <typename, typename> class Def>
+ struct grammar_class {};
+
+ template <typename Iterator, template <typename, typename> class Def>
+ inline bool
+ parse(
+ Iterator& first
+ , Iterator last
+ , grammar_class<Def>)
+ {
+ Def<Iterator, unused_type> def;
+ grammar<Def<Iterator, unused_type> > g(def);
+ return parse(first, last, g);
+ }
+
+ template <typename Iterator
+ , template <typename, typename> class Def, typename Attr>
+ inline bool
+ parse(
+ Iterator& first
+ , Iterator last
+ , grammar_class<Def>
+ , Attr& attr)
+ {
+ Def<Iterator, unused_type> def;
+ grammar<Def<Iterator, unused_type> > g(def);
+ return parse(first, last, g, attr);
+ }
+
+ template <typename Iterator
+ , template <typename, typename> class Def, typename Skipper>
+ inline bool
+ phrase_parse(
+ Iterator& first
+ , Iterator last
+ , grammar_class<Def>
+ , Skipper const& skipper_)
+ {
+ typedef typename
+ result_of::as_component<qi::domain, Skipper>::type
+ skipper_type;
+
+ skipper_type skipper = spirit::as_component(qi::domain(), skipper_);
+
+ Def<Iterator, skipper_type> def;
+ grammar<Def<Iterator, skipper_type> > g(def);
+ return phrase_parse(first, last, g, skipper);
+ }
+
+ template <typename Iterator
+ , template <typename, typename> class Def, typename Attr, typename Skipper>
+ inline bool
+ phrase_parse(
+ Iterator& first
+ , Iterator last
+ , grammar_class<Def>
+ , Attr& attr
+ , Skipper const& skipper_)
+ {
+ typedef typename
+ result_of::as_component<qi::domain, Skipper>::type
+ skipper_type;
+
+ skipper_type skipper = spirit::as_component(qi::domain(), skipper_);
+
+ Def<Iterator, skipper_type> def;
+ grammar<Def<Iterator, skipper_type> > g(def);
+ return phrase_parse(first, last, g, attr, skipper);
+ }
+
}}}
#endif
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