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) Add additional keywords, built-in classes, and '<?=' syntax #2372

Merged
merged 16 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Core Changes:

Language Improvements:

- enh(php) added more keywords and include `<?=` syntax to meta [Taufik Nurrohman][]
- (fortran) Add Fortran 2018 keywords and coarray intrinsics (#2361) [Sam Miller][]
- (delphi) highlight hexadecimal, octal, and binary numbers (#2370) [Robert Riebisch]()
- enh(plaintext) added `text` and `txt` as alias (#2360) [Taufik Nurrohman][]
Expand Down
28 changes: 17 additions & 11 deletions src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function(hljs) {
begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
};
var PREPROCESSOR = {
className: 'meta', begin: /<\?(php)?|\?>/
className: 'meta', begin: /<\?(php|=)?|\?>/
};
var STRING = {
className: 'string',
Expand All @@ -31,15 +31,21 @@ function(hljs) {
return {
aliases: ['php', 'php3', 'php4', 'php5', 'php6', 'php7'],
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 ' +
'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',
keywords: {
keyword:
// Magic constants:
// <https://www.php.net/manual/en/language.constants.predefined.php>
'__CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ ' +
// Function that look like language construct or language construct that look like function:
// List of keywords that may not require parenthesis
'die echo exit include include_once parent print require require_once self static ' +
// These are not language construct (function) but operate on the currently-executing function and can access the current symbol table
// ' compact extract func_get_arg func_get_args func_num_args get_called_class get_parent_class' +
// Other keywords:
// <https://www.php.net/manual/en/reserved.php>
'array abstract and as bool break callable case catch clone const continue declare default do else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval final finally float for foreach from global goto if instanceof insteadof int isset iterable list new object or private protected public return string switch throw trait try unset var void while xor yield',
literal: 'false null true'
},
contains: [
hljs.HASH_COMMENT_MODE,
hljs.COMMENT('//', '$', {contains: [PREPROCESSOR]}),
Expand Down Expand Up @@ -89,7 +95,7 @@ function(hljs) {
},
{
className: 'function',
beginKeywords: 'function', end: /[;{]/, excludeEnd: true,
beginKeywords: 'fn function', end: /[;{]/, excludeEnd: true,
illegal: '\\$|\\[|%',
contains: [
hljs.UNDERSCORE_TITLE_MODE,
Expand Down