stfc / fparser

This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
https://fparser.readthedocs.io
Other
63 stars 29 forks source link

Syntax error with (superfluous) parentheses in assignment #395

Closed arporter closed 1 year ago

arporter commented 1 year ago

In NEMO 4.2, fldread.f90 contains a line:

        zdepth(:) = ((gdept_1d(:) ))

which causes fparser2 to choke. Removing all the un-needed parentheses on the RHS fixes the issue.

arporter commented 1 year ago

If I remove the space after gdept_1d(:) then the match is fine. If I change it to ((gdept_1d )) then the match is also fine. This indicates a problem with the matching of the slice notation I think.

arporter commented 1 year ago

Weirdly, (gdept_1d(:) ) is matched OK.

arporter commented 1 year ago

When match fails (because of space after gdept_1d(:):

Variable('zdepth(:)') -> 'zdepth(:)'
Name('gdept_1d') -> 'gdept_1d'
Part_Name('gdept_1d') -> 'gdept_1d'
Subscript_Triplet(':') -> ':'
Section_Subscript(':') -> ':'
Section_Subscript_List(':') -> ':'
Part_Ref('gdept_1d(:)') -> 'gdept_1d(:)'

When that space is deleted so that the match succeeds:

Variable('zdepth(:)') -> 'zdepth(:)'
Name('gdept_1d') -> 'gdept_1d'
Part_Name('gdept_1d') -> 'gdept_1d'
Subscript_Triplet(':') -> ':'
Section_Subscript(':') -> ':'
Section_Subscript_List(':') -> ':'
Part_Ref('gdept_1d(:)') -> 'gdept_1d(:)'
Name('gdept_1d') -> 'gdept_1d'
Part_Name('gdept_1d') -> 'gdept_1d'
Subscript_Triplet(':') -> ':'
Section_Subscript(':') -> ':'
Section_Subscript_List(':') -> ':'
Part_Ref('gdept_1d(:)') -> 'gdept_1d(:)'
Data_Ref('gdept_1d(:)') -> 'gdept_1d(:)'
Level_1_Expr('gdept_1d(:)') -> 'gdept_1d(:)'
Mult_Operand('gdept_1d(:)') -> 'gdept_1d(:)'
Add_Operand('gdept_1d(:)') -> 'gdept_1d(:)'
Level_2_Unary_Expr('gdept_1d(:)') -> 'gdept_1d(:)'
Level_2_Expr('gdept_1d(:)') -> 'gdept_1d(:)'
Level_3_Expr('gdept_1d(:)') -> 'gdept_1d(:)'
Level_4_Expr('gdept_1d(:)') -> 'gdept_1d(:)'
And_Operand('gdept_1d(:)') -> 'gdept_1d(:)'
Or_Operand('gdept_1d(:)') -> 'gdept_1d(:)'
Equiv_Operand('gdept_1d(:)') -> 'gdept_1d(:)'
Level_5_Expr('gdept_1d(:)') -> 'gdept_1d(:)'
Expr('gdept_1d(:)') -> 'gdept_1d(:)'
Parenthesis('(gdept_1d(:))') -> '(gdept_1d(:))'
Level_1_Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
Mult_Operand('(gdept_1d(:))') -> '(gdept_1d(:))'
Add_Operand('(gdept_1d(:))') -> '(gdept_1d(:))'
Level_2_Unary_Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
Level_2_Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
Level_3_Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
Level_4_Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
And_Operand('(gdept_1d(:))') -> '(gdept_1d(:))'
Or_Operand('(gdept_1d(:))') -> '(gdept_1d(:))'
Equiv_Operand('(gdept_1d(:))') -> '(gdept_1d(:))'
Level_5_Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
Expr('(gdept_1d(:))') -> '(gdept_1d(:))'
Parenthesis('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Level_1_Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Mult_Operand('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Add_Operand('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Level_2_Unary_Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Level_2_Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Level_3_Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Level_4_Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
And_Operand('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Or_Operand('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Equiv_Operand('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Level_5_Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Expr('((gdept_1d(:)))') -> '((gdept_1d(:)))'
Assignment_Stmt('zdepth(:) = ((gdept_1d(:)))') -> 'zdepth(:) = ((gdept_1d(:)))'