Question

So, I'm using boost 1.47.0 and I've been trying to put together a lexer.

My goal is to add to some of the tokens of my lexer a semantic action containing spirit::lex::_pass = spirit::lex::pass_flags::pass_ignore. However, I haven't been able to get any semantic actions to compile. I've attached a (more or less) minimal example below. I'm compiling with clang on OS X 10.7.1.

Compile command

clang++ -DBOOST_SPIRIT_DEBUG -DBOOST_SPIRIT_LEXERTL_DEBUG -DBOOST_SPIRIT_USE_PHOENIX_V3 -c input.cc

Code that compiles

#include <boost/phoenix.hpp>
#include <boost/spirit/home/lex.hpp>
#include <boost/spirit/home/lex/lexer/lexertl/lexer.hpp>

namespace phoenix = boost::phoenix;
namespace spirit = boost::spirit;

struct vhdl_lexer : spirit::lex::lexer< spirit::lex::lexertl::lexer<> > {
    vhdl_lexer() {
        num = "[0-9]";
        any = ".";

        this->self
                = num
                | any
                ;
    }

    spirit::lex::token_def<> num, any;
};

Code that won't compile

#include <boost/phoenix.hpp>
#include <boost/spirit/home/lex.hpp>
#include <boost/spirit/home/lex/lexer/lexertl/lexer.hpp>

namespace phoenix = boost::phoenix;
namespace spirit = boost::spirit;

struct vhdl_lexer : spirit::lex::lexer< spirit::lex::lexertl::lexer<> > {
    vhdl_lexer() {
        num = "[0-9]";
        any = ".";

        this->self
            = num [ ++phoenix::ref(x) ]
            | any
            ;
    }

    int x;
    spirit::lex::token_def<> num, any;
};

Errors reported on code that doesn't compile.

/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexertl/lexer.hpp:309:34: error: no member named 'add_action' in 'boost::spirit::unused_type'
                        actions_.add_action(unique_id + j, s.second, wrapper_type::call(act));
                        ~~~~~~~~ ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/action.hpp:48:20: note: in instantiation of function template specialization
      'boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, const char *,
      boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data, const char *,
      mpl_::bool_<false>, mpl_::bool_<true> > >::add_action<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
      boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >' requested
      here
            lexdef.add_action(subject.unique_id(), subject.state(), f);
                   ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/detail/sequence_function.hpp:50:23: note: in instantiation of function template specialization
      'boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>,
      boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
      boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >::add_actions<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *,
      boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
      mpl_::bool_<true>, unsigned long>, lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >' requested here
            component.add_actions(def);
                      ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/fusion/algorithm/query/detail/any.hpp:37:16: note: in instantiation of function template specialization
      'boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
      mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
      lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::operator()<boost::spirit::lex::action<boost::spirit::lex::reference<const
      boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
      boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > > >' requested
      here
        return f(x) || 
               ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/fusion/algorithm/query/detail/any.hpp:49:16: note: in instantiation of function template specialization
      'boost::fusion::detail::linear_any<boost::fusion::cons_iterator<const boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const
      boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
      boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >,
      boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::fusion::nil> > >,
      boost::fusion::cons_iterator<const boost::fusion::nil>,
      boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
      mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
      lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > > >' requested here
        return detail::linear_any(
               ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/fusion/algorithm/query/any.hpp:30:16: note: in instantiation of function template specialization
      'boost::fusion::detail::any<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned
      long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
      boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >, boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char,
      unsigned long>, unsigned long>, boost::fusion::nil> >,
      boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
      mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
      lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >, boost::fusion::forward_traversal_tag>' requested here
        return detail::any(seq, f, typename traits::category_of<Sequence>::type());
               ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/sequence.hpp:56:13: note: in instantiation of function template specialization
      'boost::fusion::any<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>,
      boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
      boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >, boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char,
      unsigned long>, unsigned long>, boost::fusion::nil> >,
      boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
      mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
      lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > > >' requested here
            fusion::any(elements, f);
            ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexer.hpp:219:22: note: in instantiation of function template specialization
      'boost::spirit::lex::sequence<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned
      long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
      boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >, boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char,
      unsigned long>, unsigned long>, boost::fusion::nil> > >::add_actions<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *,
      boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
      mpl_::bool_<true>, unsigned long>, lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >' requested here
                expr.add_actions(def);
                     ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexer.hpp:227:17: note: in instantiation of function template specialization
      'boost::spirit::lex::detail::lexer_def_<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>,
      unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data,
      const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::compile2pass<boost::spirit::lex::sequence<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const
      boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
      boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >,
      boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::fusion::nil> > > >' requested here
                compile2pass(compile<lex::domain>(expr));
                ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexer.hpp:264:17: note: in instantiation of function template specialization
      'boost::spirit::lex::detail::lexer_def_<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>,
      unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data,
      const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::define<boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &, const
      boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
      boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > &>, 2> &, boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &>, 2> >' requested here
                define(xpr);
                ^
foo.cc:14:4: note: in instantiation of function template specialization
      'boost::spirit::lex::detail::lexer_def_<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>,
      unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data,
      const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::operator=<boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &, const
      boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
      boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > &>, 2> &, boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &>, 2> >' requested here
                        = num [ ++phoenix::ref(x) ]
                        ^
1 error generated.
Was it helpful?

Solution

http://www.boost.org/doc/libs/1_47_0/libs/spirit/doc/html/spirit/lex/abstracts/lexer_semantic_actions.html says the following:

Important

In order to use lexer semantic actions you need to use type lexertl::actor_lexer<> as your lexer class (instead of the type lexertl::lexer<> as described in earlier examples).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top