// Copyright (c) 2001-2010 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_STRING_TOKEN_DEF_MAR_28_2007_0722PM) #define BOOST_SPIRIT_LEX_STRING_TOKEN_DEF_MAR_28_2007_0722PM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include #include #include #include namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // Enablers /////////////////////////////////////////////////////////////////////////// template struct use_terminal >::type> // enables strings : mpl::true_ {}; template struct use_terminal // enables string(str) , fusion::vector1 > > : traits::is_string {}; }} namespace boost { namespace spirit { namespace lex { // use string from standard character set by default using spirit::standard::string_type; using spirit::standard::string; /////////////////////////////////////////////////////////////////////////// // // string_token_def // represents a string based token definition // /////////////////////////////////////////////////////////////////////////// template struct string_token_def : primitive_lexer > { typedef typename remove_const::type>::type char_type; typedef std::basic_string string_type; string_token_def(typename add_reference::type str) : str_(str), id_(std::size_t(~0)) {} template void collect(LexerDef& lexdef, State const& state) const { typedef typename LexerDef::id_type id_type; if (std::size_t(~0) == id_) id_ = lexdef.get_next_id(); unique_id_ = lexdef.add_token (state.c_str(), str_, id_); } template void add_actions(LexerDef&) const {} std::size_t id() const { return id_; } std::size_t unique_id() const { return unique_id_; } string_type str_; mutable std::size_t id_; mutable std::size_t unique_id_; }; /////////////////////////////////////////////////////////////////////////// // Lex generators: make_xxx function (objects) /////////////////////////////////////////////////////////////////////////// template struct make_primitive >::type> { typedef typename add_const::type const_string; typedef string_token_def result_type; result_type operator()( typename add_reference::type str, unused_type) const { return result_type(str); } }; template struct make_primitive< terminal_ex< tag::char_code , fusion::vector1 > , Modifiers> { typedef typename add_const::type const_string; typedef string_token_def result_type; template result_type operator()(Terminal const& term, unused_type) const { return result_type(fusion::at_c<0>(term.args)); } }; }}} // namespace boost::spirit::lex #endif