haxe.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. Language: Haxe
  3. Description: Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.
  4. Author: Christopher Kaster <ikasoki@gmail.com> (Based on the actionscript.js language file by Alexander Myadzel)
  5. Contributors: Kenton Hamaluik <kentonh@gmail.com>
  6. Website: https://haxe.org
  7. Category: system
  8. */
  9. function haxe(hljs) {
  10. const IDENT_RE = '[a-zA-Z_$][a-zA-Z0-9_$]*';
  11. // C_NUMBER_RE with underscores and literal suffixes
  12. const HAXE_NUMBER_RE = /(-?)(\b0[xX][a-fA-F0-9_]+|(\b\d+(\.[\d_]*)?|\.[\d_]+)(([eE][-+]?\d+)|i32|u32|i64|f64)?)/;
  13. const HAXE_BASIC_TYPES = 'Int Float String Bool Dynamic Void Array ';
  14. return {
  15. name: 'Haxe',
  16. aliases: [ 'hx' ],
  17. keywords: {
  18. keyword: 'abstract break case cast catch continue default do dynamic else enum extern '
  19. + 'final for function here if import in inline is macro never new override package private get set '
  20. + 'public return static super switch this throw trace try typedef untyped using var while '
  21. + HAXE_BASIC_TYPES,
  22. built_in:
  23. 'trace this',
  24. literal:
  25. 'true false null _'
  26. },
  27. contains: [
  28. {
  29. className: 'string', // interpolate-able strings
  30. begin: '\'',
  31. end: '\'',
  32. contains: [
  33. hljs.BACKSLASH_ESCAPE,
  34. {
  35. className: 'subst', // interpolation
  36. begin: /\$\{/,
  37. end: /\}/
  38. },
  39. {
  40. className: 'subst', // interpolation
  41. begin: /\$/,
  42. end: /\W\}/
  43. }
  44. ]
  45. },
  46. hljs.QUOTE_STRING_MODE,
  47. hljs.C_LINE_COMMENT_MODE,
  48. hljs.C_BLOCK_COMMENT_MODE,
  49. {
  50. className: 'number',
  51. begin: HAXE_NUMBER_RE,
  52. relevance: 0
  53. },
  54. {
  55. className: 'variable',
  56. begin: "\\$" + IDENT_RE,
  57. },
  58. {
  59. className: 'meta', // compiler meta
  60. begin: /@:?/,
  61. end: /\(|$/,
  62. excludeEnd: true,
  63. },
  64. {
  65. className: 'meta', // compiler conditionals
  66. begin: '#',
  67. end: '$',
  68. keywords: { keyword: 'if else elseif end error' }
  69. },
  70. {
  71. className: 'type', // function types
  72. begin: /:[ \t]*/,
  73. end: /[^A-Za-z0-9_ \t\->]/,
  74. excludeBegin: true,
  75. excludeEnd: true,
  76. relevance: 0
  77. },
  78. {
  79. className: 'type', // types
  80. begin: /:[ \t]*/,
  81. end: /\W/,
  82. excludeBegin: true,
  83. excludeEnd: true
  84. },
  85. {
  86. className: 'type', // instantiation
  87. beginKeywords: 'new',
  88. end: /\W/,
  89. excludeBegin: true,
  90. excludeEnd: true
  91. },
  92. {
  93. className: 'title.class', // enums
  94. beginKeywords: 'enum',
  95. end: /\{/,
  96. contains: [ hljs.TITLE_MODE ]
  97. },
  98. {
  99. className: 'title.class', // abstracts
  100. begin: '\\babstract\\b(?=\\s*' + hljs.IDENT_RE + '\\s*\\()',
  101. end: /[\{$]/,
  102. contains: [
  103. {
  104. className: 'type',
  105. begin: /\(/,
  106. end: /\)/,
  107. excludeBegin: true,
  108. excludeEnd: true
  109. },
  110. {
  111. className: 'type',
  112. begin: /from +/,
  113. end: /\W/,
  114. excludeBegin: true,
  115. excludeEnd: true
  116. },
  117. {
  118. className: 'type',
  119. begin: /to +/,
  120. end: /\W/,
  121. excludeBegin: true,
  122. excludeEnd: true
  123. },
  124. hljs.TITLE_MODE
  125. ],
  126. keywords: { keyword: 'abstract from to' }
  127. },
  128. {
  129. className: 'title.class', // classes
  130. begin: /\b(class|interface) +/,
  131. end: /[\{$]/,
  132. excludeEnd: true,
  133. keywords: 'class interface',
  134. contains: [
  135. {
  136. className: 'keyword',
  137. begin: /\b(extends|implements) +/,
  138. keywords: 'extends implements',
  139. contains: [
  140. {
  141. className: 'type',
  142. begin: hljs.IDENT_RE,
  143. relevance: 0
  144. }
  145. ]
  146. },
  147. hljs.TITLE_MODE
  148. ]
  149. },
  150. {
  151. className: 'title.function',
  152. beginKeywords: 'function',
  153. end: /\(/,
  154. excludeEnd: true,
  155. illegal: /\S/,
  156. contains: [ hljs.TITLE_MODE ]
  157. }
  158. ],
  159. illegal: /<\//
  160. };
  161. }
  162. export { haxe as default };