Skip to content

Commit

Permalink
Merge branch 'remove-regex-prefix' into remove-uneeded-this
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Jan 7, 2025
2 parents 9a82620 + 5dc5953 commit ed631b3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 51 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
18 changes: 9 additions & 9 deletions src/log_surgeon/finite_automata/DfaState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
#include <vector>

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

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

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

template <DfaStateType state_type>
template <StateType state_type>
class DfaState {
public:
using Tree = UnicodeIntervalTree<DfaState*>;
Expand Down Expand Up @@ -51,14 +51,14 @@ class DfaState {
private:
std::vector<uint32_t> m_matching_variable_ids;
DfaState* m_bytes_transition[cSizeOfByte];
// NOTE: We don't need m_tree_transitions for the `state_type == DfaStateType::Byte` case, so we
// NOTE: We don't need m_tree_transitions for the `state_type == StateType::Byte` case, so we
// use an empty class (`std::tuple<>`) in that case.
std::conditional_t<state_type == DfaStateType::Utf8, Tree, std::tuple<>> m_tree_transitions;
std::conditional_t<state_type == StateType::Utf8, Tree, std::tuple<>> m_tree_transitions;
};

template <DfaStateType state_type>
template <StateType state_type>
auto DfaState<state_type>::next(uint32_t character) const -> DfaState* {
if constexpr (DfaStateType::Byte == state_type) {
if constexpr (StateType::Byte == state_type) {
return m_bytes_transition[character];
} else {
if (character < cSizeOfByte) {
Expand Down
13 changes: 0 additions & 13 deletions src/log_surgeon/finite_automata/DfaStateType.hpp

This file was deleted.

20 changes: 10 additions & 10 deletions src/log_surgeon/finite_automata/NfaState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

#include <fmt/format.h>

#include <log_surgeon/finite_automata/NfaStateType.hpp>
#include <log_surgeon/finite_automata/StateType.hpp>
#include <log_surgeon/finite_automata/TaggedTransition.hpp>
#include <log_surgeon/finite_automata/UnicodeIntervalTree.hpp>

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

using ByteNfaState = NfaState<NfaStateType::Byte>;
using Utf8NfaState = NfaState<NfaStateType::Utf8>;
using ByteNfaState = NfaState<StateType::Byte>;
using Utf8NfaState = NfaState<StateType::Utf8>;

template <NfaStateType state_type>
template <StateType state_type>
class NfaState {
public:
using Tree = UnicodeIntervalTree<NfaState*>;
Expand Down Expand Up @@ -113,12 +113,12 @@ 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 == NfaStateType::Utf8, Tree, std::tuple<>> m_tree_transitions;
std::conditional_t<state_type == StateType::Utf8, Tree, std::tuple<>> m_tree_transitions;
};

template <NfaStateType state_type>
template <StateType state_type>
auto NfaState<state_type>::add_interval(Interval interval, NfaState* dest_state) -> void {
if (interval.first < cSizeOfByte) {
uint32_t const bound = std::min(interval.second, cSizeOfByte - 1);
Expand All @@ -127,7 +127,7 @@ auto NfaState<state_type>::add_interval(Interval interval, NfaState* dest_state)
}
interval.first = bound + 1;
}
if constexpr (NfaStateType::Utf8 == state_type) {
if constexpr (StateType::Utf8 == state_type) {
if (interval.second < cSizeOfByte) {
return;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ auto NfaState<state_type>::add_interval(Interval interval, NfaState* dest_state)
}
}

template <NfaStateType state_type>
template <StateType state_type>
auto NfaState<state_type>::serialize(std::unordered_map<NfaState const*, uint32_t> const& state_ids
) const -> std::optional<std::string> {
std::vector<std::string> byte_transitions;
Expand Down
13 changes: 0 additions & 13 deletions src/log_surgeon/finite_automata/NfaStateType.hpp

This file was deleted.

13 changes: 13 additions & 0 deletions src/log_surgeon/finite_automata/StateType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef LOG_SURGEON_FINITE_AUTOMATA_STATE_TYPE
#define LOG_SURGEON_FINITE_AUTOMATA_STATE_TYPE

#include <cstdint>

namespace log_surgeon::finite_automata {
enum class StateType : uint8_t {
Byte,
Utf8
};
} // namespace log_surgeon::finite_automata

#endif // LOG_SURGEON_FINITE_AUTOMATA_STATE_TYPE
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 ed631b3

Please sign in to comment.