123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651 |
- #if !defined(BOOST_SPIRIT_LEX_TOKEN_FEB_10_2008_0751PM)
- #define BOOST_SPIRIT_LEX_TOKEN_FEB_10_2008_0751PM
- #if defined(_MSC_VER)
- #pragma once
- #endif
- #include <boost/config.hpp>
- #include <boost/detail/workaround.hpp>
- #include <boost/spirit/home/qi/detail/assign_to.hpp>
- #include <boost/spirit/home/support/attributes.hpp>
- #include <boost/spirit/home/support/argument.hpp>
- #include <boost/spirit/home/support/detail/lexer/generator.hpp>
- #include <boost/spirit/home/support/detail/lexer/rules.hpp>
- #include <boost/spirit/home/support/detail/lexer/consts.hpp>
- #include <boost/spirit/home/support/utree/utree_traits_fwd.hpp>
- #include <boost/spirit/home/lex/lexer/terminals.hpp>
- #include <boost/fusion/include/vector.hpp>
- #include <boost/fusion/include/at.hpp>
- #include <boost/fusion/include/value_at.hpp>
- #include <boost/variant.hpp>
- #include <boost/mpl/bool.hpp>
- #include <boost/mpl/vector.hpp>
- #include <boost/mpl/is_sequence.hpp>
- #include <boost/mpl/begin.hpp>
- #include <boost/mpl/insert.hpp>
- #include <boost/mpl/vector.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/mpl/or.hpp>
- #include <boost/range/iterator_range_core.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/type_traits/make_unsigned.hpp>
- #include <boost/static_assert.hpp>
- #if defined(BOOST_SPIRIT_DEBUG)
- #include <iosfwd>
- #endif
- namespace boost { namespace spirit { namespace lex { namespace lexertl
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <typename Iterator = char const*
- , typename AttributeTypes = mpl::vector0<>
- , typename HasState = mpl::true_
- , typename Idtype = std::size_t>
- struct token;
-
-
-
-
- template <typename Iterator, typename Idtype>
- struct token<Iterator, lex::omit, mpl::false_, Idtype>
- {
- typedef Iterator iterator_type;
- typedef mpl::false_ has_state;
- typedef Idtype id_type;
- typedef unused_type token_value_type;
- typedef typename make_unsigned<id_type>::type uid_type;
-
- token() : id_(boost::lexer::npos) {}
-
- explicit token(int) : id_(0) {}
- token(id_type id, std::size_t) : id_(id) {}
- token(id_type id, std::size_t, token_value_type)
- : id_(id) {}
- token_value_type& value() { static token_value_type u; return u; }
- token_value_type const& value() const { return unused; }
- #if defined(BOOST_SPIRIT_DEBUG)
- token(id_type id, std::size_t, Iterator const& first
- , Iterator const& last)
- : matched_(first, last)
- , id_(id) {}
- #else
- token(id_type id, std::size_t, Iterator const&, Iterator const&)
- : id_(id) {}
- #endif
-
-
-
- operator id_type() const { return id_type(uid_type(id_)); }
-
- id_type id() const { return id_type(uid_type(id_)); }
- void id(id_type newid) { id_ = uid_type(newid); }
- std::size_t state() const { return 0; }
- bool is_valid() const
- {
- return 0 != id_ && boost::lexer::npos != id_;
- }
- #if defined(BOOST_SPIRIT_DEBUG)
- #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
-
-
- token& operator= (token const& rhs)
- {
- if (this != &rhs)
- {
- id_ = rhs.id_;
- if (is_valid())
- matched_ = rhs.matched_;
- }
- return *this;
- }
- #endif
- std::pair<Iterator, Iterator> matched_;
- #endif
- protected:
- std::size_t id_;
- };
- #if defined(BOOST_SPIRIT_DEBUG)
- template <typename Char, typename Traits, typename Iterator
- , typename AttributeTypes, typename HasState, typename Idtype>
- inline std::basic_ostream<Char, Traits>&
- operator<< (std::basic_ostream<Char, Traits>& os
- , token<Iterator, AttributeTypes, HasState, Idtype> const& t)
- {
- if (t.is_valid()) {
- Iterator end = t.matched_.second;
- for (Iterator it = t.matched_.first; it != end; ++it)
- os << *it;
- }
- else {
- os << "<invalid token>";
- }
- return os;
- }
- #endif
-
-
-
-
- template <typename Iterator, typename Idtype>
- struct token<Iterator, lex::omit, mpl::true_, Idtype>
- : token<Iterator, lex::omit, mpl::false_, Idtype>
- {
- private:
- typedef token<Iterator, lex::omit, mpl::false_, Idtype> base_type;
- public:
- typedef typename base_type::id_type id_type;
- typedef Iterator iterator_type;
- typedef mpl::true_ has_state;
- typedef unused_type token_value_type;
-
- token() : state_(boost::lexer::npos) {}
-
- explicit token(int) : base_type(0), state_(boost::lexer::npos) {}
- token(id_type id, std::size_t state)
- : base_type(id, boost::lexer::npos), state_(state) {}
- token(id_type id, std::size_t state, token_value_type)
- : base_type(id, boost::lexer::npos, unused)
- , state_(state) {}
- token(id_type id, std::size_t state
- , Iterator const& first, Iterator const& last)
- : base_type(id, boost::lexer::npos, first, last)
- , state_(state) {}
- std::size_t state() const { return state_; }
- #if defined(BOOST_SPIRIT_DEBUG) && BOOST_WORKAROUND(BOOST_MSVC, == 1600)
-
-
- token& operator= (token const& rhs)
- {
- if (this != &rhs)
- {
- this->base_type::operator=(static_cast<base_type const&>(rhs));
- state_ = rhs.state_;
- }
- return *this;
- }
- #endif
- protected:
- std::size_t state_;
- };
-
-
-
-
-
- namespace detail
- {
-
-
-
-
-
-
-
-
-
-
-
- template <typename IteratorPair, typename AttributeTypes>
- struct token_value_typesequence
- {
- typedef typename mpl::insert<
- AttributeTypes
- , typename mpl::begin<AttributeTypes>::type
- , IteratorPair
- >::type sequence_type;
- typedef typename make_variant_over<sequence_type>::type type;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <typename IteratorPair, typename AttributeTypes>
- struct token_value_type
- : mpl::eval_if<
- mpl::or_<
- is_same<AttributeTypes, mpl::vector0<> >
- , is_same<AttributeTypes, mpl::vector<> > >
- , mpl::identity<IteratorPair>
- , token_value_typesequence<IteratorPair, AttributeTypes> >
- {};
- }
- template <typename Iterator, typename AttributeTypes, typename HasState
- , typename Idtype>
- struct token : token<Iterator, lex::omit, HasState, Idtype>
- {
- private:
- BOOST_STATIC_ASSERT((mpl::is_sequence<AttributeTypes>::value ||
- is_same<AttributeTypes, lex::omit>::value));
- typedef token<Iterator, lex::omit, HasState, Idtype> base_type;
- protected:
-
-
-
-
-
-
-
- typedef iterator_range<Iterator> iterpair_type;
- public:
- typedef typename base_type::id_type id_type;
- typedef typename detail::token_value_type<
- iterpair_type, AttributeTypes
- >::type token_value_type;
- typedef Iterator iterator_type;
-
- token() : value_(iterpair_type(iterator_type(), iterator_type())) {}
-
- explicit token(int)
- : base_type(0)
- , value_(iterpair_type(iterator_type(), iterator_type())) {}
- token(id_type id, std::size_t state, token_value_type const& value)
- : base_type(id, state, value)
- , value_(value) {}
- token(id_type id, std::size_t state, Iterator const& first
- , Iterator const& last)
- : base_type(id, state, first, last)
- , value_(iterpair_type(first, last)) {}
- token_value_type& value() { return value_; }
- token_value_type const& value() const { return value_; }
- #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
-
-
- token& operator= (token const& rhs)
- {
- if (this != &rhs)
- {
- this->base_type::operator=(static_cast<base_type const&>(rhs));
- if (this->is_valid())
- value_ = rhs.value_;
- }
- return *this;
- }
- #endif
- protected:
- token_value_type value_;
- };
-
-
- template <typename Iterator, typename AttributeTypes, typename HasState
- , typename Idtype>
- inline bool
- operator== (token<Iterator, AttributeTypes, HasState, Idtype> const& lhs,
- token<Iterator, AttributeTypes, HasState, Idtype> const& rhs)
- {
- return lhs.id() == rhs.id();
- }
-
-
-
-
-
- template <typename Iterator, typename AttributeTypes, typename HasState
- , typename Idtype>
- inline bool
- token_is_valid(token<Iterator, AttributeTypes, HasState, Idtype> const& t)
- {
- return t.is_valid();
- }
- }}}}
- namespace boost { namespace spirit { namespace traits
- {
-
-
-
-
-
-
-
- template <typename Attribute, typename Iterator, typename AttributeTypes
- , typename HasState, typename Idtype>
- struct assign_to_attribute_from_value<Attribute
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- {
- static void
- call(lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> const& t
- , Attribute& attr)
- {
-
-
-
-
-
-
- if (0 == t.value().which()) {
-
- typedef iterator_range<Iterator> iterpair_type;
- iterpair_type const& ip = boost::get<iterpair_type>(t.value());
-
-
-
-
- spirit::traits::assign_to(ip.begin(), ip.end(), attr);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- typedef lex::lexertl::token<
- Iterator, AttributeTypes, HasState, Idtype> token_type;
- spirit::traits::assign_to(
- attr, const_cast<token_type&>(t).value());
- }
- else {
-
- spirit::traits::assign_to(boost::get<Attribute>(t.value()), attr);
- }
- }
- };
- template <typename Attribute, typename Iterator, typename AttributeTypes
- , typename HasState, typename Idtype>
- struct assign_to_container_from_value<Attribute
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- : assign_to_attribute_from_value<Attribute
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- {};
- template <typename Iterator, typename AttributeTypes
- , typename HasState, typename Idtype>
- struct assign_to_container_from_value<utree
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- : assign_to_attribute_from_value<utree
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- {};
- template <typename Iterator>
- struct assign_to_container_from_value<
- iterator_range<Iterator>, iterator_range<Iterator> >
- {
- static void
- call(iterator_range<Iterator> const& val, iterator_range<Iterator>& attr)
- {
- attr = val;
- }
- };
-
-
- template <typename Attribute, typename Iterator, typename HasState
- , typename Idtype>
- struct assign_to_attribute_from_value<Attribute
- , lex::lexertl::token<Iterator, mpl::vector0<>, HasState, Idtype> >
- {
- static void
- call(lex::lexertl::token<Iterator, mpl::vector0<>, HasState, Idtype> const& t
- , Attribute& attr)
- {
-
-
-
- spirit::traits::assign_to(t.value().begin(), t.value().end(), attr);
- }
- };
-
- template <typename Attribute, typename Iterator, typename HasState
- , typename Idtype>
- struct assign_to_attribute_from_value<Attribute
- , lex::lexertl::token<Iterator, mpl::vector<>, HasState, Idtype> >
- {
- static void
- call(lex::lexertl::token<Iterator, mpl::vector<>, HasState, Idtype> const& t
- , Attribute& attr)
- {
-
-
-
- spirit::traits::assign_to(t.value().begin(), t.value().end(), attr);
- }
- };
-
-
-
-
- template <typename Attribute, typename Iterator, typename HasState
- , typename Idtype>
- struct assign_to_attribute_from_value<Attribute
- , lex::lexertl::token<Iterator, lex::omit, HasState, Idtype> >
- {
- static void
- call(lex::lexertl::token<Iterator, lex::omit, HasState, Idtype> const&
- , Attribute&)
- {
-
- }
- };
- template <typename Attribute, typename Iterator, typename HasState
- , typename Idtype>
- struct assign_to_container_from_value<Attribute
- , lex::lexertl::token<Iterator, lex::omit, HasState, Idtype> >
- : assign_to_attribute_from_value<Attribute
- , lex::lexertl::token<Iterator, lex::omit, HasState, Idtype> >
- {};
-
- template <typename Iterator, typename AttributeTypes, typename HasState
- , typename Idtype_, typename Idtype>
- struct assign_to_attribute_from_value<
- fusion::vector2<Idtype_, iterator_range<Iterator> >
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- {
- static void
- call(lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> const& t
- , fusion::vector2<Idtype_, iterator_range<Iterator> >& attr)
- {
-
-
-
- typedef iterator_range<Iterator> iterpair_type;
- typedef fusion::vector2<Idtype_, iterator_range<Iterator> >
- attribute_type;
- iterpair_type const& ip = boost::get<iterpair_type>(t.value());
- attr = attribute_type(t.id(), ip);
- }
- };
- template <typename Iterator, typename AttributeTypes, typename HasState
- , typename Idtype_, typename Idtype>
- struct assign_to_container_from_value<
- fusion::vector2<Idtype_, iterator_range<Iterator> >
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- : assign_to_attribute_from_value<
- fusion::vector2<Idtype_, iterator_range<Iterator> >
- , lex::lexertl::token<Iterator, AttributeTypes, HasState, Idtype> >
- {};
-
-
-
- template <typename Iterator, typename Attribute, typename HasState
- , typename Idtype>
- struct token_printer_debug<
- lex::lexertl::token<Iterator, Attribute, HasState, Idtype> >
- {
- typedef lex::lexertl::token<Iterator, Attribute, HasState, Idtype> token_type;
- template <typename Out>
- static void print(Out& out, token_type const& val)
- {
- out << '[';
- spirit::traits::print_token(out, val.value());
- out << ']';
- }
- };
- }}}
- #endif
|