@@ -437,10 +437,10 @@ class Comment:
437437 :param reader: The reader object being used to read the input \
438438 source.
439439 :type reader: :py:class:`fparser.common.readfortran.FortranReaderBase`
440-
440+ :param inline: whether this was an inline comment.
441441 """
442442
443- def __init__ (self , comment , linenospan , reader ):
443+ def __init__ (self , comment , linenospan , reader , inline : bool = False ):
444444 self .comment = comment
445445 self .span = linenospan
446446 self .reader = reader
@@ -449,6 +449,7 @@ def __init__(self, comment, linenospan, reader):
449449 # tests as a reader can return an instance of either class and
450450 # we might want to check the contents in a consistent way.
451451 self .line = comment
452+ self .inline = inline
452453
453454 def __repr__ (self ):
454455 return self .__class__ .__name__ + "(%r,%s)" % (self .comment , self .span )
@@ -1010,9 +1011,15 @@ def multiline_item(
10101011 prefix , lines , suffix , (startlineno , endlineno ), self , errmessage
10111012 )
10121013
1013- def comment_item (self , comment , startlineno , endlineno ):
1014- """Construct Comment item."""
1015- return Comment (comment , (startlineno , endlineno ), self )
1014+ def comment_item (
1015+ self , comment , startlineno , endlineno , inline_comment : bool = False
1016+ ):
1017+ """Construct Comment item.
1018+
1019+ :param inline_comment: whether the comment is an inline comment.
1020+ Defaults to False.
1021+ """
1022+ return Comment (comment , (startlineno , endlineno ), self , inline_comment )
10161023
10171024 def cpp_directive_item (self , line , startlineno , endlineno ):
10181025 """
@@ -1245,7 +1252,14 @@ def handle_inline_comment(
12451252 newline = line [:idx ]
12461253 if '"' not in newline and "'" not in newline :
12471254 if self .format .is_f77 or not line [idx :].startswith ("!f2py" ):
1248- put_item (self .comment_item (line [idx :], lineno , lineno ))
1255+ # Its an inline comment if there is a non whitespace
1256+ # character before the comment.
1257+ is_inline = not (line .lstrip () == line [idx :])
1258+ put_item (
1259+ self .comment_item (
1260+ line [idx :], lineno , lineno , inline_comment = is_inline
1261+ )
1262+ )
12491263 return newline , quotechar , True
12501264
12511265 # We must allow for quotes...
0 commit comments