Recent

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

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #15 on: July 12, 2019, 01:37:07 am »
Maybe not the best implementation

I'm happy to hear any suggestions you might have!

As I posted in the link, I think multilines string could be:

Code: Pascal  [Select][+][-]
  1. s='hello
  2. world'
  3.  

Leading spaces, and appearence could work of the editor/IDE.

Anyway, directives could help on setting spaces and line endings.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #16 on: July 12, 2019, 01:50:04 am »
As I posted in the link, I think multilines string could be:
Code: Pascal  [Select][+][-]
  1. s='hello
  2. world'
  3.  

It already is though? Just with backticks instead of single quotes.

Code: Pascal  [Select][+][-]
  1. const s = `hello
  2. world`;

I've attached an image (that I also posted earlier) of what it looks like with a patched version of SynEdit in Lazarus.
« Last Edit: July 12, 2019, 01:52:21 am by Akira1364 »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #17 on: July 12, 2019, 02:28:07 am »
I've attached an image (that I also posted earlier) of what it looks like with a patched version of SynEdit in Lazarus.

Ah ... Off-topic but ... for future reference, would you mind cropping your images to the minimum needed for the purpose? In this case, maybe, screenshooting just the editor window?

Some of us still use (relatively) small screens, so the less scrolling the better :-[

ETA - Oh, didn't see this:
What do you see as unexpected, exactly? You type in text. The compiler reads the text. The end. It's a very, very, simple feature.

I didn't mean in the feature itself--although that too regarding the EOLs, trimming, etc.--but the possibilities of I myself (and people like me, few as there are) making lots of mistypings, and  the potentially multiple cycles of "compile-correct typo-compile- correct-typo-..." which tend to multiply inordinately the number of files in the "backup" folder. Note that in most non-US keyboards the "backtick" is a tilde key (i.e. a dead key), so it's easy to mistype it.

I kind of like the feature per se; only I would prefer some other method, like an operator or something like that. After all it's almost only a "want-to type-less" feature.
« Last Edit: July 12, 2019, 02:43:24 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #18 on: July 12, 2019, 03:29:29 am »
The problem here is that allowing multi lines for strings building is great, most editors allow it and most
compilers allow it but I don't like the idea of it changing the content of the string I specify..

 Changing the content means removing left spaces, inserting CR etc... that isn't ideal..

 I made a mini editor as a tool to create a string using multi-lines and then I have a button that translate
it to a C or Pascal string.., place it on the clipboard and drop it in the source editor.

 Its all human readable and the compiler accepts it. I keep my edited part of the text in the mini editor as a
data base for the current project...
 it works out well.
 
 I think Lazarus could benefit from having a code tool like that..
The only true wisdom is knowing you know nothing

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #19 on: July 12, 2019, 03:29:56 am »
After all it's almost only a "want-to type-less" feature.
Personally, I think it's not even "almost", that's exactly what it is.

I have mixed feelings about that feature.  There are things I like about it and things I don't like.

I like the clean, uncluttered look of the multiline string.

I am not fond of the need to have a new token in the language (presumably "(#") and, I like even less the need to have  directives to control the trimming of the strings.   Most, if not all the savings in typing, go out the window with those directives.

Here is a thought, it's a small variation on the concept Akira has presented, using current Pascal syntax:
Code: Pascal  [Select][+][-]
  1.  const
  2.    s = 'hello ' +
  3.        'world'  ;    // would print "hello world" (just as it does now.)
  4.  
  5.    {$LINEBREAKS ON}
  6.    b = 'hello'  +
  7.        'world'  ;
  8.  
  9.    // would print (imagine "// " is the beginning of the line)
  10.    // hello
  11.    // world
  12.  

{$LINEBREAKS would be active ONLY for 1 string, the very next one, to prevent having unintended line breaks in other strings.  I think this is a feature that is used rarely enough that having to type {$LINEBREAKS ON} for each one of them is within reason.

Basically, teach a new "trick" to the "+" pony.

That method would make "xxxTRIM" directives unnecessary since the programmer would still be responsible to put whatever number of spaces he/she desires within the quotes.  It also gives the programmer very precise control, which may be needed/wanted when the purpose is to have fixed-length strings on separate lines.

Those are my two (2) counterfeit cents on the subject.
« Last Edit: July 12, 2019, 03:32:46 am by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #20 on: July 12, 2019, 03:39:17 am »
Akira, thank you for working on this feature.

I saw a problem. It could be the way I applied the patch, as I was eager to test it so I was not careful enough. So just in case, this code:
Code: Pascal  [Select][+][-]
  1. program example;
  2.  
  3. {$modeswitch MultiLineStrings}
  4. {$MultiLineStringTrimLeft 5}
  5.  
  6. const Test = `ThisSpace>>>>     <<<<diappeared`;
  7.  
  8. begin
  9.   Write(Test);
  10. end.

Removed the space in the middle and gave me:
Code: Text  [Select][+][-]
  1. ThisSpace>>>><<<<diappeared

Do you get the same result?

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #21 on: July 12, 2019, 03:42:09 am »
My little mini editor makes nice like formatted paragraphs  and fits it to  pascal editor/compiler format.

Its just a click and drop in the editor with all the needed + for multilines etc..
I suppose an open quote that carries to the next line would be nice but that is the extent of it.

 I think maybe this feature is better suited for an option in the IDE not the compiler.. a simple little memo type
editor to build your bulk lines in a design look.

 Its gets hard to read code at times with strings going out side the editor window on smaller screens.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #22 on: July 12, 2019, 03:45:32 am »
Most likely the editor in the options list is setup to remove the trailing spaces, so basically it broke the
string up and there you...
The only true wisdom is knowing you know nothing

Akira1364

  • Hero Member
  • *****
  • Posts: 561
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #23 on: July 12, 2019, 03:55:08 am »
Akira, thank you for working on this feature.

I saw a problem. It could be the way I applied the patch, as I was eager to test it so I was not careful enough. So just in case, this code:
Code: Pascal  [Select][+][-]
  1. program example;
  2.  
  3. {$modeswitch MultiLineStrings}
  4. {$MultiLineStringTrimLeft 5}
  5.  
  6. const Test = `ThisSpace>>>>     <<<<diappeared`;
  7.  
  8. begin
  9.   Write(Test);
  10. end.

Removed the space in the middle and gave me:
Code: Text  [Select][+][-]
  1. ThisSpace>>>><<<<diappeared

Do you get the same result?

Oh no! That is in fact a bug. Looking at my FPC-test-suite tests now, that particular manner of "single-line-like" use seems to be the one thing I overlooked, syntactically speaking. I will fix that literally right now. Thanks for the report, and for testing!

Most likely the editor in the options list is setup to remove the trailing spaces, so basically it broke the
string up and there you...

No. It's an oversight in my implementation of the feature, which is entirely a part of FPC's scanner logic. It has absolutely nothing to do with Lazarus, at all.

I am not fond of the need to have a new token in the language (presumably "(#") and, I like even less the need to have  directives to control the trimming of the strings. Most, if not all the savings in typing, go out the window with those directives.

Where are you getting the pound sign from? The syntax is exactly what's written in my example.

I like even less the need to have  directives to control the trimming of the strings

I personally don't even think there is a need so to speak. I added that because people seemed to really be concerned about maintaining "pretty" indentation while not having spaces actually appear in the string when displayed / written to file / e.t.c. at runtime.
« Last Edit: July 12, 2019, 04:10:42 am by Akira1364 »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #24 on: July 12, 2019, 03:56:21 am »
Most likely the editor in the options list is setup to remove the trailing spaces, so basically it broke the
string up and there you...

I just opened the file with a different editor, the space is there, or did I misunderstand you.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #25 on: July 12, 2019, 04:03:50 am »
No you didn't miss understand me, I screwed that one up, I guess the editor in  your case makes
no difference but control characters and UTF8 need to be tested.

 For me all this is going to do is remove the use of the '+ at the end of the line.

 that is all I'll ever use it for.
The only true wisdom is knowing you know nothing

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #26 on: July 12, 2019, 04:07:22 am »
@jamie, do you use LineEnding anywhere in your code?

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #27 on: July 12, 2019, 04:36:26 am »
Where are you getting the pound sign from? The syntax is exactly what's written in my example.
I admit to having lost track of how you've implemented the feature.  At the time I wrote that, I was thinking about the discussion in FPC-devel which used "(##" (if I'm not mistaken again.)

I personally don't even think there is a need so to speak. I added that because people seemed to really be concerned about maintaining "pretty" indentation while not having spaces actually appear in the string when displayed / written to file / e.t.c. at runtime.
I understand.  The one thing that concerns me, if I've understood the description correctly, is that with that construct, there is no way to have fixed-length multi-line strings.    I think the ability of having fixed-length multi-line strings should not be lost (it can be done using current syntax but, obviously more typing and more clutter but, it's there, it's available if you need it.)
(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 #28 on: July 12, 2019, 04:42:50 am »
Akira, thank you for working on this feature.

I saw a problem. It could be the way I applied the patch, as I was eager to test it so I was not careful enough. So just in case, this code:
Code: Pascal  [Select][+][-]
  1. program example;
  2.  
  3. {$modeswitch MultiLineStrings}
  4. {$MultiLineStringTrimLeft 5}
  5.  
  6. const Test = `ThisSpace>>>>     <<<<diappeared`;
  7.  
  8. begin
  9.   Write(Test);
  10. end.

Removed the space in the middle and gave me:
Code: Text  [Select][+][-]
  1. ThisSpace>>>><<<<diappeared

Do you get the same result?

Oh no! That is in fact a bug. Looking at my FPC-test-suite tests now, that particular manner of "single-line-like" use seems to be the one thing I overlooked, syntactically speaking. I will fix that literally right now. Thanks for the report, and for testing!

Ok, I've now fixed this, and added your example to my "FPC test suite folder" tests with the filename "tmultilinestring22.pp".

Literally a one-line fix, believe it or not! (A boolean value needed to be set to false in a specific place, but was not.)

I've pushed the changes to my github fork, and also uploaded a new pair of patch files on the bugtracker issue.
« Last Edit: July 12, 2019, 05:21:30 am by Akira1364 »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #29 on: July 12, 2019, 04:51:17 am »
That was quick, thank you!!

 

TinyPortal © 2005-2018