Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Adding flags for specific Fortran standard. #16

Open
phn opened this issue Jun 30, 2016 · 3 comments
Open

Feature request: Adding flags for specific Fortran standard. #16

phn opened this issue Jun 30, 2016 · 3 comments

Comments

@phn
Copy link

phn commented Jun 30, 2016

Hello,

Thanks for this plugin. It makes writing Fortran much easier!

Is there a way to add flags for specific Fortran standard say, based on file extension?

For example if the file is name.f03 I would like to add " -std='f2003' " , and so on. The default for
gfortran is " -std='gnu' '".

I noticed that I can write Fortran 2003 array literals such as [1, 2, 3] in f95 file and I don't get error from the linter, probably since "-std='gnu' " supports it. I do get error from gfortran when I compile it with
"-std='f95'". I would like to be very specific about the standard used and avoid compiler extensions if
possible.

Regards,
Prasanth

@315234
Copy link
Collaborator

315234 commented Jun 30, 2016

It is definitely possible to add these extra flags for the linter, as described in the Readme.md.

Automatically adding the correct flags for each version based on file extension is a little more difficult. Currently there is no granularity in Fortran syntax versions beyond Fixed-Form and Modern (i.e. Free-Form). The appropriate linter is selected based on the current syntax.

I can think of two potential approaches:

  • Modify the linter to detect the file ending and apply the appropriate flags. I'm not keen on this because it would mean applying strict standards by default, and most people do not write strict code in my experience. At the very least this would need a package setting (off by default) to enable this behaviour.
  • Add new syntax definitions and new linters for each file type, which would let you set custom options for each linter. I think this would make the linter options even more confusing than they currently are.

I don't know that there is any advantage to rigidly sticking to each standard definition, and most people seem to agree that the use of .f03, .f08 etc is a bad idea. Therefore I'm not keen on making this a major feature of this package at the risk of complicating it.

I will have a think about approach 1 above and see if it can't be made workable with a setting like "fortran_std_from_filename": true you could toggle. This would only apply to the linter though, not the syntax highlighting.

@phn
Copy link
Author

phn commented Jun 30, 2016

Hello,

Thanks for your feedback and for the links. I am just learning modern Fortran and wasn't aware of the
potential issue with relying on "file extension for standard".

What I was looking for was just an easy way to set the "std" flag so that I know exactly what features are available, and not end up unknowingly using a feature that is a compiler extension. My guess
is that any code I write will have better chances of being portable if I stick to a standard and
not use compiler extensions.

I do this in my Makefile, and was looking to see if the linter can also do it easily.

It seemed that this could be done in SublimeText via file endings; but as you point out this may be
a bad idea.

I like your idea about "fortran_std_from_filename": true. Let it be false by default and if
someone wants it they can set it to true.

Just an idea: Is it possible for the linter to parse flags directly from a comment line, say at the top of the file. Then a user can specify flags per file, and continue using "filename.f90" no matter what
standard they use.

But this is not an urgent need, as I can always set flags in settings, and sublime text makes it very easy
to play with settings. Thanks again for your time.

Regards,
Prasanth

@315234
Copy link
Collaborator

315234 commented Jun 30, 2016

code I write will have better chances of being portable if I stick to a standard and
not use compiler extensions

I agree. For now you could set -std=f2003 in the linter settings for all free-form documents. Those features should be pretty widely supported by now. I think the major compilers are all at different stages of f2008 implementation, but that is also an option.

Is it possible for the linter to parse flags directly from a comment line

Should be possible, and that is one option. I will have a think about what the best solution could be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants