Recent

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

Akira1364

  • Hero Member
  • *****
  • Posts: 521
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #90 on: July 17, 2019, 03:58:36 am »
Just finished up a round of refactoring on this:

- The RAW option for MultiLineStringLineEnding is now called SOURCE.
- PLATFORM is now the default MultiLineStringLineEnding option.
- I've implemented the multi-line-string-specific error message that I mentioned in an earlier comment.

Here's an example that shows how the error works / is displayed:

Code: Pascal  [Select]
  1. { %FAIL }
  2.  
  3. { Will show:
  4.   tmultilinestring28.pp(20,1) Fatal: Unterminated multi-line string beginning at line 11, column 7. }
  5.  
  6. program tmultilinestring28;
  7.  
  8. {$modeswitch MultiLineStrings}
  9.  
  10. const
  11.   a = `this will be unterminated
  12. with some
  13. lines in it.
  14.  
  15. var
  16.   B : String;
  17.  
  18. begin
  19.   B:=`
  20. again
  21. something
  22. end backticked`;
  23.  
  24. end.
  25.  

Again, I've pushed the changes to my github branch of the compiler, and there's new patches on the bugtracker issue.
« Last Edit: July 17, 2019, 04:02:22 am by Akira1364 »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #91 on: July 17, 2019, 08:09:48 am »
Akira, just want to let you know. Not hearing from me, means I did not find another bug.  :)

avra

  • Hero Member
  • *****
  • Posts: 1599
    • Additional info
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #92 on: July 17, 2019, 08:51:07 am »
- The RAW option for MultiLineStringLineEnding is now called SOURCE.
- PLATFORM is now the default MultiLineStringLineEnding option.
- I've implemented the multi-line-string-specific error message that I mentioned in an earlier comment.
Thank you.

I was wondering if we really have to stick with the backtick, or we can keep the "old school" single quote instead?
Question stands first from implementation point of view, and then from "Is that really a more desirable syntax for multi line strings?" point of view.
I mean, everything is already there, and I might even prefer keeping single quotes if possible, while keeping all code switches as they are.

This renders to
Code: Pascal  [Select]
  1. const
  2.   Str1 = `this is
  3.           a multi line
  4.           string.`
versus
Code: Pascal  [Select]
  1. const
  2.   Str1 = 'this is
  3.           a multi line
  4.           string.'

And I like second example a little more.

And second example already renders nicely in the forum  ;)
« Last Edit: July 17, 2019, 08:55:05 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

PascalDragon

  • Hero Member
  • *****
  • Posts: 507
  • Compiler Developer
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #93 on: July 17, 2019, 09:12:29 am »
I was wondering if we really have to stick with the backtick, or we can keep the "old school" single quote instead?
This was a requirement from the core team to even remotely consider this for inclusion. The normal strings stay untouched. Period.

Akira1364

  • Hero Member
  • *****
  • Posts: 521
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #94 on: July 17, 2019, 03:09:28 pm »
Akira, just want to let you know. Not hearing from me, means I did not find another bug.  :)

Good to hear!

Imants

  • Full Member
  • ***
  • Posts: 178
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #95 on: July 18, 2019, 08:28:12 am »
Is your patch working on FPC 3.2.0 or only on trunk?

PascalDragon

  • Hero Member
  • *****
  • Posts: 507
  • Compiler Developer
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #96 on: July 18, 2019, 09:12:35 am »
Considering that nothing significant changed in the scanner since then I think that it should work. Just give it a try. *shrugs*

Imants

  • Full Member
  • ***
  • Posts: 178
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #97 on: July 18, 2019, 09:28:34 am »
I gave it a try and it did not compile in 3.2.0 and it compiles in trunk. I used fpcupdeluxe

Console output:
Code: Text  [Select]
  1. echo '42444' > revision.inc
  2. C:/fpcupdeluxe/fpcbootstrap/ppcx64.exe -Ur -Xs -O2 -n -Fux86_64 -Fusystems -FuC:/fpcupdeluxe/fpcsrc/rtl/units/x86_64-win64 -Fix86_64 -FE. -FUx86_64/units/x86_64-win64 -dRELEASE -vw-n-h-l-d-u-t-p-c- -dFPC_SOFT_FPUX80   -dREVINC -dx86_64 -dGDB -dBROWSERLOG -Fux86 -Sew version.pas
  3. C:/fpcupdeluxe/fpcbootstrap/ppcx64.exe -Ur -Xs -O2 -n -Fux86_64 -Fusystems -FuC:/fpcupdeluxe/fpcsrc/rtl/units/x86_64-win64 -Fix86_64 -FE. -FUx86_64/units/x86_64-win64 -dRELEASE -vw-n-h-l-d-u-t-p-c- -dFPC_SOFT_FPUX80   -dREVINC -dx86_64 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pas
  4. scanner.pas(4252,46) Error: Identifier not found "m_multiline_strings"
  5. scanner.pas(4476,53) Error: Identifier not found "m_multiline_strings"
  6. scanner.pas(5150,30) Error: Identifier not found "m_multiline_strings"
  7. scanner.pas(5684,40) Error: Identifier not found "m_multiline_strings"
  8. scanner.pas(5949) Fatal: There were 4 errors compiling module, stopping
  9. Fatal: Compilation aborted
  10.  

I was using multi_line_strings_main_rev5.patch
« Last Edit: July 18, 2019, 09:34:18 am by Imants »

Akira1364

  • Hero Member
  • *****
  • Posts: 521
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #98 on: July 18, 2019, 02:54:32 pm »
I gave it a try and it did not compile in 3.2.0

Seems like the changes to "globtype.pas", specifically, were not applied successfully against 3.2.0.

This makes sense actually, as I've been developing directly against the latest trunk, which contains several other new modeswitches (that I do not believe would exist in the 3.2.0 sources) in the list before m_multiline_strings:

m_multi_helpers, m_array2dynarray, and m_prefixed_attributes.

If you really wanted to use it with 3.2.0 though, I think it would be pretty easy to just do the changes to "globtype.pas" manually (without the other modeswitches), as for that particular file it is not very much code being added.
« Last Edit: July 18, 2019, 10:25:11 pm by Akira1364 »

PascalDragon

  • Hero Member
  • *****
  • Posts: 507
  • Compiler Developer
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #99 on: July 19, 2019, 09:28:57 am »
I gave it a try and it did not compile in 3.2.0 and it compiles in trunk. I used fpcupdeluxe
The first step after applying a patch is to check whether all changes applied cleanly. In this case you would have noticed that adding m_multiline_strings to the modeswitch enum failed. For a solution see Akira1364's remark about adding it manually.

Imants

  • Full Member
  • ***
  • Posts: 178
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #100 on: July 19, 2019, 12:18:45 pm »
I gave it a try and it did not compile in 3.2.0 and it compiles in trunk. I used fpcupdeluxe
The first step after applying a patch is to check whether all changes applied cleanly. In this case you would have noticed that adding m_multiline_strings to the modeswitch enum failed. For a solution see Akira1364's remark about adding it manually.
I used fpcupdelux to build compiler I never build compiler myself. And patching happens there automatically.

PascalDragon

  • Hero Member
  • *****
  • Posts: 507
  • Compiler Developer
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #101 on: July 20, 2019, 10:55:35 am »
I gave it a try and it did not compile in 3.2.0 and it compiles in trunk. I used fpcupdeluxe
The first step after applying a patch is to check whether all changes applied cleanly. In this case you would have noticed that adding m_multiline_strings to the modeswitch enum failed. For a solution see Akira1364's remark about adding it manually.
I used fpcupdelux to build compiler I never build compiler myself. And patching happens there automatically.
Then this should be considered a bug in fpcupdeluxe if it starts building after applying the patch failed.

Zoran

  • Hero Member
  • *****
  • Posts: 1456
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #102 on: July 20, 2019, 04:02:57 pm »

I am surprised that, no one noticed that there is an old Pascal feature which gets broken with introducing these multiline strings -- until now, in Pascal sources, all trailing spaces at the end of each line have always been insignificant.
Introducing these multiline strings breaks this rule.

See:
Code: Pascal  [Select]
  1. var
  2.   S1, S2: String;
  3. begin
  4.   S1 := 'this is a two-line string which has   ' // you can see the spaces before the quote.
  5.      + LineEnding + 'three ending spaces in first line.';
  6.  
  7.   // in the next line there are three trailing spaces; you can not see them:
  8.   S2 := `another string which has  
  9. three ending spaces in first line, but we don't know it just by looking at the code`;
  10.  
  11.  //
  12. end;
  13.  

