[fpc-devel] Some thoughts on multi-line string support, and a possible syntax that I think is perfectly clean and Pascal-ish.

Marcus Sackrow alb42 at web.de
Wed Jul 3 16:17:34 CEST 2019


Am 03.07.2019 um 15:29 schrieb Ben Grasset:
> This has been discussed I think several times in the past, but I
> thought I'd bring it up once more as it has never made sense to me
> that FPC happily supports multi-line *comments* of any length, while
> having no such multi-line equivalent for string literals.
>
> I was fiddling around with what the clearest, easiest-to-parse, and
> most similar-to-existing-syntaxes way of doing it would be, and came
> up with this:
>
> const MultiLineString = (##
>   'The
>    line
>    endings
>    would
>    be
>    implicit
>    here.
>    This
>    is
>    significantly
>    cleaner
>    looking
>    overall
>    IMO!'
> ##);

I use an operator overload(not for constants but inside the code)
because I'm used to our script engine have the '/' as operator for
strings as line break

operator / (a,b: string): string;

operator/(a, b: string): string;
begin
   Result := a + #13#10 + b;
end;

var
   MultiLineString: string;
begin
   MultiLineString :=
     'this'/
     'is'/
     'a'/
     'multiline';

   // or even shorter:
   MultiLineString := 'this'/'is'/'a'/'multiline';
end;

I would like to have such feature, but then with '/' as operator because
then you can use that also inside a normal commandline

writeln('1st line'/'second line');

Greetings,
Marcus


More information about the fpc-devel mailing list