Add a Fortran syntax highlighter - #516
Merged
Merged
Conversation
Free-form Fortran (90 and later): case-insensitive keywords, dotted and
symbolic operators, both string delimiters, '!' comments ('//' is string
concatenation, not a comment), common intrinsics as functions. Plus the
usual plumbing: suffix settings, editor config page tab, save/restore,
highlighter factory dispatch.
Also let tests/hellofortran90 build with the default 'gfortran' instead
of a hardcoded 'gfortran-12'.
Owner
|
Thanks for this. I'll review it in the next couple days. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
I've been testing MPI debugging with Seer (#60 is on my radar): half the
MPI world writes Fortran, and Seer had no highlighter for it — Fortran
sources show up as plain text.
What
A
SeerFortranSourceHighlighterfor free-form Fortran (90 and later),modeled on the Ada one (the other case-insensitive language), plus the
usual plumbing: suffix list in the settings (defaults to
.f90|.F90|.f95|.F95|.f03|.F03|.f08|.F08), a Fortran tab in the editorconfig page, save/restore of the suffixes, dispatch in the highlighter
factory, CMakeLists.
Fortran-specific choices, for review:
!only. Note//is the string concatenation operatorin Fortran, not a comment — easy trap coming from C.
free-form Fortran 90→2008 keywords plus the dotted operators and
constants (
.and.,.eq.,.true., …).==,/=,<=,>=,<,>,//,=>)use the keyword format too, so
==renders like its word form.eq..This is safe in Fortran (no templates —
</>are always relational)."..."and'...').name(...)is also how Fortran referencesarrays, so a before-parenthesis rule would mislabel half the
identifiers. Instead, a closed list of the common intrinsics
(
trim,sqrt,size,matmul, …) gets the function format whenfollowed by
(. A nice side effect:len/kindstay keywords indeclarations (
character(len=32)) and render as functions in calls.convention; derived types are already caught by the
type/classkeywords.
.f/.for, comment in column 1, code startingcolumn 7) is out of scope — it would need column-aware rules and the
legacy dialect is rarely what people debug interactively.
One small extra
tests/hellofortran90/MakefilehardcodedFC = gfortran-12, so the testdidn't build on machines with any other gfortran (mine has 13). Changed
it to plain
gfortran— that also makes it easy to try this highlighteron that test.
Testing
Qt 6.4.2, Linux Mint, gfortran 13. Verified on


tests/hellofortran90(which now builds out of the box, see above) and on a dedicated test
sheet exercising the traps above (mixed-case keywords,
//concat notcolored as comment, both string delimiters, dotted operators).
Screenshot below. The other languages' highlighting is untouched (the
factory just gains one branch).