Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file support/spirit_qi.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 19.07.2009
|
Chris@16
|
11 *
|
Chris@16
|
12 * This header enables Boost.Spirit.Qi support for Boost.Log.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@101
|
18 #include <boost/utility/enable_if.hpp>
|
Chris@101
|
19 #include <boost/spirit/include/qi_parse.hpp>
|
Chris@101
|
20 #include <boost/spirit/include/qi_domain.hpp>
|
Chris@101
|
21 #include <boost/spirit/include/support_unused.hpp>
|
Chris@101
|
22 #include <boost/spirit/home/support/meta_compiler.hpp> // spirit::compile()
|
Chris@101
|
23 #include <boost/spirit/home/qi/nonterminal/nonterminal_fwd.hpp> // rule forward declaration
|
Chris@16
|
24 #include <boost/log/detail/config.hpp>
|
Chris@16
|
25 #include <boost/log/utility/functional/matches.hpp>
|
Chris@16
|
26 #include <boost/log/detail/header.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
29 #pragma once
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost {
|
Chris@16
|
33
|
Chris@16
|
34 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
35
|
Chris@16
|
36 namespace aux {
|
Chris@16
|
37
|
Chris@101
|
38 //! This tag type is used if an expression is recognized as a Boost.Spirit.Qi expression
|
Chris@101
|
39 struct boost_spirit_qi_expression_tag;
|
Chris@101
|
40
|
Chris@101
|
41 //! The metafunction detects the matching expression kind and returns a tag that is used to specialize \c match_traits
|
Chris@101
|
42 template< typename ExpressionT >
|
Chris@101
|
43 struct matching_expression_kind< ExpressionT, typename boost::enable_if< spirit::traits::matches< spirit::qi::domain, ExpressionT > >::type >
|
Chris@16
|
44 {
|
Chris@101
|
45 typedef boost_spirit_qi_expression_tag type;
|
Chris@16
|
46 };
|
Chris@16
|
47
|
Chris@101
|
48 //! The matching function implementation
|
Chris@101
|
49 template< typename ExpressionT >
|
Chris@101
|
50 struct match_traits< ExpressionT, boost_spirit_qi_expression_tag >
|
Chris@16
|
51 {
|
Chris@101
|
52 typedef typename spirit::result_of::compile< spirit::qi::domain, ExpressionT, spirit::unused_type >::type compiled_type;
|
Chris@101
|
53
|
Chris@101
|
54 static compiled_type compile(ExpressionT const& expr)
|
Chris@101
|
55 {
|
Chris@101
|
56 return spirit::compile< spirit::qi::domain >(expr);
|
Chris@101
|
57 }
|
Chris@101
|
58
|
Chris@101
|
59 template< typename StringT >
|
Chris@101
|
60 static bool matches(StringT const& str, ExpressionT const& expr)
|
Chris@101
|
61 {
|
Chris@101
|
62 typedef typename StringT::const_iterator const_iterator;
|
Chris@101
|
63 const_iterator it = str.begin(), end = str.end();
|
Chris@101
|
64 return (spirit::qi::parse(it, end, expr) && it == end);
|
Chris@101
|
65 }
|
Chris@101
|
66 };
|
Chris@101
|
67
|
Chris@101
|
68 //! The matching function implementation
|
Chris@101
|
69 template< typename IteratorT, typename T1, typename T2, typename T3, typename T4 >
|
Chris@101
|
70 struct match_traits< spirit::qi::rule< IteratorT, T1, T2, T3, T4 >, boost_spirit_qi_expression_tag >
|
Chris@101
|
71 {
|
Chris@101
|
72 typedef spirit::qi::rule< IteratorT, T1, T2, T3, T4 > compiled_type;
|
Chris@101
|
73 static compiled_type compile(compiled_type const& expr) { return expr; }
|
Chris@101
|
74
|
Chris@101
|
75 template< typename StringT >
|
Chris@101
|
76 static bool matches(StringT const& str, compiled_type const& expr)
|
Chris@16
|
77 {
|
Chris@16
|
78 typedef typename StringT::const_iterator const_iterator;
|
Chris@16
|
79 const_iterator it = str.begin(), end = str.end();
|
Chris@16
|
80 return (spirit::qi::parse(it, end, expr) && it == end);
|
Chris@16
|
81 }
|
Chris@16
|
82 };
|
Chris@16
|
83
|
Chris@16
|
84 } // namespace aux
|
Chris@16
|
85
|
Chris@16
|
86 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
87
|
Chris@16
|
88 } // namespace boost
|
Chris@16
|
89
|
Chris@16
|
90 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
91
|
Chris@16
|
92 #endif // BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
|