Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 =============================================================================*/
|
Chris@16
|
7 #if !defined(SPIRIT_LEXEME_MARCH_24_2007_0802AM)
|
Chris@16
|
8 #define SPIRIT_LEXEME_MARCH_24_2007_0802AM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/home/qi/meta_compiler.hpp>
|
Chris@16
|
15 #include <boost/spirit/home/qi/skip_over.hpp>
|
Chris@16
|
16 #include <boost/spirit/home/qi/parser.hpp>
|
Chris@16
|
17 #include <boost/spirit/home/qi/detail/unused_skipper.hpp>
|
Chris@16
|
18 #include <boost/spirit/home/support/unused.hpp>
|
Chris@16
|
19 #include <boost/spirit/home/support/common_terminals.hpp>
|
Chris@16
|
20 #include <boost/spirit/home/qi/detail/attributes.hpp>
|
Chris@16
|
21 #include <boost/spirit/home/support/info.hpp>
|
Chris@16
|
22 #include <boost/spirit/home/support/handles_container.hpp>
|
Chris@101
|
23 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace spirit
|
Chris@16
|
26 {
|
Chris@16
|
27 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
28 // Enablers
|
Chris@16
|
29 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
30 template <>
|
Chris@16
|
31 struct use_directive<qi::domain, tag::lexeme> // enables lexeme
|
Chris@16
|
32 : mpl::true_ {};
|
Chris@16
|
33 }}
|
Chris@16
|
34
|
Chris@16
|
35 namespace boost { namespace spirit { namespace qi
|
Chris@16
|
36 {
|
Chris@16
|
37 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
|
Chris@16
|
38 using spirit::lexeme;
|
Chris@16
|
39 #endif
|
Chris@16
|
40 using spirit::lexeme_type;
|
Chris@16
|
41
|
Chris@16
|
42 template <typename Subject>
|
Chris@16
|
43 struct lexeme_directive : unary_parser<lexeme_directive<Subject> >
|
Chris@16
|
44 {
|
Chris@16
|
45 typedef Subject subject_type;
|
Chris@16
|
46 lexeme_directive(Subject const& subject_)
|
Chris@16
|
47 : subject(subject_) {}
|
Chris@16
|
48
|
Chris@16
|
49 template <typename Context, typename Iterator>
|
Chris@16
|
50 struct attribute
|
Chris@16
|
51 {
|
Chris@16
|
52 typedef typename
|
Chris@16
|
53 traits::attribute_of<subject_type, Context, Iterator>::type
|
Chris@16
|
54 type;
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 template <typename Iterator, typename Context
|
Chris@16
|
58 , typename Skipper, typename Attribute>
|
Chris@101
|
59 typename disable_if<detail::is_unused_skipper<Skipper>, bool>::type
|
Chris@101
|
60 parse(Iterator& first, Iterator const& last
|
Chris@16
|
61 , Context& context, Skipper const& skipper
|
Chris@16
|
62 , Attribute& attr_) const
|
Chris@16
|
63 {
|
Chris@16
|
64 qi::skip_over(first, last, skipper);
|
Chris@16
|
65 return subject.parse(first, last, context
|
Chris@16
|
66 , detail::unused_skipper<Skipper>(skipper), attr_);
|
Chris@16
|
67 }
|
Chris@101
|
68 template <typename Iterator, typename Context
|
Chris@101
|
69 , typename Skipper, typename Attribute>
|
Chris@101
|
70 typename enable_if<detail::is_unused_skipper<Skipper>, bool>::type
|
Chris@101
|
71 parse(Iterator& first, Iterator const& last
|
Chris@101
|
72 , Context& context, Skipper const& skipper
|
Chris@101
|
73 , Attribute& attr_) const
|
Chris@101
|
74 {
|
Chris@101
|
75 // no need to pre-skip if skipper is unused
|
Chris@101
|
76 //- qi::skip_over(first, last, skipper);
|
Chris@101
|
77 return subject.parse(first, last, context
|
Chris@101
|
78 , skipper, attr_);
|
Chris@101
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 template <typename Context>
|
Chris@16
|
82 info what(Context& context) const
|
Chris@16
|
83 {
|
Chris@16
|
84 return info("lexeme", subject.what(context));
|
Chris@16
|
85
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 Subject subject;
|
Chris@16
|
89 };
|
Chris@16
|
90
|
Chris@16
|
91 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
92 // Parser generators: make_xxx function (objects)
|
Chris@16
|
93 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
94 template <typename Subject, typename Modifiers>
|
Chris@16
|
95 struct make_directive<tag::lexeme, Subject, Modifiers>
|
Chris@16
|
96 {
|
Chris@16
|
97 typedef lexeme_directive<Subject> result_type;
|
Chris@16
|
98 result_type operator()(unused_type, Subject const& subject, unused_type) const
|
Chris@16
|
99 {
|
Chris@16
|
100 return result_type(subject);
|
Chris@16
|
101 }
|
Chris@16
|
102 };
|
Chris@16
|
103 }}}
|
Chris@16
|
104
|
Chris@16
|
105 namespace boost { namespace spirit { namespace traits
|
Chris@16
|
106 {
|
Chris@16
|
107 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
108 template <typename Subject>
|
Chris@16
|
109 struct has_semantic_action<qi::lexeme_directive<Subject> >
|
Chris@16
|
110 : unary_has_semantic_action<Subject> {};
|
Chris@16
|
111
|
Chris@16
|
112 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
113 template <typename Subject, typename Attribute, typename Context
|
Chris@16
|
114 , typename Iterator>
|
Chris@16
|
115 struct handles_container<qi::lexeme_directive<Subject>, Attribute
|
Chris@16
|
116 , Context, Iterator>
|
Chris@16
|
117 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
|
Chris@16
|
118 }}}
|
Chris@16
|
119
|
Chris@16
|
120 #endif
|