Skip to content

fix: Add NFA node for 0 repetition case to prevent incorrectly terminating. #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class DeterminizationConfiguration {
return m_lookahead < rhs.m_lookahead;
}

auto child_configuration_with_new_state(TypedNfaState const* new_nfa_state
) const -> DeterminizationConfiguration {
return DeterminizationConfiguration(
new_nfa_state,
m_tag_id_to_reg_ids,
m_history,
m_lookahead
);
}

/**
* Creates a new configuration from the current configuration by replacing the NFA state and
* appending a future tag operation.
Expand Down Expand Up @@ -161,15 +171,16 @@ auto DeterminizationConfiguration<TypedNfaState>::update_reachable_configs(
std::stack<DeterminizationConfiguration>& unexplored_stack
) const -> void {
for (auto const& nfa_spontaneous_transition : m_nfa_state->get_spontaneous_transitions()) {
auto parent_config{*this};
auto child_config{this->child_configuration_with_new_state(
nfa_spontaneous_transition.get_dest_state()
)};
for (auto const tag_op : nfa_spontaneous_transition.get_tag_ops()) {
auto child_config{parent_config.child_configuration_with_new_state_and_tag(
child_config = child_config.child_configuration_with_new_state_and_tag(
nfa_spontaneous_transition.get_dest_state(),
tag_op
)};
parent_config = child_config;
);
}
unexplored_stack.push(parent_config);
unexplored_stack.push(child_config);
}
}

Expand Down
15 changes: 14 additions & 1 deletion tests/test-dfa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TEST_CASE("Test Complex Tagged DFA", "[DFA]") {
test_dfa({var_schema}, expected_serialized_dfa);
}

TEST_CASE("Test Repetition Tagged DFA", "[DFA]") {
TEST_CASE("Test multi-valued tag in tagged DFA", "[DFA]") {
string const var_schema{"capture:([a]+=(?<val>1+),)+"};
string const expected_serialized_dfa{
"0:byte_transitions={a-()->1}\n"
Expand All @@ -156,3 +156,16 @@ TEST_CASE("Test Repetition Tagged DFA", "[DFA]") {
};
test_dfa({var_schema}, expected_serialized_dfa);
}

TEST_CASE("Test integer DFA", "[DFA]") {
string const var_schema{"int:\\-{0,1}\\d+"};
string const expected_serialized_dfa{
"0:byte_transitions={--()->1,0-()->2,1-()->2,2-()->2,3-()->2,4-()->2,5-()->2,6-()->2,7-"
"()->2,8-()->2,9-()->2}\n"
"1:byte_transitions={0-()->2,1-()->2,2-()->2,3-()->2,4-()->2,5-()->2,6-()->2,7-()->2,8-"
"()->2,9-()->2}\n"
"2:accepting_tags={0},accepting_operations={},byte_transitions={0-()->2,1-()->2,2-()->"
"2,3-()->2,4-()->2,5-()->2,6-()->2,7-()->2,8-()->2,9-()->2}\n"
};
test_dfa({var_schema}, expected_serialized_dfa);
}
Loading