From 6e65a3e50a7c2e3b9df128e428409d66a9582ba4 Mon Sep 17 00:00:00 2001 From: SharafMohamed Date: Sun, 8 Dec 2024 03:44:02 -0500 Subject: [PATCH] LALR1Parser to Lalr1Parser. --- CMakeLists.txt | 6 +-- src/log_surgeon/BufferParser.hpp | 4 +- .../{LALR1Parser.cpp => Lalr1Parser.cpp} | 2 +- .../{LALR1Parser.hpp => Lalr1Parser.hpp} | 6 +-- .../{LALR1Parser.tpp => Lalr1Parser.tpp} | 48 +++++++++---------- src/log_surgeon/LogParser.hpp | 6 +-- src/log_surgeon/ReaderParser.hpp | 4 +- src/log_surgeon/SchemaParser.cpp | 2 +- src/log_surgeon/SchemaParser.hpp | 4 +- tests/CMakeLists.txt | 6 +-- 10 files changed, 44 insertions(+), 44 deletions(-) rename src/log_surgeon/{LALR1Parser.cpp => Lalr1Parser.cpp} (93%) rename src/log_surgeon/{LALR1Parser.hpp => Lalr1Parser.hpp} (99%) rename src/log_surgeon/{LALR1Parser.tpp => Lalr1Parser.tpp} (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2627928e..ceb932dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/log_surgeon/BufferParser.hpp b/src/log_surgeon/BufferParser.hpp index 75eb41a4..4a1a8e78 100644 --- a/src/log_surgeon/BufferParser.hpp +++ b/src/log_surgeon/BufferParser.hpp @@ -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. */ @@ -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 schema_ast); diff --git a/src/log_surgeon/LALR1Parser.cpp b/src/log_surgeon/Lalr1Parser.cpp similarity index 93% rename from src/log_surgeon/LALR1Parser.cpp rename to src/log_surgeon/Lalr1Parser.cpp index d1c4b7c0..a7f54a63 100644 --- a/src/log_surgeon/LALR1Parser.cpp +++ b/src/log_surgeon/Lalr1Parser.cpp @@ -1,4 +1,4 @@ -#include "LALR1Parser.hpp" +#include "Lalr1Parser.hpp" namespace log_surgeon { MatchedSymbol NonTerminal::m_all_children[cSizeOfAllChildren]; diff --git a/src/log_surgeon/LALR1Parser.hpp b/src/log_surgeon/Lalr1Parser.hpp similarity index 99% rename from src/log_surgeon/LALR1Parser.hpp rename to src/log_surgeon/Lalr1Parser.hpp index d3ff39a0..c13103c1 100644 --- a/src/log_surgeon/LALR1Parser.hpp +++ b/src/log_surgeon/Lalr1Parser.hpp @@ -203,9 +203,9 @@ struct ItemSet { }; template -class LALR1Parser : public Parser { +class Lalr1Parser : public Parser { public: - LALR1Parser(); + Lalr1Parser(); /** * Add a lexical rule to m_lexer @@ -407,6 +407,6 @@ class LALR1Parser : public Parser { }; } // namespace log_surgeon -#include "LALR1Parser.tpp" +#include "Lalr1Parser.tpp" #endif // LOG_SURGEON_LALR1_PARSER_HPP diff --git a/src/log_surgeon/LALR1Parser.tpp b/src/log_surgeon/Lalr1Parser.tpp similarity index 95% rename from src/log_surgeon/LALR1Parser.tpp rename to src/log_surgeon/Lalr1Parser.tpp index ac03d3b5..6e60d346 100644 --- a/src/log_surgeon/LALR1Parser.tpp +++ b/src/log_surgeon/Lalr1Parser.tpp @@ -54,7 +54,7 @@ namespace { } // namespace template -LALR1Parser::LALR1Parser() { +Lalr1Parser::Lalr1Parser() { m_terminals.insert((uint32_t)SymbolId::TokenEnd); m_terminals.insert((uint32_t)SymbolId::TokenUncaughtString); m_terminals.insert((uint32_t)SymbolId::TokenInt); @@ -66,7 +66,7 @@ LALR1Parser::LALR1Parser() { } template -void LALR1Parser::add_rule( +void Lalr1Parser::add_rule( std::string const& name, std::unique_ptr> rule ) { @@ -75,7 +75,7 @@ void LALR1Parser::add_rule( } template -void LALR1Parser::add_token_group( +void Lalr1Parser::add_token_group( std::string const& name, std::unique_ptr> rule_group ) { @@ -83,7 +83,7 @@ void LALR1Parser::add_token_group( } template -void LALR1Parser::add_token_chain( +void Lalr1Parser::add_token_chain( std::string const& name, std::string const& chain ) { @@ -110,7 +110,7 @@ void LALR1Parser::add_token_chain( } template -auto LALR1Parser::add_production( +auto Lalr1Parser::add_production( std::string const& head, std::vector const& body, SemanticRule semantic_rule @@ -151,7 +151,7 @@ auto LALR1Parser::add_production( } template -void LALR1Parser::generate() { +void Lalr1Parser::generate() { this->m_lexer.generate(); assert(!m_productions.empty()); generate_lr0_kernels(); @@ -161,7 +161,7 @@ void LALR1Parser::generate() { } template -void LALR1Parser::generate_lr0_kernels() { +void Lalr1Parser::generate_lr0_kernels() { Production* root_production_ptr = m_productions[m_root_production_id].get(); Item root_item(root_production_ptr, 0, cNullSymbol); std::unique_ptr item_set0 = std::make_unique(); @@ -191,7 +191,7 @@ void LALR1Parser::generate_lr0_kernels() { } template -auto LALR1Parser::lr_closure_helper( +auto Lalr1Parser::lr_closure_helper( ItemSet* item_set_ptr, Item const* item, uint32_t* next_symbol @@ -211,7 +211,7 @@ auto LALR1Parser::lr_closure_helper( } template -void LALR1Parser::generate_lr0_closure(ItemSet* item_set_ptr) { +void Lalr1Parser::generate_lr0_closure(ItemSet* item_set_ptr) { std::deque q( item_set_ptr->m_kernel.begin(), item_set_ptr->m_kernel.end() @@ -234,7 +234,7 @@ void LALR1Parser::generate_lr0_closure(ItemSet* item } template -auto LALR1Parser::go_to( +auto Lalr1Parser::go_to( ItemSet* from_item_set, uint32_t const& next_symbol ) -> ItemSet* { @@ -267,7 +267,7 @@ auto LALR1Parser::go_to( } template -void LALR1Parser::generate_first_sets() { +void Lalr1Parser::generate_first_sets() { for (uint32_t const& s : m_terminals) { m_firsts.insert(std::pair>(s, {s})); } @@ -299,7 +299,7 @@ void LALR1Parser::generate_first_sets() { } template -void LALR1Parser::generate_lr1_item_sets() { +void Lalr1Parser::generate_lr1_item_sets() { for (std::map, std::unique_ptr>::value_type const& kv : m_lr0_item_sets) { for (Item const& l0_item : kv.second->m_kernel) { @@ -383,7 +383,7 @@ void LALR1Parser::generate_lr1_item_sets() { } template -void LALR1Parser::generate_lr1_closure(ItemSet* item_set_ptr) { +void Lalr1Parser::generate_lr1_closure(ItemSet* item_set_ptr) { std::deque queue(item_set_ptr->m_kernel.begin(), item_set_ptr->m_kernel.end()); while (!queue.empty()) { Item item = queue.back(); @@ -419,19 +419,19 @@ void LALR1Parser::generate_lr1_closure(ItemSet* item } template -void LALR1Parser::generate_lalr1_parsing_table() { +void Lalr1Parser::generate_lalr1_parsing_table() { generate_lalr1_goto(); generate_lalr1_action(); } template -void LALR1Parser::generate_lalr1_goto() { +void Lalr1Parser::generate_lalr1_goto() { // done already at end of generate_lr1_item_sets()? } // Dragon book page 253 template -void LALR1Parser::generate_lalr1_action() { +void Lalr1Parser::generate_lalr1_action() { for (std::map, std::unique_ptr>::value_type const& kv : m_lr1_item_sets) { ItemSet* item_set_ptr = kv.second.get(); @@ -519,7 +519,7 @@ void LALR1Parser::generate_lalr1_action() { } template -auto LALR1Parser::get_input_after_last_newline( +auto Lalr1Parser::get_input_after_last_newline( std::stack& parse_stack_matches ) -> std::string { std::string error_message_reversed; @@ -558,7 +558,7 @@ auto LALR1Parser::get_input_after_last_newline( } template -auto LALR1Parser::get_input_until_next_newline(Token* error_token +auto Lalr1Parser::get_input_until_next_newline(Token* error_token ) -> std::string { std::string rest_of_line; bool next_is_end_token = (error_token->m_type_ids_ptr->at(0) == (uint32_t)SymbolId::TokenEnd); @@ -578,7 +578,7 @@ auto LALR1Parser::get_input_until_next_newline(Token } template -auto LALR1Parser::report_error() -> std::string { +auto Lalr1Parser::report_error() -> std::string { assert(m_next_token == std::nullopt); assert(!m_parse_stack_matches.empty()); MatchedSymbol top_symbol = std::move(m_parse_stack_matches.top()); @@ -629,7 +629,7 @@ auto LALR1Parser::report_error() -> std::string { } template -auto LALR1Parser::parse(Reader& reader) -> NonTerminal { +auto Lalr1Parser::parse(Reader& reader) -> NonTerminal { reset(); m_parse_stack_states.push(m_root_item_set_ptr); bool accept = false; @@ -651,7 +651,7 @@ auto LALR1Parser::parse(Reader& reader) -> NonTermin } template -void LALR1Parser::reset() { +void Lalr1Parser::reset() { m_next_token = std::nullopt; while (!m_parse_stack_states.empty()) { m_parse_stack_states.pop(); @@ -664,7 +664,7 @@ void LALR1Parser::reset() { } template -auto LALR1Parser::get_next_symbol() -> Token { +auto Lalr1Parser::get_next_symbol() -> Token { if (m_next_token == std::nullopt) { Token token; if (ErrorCode error = this->m_lexer.scan(m_input_buffer, token); @@ -680,7 +680,7 @@ auto LALR1Parser::get_next_symbol() -> Token { } template -auto LALR1Parser::parse_advance(Token& next_token, bool* accept) +auto Lalr1Parser::parse_advance(Token& next_token, bool* accept) -> bool { for (auto const type : *next_token.m_type_ids_ptr) { if (parse_symbol(type, next_token, accept)) { @@ -694,7 +694,7 @@ auto LALR1Parser::parse_advance(Token& next_token, b } template -auto LALR1Parser::parse_symbol( +auto Lalr1Parser::parse_symbol( uint32_t const& type_id, Token& next_token, bool* accept diff --git a/src/log_surgeon/LogParser.hpp b/src/log_surgeon/LogParser.hpp index 14d77f88..eef04a47 100644 --- a/src/log_surgeon/LogParser.hpp +++ b/src/log_surgeon/LogParser.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -26,7 +26,7 @@ class LogParser : public Parser schema_ast); diff --git a/src/log_surgeon/ReaderParser.hpp b/src/log_surgeon/ReaderParser.hpp index 9465efbd..805cd7b4 100644 --- a/src/log_surgeon/ReaderParser.hpp +++ b/src/log_surgeon/ReaderParser.hpp @@ -19,7 +19,7 @@ class ReaderParser { /** * Constructs the parser using the 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. */ @@ -28,7 +28,7 @@ class ReaderParser { /** * 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 ReaderParser(std::unique_ptr schema_ast); diff --git a/src/log_surgeon/SchemaParser.cpp b/src/log_surgeon/SchemaParser.cpp index c7c5e6a4..b9f3bf6a 100644 --- a/src/log_surgeon/SchemaParser.cpp +++ b/src/log_surgeon/SchemaParser.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/log_surgeon/SchemaParser.hpp b/src/log_surgeon/SchemaParser.hpp index 748b94a0..50ec3f02 100644 --- a/src/log_surgeon/SchemaParser.hpp +++ b/src/log_surgeon/SchemaParser.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include namespace log_surgeon { // ASTs used in SchemaParser AST @@ -69,7 +69,7 @@ class DelimiterStringAST : public ParserAST { }; class SchemaParser - : public LALR1Parser { + : public Lalr1Parser { public: /** * File wrapper around generate_schema_ast() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1e4a8363..0551615b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,9 +11,9 @@ set( ../src/log_surgeon/finite_automata/RegisterHandler.hpp ../src/log_surgeon/finite_automata/Tag.hpp ../src/log_surgeon/finite_automata/TaggedTransition.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/ParserInputBuffer.hpp ../src/log_surgeon/ParserInputBuffer.cpp ../src/log_surgeon/Schema.hpp