Skip to content

Commit

Permalink
LALR1Parser to Lalr1Parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafMohamed committed Dec 8, 2024
1 parent cf5980d commit 6e65a3e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 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
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 @@ -203,9 +203,9 @@ struct ItemSet {
};

template <typename NfaStateType, typename DfaStateType>
class LALR1Parser : public Parser<NfaStateType, DfaStateType> {
class Lalr1Parser : public Parser<NfaStateType, DfaStateType> {
public:
LALR1Parser();
Lalr1Parser();

/**
* Add a lexical rule to m_lexer
Expand Down Expand Up @@ -407,6 +407,6 @@ class LALR1Parser : public Parser<NfaStateType, DfaStateType> {
};
} // namespace log_surgeon

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

#endif // LOG_SURGEON_LALR1_PARSER_HPP
48 changes: 24 additions & 24 deletions src/log_surgeon/LALR1Parser.tpp → src/log_surgeon/Lalr1Parser.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace {
} // namespace

template <typename NfaStateType, typename DfaStateType>
LALR1Parser<NfaStateType, DfaStateType>::LALR1Parser() {
Lalr1Parser<NfaStateType, DfaStateType>::Lalr1Parser() {
m_terminals.insert((uint32_t)SymbolId::TokenEnd);
m_terminals.insert((uint32_t)SymbolId::TokenUncaughtString);
m_terminals.insert((uint32_t)SymbolId::TokenInt);
Expand All @@ -66,7 +66,7 @@ LALR1Parser<NfaStateType, DfaStateType>::LALR1Parser() {
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::add_rule(
void Lalr1Parser<NfaStateType, DfaStateType>::add_rule(
std::string const& name,
std::unique_ptr<finite_automata::RegexAST<NfaStateType>> rule
) {
Expand All @@ -75,15 +75,15 @@ void LALR1Parser<NfaStateType, DfaStateType>::add_rule(
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::add_token_group(
void Lalr1Parser<NfaStateType, DfaStateType>::add_token_group(
std::string const& name,
std::unique_ptr<finite_automata::RegexASTGroup<NfaStateType>> rule_group
) {
add_rule(name, std::move(rule_group));
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::add_token_chain(
void Lalr1Parser<NfaStateType, DfaStateType>::add_token_chain(
std::string const& name,
std::string const& chain
) {
Expand All @@ -110,7 +110,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::add_token_chain(
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::add_production(
auto Lalr1Parser<NfaStateType, DfaStateType>::add_production(
std::string const& head,
std::vector<std::string> const& body,
SemanticRule semantic_rule
Expand Down Expand Up @@ -151,7 +151,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::add_production(
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate() {
void Lalr1Parser<NfaStateType, DfaStateType>::generate() {
this->m_lexer.generate();
assert(!m_productions.empty());
generate_lr0_kernels();
Expand All @@ -161,7 +161,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate() {
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lr0_kernels() {
void Lalr1Parser<NfaStateType, DfaStateType>::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<ItemSet> item_set0 = std::make_unique<ItemSet>();
Expand Down Expand Up @@ -191,7 +191,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate_lr0_kernels() {
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::lr_closure_helper(
auto Lalr1Parser<NfaStateType, DfaStateType>::lr_closure_helper(
ItemSet* item_set_ptr,
Item const* item,
uint32_t* next_symbol
Expand All @@ -211,7 +211,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::lr_closure_helper(
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lr0_closure(ItemSet* item_set_ptr) {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_lr0_closure(ItemSet* item_set_ptr) {
std::deque<Item> q(
item_set_ptr->m_kernel.begin(),
item_set_ptr->m_kernel.end()
Expand All @@ -234,7 +234,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate_lr0_closure(ItemSet* item
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::go_to(
auto Lalr1Parser<NfaStateType, DfaStateType>::go_to(
ItemSet* from_item_set,
uint32_t const& next_symbol
) -> ItemSet* {
Expand Down Expand Up @@ -267,7 +267,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::go_to(
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_first_sets() {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_first_sets() {
for (uint32_t const& s : m_terminals) {
m_firsts.insert(std::pair<uint32_t, std::set<uint32_t>>(s, {s}));
}
Expand Down Expand Up @@ -299,7 +299,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate_first_sets() {
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lr1_item_sets() {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_lr1_item_sets() {
for (std::map<std::set<Item>, std::unique_ptr<ItemSet>>::value_type const& kv : m_lr0_item_sets)
{
for (Item const& l0_item : kv.second->m_kernel) {
Expand Down Expand Up @@ -383,7 +383,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate_lr1_item_sets() {
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lr1_closure(ItemSet* item_set_ptr) {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_lr1_closure(ItemSet* item_set_ptr) {
std::deque<Item> queue(item_set_ptr->m_kernel.begin(), item_set_ptr->m_kernel.end());
while (!queue.empty()) {
Item item = queue.back();
Expand Down Expand Up @@ -419,19 +419,19 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate_lr1_closure(ItemSet* item
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lalr1_parsing_table() {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_lalr1_parsing_table() {
generate_lalr1_goto();
generate_lalr1_action();
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lalr1_goto() {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_lalr1_goto() {
// done already at end of generate_lr1_item_sets()?
}

// Dragon book page 253
template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::generate_lalr1_action() {
void Lalr1Parser<NfaStateType, DfaStateType>::generate_lalr1_action() {
for (std::map<std::set<Item>, std::unique_ptr<ItemSet>>::value_type const& kv : m_lr1_item_sets)
{
ItemSet* item_set_ptr = kv.second.get();
Expand Down Expand Up @@ -519,7 +519,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::generate_lalr1_action() {
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::get_input_after_last_newline(
auto Lalr1Parser<NfaStateType, DfaStateType>::get_input_after_last_newline(
std::stack<MatchedSymbol>& parse_stack_matches
) -> std::string {
std::string error_message_reversed;
Expand Down Expand Up @@ -558,7 +558,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::get_input_after_last_newline(
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::get_input_until_next_newline(Token* error_token
auto Lalr1Parser<NfaStateType, DfaStateType>::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);
Expand All @@ -578,7 +578,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::get_input_until_next_newline(Token
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::report_error() -> std::string {
auto Lalr1Parser<NfaStateType, DfaStateType>::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());
Expand Down Expand Up @@ -629,7 +629,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::report_error() -> std::string {
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::parse(Reader& reader) -> NonTerminal {
auto Lalr1Parser<NfaStateType, DfaStateType>::parse(Reader& reader) -> NonTerminal {
reset();
m_parse_stack_states.push(m_root_item_set_ptr);
bool accept = false;
Expand All @@ -651,7 +651,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::parse(Reader& reader) -> NonTermin
}

template <typename NfaStateType, typename DfaStateType>
void LALR1Parser<NfaStateType, DfaStateType>::reset() {
void Lalr1Parser<NfaStateType, DfaStateType>::reset() {
m_next_token = std::nullopt;
while (!m_parse_stack_states.empty()) {
m_parse_stack_states.pop();
Expand All @@ -664,7 +664,7 @@ void LALR1Parser<NfaStateType, DfaStateType>::reset() {
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::get_next_symbol() -> Token {
auto Lalr1Parser<NfaStateType, DfaStateType>::get_next_symbol() -> Token {
if (m_next_token == std::nullopt) {
Token token;
if (ErrorCode error = this->m_lexer.scan(m_input_buffer, token);
Expand All @@ -680,7 +680,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::get_next_symbol() -> Token {
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::parse_advance(Token& next_token, bool* accept)
auto Lalr1Parser<NfaStateType, DfaStateType>::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)) {
Expand All @@ -694,7 +694,7 @@ auto LALR1Parser<NfaStateType, DfaStateType>::parse_advance(Token& next_token, b
}

template <typename NfaStateType, typename DfaStateType>
auto LALR1Parser<NfaStateType, DfaStateType>::parse_symbol(
auto Lalr1Parser<NfaStateType, DfaStateType>::parse_symbol(
uint32_t const& type_id,
Token& next_token,
bool* accept
Expand Down
6 changes: 3 additions & 3 deletions src/log_surgeon/LogParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <memory>

#include <log_surgeon/Constants.hpp>
#include <log_surgeon/LALR1Parser.hpp>
#include <log_surgeon/Lalr1Parser.hpp>
#include <log_surgeon/LogEvent.hpp>
#include <log_surgeon/LogParserOutputBuffer.hpp>
#include <log_surgeon/Parser.hpp>
Expand All @@ -26,7 +26,7 @@ class LogParser : public Parser<finite_automata::NfaByteState, finite_automata::
/**
* 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 @@ -35,7 +35,7 @@ class LogParser : public Parser<finite_automata::NfaByteState, finite_automata::
/**
* 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 LogParser(std::unique_ptr<log_surgeon::SchemaAST> schema_ast);
Expand Down
4 changes: 2 additions & 2 deletions src/log_surgeon/ReaderParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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<log_surgeon::SchemaAST> schema_ast);
Expand Down
2 changes: 1 addition & 1 deletion src/log_surgeon/SchemaParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <log_surgeon/FileReader.hpp>
#include <log_surgeon/finite_automata/RegexAST.hpp>
#include <log_surgeon/finite_automata/Tag.hpp>
#include <log_surgeon/LALR1Parser.hpp>
#include <log_surgeon/Lalr1Parser.hpp>
#include <log_surgeon/Lexer.hpp>
#include <log_surgeon/utils.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/log_surgeon/SchemaParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string_view>
#include <utility>

#include <log_surgeon/LALR1Parser.hpp>
#include <log_surgeon/Lalr1Parser.hpp>

namespace log_surgeon {
// ASTs used in SchemaParser AST
Expand Down Expand Up @@ -69,7 +69,7 @@ class DelimiterStringAST : public ParserAST {
};

class SchemaParser
: public LALR1Parser<finite_automata::NfaByteState, finite_automata::DfaByteState> {
: public Lalr1Parser<finite_automata::NfaByteState, finite_automata::DfaByteState> {
public:
/**
* File wrapper around generate_schema_ast()
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e65a3e

Please sign in to comment.