lang-lisp.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (C) 2008 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview
  16. * Registers a language handler for Common Lisp and related languages.
  17. *
  18. *
  19. * To use, include prettify.js and this file in your HTML page.
  20. * Then put your code in an HTML tag like
  21. * <pre class="prettyprint lang-lisp">(my lisp code)</pre>
  22. * The lang-cl class identifies the language as common lisp.
  23. * This file supports the following language extensions:
  24. * lang-cl - Common Lisp
  25. * lang-el - Emacs Lisp
  26. * lang-lisp - Lisp
  27. * lang-scm - Scheme
  28. *
  29. *
  30. * I used http://www.devincook.com/goldparser/doc/meta-language/grammar-LISP.htm
  31. * as the basis, but added line comments that start with ; and changed the atom
  32. * production to disallow unquoted semicolons.
  33. *
  34. * "Name" = 'LISP'
  35. * "Author" = 'John McCarthy'
  36. * "Version" = 'Minimal'
  37. * "About" = 'LISP is an abstract language that organizes ALL'
  38. * | 'data around "lists".'
  39. *
  40. * "Start Symbol" = [s-Expression]
  41. *
  42. * {Atom Char} = {Printable} - {Whitespace} - [()"\'']
  43. *
  44. * Atom = ( {Atom Char} | '\'{Printable} )+
  45. *
  46. * [s-Expression] ::= [Quote] Atom
  47. * | [Quote] '(' [Series] ')'
  48. * | [Quote] '(' [s-Expression] '.' [s-Expression] ')'
  49. *
  50. * [Series] ::= [s-Expression] [Series]
  51. * |
  52. *
  53. * [Quote] ::= '' !Quote = do not evaluate
  54. * |
  55. *
  56. *
  57. * I used <a href="http://gigamonkeys.com/book/">Practical Common Lisp</a> as
  58. * the basis for the reserved word list.
  59. *
  60. *
  61. * @author mikesamuel@gmail.com
  62. */
  63. PR['registerLangHandler'](
  64. PR['createSimpleLexer'](
  65. [
  66. ['opn', /^\(+/, null, '('],
  67. ['clo', /^\)+/, null, ')'],
  68. // A line comment that starts with ;
  69. [PR['PR_COMMENT'], /^;[^\r\n]*/, null, ';'],
  70. // Whitespace
  71. [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
  72. // A double quoted, possibly multi-line, string.
  73. [PR['PR_STRING'], /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"']
  74. ],
  75. [
  76. [PR['PR_KEYWORD'], /^(?:block|c[ad]+r|catch|con[ds]|def(?:ine|un)|do|eq|eql|equal|equalp|eval-when|flet|format|go|if|labels|lambda|let|load-time-value|locally|macrolet|multiple-value-call|nil|progn|progv|quote|require|return-from|setq|symbol-macrolet|t|tagbody|the|throw|unwind)\b/, null],
  77. [PR['PR_LITERAL'],
  78. /^[+\-]?(?:[0#]x[0-9a-f]+|\d+\/\d+|(?:\.\d+|\d+(?:\.\d*)?)(?:[ed][+\-]?\d+)?)/i],
  79. // A single quote possibly followed by a word that optionally ends with
  80. // = ! or ?.
  81. [PR['PR_LITERAL'],
  82. /^\'(?:-*(?:\w|\\[\x21-\x7e])(?:[\w-]*|\\[\x21-\x7e])[=!?]?)?/],
  83. // A word that optionally ends with = ! or ?.
  84. [PR['PR_PLAIN'],
  85. /^-*(?:[a-z_]|\\[\x21-\x7e])(?:[\w-]*|\\[\x21-\x7e])[=!?]?/i],
  86. // A printable non-space non-special character
  87. [PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0()\"\\\';]+/]
  88. ]),
  89. ['cl', 'el', 'lisp', 'scm']);