Skip to content

Commit

Permalink
Merge pull request #669 from d7919/patch-9
Browse files Browse the repository at this point in the history
Don't store sub-groups where not needed in regex and other processing optimisations
  • Loading branch information
ZedThree authored Nov 20, 2024
2 parents 5b97d67 + fa67ed1 commit 8b9fbb6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ford/sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ class FortranBase:

POINTS_TO_RE = re.compile(r"\s*=>\s*", re.IGNORECASE)
SPLIT_RE = re.compile(r"\s*,\s*", re.IGNORECASE)
SRC_CAPTURE_STR = r"^[ \t]*([\w(),*: \t]+?[ \t]+)?{0}([\w(),*: \t]+?)?[ \t]+{1}[ \t\n,(].*?end[ \t]*{0}[ \t]+{1}[ \t]*?(!.*?)?$"

pretty_obj = {
"proc": "procedures",
Expand Down Expand Up @@ -443,8 +442,15 @@ def markdown(self, md: MetaMarkdown):
if self.obj in ["proc", "type", "program"] and self.meta.source:
obj = getattr(self, "proctype", self.obj).lower()
regex = re.compile(
self.SRC_CAPTURE_STR.format(obj, self.name),
re.IGNORECASE | re.DOTALL | re.MULTILINE,
fr"""
^(?:[\w(),*: \t]*?)? # Attributes, function type
\b{obj}\b # Subroutine/function
(?:[\w(),*: \t]+?)?[ \t]+ # Interstitial nonsense
\b{self.name}\b[ \t\n,(].*? # Entity name
^[ \t]*\bend[ \t]*{obj}\b[ \t]+\b{self.name}\b[ \t]*? # End statement
(?:!.*?)?$
""",
re.IGNORECASE | re.DOTALL | re.MULTILINE | re.VERBOSE,
)
if match := regex.search(self.source_file.raw_src):
self.src = highlight(
Expand Down

0 comments on commit 8b9fbb6

Please sign in to comment.