Skip to content

Commit

Permalink
refactor: Update NFA, DFA, and LALR1 to align with the latest coding …
Browse files Browse the repository at this point in the history
…guidelines. (#59)

- Remove redundant `Regex` prefixes from NFA's and DFA's class names
- Follow the class naming convention only to capitalize the first character for NFA, DFA, and LALR1 parser
  • Loading branch information
SharafMohamed authored Jan 8, 2025
1 parent c5017ab commit 221225e
Show file tree
Hide file tree
Showing 29 changed files with 592 additions and 642 deletions.
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ set(SOURCE_FILES
src/log_surgeon/Constants.hpp
src/log_surgeon/FileReader.cpp
src/log_surgeon/FileReader.hpp
src/log_surgeon/LALR1Parser.cpp
src/log_surgeon/LALR1Parser.hpp
src/log_surgeon/LALR1Parser.tpp
src/log_surgeon/Lalr1Parser.cpp
src/log_surgeon/Lalr1Parser.hpp
src/log_surgeon/Lalr1Parser.tpp
src/log_surgeon/Lexer.hpp
src/log_surgeon/Lexer.tpp
src/log_surgeon/LexicalRule.hpp
Expand All @@ -96,14 +96,13 @@ set(SOURCE_FILES
src/log_surgeon/finite_automata/PrefixTree.cpp
src/log_surgeon/finite_automata/PrefixTree.hpp
src/log_surgeon/finite_automata/RegexAST.hpp
src/log_surgeon/finite_automata/RegexDFA.hpp
src/log_surgeon/finite_automata/RegexDFAState.hpp
src/log_surgeon/finite_automata/RegexDFAStatePair.hpp
src/log_surgeon/finite_automata/RegexDFAStateType.hpp
src/log_surgeon/finite_automata/RegexNFA.hpp
src/log_surgeon/finite_automata/RegexNFAState.hpp
src/log_surgeon/finite_automata/RegexNFAStateType.hpp
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/Nfa.hpp
src/log_surgeon/finite_automata/NfaState.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
16 changes: 8 additions & 8 deletions examples/intersect-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <log_surgeon/Lexer.hpp>
#include <log_surgeon/Schema.hpp>

using log_surgeon::finite_automata::RegexDFA;
using log_surgeon::finite_automata::RegexDFAByteState;
using log_surgeon::finite_automata::RegexNFA;
using log_surgeon::finite_automata::RegexNFAByteState;
using log_surgeon::finite_automata::ByteDfaState;
using log_surgeon::finite_automata::ByteNfaState;
using log_surgeon::finite_automata::Dfa;
using log_surgeon::finite_automata::Nfa;
using log_surgeon::lexers::ByteLexer;
using log_surgeon::LexicalRule;
using log_surgeon::ParserAST;
Expand All @@ -17,11 +17,11 @@ using std::string;
using std::unique_ptr;
using std::vector;

using ByteLexicalRule = log_surgeon::LexicalRule<RegexNFAByteState>;
using ByteLexicalRule = log_surgeon::LexicalRule<ByteNfaState>;

auto get_intersect_for_query(
std::map<uint32_t, std::string>& m_id_symbol,
std::unique_ptr<RegexDFA<RegexDFAByteState>>& dfa1,
std::unique_ptr<Dfa<ByteDfaState>>& dfa1,
std::string const& search_string
) -> void {
std::string processed_search_string;
Expand All @@ -40,7 +40,7 @@ auto get_intersect_for_query(
auto* schema_var_ast = dynamic_cast<SchemaVarAST*>(parser_ast.get());
rules.emplace_back(0, std::move(schema_var_ast->m_regex_ptr));
}
RegexNFA<RegexNFAByteState> nfa(std::move(rules));
Nfa<ByteNfaState> nfa(std::move(rules));
auto dfa2 = ByteLexer::nfa_to_dfa(nfa);
auto schema_types = dfa1->get_intersect(dfa2.get());
std::cout << search_string << ":";
Expand Down Expand Up @@ -78,7 +78,7 @@ auto main() -> int {
rules.emplace_back(m_id_symbol.size(), std::move(var_ast->m_regex_ptr));
m_id_symbol[m_id_symbol.size()] = var_ast->m_name;
}
RegexNFA<RegexNFAByteState> nfa(std::move(rules));
Nfa<ByteNfaState> nfa(std::move(rules));
auto dfa = ByteLexer::nfa_to_dfa(nfa);
get_intersect_for_query(m_id_symbol, dfa, "*1*");
get_intersect_for_query(m_id_symbol, dfa, "*a*");
Expand Down
4 changes: 2 additions & 2 deletions src/log_surgeon/BufferParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BufferParser {
/**
* Constructs the parser using the given schema file.
* @param schema_file_path
* @throw std::runtime_error from LALR1Parser, RegexAST, or Lexer
* @throw std::runtime_error from Lalr1Parser, RegexAST, or Lexer
* describing the failure parsing the schema file or processing the schema
* AST.
*/
Expand All @@ -29,7 +29,7 @@ class BufferParser {
/**
* Constructs the parser using the given schema AST.
* @param schema_ast
* @throw std::runtime_error from LALR1Parser, RegexAST, or Lexer
* @throw std::runtime_error from Lalr1Parser, RegexAST, or Lexer
* describing the failure processing the schema AST.
*/
explicit BufferParser(std::unique_ptr<log_surgeon::SchemaAST> schema_ast);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "LALR1Parser.hpp"
#include "Lalr1Parser.hpp"

namespace log_surgeon {
MatchedSymbol NonTerminal::m_all_children[cSizeOfAllChildren];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ struct ItemSet {
std::vector<Action> m_actions;
};

template <typename NFAStateType, typename DFAStateType>
class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
template <typename TypedNfaState, typename TypedDfaState>
class Lalr1Parser : public Parser<TypedNfaState, TypedDfaState> {
public:
LALR1Parser();
Lalr1Parser();

/**
* Add a lexical rule to m_lexer
Expand All @@ -214,7 +214,7 @@ class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
*/
auto add_rule(
std::string const& name,
std::unique_ptr<finite_automata::RegexAST<NFAStateType>> rule
std::unique_ptr<finite_automata::RegexAST<TypedNfaState>> rule
) -> void override;

/**
Expand All @@ -224,7 +224,7 @@ class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
*/
auto add_token_group(
std::string const& name,
std::unique_ptr<finite_automata::RegexASTGroup<NFAStateType>> rule_group
std::unique_ptr<finite_automata::RegexASTGroup<TypedNfaState>> rule_group
) -> void;

/**
Expand Down Expand Up @@ -276,7 +276,6 @@ class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
*/
auto report_error() -> std::string;

/* Lexer<NFAStateType, DFAStateType> m_lexer; */
std::stack<MatchedSymbol> m_parse_stack_matches;
std::stack<ItemSet*> m_parse_stack_states;
ItemSet* m_root_item_set_ptr{nullptr};
Expand Down Expand Up @@ -407,6 +406,6 @@ class LALR1Parser : public Parser<NFAStateType, DFAStateType> {
};
} // namespace log_surgeon

#include "LALR1Parser.tpp"
#include "Lalr1Parser.tpp"

#endif // LOG_SURGEON_LALR1_PARSER_HPP
Loading

0 comments on commit 221225e

Please sign in to comment.