prism-perl.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. Prism.languages.perl = {
  2. 'comment': [
  3. {
  4. // POD
  5. pattern: /((?:^|\n)\s*)=\w+[\s\S]*?=cut.*/,
  6. lookbehind: true
  7. },
  8. {
  9. pattern: /(^|[^\\$])#.*?(\r?\n|$)/,
  10. lookbehind: true
  11. }
  12. ],
  13. // TODO Could be nice to handle Heredoc too.
  14. 'string': [
  15. // q/.../
  16. /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s\{\(\[<])(\\?.)*?\s*\1/,
  17. // q a...a
  18. /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(\\?.)*?\s*\1/,
  19. // q(...)
  20. /\b(?:q|qq|qx|qw)\s*\(([^()]|\\.)*\s*\)/,
  21. // q{...}
  22. /\b(?:q|qq|qx|qw)\s*\{([^{}]|\\.)*\s*\}/,
  23. // q[...]
  24. /\b(?:q|qq|qx|qw)\s*\[([^[\]]|\\.)*\s*\]/,
  25. // q<...>
  26. /\b(?:q|qq|qx|qw)\s*<([^<>]|\\.)*\s*>/,
  27. // "...", '...', `...`
  28. /("|'|`)(\\?.)*?\1/
  29. ],
  30. 'regex': [
  31. // m/.../
  32. /\b(?:m|qr)\s*([^a-zA-Z0-9\s\{\(\[<])(\\?.)*?\s*\1[msixpodualgc]*/,
  33. // m a...a
  34. /\b(?:m|qr)\s+([a-zA-Z0-9])(\\?.)*?\s*\1[msixpodualgc]*/,
  35. // m(...)
  36. /\b(?:m|qr)\s*\(([^()]|\\.)*\s*\)[msixpodualgc]*/,
  37. // m{...}
  38. /\b(?:m|qr)\s*\{([^{}]|\\.)*\s*\}[msixpodualgc]*/,
  39. // m[...]
  40. /\b(?:m|qr)\s*\[([^[\]]|\\.)*\s*\][msixpodualgc]*/,
  41. // m<...>
  42. /\b(?:m|qr)\s*<([^<>]|\\.)*\s*>[msixpodualgc]*/,
  43. // s/.../.../
  44. /\b(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(\\?.)*?\s*\1\s*((?!\1).|\\.)*\s*\1[msixpodualgcer]*/,
  45. // s a...a...a
  46. /\b(?:s|tr|y)\s+([a-zA-Z0-9])(\\?.)*?\s*\1\s*((?!\1).|\\.)*\s*\1[msixpodualgcer]*/,
  47. // s(...)(...)
  48. /\b(?:s|tr|y)\s*\(([^()]|\\.)*\s*\)\s*\(\s*([^()]|\\.)*\s*\)[msixpodualgcer]*/,
  49. // s{...}{...}
  50. /\b(?:s|tr|y)\s*\{([^{}]|\\.)*\s*\}\s*\{\s*([^{}]|\\.)*\s*\}[msixpodualgcer]*/,
  51. // s[...][...]
  52. /\b(?:s|tr|y)\s*\[([^[\]]|\\.)*\s*\]\s*\[\s*([^[\]]|\\.)*\s*\][msixpodualgcer]*/,
  53. // s<...><...>
  54. /\b(?:s|tr|y)\s*<([^<>]|\\.)*\s*>\s*<\s*([^<>]|\\.)*\s*>[msixpodualgcer]*/,
  55. // /.../
  56. /\/(\[.+?]|\\.|[^\/\r\n])*\/[msixpodualgc]*(?=\s*($|[\r\n,.;})&|\-+*=~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/
  57. ],
  58. // FIXME Not sure about the handling of ::, ', and #
  59. 'variable': [
  60. // ${^POSTMATCH}
  61. /[&*\$@%]\{\^[A-Z]+\}/,
  62. // $^V
  63. /[&*\$@%]\^[A-Z_]/,
  64. // ${...}
  65. /[&*\$@%]#?(?=\{)/,
  66. // $foo
  67. /[&*\$@%]#?((::)*'?(?!\d)[\w$]+)+(::)*/i,
  68. // $1
  69. /[&*\$@%]\d+/,
  70. // $_, @_, %!
  71. /[\$@%][!"#\$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  72. ],
  73. 'filehandle': {
  74. // <>, <FOO>, _
  75. pattern: /<(?!=).*>|\b_\b/,
  76. alias: 'symbol'
  77. },
  78. 'vstring': {
  79. // v1.2, 1.2.3
  80. pattern: /v\d+(\.\d+)*|\d+(\.\d+){2,}/,
  81. alias: 'string'
  82. },
  83. 'function': {
  84. pattern: /sub [a-z0-9_]+/i,
  85. inside: {
  86. keyword: /sub/
  87. }
  88. },
  89. '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/,
  90. 'number': /(\n|\b)-?(0x[\dA-Fa-f](_?[\dA-Fa-f])*|0b[01](_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee]-?\d+)?)\b/,
  91. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|[-+*=~\/|&]{1,2}|<=?|>=?|\.{1,3}|[!?\\^]|\b(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b/,
  92. 'punctuation': /[{}[\];(),:]/
  93. };