History

Add Perl syntax highlighting

Thibaut Courouble committed 10 years ago

Commit 0b914901 parent f78b3651 file · +142 −1Browse files

Unified · Split

assets/javascripts/vendor/prism.js+142−1
@@ -1,4 +1,4 @@
1−/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+elixir+go+lua+nginx+php+python+rust+typescript */
1+/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+elixir+go+lua+nginx+perl+php+python+rust+typescript */
22 var _self = (typeof window !== 'undefined')
33 ? window // if in browser
44 : (
@@ -1034,6 +1034,147 @@ Prism.languages.nginx = Prism.languages.extend('clike', { · 1029 unmodified lines
10341034 Prism.languages.insertBefore('nginx', 'keyword', {
10351035 'variable': /\$[a-z_]+/i
10361036 });
1037+Prism.languages.perl = {
1038+ 'comment': [
1039+ {
1040+ // POD
1041+ pattern: /(^\s*)=\w+[\s\S]*?=cut.*/m,
1042+ lookbehind: true
1043+ },
1044+ {
1045+ pattern: /(^|[^\\$])#.*/,
1046+ lookbehind: true
1047+ }
1048+ ],
1049+ // TODO Could be nice to handle Heredoc too.
1050+ 'string': [
1051+ // q/.../
1052+ /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
1053+
1054+ // q a...a
1055+ /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\1/,
1056+
1057+ // q(...)
1058+ /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
1059+
1060+ // q{...}
1061+ /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
1062+
1063+ // q[...]
1064+ /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
1065+
1066+ // q<...>
1067+ /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
1068+
1069+ // "...", `...`
1070+ /("|`)(?:[^\\]|\\[\s\S])*?\1/,
1071+
1072+ // '...'
1073+ // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
1074+ /'(?:[^'\\\r\n]|\\.)*'/
1075+ ],
1076+ 'regex': [
1077+ // m/.../
1078+ /\b(?:m|qr)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[msixpodualngc]*/,
1079+
1080+ // m a...a
1081+ /\b(?:m|qr)\s+([a-zA-Z0-9])(?:[^\\]|\\.)*?\1[msixpodualngc]*/,
1082+
1083+ // m(...)
1084+ /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
1085+
1086+ // m{...}
1087+ /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
1088+
1089+ // m[...]
1090+ /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
1091+
1092+ // m<...>
1093+ /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
1094+
1095+ // The lookbehinds prevent -s from breaking
1096+ // FIXME We don't handle change of separator like s(...)[...]
1097+ // s/.../.../
1098+ {
1099+ pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
1100+ lookbehind: true
1101+ },
1102+
1103+ // s a...a...a
1104+ {
1105+ pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
1106+ lookbehind: true
1107+ },
1108+
1109+ // s(...)(...)
1110+ {
1111+ pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
1112+ lookbehind: true
1113+ },
1114+
1115+ // s{...}{...}
1116+ {
1117+ pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
1118+ lookbehind: true
1119+ },
1120+
1121+ // s[...][...]
1122+ {
1123+ pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
1124+ lookbehind: true
1125+ },
1126+
1127+ // s<...><...>
1128+ {
1129+ pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
1130+ lookbehind: true
1131+ },
1132+
1133+ // /.../
1134+ // The look-ahead tries to prevent two divisions on
1135+ // the same line from being highlighted as regex.
1136+ // This does not support multi-line regex.
1137+ /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/
1138+ ],
1139+
1140+ // FIXME Not sure about the handling of ::, ', and #
1141+ 'variable': [
1142+ // ${^POSTMATCH}
1143+ /[&*$@%]\{\^[A-Z]+\}/,
1144+ // $^V
1145+ /[&*$@%]\^[A-Z_]/,
1146+ // ${...}
1147+ /[&*$@%]#?(?=\{)/,
1148+ // $foo
1149+ /[&*$@%]#?((::)*'?(?!\d)[\w$]+)+(::)*/i,
1150+ // $1
1151+ /[&*$@%]\d+/,
1152+ // $_, @_, %!
1153+ // The negative lookahead prevents from breaking the %= operator
1154+ /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
1155+ ],
1156+ 'filehandle': {
1157+ // <>, <FOO>, _
1158+ pattern: /<(?![<=])\S*>|\b_\b/,
1159+ alias: 'symbol'
1160+ },
1161+ 'vstring': {
1162+ // v1.2, 1.2.3
1163+ pattern: /v\d+(\.\d+)*|\d+(\.\d+){2,}/,
1164+ alias: 'string'
1165+ },
1166+ 'function': {
1167+ pattern: /sub [a-z0-9_]+/i,
1168+ inside: {
1169+ keyword: /sub/
1170+ }
1171+ },
1172+ 'keyword': /\b(any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|say|state|sub|switch|undef|unless|until|use|when|while)\b/,
1173+ 'number': /\b-?(0x[\dA-Fa-f](_?[\dA-Fa-f])*|0b[01](_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)\b/,
1174+ 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor)\b/,
1175+ 'punctuation': /[{}[\];(),:]/
1176+};
1177+
10371178 /**
10381179 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
10391180 * Modified by Miles Johnson: http://milesj.me