actionscript.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @param {string} value
  3. * @returns {RegExp}
  4. * */
  5. /**
  6. * @param {RegExp | string } re
  7. * @returns {string}
  8. */
  9. function source(re) {
  10. if (!re) return null;
  11. if (typeof re === "string") return re;
  12. return re.source;
  13. }
  14. /**
  15. * @param {...(RegExp | string) } args
  16. * @returns {string}
  17. */
  18. function concat(...args) {
  19. const joined = args.map((x) => source(x)).join("");
  20. return joined;
  21. }
  22. /*
  23. Language: ActionScript
  24. Author: Alexander Myadzel <myadzel@gmail.com>
  25. Category: scripting
  26. Audit: 2020
  27. */
  28. /** @type LanguageFn */
  29. function actionscript(hljs) {
  30. const IDENT_RE = /[a-zA-Z_$][a-zA-Z0-9_$]*/;
  31. const IDENT_FUNC_RETURN_TYPE_RE = /([*]|[a-zA-Z_$][a-zA-Z0-9_$]*)/;
  32. const AS3_REST_ARG_MODE = {
  33. className: 'rest_arg',
  34. begin: /[.]{3}/,
  35. end: IDENT_RE,
  36. relevance: 10
  37. };
  38. return {
  39. name: 'ActionScript',
  40. aliases: [ 'as' ],
  41. keywords: {
  42. keyword: 'as break case catch class const continue default delete do dynamic each ' +
  43. 'else extends final finally for function get if implements import in include ' +
  44. 'instanceof interface internal is namespace native new override package private ' +
  45. 'protected public return set static super switch this throw try typeof use var void ' +
  46. 'while with',
  47. literal: 'true false null undefined'
  48. },
  49. contains: [
  50. hljs.APOS_STRING_MODE,
  51. hljs.QUOTE_STRING_MODE,
  52. hljs.C_LINE_COMMENT_MODE,
  53. hljs.C_BLOCK_COMMENT_MODE,
  54. hljs.C_NUMBER_MODE,
  55. {
  56. className: 'class',
  57. beginKeywords: 'package',
  58. end: /\{/,
  59. contains: [ hljs.TITLE_MODE ]
  60. },
  61. {
  62. className: 'class',
  63. beginKeywords: 'class interface',
  64. end: /\{/,
  65. excludeEnd: true,
  66. contains: [
  67. { beginKeywords: 'extends implements' },
  68. hljs.TITLE_MODE
  69. ]
  70. },
  71. {
  72. className: 'meta',
  73. beginKeywords: 'import include',
  74. end: /;/,
  75. keywords: { 'meta-keyword': 'import include' }
  76. },
  77. {
  78. className: 'function',
  79. beginKeywords: 'function',
  80. end: /[{;]/,
  81. excludeEnd: true,
  82. illegal: /\S/,
  83. contains: [
  84. hljs.TITLE_MODE,
  85. {
  86. className: 'params',
  87. begin: /\(/,
  88. end: /\)/,
  89. contains: [
  90. hljs.APOS_STRING_MODE,
  91. hljs.QUOTE_STRING_MODE,
  92. hljs.C_LINE_COMMENT_MODE,
  93. hljs.C_BLOCK_COMMENT_MODE,
  94. AS3_REST_ARG_MODE
  95. ]
  96. },
  97. { begin: concat(/:\s*/, IDENT_FUNC_RETURN_TYPE_RE) }
  98. ]
  99. },
  100. hljs.METHOD_GUARD
  101. ],
  102. illegal: /#/
  103. };
  104. }
  105. module.exports = actionscript;