threads / patch / 52207

v3userdiff: add Elixir to supported userdiff languages

Subject: [PATCH v3] userdiff: add Elixir to supported userdiff languages

## tl;dr

5 messages between Nov 6, 2019 and Nov 9, 2019. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Łukasz Niemier· Nov 6, 2019, 23:49 UTC · lore

Adds support for xfuncref in Elixir[1] language which is Ruby-like language that runs on Erlang[3] Virtual Machine (BEAM).

[1]: https://elixir-lang.org [2]: https://www.erlang.org

Signed-off-by: Łukasz Niemier <lukasz@niemier.pl>
---
 t/t4018-diff-funcname.sh               |  1 +
 t/t4018/elixir-do-not-pick-end         |  5 +++++
 t/t4018/elixir-ex-unit-test            |  6 ++++++
 t/t4018/elixir-function                |  5 +++++
 t/t4018/elixir-macro                   |  5 +++++
 t/t4018/elixir-module                  |  9 +++++++++
 t/t4018/elixir-module-func             |  8 ++++++++
 t/t4018/elixir-nested-module           |  9 +++++++++
 t/t4018/elixir-private-function        |  5 +++++
 t/t4018/elixir-protocol                |  6 ++++++
 t/t4018/elixir-protocol-implementation |  5 +++++
 userdiff.c                             | 12 ++++++++++++
 12 files changed, 76 insertions(+)
 create mode 100644 t/t4018/elixir-do-not-pick-end
 create mode 100644 t/t4018/elixir-ex-unit-test
 create mode 100644 t/t4018/elixir-function
 create mode 100644 t/t4018/elixir-macro
 create mode 100644 t/t4018/elixir-module
 create mode 100644 t/t4018/elixir-module-func
 create mode 100644 t/t4018/elixir-nested-module
 create mode 100644 t/t4018/elixir-private-function
 create mode 100644 t/t4018/elixir-protocol
 create mode 100644 t/t4018/elixir-protocol-implementation
Show changes to 12 files +76 −0

t/t4018-diff-funcname.sh, t/t4018/elixir-do-not-pick-end, t/t4018/elixir-ex-unit-test, t/t4018/elixir-function, t/t4018/elixir-macro, t/t4018/elixir-module, t/t4018/elixir-module-func, t/t4018/elixir-nested-module, t/t4018/elixir-private-function, t/t4018/elixir-protocol, t/t4018/elixir-protocol-implementation, userdiff.c

diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 6f5ef0035e..c0f4839543 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -32,6 +32,7 @@ diffpatterns="
 	csharp
 	css
 	dts
+	elixir
 	fortran
 	fountain
 	golang
