Commit 988c78f1 authored by Robin Mueller's avatar Robin Mueller
Browse files

continued parser

parent 3d6ed226
......@@ -48,6 +48,8 @@ class FileParser:
self.__debug_moving_window = False
self.__debug_moving_window_filename = ""
self._verbose_level = 1
def set_regular_parser_mode(self):
"""
Set regular parsing mode. This will be the default, so it is not strictly necessary to call
......@@ -65,6 +67,9 @@ class FileParser:
self.__parser_mode = FileParserModes.MOVING_WINDOW
self.__parser_args = moving_window_size
def set_verbosity(self, verbose_level: int):
self._verbose_level = verbose_level
def enable_moving_window_debugging(self, file_name: str):
self.__debug_moving_window = True
self.__debug_moving_window_filename = file_name
......@@ -83,13 +88,13 @@ class FileParser:
if self.__parser_mode == FileParserModes.REGULAR:
for file_name in self.file_list:
# Implemented by child class ! Fill out info table (self.mib_table) in this routine
self._handle_file_parsing(file_name=file_name, *args, **kwargs)
self._handle_file_parsing(file_name, *args, **kwargs)
# Can be implemented by child class to edit the table after it is finished.
# default implementation is empty
self._post_parsing_operation()
elif self.__parser_mode == FileParserModes.MOVING_WINDOW:
for file_name in self.file_list:
self.__parse_file_with_moving_window(file_name=file_name, *args, **kwargs)
self.__parse_file_with_moving_window(file_name, *args, **kwargs)
self._post_parsing_operation()
return self.mib_table
......@@ -157,8 +162,7 @@ class FileParser:
print(f"Moving window post line anaylsis line {line_idx}")
print(moving_window)
self._handle_file_parsing_moving_window(
file_name=file_name, current_line=line_idx, moving_window=moving_window,
moving_window_size=moving_window_size, *args, **kwargs
file_name, line_idx, moving_window_size, moving_window, *args, **kwargs
)
# Now the moving window moved past the end of the file. Sections which are outside
# the file are assigned an empty string until the window has moved out of file completely
......
......@@ -10,11 +10,17 @@ DEBUG_FILE_NAME = "RingBufferAnalyzer"
class InterfaceParser(FileParser):
def __init__(self, file_list, print_table):
super().__init__(file_list)
self.count = 0
self.print_table = print_table
def _handle_file_parsing_moving_window(self, file_name: str, current_line: int,
moving_window_size: int, moving_window: list, *args,
**kwargs):
pass
def _handle_file_parsing(self, file_name: str, *args, **kwargs):
try:
file = open(file_name, 'r', encoding='utf-8')
......@@ -84,51 +90,33 @@ class ReturnValueParser(FileParser):
'HasReturnvaluesIF')})
def _handle_file_parsing(self, file_name: str, *args, **kwargs):
all_lines = self._open_file(file_name=file_name)
if len(args) == 1:
"""
Former way to parse returnvalues. Not recommended anymore
:param file_name:
:param args:
:param kwargs:
:return:
"""
if len(args) > 0:
print_truncated_entries = args[0]
else:
print_truncated_entries = False
for line_idx, line in enumerate(all_lines):
if DEBUG_FILE_NAME and DEBUG_FILE_NAME in file_name:
print(f"Moving window pre line anaylsis line {line_idx}")
print(self.moving_window)
# The moving window will start with only the bottom being in the file
if line_idx == 0:
self.moving_window[self.moving_window_size - 1] = line
# More and more of the window is inside the file now
elif line_idx < self.moving_window_size:
for idx in range(line_idx, 0, -1):
self.moving_window[self.moving_window_size - 1 - idx] = \
self.moving_window[self.moving_window_size - idx]
self.moving_window[self.moving_window_size - 1] = line
# The full window is inside the file now.
elif line_idx >= self.moving_window_size:
for idx in range(self.moving_window_size - 1):
self.moving_window[idx] = self.moving_window[idx + 1]
self.moving_window[self.moving_window_size - 1] = line
if DEBUG_FILE_NAME and DEBUG_FILE_NAME in file_name:
print(f"Moving window post line anaylsis line {line_idx}")
print(self.moving_window)
# Now the moving window moved past the end of the file. Sections which are outside
# the file are assigned an empty string until the window has moved out of file completely
for remaining_windows_idx in range(self.moving_window_size):
if DEBUG_FILE_NAME and DEBUG_FILE_NAME in file_name:
print(f"Moving window pre line analysis post EOF")
print(self.moving_window)
num_entries_to_clear = remaining_windows_idx + 1
for idx_to_clear in range(num_entries_to_clear):
self.moving_window[self.moving_window_size - 1 - idx_to_clear] = ""
for idx_to_reassign in range(self.moving_window_size - 1 - num_entries_to_clear):
self.moving_window[idx_to_reassign] = self.moving_window[idx_to_reassign + 1]
if DEBUG_FILE_NAME and DEBUG_FILE_NAME in file_name:
print(f"Moving window post line anaylsis post EOF")
print(self.moving_window)
# Clear out moving window for next cycle
self.moving_window = [""] * self.moving_window_size
# for line in all_lines:
# self.__handle_line_reading(line, file_name, print_truncated_entries)
all_lines = self._open_file(file_name=file_name)
for line in all_lines:
self.__handle_line_reading(line, file_name, print_truncated_entries)
pass
def _handle_file_parsing_moving_window(self, file_name: str, current_line: int,
moving_window_size: int, moving_window: list, *args,
**kwargs):
if "RingBufferAnalyzer" in file_name:
print("Hello!")
# print(file_name)
# Generic regex to match full returnvalue expression up until semicolon
# returnvalue_match = re.search(
# r"^[\s]*static const(?:expr)? ReturnValue_t.+?(?=;);", two_lines, re.DOTALL
# )
pass
def __handle_line_reading(self, line, file_name, print_truncated_entries: bool):
newline = line
......@@ -142,13 +130,10 @@ class ReturnValueParser(FileParser):
self.__handle_interfaceid_match(interface_id_match)
returnvalue_match = re.search(
r'^[\s]*static const(?:expr)? ReturnValue_t[\s]*([a-zA-Z_0-9]*)[\s]*=[\s]*'
r'MAKE_RETURN_CODE[\s]*\([\s]*([x0-9a-fA-F]{1,4})[\s]*\);[\t ]*(//)?([^\n]*)',
two_lines)
# Generic regex to match full returnvalue expression up until semicolon
# returnvalue_match = re.search(
# r"^[\s]*static const(?:expr)? ReturnValue_t.+?(?=;);", two_lines, re.DOTALL
#)
r'^[\s]*static const(?:expr)? ReturnValue_t[\s]*([a-zA-Z_0-9]*)[\s]*=[\s]*'
r'MAKE_RETURN_CODE[\s]*\([\s]*([x0-9a-fA-F]{1,4})[\s]*\);[\t ]*(//)?([^\n]*)',
two_lines
)
if returnvalue_match:
self.__handle_returnvalue_match(returnvalue_match, file_name, print_truncated_entries)
self.last_lines[1] = self.last_lines[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment