| OLD | NEW |
| (Empty) |
| 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 | |
| 16 | |
| 17 /** | |
| 18 * @fileoverview | |
| 19 * Registers a language handler for Lua. | |
| 20 * | |
| 21 * | |
| 22 * To use, include prettify.js and this file in your HTML page. | |
| 23 * Then put your code in an HTML tag like | |
| 24 * <pre class="prettyprint lang-lua">(my Lua code)</pre> | |
| 25 * | |
| 26 * | |
| 27 * I used http://www.lua.org/manual/5.1/manual.html#2.1 | |
| 28 * Because of the long-bracket concept used in strings and comments, Lua does | |
| 29 * not have a regular lexical grammar, but luckily it fits within the space | |
| 30 * of irregular grammars supported by javascript regular expressions. | |
| 31 * | |
| 32 * @author mikesamuel@gmail.com | |
| 33 */ | |
| 34 | |
| 35 PR['registerLangHandler']( | |
| 36 PR['createSimpleLexer']( | |
| 37 [ | |
| 38 // Whitespace | |
| 39 [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'], | |
| 40 // A double or single quoted, possibly multi-line, string. | |
| 41 [PR['PR_STRING'], /^(?:\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)|\'(?:[^\'\\
]|\\[\s\S])*(?:\'|$))/, null, '"\''] | |
| 42 ], | |
| 43 [ | |
| 44 // A comment is either a line comment that starts with two dashes, or | |
| 45 // two dashes preceding a long bracketed block. | |
| 46 [PR['PR_COMMENT'], /^--(?:\[(=*)\[[\s\S]*?(?:\]\1\]|$)|[^\r\n]*)/], | |
| 47 // A long bracketed block not preceded by -- is a string. | |
| 48 [PR['PR_STRING'], /^\[(=*)\[[\s\S]*?(?:\]\1\]|$)/], | |
| 49 [PR['PR_KEYWORD'], /^(?:and|break|do|else|elseif|end|false|for|function
|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/, null], | |
| 50 // A number is a hex integer literal, a decimal real literal, or in | |
| 51 // scientific notation. | |
| 52 [PR['PR_LITERAL'], | |
| 53 /^[+-]?(?:0x[\da-f]+|(?:(?:\.\d+|\d+(?:\.\d*)?)(?:e[+\-]?\d+)?))/i], | |
| 54 // An identifier | |
| 55 [PR['PR_PLAIN'], /^[a-z_]\w*/i], | |
| 56 // A run of punctuation | |
| 57 [PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0][^\w\t\n\r \xA0\"\'\-\+=]*/] | |
| 58 ]), | |
| 59 ['lua']); | |
| OLD | NEW |