lang-clj.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (C) 2011 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @fileoverview
  18. * Registers a language handler for Clojure.
  19. *
  20. *
  21. * To use, include prettify.js and this file in your HTML page.
  22. * Then put your code in an HTML tag like
  23. * <pre class="prettyprint lang-lisp">(my lisp code)</pre>
  24. * The lang-cl class identifies the language as common lisp.
  25. * This file supports the following language extensions:
  26. * lang-clj - Clojure
  27. *
  28. *
  29. * I used lang-lisp.js as the basis for this adding the clojure specific
  30. * keywords and syntax.
  31. *
  32. * "Name" = 'Clojure'
  33. * "Author" = 'Rich Hickey'
  34. * "Version" = '1.2'
  35. * "About" = 'Clojure is a lisp for the jvm with concurrency primitives and a richer set of types.'
  36. *
  37. *
  38. * I used <a href="http://clojure.org/Reference">Clojure.org Reference</a> as
  39. * the basis for the reserved word list.
  40. *
  41. *
  42. * @author jwall@google.com
  43. */
  44. PR['registerLangHandler'](
  45. PR['createSimpleLexer'](
  46. [
  47. // clojure has more paren types than minimal lisp.
  48. ['opn', /^[\(\{\[]+/, null, '([{'],
  49. ['clo', /^[\)\}\]]+/, null, ')]}'],
  50. // A line comment that starts with ;
  51. [PR['PR_COMMENT'], /^;[^\r\n]*/, null, ';'],
  52. // Whitespace
  53. [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
  54. // A double quoted, possibly multi-line, string.
  55. [PR['PR_STRING'], /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"']
  56. ],
  57. [
  58. // clojure has a much larger set of keywords
  59. [PR['PR_KEYWORD'], /^(?:def|if|do|let|quote|var|fn|loop|recur|throw|try|monitor-enter|monitor-exit|defmacro|defn|defn-|macroexpand|macroexpand-1|for|doseq|dosync|dotimes|and|or|when|not|assert|doto|proxy|defstruct|first|rest|cons|defprotocol|deftype|defrecord|reify|defmulti|defmethod|meta|with-meta|ns|in-ns|create-ns|import|intern|refer|alias|namespace|resolve|ref|deref|refset|new|set!|memfn|to-array|into-array|aset|gen-class|reduce|map|filter|find|nil?|empty?|hash-map|hash-set|vec|vector|seq|flatten|reverse|assoc|dissoc|list|list?|disj|get|union|difference|intersection|extend|extend-type|extend-protocol|prn)\b/, null],
  60. [PR['PR_TYPE'], /^:[0-9a-zA-Z\-]+/]
  61. ]),
  62. ['clj']);