From 94ccd6ae4471d6f9c166b38bde6b1144f99265bf Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Thu, 25 Apr 2024 16:23:49 +0200 Subject: [PATCH] depgen.py: homogenize classnames and filenames. --- mkhelper/depgen.py | 12 +++++------ .../depgen/{fortran_parser.py => fortran.py} | 18 ++++++++--------- mkhelper/depgen/line_control.py | 4 ++-- mkhelper/depgen/preprocessor.py | 20 +++++++++---------- 4 files changed, 27 insertions(+), 27 deletions(-) rename mkhelper/depgen/{fortran_parser.py => fortran.py} (94%) diff --git a/mkhelper/depgen.py b/mkhelper/depgen.py index 2c896ba..0a3208c 100755 --- a/mkhelper/depgen.py +++ b/mkhelper/depgen.py @@ -462,9 +462,9 @@ def format_debug_line(line, msg): parser = None if args.pp_enable: - from depgen.preprocessor import Preprocessor + from depgen.preprocessor import Parser - parser = Preprocessor( + parser = Parser( include_order=args.pp_inc_order, include_sys_order=args.pp_inc_sys_order, include_dirs=args.pp_inc_dirs, @@ -484,9 +484,9 @@ def format_debug_line(line, msg): ) if args.lc_enable: - from depgen.line_control import LCProcessor + from depgen.line_control import Parser - parser = LCProcessor(include_roots=args.src_roots, subparser=parser) + parser = Parser(include_roots=args.src_roots, subparser=parser) parser.lc_callback = lambda filename: lc_files.add(filename) if args.debug: @@ -496,9 +496,9 @@ def format_debug_line(line, msg): ) if args.fc_enable: - from depgen.fortran_parser import FortranParser + from depgen.fortran import Parser - parser = FortranParser( + parser = Parser( include_order=args.fc_inc_order, include_dirs=args.fc_inc_dirs, include_roots=args.src_roots, diff --git a/mkhelper/depgen/fortran_parser.py b/mkhelper/depgen/fortran.py similarity index 94% rename from mkhelper/depgen/fortran_parser.py rename to mkhelper/depgen/fortran.py index 128528f..aa96f5c 100644 --- a/mkhelper/depgen/fortran_parser.py +++ b/mkhelper/depgen/fortran.py @@ -39,7 +39,7 @@ ) -class FortranParser: +class Parser: _re_include = re.compile(r'^\s*include\s+([\'"])(.*?)\1', re.I) _re_line_continue_start = re.compile(r"^(.*)&\s*$") _re_line_continue_end = re.compile(r"^\s*&") @@ -93,9 +93,9 @@ def parse(self, stream, stream_name): include_stack = StreamStack() include_stack.push(stream, stream_name) - for line in FortranParser.streamline_input(include_stack): + for line in Parser.streamline_input(include_stack): # module definition start - match = FortranParser._re_module_start.match(line) + match = Parser._re_module_start.match(line) if match: module_name = match.group(1).lower() if self.module_start_callback: @@ -107,7 +107,7 @@ def parse(self, stream, stream_name): continue # submodule definition start - match = FortranParser._re_submodule_start.match(line) + match = Parser._re_submodule_start.match(line) if match: module_name = match.group(1).lower() parent_name = match.group(2) @@ -134,7 +134,7 @@ def parse(self, stream, stream_name): continue # module used - match = FortranParser._re_module_use.match(line) + match = Parser._re_module_use.match(line) if match: module_nature = ( match.group(1).lower() if match.group(1) is not None else "" @@ -179,7 +179,7 @@ def parse(self, stream, stream_name): continue # include statement - match = FortranParser._re_include.match(line) + match = Parser._re_include.match(line) if match: filename = match.group(2) filepath = self._include_finder.find( @@ -217,11 +217,11 @@ def parse(self, stream, stream_name): @staticmethod def streamline_input(stream): - stream = FortranParser.drop_comments_and_empty_lines(stream) + stream = Parser.drop_comments_and_empty_lines(stream) for line in stream: # concatenate lines while 1: - match = FortranParser._re_line_continue_start.match(line) + match = Parser._re_line_continue_start.match(line) if not match: break @@ -230,7 +230,7 @@ def streamline_input(stream): break line = match.group(1) + re.sub( - FortranParser._re_line_continue_end, "", next_line + Parser._re_line_continue_end, "", next_line ) # split semicolons diff --git a/mkhelper/depgen/line_control.py b/mkhelper/depgen/line_control.py index 02a2655..b49b306 100644 --- a/mkhelper/depgen/line_control.py +++ b/mkhelper/depgen/line_control.py @@ -34,7 +34,7 @@ from depgen import file_in_dir -class LCProcessor: +class Parser: _re_lc = re.compile(r'^#\s*[1-9]\d*\s*"(.*?)"\s*(?:[1-9]\d*)?') def __init__(self, include_roots=None, subparser=None): @@ -52,7 +52,7 @@ def parse(self, stream, stream_name): stream = self._get_stream_iterator(stream, stream_name) for line in stream: - match = LCProcessor._re_lc.match(line) + match = Parser._re_lc.match(line) if match: filepath = match.group(1) if os.path.isfile(filepath): diff --git a/mkhelper/depgen/preprocessor.py b/mkhelper/depgen/preprocessor.py index 6f05917..bd7b54a 100644 --- a/mkhelper/depgen/preprocessor.py +++ b/mkhelper/depgen/preprocessor.py @@ -39,7 +39,7 @@ ) -class Preprocessor: +class Parser: _re_ifdef = re.compile(r"^\s*#\s*if(n)?def\s+([a-zA-Z_]\w*)") _re_if_expr = re.compile(r"^\s*#\s*if((?:\s|\().*)") @@ -90,9 +90,9 @@ def parse(self, stream, stream_name): branch_state = BranchState() macro_handler = MacroHandler(self._predefined_macros) - for line in Preprocessor.streamline_input(include_stack): + for line in Parser.streamline_input(include_stack): # if(n)def directive - match = Preprocessor._re_ifdef.match(line) + match = Parser._re_ifdef.match(line) if match: macro, negate, state = match.group(2), bool(match.group(1)), 0 if not branch_state.is_dead(): @@ -107,7 +107,7 @@ def parse(self, stream, stream_name): continue # if directive - match = Preprocessor._re_if_expr.match(line) + match = Parser._re_if_expr.match(line) if match: expr, state = match.group(1), 0 if not branch_state.is_dead(): @@ -132,7 +132,7 @@ def parse(self, stream, stream_name): continue # elif directive - match = Preprocessor._re_elif.match(line) + match = Parser._re_elif.match(line) if match: branch_state.switch_else() expr, state = match.group(1), 0 @@ -158,13 +158,13 @@ def parse(self, stream, stream_name): continue # else directive - match = Preprocessor._re_else.match(line) + match = Parser._re_else.match(line) if match: branch_state.switch_else() continue # endif directive - match = Preprocessor._re_endif.match(line) + match = Parser._re_endif.match(line) if match: branch_state.switch_endif() continue @@ -173,7 +173,7 @@ def parse(self, stream, stream_name): continue # define directive - match = Preprocessor._re_define.match(line) + match = Parser._re_define.match(line) if match: if not branch_state.is_dead(): macro_handler.define(*match.group(1, 2, 3)) @@ -184,7 +184,7 @@ def parse(self, stream, stream_name): continue # undef directive - match = Preprocessor._re_undef.match(line) + match = Parser._re_undef.match(line) if match: if not branch_state.is_dead(): macro_handler.undefine(match.group(1)) @@ -195,7 +195,7 @@ def parse(self, stream, stream_name): continue # include directive - match = Preprocessor._re_include.match(line) + match = Parser._re_include.match(line) if match: if not branch_state.is_dead(): if match.lastindex == 1: # quoted form