Recent

Author Topic: If you've ever wanted to be able to use multi-line strings in FPC...  (Read 29906 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #150 on: August 10, 2019, 01:16:14 pm »
I only take exception to code like this:
Code: Pascal  [Select][+][-]
  1. if (c in ['1'..'9']) then // <------ sigh
  2.           begin
  3.             count:=current_scanner.readval;
  4.             if (count<0) or (count>65535) then // <------- sigh some more
Both the range and the limit. See if you can spot what I mean  :o

In my view the functionality is already covered by the string helper in sysutils and without an artificial limit. Let alone the meaning of "word"..
Okay, the range for c should start from '0' as other directives allow leading zeros as well, but that's all we're talking about here: detecting leading zeros. The complete number is read by readval.
And using High(Word) instead of the literal 65535 would indeed be nice as well.

That said there has been no decision yet whether we want to allow the use of helpers (or generics for that matter) inside the compiler. Also the string helper would be useless as a) the compiler uses mainly ShortString and b) there is no Char helper.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #151 on: August 10, 2019, 01:57:31 pm »
@Sven
You were not supposed to bite...
Specialize a type, not a var.

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #152 on: August 10, 2019, 05:45:41 pm »
I only take exception to code like this:

"c" is one character, Thaddy. (As in, the first character of what may or may not be a valid number.) "readval" then attempts to read an actual complete number into the "count" variable.

As far as this being provided by some kind of library, that would be strictly worse, as it would be slower and could not have the capabilities it does now. As far as TStringHelper being related to this kind of thing at all, I don't get what you mean.

Okay, the range for c should start from '0' as other directives allow leading zeros as well, but that's all we're talking about here: detecting leading zeros. The complete number is read by readval.
And using High(Word) instead of the literal 65535 would indeed be nice as well.

I'll make those changes.
« Last Edit: August 10, 2019, 05:48:37 pm by Akira1364 »

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #153 on: August 10, 2019, 05:55:58 pm »
This is a dirty feature.
Don't you understand -- in Pascal, trailing spaces at the end of a line have always been insignificant.

This is important -- trailing spaces are not visible.
You cannot see them! A programming language in which spaces in the end of line can be significant is not clean, as Pascal should be.

It is very bad.

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #154 on: August 10, 2019, 06:03:13 pm »
- snip -

Read my previous comment as to why I fundamentally disagree with you.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #155 on: August 10, 2019, 06:06:21 pm »
"c" is one character, Thaddy. (As in, the first character of what may or may not be a valid number.) "readval" then attempts to read an actual complete number into the "count" variable.
Well, Sven knew what I meant... :D
And as far as the helper goes, look at the interface. You can achieve the same  with few lines of code. (syshelph.inc)
Specialize a type, not a var.

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #156 on: August 10, 2019, 06:10:05 pm »
- snip -

Read my previous comment as to why I fundamentally disagree with you.

I read them, of course... Nevertheless, I still hope for a little common sense...

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #157 on: August 10, 2019, 07:14:19 pm »
Nevertheless, I still hope for a little common sense...
What I'm going to state isn't associated with the feature being discussed here, just a truism which is, common sense is the least common of all senses.  (as clearly evidenced in a number of threads completely unrelated to this new feature.)


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #158 on: August 10, 2019, 07:50:59 pm »
Nevertheless, I still hope for a little common sense...

Right, as do I. There's mountains of evidence in various places (and various languages) as to how this kind of feature does not cause anything resembling kind of issues you're speculating about.

Also, as far as I know, my implementation of this actually goes farther than any other language's implementation does with regards to end-user customization and error handling in the case of "unterminated" multi-line strings.

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #159 on: August 11, 2019, 06:25:41 am »
This is a dirty feature.
Don't you understand -- in Pascal, trailing spaces at the end of a line have always been insignificant.
...


Perhaps I am missing something, but this feature doesn't change that at all.

For those who do not implement it, there is zero change to trailing space significance.


To those who implement the feature, there is zero change to trailing space significance.


If someone needs trailing spaces for a regular or multi-line string, then they have to pay attention to it for the strings in question, but it will not automatically affect every string.

-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #160 on: August 11, 2019, 02:00:38 pm »
@Sven
You were not supposed to bite...
It's about compiler related code, so of course I'll bite. And Akira1364 said that he'd make some adjustments...
And as far as the helper goes, look at the interface. You can achieve the same  with few lines of code. (syshelph.inc)
I still don't get though what you're trying to get at with the helpers...

heejit

  • Full Member
  • ***
  • Posts: 245
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #161 on: September 14, 2019, 01:22:32 pm »
Is this FEATURE ACCEPTED BY CORE TEAM???

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #162 on: March 09, 2024, 09:25:39 am »
An old discussion, but it became relevant again.
since delphi 12 now has multiline strings, maybe you can adapt the backtick syntax to the delphi syntax.
the delphi syntax is like this
Code: Pascal  [Select][+][-]
  1.  
  2.  writeln('''test
  3.             me
  4.             multi
  5.             line''');
And the behavior of the line breaks is governed by:
Code: Pascal  [Select][+][-]
  1. {$TEXTBLOCK NATIVE/CR/LF/CRLF [<ident>]}
See this blogpost:
https://blogs.embarcadero.com/yukon-beta-blog-delphi-language-modernizing-string-literals/#Multiline_Strings

Back in the days I have been playing with your patch and I found it more and more usefull, except for the quirky backtick syntax.
I think Delphi solved the syntax in a more sane way. :)
I also think that you will have a better chance of getting this applied if you adapt the patch to Delphi syntax.

« Last Edit: March 09, 2024, 09:28:52 am by Thaddy »
Specialize a type, not a var.

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #163 on: March 09, 2024, 10:31:22 am »
Correction for Thaddy's post:
opening triple quotes must be the end of the 1st line of string.
closing triple quotes must start on the next line, after the text end.

Code: Pascal  [Select][+][-]
  1. writeln('''
  2.            test
  3.            me
  4.            multi
  5.            line
  6.            ''');
« Last Edit: March 09, 2024, 10:33:03 am by AlexTP »

colo

  • New Member
  • *
  • Posts: 43
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #164 on: March 09, 2024, 11:45:58 am »
Turns out I was looking for exactly this kind of feature/syntax sugar recently, where I wanted to be able to "template" (using simple string replacements) an INI file... As of today, is there any kind of official support for multiline string(c onstant)s in FPC/Lazarus? :)

 

TinyPortal © 2005-2018