diff --git a/t/t4018/elixir-do-not-pick-end b/t/t4018/elixir-do-not-pick-end
new file mode 100644
index 0000000000..fae08ba7e8
--- /dev/null
+++ b/t/t4018/elixir-do-not-pick-end
@@ -0,0 +1,5 @@
+defmodule RIGHT do
+end
+#
+#
+# ChangeMe; do not pick up 'end' line
diff --git a/t/t4018/elixir-ex-unit-test b/t/t4018/elixir-ex-unit-test
new file mode 100644
index 0000000000..0560a2b697
--- /dev/null
+++ b/t/t4018/elixir-ex-unit-test
@@ -0,0 +1,6 @@
+defmodule Test do
+  test "RIGHT" do
+    assert true == true
+    assert ChangeMe
+  end
+end
diff --git a/t/t4018/elixir-function b/t/t4018/elixir-function
new file mode 100644
index 0000000000..d452f495a7
--- /dev/null
+++ b/t/t4018/elixir-function
@@ -0,0 +1,5 @@
+def function(RIGHT, arg) do
+  # comment
+  # comment
+  ChangeMe
+end
diff --git a/t/t4018/elixir-macro b/t/t4018/elixir-macro
new file mode 100644
index 0000000000..4f925e9ad4
--- /dev/null
+++ b/t/t4018/elixir-macro
@@ -0,0 +1,5 @@
+defmacro foo(RIGHT) do
+  # Code
+  # Code
+  ChangeMe
+end
diff --git a/t/t4018/elixir-module b/t/t4018/elixir-module
new file mode 100644
index 0000000000..91a4e7aa20
--- /dev/null
+++ b/t/t4018/elixir-module
@@ -0,0 +1,9 @@
+defmodule RIGHT do
+  @moduledoc """
+  Foo bar
+  """
+
+  def ChangeMe(a) where is_map(a) do
+    a
+  end
+end
diff --git a/t/t4018/elixir-module-func b/t/t4018/elixir-module-func
new file mode 100644
index 0000000000..c9910d0675
--- /dev/null
+++ b/t/t4018/elixir-module-func
@@ -0,0 +1,8 @@
+defmodule Foo do
+  def fun(RIGHT) do
+     # Code
+     # Code
+     # Code
+     ChangeMe
+  end
+end
diff --git a/t/t4018/elixir-nested-module b/t/t4018/elixir-nested-module
new file mode 100644
index 0000000000..771ebc5c42
--- /dev/null
+++ b/t/t4018/elixir-nested-module
@@ -0,0 +1,9 @@
+defmodule MyApp.RIGHT do
+  @moduledoc """
+  Foo bar
+  """
+
+  def ChangeMe(a) where is_map(a) do
+    a
+  end
+end
diff --git a/t/t4018/elixir-private-function b/t/t4018/elixir-private-function
new file mode 100644
index 0000000000..1aabe33b7a
--- /dev/null
+++ b/t/t4018/elixir-private-function
@@ -0,0 +1,5 @@
+defp function(RIGHT, arg) do
+  # comment
+  # comment
+  ChangeMe
+end
diff --git a/t/t4018/elixir-protocol b/t/t4018/elixir-protocol
new file mode 100644
index 0000000000..7d9173691e
--- /dev/null
+++ b/t/t4018/elixir-protocol
@@ -0,0 +1,6 @@
+defprotocol RIGHT do
+  @doc """
+  Calculates the size (and not the length!) of a data structure
+  """
+  def size(data, ChangeMe)
+end
diff --git a/t/t4018/elixir-protocol-implementation b/t/t4018/elixir-protocol-implementation
new file mode 100644
index 0000000000..f9234bbfc4
--- /dev/null
+++ b/t/t4018/elixir-protocol-implementation
@@ -0,0 +1,5 @@
+defimpl RIGHT do
+  # Docs
+  # Docs
+  def foo(ChangeMe), do: :ok
+end
diff --git a/userdiff.c b/userdiff.c
index e187d356f6..577053c10a 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -32,6 +32,18 @@ PATTERNS("dts",
 	 /* Property names and math operators */
 	 "[a-zA-Z0-9,._+?#-]+"
 	 "|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
+PATTERNS("elixir",
+	 "^[ \t]*((def(macro|module|impl|protocol|p)?|test)[ \t].*)$",
+	 /* Atoms, names, and module attributes */
+	 "|[@:]?[a-zA-Z0-9@_?!]+"
+	 /* Numbers with specific base */
+	 "|[-+]?0[xob][0-9a-fA-F]+"
+	 /* Numbers */
+	 "|[-+]?[0-9][0-9_.]*([eE][-+]?[0-9_]+)?"
+	 /* Operators and atoms that represent them */
+	 "|:?(\\+\\+|--|\\.\\.|~~~|<>|\\^\\^\\^|<?\\|>|<<<?|>?>>|<<?~|~>?>|<~>|<=|>=|===?|!==?|=~|&&&?|\\|\\|\\|?|=>|<-|\\\\\\\\|->)"
+	 /* Not real operators, but should be grouped */
+	 "|:?%[A-Za-z0-9_.]\\{\\}?"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"
 	 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
-- 
2.23.0
Johannes Sixt· Nov 7, 2019, 20:35 UTC · re: Łukasz Niemier · lore

Re: [PATCH v3] userdiff: add Elixir to supported userdiff languages

Please keep the Cc list when you send new patch versions. Also, it is customary to send them as replies to the earlier iterations, so that they all end up in the same thread.

Am 07.11.19 um 00:49 schrieb Łukasz Niemier:
Show 5 quoted lines
> Adds support for xfuncref in Elixir[1] language which is Ruby-like
> language that runs on Erlang[3] Virtual Machine (BEAM).
> 
> [1]: https://elixir-lang.org
> [2]: https://www.erlang.org
Thanks! Much appreciated.
> 
> Signed-off-by: Łukasz Niemier <lukasz@niemier.pl>
> ---
Show 11 quoted lines
> diff --git a/t/t4018/elixir-do-not-pick-end b/t/t4018/elixir-do-not-pick-end
> new file mode 100644
> index 0000000000..fae08ba7e8
> --- /dev/null
> +++ b/t/t4018/elixir-do-not-pick-end
> @@ -0,0 +1,5 @@
> +defmodule RIGHT do
> +end
> +#
> +#
> +# ChangeMe; do not pick up 'end' line
OK.
Show 12 quoted lines
> diff --git a/t/t4018/elixir-ex-unit-test b/t/t4018/elixir-ex-unit-test
> new file mode 100644
> index 0000000000..0560a2b697
> --- /dev/null
> +++ b/t/t4018/elixir-ex-unit-test
> @@ -0,0 +1,6 @@
> +defmodule Test do
> +  test "RIGHT" do
> +    assert true == true
> +    assert ChangeMe
> +  end
> +end
A test, and also indented. Good.
Show 14 quoted lines
> diff --git a/t/t4018/elixir-module-func b/t/t4018/elixir-module-func
> new file mode 100644
> index 0000000000..c9910d0675
> --- /dev/null
> +++ b/t/t4018/elixir-module-func
> @@ -0,0 +1,8 @@
> +defmodule Foo do
> +  def fun(RIGHT) do
> +     # Code
> +     # Code
> +     # Code
> +     ChangeMe
> +  end
> +end
An indented function. Good.

These other tests (which I stripped away) ensure that the hunk header pattern does not become too restrictive. They all look good.

Show 12 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index e187d356f6..577053c10a 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -32,6 +32,18 @@ PATTERNS("dts",
>  	 /* Property names and math operators */
>  	 "[a-zA-Z0-9,._+?#-]+"
>  	 "|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
> +PATTERNS("elixir",
> +	 "^[ \t]*((def(macro|module|impl|protocol|p)?|test)[ \t].*)$",
> +	 /* Atoms, names, and module attributes */
> +	 "|[@:]?[a-zA-Z0-9@_?!]+"

There are no single- and double-quote anymore. An oversight? Or an error in the earlier iteration?

> +	 /* Numbers with specific base */
> +	 "|[-+]?0[xob][0-9a-fA-F]+"
> +	 /* Numbers */
> +	 "|[-+]?[0-9][0-9_.]*([eE][-+]?[0-9_]+)?"

The leading optional sign may be problematic. When a patch changes "i+1" to "i+2", it would be highlighted as "i{-+1-}{++2+}" instead of as "i+{-1-}{+2+}". You could remove the leading optional sign and let it be processed as an operator. But we also have an optional sign in the cpp pattern as well, and haven't noticed it until now, so...

Show 8 quoted lines
> +	 /* Operators and atoms that represent them */
> +	 "|:?(\\+\\+|--|\\.\\.|~~~|<>|\\^\\^\\^|<?\\|>|<<<?|>?>>|<<?~|~>?>|<~>|<=|>=|===?|!==?|=~|&&&?|\\|\\|\\|?|=>|<-|\\\\\\\\|->)"
> +	 /* Not real operators, but should be grouped */
> +	 "|:?%[A-Za-z0-9_.]\\{\\}?"),
>  IPATTERN("fortran",
>  	 "!^([C*]|[ \t]*!)\n"
>  	 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
> 
In summary, this version looks good!
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes
Łukasz Niemier· Nov 8, 2019, 15:42 UTC · re: Johannes Sixt · lore

Re: [PATCH v3] userdiff: add Elixir to supported userdiff languages

> Please keep the Cc list when you send new patch versions. Also, it is
> customary to send them as replies to the earlier iterations, so that
> they all end up in the same thread.

Sorry, I am still learning how to use git send-email and I thought it would be handled automatically. I need to find how to operate it properly and how to configure it to reply in thread instead of creating new one.

> There are no single- and double-quote anymore. An oversight? Or an error
> in the earlier iteration?

No, I intentionally left them out, as :’foo bar’ is allowed atom, and I didn’t want to complicate everything word regex. Instead I assumed that these are so rare, that it should not be a problem.

Show 5 quoted lines
> The leading optional sign may be problematic. When a patch changes "i+1"
> to "i+2", it would be highlighted as "i{-+1-}{++2+}" instead of as
> "i+{-1-}{+2+}". You could remove the leading optional sign and let it be
> processed as an operator. But we also have an optional sign in the cpp
> pattern as well, and haven't noticed it until now, so…

I copied this pattern from other languages, so I assumed that this is what is expected. It could be fixed, but I think it should be handled in separate patch.

--

Łukasz Niemier lukasz@niemier.pl

Łukasz Niemier· Nov 8, 2019, 21:38 UTC · re: Łukasz Niemier · lore

[PATCH v4] userdiff: add Elixir to supported userdiff languages

Adds support for xfuncref in Elixir[1] language which is Ruby-like language that runs on Erlang[3] Virtual Machine (BEAM).

[1]: https://elixir-lang.org [2]: https://www.erlang.org

Signed-off-by: Łukasz Niemier <lukasz@niemier.pl>
---
Add entry to the documentation of gitattributes as well.
 Documentation/gitattributes.txt        |  2 ++
 t/t4018-diff-funcname.sh               |  1 +
 t/t4018/elixir-do-not-pick-end         |  5 +++++
 t/t4018/elixir-ex-unit-test            |  6 ++++++
 t/t4018/elixir-function                |  5 +++++
 t/t4018/elixir-macro                   |  5 +++++
 t/t4018/elixir-module                  |  9 +++++++++
 t/t4018/elixir-module-func             |  8 ++++++++
 t/t4018/elixir-nested-module           |  9 +++++++++
 t/t4018/elixir-private-function        |  5 +++++
 t/t4018/elixir-protocol                |  6 ++++++
 t/t4018/elixir-protocol-implementation |  5 +++++
 userdiff.c                             | 12 ++++++++++++
 13 files changed, 78 insertions(+)
 create mode 100644 t/t4018/elixir-do-not-pick-end
 create mode 100644 t/t4018/elixir-ex-unit-test
 create mode 100644 t/t4018/elixir-function
 create mode 100644 t/t4018/elixir-macro
 create mode 100644 t/t4018/elixir-module
 create mode 100644 t/t4018/elixir-module-func
 create mode 100644 t/t4018/elixir-nested-module
 create mode 100644 t/t4018/elixir-private-function
 create mode 100644 t/t4018/elixir-protocol
 create mode 100644 t/t4018/elixir-protocol-implementation
Show changes to 13 files +78 −0

Documentation/gitattributes.txt, t/t4018-diff-funcname.sh, t/t4018/elixir-do-not-pick-end, t/t4018/elixir-ex-unit-test, t/t4018/elixir-function, t/t4018/elixir-macro, t/t4018/elixir-module, t/t4018/elixir-module-func, t/t4018/elixir-nested-module, t/t4018/elixir-private-function, t/t4018/elixir-protocol, t/t4018/elixir-protocol-implementation, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index c5a528c667..03d8fe6f30 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -812,6 +812,8 @@ patterns are available:
 
 - `dts` suitable for devicetree (DTS) files.
 
+- `elixir` suitable for source code in the Elixir language.
+
 - `fortran` suitable for source code in the Fortran language.
 
 - `fountain` suitable for Fountain documents.
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 6f5ef0035e..c0f4839543 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -32,6 +32,7 @@ diffpatterns="
 	csharp
 	css
 	dts
+	elixir
 	fortran
 	fountain
 	golang
diff --git a/t/t4018/elixir-do-not-pick-end b/t/t4018/elixir-do-not-pick-end
new file mode 100644
index 0000000000..fae08ba7e8
--- /dev/null
+++ b/t/t4018/elixir-do-not-pick-end
@@ -0,0 +1,5 @@
+defmodule RIGHT do
+end
+#
+#
+# ChangeMe; do not pick up 'end' line
diff --git a/t/t4018/elixir-ex-unit-test b/t/t4018/elixir-ex-unit-test
new file mode 100644
index 0000000000..0560a2b697
--- /dev/null
+++ b/t/t4018/elixir-ex-unit-test
@@ -0,0 +1,6 @@
+defmodule Test do
+  test "RIGHT" do
+    assert true == true
+    assert ChangeMe
+  end
+end
diff --git a/t/t4018/elixir-function b/t/t4018/elixir-function
new file mode 100644
index 0000000000..d452f495a7
--- /dev/null
+++ b/t/t4018/elixir-function
@@ -0,0 +1,5 @@
+def function(RIGHT, arg) do
+  # comment
+  # comment
+  ChangeMe
+end
diff --git a/t/t4018/elixir-macro b/t/t4018/elixir-macro
new file mode 100644
index 0000000000..4f925e9ad4
--- /dev/null
+++ b/t/t4018/elixir-macro
@@ -0,0 +1,5 @@
+defmacro foo(RIGHT) do
+  # Code
+  # Code
+  ChangeMe
+end
diff --git a/t/t4018/elixir-module b/t/t4018/elixir-module
new file mode 100644
index 0000000000..91a4e7aa20
--- /dev/null
+++ b/t/t4018/elixir-module
@@ -0,0 +1,9 @@
+defmodule RIGHT do
+  @moduledoc """
+  Foo bar
+  """
+
+  def ChangeMe(a) where is_map(a) do
+    a
+  end
+end
diff --git a/t/t4018/elixir-module-func b/t/t4018/elixir-module-func
new file mode 100644
index 0000000000..c9910d0675
--- /dev/null
+++ b/t/t4018/elixir-module-func
@@ -0,0 +1,8 @@
+defmodule Foo do
+  def fun(RIGHT) do
+     # Code
+     # Code
+     # Code
+     ChangeMe
+  end
+end
diff --git a/t/t4018/elixir-nested-module b/t/t4018/elixir-nested-module
new file mode 100644
index 0000000000..771ebc5c42
--- /dev/null
+++ b/t/t4018/elixir-nested-module
@@ -0,0 +1,9 @@
+defmodule MyApp.RIGHT do
+  @moduledoc """
+  Foo bar
+  """
+
+  def ChangeMe(a) where is_map(a) do
+    a
+  end
+end
diff --git a/t/t4018/elixir-private-function b/t/t4018/elixir-private-function
new file mode 100644
index 0000000000..1aabe33b7a
--- /dev/null
+++ b/t/t4018/elixir-private-function
@@ -0,0 +1,5 @@
+defp function(RIGHT, arg) do
+  # comment
+  # comment
+  ChangeMe
+end
diff --git a/t/t4018/elixir-protocol b/t/t4018/elixir-protocol
new file mode 100644
index 0000000000..7d9173691e
--- /dev/null
+++ b/t/t4018/elixir-protocol
@@ -0,0 +1,6 @@
+defprotocol RIGHT do
+  @doc """
+  Calculates the size (and not the length!) of a data structure
+  """
+  def size(data, ChangeMe)
+end
diff --git a/t/t4018/elixir-protocol-implementation b/t/t4018/elixir-protocol-implementation
new file mode 100644
index 0000000000..f9234bbfc4
--- /dev/null
+++ b/t/t4018/elixir-protocol-implementation
@@ -0,0 +1,5 @@
+defimpl RIGHT do
+  # Docs
+  # Docs
+  def foo(ChangeMe), do: :ok
+end
diff --git a/userdiff.c b/userdiff.c
index e187d356f6..577053c10a 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -32,6 +32,18 @@ PATTERNS("dts",
 	 /* Property names and math operators */
 	 "[a-zA-Z0-9,._+?#-]+"
 	 "|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
+PATTERNS("elixir",
+	 "^[ \t]*((def(macro|module|impl|protocol|p)?|test)[ \t].*)$",
+	 /* Atoms, names, and module attributes */
+	 "|[@:]?[a-zA-Z0-9@_?!]+"
+	 /* Numbers with specific base */
+	 "|[-+]?0[xob][0-9a-fA-F]+"
+	 /* Numbers */
+	 "|[-+]?[0-9][0-9_.]*([eE][-+]?[0-9_]+)?"
+	 /* Operators and atoms that represent them */
+	 "|:?(\\+\\+|--|\\.\\.|~~~|<>|\\^\\^\\^|<?\\|>|<<<?|>?>>|<<?~|~>?>|<~>|<=|>=|===?|!==?|=~|&&&?|\\|\\|\\|?|=>|<-|\\\\\\\\|->)"
+	 /* Not real operators, but should be grouped */
+	 "|:?%[A-Za-z0-9_.]\\{\\}?"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"
 	 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
-- 
2.23.0
Johannes Sixt· Nov 9, 2019, 19:31 UTC · re: Łukasz Niemier · lore

Re: [PATCH v4] userdiff: add Elixir to supported userdiff languages

Am 08.11.19 um 22:38 schrieb Łukasz Niemier:
Show 9 quoted lines
> Adds support for xfuncref in Elixir[1] language which is Ruby-like
> language that runs on Erlang[3] Virtual Machine (BEAM).
> 
> [1]: https://elixir-lang.org
> [2]: https://www.erlang.org
> 
> Signed-off-by: Łukasz Niemier <lukasz@niemier.pl>
> ---
> Add entry to the documentation of gitattributes as well.
Oh, yes! Thanks for being diligent! Let me repeat my
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes

← back to recent threads