monkey.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. Language: Monkey
  3. Description: Monkey2 is an easy to use, cross platform, games oriented programming language from Blitz Research.
  4. Author: Arthur Bikmullin <devolonter@gmail.com>
  5. Website: https://blitzresearch.itch.io/monkey2
  6. */
  7. function monkey(hljs) {
  8. const NUMBER = {
  9. className: 'number',
  10. relevance: 0,
  11. variants: [
  12. { begin: '[$][a-fA-F0-9]+' },
  13. hljs.NUMBER_MODE
  14. ]
  15. };
  16. const FUNC_DEFINITION = {
  17. variants: [
  18. { match: [
  19. /(function|method)/,
  20. /\s+/,
  21. hljs.UNDERSCORE_IDENT_RE,
  22. ] },
  23. ],
  24. scope: {
  25. 1: "keyword",
  26. 3: "title.function"
  27. }
  28. };
  29. const CLASS_DEFINITION = {
  30. variants: [
  31. { match: [
  32. /(class|interface|extends|implements)/,
  33. /\s+/,
  34. hljs.UNDERSCORE_IDENT_RE,
  35. ] },
  36. ],
  37. scope: {
  38. 1: "keyword",
  39. 3: "title.class"
  40. }
  41. };
  42. const BUILT_INS = [
  43. "DebugLog",
  44. "DebugStop",
  45. "Error",
  46. "Print",
  47. "ACos",
  48. "ACosr",
  49. "ASin",
  50. "ASinr",
  51. "ATan",
  52. "ATan2",
  53. "ATan2r",
  54. "ATanr",
  55. "Abs",
  56. "Abs",
  57. "Ceil",
  58. "Clamp",
  59. "Clamp",
  60. "Cos",
  61. "Cosr",
  62. "Exp",
  63. "Floor",
  64. "Log",
  65. "Max",
  66. "Max",
  67. "Min",
  68. "Min",
  69. "Pow",
  70. "Sgn",
  71. "Sgn",
  72. "Sin",
  73. "Sinr",
  74. "Sqrt",
  75. "Tan",
  76. "Tanr",
  77. "Seed",
  78. "PI",
  79. "HALFPI",
  80. "TWOPI"
  81. ];
  82. const LITERALS = [
  83. "true",
  84. "false",
  85. "null"
  86. ];
  87. const KEYWORDS = [
  88. "public",
  89. "private",
  90. "property",
  91. "continue",
  92. "exit",
  93. "extern",
  94. "new",
  95. "try",
  96. "catch",
  97. "eachin",
  98. "not",
  99. "abstract",
  100. "final",
  101. "select",
  102. "case",
  103. "default",
  104. "const",
  105. "local",
  106. "global",
  107. "field",
  108. "end",
  109. "if",
  110. "then",
  111. "else",
  112. "elseif",
  113. "endif",
  114. "while",
  115. "wend",
  116. "repeat",
  117. "until",
  118. "forever",
  119. "for",
  120. "to",
  121. "step",
  122. "next",
  123. "return",
  124. "module",
  125. "inline",
  126. "throw",
  127. "import",
  128. // not positive, but these are not literals
  129. "and",
  130. "or",
  131. "shl",
  132. "shr",
  133. "mod"
  134. ];
  135. return {
  136. name: 'Monkey',
  137. case_insensitive: true,
  138. keywords: {
  139. keyword: KEYWORDS,
  140. built_in: BUILT_INS,
  141. literal: LITERALS
  142. },
  143. illegal: /\/\*/,
  144. contains: [
  145. hljs.COMMENT('#rem', '#end'),
  146. hljs.COMMENT(
  147. "'",
  148. '$',
  149. { relevance: 0 }
  150. ),
  151. FUNC_DEFINITION,
  152. CLASS_DEFINITION,
  153. {
  154. className: 'variable.language',
  155. begin: /\b(self|super)\b/
  156. },
  157. {
  158. className: 'meta',
  159. begin: /\s*#/,
  160. end: '$',
  161. keywords: { keyword: 'if else elseif endif end then' }
  162. },
  163. {
  164. match: [
  165. /^\s*/,
  166. /strict\b/
  167. ],
  168. scope: { 2: "meta" }
  169. },
  170. {
  171. beginKeywords: 'alias',
  172. end: '=',
  173. contains: [ hljs.UNDERSCORE_TITLE_MODE ]
  174. },
  175. hljs.QUOTE_STRING_MODE,
  176. NUMBER
  177. ]
  178. };
  179. }
  180. export { monkey as default };