Although having multiline strings can be useful, I really don't like breaking this old Pascal feature -- trailing spaces on a line should always be insignificant!

Zoran

  • Hero Member
  • *****
  • Posts: 1456
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #103 on: July 20, 2019, 04:31:26 pm »
Another thing which bothers me is the choice of "backtick" character.
It is too similar to quote character, not very careful reader will not notice that it is not a single quote.

Better choice would be some character which does not resemble the single quote, which is used for "normal" strings.

I wonder if all latin keyboards even have this character.
I found that I actually have two very similar characters on my keyboard -- "`" (right-alt+7) and "´" (right-alt+9), which makes further confusion.

lucamar

  • Hero Member
  • *****
  • Posts: 1943
Re: If you've ever wanted to be able to use multi-line strings in FPC...
« Reply #104 on: July 20, 2019, 10:25:51 pm »
I wonder if all latin keyboards even have this character.
I found that I actually have two very similar characters on my keyboard -- "`" (right-alt+7) and "´" (right-alt+9), which makes further confusion.

I don't know if all, but most* should have them (both the "grave" ^ and "acute" ' tildes, different from the apostrophe: '). They are both used as tildes rather extensively throughout most of Europe, West, Central and East, along with ^, " and ~.


* Actually looked (a quick look) in an old IBM guide of international keyboard layouts. It's a bit old and doesn't have all, but enough of them to get the idea.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.