More improvements and testing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
diff --git a/components/prism-clike.js b/components/prism-clike.js
index a80cc38..5ec416e 100644
--- a/components/prism-clike.js
+++ b/components/prism-clike.js
@@ -5,7 +5,7 @@ Prism.languages.clike = {
},
'string': /("|')(\\?.)*?\1/g,
'class-name': {
- pattern: /(class|interface|extends|implements|trait|instanceof|new)\s+[a-z0-9_\.\\]+/ig,
+ pattern: /((?:class|interface|extends|implements|trait|instanceof|new)\s+)[a-z0-9_\.\\]+/ig,
lookbehind: true
},
'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,
diff --git a/components/prism-clike.min.js b/components/prism-clike.min.js
index 131d3c4..9f8c8de 100644
--- a/components/prism-clike.min.js
+++ b/components/prism-clike.min.js
@@ -1 +1 @@
-Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/(class|interface|extends|implements|trait|instanceof|new)\s+[a-z0-9_\.\\]+/ig,lookbehind:!0},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?[\da-f]+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};
\ No newline at end of file
+Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/((?:class|interface|extends|implements|trait|instanceof|new)\s+)[a-z0-9_\.\\]+/ig,lookbehind:!0},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?[\da-f]+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};
\ No newline at end of file
diff --git a/components/prism-php.js b/components/prism-php.js
index a9a5545..cd4b9a9 100644
--- a/components/prism-php.js
+++ b/components/prism-php.js
@@ -8,7 +8,7 @@
* - Smarter constant and function matching
*
* Adds the following new token classes:
- * constant, deliminator, variable, function, scope, package
+ * constant, deliminator, variable, function, scope, package, this
*/
Prism.languages.php = Prism.languages.extend('clike', {
@@ -18,11 +18,13 @@ Prism.languages.php = Prism.languages.extend('clike', {
Prism.languages.insertBefore('php', 'keyword', {
'deliminator': /(\?>|\?>|<\?php|<\?php)/ig,
+ 'this': /\$this/,
'variable': /(\$\w+)\b/ig,
'scope': {
pattern: /[a-z0-9_\\]+::/ig,
inside: {
- operator: /::/
+ keyword: /(static|self|parent)/,
+ punctuation: /(::|\\)/
}
},
'package': {
@@ -34,7 +36,7 @@ Prism.languages.insertBefore('php', 'keyword', {
}
});
-Prism.languages.insertBefore('php', 'punctuation', {
+Prism.languages.insertBefore('php', 'operator', {
'function': {
pattern: /[a-z0-9_]+\(/ig,
inside: {
@@ -42,10 +44,8 @@ Prism.languages.insertBefore('php', 'punctuation', {
}
},
'property': {
- pattern: /->[a-z0-9_]+/ig,
- inside: {
- operator: /->/
- }
+ pattern: /(->)[a-z0-9_]+/ig,
+ lookbehind: true
}
});
diff --git a/components/prism-php.min.js b/components/prism-php.min.js
index c6fe14c..62ff111 100644
--- a/components/prism-php.min.js
+++ b/components/prism-php.min.js
@@ -1 +1 @@
-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|extends|private|protected|parent|static|throw|null|echo|print|trait|namespace|use|final|yield|goto)\b/ig,constant:/[A-Z0-9_]{2,}/g});Prism.languages.insertBefore("php","keyword",{deliminator:/(\?>|\?>|<\?php|<\?php)/ig,variable:/(\$\w+)\b/ig,scope:{pattern:/[a-z0-9_\\]+::/ig,inside:{operator:/::/}},"package":{pattern:/(\\|namespace\s+|use\s+)[a-z0-9_\\]+/ig,lookbehind:!0,inside:{punctuation:/\\/}}});Prism.languages.insertBefore("php","punctuation",{"function":{pattern:/[a-z0-9_]+\(/ig,inside:{punctuation:/\(/}},property:{pattern:/->[a-z0-9_]+/ig,inside:{operator:/->/}}});Prism.languages.markup&&Prism.languages.insertBefore("php","comment",{markup:{pattern:/(\?>|\?>)[\w\W]*?(?=(<\?php|<\?php))/ig,lookbehind:!0,inside:{markup:{pattern:/<\/?[\w:-]+\s*[\w\W]*?>/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.php}}});
\ No newline at end of file
+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|extends|private|protected|parent|static|throw|null|echo|print|trait|namespace|use|final|yield|goto)\b/ig,constant:/[A-Z0-9_]{2,}/g});Prism.languages.insertBefore("php","keyword",{deliminator:/(\?>|\?>|<\?php|<\?php)/ig,"this":/\$this/,variable:/(\$\w+)\b/ig,scope:{pattern:/[a-z0-9_\\]+::/ig,inside:{keyword:/(static|self|parent)/,punctuation:/(::|\\)/}},"package":{pattern:/(\\|namespace\s+|use\s+)[a-z0-9_\\]+/ig,lookbehind:!0,inside:{punctuation:/\\/}}});Prism.languages.insertBefore("php","operator",{"function":{pattern:/[a-z0-9_]+\(/ig,inside:{punctuation:/\(/}},property:{pattern:/(->)[a-z0-9_]+/ig,lookbehind:!0}});Prism.languages.markup&&Prism.languages.insertBefore("php","comment",{markup:{pattern:/(\?>|\?>)[\w\W]*?(?=(<\?php|<\?php))/ig,lookbehind:!0,inside:{markup:{pattern:/<\/?[\w:-]+\s*[\w\W]*?>/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.php}}});
\ No newline at end of file
diff --git a/examples.html b/examples.html
index 28faf88..b1baeff 100644
--- a/examples.html
+++ b/examples.html
@@ -311,7 +311,7 @@ namespace Prism;
use Some\Child\Class;
-class Prism extends AbstractClass implements InterfaceCass {
+class Prism extends AbstractClass implements Interface_Class {
const CONSTANT = 12345;
public $foo = true;
public static $bar = array('foo' => 'bar');
@@ -330,8 +330,13 @@ class Prism extends AbstractClass implements InterfaceCass {
};
}
+ public function under_score() {
+ self::doSomething();
+ static::_other_method();
+ }
+
public function doSomething() {
- $var = StaticClass::methodCall();
+ $var = Static\Class::methodCall();
for ($i = 0; $i <= 10; $i++) {
$var = str_replace($i, rand(), $var);
diff --git a/prism.js b/prism.js
index 9a3e478..9e3e27e 100644
--- a/prism.js
+++ b/prism.js
@@ -442,7 +442,7 @@ Prism.languages.clike = {
},
'string': /("|')(\\?.)*?\1/g,
'class-name': {
- pattern: /(class|interface|extends|implements|trait|instanceof|new)\s+[a-z0-9_\.\\]+/ig,
+ pattern: /((?:class|interface|extends|implements|trait|instanceof|new)\s+)[a-z0-9_\.\\]+/ig,
lookbehind: true
},
'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,
@@ -495,11 +495,13 @@ Prism.languages.php = Prism.languages.extend('clike', {
Prism.languages.insertBefore('php', 'keyword', {
'deliminator': /(\?>|\?>|<\?php|<\?php)/ig,
+ 'this': /\$this/,
'variable': /(\$\w+)\b/ig,
'scope': {
pattern: /[a-z0-9_\\]+::/ig,
inside: {
- operator: /::/
+ keyword: /(static|self|parent)/,
+ punctuation: /(::|\\)/
}
},
'package': {
@@ -511,7 +513,7 @@ Prism.languages.insertBefore('php', 'keyword', {
}
});
-Prism.languages.insertBefore('php', 'punctuation', {
+Prism.languages.insertBefore('php', 'operator', {
'function': {
pattern: /[a-z0-9_]+\(/ig,
inside: {
@@ -519,10 +521,8 @@ Prism.languages.insertBefore('php', 'punctuation', {
}
},
'property': {
- pattern: /->[a-z0-9_]+/ig,
- inside: {
- operator: /->/
- }
+ pattern: /(->)[a-z0-9_]+/ig,
+ lookbehind: true
}
});