dparkins / language-fortran

Syntax highlighting for FORTRAN for atom
MIT License
35 stars 16 forks source link

Folding code doesn't follow program structure #84

Open cbcoutinho opened 7 years ago

cbcoutinho commented 7 years ago

Atom correctly indents different statements within a module or subroutine as expected. The contain statement is also indented at the level of the procedure it is contained, which I didn't expect but I actually really like:

screenshot from 2016-10-17 23-12-11

The issue is, when folding code that contains a contain statement, the folding stops at the contain statement instead of down to where it should fold at end module. This seems to me like atom is repeating some behavior I would expect from python, where everything is progressively nested; however in Fortran that isn't the case.

See gif:

out

tomedunn commented 7 years ago

Thanks for posting. I've been aware of this issue for some time but last I checked code folding is not something that can be altered via a languages syntax rules. It's possible there have been some improvements since I last looked so I'll look into it to see if any improvements can be made. Otherwise the only option is to have the rules for indenting not indent contains, since code folding in Atom in based entirely on indentation levels, but I rather like how it looks.

cbcoutinho commented 7 years ago

you seem to be pretty up-to-date on this issue: thread

I also found a related open atom issue here: atom/atom#11838

I guess this is just going to be the way it is until atom is changed upstream. I agree, you should keep the way contain is currently indented.

EDIT: Oops, I accidentally closed this issue. My bad.

stadelmanma commented 6 years ago

I think this is a fix for this in the works via PR https://github.com/atom/atom/pull/16299 but we would need to write a tree-sitter-parser for the Fortran language (unless one already exists). I don't know what all is required to do that but given Fortran's relatively concise syntax and set of keywords I don't think it would be that bad compared to a language like Python or Ruby for which parsers already exist.

Arcanemagus commented 6 years ago

@stadelmanma You can see basic instructions for creating a grammar here: https://github.com/tree-sitter/tree-sitter#writing-a-grammar

You can find full examples in the languages linked from https://github.com/atom/atom/pull/16299 as those are the ones most likely to be fully up to date.

stadelmanma commented 6 years ago

@Arcanemagus thanks for the links, I've been doing some reading on logic behind how TreeSitter works to get a better handle on things. Although, I wonder how a grammar would handle the minor differences between fixed and free form Fortran (i.e. comments, and line continuation).

I found some old docs on a context free grammar for fortran 90/77 but I'm not sure how useful it will be. http://eli-project.sourceforge.net/fortran_html/Parse.html http://slebok.github.io/zoo/fortran/f90/waite-cordy/extracted/index.html