Skip to content

Commit

Permalink
Made false, true, and null constants in PHP (#1694)
Browse files Browse the repository at this point in the history
- This adds the `constant` alias to `false` and `true`.
- `null` is no longer `keyword` but a `constant`.
  • Loading branch information
volado authored and RunDevelopment committed Jan 10, 2019
1 parent 7def8f5 commit 439e3bd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
11 changes: 9 additions & 2 deletions components/prism-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
*/
(function (Prism) {
Prism.languages.php = Prism.languages.extend('clike', {
'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|null|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
'constant': /\b[A-Z_][A-Z0-9_]*\b/,
'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
'boolean': {
pattern: /\b(?:false|true)\b/i,
alias: 'constant'
},
'constant': [
/\b[A-Z_][A-Z0-9_]*\b/,
/\b(?:null)\b/i,
],
'comment': {
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
lookbehind: true
Expand Down
2 changes: 1 addition & 1 deletion components/prism-php.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/languages/php/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FALSE
false
TRUE
true

----------------------------------------------------

[
["boolean", "FALSE"],
["boolean", "false"],
["boolean", "TRUE"],
["boolean", "true"]
]

----------------------------------------------------

Checks for booleans.
2 changes: 2 additions & 0 deletions tests/languages/php/constant_feature.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
null
_
X
AZ
Expand All @@ -7,6 +8,7 @@ FOOBAR_42
----------------------------------------------------

[
["constant", "null"],
["constant", "_"],
["constant", "X"],
["constant", "AZ"],
Expand Down
2 changes: 0 additions & 2 deletions tests/languages/php/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ isset
list
namespace;
new;
null
or
parent
print
Expand Down Expand Up @@ -119,7 +118,6 @@ yield
["keyword", "list"],
["keyword", "namespace"], ["punctuation", ";"],
["keyword", "new"], ["punctuation", ";"],
["keyword", "null"],
["keyword", "or"],
["keyword", "parent"],
["keyword", "print"],
Expand Down

0 comments on commit 439e3bd

Please sign in to comment.