-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding strict order statements (closes #353) #358
base: master
Are you sure you want to change the base?
Changes from all commits
f532b42
8b90bc0
2c831c3
c20d9e1
3eb33d4
0f7b914
77e0b10
800af82
8b371f4
b7b4f27
e4baa7f
e4efa6a
9f0dcbc
365a80d
512cdfe
2fea1f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -619,6 +619,7 @@ def match( | |
enable_where_construct_hook=False, | ||
strict_order=False, | ||
strict_match_names=False, | ||
once_only=False, | ||
): | ||
""" | ||
Checks whether the content in reader matches the given | ||
|
@@ -642,6 +643,9 @@ def match( | |
given subclasses. | ||
:param bool strict_match_names: if start name present, end name \ | ||
must exist and match. | ||
:param bool once_only: whether to restrict matching to at most \ | ||
once for a subclass. This is only active if strict_order is \ | ||
also set. | ||
|
||
:return: instance of startcls or None if no match is found | ||
:rtype: startcls | ||
|
@@ -690,18 +694,14 @@ def match( | |
if match_names: | ||
start_name = obj.get_start_name() | ||
|
||
# Comments and Include statements are always valid sub-classes | ||
classes = subclasses + [di.Comment, di.Include_Stmt] | ||
# 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 | ||
classes = subclasses | ||
if endcls is not None: | ||
classes += [endcls] | ||
endcls_all = tuple([endcls] + endcls.subclasses[endcls.__name__]) | ||
|
||
# Deal with any preceding comments, includes, and/or directives | ||
DynamicImport.add_comments_includes_directives(content, reader) | ||
|
||
try: | ||
# Start trying to match the various subclasses, starting from | ||
# the beginning of the list (where else?) | ||
|
@@ -769,11 +769,11 @@ def match( | |
reader, | ||
f"Name '{end_name}' has no corresponding starting name", | ||
) | ||
elif strict_match_names and start_name and not end_name: | ||
if strict_match_names and start_name and not end_name: | ||
raise FortranSyntaxError( | ||
reader, f"Expecting name '{start_name}' but none given" | ||
) | ||
elif ( | ||
if ( | ||
start_name | ||
and end_name | ||
and (start_name.lower() != end_name.lower()) | ||
|
@@ -785,9 +785,18 @@ def match( | |
# We've found the enclosing end statement so break out | ||
found_end = True | ||
break | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly yours but since we're here pylint complains that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified. |
||
# Deal with any following comments, includes, and/or directives | ||
DynamicImport.add_comments_includes_directives(content, reader) | ||
|
||
if not strict_order: | ||
# Return to start of classes list now that we've matched. | ||
i = 0 | ||
elif once_only: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest a comment: we had a match for this sub-class and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment. |
||
# There was a match for this sub-class and | ||
# once_only is set so move on to the next | ||
# sub-class | ||
i += 1 | ||
if enable_if_construct_hook: | ||
if isinstance(obj, di.Else_If_Stmt): | ||
# Got an else-if so go back to start of possible | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each sub-class can only match once for a valid module? (I initially got worried that this wouldn't work for multiple modules in a file but it's fine.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a Module can only contain one Module_Stmt, one Specification_Part, one Module_Subprogram_Part and one End_Module_Stmt. Multiple modules are supported in 'higher level' rules, such as Program_Unit.