Commit b1003de31bb7a970d9e93afced8f5e45ffd32687

Miles Johnson 2013-05-16T12:19:58

More improvements and testing

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': /(\?>|\?&gt;|&lt;\?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: /-&gt;[a-z0-9_]+/ig,
-		inside: {
-			operator: /-&gt;/
-		}
+		pattern: /(-&gt;)[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:/(\?>|\?&gt;|&lt;\?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:/-&gt;[a-z0-9_]+/ig,inside:{operator:/-&gt;/}}});Prism.languages.markup&&Prism.languages.insertBefore("php","comment",{markup:{pattern:/(\?>|\?&gt;)[\w\W]*?(?=(&lt;\?php|<\?php))/ig,lookbehind:!0,inside:{markup:{pattern:/&lt;\/?[\w:-]+\s*[\w\W]*?&gt;/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:/(\?>|\?&gt;|&lt;\?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:/(-&gt;)[a-z0-9_]+/ig,lookbehind:!0}});Prism.languages.markup&&Prism.languages.insertBefore("php","comment",{markup:{pattern:/(\?>|\?&gt;)[\w\W]*?(?=(&lt;\?php|<\?php))/ig,lookbehind:!0,inside:{markup:{pattern:/&lt;\/?[\w:-]+\s*[\w\W]*?&gt;/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': /(\?>|\?&gt;|&lt;\?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: /-&gt;[a-z0-9_]+/ig,
-		inside: {
-			operator: /-&gt;/
-		}
+		pattern: /(-&gt;)[a-z0-9_]+/ig,
+		lookbehind: true
 	}
 });