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 OCaml, SML, F# and similar languages. | |
20 * | |
21 * Based on the lexical grammar at | |
22 * http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.
html#_Toc270597388 | |
23 * | |
24 * @author mikesamuel@gmail.com | |
25 */ | |
26 | |
27 PR['registerLangHandler']( | |
28 PR['createSimpleLexer']( | |
29 [ | |
30 // Whitespace is made up of spaces, tabs and newline characters. | |
31 [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'], | |
32 // #if ident/#else/#endif directives delimit conditional compilation | |
33 // sections | |
34 [PR['PR_COMMENT'], | |
35 /^#(?:if[\t\n\r \xA0]+(?:[a-z_$][\w\']*|``[^\r\n\t`]*(?:``|$))|else|en
dif|light)/i, | |
36 null, '#'], | |
37 // A double or single quoted, possibly multi-line, string. | |
38 // F# allows escaped newlines in strings. | |
39 [PR['PR_STRING'], /^(?:\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)|\'(?:[^\'\\
]|\\[\s\S])(?:\'|$))/, null, '"\''] | |
40 ], | |
41 [ | |
42 // Block comments are delimited by (* and *) and may be | |
43 // nested. Single-line comments begin with // and extend to | |
44 // the end of a line. | |
45 // TODO: (*...*) comments can be nested. This does not handle that. | |
46 [PR['PR_COMMENT'], /^(?:\/\/[^\r\n]*|\(\*[\s\S]*?\*\))/], | |
47 [PR['PR_KEYWORD'], /^(?:abstract|and|as|assert|begin|class|default|
delegate|do|done|downcast|downto|elif|else|end|exception|extern|false|finally|fo
r|fun|function|if|in|inherit|inline|interface|internal|lazy|let|match|member|mod
ule|mutable|namespace|new|null|of|open|or|override|private|public|rec|return|sta
tic|struct|then|to|true|try|type|upcast|use|val|void|when|while|with|yield|asr|l
and|lor|lsl|lsr|lxor|mod|sig|atomic|break|checked|component|const|constraint|con
structor|continue|eager|event|external|fixed|functor|global|include|method|mixin
|object|parallel|process|protected|pure|sealed|trait|virtual|volatile)\b/], | |
48 // A number is a hex integer literal, a decimal real literal, or in | |
49 // scientific notation. | |
50 [PR['PR_LITERAL'], | |
51 /^[+\-]?(?:0x[\da-f]+|(?:(?:\.\d+|\d+(?:\.\d*)?)(?:e[+\-]?\d+)?))/i], | |
52 [PR['PR_PLAIN'], /^(?:[a-z_][\w']*[!?#]?|``[^\r\n\t`]*(?:``|$))/i
], | |
53 // A printable non-space non-special character | |
54 [PR['PR_PUNCTUATION'], /^[^\t\n\r \xA0\"\'\w]+/] | |
55 ]), | |
56 ['fs', 'ml']); | |
OLD | NEW |