-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Request: (fortran) Add support for FORTRAN 77 style comments #2310
Comments
Please show us some example code. |
Please see this example:
The |
Can a line in Fortran >= 90 not legitimately start with |
Fortran 90 introduced free-format that requires to use |
It sounds like we can really only support one then since we can’t know if the file is FORTRAN 90 or FORTRAN 77 - so we can’t know which rule to apply. And having two separate FORTRAN languages seems a bit much. Am I missing something? |
I'm not sure you understood. I meant in Fortran 90 can |
Fortran is quite backwards compatible. That means,
|
Ah, yes since
No solid way to tell a comment from something else. |
My example is misleading. Of course, writting in FORTRAN 77 requires fixed format, that means the first six characters of each line are reserved for line number, format descriptions, carriage control, and so on (no statements allowed). But that would require to distinguish between FORTRAN 77 and Fortran 90. FORTRAN 77 fixed format:
Fortran 90 free format:
The Wikipedia linter seems to get it right. |
Right, that's the real problem.
An interesting but not necessarily related data-point. ;-) |
Hm, this is another example of problem that can be solved by parametrized grammar. So that one using Olde Fortran can just turn on C-comments. |
When and where are you imagining you'd pass these params to the grammar? I can see that helping SOME people... but I think a lot of people just want to throw two code snippets all the wall - one of then Fortran 77 and the other Fortran 90 and it magically just works. <pre><code data-hljs-language="fortran(version:77)">... ??? Or were you imagining GLOBALLY setting such things? That's already SORTA possible if you hacked registerLanguage("fortran", fortranLangDefinition, {version: 77})
The conditional rules perhaps... but not passing the params themselves, that's something new (one idea above). |
@interkosmos Would specifying the variant (77 or 90) manually help you, or were you really just wanting it to work automagically? |
Of course everybody will prefer automagic. But looks like here we just can't do it, right? I imagined something like a rule for C-comments in grammar which tries to get a parameter value from a plug-in that handles some special event. If no plug-in registered, no parameters received. |
Passing parameters sounds like a potentially useful feature for core to me... I could imagine how you'd frankenstein it on top of plugin/callback functionality we don't have yet... but if we thought it was a good idea I think it'd be easier to support in the core lib. Having to write a plugin for the sole purpose of parametrizing a language sounds blah to me. You could also just define a configureLanguage("fortran",{version:77})
// ...
paramDefaults: {version: 90 }
// ...
{
skipThisRuleIf: (x, params) => {params.version == 77 }
...
skipThisRuleIf: (x, params) => {params.version == 90 }
} |
Although skipping entire rules dynamically starts to get complex since we aggregate the rules when we compile the grammar... but that's a technical problem... obviously it's easy to imagine in theory some simple of |
It would be totally fine to select the language version. |
Per code section or is your whole usage all one version of FORTRAN or the other? |
Per code section would be great, as this would make it possible to compare language versions. |
This also complicates testing since right now there is no way to configure detects/markup tests to pass this extra info. For example we'd really want to test both the Fortran 77 and 90 comment functionality with two different markup tests to make sure both config options work. |
At this point it's starting to sound like a separate grammar since then you could check for the spacing and give it relevancy so then you'd "detect" whether a fortran file was 77 or 90 version. I've also suggested the idea of "rollup" languages elsewhere. So that |
Can you think of other false positive scenarios? If we simply added a C =================
C This is a pretty comment with borders...
C ================== Does Fortran have a |
I was looking at arbitrary source code, but couldn’t find any other false positives.
Yes, but only inside statements (e.g., |
So if we added the following as comment patterns:
Would that get the job done? |
The white-space between |
Yeah, I figured... the final regex would allow for whitespace variance, but otherwise does that look good? |
Should work, so far. |
The style for source code in Fortran accepts only
!
as a comment identifier, not the oldC
as in FORTRAN 77 and earlier. Is it possible to treatC
as the beginning of a comment?The text was updated successfully, but these errors were encountered: