Re: [lex][boost 1.44] 2 oddities
"Hartmut Kaiser" <[email protected]> Wed, 17 Nov 2010 14:44:21 -0600
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <[email protected]> |
Zach,
> I couldn't find anything about these on either Spirit list, but apologies
> if I just missed it.
>
> Oddity #1: There is a specialization of
> assign_to_attribute_from_iterators<> for bool, in
> home/qi/detail/construct.hpp:
>
> template <typename Iterator>
> struct assign_to_attribute_from_iterators<bool, Iterator>
> {
> static void
> call(Iterator const& first, Iterator const& last, char& attr)
> { ... }
> };
>
> Notice that attr is a char&, not a bool&. Is this a cut-and-paste error,
> or is it intentional? It has forced me to provide my own specialization
> to get lex to automatically create a token_def<bool>:
>
> template <>
> struct assign_to_attribute_from_iterators<bool, my_iterator_type,
> void>
> {
> static void call(const GG::text_iterator& first, const
> my_iterator_type& last, bool& attr)
> { ... }
> };
>
> Notice that I was forced to supply an iterator type so that my
> specialization is a better fit. This means that I can't currently define
> a lexer template that takes an Iterator parameter that "just works" --
> when my users change their choice of iterator, they have to add a new full
> specialization of assign_to_attribute_from_iterators<>.
That seems to be a cut&paste error. It's fixed in SVN (and I added a couple
of missing specializations while I was at it as well).
> I've verified that this code is still in place on the release branch, so
> presumably it will go out in 1.45.
Yes, I don't believe I would get permission to merge at this stage.
> Oddity #2: It seems that I have to define
> assign_to_attribute_from_iterators<> for new types, even if I define a
> semantic action that does the assignment.
Yes, that's true. It's the only way the lexer could know how to convert a
certain input character sequence into your type. Or do I misunderstand
something?
> This further means that any
> semantic action [_val = ...] is useless, because the conversion will
> happen later and overwrite the token's value anyway, right?
Hmmm, I think these two things are unrelated. The conversion from the input
iterators to your type is one thing, while the assignment inside the
semantic action is another one. Could you elaborate why you believe the
semantic action to be useless?
Regards Hartmut
---------------
http://boost-spirit.com
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev