stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,32 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_LEX_IN_STATE_OCT_09_2007_0748PM)
#define BOOST_SPIRIT_LEX_IN_STATE_OCT_09_2007_0748PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/proto/core.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace qi
{
///////////////////////////////////////////////////////////////////////////
// The following is a helper template allowing to use the in_state()[] as
// a skip parser
///////////////////////////////////////////////////////////////////////////
template <typename Skipper, typename String = char const*>
struct in_state_skipper
: proto::subscript<
typename proto::terminal<
terminal_ex<tag::in_state, fusion::vector1<String> >
>::type
, Skipper
>::type {};
}}}
#endif
@@ -0,0 +1,149 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_LEX_PLAIN_RAW_TOKEN_JUN_03_2011_0853PM)
#define BOOST_SPIRIT_LEX_PLAIN_RAW_TOKEN_JUN_03_2011_0853PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/qi/skip_over.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/lexical_cast.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
// enables raw_token
template <>
struct use_terminal<qi::domain, tag::raw_token>
: mpl::true_ {};
// enables raw_token(id)
template <typename A0>
struct use_terminal<qi::domain
, terminal_ex<tag::raw_token, fusion::vector1<A0> >
> : mpl::or_<is_integral<A0>, is_enum<A0> > {};
// enables *lazy* raw_token(id)
template <>
struct use_lazy_terminal<
qi::domain, tag::raw_token, 1
> : mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
using spirit::raw_token;
#endif
using spirit::raw_token_type;
///////////////////////////////////////////////////////////////////////////
template <typename TokenId>
struct plain_raw_token
: primitive_parser<plain_raw_token<TokenId> >
{
template <typename Context, typename Iterator>
struct attribute
{
typedef unused_type type;
};
plain_raw_token(TokenId const& id)
: id(id) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
if (first != last) {
// simply match the token id with the id this component has
// been initialized with
typedef typename
boost::detail::iterator_traits<Iterator>::value_type
token_type;
typedef typename token_type::id_type id_type;
token_type const& t = *first;
if (id_type(~0) == id_type(id) || id_type(id) == t.id()) {
spirit::traits::assign_to(t, attr);
++first;
return true;
}
}
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("raw_token",
"raw_token(" + boost::lexical_cast<utf8_string>(id) + ")");
}
TokenId id;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Modifiers>
struct make_primitive<tag::raw_token, Modifiers>
{
typedef plain_raw_token<std::size_t> result_type;
result_type operator()(unused_type, unused_type) const
{
return result_type(std::size_t(~0));
}
};
template <typename Modifiers, typename TokenId>
struct make_primitive<terminal_ex<tag::raw_token, fusion::vector1<TokenId> >
, Modifiers>
{
typedef plain_raw_token<TokenId> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args));
}
};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template<typename Idtype, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::plain_raw_token<Idtype>, Attr, Context, Iterator>
: mpl::true_
{};
}}}
#endif
@@ -0,0 +1,242 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_LEX_PLAIN_TOKEN_NOV_11_2007_0451PM)
#define BOOST_SPIRIT_LEX_PLAIN_TOKEN_NOV_11_2007_0451PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/qi/skip_over.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/lexical_cast.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
// enables token
template <>
struct use_terminal<qi::domain, tag::token>
: mpl::true_ {};
// enables token(id)
template <typename A0>
struct use_terminal<qi::domain
, terminal_ex<tag::token, fusion::vector1<A0> >
> : mpl::or_<is_integral<A0>, is_enum<A0> > {};
// enables token(idmin, idmax)
template <typename A0, typename A1>
struct use_terminal<qi::domain
, terminal_ex<tag::token, fusion::vector2<A0, A1> >
> : mpl::and_<
mpl::or_<is_integral<A0>, is_enum<A0> >
, mpl::or_<is_integral<A1>, is_enum<A1> >
> {};
// enables *lazy* token(id)
template <>
struct use_lazy_terminal<
qi::domain, tag::token, 1
> : mpl::true_ {};
// enables *lazy* token(idmin, idmax)
template <>
struct use_lazy_terminal<
qi::domain, tag::token, 2
> : mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
using spirit::token;
#endif
using spirit::token_type;
///////////////////////////////////////////////////////////////////////////
template <typename TokenId>
struct plain_token
: primitive_parser<plain_token<TokenId> >
{
template <typename Context, typename Iterator>
struct attribute
{
typedef typename Iterator::base_iterator_type iterator_type;
typedef iterator_range<iterator_type> type;
};
plain_token(TokenId const& id)
: id(id) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
if (first != last) {
// simply match the token id with the id this component has
// been initialized with
typedef typename
boost::detail::iterator_traits<Iterator>::value_type
token_type;
typedef typename token_type::id_type id_type;
token_type const& t = *first;
if (id_type(~0) == id_type(id) || id_type(id) == t.id()) {
spirit::traits::assign_to(t, attr);
++first;
return true;
}
}
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("token",
"token(" + boost::lexical_cast<utf8_string>(id) + ")");
}
TokenId id;
};
///////////////////////////////////////////////////////////////////////////
template <typename TokenId>
struct plain_token_range
: primitive_parser<plain_token_range<TokenId> >
{
template <typename Context, typename Iterator>
struct attribute
{
typedef typename Iterator::base_iterator_type iterator_type;
typedef iterator_range<iterator_type> type;
};
plain_token_range(TokenId const& idmin, TokenId const& idmax)
: idmin(idmin), idmax(idmax) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
if (first != last) {
// simply match the token id with the id this component has
// been initialized with
typedef typename
boost::detail::iterator_traits<Iterator>::value_type
token_type;
typedef typename token_type::id_type id_type;
token_type const& t = *first;
if (id_type(idmin) >= t.id() && id_type(idmin) <= t.id())
{
spirit::traits::assign_to(t, attr);
++first;
return true;
}
}
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("token_range"
, "token(" +
boost::lexical_cast<utf8_string>(idmin) + ", " +
boost::lexical_cast<utf8_string>(idmax) + ")"
);
return info("token_range");
}
TokenId idmin, idmax;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Modifiers>
struct make_primitive<tag::token, Modifiers>
{
typedef plain_token<std::size_t> result_type;
result_type operator()(unused_type, unused_type) const
{
return result_type(std::size_t(~0));
}
};
template <typename Modifiers, typename TokenId>
struct make_primitive<terminal_ex<tag::token, fusion::vector1<TokenId> >
, Modifiers>
{
typedef plain_token<TokenId> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args));
}
};
template <typename Modifiers, typename TokenId>
struct make_primitive<terminal_ex<tag::token, fusion::vector2<TokenId, TokenId> >
, Modifiers>
{
typedef plain_token_range<TokenId> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args)
, fusion::at_c<1>(term.args));
}
};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template<typename Idtype, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::plain_token<Idtype>, Attr, Context, Iterator>
: mpl::true_
{};
template<typename Idtype, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::plain_token_range<Idtype>, Attr, Context, Iterator>
: mpl::true_
{};
}}}
#endif
@@ -0,0 +1,242 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_LEX_PLAIN_TOKENID_NOV_26_2010_0944AM)
#define BOOST_SPIRIT_LEX_PLAIN_TOKENID_NOV_26_2010_0944AM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/qi/skip_over.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/lexical_cast.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
// enables tokenid
template <>
struct use_terminal<qi::domain, tag::tokenid>
: mpl::true_ {};
// enables tokenid(id)
template <typename A0>
struct use_terminal<qi::domain
, terminal_ex<tag::tokenid, fusion::vector1<A0> >
> : mpl::or_<is_integral<A0>, is_enum<A0> > {};
// enables tokenid(idmin, idmax)
template <typename A0, typename A1>
struct use_terminal<qi::domain
, terminal_ex<tag::tokenid, fusion::vector2<A0, A1> >
> : mpl::and_<
mpl::or_<is_integral<A0>, is_enum<A0> >
, mpl::or_<is_integral<A1>, is_enum<A1> >
> {};
// enables *lazy* tokenid(id)
template <>
struct use_lazy_terminal<
qi::domain, tag::tokenid, 1
> : mpl::true_ {};
// enables *lazy* tokenid(idmin, idmax)
template <>
struct use_lazy_terminal<
qi::domain, tag::tokenid, 2
> : mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
using spirit::tokenid;
#endif
using spirit::tokenid_type;
///////////////////////////////////////////////////////////////////////////
// The plain_tokenid represents a simple token defined by the lexer inside
// a Qi grammar. The difference to plain_token is that it exposes the
// matched token id instead of the iterator_range of the matched input.
template <typename TokenId>
struct plain_tokenid
: primitive_parser<plain_tokenid<TokenId> >
{
template <typename Context, typename Iterator>
struct attribute
{
typedef TokenId type;
};
plain_tokenid(TokenId const& id)
: id(id) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
if (first != last) {
// simply match the token id with the id this component has
// been initialized with
typedef typename
boost::detail::iterator_traits<Iterator>::value_type
token_type;
typedef typename token_type::id_type id_type;
token_type const& t = *first;
if (id_type(~0) == id_type(id) || id_type(id) == t.id()) {
spirit::traits::assign_to(id, attr);
++first;
return true;
}
}
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("tokenid",
"tokenid(" + boost::lexical_cast<utf8_string>(id) + ")");
}
TokenId id;
};
///////////////////////////////////////////////////////////////////////////
template <typename TokenId>
struct plain_tokenid_range
: primitive_parser<plain_tokenid_range<TokenId> >
{
template <typename Context, typename Iterator>
struct attribute
{
typedef TokenId type;
};
plain_tokenid_range(TokenId const& idmin, TokenId const& idmax)
: idmin(idmin), idmax(idmax) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
if (first != last) {
// simply match the token id with the id this component has
// been initialized with
typedef typename
boost::detail::iterator_traits<Iterator>::value_type
token_type;
typedef typename token_type::id_type id_type;
token_type const& t = *first;
if (id_type(idmin) >= t.id() && id_type(idmin) <= t.id())
{
spirit::traits::assign_to(t.id(), attr);
++first;
return true;
}
}
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("tokenid_range"
, "token(" +
boost::lexical_cast<utf8_string>(idmin) + ", " +
boost::lexical_cast<utf8_string>(idmax) + ")"
);
}
TokenId idmin, idmax;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Modifiers>
struct make_primitive<tag::tokenid, Modifiers>
{
typedef plain_tokenid<std::size_t> result_type;
result_type operator()(unused_type, unused_type) const
{
return result_type(std::size_t(~0));
}
};
template <typename Modifiers, typename TokenId>
struct make_primitive<terminal_ex<tag::tokenid, fusion::vector1<TokenId> >
, Modifiers>
{
typedef plain_tokenid<TokenId> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args));
}
};
template <typename Modifiers, typename TokenId>
struct make_primitive<terminal_ex<tag::tokenid, fusion::vector2<TokenId, TokenId> >
, Modifiers>
{
typedef plain_tokenid_range<TokenId> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args)
, fusion::at_c<1>(term.args));
}
};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template<typename Idtype, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::plain_tokenid<Idtype>, Attr, Context, Iterator>
: mpl::true_
{};
template<typename Idtype, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::plain_tokenid_range<Idtype>, Attr, Context, Iterator>
: mpl::true_
{};
}}}
#endif
@@ -0,0 +1,138 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_LEX_PLAIN_TOKENID_MASK_JUN_03_2011_0929PM)
#define BOOST_SPIRIT_LEX_PLAIN_TOKENID_MASK_JUN_03_2011_0929PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/qi/skip_over.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/lexical_cast.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
// enables tokenid_mask(id)
template <typename A0>
struct use_terminal<qi::domain
, terminal_ex<tag::tokenid_mask, fusion::vector1<A0> >
> : mpl::or_<is_integral<A0>, is_enum<A0> > {};
// enables *lazy* tokenid_mask(id)
template <>
struct use_lazy_terminal<
qi::domain, tag::tokenid_mask, 1
> : mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
using spirit::tokenid_mask;
#endif
using spirit::tokenid_mask_type;
///////////////////////////////////////////////////////////////////////////
// The plain_tokenid represents a simple token defined by the lexer inside
// a Qi grammar. The difference to plain_token is that it exposes the
// matched token id instead of the iterator_range of the matched input.
// Additionally it applies the given mask to the matched token id.
template <typename Mask>
struct plain_tokenid_mask
: primitive_parser<plain_tokenid_mask<Mask> >
{
template <typename Context, typename Iterator>
struct attribute
{
typedef Mask type;
};
plain_tokenid_mask(Mask const& mask)
: mask(mask) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
if (first != last) {
// simply match the token id with the mask this component has
// been initialized with
typedef typename
boost::detail::iterator_traits<Iterator>::value_type
token_type;
typedef typename token_type::id_type id_type;
token_type const& t = *first;
if ((t.id() & mask) == id_type(mask))
{
spirit::traits::assign_to(t.id(), attr);
++first;
return true;
}
}
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("tokenid_mask",
"tokenid_mask(" + boost::lexical_cast<utf8_string>(mask) + ")");
}
Mask mask;
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Modifiers, typename Mask>
struct make_primitive<terminal_ex<tag::tokenid_mask, fusion::vector1<Mask> >
, Modifiers>
{
typedef plain_tokenid_mask<Mask> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args));
}
};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template<typename Mask, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::plain_tokenid_mask<Mask>, Attr, Context, Iterator>
: mpl::true_
{};
}}}
#endif
@@ -0,0 +1,270 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
// Copyright (c) 2010 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_LEX_STATE_SWITCHER_SEP_23_2007_0714PM)
#define BOOST_SPIRIT_LEX_STATE_SWITCHER_SEP_23_2007_0714PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/qi/detail/attributes.hpp>
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/spirit/home/support/string_traits.hpp>
#include <boost/spirit/home/support/has_semantic_action.hpp>
#include <boost/spirit/home/support/handles_container.hpp>
#include <boost/spirit/home/qi/skip_over.hpp>
#include <boost/spirit/home/qi/domain.hpp>
#include <boost/spirit/home/qi/parser.hpp>
#include <boost/spirit/home/qi/meta_compiler.hpp>
#include <boost/mpl/print.hpp>
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
// enables set_state(s)
template <typename A0>
struct use_terminal<qi::domain
, terminal_ex<tag::set_state, fusion::vector1<A0> >
> : traits::is_string<A0> {};
// enables *lazy* set_state(s)
template <>
struct use_lazy_terminal<
qi::domain, tag::set_state, 1
> : mpl::true_ {};
// enables in_state(s)[p]
template <typename A0>
struct use_directive<qi::domain
, terminal_ex<tag::in_state, fusion::vector1<A0> >
> : traits::is_string<A0> {};
// enables *lazy* in_state(s)[p]
template <>
struct use_lazy_directive<
qi::domain, tag::in_state, 1
> : mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
using spirit::set_state;
using spirit::in_state;
#endif
using spirit::set_state_type;
using spirit::in_state_type;
///////////////////////////////////////////////////////////////////////////
namespace detail
{
template <typename Iterator>
inline std::size_t
set_lexer_state(Iterator& it, std::size_t state)
{
return it.set_state(state);
}
template <typename Iterator, typename Char>
inline std::size_t
set_lexer_state(Iterator& it, Char const* statename)
{
std::size_t state = it.map_state(statename);
// If the following assertion fires you probably used the
// set_state(...) or in_state(...)[...] lexer state switcher with
// a lexer state name unknown to the lexer (no token definitions
// have been associated with this lexer state).
BOOST_ASSERT(std::size_t(~0) != state);
return it.set_state(state);
}
}
///////////////////////////////////////////////////////////////////////////
// Parser switching the state of the underlying lexer component.
// This parser gets used for the set_state(...) construct.
///////////////////////////////////////////////////////////////////////////
template <typename State>
struct state_switcher
: primitive_parser<state_switcher<State> >
{
typedef typename
remove_const<typename traits::char_type_of<State>::type>::type
char_type;
typedef std::basic_string<char_type> string_type;
template <typename Context, typename Iterator>
struct attribute
{
typedef unused_type type;
};
state_switcher(char_type const* state)
: state(state) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& /*context*/, Skipper const& skipper
, Attribute& /*attr*/) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
// just switch the state and return success
detail::set_lexer_state(first, state.c_str());
return true;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("set_state");
}
string_type state;
};
///////////////////////////////////////////////////////////////////////////
namespace detail
{
template <typename Iterator>
struct reset_state_on_exit
{
template <typename State>
reset_state_on_exit(Iterator& it_, State state_)
: it(it_)
, state(set_lexer_state(it_, traits::get_c_string(state_)))
{}
~reset_state_on_exit()
{
// reset the state of the underlying lexer instance
set_lexer_state(it, state);
}
Iterator& it;
std::size_t state;
private:
// silence MSVC warning C4512: assignment operator could not be generated
reset_state_on_exit& operator= (reset_state_on_exit const&);
};
}
///////////////////////////////////////////////////////////////////////////
// Parser, which switches the state of the underlying lexer component
// for the execution of the embedded sub-parser, switching the state back
// afterwards. This parser gets used for the in_state(...)[p] construct.
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename State>
struct state_switcher_context
: unary_parser<state_switcher_context<Subject, State> >
{
typedef Subject subject_type;
typedef typename traits::char_type_of<State>::type char_type;
typedef typename remove_const<char_type>::type non_const_char_type;
template <typename Context, typename Iterator>
struct attribute
{
typedef typename
traits::attribute_of<subject_type, Context, Iterator>::type
type;
};
state_switcher_context(Subject const& subject
, typename add_reference<State>::type state)
: subject(subject), state(state) {}
// The following conversion constructors are needed to make the
// in_state_switcher template usable
template <typename String>
state_switcher_context(
state_switcher_context<Subject, String> const& rhs)
: subject(rhs.subject), state(traits::get_c_string(rhs.state)) {}
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
, Context& context, Skipper const& skipper
, Attribute& attr) const
{
qi::skip_over(first, last, skipper); // always do a pre-skip
// the state has to be reset at exit in any case
detail::reset_state_on_exit<Iterator> guard(first, state);
return subject.parse(first, last, context, skipper, attr);
}
template <typename Context>
info what(Context& context) const
{
return info("in_state", subject.what(context));
}
Subject subject;
State state;
private:
// silence MSVC warning C4512: assignment operator could not be generated
state_switcher_context& operator= (state_switcher_context const&);
};
///////////////////////////////////////////////////////////////////////////
// Parser generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Modifiers, typename State>
struct make_primitive<terminal_ex<tag::set_state, fusion::vector1<State> >
, Modifiers, typename enable_if<traits::is_string<State> >::type>
{
typedef typename add_const<State>::type const_string;
typedef state_switcher<const_string> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(traits::get_c_string(fusion::at_c<0>(term.args)));
}
};
template <typename State, typename Subject, typename Modifiers>
struct make_directive<terminal_ex<tag::in_state, fusion::vector1<State> >
, Subject, Modifiers>
{
typedef typename add_const<State>::type const_string;
typedef state_switcher_context<Subject, const_string> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, Subject const& subject
, unused_type) const
{
return result_type(subject, fusion::at_c<0>(term.args));
}
};
}}}
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename State>
struct has_semantic_action<qi::state_switcher_context<Subject, State> >
: unary_has_semantic_action<Subject> {};
///////////////////////////////////////////////////////////////////////////
template <typename Subject, typename State, typename Attribute
, typename Context, typename Iterator>
struct handles_container<qi::state_switcher_context<Subject, State>
, Attribute, Context, Iterator>
: unary_handles_container<Subject, Attribute, Context, Iterator> {};
}}}
#endif