Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elixir) Support function names with a slash #2406

Merged
merged 3 commits into from Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -16,6 +16,7 @@ Core Changes:

Language Improvements:

- fix(elixir) Support function names with a slash (#2406) [Josh Goebel][]
- fix(javascript) comma is allowed in a "value container" (#2403) [Josh Goebel][]
- enh(apache) add `deny` and `allow` keywords [Josh Goebel][]
- enh(apache) highlight numeric attributes values [Josh Goebel][]
Expand Down
21 changes: 15 additions & 6 deletions src/languages/elixir.js
Expand Up @@ -19,7 +19,11 @@ export default function(hljs) {
lexemes: ELIXIR_IDENT_RE,
keywords: ELIXIR_KEYWORDS
};

var NUMBER = {
className: 'number',
begin: '(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(-?\\b[1-9][0-9_]*(.[0-9_]+([eE][-+]?[0-9]+)?)?)',
relevance: 0
};
var SIGIL_DELIMITERS = '[/|([{<"\']'
var LOWERCASE_SIGIL = {
className: 'string',
Expand Down Expand Up @@ -128,11 +132,7 @@ export default function(hljs) {
begin: ELIXIR_IDENT_RE + ':(?!:)',
relevance: 0
},
{
className: 'number',
begin: '(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(-?\\b[1-9][0-9_]*(.[0-9_]+([eE][-+]?[0-9]+)?)?)',
relevance: 0
},
NUMBER,
{
className: 'variable',
begin: '(\\$\\W)|((\\$|\\@\\@?)(\\w+))'
Expand All @@ -144,6 +144,15 @@ export default function(hljs) {
begin: '(' + hljs.RE_STARTERS_RE + ')\\s*',
contains: [
hljs.HASH_COMMENT_MODE,
{
// to prevent false regex triggers for the division function:
// /:
begin: /\/: (?=\d+\s*[,\]])/,
relevance: 0,
contains: [
NUMBER
]
},
{
className: 'regexp',
illegal: '\\n',
Expand Down
6 changes: 6 additions & 0 deletions test/markup/elixir/function-not-regex.expect.txt
@@ -0,0 +1,6 @@
<span class="hljs-keyword">import</span> Kernel, <span class="hljs-symbol">except:</span> [
<span class="hljs-symbol">spawn:</span> <span class="hljs-number">1</span>,
+: <span class="hljs-number">2</span>,
/: <span class="hljs-number">2</span>,
<span class="hljs-symbol">Unless:</span> <span class="hljs-number">2</span>
]
6 changes: 6 additions & 0 deletions test/markup/elixir/function-not-regex.txt
@@ -0,0 +1,6 @@
import Kernel, except: [
spawn: 1,
+: 2,
/: 2,
Unless: 2
]