coffee.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/coffee/coffee.ts
  8. var conf = {
  9. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#%\^\&\*\(\)\=\$\-\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  10. comments: {
  11. blockComment: ["###", "###"],
  12. lineComment: "#"
  13. },
  14. brackets: [
  15. ["{", "}"],
  16. ["[", "]"],
  17. ["(", ")"]
  18. ],
  19. autoClosingPairs: [
  20. { open: "{", close: "}" },
  21. { open: "[", close: "]" },
  22. { open: "(", close: ")" },
  23. { open: '"', close: '"' },
  24. { open: "'", close: "'" }
  25. ],
  26. surroundingPairs: [
  27. { open: "{", close: "}" },
  28. { open: "[", close: "]" },
  29. { open: "(", close: ")" },
  30. { open: '"', close: '"' },
  31. { open: "'", close: "'" }
  32. ],
  33. folding: {
  34. markers: {
  35. start: new RegExp("^\\s*#region\\b"),
  36. end: new RegExp("^\\s*#endregion\\b")
  37. }
  38. }
  39. };
  40. var language = {
  41. defaultToken: "",
  42. ignoreCase: true,
  43. tokenPostfix: ".coffee",
  44. brackets: [
  45. { open: "{", close: "}", token: "delimiter.curly" },
  46. { open: "[", close: "]", token: "delimiter.square" },
  47. { open: "(", close: ")", token: "delimiter.parenthesis" }
  48. ],
  49. regEx: /\/(?!\/\/)(?:[^\/\\]|\\.)*\/[igm]*/,
  50. keywords: [
  51. "and",
  52. "or",
  53. "is",
  54. "isnt",
  55. "not",
  56. "on",
  57. "yes",
  58. "@",
  59. "no",
  60. "off",
  61. "true",
  62. "false",
  63. "null",
  64. "this",
  65. "new",
  66. "delete",
  67. "typeof",
  68. "in",
  69. "instanceof",
  70. "return",
  71. "throw",
  72. "break",
  73. "continue",
  74. "debugger",
  75. "if",
  76. "else",
  77. "switch",
  78. "for",
  79. "while",
  80. "do",
  81. "try",
  82. "catch",
  83. "finally",
  84. "class",
  85. "extends",
  86. "super",
  87. "undefined",
  88. "then",
  89. "unless",
  90. "until",
  91. "loop",
  92. "of",
  93. "by",
  94. "when"
  95. ],
  96. symbols: /[=><!~?&%|+\-*\/\^\.,\:]+/,
  97. escapes: /\\(?:[abfnrtv\\"'$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  98. tokenizer: {
  99. root: [
  100. [/\@[a-zA-Z_]\w*/, "variable.predefined"],
  101. [
  102. /[a-zA-Z_]\w*/,
  103. {
  104. cases: {
  105. this: "variable.predefined",
  106. "@keywords": { token: "keyword.$0" },
  107. "@default": ""
  108. }
  109. }
  110. ],
  111. [/[ \t\r\n]+/, ""],
  112. [/###/, "comment", "@comment"],
  113. [/#.*$/, "comment"],
  114. ["///", { token: "regexp", next: "@hereregexp" }],
  115. [/^(\s*)(@regEx)/, ["", "regexp"]],
  116. [/(\()(\s*)(@regEx)/, ["@brackets", "", "regexp"]],
  117. [/(\,)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  118. [/(\=)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  119. [/(\:)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  120. [/(\[)(\s*)(@regEx)/, ["@brackets", "", "regexp"]],
  121. [/(\!)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  122. [/(\&)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  123. [/(\|)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  124. [/(\?)(\s*)(@regEx)/, ["delimiter", "", "regexp"]],
  125. [/(\{)(\s*)(@regEx)/, ["@brackets", "", "regexp"]],
  126. [/(\;)(\s*)(@regEx)/, ["", "", "regexp"]],
  127. [
  128. /}/,
  129. {
  130. cases: {
  131. "$S2==interpolatedstring": {
  132. token: "string",
  133. next: "@pop"
  134. },
  135. "@default": "@brackets"
  136. }
  137. }
  138. ],
  139. [/[{}()\[\]]/, "@brackets"],
  140. [/@symbols/, "delimiter"],
  141. [/\d+[eE]([\-+]?\d+)?/, "number.float"],
  142. [/\d+\.\d+([eE][\-+]?\d+)?/, "number.float"],
  143. [/0[xX][0-9a-fA-F]+/, "number.hex"],
  144. [/0[0-7]+(?!\d)/, "number.octal"],
  145. [/\d+/, "number"],
  146. [/[,.]/, "delimiter"],
  147. [/"""/, "string", '@herestring."""'],
  148. [/'''/, "string", "@herestring.'''"],
  149. [
  150. /"/,
  151. {
  152. cases: {
  153. "@eos": "string",
  154. "@default": { token: "string", next: '@string."' }
  155. }
  156. }
  157. ],
  158. [
  159. /'/,
  160. {
  161. cases: {
  162. "@eos": "string",
  163. "@default": { token: "string", next: "@string.'" }
  164. }
  165. }
  166. ]
  167. ],
  168. string: [
  169. [/[^"'\#\\]+/, "string"],
  170. [/@escapes/, "string.escape"],
  171. [/\./, "string.escape.invalid"],
  172. [/\./, "string.escape.invalid"],
  173. [
  174. /#{/,
  175. {
  176. cases: {
  177. '$S2=="': {
  178. token: "string",
  179. next: "root.interpolatedstring"
  180. },
  181. "@default": "string"
  182. }
  183. }
  184. ],
  185. [
  186. /["']/,
  187. {
  188. cases: {
  189. "$#==$S2": { token: "string", next: "@pop" },
  190. "@default": "string"
  191. }
  192. }
  193. ],
  194. [/#/, "string"]
  195. ],
  196. herestring: [
  197. [
  198. /("""|''')/,
  199. {
  200. cases: {
  201. "$1==$S2": { token: "string", next: "@pop" },
  202. "@default": "string"
  203. }
  204. }
  205. ],
  206. [/[^#\\'"]+/, "string"],
  207. [/['"]+/, "string"],
  208. [/@escapes/, "string.escape"],
  209. [/\./, "string.escape.invalid"],
  210. [/#{/, { token: "string.quote", next: "root.interpolatedstring" }],
  211. [/#/, "string"]
  212. ],
  213. comment: [
  214. [/[^#]+/, "comment"],
  215. [/###/, "comment", "@pop"],
  216. [/#/, "comment"]
  217. ],
  218. hereregexp: [
  219. [/[^\\\/#]+/, "regexp"],
  220. [/\\./, "regexp"],
  221. [/#.*$/, "comment"],
  222. ["///[igm]*", { token: "regexp", next: "@pop" }],
  223. [/\//, "regexp"]
  224. ]
  225. }
  226. };
  227. export {
  228. conf,
  229. language
  230. };