31 namespace std _GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
43 case _S_opcode_alternative:
44 ostr <<
"alt next=" << _M_next <<
" alt=" << _M_alt;
46 case _S_opcode_subexpr_begin:
47 ostr <<
"subexpr begin next=" << _M_next <<
" index=" << _M_subexpr;
49 case _S_opcode_subexpr_end:
50 ostr <<
"subexpr end next=" << _M_next <<
" index=" << _M_subexpr;
52 case _S_opcode_backref:
53 ostr <<
"backref next=" << _M_next <<
" index=" << _M_backref_index;
56 ostr <<
"match next=" << _M_next;
58 case _S_opcode_accept:
59 ostr <<
"accept next=" << _M_next;
62 ostr <<
"unknown next=" << _M_next;
70 _State_base::_M_dot(
std::ostream& __ostr, _StateIdT __id)
const
74 case _S_opcode_alternative:
75 __ostr << __id <<
" [label=\"" << __id <<
"\\nALT\"];\n"
76 << __id <<
" -> " << _M_next
77 <<
" [label=\"epsilon\", tailport=\"s\"];\n"
78 << __id <<
" -> " << _M_alt
79 <<
" [label=\"epsilon\", tailport=\"n\"];\n";
81 case _S_opcode_backref:
82 __ostr << __id <<
" [label=\"" << __id <<
"\\nBACKREF "
83 << _M_subexpr <<
"\"];\n"
84 << __id <<
" -> " << _M_next <<
" [label=\"<match>\"];\n";
86 case _S_opcode_line_begin_assertion:
87 __ostr << __id <<
" [label=\"" << __id <<
"\\nLINE_BEGIN \"];\n"
88 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
90 case _S_opcode_line_end_assertion:
91 __ostr << __id <<
" [label=\"" << __id <<
"\\nLINE_END \"];\n"
92 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
94 case _S_opcode_word_boundary:
95 __ostr << __id <<
" [label=\"" << __id <<
"\\nWORD_BOUNDRY "
97 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
99 case _S_opcode_subexpr_lookahead:
100 __ostr << __id <<
" [label=\"" << __id <<
"\\nLOOK_AHEAD\"];\n"
101 << __id <<
" -> " << _M_next
102 <<
" [label=\"epsilon\", tailport=\"s\"];\n"
103 << __id <<
" -> " << _M_alt
104 <<
" [label=\"<assert>\", tailport=\"n\"];\n";
106 case _S_opcode_subexpr_begin:
107 __ostr << __id <<
" [label=\"" << __id <<
"\\nSBEGIN "
108 << _M_subexpr <<
"\"];\n"
109 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
111 case _S_opcode_subexpr_end:
112 __ostr << __id <<
" [label=\"" << __id <<
"\\nSEND "
113 << _M_subexpr <<
"\"];\n"
114 << __id <<
" -> " << _M_next <<
" [label=\"epsilon\"];\n";
116 case _S_opcode_dummy:
118 case _S_opcode_match:
119 __ostr << __id <<
" [label=\"" << __id <<
"\\nMATCH\"];\n"
120 << __id <<
" -> " << _M_next <<
" [label=\"<match>\"];\n";
122 case _S_opcode_accept:
123 __ostr << __id <<
" [label=\"" << __id <<
"\\nACC\"];\n" ;
126 _GLIBCXX_DEBUG_ASSERT(
false);
132 template<
typename _TraitsT>
136 __ostr <<
"digraph _Nfa {\n"
138 for (
size_t __i = 0; __i < this->
size(); ++__i)
139 (*
this)[__i]._M_dot(__ostr, __i);
145 template<
typename _TraitsT>
147 _NFA<_TraitsT>::_M_insert_backref(
size_t __index)
156 if (__index >= _M_subexpr_count)
158 for (
auto __it : this->_M_paren_stack)
161 this->_M_has_backref =
true;
162 _StateT __tmp(_S_opcode_backref);
163 __tmp._M_backref_index = __index;
164 return _M_insert_state(std::move(__tmp));
167 template<
typename _TraitsT>
169 _NFA<_TraitsT>::_M_eliminate_dummy()
171 for (
auto& __it : *
this)
173 while (__it._M_next >= 0 && (*
this)[__it._M_next]._M_opcode
175 __it._M_next = (*this)[__it._M_next]._M_next;
176 if (__it._M_opcode == _S_opcode_alternative
177 || __it._M_opcode == _S_opcode_subexpr_lookahead)
178 while (__it._M_alt >= 0 && (*
this)[__it._M_alt]._M_opcode
180 __it._M_alt = (*this)[__it._M_alt]._M_next;
185 template<
typename _TraitsT>
187 _StateSeq<_TraitsT>::_M_clone()
191 __stack.
push(_M_start);
192 while (!__stack.empty())
194 auto __u = __stack.
top();
196 auto __dup = _M_nfa[__u];
197 auto __id = _M_nfa._M_insert_state(__dup);
201 if (__m.
count(__dup._M_next) == 0)
202 __stack.
push(__dup._M_next);
203 if (__dup._M_opcode == _S_opcode_alternative
204 || __dup._M_opcode == _S_opcode_subexpr_lookahead)
205 if (__m.
count(__dup._M_alt) == 0)
206 __stack.
push(__dup._M_alt);
208 for (
auto __it : __m)
210 auto& __ref = _M_nfa[__it.second];
211 if (__ref._M_next != -1)
213 _GLIBCXX_DEBUG_ASSERT(__m.count(__ref._M_next));
214 __ref._M_next = __m[__ref._M_next];
216 if (__ref._M_opcode == _S_opcode_alternative
217 || __ref._M_opcode == _S_opcode_subexpr_lookahead)
218 if (__ref._M_alt != -1)
220 _GLIBCXX_DEBUG_ASSERT(__m.count(__ref._M_alt));
221 __ref._M_alt = __m[__ref._M_alt];
224 return _StateSeq(_M_nfa, __m[_M_start], __m[_M_end]);
227 _GLIBCXX_END_NAMESPACE_VERSION
constexpr size_t size() const noexcept
Returns the total number of bits.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
void pop()
Removes first element.
constexpr error_type error_backref(_S_error_backref)
void push(const value_type &__x)
Add data to the top of the stack.
A standard container giving FILO behavior.