]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 1998-2003 Joel de Guzman | |
3 | http://spirit.sourceforge.net/ | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | =============================================================================*/ | |
8 | #if !defined(BOOST_SPIRIT_RULE_ALIAS_HPP) | |
9 | #define BOOST_SPIRIT_RULE_ALIAS_HPP | |
10 | ||
11 | #include <boost/spirit/home/classic/namespace.hpp> | |
12 | #include <boost/spirit/home/classic/core/parser.hpp> | |
13 | ||
14 | namespace boost { namespace spirit { | |
15 | ||
16 | BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////// | |
19 | // | |
20 | // rule_alias class | |
21 | // | |
22 | /////////////////////////////////////////////////////////////////////////// | |
23 | template <typename ParserT> | |
24 | class rule_alias : | |
25 | public parser<rule_alias<ParserT> > | |
26 | { | |
27 | public: | |
28 | ||
29 | typedef rule_alias<ParserT> self_t; | |
30 | ||
31 | template <typename ScannerT> | |
32 | struct result | |
33 | { | |
34 | typedef typename parser_result<ParserT, ScannerT>::type type; | |
35 | }; | |
36 | ||
37 | rule_alias() | |
38 | : ptr(0) {} | |
39 | ||
40 | rule_alias(ParserT const& p) | |
41 | : ptr(&p) {} | |
42 | ||
43 | rule_alias& | |
44 | operator=(ParserT const& p) | |
45 | { | |
46 | ptr = &p; | |
47 | return *this; | |
48 | } | |
49 | ||
50 | template <typename ScannerT> | |
51 | typename parser_result<ParserT, ScannerT>::type | |
52 | parse(ScannerT const& scan) const | |
53 | { | |
54 | if (ptr) | |
55 | return ptr->parse(scan); | |
56 | else | |
57 | return scan.no_match(); | |
58 | } | |
59 | ||
60 | ParserT const& | |
61 | get() const | |
62 | { | |
63 | BOOST_ASSERT(ptr != 0); | |
64 | return *ptr; | |
65 | } | |
66 | ||
67 | private: | |
68 | ||
69 | ParserT const* ptr; // hold it by pointer | |
70 | }; | |
71 | ||
72 | BOOST_SPIRIT_CLASSIC_NAMESPACE_END | |
73 | ||
74 | }} // namespace BOOST_SPIRIT_CLASSIC_NS | |
75 | ||
76 | #endif |