Skip to content

Commit

Permalink
Linter + Merge branch 'remove-redundant-typenames' into remove-regex-…
Browse files Browse the repository at this point in the history
…prefix
  • Loading branch information
SharafMohamed committed Dec 5, 2024
2 parents 7f6fcd9 + effac53 commit 43aa3be
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/log_surgeon/Lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <vector>

#include <log_surgeon/Constants.hpp>
#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/finite_automata/Dfa.hpp>
#include <log_surgeon/finite_automata/Nfa.hpp>
#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/LexicalRule.hpp>
#include <log_surgeon/ParserInputBuffer.hpp>
#include <log_surgeon/Token.hpp>
Expand Down
16 changes: 6 additions & 10 deletions src/log_surgeon/LogParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ using std::unique_ptr;
using std::vector;

namespace log_surgeon {
using finite_automata::DfaByteState;
using finite_automata::NfaByteState;
using finite_automata::RegexAST;
using finite_automata::RegexASTCat;
using finite_automata::RegexASTGroup;
using finite_automata::RegexASTInteger;
using finite_automata::RegexASTLiteral;
using finite_automata::RegexASTMultiplication;
using finite_automata::RegexASTOr;
using finite_automata::DfaByteState;
using finite_automata::NfaByteState;

LogParser::LogParser(string const& schema_file_path)
: LogParser::LogParser(SchemaParser::try_schema_file(schema_file_path)) {}
Expand Down Expand Up @@ -62,8 +62,7 @@ void LogParser::add_rules(std::unique_ptr<SchemaAST> schema_ast) {
for (unique_ptr<ParserAST> const& parser_ast : schema_ast->m_schema_vars) {
auto* rule = dynamic_cast<SchemaVarAST*>(parser_ast.get());
if (rule->m_name == "timestamp") {
unique_ptr<RegexAST<NfaByteState>> first_timestamp_regex_ast(
rule->m_regex_ptr->clone()
unique_ptr<RegexAST<NfaByteState>> first_timestamp_regex_ast(rule->m_regex_ptr->clone()
);
unique_ptr<RegexASTLiteral<NfaByteState>> r1
= make_unique<RegexASTLiteral<NfaByteState>>(utf8::cCharStartOfFile);
Expand All @@ -74,9 +73,8 @@ void LogParser::add_rules(std::unique_ptr<SchemaAST> schema_ast) {
std::move(first_timestamp_regex_ast)
)
);
unique_ptr<RegexAST<NfaByteState>> newline_timestamp_regex_ast(
rule->m_regex_ptr->clone()
);
unique_ptr<RegexAST<NfaByteState>> newline_timestamp_regex_ast(rule->m_regex_ptr->clone(
));
unique_ptr<RegexASTLiteral<NfaByteState>> r2
= make_unique<RegexASTLiteral<NfaByteState>>('\n');
add_rule(
Expand Down Expand Up @@ -143,9 +141,7 @@ void LogParser::add_rules(std::unique_ptr<SchemaAST> schema_ast) {

// For log-specific lexing: modify variable regex to contain a delimiter at the start.
unique_ptr<RegexASTGroup<NfaByteState>> delimiter_group
= make_unique<RegexASTGroup<NfaByteState>>(
RegexASTGroup<NfaByteState>(delimiters)
);
= make_unique<RegexASTGroup<NfaByteState>>(RegexASTGroup<NfaByteState>(delimiters));
rule->m_regex_ptr = make_unique<RegexASTCat<NfaByteState>>(
std::move(delimiter_group),
std::move(rule->m_regex_ptr)
Expand Down
3 changes: 1 addition & 2 deletions src/log_surgeon/LogParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

namespace log_surgeon {
// TODO: Compare c-array vs. vectors (its underlying array) for buffers
class LogParser
: public Parser<finite_automata::NfaByteState, finite_automata::DfaByteState> {
class LogParser : public Parser<finite_automata::NfaByteState, finite_automata::DfaByteState> {
public:
enum class ParsingAction {
None,
Expand Down
24 changes: 12 additions & 12 deletions src/log_surgeon/SchemaParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ using ParserValueRegex = log_surgeon::ParserValue<std::unique_ptr<
log_surgeon::finite_automata::RegexAST<log_surgeon::finite_automata::NfaByteState>>>;
using RegexASTByte
= log_surgeon::finite_automata::RegexAST<log_surgeon::finite_automata::NfaByteState>;
using RegexASTGroupByte = log_surgeon::finite_automata::RegexASTGroup<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTIntegerByte = log_surgeon::finite_automata::RegexASTInteger<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTLiteralByte = log_surgeon::finite_automata::RegexASTLiteral<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTGroupByte
= log_surgeon::finite_automata::RegexASTGroup<log_surgeon::finite_automata::NfaByteState>;
using RegexASTIntegerByte
= log_surgeon::finite_automata::RegexASTInteger<log_surgeon::finite_automata::NfaByteState>;
using RegexASTLiteralByte
= log_surgeon::finite_automata::RegexASTLiteral<log_surgeon::finite_automata::NfaByteState>;
using RegexASTMultiplicationByte = log_surgeon::finite_automata::RegexASTMultiplication<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTOrByte
= log_surgeon::finite_automata::RegexASTOr<log_surgeon::finite_automata::NfaByteState>;
using RegexASTCatByte = log_surgeon::finite_automata::RegexASTCat<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTCaptureByte = log_surgeon::finite_automata::RegexASTCapture<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTEmptyByte = log_surgeon::finite_automata::RegexASTEmpty<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTCatByte
= log_surgeon::finite_automata::RegexASTCat<log_surgeon::finite_automata::NfaByteState>;
using RegexASTCaptureByte
= log_surgeon::finite_automata::RegexASTCapture<log_surgeon::finite_automata::NfaByteState>;
using RegexASTEmptyByte
= log_surgeon::finite_automata::RegexASTEmpty<log_surgeon::finite_automata::NfaByteState>;

using std::make_unique;
using std::string;
Expand Down
8 changes: 3 additions & 5 deletions src/log_surgeon/SchemaParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class SchemaVarAST : public ParserAST {
// Constructor
SchemaVarAST(
std::string name,
std::unique_ptr<finite_automata::RegexAST<finite_automata::NfaByteState>>
regex_ptr,
std::unique_ptr<finite_automata::RegexAST<finite_automata::NfaByteState>> regex_ptr,
uint32_t line_num
)
: m_line_num(line_num),
Expand All @@ -69,9 +68,8 @@ class DelimiterStringAST : public ParserAST {
std::vector<uint32_t> m_delimiters;
};

class SchemaParser : public LALR1Parser<
finite_automata::NfaByteState,
finite_automata::DfaByteState> {
class SchemaParser
: public LALR1Parser<finite_automata::NfaByteState, finite_automata::DfaByteState> {
public:
/**
* File wrapper around generate_schema_ast()
Expand Down
3 changes: 1 addition & 2 deletions src/log_surgeon/finite_automata/Dfa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class Dfa {

template <typename DfaStateType>
template <typename NfaStateType>
auto Dfa<DfaStateType>::new_state(std::set<NfaStateType*> const& nfa_state_set
) -> DfaStateType* {
auto Dfa<DfaStateType>::new_state(std::set<NfaStateType*> const& nfa_state_set) -> DfaStateType* {
m_states.emplace_back(std::make_unique<DfaStateType>());
auto* dfa_state = m_states.back().get();
for (auto const* nfa_state : nfa_state_set) {
Expand Down
2 changes: 1 addition & 1 deletion src/log_surgeon/finite_automata/DfaStateType.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 DfaStateType : uint8_t {
enum class DfaStateType : uint8_t {
Byte,
Utf8
};
Expand Down
12 changes: 4 additions & 8 deletions src/log_surgeon/finite_automata/NfaState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class NfaState {
return m_matching_variable_id;
}

auto
add_positive_tagged_start_transition(Tag const* tag, NfaState const* dest_state) -> void {
auto add_positive_tagged_start_transition(Tag const* tag, NfaState const* dest_state) -> void {
m_positive_tagged_start_transitions.emplace_back(tag, dest_state);
}

Expand Down Expand Up @@ -80,8 +79,7 @@ class NfaState {
m_bytes_transitions[byte].push_back(dest_state);
}

[[nodiscard]] auto get_byte_transitions(uint8_t byte
) const -> std::vector<NfaState*> const& {
[[nodiscard]] auto get_byte_transitions(uint8_t byte) const -> std::vector<NfaState*> const& {
return m_bytes_transitions[byte];
}

Expand Down Expand Up @@ -117,8 +115,7 @@ class NfaState {
// NOTE: We don't need m_tree_transitions for the `stateType ==
// DfaStateType::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 == NfaStateType::Utf8, Tree, std::tuple<>> m_tree_transitions;
};

template <NfaStateType state_type>
Expand Down Expand Up @@ -169,8 +166,7 @@ auto NfaState<state_type>::add_interval(Interval interval, NfaState* dest_state)
}

template <NfaStateType state_type>
auto NfaState<state_type>::serialize(
std::unordered_map<NfaState const*, uint32_t> const& state_ids
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;
for (uint32_t idx{0}; idx < cSizeOfByte; ++idx) {
Expand Down
6 changes: 2 additions & 4 deletions src/log_surgeon/finite_automata/RegexAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,8 @@ template <typename NfaStateType>
}

template <typename NfaStateType>
auto RegexASTCapture<NfaStateType>::add_to_nfa(
Nfa<NfaStateType>* nfa,
NfaStateType* dest_state
) const -> void {
auto RegexASTCapture<NfaStateType>::add_to_nfa(Nfa<NfaStateType>* nfa, NfaStateType* dest_state)
const -> void {
// TODO: move this into a documentation file in the future, and reference it here.
// The NFA constructed for a capture group follows the structure below, with tagged transitions
// explicitly labeled for clarity:
Expand Down
13 changes: 13 additions & 0 deletions src/log_surgeon/finite_automata/RegexDFAStateType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef LOG_SURGEON_FINITE_AUTOMATA_REGEX_DFA_STATE_TYPE
#define LOG_SURGEON_FINITE_AUTOMATA_REGEX_DFA_STATE_TYPE

#include <cstdint>

namespace log_surgeon::finite_automata {
enum class RegexDFAStateType : uint8_t {
Byte,
UTF8
};
} // namespace log_surgeon::finite_automata

#endif // LOG_SURGEON_FINITE_AUTOMATA_REGEX_DFA_STATE_TYPE
2 changes: 1 addition & 1 deletion tests/test-NFA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <catch2/catch_test_macros.hpp>

#include <log_surgeon/Constants.hpp>
#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/finite_automata/Nfa.hpp>
#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/Schema.hpp>
#include <log_surgeon/SchemaParser.hpp>

Expand Down
18 changes: 9 additions & 9 deletions tests/test-lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <catch2/catch_test_macros.hpp>

#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/finite_automata/Nfa.hpp>
#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/Schema.hpp>
#include <log_surgeon/SchemaParser.hpp>

Expand All @@ -18,14 +18,14 @@ using std::u32string;
using std::vector;
using std::wstring_convert;

using RegexASTCatByte = log_surgeon::finite_automata::RegexASTCat<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTCaptureByte = log_surgeon::finite_automata::RegexASTCapture<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTGroupByte = log_surgeon::finite_automata::RegexASTGroup<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTLiteralByte = log_surgeon::finite_automata::RegexASTLiteral<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTCatByte
= log_surgeon::finite_automata::RegexASTCat<log_surgeon::finite_automata::NfaByteState>;
using RegexASTCaptureByte
= log_surgeon::finite_automata::RegexASTCapture<log_surgeon::finite_automata::NfaByteState>;
using RegexASTGroupByte
= log_surgeon::finite_automata::RegexASTGroup<log_surgeon::finite_automata::NfaByteState>;
using RegexASTLiteralByte
= log_surgeon::finite_automata::RegexASTLiteral<log_surgeon::finite_automata::NfaByteState>;
using RegexASTMultiplicationByte = log_surgeon::finite_automata::RegexASTMultiplication<
log_surgeon::finite_automata::NfaByteState>;
using RegexASTOrByte
Expand Down

0 comments on commit 43aa3be

Please sign in to comment.