Skip to content

Commit

Permalink
Added import mode to Elixir
Browse files Browse the repository at this point in the history
Relates to p.3 from highlightjs#730
  • Loading branch information
Sannis committed Sep 8, 2015
1 parent ccabd51 commit 19d0e6c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
55 changes: 43 additions & 12 deletions src/languages/elixir.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,65 @@ function(hljs) {
className: 'class',
beginKeywords: 'defmodule defrecord', end: /\bdo\b|$|;/
});
var ELIXIR_DEFAULT_CONTAINS = [
STRING,
hljs.HASH_COMMENT_MODE,
CLASS,
FUNCTION,

var ELIXIR_NUMBER = {
className: 'number',
begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
relevance: 0
};

var ELIXIR_SYMBOL_MODES = [
{
className: 'symbol',
begin: ':',
contains: [STRING, {begin: ELIXIR_METHOD_RE}],
begin: ELIXIR_IDENT_RE + ':',
relevance: 0
},
{
className: 'symbol',
begin: ELIXIR_IDENT_RE + ':',
begin: ':' + ELIXIR_IDENT_RE,
relevance: 0
},
{
className: 'number',
begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
className: 'symbol',
begin: ':',
contains: [STRING, {begin: ELIXIR_METHOD_RE}],
relevance: 0
},
}
];

var ELIXIR_DEFAULT_CONTAINS = [
STRING,
hljs.HASH_COMMENT_MODE,
CLASS,
FUNCTION
].concat(ELIXIR_SYMBOL_MODES).concat([
ELIXIR_NUMBER,
{
className: 'variable',
begin: '(\\$\\W)|((\\$|\\@\\@?)(\\w+))'
},
{
begin: '->'
},
// import
{
beginKeywords: 'import', end: '$',
contains: ELIXIR_SYMBOL_MODES.concat([
{
begin: ELIXIR_IDENT_RE,
relevance: 0
},
// functions list
{
begin: '\\[', end: '\\]',
contains: [
ELIXIR_NUMBER
],
relevance: 0
}
]),
relevance: 0
},
{ // regexp container
begin: '(' + hljs.RE_STARTERS_RE + ')\\s*',
contains: [
Expand All @@ -92,7 +123,7 @@ function(hljs) {
],
relevance: 0
}
];
]);
SUBST.contains = ELIXIR_DEFAULT_CONTAINS;

return {
Expand Down
4 changes: 2 additions & 2 deletions src/languages/haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function(hljs) {
},
{
className: 'import',
begin: '\\bimport\\b', end: '$',
keywords: 'import|0 qualified as hiding',
beginKeywords: 'import', end: '$',
keywords: 'qualified as hiding',
contains: [LIST].concat(COMMENT_MODES),
illegal: '\\W\\.|;'
},
Expand Down
2 changes: 2 additions & 0 deletions test/detect/elixir/default.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Kernel, except: [spawn: 1, +: 2, /: 2, Unless: 2]

defrecord Person, first_name: nil, last_name: "Dudington" do
def name record do # huh ?
"#{record.first_name} #{record.last_name}"
Expand Down
1 change: 1 addition & 0 deletions test/markup/elixir/import-function-with-slash.except.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="hljs-keyword">import</span> Kernel, <span class="hljs-symbol">except:</span> [spawn: <span class="hljs-number">1</span>, +: <span class="hljs-number">2</span>, /: <span class="hljs-number">2</span>, Unless: <span class="hljs-number">2</span>]
1 change: 1 addition & 0 deletions test/markup/elixir/import-function-with-slash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Kernel, except: [spawn: 1, +: 2, /: 2, Unless: 2]

0 comments on commit 19d0e6c

Please sign in to comment.