diff --git a/CHANGELOG.md b/CHANGELOG.md index 2971f7ef..b477165f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,11 @@ Modifications by (in alphabetical order): * P. Vitt, University of Siegen, Germany * A. Voysey, UK Met Office + +27/04/2026 PR #504 for #503. Improve preprocessor directives parsing. + +## Release 0.2.2 (19/03/2026) ## + 19/03/2026 PR #496. Add support for F2008 unlimited-format-item. 13/03/2026 PR #495 for #494. Fix CI issues with the black formatting check. diff --git a/src/fparser/two/utils.py b/src/fparser/two/utils.py index 7a179d2e..a2f3e3b7 100644 --- a/src/fparser/two/utils.py +++ b/src/fparser/two/utils.py @@ -712,15 +712,14 @@ def match( if reader.process_directives: comments.insert(0, di.Directive) classes = subclasses + comments - # Preprocessor directives are always valid sub-classes - cpp_classes = [ - getattr(di.C99Preprocessor, cls_name) - for cls_name in di.C99Preprocessor.CPP_CLASS_NAMES - ] - classes += cpp_classes if endcls is not None: classes += [endcls] endcls_all = tuple([endcls] + endcls.subclasses[endcls.__name__]) + # Preprocessor directives are always valid sub-classes. While + # `match_cpp_directive` is a function, it behaves correctly here + # returning either None or an instance, so we can just add it to + # the classes that will be tested. + classes.append(di.C99Preprocessor.match_cpp_directive) try: # Start trying to match the various subclasses, starting from