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