From: ohl@physik.uni-wuerzburg.de (Thorsten Ohl (TP2))
To: caml-list@yquem.inria.fr
Subject: Format: Fortran (&c.) style continuation lines?
Date: Thu, 8 Apr 2010 12:58:28 +0200 (CEST) [thread overview]
Message-ID: <20100408105828.3626347A7A@wthp058.physik.uni-wuerzburg.de> (raw)
Hi,
for ages, I've been using the following (somewhat hackish) approach to
pretty printing source code that requires special lexical markers to
allow statements that continue over more than one line. (e.g. in
Fortran
foo = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 &
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 &
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 &
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 &
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 &
+ 1 + 1 + 1 + 1 + 1 + 1 + 1
and in /bin/sh we have the same with "\\" instead of "&"):
open Format;;
let continuing = ref true;;
let wrap_newline () =
let out, flush, newline, space = get_all_formatter_output_functions
() in
let newline' () =
if !continuing then
out " &" 0 2;
newline () in
set_all_formatter_output_functions out flush newline' space;;
let nl () =
continuing := false;
print_newline ();
continuing := true;;
let _ =
wrap_newline ();;
(* Nonsensical example: *)
for statement = 1 to 3 do
printf " @[<2>foo = 1";
for i = 1 to 100 do
printf "@, + 1"
done;
nl ()
done;;
The requirement to end each statement with "nl ()" is tedious in real
world applications and the use of the global variable "continuing"
violates my sense of aesthetics...
Is there a more idiomatic approach that I'm missing?
Thanks,
-Thorsten
--
Thorsten Ohl, Wuerzburg Univ., Physics -- http://physik.uni-wuerzburg.de/ohl
next reply other threads:[~2010-04-08 10:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-08 10:58 Thorsten Ohl (TP2) [this message]
2010-04-08 17:53 ` [Caml-list] " Martin Jambon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100408105828.3626347A7A@wthp058.physik.uni-wuerzburg.de \
--to=ohl@physik.uni-wuerzburg.de \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).