1/**
2 * @license
3 * Copyright (C) 2013 Andrew Allen
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 Erlang.
21 *
22 * Derived from https://raw.github.com/erlang/otp/dev/lib/compiler/src/core_parse.yrl
23 * Modified from Mike Samuel's Haskell plugin for google-code-prettify
24 *
25 * @author achew22@gmail.com
26 */
27
28PR['registerLangHandler'](
29    PR['createSimpleLexer'](
30        [
31         // Whitespace
32         // whitechar    ->    newline | vertab | space | tab | uniWhite
33         // newline      ->    return linefeed | return | linefeed | formfeed
34         [PR['PR_PLAIN'],       /^[\t\n\x0B\x0C\r ]+/, null, '\t\n\x0B\x0C\r '],
35         // Single line double-quoted strings.
36         [PR['PR_STRING'],      /^\"(?:[^\"\\\n\x0C\r]|\\[\s\S])*(?:\"|$)/,
37          null, '"'],
38
39         // Handle atoms
40         [PR['PR_LITERAL'],      /^[a-z][a-zA-Z0-9_]*/],
41         // Handle single quoted atoms
42         [PR['PR_LITERAL'],      /^\'(?:[^\'\\\n\x0C\r]|\\[^&])+\'?/,
43          null, "'"],
44
45         // Handle macros. Just to be extra clear on this one, it detects the ?
46         // then uses the regexp to end it so be very careful about matching
47         // all the terminal elements
48         [PR['PR_LITERAL'],      /^\?[^ \t\n({]+/, null, "?"],
49
50
51
52         // decimal      ->    digit{digit}
53         // octal        ->    octit{octit}
54         // hexadecimal  ->    hexit{hexit}
55         // integer      ->    decimal
56         //               |    0o octal | 0O octal
57         //               |    0x hexadecimal | 0X hexadecimal
58         // float        ->    decimal . decimal [exponent]
59         //               |    decimal exponent
60         // exponent     ->    (e | E) [+ | -] decimal
61         [PR['PR_LITERAL'],
62          /^(?:0o[0-7]+|0x[\da-f]+|\d+(?:\.\d+)?(?:e[+\-]?\d+)?)/i,
63          null, '0123456789']
64        ],
65        [
66         // TODO: catch @declarations inside comments
67
68         // Comments in erlang are started with % and go till a newline
69         [PR['PR_COMMENT'], /^%[^\n]*/],
70
71         // Catch macros
72         //[PR['PR_TAG'], /?[^( \n)]+/],
73
74         /**
75          * %% Keywords (atoms are assumed to always be single-quoted).
76          * 'module' 'attributes' 'do' 'let' 'in' 'letrec'
77          * 'apply' 'call' 'primop'
78          * 'case' 'of' 'end' 'when' 'fun' 'try' 'catch' 'receive' 'after'
79          */
80         [PR['PR_KEYWORD'], /^(?:module|attributes|do|let|in|letrec|apply|call|primop|case|of|end|when|fun|try|catch|receive|after|char|integer|float,atom,string,var)\b/],
81
82         /**
83          * Catch definitions (usually defined at the top of the file)
84          * Anything that starts -something
85          */
86         [PR['PR_KEYWORD'], /^-[a-z_]+/],
87
88         // Catch variables
89         [PR['PR_TYPE'], /^[A-Z_][a-zA-Z0-9_]*/],
90
91         // matches the symbol production
92         [PR['PR_PUNCTUATION'], /^[.,;]/]
93        ]),
94    ['erlang', 'erl']);
95