1
0

clojure.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. 'use strict';
  6. import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
  7. import ILanguage = monaco.languages.IMonarchLanguage;
  8. export const conf: IRichLanguageConfiguration = {
  9. comments: {
  10. lineComment: ';;',
  11. blockComment: ['(comment', ')'],
  12. },
  13. brackets: [['(', ')'], ['{', '}'], ['[', ']']],
  14. autoClosingPairs: [
  15. { open: '{', close: '}' },
  16. { open: '[', close: ']' },
  17. { open: '(', close: ')' },
  18. { open: '"', close: '"' },
  19. ],
  20. surroundingPairs: [
  21. { open: '{', close: '}' },
  22. { open: '[', close: ']' },
  23. { open: '(', close: ')' },
  24. { open: '"', close: '"' },
  25. ],
  26. };
  27. export const language = <ILanguage>{
  28. defaultToken: '',
  29. ignoreCase: true,
  30. tokenPostfix: '.clj',
  31. brackets: [
  32. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  33. { open: '{', close: '}', token: 'delimiter.curly' },
  34. { open: '[', close: ']', token: 'delimiter.square' },
  35. ],
  36. keywords: [
  37. 'ns',
  38. 'ns-unmap',
  39. 'create-ns',
  40. 'in-ns',
  41. 'fn',
  42. 'def',
  43. 'defn',
  44. 'defmacro',
  45. 'defmulti',
  46. 'defonce',
  47. 'require',
  48. 'import',
  49. 'new',
  50. 'refer',
  51. 'pos',
  52. 'pos?',
  53. 'filter',
  54. 'map',
  55. 'reduce',
  56. 'repeat',
  57. 'key',
  58. 'rest',
  59. 'concat',
  60. 'into',
  61. 'reverse',
  62. 'iterate',
  63. 'range',
  64. 'drop',
  65. 'drop-while',
  66. 'take',
  67. 'take-while',
  68. 'neg',
  69. 'neg?',
  70. 'bound-fn',
  71. 'if',
  72. 'if-not',
  73. 'if-let',
  74. 'case,',
  75. 'contains',
  76. 'conj',
  77. 'disj',
  78. 'sort',
  79. 'get',
  80. 'assoc',
  81. 'merge',
  82. 'keys',
  83. 'vals',
  84. 'nth',
  85. 'first',
  86. 'last',
  87. 'count',
  88. 'contains?',
  89. 'cond',
  90. 'condp',
  91. 'cond->',
  92. 'cond->>',
  93. 'when',
  94. 'while',
  95. 'when-not',
  96. 'when-let',
  97. 'when-first',
  98. 'do',
  99. 'future',
  100. 'comment',
  101. 'doto',
  102. 'locking',
  103. 'proxy',
  104. 'println',
  105. 'type',
  106. 'meta',
  107. 'var',
  108. 'as->',
  109. 'reify',
  110. 'deftype',
  111. 'defrecord',
  112. 'defprotocol',
  113. 'extend',
  114. 'extend-protocol',
  115. 'extend-type',
  116. 'specify',
  117. 'specify!',
  118. 'try',
  119. 'catch',
  120. 'finally',
  121. 'let',
  122. 'letfn',
  123. 'binding',
  124. 'loop',
  125. 'for',
  126. 'seq',
  127. 'doseq',
  128. 'dotimes',
  129. 'when-let',
  130. 'if-let',
  131. 'when-some',
  132. 'if-some',
  133. 'this-as',
  134. 'defmethod',
  135. 'testing',
  136. 'deftest',
  137. 'are',
  138. 'use-fixtures',
  139. 'use',
  140. 'remove',
  141. 'run',
  142. 'run*',
  143. 'fresh',
  144. 'alt!',
  145. 'alt!!',
  146. 'go',
  147. 'go-loop',
  148. 'thread',
  149. 'boolean',
  150. 'str',
  151. ],
  152. constants: ['true', 'false', 'nil'],
  153. operators: [
  154. '=',
  155. 'not=',
  156. '<',
  157. '<=',
  158. '>',
  159. '>=',
  160. 'and',
  161. 'or',
  162. 'not',
  163. 'inc',
  164. 'dec',
  165. 'max',
  166. 'min',
  167. 'rem',
  168. 'bit-and',
  169. 'bit-or',
  170. 'bit-xor',
  171. 'bit-not',
  172. ],
  173. tokenizer: {
  174. root: [
  175. [/0[xX][0-9a-fA-F]+/, 'number.hex'],
  176. [/[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?/, 'number.float'],
  177. [
  178. /(?:\b(?:(ns|def|defn|defn-|defmacro|defmulti|defonce|ns|ns-unmap|fn))(?![\w-]))(\s+)((?:\w|\-|\!|\?)*)/,
  179. ['keyword', 'white', 'variable'],
  180. ],
  181. [
  182. /[a-zA-Z_#][a-zA-Z0-9_\-\?\!\*]*/,
  183. {
  184. cases: {
  185. '@keywords': 'keyword',
  186. '@constants': 'constant',
  187. '@operators': 'operators',
  188. '@default': 'identifier',
  189. },
  190. },
  191. ],
  192. { include: '@whitespace' },
  193. { include: '@strings' },
  194. ],
  195. comment: [
  196. [/[^\(comment]+/, 'comment'],
  197. [/\)/, 'comment', '@push'],
  198. [/\(comment/, 'comment', '@pop'],
  199. [/[\)]/, 'comment'],
  200. ],
  201. whitespace: [
  202. [/[ \t\r\n]+/, 'white'],
  203. [/\(comment/, 'comment', '@comment'],
  204. [/;;.*$/, 'comment'],
  205. ],
  206. strings: [
  207. [/"$/, 'string', '@popall'],
  208. [/"(?=.)/, 'string', '@multiLineString'],
  209. ],
  210. multiLineString: [
  211. [/\\./, 'string.escape'],
  212. [/"/, 'string', '@popall'],
  213. [/.(?=.*")/, 'string'],
  214. [/.*\\$/, 'string'],
  215. [/.*$/, 'string', '@popall'],
  216. ],
  217. },
  218. };