add support for for skipping retvals and events

This commit is contained in:
Robin Müller 2023-02-19 12:58:08 +01:00
parent 98ecaba93a
commit 1f1d7ab62a
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 57 additions and 29 deletions

View File

@ -3,7 +3,7 @@ import logging
from pathlib import Path from pathlib import Path
from typing import List, Optional, Dict from typing import List, Optional, Dict
from fsfwgen.parserbase.parser import FileParser from fsfwgen.parserbase.parser import FileParser, MetaType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -147,10 +147,16 @@ class EventParser(FileParser):
event_full_match = self.__generate_regex_event_match( event_full_match = self.__generate_regex_event_match(
macro_api_match=macro_api_match, full_string=multi_line_string 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, moving_window=moving_window,
break_pattern=r"[\s]*static const(?:expr)?[\s]*Event[\s]*", 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: if event_full_match:
name = event_match.group(EVENT_NAME_IDX) name = event_match.group(EVENT_NAME_IDX)
if macro_api_match: if macro_api_match:

View File

@ -11,6 +11,7 @@ Child classes fill out the MIB table (self.mib_table)
@author R. Mueller @author R. Mueller
@date 14.11.2019 @date 14.11.2019
""" """
import dataclasses
import enum import enum
import re import re
from abc import abstractmethod from abc import abstractmethod
@ -30,6 +31,17 @@ class FileParserModes(Enum):
MOVING_WINDOW = 2 MOVING_WINDOW = 2
class MetaType(enum.IntEnum):
SKIP = 1
DESC = 2
@dataclasses.dataclass
class MetaInfo:
type: MetaType
value: str = ""
class FileParser: class FileParser:
""" """
This parent class gathers common file parser operations into a super class. This parent class gathers common file parser operations into a super class.
@ -250,36 +262,40 @@ class FileParser:
def _search_for_descrip_string_generic( def _search_for_descrip_string_generic(
self, moving_window: List[str], break_pattern: str self, moving_window: List[str], break_pattern: str
) -> str: ) -> List[MetaInfo]:
current_idx = self._moving_window_center_idx - 1 current_idx = self._moving_window_center_idx - 1
# Look at the line above first # Look at the line above first
descrip_match = re.search( export_match = re.search(
r"\[EXPORT][\s]*:[\s]*\[COMMENT]", moving_window[current_idx] r"\[EXPORT]\s*:\s*\[(\w*)]", moving_window[current_idx]
) )
if not descrip_match: if not export_match:
while True: while True:
if re.search(break_pattern, moving_window[current_idx]): if re.search(break_pattern, moving_window[current_idx]):
break break
descrip_match = re.search( export_match = re.search(
r"\[EXPORT][\s]*:[\s]*\[COMMENT]", moving_window[current_idx] r"\[EXPORT]\s*:\s*\[(\w*)]", moving_window[current_idx]
) )
if descrip_match or current_idx <= 0: if export_match or current_idx <= 0:
break break
current_idx -= 1 current_idx -= 1
if descrip_match: info = MetaInfo(MetaType.DESC)
current_build_idx = current_idx if export_match:
descrip_string = "" if export_match.group(1).lower() == "comment":
while current_build_idx < self._moving_window_center_idx: current_build_idx = current_idx
string_to_add = moving_window[current_build_idx].lstrip() descrip_string = ""
string_to_add = string_to_add.lstrip("//!<>") while current_build_idx < self._moving_window_center_idx:
string_to_add = string_to_add.rstrip() string_to_add = moving_window[current_build_idx].lstrip()
descrip_string += string_to_add string_to_add = string_to_add.lstrip("//!<>")
current_build_idx += 1 string_to_add = string_to_add.rstrip()
else: descrip_string += string_to_add
return "" current_build_idx += 1
resulting_description = re.search( resulting_description = re.search(
r"\[EXPORT][\s]*:[\s]*\[COMMENT][\s](.*)", descrip_string r"\[EXPORT]\s*:\s*\[\w*]\s(.*)", descrip_string
) )
if resulting_description: if resulting_description:
return resulting_description.group(1) info.value = resulting_description.group(1)
return ""
elif export_match.group(1).lower() == "skip":
info.type = MetaType.SKIP
return [info]
return []

View File

@ -5,7 +5,7 @@ from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import List, Optional, Dict 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 from fsfwgen.utility.printer import PrettyPrinter
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -339,7 +339,13 @@ class ReturnValueParser(FileParser):
else: else:
number_match = get_number_from_dec_or_hex_str(returnvalue_match.group(3)) number_match = get_number_from_dec_or_hex_str(returnvalue_match.group(3))
if returnvalue_match: 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: if number_match == INVALID_IF_ID:
_LOGGER.warning(f"Invalid number match detected for file {file_name}") _LOGGER.warning(f"Invalid number match detected for file {file_name}")
_LOGGER.warning(f"Match groups:") _LOGGER.warning(f"Match groups:")
@ -359,7 +365,7 @@ class ReturnValueParser(FileParser):
first_line=first_line, moving_window=moving_window 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( return self._search_for_descrip_string_generic(
moving_window=moving_window, moving_window=moving_window,
break_pattern=r"^[\s]*static const(?:expr)? ReturnValue_t", break_pattern=r"^[\s]*static const(?:expr)? ReturnValue_t",