|
Boost : |
From: Jon Wray (jwray_at_[hidden])
Date: 2003-03-21 21:55:08
Thanks! I noticed that this change leads to different behavior when
assigning rules. Consider this code:
typename rule_<ScannerT, IDENTIFIER>::type Identifier;
typename rule_<ScannerT, FUNCTION>::type Function;
typename rule_<ScannerT, PREDICATE>::type Predicate;
typename rule_<ScannerT, VARIABLE>::type Variable;
Identifier = lexeme_d[token_node_d[(alpha_p | '_' | '$') >> *(alnum_p
| '_' | '$')]];
Function = Identifier;
Predicate = Identifier;
Variable = Identifier;
value.id().to_long() used to return FUNCTION, PREDICATE, or VARIABLE,
but it now returns IDENTIFIER. There's an easy, cut-and-paste
workaround:
Function = lexeme_d[token_node_d[(alpha_p | '_' | '$') >> *(alnum_p |
'_' | '$')]];
Predicate = lexeme_d[token_node_d[(alpha_p | '_' | '$') >> *(alnum_p |
'_' | '$')]];
Variable = lexeme_d[token_node_d[(alpha_p | '_' | '$') >> *(alnum_p |
'_' | '$')]];
Anyone have a better suggestion?
Jon
-----Original Message-----
From: Joel de Guzman [mailto:djowel_at_[hidden]]
Sent: Thursday, March 20, 2003 6:01 PM
To: Boost mailing list; Spirit
Subject: Re: [boost] spirit::rule<>::set_id()
Jon Wray wrote:
> What happened to spirit::rule<>::set_id()? It was in Spirit 1.5.1,
> but it's
> missing from 1.6.0. The doc still refers to it (see the very bottom
of
> http://www.boost.org/libs/spirit/doc/rule.html).
Giovanni Bajo wrote:
> I might be dumb, but I read in the documentation that each rule should
> have a member called set_id() to modify the parser ID. Now, looking
> into the code that method does not exist. Not only that, but there is
> not even a member holding the parser_id, it's just computed on the fly
> through a policy, which means that it is impossible to modify at
> runtime.
No, you are not dumb. This is a documentation oversight.
> The only way I found was:
>
> rule<T, parser_context, parser_tag<AST::ID_INTERFACE> >
> interf;
This is correct. Pardon the oversight. The change was done so as to have
a consistent interface for rules, subrules and grammars. Following the
precept that "the user should not pay for features she does not need",
the member variable was taken out in favor of a static constant. The
additional member variable is not needed in many cases.
> which is quite bloated, especially since I have to do this for many
> many rules. So, where is the missing set_id() member?
In the meantime, this is the way to do it. You can write a simple
metaprogram to ease the typing (pun?). Example:
template <typename ScannerT, in ID>
struct rule_
{
rule<ScannerT, parser_context, parser_tag<ID> > type;
};
Then:
rule_<T, AST::ID_INTERFACE>::type interf;
Sometime in the future, the interface to rules will be made easier such
that the optional template arguments can be passed in arbitrary
sequence.
Hope this helps. Again pardon the oversight.
-- Joel de Guzman joel at boost-consulting.com http://www.boost-consulting.com http://spirit.sf.net _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk