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