prism-parser.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (function (Prism) {
  2. var parser = Prism.languages.parser = Prism.languages.extend('markup', {
  3. 'keyword': {
  4. pattern: /(^|[^^])(?:\^(?:case|eval|for|if|switch|throw)\b|@(?:BASE|CLASS|GET(?:_DEFAULT)?|OPTIONS|SET_DEFAULT|USE)\b)/,
  5. lookbehind: true
  6. },
  7. 'variable': {
  8. pattern: /(^|[^^])\B\$(?:\w+|(?=[.{]))(?:(?:\.|::?)\w+)*(?:\.|::?)?/,
  9. lookbehind: true,
  10. inside: {
  11. 'punctuation': /\.|:+/
  12. }
  13. },
  14. 'function': {
  15. pattern: /(^|[^^])\B[@^]\w+(?:(?:\.|::?)\w+)*(?:\.|::?)?/,
  16. lookbehind: true,
  17. inside: {
  18. 'keyword': {
  19. pattern: /(^@)(?:GET_|SET_)/,
  20. lookbehind: true
  21. },
  22. 'punctuation': /\.|:+/
  23. }
  24. },
  25. 'escape': {
  26. pattern: /\^(?:[$^;@()\[\]{}"':]|#[a-f\d]*)/i,
  27. alias: 'builtin'
  28. },
  29. 'punctuation': /[\[\](){};]/
  30. });
  31. parser = Prism.languages.insertBefore('parser', 'keyword', {
  32. 'parser-comment': {
  33. pattern: /(\s)#.*/,
  34. lookbehind: true,
  35. alias: 'comment'
  36. },
  37. 'expression': {
  38. // Allow for 3 levels of depth
  39. pattern: /(^|[^^])\((?:[^()]|\((?:[^()]|\((?:[^()])*\))*\))*\)/,
  40. greedy: true,
  41. lookbehind: true,
  42. inside: {
  43. 'string': {
  44. pattern: /(^|[^^])(["'])(?:(?!\2)[^^]|\^[\s\S])*\2/,
  45. lookbehind: true
  46. },
  47. 'keyword': parser.keyword,
  48. 'variable': parser.variable,
  49. 'function': parser.function,
  50. 'boolean': /\b(?:false|true)\b/,
  51. 'number': /\b(?:0x[a-f\d]+|\d+(?:\.\d*)?(?:e[+-]?\d+)?)\b/i,
  52. 'escape': parser.escape,
  53. 'operator': /[~+*\/\\%]|!(?:\|\|?|=)?|&&?|\|\|?|==|<[<=]?|>[>=]?|-[fd]?|\b(?:def|eq|ge|gt|in|is|le|lt|ne)\b/,
  54. 'punctuation': parser.punctuation
  55. }
  56. }
  57. });
  58. Prism.languages.insertBefore('inside', 'punctuation', {
  59. 'expression': parser.expression,
  60. 'keyword': parser.keyword,
  61. 'variable': parser.variable,
  62. 'function': parser.function,
  63. 'escape': parser.escape,
  64. 'parser-punctuation': {
  65. pattern: parser.punctuation,
  66. alias: 'punctuation'
  67. }
  68. }, parser['tag'].inside['attr-value']);
  69. }(Prism));