|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright (C) 2017 Jacek Królikowski |
| 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 Elixir. |
| 21 | + * |
| 22 | + |
| 23 | + */ |
| 24 | + |
| 25 | +PR['registerLangHandler']( |
| 26 | + PR['createSimpleLexer']( |
| 27 | + [ |
| 28 | + [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'], |
| 29 | + // # comments |
| 30 | + [PR['PR_COMMENT'], /^#.*/, null, '#'], |
| 31 | + // a (possibly multiline) charlist |
| 32 | + [PR['PR_LITERAL'], /^'(?:[^'\\]|\\(?:.|\n|\r))*'?/, null, '\''], |
| 33 | + // @attributes |
| 34 | + [PR['PR_ATTRIB_NAME'], /^@\w+/, null, '@'], |
| 35 | + [PR['PR_PUNCTUATION'], /^[!%&()*+,\-;<=>?\[\\\]^{|}]+/, null, |
| 36 | + '!%&()*+,-;<=>?[\\]^{|}'], |
| 37 | + // Borrowed from lang-erlang.js: |
| 38 | + [PR['PR_LITERAL'], |
| 39 | + /^(?:0o[0-7](?:[0-7]|_[0-7])*|0x[\da-fA-F](?:[\da-fA-F]|_[\da-fA-F])*|\d(?:\d|_\d)*(?:\.\d(?:\d|_\d)*)?(?:[eE][+\-]?\d(?:\d|_\d)*)?)/, |
| 40 | + null, '0123456789'] |
| 41 | + ], |
| 42 | + [ |
| 43 | + // the iex> prompt for interactive examples |
| 44 | + [PR['PR_ATTRIB_NAME'], /^iex(?:\(\d+\))?> /], |
| 45 | + // special case for binaries, so that they don't get presented like atoms |
| 46 | + [PR['PR_PUNCTUATION'], /^::/], |
| 47 | + // atoms - :__a_word or :"colon followed by a string" |
| 48 | + [PR['PR_LITERAL'], /^:(?:\w+[\!\?\@]?|"(?:[^"\\]|\\.)*"?)/], |
| 49 | + // compile-time information |
| 50 | + [PR['PR_ATTRIB_NAME'], /^(?:__(?:CALLER|ENV|MODULE|DIR)__)/], |
| 51 | + // keywords |
| 52 | + [PR['PR_KEYWORD'], |
| 53 | + /^(?:alias|case|catch|def(?:delegate|exception|impl|macrop?|module|overridable|p?|protocol|struct)|do|else|end|fn|for|if|in|import|quote|raise|require|rescue|super|throw|try|unless|unquote(?:_splicing)?|use|when|with|yield)\b/], |
| 54 | + [PR['PR_LITERAL'], /^(?:true|false|nil)\b/], |
| 55 | + // atoms as keyword list keys |
| 56 | + // NOTE: this does also handle the %{"I'm an atom": :foo} case |
| 57 | + // |
| 58 | + // Contains negative lookahead to handle <<foo::binary>> |
| 59 | + [PR['PR_LITERAL'], /^(?:\w+[\!\?\@]?|"(?:[^"\\]|\\.)*"):(?!:)/], |
| 60 | + // heredoc: triple double-quoted multi-line string. |
| 61 | + // |
| 62 | + // NOTE: the opening """ needs to be followed by a newline |
| 63 | + [PR['PR_STRING'], |
| 64 | + /^"""\s*(\r|\n)+(?:""?(?!")|[^\\"]|\\(?:.|\n|\r))*"{0,3}/], |
| 65 | + // A double-quoted multi-line string |
| 66 | + [PR['PR_STRING'], |
| 67 | + /^"(?:[^"\\]|\\(?:.|\n|\r))*"?(?!")/], |
| 68 | + // types |
| 69 | + [PR['PR_TYPE'], /^[A-Z]\w*/], |
| 70 | + // variables not meant to be used or private functions |
| 71 | + [PR['PR_COMMENT'], /^_\w*/], |
| 72 | + // plain: variables, functions, ... |
| 73 | + [PR['PR_PLAIN'], /^[$a-z]\w*[\!\?]?/], |
| 74 | + // sigils with the same starting and ending character. |
| 75 | + // Key part: X(?:[^X\r\n\\]|\\.)+X where X is the sigil character |
| 76 | + [PR['PR_ATTRIB_VALUE'], /^~[A-Z](?:\/(?:[^\/\r\n\\]|\\.)+\/|\|(?:[^\|\r\n\\]|\\.)+\||"(?:[^"\r\n\\]|\\.)+"|'(?:[^'\r\n\\]|\\.)+')[A-Z]*/i], |
| 77 | + // sigils with a different starting and ending character. |
| 78 | + // Key part: X(?:[^Y\r\n\\]|\\.)+Y where X and Y are the starting and ending characters |
| 79 | + [PR['PR_ATTRIB_VALUE'], /^~[A-Z](?:\((?:[^\)\r\n\\]|\\.)+\)|\[(?:[^\]\r\n\\]|\\.)+\]|\{(?:[^\}\r\n\\]|\\.)+\}|\<(?:[^\>\r\n\\]|\\.)+\>)[A-Z]*/i], |
| 80 | + [PR['PR_PUNCTUATION'], /^(?:\.+|\/|[:~])/] |
| 81 | + ]), |
| 82 | + ['ex','exs']); |
0 commit comments