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) Add additional keywords, built-in classes, and '<?=' syntax #2372
Conversation
+ `__TRAIT__` + `bool`, `callable`, `float`, `from`, `int`, `iterable`, `object`, `string`, `void` <https://www.php.net/manual/en/language.types.intro.php> <https://www.php.net/manual/en/migration71.new-features.php> + `fn` <https://wiki.php.net/rfc/arrow_functions_v2> + `true`, `false` and `null` are now literals.
Please don't mix a bunch of items in a single PR, that makes it much harder to review and will slow things down. |
I mean grouping the PHP things is ok, but the other stuff should preferably be split out... typically we squash commits here, which is another reason for this - since most people are bad/terrible with maintaining a proper commit history otherwise. It looks like you MIGHT be an exception in that regard (good commit name, splits) but still it makes things more complex to review vs 3 smaller PRs. For example if this had just been PHP stuff it likely would already be merged, without any need to get into the complexities of attr vs attribute, etc. |
These are very different things on purpose. You can search issues in the past to find the write up, sorry I don't have it off the top of my head. So you'd have to review other themes to see if attr aliasing to attribute is something we would accept. Some themes purposely only highlight one and choose to ignore the other. |
I will approve and flat-merge if you simply pull out 622f5cb. We can discuss that elsewhere. |
OK but now you're going to have to look at the PHP/zephir collision. It may be that you need to apply your PHP updates to Zephir as well. Sorry just now noticed the failing test. |
Probably wouldn't hurt to add a comment to the PHP and Zephier files to tell maintainers to cross-reference them when making updates. I also wouldn't mind if Zephir pulled in PHP as a requirement and built upon it (which would avoid these issues in the future) but that might be a bit more work than you were wanting to put it. Let me know. :) |
--- src/languages/php.js 2020-01-31 08:28:57.000000000 -0500
+++ src/languages/zephir.js 2020-01-31 08:28:54.000000000 -0500
@@ -1,21 +1,14 @@
/*
-Language: PHP
-Author: Victor Karamzin <Victor.Karamzin@enterra-inc.com>
-Contributors: Evgeny Stepanischev <imbolk@gmail.com>, Ivan Sagalaev <maniac@softwaremaniacs.org>
-Website: https://www.php.net
-Category: common
-*/
+ Language: Zephir
+ Description: Zephir, an open source, high-level language designed to ease the creation and maintainability of extensions for PHP with a focus on type and memory safety.
+ Author: Oleg Efimov <efimovov@gmail.com>
+ Website: https://zephir-lang.com/en
+ */
function(hljs) {
- var VARIABLE = {
- begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
- };
- var PREPROCESSOR = {
- className: 'meta', begin: /<\?(php)?|\?>/
- };
var STRING = {
className: 'string',
- contains: [hljs.BACKSLASH_ESCAPE, PREPROCESSOR],
+ contains: [hljs.BACKSLASH_ESCAPE],
variants: [
{
begin: 'b"', end: '"'
@@ -29,20 +22,21 @@
};
var NUMBER = {variants: [hljs.BINARY_NUMBER_MODE, hljs.C_NUMBER_MODE]};
return {
- aliases: ['php', 'php3', 'php4', 'php5', 'php6', 'php7'],
+ aliases: ['zep'],
case_insensitive: true,
keywords:
'and include_once list abstract global private echo interface as static endswitch ' +
- 'array null if endwhile or const for endforeach self var while isset public ' +
+ 'array null if endwhile or const for endforeach self var let while isset public ' +
'protected exit foreach throw elseif include __FILE__ empty require_once do xor ' +
'return parent clone use __CLASS__ __LINE__ else break print eval new ' +
'catch __METHOD__ case exception default die require __FUNCTION__ ' +
'enddeclare final try switch continue endfor endif declare unset true false ' +
'trait goto instanceof insteadof __DIR__ __NAMESPACE__ ' +
- 'yield finally',
+ 'yield finally int uint long ulong char uchar double float bool boolean string' +
+ 'likely unlikely',
contains: [
+ hljs.C_LINE_COMMENT_MODE,
hljs.HASH_COMMENT_MODE,
- hljs.COMMENT('//', '$', {contains: [PREPROCESSOR]}),
hljs.COMMENT(
'/\\*',
'\\*/',
@@ -66,23 +60,9 @@
),
{
className: 'string',
- begin: /<<<['"]?\w+['"]?$/, end: /^\w+;?$/,
- contains: [
- hljs.BACKSLASH_ESCAPE,
- {
- className: 'subst',
- variants: [
- {begin: /\$\w+/},
- {begin: /\{\$/, end: /\}/}
- ]
- }
- ]
- },
- PREPROCESSOR,
- {
- className: 'keyword', begin: /\$this\b/
+ begin: '<<<[\'"]?\\w+[\'"]?$', end: '^\\w+;',
+ contains: [hljs.BACKSLASH_ESCAPE]
},
- VARIABLE,
{
// swallow composed identifiers to avoid parsing them as keywords
begin: /(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
@@ -98,7 +78,6 @@
begin: '\\(', end: '\\)',
contains: [
'self',
- VARIABLE,
hljs.C_BLOCK_COMMENT_MODE,
STRING,
NUMBER
Ok I never looked closely before. I didn't realize they were so similar. I can probably consolidate them myself, so I wonder if there is a simpler way just to get your tests passing so we could get the PHP portions of this merged? |
Hmm. I’m confused. How can I revert specific item from a pull that has been requested? Can I just undo modifying the |
The preferable way would be to rebase onto master and just snip out the bad commit... if you want to try:
Rewriting history in branches is one of gits amazing and powerful features. |
That would typically have been ok since we usually squash the commit history (although you'd do it with |
Thanks for the instructions. It’s almost midnight here. I will try it tomorrow. |
Once you see the power hopefully you'll go off and learn a bit more about rebasing, it's SUPER useful if you use git a lot and contribute to projects. |
b2490ae
to
ce1b149
Compare
Well, that all depends on your theme. Some are awful, some are good IME. |
This isn't truly rebased onto upstream master though or there wouldn't be any conflicts... you first need to make sure YOUR local master points to upstream/master. Where upstream = the highlightjs core repository. I usually have upstream as a git Oh you really should be using branches for development not master. :-) Generally you should never commit to master (for projects you don't own), but rather use branches. So you probably should:
If that's all sounding too complex then you can also just remove the unrelated htaccess changes here and let this just be PHP changes (which we can squash). But this is why we usually prefer focused PRs. :-) Working with larger ones is a pain UNLESS you're really familiar with Git. (not to mention being harder to review, etc) |
ce1b149
to
87e464d
Compare
Most of the contributions I have made are because I use the application, not because I am proficient with Git. I will usually delete the fork repository when my pull requests has been merged, and will re-fork it when I want to make new pull requests 😛 |
That works, but makes it hard to make multiple PRs against a single repo at once. :-) |
It seems you added:
Possibly missing:
Where did you get this list of types? just checking quickly I see you've added Also what is And removed:
Please explain the removals. (also quite likely the reason the tests are failing) We support back to PHP3 so I'm not sure anything should be removed; |
If that's the full list that's not so terrible... what is that? 50-80 items maybe? I'm fine with that IF you think they'd be useful for highlighting. If not lets just add |
- This moves `exception`, `parent`, `self` and `static` keyword to built-in. - Added `class`, `extends`, `implements`, `interface` and `use` back to the keyword list. - Added type aliases such as `boolean` and `integer` (alias of `bool` and `int`) to the keyword list. - Finally found a way to highlight keywords within function arguments based on `csharp.js` language highlighter.
Trying to remove Sync and Update log but could’t find it when trying to rebase. |
Does't matter, we'll squash this now... but what you probably want is to mark them as "fixup" then they'll be silently merged into the prior commit. In order to rebase properly you really want your master to point to a clean state. If you're rebasing onto yourself (which I think you're doing) I'm not sure how that works... I always branch, so I'm rebasing my branches on top of master. |
Now your'e conflicting with Java... we may need to improve our Java sample. |
This may have to wait now until after #2387 gets merged. (rather than keep fixing Zephir issues here) |
Oh, I see you guys have done a great job here and in #2387. What do you think about adding some tests? We have not a single one for Zephir yet... |
I don't tend to require tests for contributors that are simply adding keywords. That's really a feature of HLJS, not something we need a test fore (when the keywords are just global, like here).
I was using the detect file for all my testing... shall I just copy it wholesale over into the markup folder with it's expected result? |
That's right, my concern was more about #2387.
It is better than nothing, and will make it easier to add other tests afterwards. |
Ok, the only failing test now seems to be regarding how you've changed params... I actually raised my eyebrows when I saw how you changed it, but I need to look at all our other grammars and see how we're doing it there. Either the Did you already look around before making this changes? |
I did.
I could make you become very very confusing in seconds without magic: with ES6 arrow functions const foo = (bar, baz) => {};
const bar = baz => {}; |
Ok, awesome. Now can you just fix the one failing test and then I think this might be ready to go! |
<?=
syntax
<?=
syntax
I think you only fixed half of it. If you can run the tests yourself locally that'd make checking a lot easier. |
@taufik-nurrohman Thanks for putting in the time on this one! |
…ighlightjs#2372) * Added More Keywords + `__TRAIT__` + `bool`, `callable`, `float`, `from`, `int`, `iterable`, `object`, `string`, `void` <https://www.php.net/manual/en/language.types.intro.php> <https://www.php.net/manual/en/migration71.new-features.php> + `fn` <https://wiki.php.net/rfc/arrow_functions_v2> + `true`, `false` and `null` are now literals. * `<?=` Tag is Enabled By Default Since PHP 5.4 * enh(zephir) add `fn` keyword for => functions * chore(zephir) boost score by using likely/unlikely * Added Built-In Keywords - This moves `exception`, `parent`, `self` and `static` keyword to built-in. - Added `class`, `extends`, `implements`, `interface` and `use` back to the keyword list. - Added aliases such as `boolean` and `integer` (alias of `bool` and `int`) to the keywords. - Highlight keywords within function arguments (based on `csharp.js` language). * fix auto-detect conflict with Java * Exclude Parenthesis from `.hljs-params` Co-authored-by: Josh Goebel <me@joshgoebel.com>
Add(#issuecomment-580984827)htaccess
as alias forapache
(#issuecomment-579757989)Highlight JSON and YAML attributes.PS: For maintainers, you may need to unifyattr
class name toattribute
or simply include.hljs-attr
along with.hljs-attribute
class declaration.https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html(#issuecomment-580729326)