clojure.ts 12 KB

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