Skip to content

Commit 7d396b6

Browse files
authored
Merge pull request #504 from stfc/503_more_efficient_cpp_parsing
#503 Remove unnecessary tests for preprocessor directives.
2 parents a197a85 + bd50fc6 commit 7d396b6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ Modifications by (in alphabetical order):
2222
* P. Vitt, University of Siegen, Germany
2323
* A. Voysey, UK Met Office
2424

25+
26+
27/04/2026 PR #504 for #503. Improve preprocessor directives parsing.
27+
28+
## Release 0.2.2 (19/03/2026) ##
29+
2530
19/03/2026 PR #496. Add support for F2008 unlimited-format-item.
2631

2732
13/03/2026 PR #495 for #494. Fix CI issues with the black formatting check.

src/fparser/two/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,14 @@ def match(
712712
if reader.process_directives:
713713
comments.insert(0, di.Directive)
714714
classes = subclasses + comments
715-
# Preprocessor directives are always valid sub-classes
716-
cpp_classes = [
717-
getattr(di.C99Preprocessor, cls_name)
718-
for cls_name in di.C99Preprocessor.CPP_CLASS_NAMES
719-
]
720-
classes += cpp_classes
721715
if endcls is not None:
722716
classes += [endcls]
723717
endcls_all = tuple([endcls] + endcls.subclasses[endcls.__name__])
718+
# Preprocessor directives are always valid sub-classes. While
719+
# `match_cpp_directive` is a function, it behaves correctly here
720+
# returning either None or an instance, so we can just add it to
721+
# the classes that will be tested.
722+
classes.append(di.C99Preprocessor.match_cpp_directive)
724723

725724
try:
726725
# Start trying to match the various subclasses, starting from

0 commit comments

Comments
 (0)