Skip to content

Commit

Permalink
Merge branch 'refactor-nfa-to-dfa' into fixed-tagged-dfa
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Jan 7, 2025
2 parents 5d7e53b + 6515cbc commit 49474bb
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 25 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ set(SOURCE_FILES
src/log_surgeon/finite_automata/Dfa.hpp
src/log_surgeon/finite_automata/DfaState.hpp
src/log_surgeon/finite_automata/DfaStatePair.hpp
src/log_surgeon/finite_automata/DfaStateType.hpp
src/log_surgeon/finite_automata/Nfa.hpp
src/log_surgeon/finite_automata/NfaState.hpp
src/log_surgeon/finite_automata/NfaStateType.hpp
src/log_surgeon/finite_automata/RegisterHandler.hpp
src/log_surgeon/finite_automata/StateType.hpp
src/log_surgeon/finite_automata/Tag.hpp
src/log_surgeon/finite_automata/TaggedTransition.hpp
src/log_surgeon/finite_automata/UnicodeIntervalTree.hpp
Expand Down
6 changes: 3 additions & 3 deletions src/log_surgeon/finite_automata/DfaState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#include <type_traits>
#include <vector>

#include <log_surgeon/finite_automata/StateType.hpp>
#include <log_surgeon/Constants.hpp>
#include <log_surgeon/finite_automata/StateType.hpp>
#include <log_surgeon/finite_automata/UnicodeIntervalTree.hpp>

namespace log_surgeon::finite_automata {
template <StateType state_type>
class DfaState;

using DfaByteState = DfaState<StateType::Byte>;
using DfaUtf8State = DfaState<StateType::Utf8>;
using ByteDfaState = DfaState<StateType::Byte>;
using Utf8DfaState = DfaState<StateType::Utf8>;

template <StateType state_type>
class DfaState {
Expand Down
13 changes: 0 additions & 13 deletions src/log_surgeon/finite_automata/DfaStateType.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/log_surgeon/finite_automata/NfaState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class NfaState {
std::vector<NfaState*> m_epsilon_transitions;
std::array<std::vector<NfaState*>, cSizeOfByte> m_bytes_transitions;
// NOTE: We don't need m_tree_transitions for the `stateType ==
// NfaStateType::Byte` case, so we use an empty class (`std::tuple<>`)
// StateType::Byte` case, so we use an empty class (`std::tuple<>`)
// in that case.
std::conditional_t<state_type == StateType::Utf8, Tree, std::tuple<>> m_tree_transitions;
};
Expand All @@ -146,7 +146,7 @@ class RegOpNfaStatePair {

[[nodiscard]] auto is_start() const -> bool { return m_register_operation.is_start(); }

[[nodiscard]] auto get_state() const -> NfaStateTypeTypedDfaState* { return m_nfa_state; }
[[nodiscard]] auto get_state() const -> TypedDfaState* { return m_nfa_state; }

bool operator<(RegOpNfaStatePair const& other) const { return m_nfa_state < other.m_nfa_state; }

Expand Down
2 changes: 1 addition & 1 deletion src/log_surgeon/finite_automata/StateType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstdint>

namespace log_surgeon::finite_automata {
enum class StateType : uint8_t {
enum class StateType : uint8_t {
Byte,
Utf8
};
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set(
../src/log_surgeon/finite_automata/RegexAST.hpp
../src/log_surgeon/finite_automata/Nfa.hpp
../src/log_surgeon/finite_automata/NfaState.hpp
../src/log_surgeon/finite_automata/NfaStateType.hpp
../src/log_surgeon/finite_automata/RegisterHandler.hpp
../src/log_surgeon/finite_automata/StateType.hpp
../src/log_surgeon/finite_automata/Tag.hpp
../src/log_surgeon/finite_automata/TaggedTransition.hpp
../src/log_surgeon/Lalr1Parser.cpp
Expand All @@ -24,7 +24,7 @@ set(
../src/log_surgeon/Token.hpp
)

set(SOURCES_TESTS test-lexer.cpp test-NFA.cpp test-prefix-tree.cpp test-register-handler.cpp test-tag.cpp)
set(SOURCES_TESTS test-lexer.cpp test-nfa.cpp test-prefix-tree.cpp test-register-handler.cpp test-tag.cpp)

add_executable(unit-test ${SOURCES_LOG_SURGEON} ${SOURCES_TESTS})
target_link_libraries(unit-test PRIVATE Catch2::Catch2WithMain log_surgeon::log_surgeon)
Expand Down
4 changes: 2 additions & 2 deletions tests/test-NFA.cpp → tests/test-nfa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using std::stringstream;
using std::vector;

using ByteLexicalRule = log_surgeon::LexicalRule<ByteNfaState>;
using ByteNFA = log_surgeon::finite_automata::Nfa<ByteNfaState>;
using ByteNfa = log_surgeon::finite_automata::Nfa<ByteNfaState>;
using RegexASTCatByte = log_surgeon::finite_automata::RegexASTCat<ByteNfaState>;
using RegexASTCaptureByte = log_surgeon::finite_automata::RegexASTCapture<ByteNfaState>;
using RegexASTGroupByte = log_surgeon::finite_automata::RegexASTGroup<ByteNfaState>;
Expand All @@ -44,7 +44,7 @@ TEST_CASE("Test NFA", "[NFA]") {
auto& capture_rule_ast = dynamic_cast<SchemaVarAST&>(*schema_ast->m_schema_vars[0]);
vector<ByteLexicalRule> rules;
rules.emplace_back(0, std::move(capture_rule_ast.m_regex_ptr));
ByteNFA const nfa{std::move(rules)};
ByteNfa const nfa{std::move(rules)};

// Compare against expected output
string expected_serialized_nfa = "0:byte_transitions={A-->1,Z-->2},"
Expand Down

0 comments on commit 49474bb

Please sign in to comment.