Skip to content

Commit

Permalink
depgen.py: homogenize classnames and filenames.
Browse files Browse the repository at this point in the history
  • Loading branch information
skosukhin committed Apr 25, 2024
1 parent 69ce2da commit 94ccd6a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions mkhelper/depgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions mkhelper/depgen/fortran_parser.py → mkhelper/depgen/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*&")
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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 ""
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mkhelper/depgen/line_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
20 changes: 10 additions & 10 deletions mkhelper/depgen/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|\().*)")

Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 94ccd6a

Please sign in to comment.