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 Lua.
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-lua">(my Lua code)</pre>
26 *
27 *
28 * I used http://www.lua.org/manual/5.1/manual.html#2.1
29 * Because of the long-bracket concept used in strings and comments, Lua does
30 * not have a regular lexical grammar, but luckily it fits within the space
31 * of irregular grammars supported by javascript regular expressions.
32 *
33 * @author mikesamuel@gmail.com
34 */
35
36PR['registerLangHandler'](
37    PR['createSimpleLexer'](
38        [
39         // Whitespace
40         [PR['PR_PLAIN'],       /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
41         // A double or single quoted, possibly multi-line, string.
42         [PR['PR_STRING'],      /^(?:\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)|\'(?:[^\'\\]|\\[\s\S])*(?:\'|$))/, null, '"\'']
43        ],
44        [
45         // A comment is either a line comment that starts with two dashes, or
46         // two dashes preceding a long bracketed block.
47         [PR['PR_COMMENT'], /^--(?:\[(=*)\[[\s\S]*?(?:\]\1\]|$)|[^\r\n]*)/],
48         // A long bracketed block not preceded by -- is a string.
49         [PR['PR_STRING'],  /^\[(=*)\[[\s\S]*?(?:\]\1\]|$)/],
50         [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],
51         // A number is a hex integer literal, a decimal real literal, or in
52         // scientific notation.
53         [PR['PR_LITERAL'],
54          /^[+-]?(?:0x[\da-f]+|(?:(?:\.\d+|\d+(?:\.\d*)?)(?:e[+\-]?\d+)?))/i],
55         // An identifier
56         [PR['PR_PLAIN'], /^[a-z_]\w*/i],
57         // A run of punctuation
58         [PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0][^\w\t\n\r \xA0\"\'\-\+=]*/]
59        ]),
60    ['lua']);
61