1 // class template regex -*- C++ -*-
3 // Copyright (C) 2013-2015 Free Software Foundation, Inc.
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)
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.
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.
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/>.
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}
31 namespace std _GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
38 * @addtogroup regex-detail
45 /// Token types returned from the scanner.
53 _S_token_subexpr_begin,
54 _S_token_subexpr_no_group_begin,
55 _S_token_subexpr_lookahead_begin, // neg if _M_value[0] == 'n'
57 _S_token_bracket_begin,
58 _S_token_bracket_neg_begin,
60 _S_token_interval_begin,
61 _S_token_interval_end,
62 _S_token_quoted_class,
63 _S_token_char_class_name,
65 _S_token_equiv_class_name,
72 _S_token_word_bound, // neg if _M_value[0] == 'n'
80 typedef regex_constants::syntax_option_type _FlagT;
90 _ScannerBase(_FlagT __flags)
91 : _M_state(_S_state_normal),
93 _M_escape_tbl(_M_is_ecma()
96 _M_spec_char(_M_is_ecma()
98 : _M_flags & regex_constants::basic
100 : _M_flags & regex_constants::extended
101 ? _M_extended_spec_char
102 : _M_flags & regex_constants::grep
104 : _M_flags & regex_constants::egrep
106 : _M_flags & regex_constants::awk
107 ? _M_extended_spec_char
109 _M_at_bracket_start(false)
110 { __glibcxx_assert(_M_spec_char); }
114 _M_find_escape(char __c)
116 auto __it = _M_escape_tbl;
117 for (; __it->first != '\0'; ++__it)
118 if (__it->first == __c)
119 return &__it->second;
125 { return _M_flags & regex_constants::ECMAScript; }
129 { return _M_flags & (regex_constants::basic | regex_constants::grep); }
132 _M_is_extended() const
134 return _M_flags & (regex_constants::extended
135 | regex_constants::egrep
136 | regex_constants::awk);
141 { return _M_flags & (regex_constants::grep | regex_constants::egrep); }
145 { return _M_flags & regex_constants::awk; }
148 // TODO: Make them static in the next abi change.
149 const std::pair<char, _TokenT> _M_token_tbl[9] =
151 {'^', _S_token_line_begin},
152 {'$', _S_token_line_end},
153 {'.', _S_token_anychar},
154 {'*', _S_token_closure0},
155 {'+', _S_token_closure1},
158 {'\n', _S_token_or}, // grep and egrep
161 const std::pair<char, char> _M_ecma_escape_tbl[8] =
172 const std::pair<char, char> _M_awk_escape_tbl[11] =
186 const char* _M_ecma_spec_char = "^$\\.*+?()[]{}|";
187 const char* _M_basic_spec_char = ".[\\*^$";
188 const char* _M_extended_spec_char = ".[\\()*+?{|^$";
193 const std::pair<char, char>* _M_escape_tbl;
194 const char* _M_spec_char;
195 bool _M_at_bracket_start;
199 * @brief Scans an input range for regex tokens.
201 * The %_Scanner class interprets the regular expression pattern in
202 * the input range passed to its constructor as a sequence of parse
203 * tokens passed to the regular expression compiler. The sequence
204 * of tokens provided depends on the flag settings passed to the
205 * constructor: different regular expression grammars will interpret
206 * the same input pattern in syntactically different ways.
208 template<typename _CharT>
210 : public _ScannerBase
213 typedef const _CharT* _IterT;
214 typedef std::basic_string<_CharT> _StringT;
215 typedef regex_constants::syntax_option_type _FlagT;
216 typedef const std::ctype<_CharT> _CtypeT;
218 _Scanner(_IterT __begin, _IterT __end,
219 _FlagT __flags, std::locale __loc);
232 #ifdef _GLIBCXX_DEBUG
234 _M_print(std::ostream&);
242 _M_scan_in_bracket();
248 _M_eat_escape_ecma();
251 _M_eat_escape_posix();
263 void (_Scanner::* _M_eat_escape)();
267 _GLIBCXX_END_NAMESPACE_VERSION
268 } // namespace __detail
271 #include <bits/regex_scanner.tcc>