all files / lib/languages/ php.js

100% Statements 10/10
100% Branches 0/0
100% Functions 0/0
100% Lines 10/10
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                                                                                                                                                                                                                                           
"use strict";
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.php = undefined;
 
var _clike = require("./clike");
 
var _utils = require("../utils");
 
var php = _utils.lang.extend(_clike.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: /(^|[^\\])(?:\/\*[\w\W]*?\*\/|\/\/.*)/,
        lookbehind: true
    }
});
 
// Shell-like comments are matched after strings, because they are less
// common than strings containing hashes...
_utils.lang.insertBefore(php, "class-name", {
    "shell-comment": {
        pattern: /(^|[^\\])#.*/,
        lookbehind: true,
        alias: "comment"
    },
    _order: ["shell-comment"]
});
 
_utils.lang.insertBefore(php, "keyword", {
    delimiter: /\?>|<\?(?:php)?/ig,
    variable: /\$\w+\b/i,
    "package": {
        pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
        lookbehind: true,
        inside: {
            punctuation: /\\/,
            _order: ["punctuation"]
        }
    },
    _order: ["delimiter", "variable", "package"]
});
 
// Must be defined after the function pattern
_utils.lang.insertBefore(php, "operator", {
    "property": {
        pattern: /(->)[\w]+/,
        lookbehind: true
    },
    _order: ["property"]
});
 
_utils.lang.insertBefore(php, "variable", {
    "this": /\$this\b/,
    global: /\$(?:_(?:SERVER|GET|POST|FILES|REQUEST|SESSION|ENV|COOKIE)|GLOBALS|HTTP_RAW_POST_DATA|argc|argv|php_errormsg|http_response_header)/,
    scope: {
        pattern: /\b[\w\\]+::/,
        inside: {
            keyword: /(static|self|parent)/,
            punctuation: /(::|\\)/,
            _order: ["keyword", "punctuation"]
        }
    },
    _order: ["this", "global", "scope"]
});
 
// Add HTML support of 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') {
//             return;
//         }
//
//         env.tokenStack = [];
//
//         env.backupCode = env.code;
//         env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) {
//             env.tokenStack.push(match);
//
//             return '{{{PHP' + env.tokenStack.length + '}}}';
//         });
//     });
//
//     // Restore env.code for other plugins (e.g. line-numbers)
//     Prism.hooks.add('before-insert', function(env) {
//         if (env.language === 'php') {
//             env.code = env.backupCode;
//             delete env.backupCode;
//         }
//     });
//
//     // Re-insert the tokens after highlighting
//     Prism.hooks.add('after-highlight', function(env) {
//         if (env.language !== 'php') {
//             return;
//         }
//
//         for (var i = 0, t; t = env.tokenStack[i]; i++) {
//             // The replace prevents $$, $&, $`, $', $n, $nn from being interpreted as special patterns
//             env.highlightedCode = env.highlightedCode.replace('{{{PHP' + (i + 1) + '}}}', Prism.highlight(t, env.grammar, 'php').replace(/\$/g, '$$$$'));
//         }
//
//         env.element.innerHTML = env.highlightedCode;
//     });
//
//     // Wrap tokens in classes that are missing them
//     Prism.hooks.add('wrap', function(env) {
//         if (env.language === 'php' && env.type === 'markup') {
//             env.content = env.content.replace(/(\{\{\{PHP[0-9]+\}\}\})/g, "<span class=\"token php\">$1</span>");
//         }
//     });
//
//     // Add the rules before all others
//     Prism.languages.insertBefore('php', 'comment', {
//         'markup': {
//             pattern: /<[^?]\/?(.*?)>/,
//             inside: Prism.languages.markup
//         },
//         'php': /\{\{\{PHP[0-9]+\}\}\}/
//     });
//
//
exports.php = php;