1 // class template regex -*- C++ -*-
3 // Copyright (C) 2013-2018 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)
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
38 * @addtogroup regex-detail
45 /// Token types returned from the scanner.
46 enum _TokenT
: unsigned
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'
76 _S_token_bracket_dash
,
77 _S_token_unknown
= -1u
81 typedef regex_constants::syntax_option_type _FlagT
;
91 _ScannerBase(_FlagT __flags
)
92 : _M_state(_S_state_normal
),
94 _M_escape_tbl(_M_is_ecma()
97 _M_spec_char(_M_is_ecma()
99 : _M_flags
& regex_constants::basic
101 : _M_flags
& regex_constants::extended
102 ? _M_extended_spec_char
103 : _M_flags
& regex_constants::grep
105 : _M_flags
& regex_constants::egrep
107 : _M_flags
& regex_constants::awk
108 ? _M_extended_spec_char
110 _M_at_bracket_start(false)
111 { __glibcxx_assert(_M_spec_char
); }
115 _M_find_escape(char __c
)
117 auto __it
= _M_escape_tbl
;
118 for (; __it
->first
!= '\0'; ++__it
)
119 if (__it
->first
== __c
)
120 return &__it
->second
;
126 { return _M_flags
& regex_constants::ECMAScript
; }
130 { return _M_flags
& (regex_constants::basic
| regex_constants::grep
); }
133 _M_is_extended() const
135 return _M_flags
& (regex_constants::extended
136 | regex_constants::egrep
137 | regex_constants::awk
);
142 { return _M_flags
& (regex_constants::grep
| regex_constants::egrep
); }
146 { return _M_flags
& regex_constants::awk
; }
149 // TODO: Make them static in the next abi change.
150 const std::pair
<char, _TokenT
> _M_token_tbl
[9] =
152 {'^', _S_token_line_begin
},
153 {'$', _S_token_line_end
},
154 {'.', _S_token_anychar
},
155 {'*', _S_token_closure0
},
156 {'+', _S_token_closure1
},
159 {'\n', _S_token_or
}, // grep and egrep
162 const std::pair
<char, char> _M_ecma_escape_tbl
[8] =
173 const std::pair
<char, char> _M_awk_escape_tbl
[11] =
187 const char* _M_ecma_spec_char
= "^$\\.*+?()[]{}|";
188 const char* _M_basic_spec_char
= ".[\\*^$";
189 const char* _M_extended_spec_char
= ".[\\()*+?{|^$";
194 const std::pair
<char, char>* _M_escape_tbl
;
195 const char* _M_spec_char
;
196 bool _M_at_bracket_start
;
200 * @brief Scans an input range for regex tokens.
202 * The %_Scanner class interprets the regular expression pattern in
203 * the input range passed to its constructor as a sequence of parse
204 * tokens passed to the regular expression compiler. The sequence
205 * of tokens provided depends on the flag settings passed to the
206 * constructor: different regular expression grammars will interpret
207 * the same input pattern in syntactically different ways.
209 template<typename _CharT
>
211 : public _ScannerBase
214 typedef const _CharT
* _IterT
;
215 typedef std::basic_string
<_CharT
> _StringT
;
216 typedef regex_constants::syntax_option_type _FlagT
;
217 typedef const std::ctype
<_CharT
> _CtypeT
;
219 _Scanner(_IterT __begin
, _IterT __end
,
220 _FlagT __flags
, std::locale __loc
);
233 #ifdef _GLIBCXX_DEBUG
235 _M_print(std::ostream
&);
243 _M_scan_in_bracket();
249 _M_eat_escape_ecma();
252 _M_eat_escape_posix();
264 void (_Scanner::* _M_eat_escape
)();
268 } // namespace __detail
269 _GLIBCXX_END_NAMESPACE_VERSION
272 #include <bits/regex_scanner.tcc>