当我尝试编译下面的代码(使用示例boost\spirit\home\lex\argument.hpp: value_setter
)时,我收到以下编译器错误:
c:\program files (x86)\boost\boost_1_50\boost\range\iterator.hpp(63) : error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c<C,F1,F2>'
with
[
C=true,
F1=boost::range_const_iterator<const char *>,
F2=boost::range_mutable_iterator<const char *const >
]
c:\program files (x86)\boost\boost_1_50\boost\range\iterator_range_core.hpp(56) : see reference to class template instantiation 'boost::range_iterator<C>' being compiled
with
[
C=const char *const
]
...
没有语义动作,一切都编译得很好。这是示例:
#include <boost/spirit/include/lex_lexertl.hpp>
namespace lex = boost::spirit::lex;
template <typename Lexer>
struct my_tokens : lex::lexer<Lexer>
{
my_tokens()
{
identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
this->self = identifier [ lex::_val = "identifier" ] // problematic action
;
}
lex::token_def<> identifier;
};
int main()
{
typedef std::string::iterator base_iterator_type;
typedef
lex::lexertl::actor_lexer<lex::lexertl::token<base_iterator_type> >
lexer_type;
my_tokens<lexer_type> myLexer;
std::string str = "id1";
base_iterator_type first = str.begin();
bool r = lex::tokenize(first, str.end(), myLexer);
if (!r) {
std::string rest(first, str.end());
std::cerr << "Lexical analysis failed\n" << "stopped at: \""
<< rest << "\"\n";
}
}
出了什么问题?如何设置/更改令牌的值?