Skip to content

Commit

Permalink
Improve recognition of constants in PHP (#1688)
Browse files Browse the repository at this point in the history
The pattern for PHP constants now have to be a valid identifier and recognizes single-letter names.
  • Loading branch information
volado authored and RunDevelopment committed Jan 2, 2019
1 parent 88434f7 commit f1026b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(function (Prism) {
Prism.languages.php = Prism.languages.extend('clike', {
'keyword': /\b(?:and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\b/i,
'constant': /\b[A-Z0-9_]{2,}\b/,
'constant': /\b[A-Z_][A-Z0-9_]*\b/,
'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.

4 changes: 4 additions & 0 deletions tests/languages/php/constant_feature.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
_
X
AZ
PRISM
FOOBAR_42

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

[
["constant", "_"],
["constant", "X"],
["constant", "AZ"],
["constant", "PRISM"],
["constant", "FOOBAR_42"]
Expand Down

0 comments on commit f1026b4

Please sign in to comment.