prism-haxe.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Prism.languages.haxe = Prism.languages.extend('clike', {
  2. 'string': {
  3. // Strings can be multi-line
  4. pattern: /"(?:[^"\\]|\\[\s\S])*"/,
  5. greedy: true
  6. },
  7. 'class-name': [
  8. {
  9. pattern: /(\b(?:abstract|class|enum|extends|implements|interface|new|typedef)\s+)[A-Z_]\w*/,
  10. lookbehind: true,
  11. },
  12. // based on naming convention
  13. /\b[A-Z]\w*/
  14. ],
  15. // The final look-ahead prevents highlighting of keywords if expressions such as "haxe.macro.Expr"
  16. 'keyword': /\bthis\b|\b(?:abstract|as|break|case|cast|catch|class|continue|default|do|dynamic|else|enum|extends|extern|final|for|from|function|if|implements|import|in|inline|interface|macro|new|null|operator|overload|override|package|private|public|return|static|super|switch|throw|to|try|typedef|untyped|using|var|while)(?!\.)\b/,
  17. 'function': {
  18. pattern: /\b[a-z_]\w*(?=\s*(?:<[^<>]*>\s*)?\()/i,
  19. greedy: true
  20. },
  21. 'operator': /\.{3}|\+\+|--|&&|\|\||->|=>|(?:<<?|>{1,3}|[-+*/%!=&|^])=?|[?:~]/
  22. });
  23. Prism.languages.insertBefore('haxe', 'string', {
  24. 'string-interpolation': {
  25. pattern: /'(?:[^'\\]|\\[\s\S])*'/,
  26. greedy: true,
  27. inside: {
  28. 'interpolation': {
  29. pattern: /(^|[^\\])\$(?:\w+|\{[^{}]+\})/,
  30. lookbehind: true,
  31. inside: {
  32. 'interpolation-punctuation': {
  33. pattern: /^\$\{?|\}$/,
  34. alias: 'punctuation'
  35. },
  36. 'expression': {
  37. pattern: /[\s\S]+/,
  38. inside: Prism.languages.haxe
  39. },
  40. }
  41. },
  42. 'string': /[\s\S]+/
  43. }
  44. }
  45. });
  46. Prism.languages.insertBefore('haxe', 'class-name', {
  47. 'regex': {
  48. pattern: /~\/(?:[^\/\\\r\n]|\\.)+\/[a-z]*/,
  49. greedy: true,
  50. inside: {
  51. 'regex-flags': /\b[a-z]+$/,
  52. 'regex-source': {
  53. pattern: /^(~\/)[\s\S]+(?=\/$)/,
  54. lookbehind: true,
  55. alias: 'language-regex',
  56. inside: Prism.languages.regex
  57. },
  58. 'regex-delimiter': /^~\/|\/$/,
  59. }
  60. }
  61. });
  62. Prism.languages.insertBefore('haxe', 'keyword', {
  63. 'preprocessor': {
  64. pattern: /#(?:else|elseif|end|if)\b.*/,
  65. alias: 'property'
  66. },
  67. 'metadata': {
  68. pattern: /@:?[\w.]+/,
  69. alias: 'symbol'
  70. },
  71. 'reification': {
  72. pattern: /\$(?:\w+|(?=\{))/,
  73. alias: 'important'
  74. }
  75. });