Fortran syntax highlighting: distinguish free format and fixed format
Review Request #129569 - Created Nov. 28, 2016 and updated
See https://bugs.kde.org/show_bug.cgi?id=372950 for bug description and https://github.com/janusw/syntax-highlighting/commits/master for three separate commits implementing this. Description copied from bugzilla: Kate currently seems to have only one syntax-highlighting mode for Fortran. However, in the Fortran language there are two different source formats: * fixed format (from the old Fortran77 standard, extension .f) * free format (introduced with Fortran90, extension .f90) The keywords etc are the same, but one thing that differs is commenting: In fixed format every line with a 'c' in the first column is a comment, while in free format comments start with an '!' (in any column). Both of these mechanisms seem to be supported in Kate 16.04.3 on Ubuntu 16.10 (with Fortran highlighting file v2). The problem is that lines starting with 'c' are also displayed like a comment in f90 files (where only '!' indicates a comment). Simple example ('test.f90'): ! this is a test program that does absolutely nothing program test contains subroutine s end subroutine end program The first line is greyed out, which is correct, but also the third line ('contains') is greyed out, which is wrong. It is displayed normally if a space is inserted before 'contains.'
Opened a few different files (.f, .f90, .f03, .f08) in Kate and verified that the comments show up as expected and all artefacts disappear. A good source for test files is the testsuite of the gfortran compiler ( see e.g. https://github.com/gcc-mirror/gcc/tree/master/gcc/testsuite/gfortran.dg ).
Hi Janus, sorry for the long delay.
In general, the patch looks good.
I have some comments, though, maybe we can improve the following:
1. automated tests: Running
make test, the highlight.f90 does not not work anymore. This is easily fixed by running in the build folder ./autotests/update-reference-data.sh. However, I think since contents is for .f90 and for .f, the test itself is not correct anymore everywhere. --> Could you copy the highligh.f90 to highlight.f and adapt both files so that the contents makes sense again? You can verify the output by looking at the generated .html files.
2. The file contents now are almost identical, so we have quite some duplicated code. In theorey, it should be possible to use IncludeRules to include highlighting rules from a different highlighting .xml file. Could you maybe try this as well in order to avoid the code duplication? Just grep for IncludeRules containing a '##' or similar, you should also be able to include just include rules from a dedicated context. See also IncludeRules at https://docs.kde.org/stable5/en/applications/katepart/highlight.html
If we cannot fix 2. properly, I'd also accept the patch as is. But please have a look into 1. again, since the unit tests are really important. Thanks!