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

enh(php) detect newer more flexible HEREdoc syntax #2658

Merged

Conversation

eytienne
Copy link
Contributor

Allows the use of the new indented heredoc : https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes

@eytienne
Copy link
Contributor Author

#2651 Resolves this issue

Comment on lines 49 to 52
begin: /<<<[ \t]*(?<marker>\w+)\n(?:.*\n)*?^[ \t]*\k<marker>\b/,
returnBegin: true,
contains: [
{ begin: /<<<[ \t]*/ },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think se need any of this... move the <<< into the BEGIN match... we shouldn't only need a simple being/end match here (inside the END_SAME_AS_BEGIN) helper, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ie, we don't need to find the end first...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I missed that copying from ruby.js

Comment on lines 29 to 47
var SINGLE_QUOTED = hljs.inherit(
hljs.APOS_STRING_MODE,
{
illegal: null,
variants: [{
begin: 'b\'', end: '\''
}]
}
);
var DOUBLE_QUOTED = hljs.inherit(
hljs.QUOTE_STRING_MODE,
{
illegal: null,
variants: [{
begin: 'b"', end: '"'
}],
contains: [hljs.BACKSLASH_ESCAPE, SUBST]
}
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is wrong and not the equivalent of what we were doing before, it's also MUCH harder to read. (it's unclear that there are two branches). Pretty sure variants needs to spell out ALL the variants. You're also making every variant null, which is also incorrect, etc...

Variants are a complete list not "in addition to"....

I'd make another attempt here or just revert this to what we had before.

Copy link
Contributor Author

@eytienne eytienne Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood thinking the variants of the main will result in the main + expansion for each variant, isn't it? It was working as expected testing it, so how? I wanted to reflect the fact that each string (single and double) has its own "binary" equivalent for PHP6 compatibility...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood thinking the variants of the main will result in the main + expansion for each variant, isn't it?

No. Variants are exclusive (they merge over-top of the "defaults" from the top).

I wanted to reflect the fact that each string (single and double) has its own "binary" equivalent for PHP6 compatibility...

I think we can just do this with comments the way this was prior. Otherwise you're repeating a lot of the string bits over and over for no real big win...

Copy link
Contributor Author

@eytienne eytienne Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so I noticed when retesting my code that binary strings were broken so I fixed it. I seems the variants where not expanded recursively, a bug maybe ? (Prior the substitution was not used in binary strings, not a big win because it surely affects nobody as it is a backward compatiblity residue but seems clearer...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so I noticed when retesting my code that binary strings were broken so I fixed it. I seems the variants where not expanded recursively, a bug maybe ?

The problem before was variants are not "in addition to". Whether variants can nest inside other variants I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior the substitution was not used in binary strings

Nice fix. Should mention that in CHANGES.md also.

test/markup/php/heredoc.txt Show resolved Hide resolved
@joshgoebel
Copy link
Member

Looks good, lets update the CHANGES.md file and I think I can merge.

@joshgoebel joshgoebel changed the title Php flexible heredoc syntax rfc enh(php) detect newer more flexible HEREdoc syntax Aug 21, 2020
contains: hljs.QUOTE_STRING_MODE.contains.concat(SUBST),
});
var HEREDOC = {
begin: /<<<[ \t]*(?<marker>\w+)\n(?:.*\n)*?^[ \t]*\k<marker>\b/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we not discuss simplifying all this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i moved the "<<<" into the end_same_as_begin, it seems good now, the regex is clear with the named group marker, ready yo be merged ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is why do we need lines 40/41/42 at all? ALL we really need here is just the END_SAME_AS_BEGIN rule without any other rules, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I missed that copying from ruby.js, fixed!

@joshgoebel joshgoebel merged commit 2a65144 into highlightjs:master Aug 31, 2020
@eytienne eytienne deleted the php_flexible_heredoc_syntax_rfc branch September 1, 2020 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants