Commit de8ebe2013f2e5c8a6d6be609f0b5547464b4fa8

Golmote 2018-03-03T21:42:51

PHP: Code style

diff --git a/components/prism-php.js b/components/prism-php.js
index bca88ac..3e4142b 100644
--- a/components/prism-php.js
+++ b/components/prism-php.js
@@ -11,161 +11,161 @@
  * 		constant, delimiter, variable, function, package
  */
 (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/,
-	'comment': {
-		pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
-		lookbehind: true
-	}
-});
-
-Prism.languages.insertBefore('php', 'string', {
-	'shell-comment': {
-		pattern: /(^|[^\\])#.*/,
-		lookbehind: true,
-		alias: 'comment'
-	}
-});
-
-Prism.languages.insertBefore('php', 'keyword', {
-	'delimiter': {
-		pattern: /\?>|<\?(?:php|=)?/i,
-		alias: 'important'
-	},
-	'variable': /\$+(?:\w+\b|(?={))/i,
-	'package': {
-		pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
-		lookbehind: true,
-		inside: {
-			punctuation: /\\/
+	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/,
+		'comment': {
+			pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
+			lookbehind: true
 		}
-	}
-});
+	});
 
-// Must be defined after the function pattern
-Prism.languages.insertBefore('php', 'operator', {
-	'property': {
-		pattern: /(->)[\w]+/,
-		lookbehind: true
-	}
-});
+	Prism.languages.insertBefore('php', 'string', {
+		'shell-comment': {
+			pattern: /(^|[^\\])#.*/,
+			lookbehind: true,
+			alias: 'comment'
+		}
+	});
 
