diff --git a/fsfwgen/events/event_parser.py b/fsfwgen/events/event_parser.py index 2f1ca07..bc99358 100644 --- a/fsfwgen/events/event_parser.py +++ b/fsfwgen/events/event_parser.py @@ -3,7 +3,7 @@ import logging from pathlib import Path from typing import List, Optional, Dict -from fsfwgen.parserbase.parser import FileParser +from fsfwgen.parserbase.parser import FileParser, MetaType _LOGGER = logging.getLogger(__name__) @@ -147,10 +147,16 @@ class EventParser(FileParser): event_full_match = self.__generate_regex_event_match( macro_api_match=macro_api_match, full_string=multi_line_string ) - description = self._search_for_descrip_string_generic( + description = "No description" + meta_list = self._search_for_descrip_string_generic( moving_window=moving_window, break_pattern=r"[\s]*static const(?:expr)?[\s]*Event[\s]*", ) + for meta in meta_list: + if meta.type == MetaType.SKIP: + return + elif meta.type == MetaType.DESC: + description = meta.value if event_full_match: name = event_match.group(EVENT_NAME_IDX) if macro_api_match: diff --git a/fsfwgen/parserbase/parser.py b/fsfwgen/parserbase/parser.py index 37ec601..0e484f5 100644 --- a/fsfwgen/parserbase/parser.py +++ b/fsfwgen/parserbase/parser.py @@ -11,6 +11,7 @@ Child classes fill out the MIB table (self.mib_table) @author R. Mueller @date 14.11.2019 """ +import dataclasses import enum import re from abc import abstractmethod @@ -30,6 +31,17 @@ class FileParserModes(Enum): MOVING_WINDOW = 2 +class MetaType(enum.IntEnum): + SKIP = 1 + DESC = 2 + + +@dataclasses.dataclass +class MetaInfo: + type: MetaType + value: str = "" + + class FileParser: """ This parent class gathers common file parser operations into a super class. @@ -250,36 +262,40 @@ class FileParser: def _search_for_descrip_string_generic( self, moving_window: List[str], break_pattern: str - ) -> str: + ) -> List[MetaInfo]: current_idx = self._moving_window_center_idx - 1 # Look at the line above first - descrip_match = re.search( - r"\[EXPORT][\s]*:[\s]*\[COMMENT]", moving_window[current_idx] + export_match = re.search( + r"\[EXPORT]\s*:\s*\[(\w*)]", moving_window[current_idx] ) - if not descrip_match: + if not export_match: while True: if re.search(break_pattern, moving_window[current_idx]): break - descrip_match = re.search( - r"\[EXPORT][\s]*:[\s]*\[COMMENT]", moving_window[current_idx] + export_match = re.search( + r"\[EXPORT]\s*:\s*\[(\w*)]", moving_window[current_idx] ) - if descrip_match or current_idx <= 0: + if export_match or current_idx <= 0: break current_idx -= 1 - if descrip_match: - current_build_idx = current_idx - descrip_string = "" - while current_build_idx < self._moving_window_center_idx: - string_to_add = moving_window[current_build_idx].lstrip() - string_to_add = string_to_add.lstrip("//!<>") - string_to_add = string_to_add.rstrip() - descrip_string += string_to_add - current_build_idx += 1 - else: - return "" - resulting_description = re.search( - r"\[EXPORT][\s]*:[\s]*\[COMMENT][\s](.*)", descrip_string - ) - if resulting_description: - return resulting_description.group(1) - return "" + info = MetaInfo(MetaType.DESC) + if export_match: + if export_match.group(1).lower() == "comment": + current_build_idx = current_idx + descrip_string = "" + while current_build_idx < self._moving_window_center_idx: + string_to_add = moving_window[current_build_idx].lstrip() + string_to_add = string_to_add.lstrip("//!<>") + string_to_add = string_to_add.rstrip() + descrip_string += string_to_add + current_build_idx += 1 + resulting_description = re.search( + r"\[EXPORT]\s*:\s*\[\w*]\s(.*)", descrip_string + ) + if resulting_description: + info.value = resulting_description.group(1) + + elif export_match.group(1).lower() == "skip": + info.type = MetaType.SKIP + return [info] + return [] diff --git a/fsfwgen/returnvalues/returnvalues_parser.py b/fsfwgen/returnvalues/returnvalues_parser.py index 57a5af8..4e22dd4 100644 --- a/fsfwgen/returnvalues/returnvalues_parser.py +++ b/fsfwgen/returnvalues/returnvalues_parser.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from pathlib import Path from typing import List, Optional, Dict -from fsfwgen.parserbase.parser import FileParser, VerbosityLevels +from fsfwgen.parserbase.parser import FileParser, VerbosityLevels, MetaInfo, MetaType from fsfwgen.utility.printer import PrettyPrinter _LOGGER = logging.getLogger(__name__) @@ -339,7 +339,13 @@ class ReturnValueParser(FileParser): else: number_match = get_number_from_dec_or_hex_str(returnvalue_match.group(3)) if returnvalue_match: - description = self.__search_for_descrip_string(moving_window=moving_window) + description = "No description" + meta_list = self.__search_for_descrip_string(moving_window=moving_window) + for meta in meta_list: + if meta.type == MetaType.DESC: + description = meta.value + elif meta.type == MetaType.SKIP: + return if number_match == INVALID_IF_ID: _LOGGER.warning(f"Invalid number match detected for file {file_name}") _LOGGER.warning(f"Match groups:") @@ -359,7 +365,7 @@ class ReturnValueParser(FileParser): first_line=first_line, moving_window=moving_window ) - def __search_for_descrip_string(self, moving_window: List[str]) -> str: + def __search_for_descrip_string(self, moving_window: List[str]) -> List[MetaInfo]: return self._search_for_descrip_string_generic( moving_window=moving_window, break_pattern=r"^[\s]*static const(?:expr)? ReturnValue_t",