satamas / fortran-plugin

Fortran language plugin for IntelliJ Idea
Apache License 2.0
81 stars 18 forks source link

legacy f77 code is not detected with spaces #41

Closed kostyfisik closed 5 years ago

kostyfisik commented 5 years ago

This code compiles and works well, however, T H E N end E L S E statements are not detected\colored\folded.

      ALPHA=SQRT(DFLOAT((L-M)*(L+M+1)))/2.D0  
      BETA =SQRT(DFLOAT((L+M)*(L-M+1)))/2.D0  
      IF(ABS(M+1).LE.L)  T H E N  
      I=L*L+L+M+2  
      Z1=YLM(I)  
                         E L S E  
      Z1=CZERO  
                         E N D    I F  
      IF(ABS(M-1).LE.L)  T H E N  
      I=L*L+L+M  
      Z2=YLM(I)  
                         E L S E  
      Z2=CZERO  
                         E N D    I F  
      I=L*L+L+M+1  
      Z3=YLM(I)  
      DLMH(1,II)=COEF*(BETA*CT*CF*Z2-DFLOAT(M)*ST*Z3 

Screenshot from 2019-06-05 11-26-27

satamas commented 5 years ago

That's won't fix kind of issue. I do know that we don't folow fortran spec in part of spaces, but we've did it intentionally. This language feature is one of those features that's extreamly complex to support by modern lexer/parser and at the same time it's usage should be eliminated from supported code (from my point of view), so marking this as an error is rather reasonable.

kostyfisik commented 5 years ago

Ok. I just though that it can be some kind of pre-parser module, which search for space separated keywords and pass the normalized code to the lexer/parser. This special spaces-handling should probably be presented in top-level readme.

Does it mean that converting this type of code to free form by the plugin may generate a wrong working programm?

satamas commented 5 years ago

I just though that it can be some kind of pre-parser module, which search for space separated keywords and pass the normalized code to the lexer/parser

I think that this example shows that there is no good way of parsing fortran code when spaces are ignored. Also you should take into account that one can use keyword as variable name or split keyword token between lines.

This special spaces-handling should probably be presented in top-level readme.

Yes, sounds reasonable, I'll update readme

Does it mean that converting this type of code to free form by the plugin may generate a wrong working programm?

As far as I see it shouldn't. Conversion depends only on PsiComment elements and it's rather hard to break comment parsing.

kostyfisik commented 5 years ago

See #42 for conversion problem.