MatchInfo: store pointer to the accepting state rather than copying its fields
This commit is contained in:
parent
aabb574fea
commit
1af018b103
@ -261,11 +261,9 @@ class <%= @classname %>
|
|||||||
size_t length;
|
size_t length;
|
||||||
size_t delta_row;
|
size_t delta_row;
|
||||||
size_t delta_col;
|
size_t delta_col;
|
||||||
uint token;
|
const(State) * accepting_state;
|
||||||
uint code_id;
|
|
||||||
}
|
}
|
||||||
MatchInfo longest_match_info;
|
MatchInfo longest_match_info;
|
||||||
longest_match_info.token = _TOKEN_COUNT;
|
|
||||||
MatchInfo attempt_match_info;
|
MatchInfo attempt_match_info;
|
||||||
uint current_state = modes[m_mode].state_table_offset;
|
uint current_state = modes[m_mode].state_table_offset;
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -297,8 +295,7 @@ class <%= @classname %>
|
|||||||
if ((states[current_state].token != _TOKEN_COUNT) ||
|
if ((states[current_state].token != _TOKEN_COUNT) ||
|
||||||
(states[current_state].code_id != 0xFFFF_FFFFu))
|
(states[current_state].code_id != 0xFFFF_FFFFu))
|
||||||
{
|
{
|
||||||
attempt_match_info.token = states[current_state].token;
|
attempt_match_info.accepting_state = &states[current_state];
|
||||||
attempt_match_info.code_id = states[current_state].code_id;
|
|
||||||
longest_match_info = attempt_match_info;
|
longest_match_info = attempt_match_info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,13 +305,12 @@ class <%= @classname %>
|
|||||||
lt.token = TOKEN_0EOF;
|
lt.token = TOKEN_0EOF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!lex_continue)
|
if (!lex_continue && (longest_match_info.accepting_state != null))
|
||||||
{
|
{
|
||||||
bool pattern_accepted = false;
|
uint token_to_accept = longest_match_info.accepting_state.token;
|
||||||
uint token_to_accept = longest_match_info.token;
|
if (longest_match_info.accepting_state.code_id != 0xFFFF_FFFFu)
|
||||||
if (longest_match_info.code_id != 0xFFFF_FFFFu)
|
|
||||||
{
|
{
|
||||||
uint user_code_token = user_code(longest_match_info.code_id, m_input[m_input_position..(m_input_position + longest_match_info.length)], <);
|
uint user_code_token = user_code(longest_match_info.accepting_state.code_id, m_input[m_input_position..(m_input_position + longest_match_info.length)], <);
|
||||||
/* A return of _TOKEN_COUNT from user_code() means
|
/* A return of _TOKEN_COUNT from user_code() means
|
||||||
* that the user code did not explicitly return a
|
* that the user code did not explicitly return a
|
||||||
* token. So only override the token to return if the
|
* token. So only override the token to return if the
|
||||||
@ -323,25 +319,22 @@ class <%= @classname %>
|
|||||||
{
|
{
|
||||||
token_to_accept = user_code_token;
|
token_to_accept = user_code_token;
|
||||||
}
|
}
|
||||||
pattern_accepted = true;
|
|
||||||
}
|
}
|
||||||
if (pattern_accepted || (token_to_accept != _TOKEN_COUNT))
|
|
||||||
|
/* Update the input position tracking. */
|
||||||
|
m_input_position += longest_match_info.length;
|
||||||
|
m_input_row += longest_match_info.delta_row;
|
||||||
|
if (longest_match_info.delta_row != 0u)
|
||||||
{
|
{
|
||||||
/* Update the input position tracking. */
|
m_input_col = longest_match_info.delta_col;
|
||||||
m_input_position += longest_match_info.length;
|
|
||||||
m_input_row += longest_match_info.delta_row;
|
|
||||||
if (longest_match_info.delta_row != 0u)
|
|
||||||
{
|
|
||||||
m_input_col = longest_match_info.delta_col;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_input_col += longest_match_info.delta_col;
|
|
||||||
}
|
|
||||||
lt.token = token_to_accept;
|
|
||||||
lt.length = longest_match_info.length;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_input_col += longest_match_info.delta_col;
|
||||||
|
}
|
||||||
|
lt.token = token_to_accept;
|
||||||
|
lt.length = longest_match_info.length;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lt;
|
return lt;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user