diff --git a/CHANGES.md b/CHANGES.md
index f311454d0a..f4ce1428b1 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -5,10 +5,13 @@ Grammars:
- fix(python) identifiers starting with underscore not highlighted (#3221) [Antoine Lambert][]
- enh(clojure) added `edn` alias (#3213) [Stel Abrego][]
- enh(elixir) much improved regular expression sigil support (#3207) [Josh Goebel][]
+- enh(elixir) updated list of keywords (#3212) [Angelika Tyborska][]
+- fix(elixir) fixed number detection when numbers start with a zero (#3212) [Angelika Tyborska][]
[Stel Abrego]: https://github.com/stelcodes
[Josh Goebel]: https://github.com/joshgoebel
[Antoine Lambert]: https://github.com/anlambert
+[Angelika Tyborska]: https://github.com/angelikatyborska
## Version 11.0.0
diff --git a/src/languages/elixir.js b/src/languages/elixir.js
index 6c5dfa46c3..2e0acbc408 100644
--- a/src/languages/elixir.js
+++ b/src/languages/elixir.js
@@ -13,46 +13,45 @@ export default function(hljs) {
const ELIXIR_IDENT_RE = '[a-zA-Z_][a-zA-Z0-9_.]*(!|\\?)?';
const ELIXIR_METHOD_RE = '[a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?';
const KEYWORDS = [
- "alias",
+ "after",
"alias",
"and",
- "begin",
- "break",
"case",
+ "catch",
"cond",
- "defined",
+ "defstruct",
"do",
+ "else",
"end",
- "ensure",
- "false",
"fn",
"for",
+ "if",
"import",
"in",
- "include",
- "module",
- "next",
- "nil",
"not",
"or",
"quote",
- "redo",
+ "raise",
+ "receive",
"require",
- "retry",
- "return",
- "self",
- "then",
- "true",
+ "reraise",
+ "rescue",
+ "try",
"unless",
- "until",
+ "unquote",
+ "unquote_splicing",
"use",
- "when",
- "while",
"with|0"
];
+ const LITERALS = [
+ "false",
+ "nil",
+ "true"
+ ];
const KWS = {
$pattern: ELIXIR_IDENT_RE,
- keyword: KEYWORDS
+ keyword: KEYWORDS,
+ literal: LITERALS
};
const SUBST = {
className: 'subst',
@@ -62,7 +61,7 @@ export default function(hljs) {
};
const NUMBER = {
className: 'number',
- begin: '(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(-?\\b[1-9][0-9_]*(\\.[0-9_]+([eE][-+]?[0-9]+)?)?)',
+ begin: '(\\b0o[0-7_]+)|(\\b0b[01_]+)|(\\b0x[0-9a-fA-F_]+)|(-?\\b[0-9][0-9_]*(\\.[0-9_]+([eE][-+]?[0-9]+)?)?)',
relevance: 0
};
// TODO: could be tightened
@@ -218,7 +217,7 @@ export default function(hljs) {
};
const FUNCTION = {
className: 'function',
- beginKeywords: 'def defp defmacro',
+ beginKeywords: 'def defp defmacro defmacrop',
end: /\B\b/, // the mode is ended by the title
contains: [
hljs.inherit(hljs.TITLE_MODE, {
@@ -272,6 +271,7 @@ export default function(hljs) {
return {
name: 'Elixir',
+ aliases: ['ex', 'exs'],
keywords: KWS,
contains: ELIXIR_DEFAULT_CONTAINS
};
diff --git a/test/markup/elixir/conditionals.expect.txt b/test/markup/elixir/conditionals.expect.txt
new file mode 100644
index 0000000000..6745140583
--- /dev/null
+++ b/test/markup/elixir/conditionals.expect.txt
@@ -0,0 +1,40 @@
+case x do
+ 1 -> :one
+ 2 -> :two
+ _ -> :error
+end
+
+cond do
+ x > 30 -> :ok
+ y <= 7 -> :maybe
+ z == :skip -> :ok
+ true -> :error
+end
+
+if x > 4 do
+ :ok
+end
+
+if x > 4, do: :ok
+
+if x > 4 do
+ :ok
+else
+ :error
+end
+
+if x > 4, do: :ok, else: :error
+
+unless y < 50 do
+ :error
+end
+
+unless y < 50, do: :error
+
+unless y < 50 do
+ :error
+else
+ :ok
+end
+
+unless y < 50, do: :error, else: :ok
diff --git a/test/markup/elixir/conditionals.txt b/test/markup/elixir/conditionals.txt
new file mode 100644
index 0000000000..e9ad418959
--- /dev/null
+++ b/test/markup/elixir/conditionals.txt
@@ -0,0 +1,40 @@
+case x do
+ 1 -> :one
+ 2 -> :two
+ _ -> :error
+end
+
+cond do
+ x > 30 -> :ok
+ y <= 7 -> :maybe
+ z == :skip -> :ok
+ true -> :error
+end
+
+if x > 4 do
+ :ok
+end
+
+if x > 4, do: :ok
+
+if x > 4 do
+ :ok
+else
+ :error
+end
+
+if x > 4, do: :ok, else: :error
+
+unless y < 50 do
+ :error
+end
+
+unless y < 50, do: :error
+
+unless y < 50 do
+ :error
+else
+ :ok
+end
+
+unless y < 50, do: :error, else: :ok
diff --git a/test/markup/elixir/function-title.expect.txt b/test/markup/elixir/function-title.expect.txt
index 9e085be9e9..ab62908731 100644
--- a/test/markup/elixir/function-title.expect.txt
+++ b/test/markup/elixir/function-title.expect.txt
@@ -12,4 +12,10 @@
def f!, do: IO.puts "hello world"
+defp f?, do: true
+
+defmacro foo, do: :ok
+
+defmacrop do_foo, do: :ok
+
x = 5
diff --git a/test/markup/elixir/function-title.txt b/test/markup/elixir/function-title.txt
index 9f950a66f8..a736c0efa5 100644
--- a/test/markup/elixir/function-title.txt
+++ b/test/markup/elixir/function-title.txt
@@ -12,4 +12,10 @@ end
def f!, do: IO.puts "hello world"
+defp f?, do: true
+
+defmacro foo, do: :ok
+
+defmacrop do_foo, do: :ok
+
x = 5
diff --git a/test/markup/elixir/modules.expect.txt b/test/markup/elixir/modules.expect.txt
new file mode 100644
index 0000000000..0ad1227040
--- /dev/null
+++ b/test/markup/elixir/modules.expect.txt
@@ -0,0 +1,12 @@
+defmodule User do
+ defstruct [:name, :email, age: 18]
+end
+
+defprotocol Size do
+ @doc "Calculates the size (and not the length!) of a data structure"
+ def size(data)
+end
+
+defimpl Size, for: Map do
+ def size(map), do: map_size(map)
+end
diff --git a/test/markup/elixir/modules.txt b/test/markup/elixir/modules.txt
new file mode 100644
index 0000000000..46e5464b61
--- /dev/null
+++ b/test/markup/elixir/modules.txt
@@ -0,0 +1,12 @@
+defmodule User do
+ defstruct [:name, :email, age: 18]
+end
+
+defprotocol Size do
+ @doc "Calculates the size (and not the length!) of a data structure"
+ def size(data)
+end
+
+defimpl Size, for: Map do
+ def size(map), do: map_size(map)
+end
diff --git a/test/markup/elixir/numbers.expect.txt b/test/markup/elixir/numbers.expect.txt
index 5862061dfc..be6831552d 100644
--- a/test/markup/elixir/numbers.expect.txt
+++ b/test/markup/elixir/numbers.expect.txt
@@ -1,14 +1,21 @@
integer = 1234
+integer_with_leading_zero = 01234
+integer_zero = 0
big_integer = 1_234_000
neg_integer = -20_000
float = 2.34
+float_with_leading_zero = 0.34
+float_zero = 0.0
sci_float = 2.4e23
plus_sci_float = 2.4e+23
small_sci_float = 2.4e-23
cap_sci_float = 2.4E23
binary = 0b1010
+binary_with_leading_zero = 0b0010
strange_binary = 0b1010_1010_1010
octal = 0o777
+octal_with_leading_zero = 0o077
strange_octal = 0o777_666_555
hex = 0x1ABEF
+hex_with_leading_zero = 0x0ABEF
strange_hex = 0x1234_FACE_987D
diff --git a/test/markup/elixir/numbers.txt b/test/markup/elixir/numbers.txt
index 3e1c2a22a7..d9c2567dbf 100644
--- a/test/markup/elixir/numbers.txt
+++ b/test/markup/elixir/numbers.txt
@@ -1,14 +1,21 @@
integer = 1234
+integer_with_leading_zero = 01234
+integer_zero = 0
big_integer = 1_234_000
neg_integer = -20_000
float = 2.34
+float_with_leading_zero = 0.34
+float_zero = 0.0
sci_float = 2.4e23
plus_sci_float = 2.4e+23
small_sci_float = 2.4e-23
cap_sci_float = 2.4E23
binary = 0b1010
+binary_with_leading_zero = 0b0010
strange_binary = 0b1010_1010_1010
octal = 0o777
+octal_with_leading_zero = 0o077
strange_octal = 0o777_666_555
hex = 0x1ABEF
+hex_with_leading_zero = 0x0ABEF
strange_hex = 0x1234_FACE_987D
diff --git a/test/markup/elixir/strings.expect.txt b/test/markup/elixir/strings.expect.txt
index e3c845a72c..eb3e93311a 100644
--- a/test/markup/elixir/strings.expect.txt
+++ b/test/markup/elixir/strings.expect.txt
@@ -1,4 +1,8 @@
-a = """test"""
-b = '''test'''
+a = """
+test
+"""
+b = '''
+test
+'''
c = "test"
d = 'test'
diff --git a/test/markup/elixir/strings.txt b/test/markup/elixir/strings.txt
index 4c7c8fb4dc..a178ddcb28 100644
--- a/test/markup/elixir/strings.txt
+++ b/test/markup/elixir/strings.txt
@@ -1,4 +1,8 @@
-a = """test"""
-b = '''test'''
+a = """
+test
+"""
+b = '''
+test
+'''
c = "test"
d = 'test'