Page 2 of 2

Re: Problem on heredoc

Posted: 24 Jan 2012 11:31
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.

Re: Problem on heredoc

Posted: 24 Jan 2012 14:14
by admin
Yep, confirmed!

Re: Problem on heredoc

Posted: 24 Jan 2012 17:14
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!

Re: Problem on heredoc

Posted: 24 Jan 2012 17:21
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.

Re: Problem on heredoc

Posted: 24 Jan 2012 17:37
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!)

Re: Problem on heredoc

Posted: 24 Jan 2012 17:45
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.

Re: Problem on heredoc

Posted: 24 Jan 2012 20:58
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?

Re: Problem on heredoc

Posted: 24 Jan 2012 21:08
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;

Re: Problem on heredoc

Posted: 24 Jan 2012 22:32
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??

Re: Problem on heredoc

Posted: 25 Jan 2012 10:52
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;

Re: Problem on heredoc

Posted: 25 Jan 2012 15:18
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?

Re: Problem on heredoc

Posted: 25 Jan 2012 16:28
by admin

Code: Select all

::virtualscreen

Re: Problem on heredoc

Posted: 25 Jan 2012 18:37
by PeterH
::virtualscreen

Also this came on the wrong screen - and x is negative:
screenshot.png

Re: Problem on heredoc

Posted: 25 Jan 2012 19:06
by admin
Thanks, next version will be better...