Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(php) Support indented heredoc closing marker #2651

Closed
oadam opened this issue Aug 10, 2020 · 5 comments
Closed

(php) Support indented heredoc closing marker #2651

oadam opened this issue Aug 10, 2020 · 5 comments
Labels
bug help welcome Could use help from community language

Comments

@oadam
Copy link

oadam commented Aug 10, 2020

Indented closing markers are valid in heredoc strings since PHP version 7.3

Here is a fiddle that reproduces the issue : https://jsfiddle.net/ywhrtvzo/
The string mode should end at the second EOTEXT marker

I've checked the code to see if I could fix it myself, and the END_SAME_AS_BEGIN used in the ruby language for heredoc seems very promising, but I was not able to figure out how to adapt the php mode.
If I understand it well, a capturing group in the begin regex could be used for the end matching, which would be perfect !

@oadam oadam added bug help welcome Could use help from community language labels Aug 10, 2020
@joshgoebel
Copy link
Member

joshgoebel commented Aug 17, 2020

If I understand it well, a capturing group in the begin regex could be used for the end matching, which would be perfect !

Yes, the first capture group in both the being and end is what is used by default with END_SAME_AS_BEGIN... looks like it'd be a fairly straight forward PR.

You'd just need to add the match groups and remove the ^ and $ from the end regex.

We've a love a PR!

@joshgoebel joshgoebel changed the title (PHP) Support indented heredoc closing marker (php) Support indented heredoc closing marker Aug 17, 2020
@eytienne
Copy link
Contributor

I am working on a PR but sadly, it is not as simple as you said, look at the this for the details : https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
It will need a bit of custom code, but maybe I am confusing an highlighter with a parser.

@joshgoebel
Copy link
Member

What seems to be the problem? We just have to match the beginning and ending. We already do it for "normal" heredocs (although poorly since we're not even making sure the end tag matches, etc).

So you just need to edit the end rule to match ANYWHERE (not just at the start/end of a line) and then use a END_SAME_AS_BEGIN to make sure the end is the same as the beginning...

If you make a PR of what you have so far I can take a look.

@eytienne
Copy link
Contributor

I followed your advice, I was too focused on the rfc but we only need the level of precision of an highlighter.

@eytienne
Copy link
Contributor

eytienne commented Sep 1, 2020

Closed by #2658

@oadam oadam closed this as completed Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

3 participants