Global logging, ANSI-colored diagnostics, and pretty error/warning reporting for fpx.
This module is the central place for all human-readable output in the fpx preprocessor. It provides:
- Full ANSI color and style support (bold, underline, colors, etc.)
- Structured diagnostic messages with source context, line numbers, and caret markers
- Pretty-printed multi-line error/warning/help/note/info reports
- Label-based highlighting of specific code ranges (like rustc-style diagnostics)
- Recursive sub-diagnostic support for nested explanations
Designed to produce modern, readable, IDE-friendly output similar to rustc, clang, or cargo. When nocolor = .true. (or terminal does not support ANSI), falls back to plain text.
- Simple colored message (used internally for verbose logging):
use fpx_logging
print
'(A)',
render(
'Macro expanded: PI = 3.14159')
logical, public verbose
Master switch for verbose diagnostic output Default value is .false. (quiet mode)....
Interface to render diagnostic messages and labels.
Full diagnostic report (like a compiler error):
character(*), parameter :: input = &
'# This is a TOML document.' // nl // &
'title = ' // nl // &
'[owner]' // nl // &
'name = ' // nl // &
'dob = 1979-05-27T07:32:00-08:00 # First class dates' // nl // &
'[database]' // nl // &
'server = ' // nl // &
'ports = [ 8001, 8001, 8002 ]' // nl // &
'connection_max = 5000' // nl // &
'enabled = true' // nl // &
'[servers]' // nl // &
' # Indentation (tabs and/or spaces) is allowed but not required' // nl // &
' [servers.alpha]' // nl // &
' ip = ' // nl // &
' dc = ' // nl // &
' [servers.beta]' // nl // &
' ip = ' // nl // &
' dc = ' // nl // &
'[title]' // nl // &
'data = [ [, ], [1, 2] ]' // nl // &
'# Line breaks are OK when inside arrays' // nl // &
'hosts = [' // nl // &
' ,' // nl // &
' ' // nl // &
message=, &
source=, &
input)
end
Definition of diagnostic message.
Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character ar...
Output might look like (colored in terminal):
error: duplicated key 'title' found
--> example.toml:19:2-6
|
1 | # This is a TOML document.
2 | title =
| ----- first defined here
3 | [owner]
:
18 | dc =
19 | [title]
| ^^^^^ table 'title' redefined here
20 | data = [ [, ], [1, 2] ]
|
- ANSI style & color reference (used internally)
- Styles: BOLD_ON, UNDERLINE_ON, INVERSE_ON, STRIKETHROUGH_ON, ...
- Foreground: RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, ...
- Background: same as foreground but prefixed with BG_
- Note
- This code is adapted from pretty-diagnostics.