Skip to content

Commit

Permalink
Merge pull request #614 from Golmote/prism-elixir
Browse files Browse the repository at this point in the history
Add support for elixir
  • Loading branch information
Golmote committed Sep 5, 2015
2 parents 4eaf771 + ea49b66 commit a1c028c
Show file tree
Hide file tree
Showing 17 changed files with 922 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ var components = {
"title": "Eiffel",
"owner": "Conaclos"
},
"elixir": {
"title": "elixir",
"owner": "Golmote"
},
"erlang": {
"title": "Erlang",
"owner": "Golmote"
Expand Down
84 changes: 84 additions & 0 deletions components/prism-elixir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Prism.languages.elixir = {
// Negative look-ahead is needed for string interpolation
'comment': /#(?!\{).*/,
// ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
'regex': /~[rR](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|[^}])+\}|<(?:\\>|[^>])+>)[uismxfr]*/,
'string': [
{
// ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,
inside: {
// See interpolation below
}
},
{
pattern: /("""|''')[\s\S]*?\1/,
inside: {
// See interpolation below
}
},
{
// Multi-line strings are allowed
pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
inside: {
// See interpolation below
}
}
],
'atom': {
// Look-behind prevents bad highlighting of the :: operator
pattern: /(^|[^:]):\w+/,
lookbehind: true,
alias: 'symbol'
},
// Look-ahead prevents bad highlighting of the :: operator
'attr-name': /\w+:(?!:)/,
'capture': {
// Look-behind prevents bad highlighting of the && operator
pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
lookbehind: true,
alias: 'function'
},
'argument': {
// Look-behind prevents bad highlighting of the && operator
pattern: /(^|[^&])&\d+/,
lookbehind: true,
alias: 'variable'
},
'attribute': {
pattern: /@[\S]+/,
alias: 'variable'
},
'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
'boolean': /\b(?:true|false|nil)\b/,
'operator': [
/\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
{
// We don't want to match <<
pattern: /([^<])<(?!<)/,
lookbehind: true
},
{
// We don't want to match >>
pattern: /([^>])>(?!>)/,
lookbehind: true
}
],
'punctuation': /<<|>>|[.,%\[\]{}()]/
};

Prism.languages.elixir.string.forEach(function(o) {
o.inside = {
'interpolation': {
pattern: /#\{[^}]+\}/,
inside: {
'delimiter': {
pattern: /^#\{|\}$/,
alias: 'punctuation'
},
rest: Prism.util.clone(Prism.languages.elixir)
}
}
};
});
1 change: 1 addition & 0 deletions components/prism-elixir.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a1c028c

Please sign in to comment.