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