Commit b2f7cb79 authored by Robin Mueller's avatar Robin Mueller
Browse files

first version of mov window event parser

parent 8d86d771
......@@ -10,6 +10,8 @@ FSFW_EVENT_HEADER_INCLUDE = "#include <fsfw/events/Event.h>"
DEFAULT_MOVING_WINDOWS_SIZE = 7
SUBSYSTEM_ID_NAMESPACE = "SUBSYSTEM_ID"
EVENT_NAME_IDX = 1
class SubsystemDefinitionParser(FileParser):
def __init__(self, file_list):
......@@ -62,39 +64,66 @@ class EventParser(FileParser):
def _handle_file_parsing_moving_window(
self, file_name: str, current_line: int, moving_window_size: int, moving_window: list,
*args, **kwargs):
match1 = re.search(
r"SUBSYSTEM_ID[\s]*=[\s]*SUBSYSTEM_ID::([A-Z_0-9]*);", moving_window[self.moving_window_center_idx]
subsystem_id_assignment_match = re.search(
rf"([\w]*)[\s]*=[\s]*{SUBSYSTEM_ID_NAMESPACE}::([A-Z_0-9]*);", moving_window[self.moving_window_center_idx]
)
if match1:
self.current_id = self.interfaces[match1.group(1)][0]
# print( "Current ID: " + str(currentId) )
if subsystem_id_assignment_match:
# For now, it is assumed that there is only going to be one subsystem ID per class / source file
# if "SUBSYSTEM_ID" in subsystem_id_assignment_match.group(1):
self.current_id = self.interfaces[subsystem_id_assignment_match.group(2)][0]
self.my_id = self.return_number_from_string(self.current_id)
# Now try to look for event definitions. Moving windows allows multi line event definitions
# These two variants need to be checked
event_match = re.match(
r"static const(?:expr)? Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*event::makeEvent",
r"[\s]*static const(?:expr)?[\s]*Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*event::makeEvent[^\n]*",
moving_window[self.moving_window_center_idx]
)
regex_string = r""
macro_api_match = False
if not event_match:
event_match = re.match(
r"static const(?:expr)? Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*MAKE_EVENT",
r"[\s]*static[\s]*const(?:expr)?[\s]*Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*MAKE_EVENT[^\n]*",
moving_window[self.moving_window_center_idx]
)
if event_match:
regex_string = \
r"static const(?:expr)? Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*" \
r"event::makeEvent\(([0-9]{1,2}),[\s]*severity::([A-Z]*)\);[\t ]*(//!<)?([^\n]*)"
macro_api_match = True
if event_match:
self.__handle_event_match(
event_match=event_match, macro_api_match=macro_api_match, moving_window=moving_window,
file_name=file_name
)
def __handle_event_match(self, event_match, macro_api_match: bool, moving_window: list, file_name: str):
event_full_match = False
if ";" in event_match.group(0):
event_full_match = self.__handle_one_line_event_match(
macro_api_match=macro_api_match, moving_window=moving_window
)
# Description will be parsed separately later
description = " "
if event_full_match:
name = event_match.group(EVENT_NAME_IDX)
if macro_api_match:
full_id = (self.my_id * 100) + self.return_number_from_string(event_full_match.group(2))
severity = event_full_match.group(3)
else:
full_id = (self.my_id * 100) + self.return_number_from_string(event_full_match.group(3))
severity = event_full_match.group(4)
self.mib_table.update({full_id: (name, severity, description, file_name)})
self.count = self.count + 1
def __handle_one_line_event_match(self, macro_api_match: bool, moving_window: list):
if macro_api_match:
# One line event definition.
regex_string = \
r"static const(?:expr)? Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*" \
r"MAKE_EVENT\(([0-9]{1,2}),[\s]*severity::([A-Z]*)\)[\s]*;"
else:
regex_string = \
r"static const(?:expr)? Event[\s]*([A-Z_0-9]*)[\s]*=[\s]*" \
r"MAKE_EVENT\(([0-9]{1,2}),[\s]*severity::([A-Z]*)\);[\t ]*(//!<)?([^\n]*)"
if event_match:
if ";" in event_match.group(0):
# One line event definition.
event_full_match = re.search(regex_string, moving_window[self.moving_window_center_idx])
# Description will be parsed separately
description = " "
r"event::makeEvent\(([\w]*),[\s]*([0-9]{1,2})[\s]*,[\s]*severity::([A-Z]*)\)[\s]*;"
event_full_match = re.search(regex_string, moving_window[self.moving_window_center_idx])
return event_full_match
def _post_parsing_operation(self):
pass
......
......@@ -122,7 +122,7 @@ class ReturnValueParser(FileParser):
moving_window_size: int, moving_window: list, *args,
**kwargs):
interface_id_match = re.search(
f"{CLASS_ID_NAMESPACE}::([a-zA-Z_0-9]*)", moving_window[self.moving_window_center_idx]
rf"{CLASS_ID_NAMESPACE}::([a-zA-Z_0-9]*)", moving_window[self.moving_window_center_idx]
)
if interface_id_match:
......@@ -201,7 +201,6 @@ class ReturnValueParser(FileParser):
current_build_idx += 1
else:
return ""
print(descrip_string)
resulting_description = re.search(
r"\[EXPORT\][\s]*:[\s]*\[COMMENT\](.*)", descrip_string
)
......
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