clojure.js 20 KB

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