File indexing completed on 2025-01-31 10:02:05
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_SPIRIT_SYMBOLS_HPP
0009 #define BOOST_SPIRIT_SYMBOLS_HPP
0010
0011
0012 #include <string>
0013
0014 #include <boost/ref.hpp>
0015
0016 #include <boost/spirit/home/classic/namespace.hpp>
0017 #include <boost/spirit/home/classic/core/parser.hpp>
0018 #include <boost/spirit/home/classic/core/composite/directives.hpp>
0019
0020 #include <boost/spirit/home/classic/symbols/symbols_fwd.hpp>
0021
0022
0023
0024 namespace boost { namespace spirit {
0025
0026 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 template <typename T, typename CharT, typename SetT>
0071 class symbols
0072 : private SetT
0073 , public parser<symbols<T, CharT, SetT> >
0074 {
0075 public:
0076
0077 typedef parser<symbols<T, CharT, SetT> > parser_base_t;
0078 typedef symbols<T, CharT, SetT> self_t;
0079 typedef self_t const& embed_t;
0080 typedef T symbol_data_t;
0081 typedef boost::reference_wrapper<T> symbol_ref_t;
0082
0083 symbols();
0084 symbols(symbols const& other);
0085 ~symbols();
0086
0087 symbols&
0088 operator=(symbols const& other);
0089
0090 symbol_inserter<T, SetT> const&
0091 operator=(CharT const* str);
0092
0093 template <typename ScannerT>
0094 struct result
0095 {
0096 typedef typename match_result<ScannerT, symbol_ref_t>::type type;
0097 };
0098
0099 template <typename ScannerT>
0100 typename parser_result<self_t, ScannerT>::type
0101 parse_main(ScannerT const& scan) const
0102 {
0103 typedef typename ScannerT::iterator_t iterator_t;
0104 iterator_t first = scan.first;
0105 typename SetT::search_info result = SetT::find(scan);
0106
0107 if (result.data)
0108 return scan.
0109 create_match(
0110 result.length,
0111 symbol_ref_t(*result.data),
0112 first,
0113 scan.first);
0114 else
0115 return scan.no_match();
0116 }
0117
0118 template <typename ScannerT>
0119 typename parser_result<self_t, ScannerT>::type
0120 parse(ScannerT const& scan) const
0121 {
0122 typedef typename parser_result<self_t, ScannerT>::type result_t;
0123 return impl::implicit_lexeme_parse<result_t>
0124 (*this, scan, scan);
0125 }
0126
0127 template < typename ScannerT >
0128 T* find(ScannerT const& scan) const
0129 { return SetT::find(scan).data; }
0130
0131 symbol_inserter<T, SetT> const add;
0132 };
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 template <typename T, typename CharT, typename SetT>
0152 T* add(symbols<T, CharT, SetT>& table, CharT const* sym, T const& data = T());
0153
0154 template <typename T, typename CharT, typename SetT>
0155 T* find(symbols<T, CharT, SetT> const& table, CharT const* sym);
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 template <typename T, typename SetT>
0179 class symbol_inserter
0180 {
0181 public:
0182
0183 symbol_inserter(SetT& set_)
0184 : set(set_) {}
0185
0186 typedef symbol_inserter const & result_type;
0187
0188 template <typename IteratorT>
0189 symbol_inserter const&
0190 operator()(IteratorT first, IteratorT const& last, T const& data = T()) const
0191 {
0192 set.add(first, last, data);
0193 return *this;
0194 }
0195
0196 template <typename CharT>
0197 symbol_inserter const&
0198 operator()(CharT const* str, T const& data = T()) const
0199 {
0200 CharT const* last = str;
0201 while (*last)
0202 last++;
0203 set.add(str, last, data);
0204 return *this;
0205 }
0206
0207 template <typename CharT>
0208 symbol_inserter const&
0209 operator,(CharT const* str) const
0210 {
0211 CharT const* last = str;
0212 while (*last)
0213 last++;
0214 set.add(str, last, T());
0215 return *this;
0216 }
0217
0218 private:
0219
0220 SetT& set;
0221 };
0222
0223
0224 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0225
0226 }}
0227
0228 #include <boost/spirit/home/classic/symbols/impl/symbols.ipp>
0229 #endif