Improve the Fortran fixed format syntax highlighting
ClosedPublic

Authored by nononux on Jul 3 2019, 8:11 PM.

Details

Summary

3 improvements:

  • Restore the comment highlighting when using the "!" character (comment all the line after the !, works whatever the position of the !)
  • The characters after the 72th column are highlighted as comments (they are ignored by the compiler)
  • The continuation character is highlighted (5 firsts characters are blank and the 6th is not blank and not a number, usually "&" or "*")
Test Plan

Check the updated autotests/input/highlight.f

Diff Detail

Repository
R216 Syntax Highlighting
Branch
fortran-fixed-format (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 13655
Build 13673: arc lint + arc unit
nononux created this revision.Jul 3 2019, 8:11 PM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptJul 3 2019, 8:11 PM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
nononux requested review of this revision.Jul 3 2019, 8:11 PM
nibags added a subscriber: nibags.Jul 3 2019, 9:18 PM

Only a small detail needs to be added. You also have to increase the version of the file.

data/syntax/fortran-fixed.xml
557–558

Here add the rule: <DetectChar attribute="Comment" context="comment" char="!" firstNonSpace="true"/>

In the previous fortran.xml file it was like this.

nononux updated this revision to Diff 61110.Jul 3 2019, 9:48 PM

Update of the version number + add the line proposed by nibags

nononux marked an inline comment as done.Jul 3 2019, 9:48 PM
nibags added a comment.Jul 4 2019, 8:16 AM

Now I checked the patch well and I want to add some final recommendations before merging.
I think it's okay.

data/syntax/fortran-fixed.xml
370

I recommend moving lines 374 and 375 (<IncludeRules context="find_preprocessor" /> and <IncludeRules context="find_comments" />) to the beginning of the "default" context so that they have higher priority. For example, when writing a number on column 72, it's not highlighted as a comment, because numbers have a higher priority.

411

Here put String="." instead of ".*", because this also highlights alerts in the comment line (for example: TODO, NOTE, ALERT).

nononux updated this revision to Diff 61238.Jul 5 2019, 6:50 PM

Update with nibags recommendations

nononux marked 2 inline comments as done.Jul 5 2019, 7:07 PM

Thanks for the improvements propositions.

In the same way, I note the ">72th column" highlighting is not working when a context start before the 72th column and goes after.
For example if a 2 digits number is placed on columns 72 and 73 or if the keyword "THEN" is placed on the 72th column.

However, I don't find a way to solve the problem.
I thought for numbers about switching context to one which check the 72th column or the end of the number. But I didn't succeed to have something working and this method will add a big number of new rules.

Any idea ? Otherwise, I think we can let the patch as is.

nibags accepted this revision.Jul 6 2019, 6:30 AM

That is complicated to do, we would have to make rules for all the columns before 72 and for all the possible matchings, which is a lot of work and would make the code difficult to maintain.
I think a better solution is to add the functionality to the highlighting engine, for example, allowing a rule to be forced in a column, so that it can be applied above of any context. It can be something like this:

<RegExpr attribute="Comment" context="comment" String="." column="72" forceColumn="true" />

Another option is to allow having a set of rules that are applied above of the rest of the syntax highlighting; something like "injecting" rules. Such a feature could also be used in the PHP highlighter, instead of the generator script. For example:

<InjectRules>
    <RegExpr attribute="Comment" context="comment" String="." column="72" />
</InjectRules>

I think the patch is fine like that. If there is no problem, I will land this patch (to be included in the next version of KDE Frameworks).
Any idea or improvement in the highlighting of the comment in column 72, it can be done in another diff.

I will also change the license of the file to MIT.

This revision is now accepted and ready to land.Jul 6 2019, 6:30 AM
nibags closed this revision.Jul 6 2019, 6:44 AM