Re: [PHP-DEV] One-line heredoc for better syntax highlightning

2022-09-20 Thread Rowan Tommins

On 20/09/2022 19:29, Olle Härstedt wrote:

Ya ok, this kills my idea. If heredoc was designed from start so that
the delimiter would not be allowed at all in the text, then it would
make sense. Weird that they did it like that, would be easy enough to
come up with a unique delimiter so that it would not cause a
problem... Obviously it can't be changed now without breaking
backwards compatibility.



For what it's worth, the "they" in question are the authors of the early 
Unix shells in the 1970s - from a quick search, it seems like the Bourne 
shell was the first to implement "here document" syntax, sometime around 
1979. As the name suggests, they were not for defining strings, but for 
entering entire text files embedded in a script or interactive shell 
session.


In that context, the original format is actually elegantly minimal: 
content is read one line at a time; if it exactly matches the delimiter, 
stop; else, add the line to the file buffer. No actual parsing is required.


Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] One-line heredoc for better syntax highlightning

2022-09-20 Thread Olle Härstedt
2022-09-20 17:00 GMT+02:00, Sara Golemon :
> On 19 September 2022 15:24:26 BST, "Olle Härstedt" <
> olle.haerst...@limesurvey.org> wrote:
>>Some editors can guess the domain-specific language inside heredoc, e.g.
> if you do
>>
>>$query = <<>SELECT * FROM foo
>>MySQL;
>>
>>It would be nice if this feature could be used in single lines as well:
>>
>>$query = <<>
> Good news! This feature exists and was introduced by Rasmus **checks
> notes** about 25 years ago.
>
> To use it, you'll want to hold down your shift key, then press the key just
> to the left of your enter key.  This is called a "quote", and you can see
> it demonstrated here around the word quote.
>
> Hope that helps!
>
> Seriously though, I know you're looking to help your editor find something
> to syntax highlight, but this is an editor problem, not a PHP language
> problem.  If your editor can detect SQL in heredoc, then it should be able
> to improve and find it in interpolated strings.

Nope, because you need to be explicit which type of SQL you're working
with - MySQL, Postgres, SQL Server, etc. Would be hard to write a
regexp to guess that for the editor. :) In the Vim case, it reads your
delimiter name and applies syntax highlight from that (mysql,
javascript, html).

> Making the parser more
> complex for no benefit to the actual language (some detriment, I would
> argue) is not the fix here.
>
> -Sara
>
> P.S. - Yes, I'm assuming a US layout, you know where your quote key is.

I you read my text more carefully, you'd see that I thought the parser
would be simplified by my suggestion, by removing what I thought was
an arbitrary limitation. I was wrong. :(

Olle

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] One-line heredoc for better syntax highlightning

2022-09-20 Thread Olle Härstedt
2022-09-20 11:54 GMT+02:00, Rowan Tommins :
> On 19/09/2022 20:10, Olle Härstedt wrote:
>> More for users to learn? Don't you mean less, haha? This is an
>> arbitrary limitation of heredoc, that we can remove (it might not be
>> arbitrary from a yacc perspective, someone would have to explain that
>> if so).
>
>
> I don't think the rules for heredoc are arbitrary,  but they are quite
> specific: the end delimiter has to appear at the *start* of a line, so
> it can appear anywhere else in the text without prematurely ending the
> string:
>
> $foo = << This is a normal heredoc
> this is not the end FOO
> this is:
> FOO;

Ya ok, this kills my idea. If heredoc was designed from start so that
the delimiter would not be allowed at all in the text, then it would
make sense. Weird that they did it like that, would be easy enough to
come up with a unique delimiter so that it would not cause a
problem... Obviously it can't be changed now without breaking
backwards compatibility.

Our product still supports PHP 7.2 sadly, but that's our own problem. :)

Thank you.

Olle

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] One-line heredoc for better syntax highlightning

2022-09-20 Thread Sara Golemon
On 19 September 2022 15:24:26 BST, "Olle Härstedt" <
olle.haerst...@limesurvey.org> wrote:
>Some editors can guess the domain-specific language inside heredoc, e.g.
if you do
>
>$query = <MySQL;
>
>It would be nice if this feature could be used in single lines as well:
>
>$query = <

[PHP-DEV] One-line heredoc for better syntax highlightning

2022-09-19 Thread Olle Härstedt
Hi internals!



Some editors can guess the domain-specific language inside heredoc, e.g. if you 
do



$query = <