36 void add(
unsigned col, T_Char c)
override;
37 void setLine(
unsigned line)
override;
38 void setSource(std::string_view src)
override;
44 { m_1stFits = states; m_isFinal = isFinal; m_1stFitN = stateN; }
46 { m_stateRecs = stateRecs; m_gotoN = gotoN; }
51 typedef std::vector<T_Char> C_ChStack;
52 typedef std::vector<C_SourcePos> C_PosStack;
56 std::string_view m_OldSrc;
57 std::string_view m_CurSrc;
63 C_ChStack m_ReadCh, m_UnreadCh;
64 C_PosStack m_ReadPos, m_UnreadPos;
67 const C_StateRec *m_stateRecs {
nullptr};
68 const T_Input *m_gotoN {
nullptr};
69 const T_State *m_1stFits {
nullptr};
75 void addToken(
T_LexID token, C_SourcePos pos, I_LexAttr *unownedAttr);
76 void resetReadState();
77 void shrinkReadSize(
size_t newSize);
92 for (
bool consumed =
false;;)
95 if (m_UnreadCh.empty())
101 m_ReadCh.emplace_back(c);
102 m_ReadPos.emplace_back(m_CurSrc, m_CurLine, col);
107 m_ReadPos.emplace_back(m_UnreadPos.back());
108 m_UnreadPos.pop_back();
109 m_ReadCh.emplace_back(m_UnreadCh.back());
110 m_UnreadCh.pop_back();
114 const T_LexID idTop = C_Traits::id(m_ReadCh.back());
117 const auto gotos = m_stateRecs[m_CurState].m_goto;
120 for (
int i = m_gotoN[m_CurState]; i > 0;)
122 const auto pt = gotos[--i];
123 if (pt.m_inputLB <= idTop)
125 nextState = pt.m_nextState;
126 if (std::numeric_limits<T_State>::max() != nextState)
134 m_CurState = nextState;
135 if (
auto pAction = m_stateRecs[nextState].m_action)
138 for (
size_t i = 0; i < m_1stFitN; ++i)
139 if (m_1stFits[i] == nextState &&
140 (!m_isFinal[i] || (*m_isFinal[i])(m_ReadCh.data(), m_ReadCh.size())))
143 const C_ActionRet ret = (*pAction)(m_ReadCh.data(), m_ReadCh.size());
144 return addToken(ret.
m_id, m_ReadPos.front(), ret.
m_pAttr);
146 m_LastSuccess =
int(m_ReadCh.size());
154 const auto pos = m_ReadPos.front();
157 if (m_LastSuccess < 0)
161 token = C_Traits::id(m_ReadCh.front());
167 for (
auto i: m_ReadCh)
168 switch (
auto id = C_Traits::id(i))
176 RUNTIME_ERROR(
"Run out of scanner at {}({},{},{}) |{}|", pos.m_Source, pos.m_Line, pos.m_Col, m_CurState, buf);
181 shrinkReadSize(
size_t(m_LastSuccess));
182 const C_ActionRet ret = (*m_pAction)(m_ReadCh.data(), m_ReadCh.size());
188 addToken(token, pos, attr);
210void C_ScannerImpl<T_Input,T_State,T_Char,C_Traits>::resetReadState()