35namespace std _GLIBCXX_VISIBILITY(default)
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
47 case _S_opcode_alternative:
48 case _S_opcode_repeat:
49 __ostr <<
"alt next=" << _M_next <<
" alt=" << _M_alt;
51 case _S_opcode_subexpr_begin:
52 __ostr <<
"subexpr begin next=" << _M_next <<
" index=" << _M_subexpr;
54 case _S_opcode_subexpr_end:
55 __ostr <<
"subexpr end next=" << _M_next <<
" index=" << _M_subexpr;
57 case _S_opcode_backref:
58 __ostr <<
"backref next=" << _M_next <<
" index=" << _M_backref_index;
61 __ostr <<
"match next=" << _M_next;
63 case _S_opcode_accept:
64 __ostr <<
"accept next=" << _M_next;
67 __ostr <<
"unknown next=" << _M_next;
75 _State_base::_M_dot(
std::ostream& __ostr, _StateIdT __id)
const
79 case _S_opcode_alternative:
80 case _S_opcode_repeat:
81 __ostr << __id <<
" [label=\"" << __id <<
"\\nALT\"];\n"
82 << __id <<
" -> " << _M_next
83 <<
" [label=\"next\", tailport=\"s\"];\n"
84 << __id <<
" -> " << _M_alt
85 <<
" [label=\"alt\", tailport=\"n\"];\n";
87 case _S_opcode_backref:
88 __ostr << __id <<
" [label=\"" << __id <<
"\\nBACKREF "
89 << _M_subexpr <<
"\"];\n"
90 << __id <<
" -> " << _M_next <<
" [label=\"<match>\"];\n";
92 case _S_opcode_line_begin_assertion:
93 __ostr << __id <<
" [label=\"" << __id <<
"\\nLINE_BEGIN \"];\n"
94 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
96 case _S_opcode_line_end_assertion:
97 __ostr << __id <<
" [label=\"" << __id <<
"\\nLINE_END \"];\n"
98 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
100 case _S_opcode_word_boundary:
101 __ostr << __id <<
" [label=\"" << __id <<
"\\nWORD_BOUNDRY "
102 << _M_neg <<
"\"];\n"
103 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
105 case _S_opcode_subexpr_lookahead:
106 __ostr << __id <<
" [label=\"" << __id <<
"\\nLOOK_AHEAD\"];\n"
107 << __id <<
" -> " << _M_next
108 <<
" [label=\"epsilon\", tailport=\"s\"];\n"
109 << __id <<
" -> " << _M_alt
110 <<
" [label=\"<assert>\", tailport=\"n\"];\n";
112 case _S_opcode_subexpr_begin:
113 __ostr << __id <<
" [label=\"" << __id <<
"\\nSBEGIN "
114 << _M_subexpr <<
"\"];\n"
115 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
117 case _S_opcode_subexpr_end:
118 __ostr << __id <<
" [label=\"" << __id <<
"\\nSEND "
119 << _M_subexpr <<
"\"];\n"
120 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
122 case _S_opcode_dummy:
124 case _S_opcode_match:
125 __ostr << __id <<
" [label=\"" << __id <<
"\\nMATCH\"];\n"
126 << __id <<
" -> " << _M_next <<
" [label=\"<match>\"];\n";
128 case _S_opcode_accept:
129 __ostr << __id <<
" [label=\"" << __id <<
"\\nACC\"];\n" ;
132 _GLIBCXX_DEBUG_ASSERT(
false);
138 template<
typename _TraitsT>
142 __ostr <<
"digraph _Nfa {\n"
144 for (
size_t __i = 0; __i < this->
size(); ++__i)
145 (*
this)[__i]._M_dot(__ostr, __i);
151 template<
typename _TraitsT>
153 _NFA<_TraitsT>::_M_insert_backref(
size_t __index)
157 "Unexpected back-reference in polynomial mode.");
165 if (__index >= _M_subexpr_count)
168 "Back-reference index exceeds current sub-expression count.");
169 for (
auto __it : this->_M_paren_stack)
173 "Back-reference referred to an opened sub-expression.");
174 this->_M_has_backref =
true;
175 _StateT __tmp(_S_opcode_backref);
176 __tmp._M_backref_index = __index;
177 return _M_insert_state(
std::move(__tmp));
180 template<
typename _TraitsT>
182 _NFA<_TraitsT>::_M_eliminate_dummy()
184 for (
auto& __it : *
this)
186 while (__it._M_next >= 0 && (*
this)[__it._M_next]._M_opcode()
188 __it._M_next = (*this)[__it._M_next]._M_next;
189 if (__it._M_has_alt())
190 while (__it._M_alt >= 0 && (*
this)[__it._M_alt]._M_opcode()
192 __it._M_alt = (*this)[__it._M_alt]._M_next;
197 template<
typename _TraitsT>
199 _StateSeq<_TraitsT>::_M_clone()
201 _GLIBCXX_STD_C::map<_StateIdT, _StateIdT> __m;
202 std::stack<_StateIdT, _GLIBCXX_STD_C::deque<_StateIdT>> __stack;
203 __stack.
push(_M_start);
204 while (!__stack.
empty())
206 auto __u = __stack.
top();
208 auto __dup = _M_nfa[__u];
210 auto __id = _M_nfa._M_insert_state(
std::move(__dup));
212 if (__dup._M_has_alt())
213 if (__dup._M_alt != _S_invalid_state_id
214 && __m.count(__dup._M_alt) == 0)
215 __stack.
push(__dup._M_alt);
218 if (__dup._M_next != _S_invalid_state_id
219 && __m.count(__dup._M_next) == 0)
220 __stack.
push(__dup._M_next);
222 for (
auto __it : __m)
224 auto __v = __it.second;
225 auto& __ref = _M_nfa[__v];
226 if (__ref._M_next != _S_invalid_state_id)
227 __ref._M_next = __m.find(__ref._M_next)->second;
228 if (__ref._M_has_alt() && __ref._M_alt != _S_invalid_state_id)
229 __ref._M_alt = __m.find(__ref._M_alt)->second;
231 return _StateSeq(_M_nfa, __m[_M_start], __m[_M_end]);
235_GLIBCXX_END_NAMESPACE_VERSION
basic_ostream< char > ostream
Base class for char output streams.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
ISO C++ entities toplevel namespace is std.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
Implementation details not part of the namespace std interface.
constexpr syntax_option_type __polynomial
constexpr error_type error_backref(_S_error_backref)
constexpr error_type error_complexity(_S_error_complexity)
Describes a sequence of one or more _State, its current start and end(s). This structure contains fra...
void pop()
Removes first element.
void push(const value_type &__x)
Add data to the top of the stack.