clojure.js 17 KB

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