Wondering if anyone thinks proposing a block text feature for
Fortran would be as useful as I think it would be.
Most of my own preprocessing is to allow for placing free-format
documentation in the same file as the code or for defining
a character variable using a block of free-format text (see
prep).
But there is no standard Fortran preprocessor that might support the
feature and it would be preferable in my mind for Fortran to support
something like docstrings and “”" in Python as part of the language
anyway.
And I would strongly prefer the documentation be easily exported into
its own file for treatment as HTML, or tex, or markdown, or man-pages,
or other flat text formats in order to easily generate documentation
(short of Fortran supporting something like ford(1) or doxygen(1)).
As far as possible syntax goes I could envision something like a keyword
in a CHARACTER declaration or something like a BLOCK statement that
could only contain a block of text:
NAME : textblock (mytext)
This is a block of text
that can become a character variable or
just be treated as a comment block.
end textblock NAME
where if (varname) is not present it is just a block comment, but if it
is present the data is used to define the specified variable name, for
example.
Or a new descriptor on CHARACTER statements something like
character(len=*),freeformat,parameter :: name(*)=[ character(len=80) ::&
free-format text
could go here
]
or using [[
character(len=*),freeformat,parameter :: name(*)=[[ character(len=80) ::&
free-format text
could go here
]]
instead of
character(len=*),parameter :: name(*)=[ character(len=80) ::&
" free-format text", &
" could go here" &
]
But those have several issues and potentially could be hard to parse
out of the file.
The INCLUDE directive is far more like a preprocessor directive (actually,
that is exactly what it is, come to think about it) that has a very simple
syntax and has to be on a line by itself and cannot be continued. So
it would be easy to locate and parse. So using it as a model a simple
comment would be something like
TEXT
free-format comments
go here
END TEXT
and a variable definition would be
character(len=80),allocatable :: myname
:
:
! in the body of the program, not in the declarations ...
TEXT myname
free-format text
could go here
END TEXT
and an optional label that could easily be parsed by an external program
could contain a suggested filename that some compilers might actually
support using for generating a filename on demand via a compiler switch:
TEXT name "myfile.tex"
free-format text
could go here that could be markdown, tex, HTML, flat text, ...
END TEXT
So an unquoted value would define data for a CHARACTER variable and a
quoted string could be used as a hint for a filename, or maybe a tag
for the developer like “todo”, and both could be on a single statement.
The rules that INCLUDE requires (line cannot be numbered, must be on a
single line by itself, … would make extracting the data externally
far easier.
It would be even better if the data was actually (optionall?) written
to the file, but that has other ramifications that might (or might
not?) make the feature more controversial.