-Prism.languages.insertBefore('php', 'string', {
-	'nowdoc-string': {
-		pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
-		greedy: true,
-		alias: 'string',
-		inside: {
-			'delimiter': {
-				pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
-				alias: 'symbol',
-				inside: {
-					'punctuation': /^<<<'?|[';]$/
-				}
+	Prism.languages.insertBefore('php', 'keyword', {
+		'delimiter': {
+			pattern: /\?>|<\?(?:php|=)?/i,
+			alias: 'important'
+		},
+		'variable': /\$+(?:\w+\b|(?={))/i,
+		'package': {
+			pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
+			lookbehind: true,
+			inside: {
+				punctuation: /\\/
 			}
 		}
-	},
-	'heredoc-string': {
-		pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i,
-		greedy: true,
-		alias: 'string',
-		inside: {
-			'delimiter': {
-				pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
-				alias: 'symbol',
-				inside: {
-					'punctuation': /^<<<"?|[";]$/
+	});
+
+	// Must be defined after the function pattern
+	Prism.languages.insertBefore('php', 'operator', {
+		'property': {
+			pattern: /(->)[\w]+/,
+			lookbehind: true
+		}
+	});
+
+	Prism.languages.insertBefore('php', 'string', {
+		'nowdoc-string': {
+			pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
+			greedy: true,
+			alias: 'string',
+			inside: {
+				'delimiter': {
+					pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
+					alias: 'symbol',
+					inside: {
+						'punctuation': /^<<<'?|[';]$/
+					}
 				}
-			},
-			'interpolation': null // See below
+			}
+		},
+		'heredoc-string': {
+			pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i,
+			greedy: true,
+			alias: 'string',
+			inside: {
+				'delimiter': {
+					pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
+					alias: 'symbol',
+					inside: {
+						'punctuation': /^<<<"?|[";]$/
+					}
+				},
+				'interpolation': null // See below
+			}
+		},
+		'single-quoted-string': {
+			pattern: /'(?:\\[\s\S]|[^\\'])*'/,
+			greedy: true,
+			alias: 'string'
+		},
+		'double-quoted-string': {
+			pattern: /"(?:\\[\s\S]|[^\\"])*"/,
+			greedy: true,
+			alias: 'string',
+			inside: {
+				'interpolation': null // See below
+			}
 		}
-	},
-	'single-quoted-string': {
-		pattern: /'(?:\\[\s\S]|[^\\'])*'/,
-		greedy: true,
-		alias: 'string'
-	},
-	'double-quoted-string': {
-		pattern: /"(?:\\[\s\S]|[^\\"])*"/,
-		greedy: true,
-		alias: 'string',
+	});
+	// The different types of PHP strings "replace" the C-like standard string
+	delete Prism.languages.php['string'];
+
+	var string_interpolation = {
+		pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
+		lookbehind: true,
 		inside: {
-			'interpolation': null // See below
-		}
-	}
-});
-// The different types of PHP strings "replace" the C-like standard string
-delete Prism.languages.php['string'];
-
-var string_interpolation = {
-	pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
-	lookbehind: true,
-	inside: {
-		rest: Prism.languages.php
-	}
-};
-Prism.languages.php['heredoc-string'].inside['interpolation'] = string_interpolation;
-Prism.languages.php['double-quoted-string'].inside['interpolation'] = string_interpolation;
-
-// Add HTML support if the markup language exists
-if (Prism.languages.markup) {
-
-	// Tokenize all inline PHP blocks that are wrapped in <?php ?>
-	// This allows for easy PHP + markup highlighting
-	Prism.hooks.add('before-highlight', function(env) {
-		if (env.language !== 'php' || !/(?:<\?php|<\?)/ig.test(env.code)) {
-			return;
+			rest: Prism.languages.php
 		}
+	};
+	Prism.languages.php['heredoc-string'].inside['interpolation'] = string_interpolation;
+	Prism.languages.php['double-quoted-string'].inside['interpolation'] = string_interpolation;
+
+	// Add HTML support if the markup language exists
+	if (Prism.languages.markup) {
+
+		// Tokenize all inline PHP blocks that are wrapped in <?php ?>
+		// This allows for easy PHP + markup highlighting
+		Prism.hooks.add('before-highlight', function (env) {
+			if (env.language !== 'php' || !/(?:<\?php|<\?)/ig.test(env.code)) {
+				return;
+			}
 
-		env.tokenStack = [];
+			env.tokenStack = [];
 
-		env.backupCode = env.code;
-		env.code = env.code.replace(/(?:<\?php|<\?)[\s\S]*?(?:\?>|$)/ig, function(match) {
-			var i = env.tokenStack.length;
-			// Check for existing strings
-			while (env.backupCode.indexOf('___PHP' + i + '___') !== -1)
-				++i;
+			env.backupCode = env.code;
+			env.code = env.code.replace(/(?:<\?php|<\?)[\s\S]*?(?:\?>|$)/ig, function (match) {
+				var i = env.tokenStack.length;
+				// Check for existing strings
+				while (env.backupCode.indexOf('___PHP' + i + '___') !== -1)
+					++i;
 
-			// Create a sparse array
-			env.tokenStack[i] = match;
+				// Create a sparse array
+				env.tokenStack[i] = match;
 
-			return '___PHP' + i + '___';
-		});
+				return '___PHP' + i + '___';
+			});
 
-		// Switch the grammar to markup
-		env.grammar = Prism.languages.markup;
-	});
+			// Switch the grammar to markup
+			env.grammar = Prism.languages.markup;
+		});
 
-	// Restore env.code for other plugins (e.g. line-numbers)
-	Prism.hooks.add('before-insert', function(env) {
-		if (env.language === 'php' && env.backupCode) {
-			env.code = env.backupCode;
-			delete env.backupCode;
-		}
-	});
+		// Restore env.code for other plugins (e.g. line-numbers)
+		Prism.hooks.add('before-insert', function (env) {
+			if (env.language === 'php' && env.backupCode) {
+				env.code = env.backupCode;
+				delete env.backupCode;
+			}
+		});
 
-	// Re-insert the tokens after highlighting
-	Prism.hooks.add('after-highlight', function(env) {
-		if (env.language !== 'php' || !env.tokenStack) {
-			return;
-		}
+		// Re-insert the tokens after highlighting
+		Prism.hooks.add('after-highlight', function (env) {
+			if (env.language !== 'php' || !env.tokenStack) {
+				return;
+			}
 
-		// Switch the grammar back
-		env.grammar = Prism.languages.php;
+			// Switch the grammar back
+			env.grammar = Prism.languages.php;
 
-		for (var i = 0, keys = Object.keys(env.tokenStack); i < keys.length; ++i) {
-			var k = keys[i];
-			var t = env.tokenStack[k];
+			for (var i = 0, keys = Object.keys(env.tokenStack); i < keys.length; ++i) {
+				var k = keys[i];
+				var t = env.tokenStack[k];
 
-			// The replace prevents $$, $&, $`, $', $n, $nn from being interpreted as special patterns
-			env.highlightedCode = env.highlightedCode.replace('___PHP' + k + '___',
+				// The replace prevents $$, $&, $`, $', $n, $nn from being interpreted as special patterns
+				env.highlightedCode = env.highlightedCode.replace('___PHP' + k + '___',
 					"<span class=\"token php language-php\">" +
 					Prism.highlight(t, env.grammar, 'php').replace(/\$/g, '$$$$') +
 					"</span>");
-		}
+			}
 
-		env.element.innerHTML = env.highlightedCode;
-	});
-}
+			env.element.innerHTML = env.highlightedCode;
+		});
+	}
 }(Prism));
\ No newline at end of file