actionscript.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. Language: ActionScript
  3. Author: Alexander Myadzel <myadzel@gmail.com>
  4. Category: scripting
  5. Audit: 2020
  6. */
  7. /** @type LanguageFn */
  8. function actionscript(hljs) {
  9. const regex = hljs.regex;
  10. const IDENT_RE = /[a-zA-Z_$][a-zA-Z0-9_$]*/;
  11. const PKG_NAME_RE = regex.concat(
  12. IDENT_RE,
  13. regex.concat("(\\.", IDENT_RE, ")*")
  14. );
  15. const IDENT_FUNC_RETURN_TYPE_RE = /([*]|[a-zA-Z_$][a-zA-Z0-9_$]*)/;
  16. const AS3_REST_ARG_MODE = {
  17. className: 'rest_arg',
  18. begin: /[.]{3}/,
  19. end: IDENT_RE,
  20. relevance: 10
  21. };
  22. const KEYWORDS = [
  23. "as",
  24. "break",
  25. "case",
  26. "catch",
  27. "class",
  28. "const",
  29. "continue",
  30. "default",
  31. "delete",
  32. "do",
  33. "dynamic",
  34. "each",
  35. "else",
  36. "extends",
  37. "final",
  38. "finally",
  39. "for",
  40. "function",
  41. "get",
  42. "if",
  43. "implements",
  44. "import",
  45. "in",
  46. "include",
  47. "instanceof",
  48. "interface",
  49. "internal",
  50. "is",
  51. "namespace",
  52. "native",
  53. "new",
  54. "override",
  55. "package",
  56. "private",
  57. "protected",
  58. "public",
  59. "return",
  60. "set",
  61. "static",
  62. "super",
  63. "switch",
  64. "this",
  65. "throw",
  66. "try",
  67. "typeof",
  68. "use",
  69. "var",
  70. "void",
  71. "while",
  72. "with"
  73. ];
  74. const LITERALS = [
  75. "true",
  76. "false",
  77. "null",
  78. "undefined"
  79. ];
  80. return {
  81. name: 'ActionScript',
  82. aliases: [ 'as' ],
  83. keywords: {
  84. keyword: KEYWORDS,
  85. literal: LITERALS
  86. },
  87. contains: [
  88. hljs.APOS_STRING_MODE,
  89. hljs.QUOTE_STRING_MODE,
  90. hljs.C_LINE_COMMENT_MODE,
  91. hljs.C_BLOCK_COMMENT_MODE,
  92. hljs.C_NUMBER_MODE,
  93. {
  94. match: [
  95. /\bpackage/,
  96. /\s+/,
  97. PKG_NAME_RE
  98. ],
  99. className: {
  100. 1: "keyword",
  101. 3: "title.class"
  102. }
  103. },
  104. {
  105. match: [
  106. /\b(?:class|interface|extends|implements)/,
  107. /\s+/,
  108. IDENT_RE
  109. ],
  110. className: {
  111. 1: "keyword",
  112. 3: "title.class"
  113. }
  114. },
  115. {
  116. className: 'meta',
  117. beginKeywords: 'import include',
  118. end: /;/,
  119. keywords: { keyword: 'import include' }
  120. },
  121. {
  122. beginKeywords: 'function',
  123. end: /[{;]/,
  124. excludeEnd: true,
  125. illegal: /\S/,
  126. contains: [
  127. hljs.inherit(hljs.TITLE_MODE, { className: "title.function" }),
  128. {
  129. className: 'params',
  130. begin: /\(/,
  131. end: /\)/,
  132. contains: [
  133. hljs.APOS_STRING_MODE,
  134. hljs.QUOTE_STRING_MODE,
  135. hljs.C_LINE_COMMENT_MODE,
  136. hljs.C_BLOCK_COMMENT_MODE,
  137. AS3_REST_ARG_MODE
  138. ]
  139. },
  140. { begin: regex.concat(/:\s*/, IDENT_FUNC_RETURN_TYPE_RE) }
  141. ]
  142. },
  143. hljs.METHOD_GUARD
  144. ],
  145. illegal: /#/
  146. };
  147. }
  148. export { actionscript as default };