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

Elixir: Add defdelagate keyword and for function/module name #2709

Merged
merged 3 commits into from Jan 10, 2021
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
14 changes: 13 additions & 1 deletion components/prism-elixir.js
Expand Up @@ -55,7 +55,7 @@ Prism.languages.elixir = {
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/,
'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct|delegate)?|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!|=(?:==?|[>~])?|[*\/^]/,
Expand All @@ -73,6 +73,18 @@ Prism.languages.elixir = {
'punctuation': /<<|>>|[.,%\[\]{}()]/
};

Prism.languages.insertBefore('elixir', 'keyword', {
'module': {
pattern: /\b(defmodule\s)[A-Z][\w.\\]+/,
lookbehind: true,
alias: 'class-name'
},
'function': {
pattern: /\b(defp?\s)[\w.\\]+/,
lookbehind: true
}
});

Prism.languages.elixir.string.forEach(function(o) {
o.inside = {
'interpolation': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-elixir.min.js

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

10 changes: 7 additions & 3 deletions tests/languages/elixir/keyword_feature.test
Expand Up @@ -3,7 +3,9 @@ catch cond def
defcallback
defexception
defimpl defmodule
defp defprotocol
defp
defprotocol
defdelegate
defstruct do else
end fn for if
import not or
Expand All @@ -18,7 +20,9 @@ unless use when
["keyword", "defcallback"],
["keyword", "defexception"],
["keyword", "defimpl"], ["keyword", "defmodule"],
["keyword", "defp"], ["keyword", "defprotocol"],
["keyword", "defp"],
["keyword", "defprotocol"],
["keyword", "defdelegate"],
["keyword", "defstruct"], ["keyword", "do"], ["keyword", "else"],
["keyword", "end"], ["keyword", "fn"], ["keyword", "for"], ["keyword", "if"],
["keyword", "import"], ["keyword", "not"], ["keyword", "or"],
Expand All @@ -28,4 +32,4 @@ unless use when

----------------------------------------------------

Checks for all keywords.
Checks for all keywords.
29 changes: 29 additions & 0 deletions tests/languages/elixir/module_feature.test
@@ -0,0 +1,29 @@
defmodule Math do
def sum(a, b) do
a + b
end
end

----------------------------------------------------

[
["keyword", "defmodule"], ["module", "Math"], ["keyword", "do"],

["keyword", "def"],
["function", "sum"],
["punctuation", "("],
"a",
["punctuation", ","],
" b",
["punctuation", ")"],
["keyword", "do"],

"\n a ", ["operator", "+"], " b\n ",

["keyword", "end"],
["keyword", "end"]
]

----------------------------------------------------

Checks for all keywords.