angelscript.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. Language: AngelScript
  3. Author: Melissa Geels <melissa@nimble.tools>
  4. Category: scripting
  5. Website: https://www.angelcode.com/angelscript/
  6. */
  7. /** @type LanguageFn */
  8. function angelscript(hljs) {
  9. const builtInTypeMode = {
  10. className: 'built_in',
  11. begin: '\\b(void|bool|int8|int16|int32|int64|int|uint8|uint16|uint32|uint64|uint|string|ref|array|double|float|auto|dictionary)'
  12. };
  13. const objectHandleMode = {
  14. className: 'symbol',
  15. begin: '[a-zA-Z0-9_]+@'
  16. };
  17. const genericMode = {
  18. className: 'keyword',
  19. begin: '<',
  20. end: '>',
  21. contains: [
  22. builtInTypeMode,
  23. objectHandleMode
  24. ]
  25. };
  26. builtInTypeMode.contains = [ genericMode ];
  27. objectHandleMode.contains = [ genericMode ];
  28. const KEYWORDS = [
  29. "for",
  30. "in|0",
  31. "break",
  32. "continue",
  33. "while",
  34. "do|0",
  35. "return",
  36. "if",
  37. "else",
  38. "case",
  39. "switch",
  40. "namespace",
  41. "is",
  42. "cast",
  43. "or",
  44. "and",
  45. "xor",
  46. "not",
  47. "get|0",
  48. "in",
  49. "inout|10",
  50. "out",
  51. "override",
  52. "set|0",
  53. "private",
  54. "public",
  55. "const",
  56. "default|0",
  57. "final",
  58. "shared",
  59. "external",
  60. "mixin|10",
  61. "enum",
  62. "typedef",
  63. "funcdef",
  64. "this",
  65. "super",
  66. "import",
  67. "from",
  68. "interface",
  69. "abstract|0",
  70. "try",
  71. "catch",
  72. "protected",
  73. "explicit",
  74. "property"
  75. ];
  76. return {
  77. name: 'AngelScript',
  78. aliases: [ 'asc' ],
  79. keywords: KEYWORDS,
  80. // avoid close detection with C# and JS
  81. illegal: '(^using\\s+[A-Za-z0-9_\\.]+;$|\\bfunction\\s*[^\\(])',
  82. contains: [
  83. { // 'strings'
  84. className: 'string',
  85. begin: '\'',
  86. end: '\'',
  87. illegal: '\\n',
  88. contains: [ hljs.BACKSLASH_ESCAPE ],
  89. relevance: 0
  90. },
  91. // """heredoc strings"""
  92. {
  93. className: 'string',
  94. begin: '"""',
  95. end: '"""'
  96. },
  97. { // "strings"
  98. className: 'string',
  99. begin: '"',
  100. end: '"',
  101. illegal: '\\n',
  102. contains: [ hljs.BACKSLASH_ESCAPE ],
  103. relevance: 0
  104. },
  105. hljs.C_LINE_COMMENT_MODE, // single-line comments
  106. hljs.C_BLOCK_COMMENT_MODE, // comment blocks
  107. { // metadata
  108. className: 'string',
  109. begin: '^\\s*\\[',
  110. end: '\\]'
  111. },
  112. { // interface or namespace declaration
  113. beginKeywords: 'interface namespace',
  114. end: /\{/,
  115. illegal: '[;.\\-]',
  116. contains: [
  117. { // interface or namespace name
  118. className: 'symbol',
  119. begin: '[a-zA-Z0-9_]+'
  120. }
  121. ]
  122. },
  123. { // class declaration
  124. beginKeywords: 'class',
  125. end: /\{/,
  126. illegal: '[;.\\-]',
  127. contains: [
  128. { // class name
  129. className: 'symbol',
  130. begin: '[a-zA-Z0-9_]+',
  131. contains: [
  132. {
  133. begin: '[:,]\\s*',
  134. contains: [
  135. {
  136. className: 'symbol',
  137. begin: '[a-zA-Z0-9_]+'
  138. }
  139. ]
  140. }
  141. ]
  142. }
  143. ]
  144. },
  145. builtInTypeMode, // built-in types
  146. objectHandleMode, // object handles
  147. { // literals
  148. className: 'literal',
  149. begin: '\\b(null|true|false)'
  150. },
  151. { // numbers
  152. className: 'number',
  153. relevance: 0,
  154. begin: '(-?)(\\b0[xXbBoOdD][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?f?|\\.\\d+f?)([eE][-+]?\\d+f?)?)'
  155. }
  156. ]
  157. };
  158. }
  159. export { angelscript as default };