clojure.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
  6. import ILanguage = monaco.languages.IMonarchLanguage;
  7. export const conf: IRichLanguageConfiguration = {
  8. comments: {
  9. lineComment: ';;'
  10. },
  11. brackets: [
  12. ['[', ']'],
  13. ['(', ')'],
  14. ['{', '}']
  15. ],
  16. autoClosingPairs: [
  17. { open: '[', close: ']' },
  18. { open: '"', close: '"' },
  19. { open: '(', close: ')' },
  20. { open: '{', close: '}' }
  21. ],
  22. surroundingPairs: [
  23. { open: '[', close: ']' },
  24. { open: '"', close: '"' },
  25. { open: '(', close: ')' },
  26. { open: '{', close: '}' }
  27. ]
  28. };
  29. export const language = <ILanguage>{
  30. defaultToken: '',
  31. ignoreCase: true,
  32. tokenPostfix: '.clj',
  33. brackets: [
  34. { open: '[', close: ']', token: 'delimiter.square' },
  35. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  36. { open: '{', close: '}', token: 'delimiter.curly' }
  37. ],
  38. constants: ['true', 'false', 'nil'],
  39. // delimiters: /[\\\[\]\s"#'(),;@^`{}~]|$/,
  40. numbers: /^(?:[+\-]?\d+(?:(?:N|(?:[eE][+\-]?\d+))|(?:\.?\d*(?:M|(?:[eE][+\-]?\d+))?)|\/\d+|[xX][0-9a-fA-F]+|r[0-9a-zA-Z]+)?(?=[\\\[\]\s"#'(),;@^`{}~]|$))/,
  41. characters: /^(?:\\(?:backspace|formfeed|newline|return|space|tab|o[0-7]{3}|u[0-9A-Fa-f]{4}|x[0-9A-Fa-f]{4}|.)?(?=[\\\[\]\s"(),;@^`{}~]|$))/,
  42. escapes: /^\\(?:["'\\bfnrt]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  43. // simple-namespace := /^[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*/
  44. // simple-symbol := /^(?:\/|[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*)/
  45. // qualified-symbol := (<simple-namespace>(<.><simple-namespace>)*</>)?<simple-symbol>
  46. qualifiedSymbols: /^(?:(?:[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*(?:\.[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*)*\/)?(?:\/|[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*)*(?=[\\\[\]\s"(),;@^`{}~]|$))/,
  47. specialForms: [
  48. '.',
  49. 'catch',
  50. 'def',
  51. 'do',
  52. 'if',
  53. 'monitor-enter',
  54. 'monitor-exit',
  55. 'new',
  56. 'quote',
  57. 'recur',
  58. 'set!',
  59. 'throw',
  60. 'try',
  61. 'var'
  62. ],
  63. coreSymbols: [
  64. '*',
  65. "*'",
  66. '*1',
  67. '*2',
  68. '*3',
  69. '*agent*',
  70. '*allow-unresolved-vars*',
  71. '*assert*',
  72. '*clojure-version*',
  73. '*command-line-args*',
  74. '*compile-files*',
  75. '*compile-path*',
  76. '*compiler-options*',
  77. '*data-readers*',
  78. '*default-data-reader-fn*',
  79. '*e',
  80. '*err*',
  81. '*file*',
  82. '*flush-on-newline*',
  83. '*fn-loader*',
  84. '*in*',
  85. '*math-context*',
  86. '*ns*',
  87. '*out*',
  88. '*print-dup*',
  89. '*print-length*',
  90. '*print-level*',
  91. '*print-meta*',
  92. '*print-namespace-maps*',
  93. '*print-readably*',
  94. '*read-eval*',
  95. '*reader-resolver*',
  96. '*source-path*',
  97. '*suppress-read*',
  98. '*unchecked-math*',
  99. '*use-context-classloader*',
  100. '*verbose-defrecords*',
  101. '*warn-on-reflection*',
  102. '+',
  103. "+'",
  104. '-',
  105. "-'",
  106. '->',
  107. '->>',
  108. '->ArrayChunk',
  109. '->Eduction',
  110. '->Vec',
  111. '->VecNode',
  112. '->VecSeq',
  113. '-cache-protocol-fn',
  114. '-reset-methods',
  115. '..',
  116. '/',
  117. '<',
  118. '<=',
  119. '=',
  120. '==',
  121. '>',
  122. '>=',
  123. 'EMPTY-NODE',
  124. 'Inst',
  125. 'StackTraceElement->vec',
  126. 'Throwable->map',
  127. 'accessor',
  128. 'aclone',
  129. 'add-classpath',
  130. 'add-watch',
  131. 'agent',
  132. 'agent-error',
  133. 'agent-errors',
  134. 'aget',
  135. 'alength',
  136. 'alias',
  137. 'all-ns',
  138. 'alter',
  139. 'alter-meta!',
  140. 'alter-var-root',
  141. 'amap',
  142. 'ancestors',
  143. 'and',
  144. 'any?',
  145. 'apply',
  146. 'areduce',
  147. 'array-map',
  148. 'as->',
  149. 'aset',
  150. 'aset-boolean',
  151. 'aset-byte',
  152. 'aset-char',
  153. 'aset-double',
  154. 'aset-float',
  155. 'aset-int',
  156. 'aset-long',
  157. 'aset-short',
  158. 'assert',
  159. 'assoc',
  160. 'assoc!',
  161. 'assoc-in',
  162. 'associative?',
  163. 'atom',
  164. 'await',
  165. 'await-for',
  166. 'await1',
  167. 'bases',
  168. 'bean',
  169. 'bigdec',
  170. 'bigint',
  171. 'biginteger',
  172. 'binding',
  173. 'bit-and',
  174. 'bit-and-not',
  175. 'bit-clear',
  176. 'bit-flip',
  177. 'bit-not',
  178. 'bit-or',
  179. 'bit-set',
  180. 'bit-shift-left',
  181. 'bit-shift-right',
  182. 'bit-test',
  183. 'bit-xor',
  184. 'boolean',
  185. 'boolean-array',
  186. 'boolean?',
  187. 'booleans',
  188. 'bound-fn',
  189. 'bound-fn*',
  190. 'bound?',
  191. 'bounded-count',
  192. 'butlast',
  193. 'byte',
  194. 'byte-array',
  195. 'bytes',
  196. 'bytes?',
  197. 'case',
  198. 'cast',
  199. 'cat',
  200. 'char',
  201. 'char-array',
  202. 'char-escape-string',
  203. 'char-name-string',
  204. 'char?',
  205. 'chars',
  206. 'chunk',
  207. 'chunk-append',
  208. 'chunk-buffer',
  209. 'chunk-cons',
  210. 'chunk-first',
  211. 'chunk-next',
  212. 'chunk-rest',
  213. 'chunked-seq?',
  214. 'class',
  215. 'class?',
  216. 'clear-agent-errors',
  217. 'clojure-version',
  218. 'coll?',
  219. 'comment',
  220. 'commute',
  221. 'comp',
  222. 'comparator',
  223. 'compare',
  224. 'compare-and-set!',
  225. 'compile',
  226. 'complement',
  227. 'completing',
  228. 'concat',
  229. 'cond',
  230. 'cond->',
  231. 'cond->>',
  232. 'condp',
  233. 'conj',
  234. 'conj!',
  235. 'cons',
  236. 'constantly',
  237. 'construct-proxy',
  238. 'contains?',
  239. 'count',
  240. 'counted?',
  241. 'create-ns',
  242. 'create-struct',
  243. 'cycle',
  244. 'dec',
  245. "dec'",
  246. 'decimal?',
  247. 'declare',
  248. 'dedupe',
  249. 'default-data-readers',
  250. 'definline',
  251. 'definterface',
  252. 'defmacro',
  253. 'defmethod',
  254. 'defmulti',
  255. 'defn',
  256. 'defn-',
  257. 'defonce',
  258. 'defprotocol',
  259. 'defrecord',
  260. 'defstruct',
  261. 'deftype',
  262. 'delay',
  263. 'delay?',
  264. 'deliver',
  265. 'denominator',
  266. 'deref',
  267. 'derive',
  268. 'descendants',
  269. 'destructure',
  270. 'disj',
  271. 'disj!',
  272. 'dissoc',
  273. 'dissoc!',
  274. 'distinct',
  275. 'distinct?',
  276. 'doall',
  277. 'dorun',
  278. 'doseq',
  279. 'dosync',
  280. 'dotimes',
  281. 'doto',
  282. 'double',
  283. 'double-array',
  284. 'double?',
  285. 'doubles',
  286. 'drop',
  287. 'drop-last',
  288. 'drop-while',
  289. 'eduction',
  290. 'empty',
  291. 'empty?',
  292. 'ensure',
  293. 'ensure-reduced',
  294. 'enumeration-seq',
  295. 'error-handler',
  296. 'error-mode',
  297. 'eval',
  298. 'even?',
  299. 'every-pred',
  300. 'every?',
  301. 'ex-data',
  302. 'ex-info',
  303. 'extend',
  304. 'extend-protocol',
  305. 'extend-type',
  306. 'extenders',
  307. 'extends?',
  308. 'false?',
  309. 'ffirst',
  310. 'file-seq',
  311. 'filter',
  312. 'filterv',
  313. 'find',
  314. 'find-keyword',
  315. 'find-ns',
  316. 'find-protocol-impl',
  317. 'find-protocol-method',
  318. 'find-var',
  319. 'first',
  320. 'flatten',
  321. 'float',
  322. 'float-array',
  323. 'float?',
  324. 'floats',
  325. 'flush',
  326. 'fn',
  327. 'fn?',
  328. 'fnext',
  329. 'fnil',
  330. 'for',
  331. 'force',
  332. 'format',
  333. 'frequencies',
  334. 'future',
  335. 'future-call',
  336. 'future-cancel',
  337. 'future-cancelled?',
  338. 'future-done?',
  339. 'future?',
  340. 'gen-class',
  341. 'gen-interface',
  342. 'gensym',
  343. 'get',
  344. 'get-in',
  345. 'get-method',
  346. 'get-proxy-class',
  347. 'get-thread-bindings',
  348. 'get-validator',
  349. 'group-by',
  350. 'halt-when',
  351. 'hash',
  352. 'hash-combine',
  353. 'hash-map',
  354. 'hash-ordered-coll',
  355. 'hash-set',
  356. 'hash-unordered-coll',
  357. 'ident?',
  358. 'identical?',
  359. 'identity',
  360. 'if-let',
  361. 'if-not',
  362. 'if-some',
  363. 'ifn?',
  364. 'import',
  365. 'in-ns',
  366. 'inc',
  367. "inc'",
  368. 'indexed?',
  369. 'init-proxy',
  370. 'inst-ms',
  371. 'inst-ms*',
  372. 'inst?',
  373. 'instance?',
  374. 'int',
  375. 'int-array',
  376. 'int?',
  377. 'integer?',
  378. 'interleave',
  379. 'intern',
  380. 'interpose',
  381. 'into',
  382. 'into-array',
  383. 'ints',
  384. 'io!',
  385. 'isa?',
  386. 'iterate',
  387. 'iterator-seq',
  388. 'juxt',
  389. 'keep',
  390. 'keep-indexed',
  391. 'key',
  392. 'keys',
  393. 'keyword',
  394. 'keyword?',
  395. 'last',
  396. 'lazy-cat',
  397. 'lazy-seq',
  398. 'let',
  399. 'letfn',
  400. 'line-seq',
  401. 'list',
  402. 'list*',
  403. 'list?',
  404. 'load',
  405. 'load-file',
  406. 'load-reader',
  407. 'load-string',
  408. 'loaded-libs',
  409. 'locking',
  410. 'long',
  411. 'long-array',
  412. 'longs',
  413. 'loop',
  414. 'macroexpand',
  415. 'macroexpand-1',
  416. 'make-array',
  417. 'make-hierarchy',
  418. 'map',
  419. 'map-entry?',
  420. 'map-indexed',
  421. 'map?',
  422. 'mapcat',
  423. 'mapv',
  424. 'max',
  425. 'max-key',
  426. 'memfn',
  427. 'memoize',
  428. 'merge',
  429. 'merge-with',
  430. 'meta',
  431. 'method-sig',
  432. 'methods',
  433. 'min',
  434. 'min-key',
  435. 'mix-collection-hash',
  436. 'mod',
  437. 'munge',
  438. 'name',
  439. 'namespace',
  440. 'namespace-munge',
  441. 'nat-int?',
  442. 'neg-int?',
  443. 'neg?',
  444. 'newline',
  445. 'next',
  446. 'nfirst',
  447. 'nil?',
  448. 'nnext',
  449. 'not',
  450. 'not-any?',
  451. 'not-empty',
  452. 'not-every?',
  453. 'not=',
  454. 'ns',
  455. 'ns-aliases',
  456. 'ns-imports',
  457. 'ns-interns',
  458. 'ns-map',
  459. 'ns-name',
  460. 'ns-publics',
  461. 'ns-refers',
  462. 'ns-resolve',
  463. 'ns-unalias',
  464. 'ns-unmap',
  465. 'nth',
  466. 'nthnext',
  467. 'nthrest',
  468. 'num',
  469. 'number?',
  470. 'numerator',
  471. 'object-array',
  472. 'odd?',
  473. 'or',
  474. 'parents',
  475. 'partial',
  476. 'partition',
  477. 'partition-all',
  478. 'partition-by',
  479. 'pcalls',
  480. 'peek',
  481. 'persistent!',
  482. 'pmap',
  483. 'pop',
  484. 'pop!',
  485. 'pop-thread-bindings',
  486. 'pos-int?',
  487. 'pos?',
  488. 'pr',
  489. 'pr-str',
  490. 'prefer-method',
  491. 'prefers',
  492. 'primitives-classnames',
  493. 'print',
  494. 'print-ctor',
  495. 'print-dup',
  496. 'print-method',
  497. 'print-simple',
  498. 'print-str',
  499. 'printf',
  500. 'println',
  501. 'println-str',
  502. 'prn',
  503. 'prn-str',
  504. 'promise',
  505. 'proxy',
  506. 'proxy-call-with-super',
  507. 'proxy-mappings',
  508. 'proxy-name',
  509. 'proxy-super',
  510. 'push-thread-bindings',
  511. 'pvalues',
  512. 'qualified-ident?',
  513. 'qualified-keyword?',
  514. 'qualified-symbol?',
  515. 'quot',
  516. 'rand',
  517. 'rand-int',
  518. 'rand-nth',
  519. 'random-sample',
  520. 'range',
  521. 'ratio?',
  522. 'rational?',
  523. 'rationalize',
  524. 're-find',
  525. 're-groups',
  526. 're-matcher',
  527. 're-matches',
  528. 're-pattern',
  529. 're-seq',
  530. 'read',
  531. 'read-line',
  532. 'read-string',
  533. 'reader-conditional',
  534. 'reader-conditional?',
  535. 'realized?',
  536. 'record?',
  537. 'reduce',
  538. 'reduce-kv',
  539. 'reduced',
  540. 'reduced?',
  541. 'reductions',
  542. 'ref',
  543. 'ref-history-count',
  544. 'ref-max-history',
  545. 'ref-min-history',
  546. 'ref-set',
  547. 'refer',
  548. 'refer-clojure',
  549. 'reify',
  550. 'release-pending-sends',
  551. 'rem',
  552. 'remove',
  553. 'remove-all-methods',
  554. 'remove-method',
  555. 'remove-ns',
  556. 'remove-watch',
  557. 'repeat',
  558. 'repeatedly',
  559. 'replace',
  560. 'replicate',
  561. 'require',
  562. 'reset!',
  563. 'reset-meta!',
  564. 'reset-vals!',
  565. 'resolve',
  566. 'rest',
  567. 'restart-agent',
  568. 'resultset-seq',
  569. 'reverse',
  570. 'reversible?',
  571. 'rseq',
  572. 'rsubseq',
  573. 'run!',
  574. 'satisfies?',
  575. 'second',
  576. 'select-keys',
  577. 'send',
  578. 'send-off',
  579. 'send-via',
  580. 'seq',
  581. 'seq?',
  582. 'seqable?',
  583. 'seque',
  584. 'sequence',
  585. 'sequential?',
  586. 'set',
  587. 'set-agent-send-executor!',
  588. 'set-agent-send-off-executor!',
  589. 'set-error-handler!',
  590. 'set-error-mode!',
  591. 'set-validator!',
  592. 'set?',
  593. 'short',
  594. 'short-array',
  595. 'shorts',
  596. 'shuffle',
  597. 'shutdown-agents',
  598. 'simple-ident?',
  599. 'simple-keyword?',
  600. 'simple-symbol?',
  601. 'slurp',
  602. 'some',
  603. 'some->',
  604. 'some->>',
  605. 'some-fn',
  606. 'some?',
  607. 'sort',
  608. 'sort-by',
  609. 'sorted-map',
  610. 'sorted-map-by',
  611. 'sorted-set',
  612. 'sorted-set-by',
  613. 'sorted?',
  614. 'special-symbol?',
  615. 'spit',
  616. 'split-at',
  617. 'split-with',
  618. 'str',
  619. 'string?',
  620. 'struct',
  621. 'struct-map',
  622. 'subs',
  623. 'subseq',
  624. 'subvec',
  625. 'supers',
  626. 'swap!',
  627. 'swap-vals!',
  628. 'symbol',
  629. 'symbol?',
  630. 'sync',
  631. 'tagged-literal',
  632. 'tagged-literal?',
  633. 'take',
  634. 'take-last',
  635. 'take-nth',
  636. 'take-while',
  637. 'test',
  638. 'the-ns',
  639. 'thread-bound?',
  640. 'time',
  641. 'to-array',
  642. 'to-array-2d',
  643. 'trampoline',
  644. 'transduce',
  645. 'transient',
  646. 'tree-seq',
  647. 'true?',
  648. 'type',
  649. 'unchecked-add',
  650. 'unchecked-add-int',
  651. 'unchecked-byte',
  652. 'unchecked-char',
  653. 'unchecked-dec',
  654. 'unchecked-dec-int',
  655. 'unchecked-divide-int',
  656. 'unchecked-double',
  657. 'unchecked-float',
  658. 'unchecked-inc',
  659. 'unchecked-inc-int',
  660. 'unchecked-int',
  661. 'unchecked-long',
  662. 'unchecked-multiply',
  663. 'unchecked-multiply-int',
  664. 'unchecked-negate',
  665. 'unchecked-negate-int',
  666. 'unchecked-remainder-int',
  667. 'unchecked-short',
  668. 'unchecked-subtract',
  669. 'unchecked-subtract-int',
  670. 'underive',
  671. 'unquote',
  672. 'unquote-splicing',
  673. 'unreduced',
  674. 'unsigned-bit-shift-right',
  675. 'update',
  676. 'update-in',
  677. 'update-proxy',
  678. 'uri?',
  679. 'use',
  680. 'uuid?',
  681. 'val',
  682. 'vals',
  683. 'var-get',
  684. 'var-set',
  685. 'var?',
  686. 'vary-meta',
  687. 'vec',
  688. 'vector',
  689. 'vector-of',
  690. 'vector?',
  691. 'volatile!',
  692. 'volatile?',
  693. 'vreset!',
  694. 'vswap!',
  695. 'when',
  696. 'when-first',
  697. 'when-let',
  698. 'when-not',
  699. 'when-some',
  700. 'while',
  701. 'with-bindings',
  702. 'with-bindings*',
  703. 'with-in-str',
  704. 'with-loading-context',
  705. 'with-local-vars',
  706. 'with-meta',
  707. 'with-open',
  708. 'with-out-str',
  709. 'with-precision',
  710. 'with-redefs',
  711. 'with-redefs-fn',
  712. 'xml-seq',
  713. 'zero?',
  714. 'zipmap'
  715. ],
  716. tokenizer: {
  717. root: [
  718. // whitespaces and comments
  719. { include: '@whitespace' },
  720. // numbers
  721. [/@numbers/, 'number'],
  722. // characters
  723. [/@characters/, 'string'],
  724. // strings
  725. { include: '@string' },
  726. // brackets
  727. [/[()\[\]{}]/, '@brackets'],
  728. // regular expressions
  729. [/\/#"(?:\.|(?:")|[^"\n])*"\/g/, 'regexp'],
  730. // reader macro characters
  731. [/[#'@^`~]/, 'meta'],
  732. // symbols
  733. [
  734. /@qualifiedSymbols/,
  735. {
  736. cases: {
  737. '^:.+$': 'constant', // Clojure keywords (e.g., `:foo/bar`)
  738. '@specialForms': 'keyword',
  739. '@coreSymbols': 'keyword',
  740. '@constants': 'constant',
  741. '@default': 'identifier'
  742. }
  743. }
  744. ]
  745. ],
  746. whitespace: [
  747. [/[\s,]+/, 'white'],
  748. [/;.*$/, 'comment'],
  749. [/\(comment\b/, 'comment', '@comment']
  750. ],
  751. comment: [
  752. [/\(/, 'comment', '@push'],
  753. [/\)/, 'comment', '@pop'],
  754. [/[^()]/, 'comment']
  755. ],
  756. string: [[/"/, 'string', '@multiLineString']],
  757. multiLineString: [
  758. [/"/, 'string', '@popall'],
  759. [/@escapes/, 'string.escape'],
  760. [/./, 'string']
  761. ]
  762. }
  763. };