Problem on heredoc

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

admin wrote:I found one little problem with heredoc which I could fix.

But most of your post I did not understand. Please send the code that does not work as expected (and explain what you expected).
This isn't understandable :?

Once this was a script of > 250 lines. I have shortened it to 9 lines - and the problem is still there! So here it is. (Don't mind that this rest is only nonsense :roll: )

Code: Select all

//
   $fileo   = "$file2.csv";

   $isok    = Confirm (<<<>>>
Verify files to compare:
>>>      );

   $a++;
// x
The problem is triggered by the very last line: the comment! There can be more or less lines of code between heredoc and that comment - here tested by $a++; - this may be there or not...

In this form the script doesn't start.
If you insert some blancs in front of that // the script will start. But if you let it reach the end it says that "//" is invalid :shock:

I hope you see the same effects?
To verify I copy/pasted this codebox to Try Script... and the error occurred again.

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

Yep, confirmed!

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

admin wrote:Yep, confirmed!
...and solved! All tests OK now!
Thanks again! Quite a lot of fine things for me in the last days!

One thing I don't understand: you made 2 changes!
1) After the end of a heredoc everything is allowed now. (Before: only ";".)
2) The end of heredoc may be everywhere on the line.

The first brings only(!) advantages. You still can add a newline after the end-pattern (with maybe ";") and everything is as before. Or you can continue text on the line with heredoc. So I think this is 100% compatible with old code.

The second brings the ability to add the end-string anywhere on a line. Bringing the problem, that an old script containing the end-pattern somewhere in the text will fail now. Only for this you need the new ScriptHereDocEndsAnywhere=1 tweak. Is this worth the trouble?

But don't get me wrong: I can happily live with it!

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

Yes, I was in the mood to remove limits. And a research brought up some other languages which also allow the end-string anywhere. The price of a tweak seemed worthwhile to me.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

But the question is: will this tweak some day become the default? Else it's a problem for people using it to supply their scripts to the community...

(...and I would *not* want to miss this enhancement!)

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

PeterH wrote:But the question is: will this tweak some day become the default? Else it's a problem for people using it to supply their scripts to the community...

(...and I would *not* want to miss this enhancement!)
You are right, hmm....

Now there's a second reason I did not mention before: I HAD to do it the radical way it's done now, because the previous less radical way (allow it at the beginning of the line) lead to a bug (your "//comment" bug) that could not be fixed otherwise (resp. would be too complex to fix).

So, hmm.... I think it will have to stay a tweak for now.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

That's good: you gave the bad answer before I did ask!
(I would have said that for me that half of the change would suffice that would have no compatibility issues. But you say that they technically "belong together". Sad!)

On the other side: I wonder if there really are scripts affected by the compatibility issue: if I'm right these only are scripts that use the end-pattern of a heredoc also as text inside the heredoc. Though it was allowed till now I personally never would have done that. As long as I could avoid it - and I can't imagine a situation where I could not avoid it.
So my hope is big, that nobody has done it.
But that's no guaranty...

To everyone reading here: do you have scripts with heredocs, where your end-phrase of the heredoc is used as text inside the heredoc? Please tell us!

Example:

Code: Select all

   $text = <<<$$$
This is a note
asking for $$$
and more
$$$;
I hope this example is correct?

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

BTW, your previous assumption is not correct: also the less radical approach would have potentially broken user code.

This works with 10.80.0000, but not anymore with the recent tweak:

Code: Select all

$isOk = Confirm (<<<FOO
Blah
FOO Blah
FOO
  ); echo $isOk;

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

Oh dear! I luckily forgot that! :roll:

I hope that nobody ever did that. :?
But me :oops:

But I must say I did that (wrongly) assuming that the text after the first FOO would be outside the heredoc, i.e. that the first FOO ended the heredoc!
And I hope very hard that nobody used this (how should I call it?) "strange rule" at will :twisted:

Is somebody here who did this??

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

A smart way would be to control heredoc parsing by the form of the identifier. That way, and only that way, one could have different heredoc syntaxes in one script.

I propose that the new "radical" parsing is applied when the identifier begins with "#". The following blocks could then run correctly within one and the same script:

New parsing (ending identifier can be anywhere):

Code: Select all

$isOk = Confirm (<<<#FOO
Blah
BlahFOO#FOO); echo $isOk;
Old parsing (ending identifier must be on own line):

Code: Select all

$isOk = Confirm (<<<FOO
Blah
BlahFOO
FOO
  ); echo $isOk;

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

I think it's a good idea.

On first test it works as expected!

Offtopic - but related to v10.80.13:

A text-box suddenly is displayed on the wrong screen!
(I assume correct would be the screen XY is displayed on?)
Move box to the correct screen, then close and redisplay didn't help.

Special for my setup: 2 screens, primary is right!
As much as I remember you had problems with this years ago...
(I think the 2nd screen (with XY on it) has negative coordinates.)

Just forgot: you had a command to show that?

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

Code: Select all

::virtualscreen

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Problem on heredoc

Post by PeterH »

::virtualscreen

Also this came on the wrong screen - and x is negative:
screenshot.png
To see the attached files, you need to log into the forum.

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Problem on heredoc

Post by admin »

Thanks, next version will be better...

Post Reply