Skip to content

Add a Fortran syntax highlighter - #516

Merged
epasveer merged 1 commit into
epasveer:mainfrom
tiresiasfromthebai:fortran-highlighter
Aug 12, 2026
Merged

Add a Fortran syntax highlighter#516
epasveer merged 1 commit into
epasveer:mainfrom
tiresiasfromthebai:fortran-highlighter

Conversation

@tiresiasfromthebai

Copy link
Copy Markdown
Contributor

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 SeerFortranSourceHighlighter for 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 editor
config page, save/restore of the suffixes, dispatch in the highlighter
factory, CMakeLists.

Fortran-specific choices, for review:

  • Comments are ! only. Note // is the string concatenation operator
    in Fortran, not a comment — easy trap coming from C.
  • Keywords are matched case-insensitively (like Ada). The list covers
    free-form Fortran 90→2008 keywords plus the dotted operators and
    constants (.and., .eq., .true., …).
  • The symbolic operators (==, /=, <=, >=, <, >, //, =>)
    use the keyword format too, so == renders like its word form .eq..
    This is safe in Fortran (no templates — </> are always relational).
  • Strings match with both delimiters ("..." and '...').
  • No generic "function" rule: name(...) is also how Fortran references
    arrays, 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 when
    followed by (. A nice side effect: len/kind stay keywords in
    declarations (character(len=32)) and render as functions in calls.
  • No "class" rule: the language is case insensitive with no reliable case
    convention; derived types are already caught by the type/class
    keywords.
  • Fixed-form Fortran (F77 .f/.for, comment in column 1, code starting
    column 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/Makefile hardcoded FC = gfortran-12, so the test
didn't build on machines with any other gfortran (mine has 13). Changed
it to plain gfortran — that also makes it easy to try this highlighter
on 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 not
colored as comment, both string delimiters, dotted operators).
Screenshot below. The other languages' highlighting is untouched (the
factory just gains one branch).
Capture d’écran du 2026-08-11 11-45-14
Capture d’écran du 2026-08-11 11-46-31

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'.
@epasveer

Copy link
Copy Markdown
Owner

Thanks for this. I'll review it in the next couple days.

@epasveer
epasveer merged commit 781d57d into epasveer:main Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants