fparser
fparser copied to clipboard
Naming of block constructs not well reproduced by `repr` methods.
In #392, Sergi pointed out that doing repr of a matched block construct gave confusing information on the name.
However, it turns out that this is already true of the Block_Label_Do_Construct, e.g. test_block_nonlabel_do_construct has:
obj = tcls(
get_reader(
"""\
foo:do i=1,10
a = 1
end do foo
"""
)
)
and obj is:
Block_Nonlabel_Do_Construct(Nonlabel_Do_Stmt('DO', Loop_Control(None, (Name('i'), [Int_Literal_Constant('1', None), Int_Literal_Constant('10', None)]), None)), Assignment_Stmt(Name('a'), '=', Int_Literal_Constant('1', None)), End_Do_Stmt('DO', Name('foo')))
i.e., the name 'foo' only appears in the End_Do_Stmt and not in the Nonlabel_Do_Stmt. The difficulty is that the label ('foo' in this case) remains an attribute of the Line object constructed by the reader and is not available within the match method. This Line object is only added to an object (under the item attribute) after it has been constructed following a successful match.