Skip to content

Commit f1026b4

Browse files
voladoRunDevelopment
authored andcommitted
Improve recognition of constants in PHP (#1688)
The pattern for PHP constants now have to be a valid identifier and recognizes single-letter names.
1 parent 88434f7 commit f1026b4

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

components/prism-php.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(function (Prism) {
1414
Prism.languages.php = Prism.languages.extend('clike', {
1515
'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,
16-
'constant': /\b[A-Z0-9_]{2,}\b/,
16+
'constant': /\b[A-Z_][A-Z0-9_]*\b/,
1717
'comment': {
1818
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
1919
lookbehind: true

components/prism-php.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/php/constant_feature.test

+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
_
2+
X
13
AZ
24
PRISM
35
FOOBAR_42
46

57
----------------------------------------------------
68

79
[
10+
["constant", "_"],
11+
["constant", "X"],
812
["constant", "AZ"],
913
["constant", "PRISM"],
1014
["constant", "FOOBAR_42"]

0 commit comments

Comments
 (0)