[fpc-devel] Some thoughts on multi-line string support, and a possible syntax that I think is perfectly clean and Pascal-ish.
operator97 at gmail.com
Wed Jul 3 15:29:18 CEST 2019
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
const MultiLineString = (##
The rationale being: round-bracket-plus-double-pound-sign is an uncommon
enough combination of characters that it is highly unlikely to conflict
with anything anyone currently has written inside of a string literal, and
also relatively similar to the classic round-bracket-plus-apostrophe
(It could even be reduced to just one pound sign after the opening bracket
and before the closing bracket if that was deemed "safe" to do, but I was
just trying to play it safe here.)
So the grammar rules would be:
Any instance of (## *must* be immediately followed by a single apostrophe.
After that, a string is parsed, line by line, until another single
apostrophe is hit. That second apostrophe *must *be immediately followed by
##) and then finally a semicolon to "terminate" everything.
Note that in Lazarus, for example, everything from the opening (## to the
closing ##) would be highlighted in blue just as multi-line comments
*string literals currently are, making them stand out nice and clearly.
To compare that directly to the current way of doing multi-line strings:
const SingleLineString =
'No' + sLineBreak +
'implicit' + sLineBreak +
'line' + sLineBreak +
'endings' + sLineBreak +
'are' + sLineBreak +
'currently' + sLineBreak +
'available.' + sLineBreak +
'I' + sLineBreak +
'fail' + sLineBreak +
'to' + sLineBreak +
'see' + sLineBreak +
'how' + sLineBreak +
'this' + sLineBreak +
'syntax' + sLineBreak +
'is' + sLineBreak +
'preferable' + sLineBreak +
'in' + sLineBreak +
'any' + sLineBreak +
I simply don't, personally, see any argument in *favor* of the current way.
(Much more "line noise" due to all the apostrophes, addition signs, and
"sLineBreaks", and of course no consistent blue syntax highlighting in
IDEs, as well as the fact that it's much more difficult to make use of
already-formatted-like-you-want-it text that way, and so on.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel