Re: easy naming of a no actions scanner

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Re: easy naming of a no actions scanner

Joao Abecasis
Carl Barron wrote:

> Is this all that is needed to create the type of
> a scanner. given another scanner Scan?
> #include <boost/spirit/core.hpp>
> template <class Scan>
> struct no_node_scanner
> {
>     typename boost::spirit::scanner
>     <
>         typename Scan::iterator_t,
>         boost::spirit::scanner_policies
>         <
>             typename Scan::iteration_policy_t,
>             boost::spirit´∑::match_policy,
>             typename Scan::action_policy_t
>         >
>     >    type;
> };
> no_node_scanner<Scan>::type is the type of a no node scanner created
> from Scan,
> Scan is a boost::spirit::scanner<....>

Well, that is almost all there is to it.

One thing, though. Replacing scanner policies is usually done in a
non-destructive way in Spirit. That is, instead of just replacing
match_policy as you do above, you would wrap it for future reference.
Something like match_policy_override<old_match_policy>. In this way we
can always get the initial scanner from the new one and we leave room
for extension.

Then, you may want to add a safeguard to avoid creating large chains of
unnecessary match_policy_overrides:


<<< Which reminds, me... I offered to look into places where this comes
up in Spirit, but haven't got around to it. :-/ Sorry, Joel! >>>

The final solution could be something like:

     template <class PreviousMatchPolicy>
     struct reset_match_policy
         : PreviousMatchPolicy
         reset_match_policy() {}

         template <class OtherPolicy>
         reset_match_policy(OtherPolicy const & p)
             : PreviousMatchPolicy(p)

         ... cirurgically override match policy here ...

     template <class MatchPolicy>
     struct reset_match_scanner_match_policy
         typedef reset_match_policy<MatchPolicy> type;

     template <class MatchPolicy>
     struct reset_match_scanner_match_policy<
         reset_match_policy<MatchPolicy> >
         typedef reset_match_policy<MatchPolicy> type;

     template <class Scanner>
     struct reset_match_scanner
         typedef scanner<
             typename Scanner::iterator_t,
                 typename Scanner::iteration_policy_t,
                 typename reset_match_scanner_match_policy<
                     typename Scanner::match_policy_t>::type,
                 typename Scanner::action_policy_t
         > type;

Then again, depending on what you're trying to do this could be overkill ;-)



SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Spirit-general mailing list
[hidden email]