Skip to content

Commit

Permalink
Merge branch 'use-auto' into refactor-nfa-to-dfa
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Dec 11, 2024
2 parents 9302ecb + ee46719 commit 4cebc06
Show file tree
Hide file tree
Showing 30 changed files with 716 additions and 629 deletions.
6 changes: 3 additions & 3 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 Down
14 changes: 7 additions & 7 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::ByteDfaState;
using log_surgeon::finite_automata::ByteNfaState;
using log_surgeon::finite_automata::Dfa;
using log_surgeon::finite_automata::DfaByteState;
using log_surgeon::finite_automata::Nfa;
using log_surgeon::finite_automata::NfaByteState;
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<NfaByteState>;
using ByteLexicalRule = log_surgeon::LexicalRule<ByteNfaState>;

auto get_intersect_for_query(
std::map<uint32_t, std::string>& m_id_symbol,
std::unique_ptr<Dfa<DfaByteState>>& dfa1,
std::unique_ptr<Dfa<ByteDfaState>>& dfa1,
std::string const& search_string
) -> void {
std::string processed_search_string;
Expand All @@ -40,9 +40,9 @@ 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));
}
Nfa<NfaByteState> nfa(std::move(rules));
Nfa<ByteNfaState> nfa(std::move(rules));
Dfa dfa2(nfa);
auto schema_types = dfa1->get_intersect(dfa2);
auto schema_types = dfa1->get_intersect(dfa2.get());
std::cout << search_string << ":";
for (auto const& schema_type : schema_types) {
std::cout << m_id_symbol[schema_type] << ",";
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;
}
Nfa<NfaByteState> nfa(std::move(rules));
Nfa<ByteNfaState> nfa(std::move(rules));
Dfa 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 @@ -200,10 +200,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 @@ -212,7 +212,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 @@ -222,7 +222,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 @@ -274,7 +274,7 @@ class LALR1Parser : public Parser<NfaStateType, DfaStateType> {
*/
auto report_error() -> std::string;

/* Lexer<NfaStateType, DfaStateType> m_lexer; */
/* Lexer<TypedNfaState, TypedDfaState> 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 @@ -394,6 +394,8 @@ class LALR1Parser : public Parser<NfaStateType, DfaStateType> {

auto symbol_is_token(uint32_t s) -> bool { return m_terminals.find(s) != m_terminals.end(); }

using Parser<TypedNfaState, TypedDfaState>::m_lexer;

std::set<uint32_t> m_terminals;
std::set<uint32_t> m_nullable;
std::map<std::set<Item>, std::unique_ptr<ItemSet>> m_lr0_item_sets;
Expand All @@ -405,6 +407,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 4cebc06

Please sign in to comment.