libstdc++
regex_scanner.h
Go to the documentation of this file.
1 // class template regex -*- C++ -*-
2 
3 // Copyright (C) 2013-2014 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /**
26  * @file bits/regex_scanner.h
27  * This is an internal header file, included by other library headers.
28  * Do not attempt to use it directly. @headername{regex}
29  */
30 
31 namespace std _GLIBCXX_VISIBILITY(default)
32 {
33 namespace __detail
34 {
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
36 
37  /**
38  * @addtogroup regex-detail
39  * @{
40  */
41 
42  /**
43  * @brief struct _Scanner. Scans an input range for regex tokens.
44  *
45  * The %_Scanner class interprets the regular expression pattern in
46  * the input range passed to its constructor as a sequence of parse
47  * tokens passed to the regular expression compiler. The sequence
48  * of tokens provided depends on the flag settings passed to the
49  * constructor: different regular expression grammars will interpret
50  * the same input pattern in syntactically different ways.
51  */
52  template<typename _FwdIter>
53  class _Scanner
54  {
55  public:
56  typedef typename std::iterator_traits<_FwdIter>::value_type _CharT;
59  typedef const std::ctype<_CharT> _CtypeT;
60 
61  /// Token types returned from the scanner.
62  enum _TokenT
63  {
64  _S_token_anychar,
65  _S_token_ord_char,
66  _S_token_oct_num,
67  _S_token_hex_num,
68  _S_token_backref,
69  _S_token_subexpr_begin,
70  _S_token_subexpr_no_group_begin,
71  _S_token_subexpr_lookahead_begin, // neg if _M_value[0] == 'n'
72  _S_token_subexpr_end,
73  _S_token_bracket_begin,
74  _S_token_bracket_neg_begin,
75  _S_token_bracket_end,
76  _S_token_interval_begin,
77  _S_token_interval_end,
78  _S_token_quoted_class,
79  _S_token_char_class_name,
80  _S_token_collsymbol,
81  _S_token_equiv_class_name,
82  _S_token_opt,
83  _S_token_or,
84  _S_token_closure0,
85  _S_token_closure1,
86  _S_token_ungreedy,
87  _S_token_line_begin,
88  _S_token_line_end,
89  _S_token_word_bound, // neg if _M_value[0] == 'n'
90  _S_token_comma,
91  _S_token_dup_count,
92  _S_token_eof,
93  _S_token_unknown
94  };
95 
96  _Scanner(_FwdIter __begin, _FwdIter __end,
97  _FlagT __flags, std::locale __loc);
98 
99  void
100  _M_advance();
101 
102  _TokenT
103  _M_get_token() const
104  { return _M_token; }
105 
106  const _StringT&
107  _M_get_value() const
108  { return _M_value; }
109 
110 #ifdef _GLIBCXX_DEBUG
111  std::ostream&
112  _M_print(std::ostream&);
113 #endif
114 
115  private:
116  enum _StateT
117  {
118  _S_state_normal,
119  _S_state_in_brace,
120  _S_state_in_bracket,
121  };
122 
123  void
124  _M_scan_normal();
125 
126  void
127  _M_scan_in_bracket();
128 
129  void
130  _M_scan_in_brace();
131 
132  void
133  _M_eat_escape_ecma();
134 
135  void
136  _M_eat_escape_posix();
137 
138  void
139  _M_eat_escape_awk();
140 
141  void
142  _M_eat_class(char);
143 
144  constexpr bool
145  _M_is_ecma()
146  { return _M_flags & regex_constants::ECMAScript; }
147 
148  constexpr bool
149  _M_is_basic()
150  { return _M_flags & (regex_constants::basic | regex_constants::grep); }
151 
152  constexpr bool
153  _M_is_extended()
154  {
155  return _M_flags & (regex_constants::extended
158  }
159 
160  constexpr bool
161  _M_is_grep()
162  { return _M_flags & (regex_constants::grep | regex_constants::egrep); }
163 
164  constexpr bool
165  _M_is_awk()
166  { return _M_flags & regex_constants::awk; }
167 
168  _StateT _M_state;
169  _FwdIter _M_current;
170  _FwdIter _M_end;
171  _FlagT _M_flags;
172  _CtypeT& _M_ctype;
173  _TokenT _M_token;
174  _StringT _M_value;
175  bool _M_at_bracket_start;
176  public:
177  // FIXME: make them static when this file is stable.
178  const std::map<char, _TokenT> _M_token_map;
179  const std::map<char, char> _M_ecma_escape_map;
180  const std::map<char, char> _M_awk_escape_map;
181  const std::set<char> _M_ecma_spec_char;
182  const std::set<char> _M_basic_spec_char;
183  const std::set<char> _M_extended_spec_char;
184 
185  const std::map<char, char>& _M_escape_map;
186  const std::set<char>& _M_spec_char;
187  void (_Scanner::* _M_eat_escape)();
188  };
189 
190  //@} regex-detail
191 _GLIBCXX_END_NAMESPACE_VERSION
192 } // namespace __detail
193 } // namespace std
194 
195 #include <bits/regex_scanner.tcc>
Primary class template ctype facet.This template class defines classification and conversion function...
struct _Scanner. Scans an input range for regex tokens.
Definition: regex_scanner.h:53
Container class for localization functionality.The locale class is first a class wrapper for C librar...
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
_TokenT
Token types returned from the scanner.
Definition: regex_scanner.h:62