[fpc-devel] Some thoughts on multi-line string support, and a possible syntax that I think is perfectly clean and Pascal-ish.
Ben Grasset
operator97 at gmail.com
Tue Jul 9 03:56:29 CEST 2019
Ok, after thinking about it for a bit, I decided to go ahead and implement
the "customizable leading whitespace" thing right away, as a lot of people
seemed to want it, and also because I just realized that it would not be
difficult at all to do.
So, that said, my Github fork branch
<https://github.com/Akira13641/freepascal> of the compiler now contains a
{$MultiLineStringTrimLeft} directive, that does precisely what you might
think. Here's one of my compiler tests, which I think demonstrates it
fairly well:
program tmultilinestring14;
{$modeswitch MultiLineStrings}
{$MultiLineStringTrimLeft 2}
const A = `
A
B
C
D
`;
{$MultiLineStringTrimLeft 4}
const B = `
A
B
C
D
`;
begin
Write(A);
Write(B);
{ The number-to-trim being larger, (even much larger) than the amount of
whitespace is not a problem,
as it stops immediately when it is no longer actually *in* whitespace
regardless. }
{$MultiLineStringTrimLeft 10000}
{ Non-leading whitespace is preserved properly, of course. }
Write(`
sdfs
sd fs fs
sd fsfs sdfd sfdf
sdfs fsd
`);
end.
The output looks like this, showing that everything appears as though it
was written at the "far left" of the file without indentation:
A
B
C
D
A
B
C
D
sdfs
sd fs fs
sd fsfs sdfd sfdf
sdfs fsd
Hopefully this will quell some of the uncertainties people may still have
had about the feature, and also ultimately make it easier to use overall!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190708/d3d0df4c/attachment.html>
More information about the fpc-devel
mailing list