-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(erlang) Erlang/OTP 27 enhancements (#4063)
* enh(erlang) OTP 27 triple-quoted strings https://www.erlang.org/blog/highlights-otp-27/ https://www.erlang.org/doc/system/data_types#string Test examples taken from the blog and the documentation. * enh(erlang) OTP 27 doc attribute The doc/moduledoc attributes can contain strings without params so I've adjusted the directive segment to accomodate this. https://www.erlang.org/blog/highlights-otp-27/ https://www.erlang.org/doc/system/documentation Also added some missing directives: https://www.erlang.org/doc/system/modules#pre-defined-module-attributes * enh(erlang) OTP 27 Sigil type This one is the most involved change. https://www.erlang.org/blog/highlights-otp-27/ https://www.erlang.org/doc/system/data_types#sigil * enh(erlang) OTP25/27 maybe statement https://www.erlang.org/blog/highlights-otp-27/#no-need-to-enable-feature-maybe https://www.erlang.org/doc/system/expressions#maybe * Pure regex TRIPLE_QUOTE Lifted from csharp * change sigil to use variants * Fix priority on Sigil variants matching. * update changelog * forgot contributor link
- Loading branch information
1 parent
78f3b1c
commit 9267f50
Showing
10 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<span class="hljs-keyword">-module</span><span class="hljs-params">(arith)</span>. | ||
<span class="hljs-keyword">-moduledoc</span> <span class="hljs-string">""" | ||
A module for basic arithmetic. | ||
"""</span>. | ||
|
||
<span class="hljs-keyword">-export</span><span class="hljs-params">([add/<span class="hljs-number">2</span>])</span>. | ||
|
||
<span class="hljs-keyword">-doc</span> <span class="hljs-string">"Adds two numbers."</span>. | ||
<span class="hljs-function"><span class="hljs-title">add</span><span class="hljs-params">(One, Two)</span> -></span> One + Two. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-module(arith). | ||
-moduledoc """ | ||
A module for basic arithmetic. | ||
""". | ||
|
||
-export([add/2]). | ||
|
||
-doc "Adds two numbers.". | ||
add(One, Two) -> One + Two. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<span class="hljs-keyword">maybe</span> | ||
{ok, A} ?= a(), | ||
<span class="hljs-literal">true</span> = A >= <span class="hljs-number">0</span>, | ||
{ok, B} ?= b(), | ||
A + B | ||
<span class="hljs-keyword">else</span> | ||
error -> error; | ||
wrong -> error | ||
<span class="hljs-keyword">end</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
maybe | ||
{ok, A} ?= a(), | ||
true = A >= 0, | ||
{ok, B} ?= b(), | ||
A + B | ||
else | ||
error -> error; | ||
wrong -> error | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<span class="hljs-function"><span class="hljs-title">greek_quote</span><span class="hljs-params">()</span> -></span> | ||
S = <span class="hljs-string">~B["Know thyself" (Greek: Γνῶθι σαυτόν)]</span>, | ||
io:format(<span class="hljs-string">"~ts\n"</span>, [S]). | ||
|
||
<span class="hljs-string">~'foo'</span>. | ||
|
||
<<<span class="hljs-string">"\"\\µA\""</span>/utf8>> = <<<span class="hljs-string">$"</span>,<span class="hljs-string">$\\</span>,<span class="hljs-number">194</span>,<span class="hljs-number">181</span>,<span class="hljs-string">$A</span>,<span class="hljs-string">$"</span>>> = | ||
<span class="hljs-string">~b""" | ||
"\\µA" | ||
"""</span> = <span class="hljs-string">~b'"\\µA"'</span> = | ||
<span class="hljs-string">~B""" | ||
"\µA" | ||
"""</span> = <span class="hljs-string">~B<"\µA"></span> = | ||
<span class="hljs-string">~""" | ||
"\µA" | ||
"""</span> = <span class="hljs-string">~"\"\\µA\""</span> = <span class="hljs-string">~/"\\µA"/</span> | ||
|
||
<span class="hljs-function"><span class="hljs-title">quotes</span><span class="hljs-params">()</span> -></span> | ||
S = <span class="hljs-string">~""" | ||
"I always have a quotation for everything - | ||
it saves original thinking." - Dorothy L. Sayers | ||
|
||
"Real stupidity beats artificial intelligence every time." | ||
- Terry Pratchett | ||
"""</span>, | ||
io:put_chars(S), | ||
io:nl(). | ||
|
||
<span class="hljs-string">~s{"abc\txyz"}</span>. | ||
<span class="hljs-string">~(parenthesis)</span>. | ||
<span class="hljs-string">~<alligators></span>. | ||
<span class="hljs-string">~`backticks`</span>. | ||
<span class="hljs-string">~#hashpounds#</span>. | ||
<span class="hljs-string">~|pipes|</span>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
greek_quote() -> | ||
S = ~B["Know thyself" (Greek: Γνῶθι σαυτόν)], | ||
io:format("~ts\n", [S]). | ||
|
||
~'foo'. | ||
|
||
<<"\"\\µA\""/utf8>> = <<$",$\\,194,181,$A,$">> = | ||
~b""" | ||
"\\µA" | ||
""" = ~b'"\\µA"' = | ||
~B""" | ||
"\µA" | ||
""" = ~B<"\µA"> = | ||
~""" | ||
"\µA" | ||
""" = ~"\"\\µA\"" = ~/"\\µA"/ | ||
|
||
quotes() -> | ||
S = ~""" | ||
"I always have a quotation for everything - | ||
it saves original thinking." - Dorothy L. Sayers | ||
|
||
"Real stupidity beats artificial intelligence every time." | ||
- Terry Pratchett | ||
""", | ||
io:put_chars(S), | ||
io:nl(). | ||
|
||
~s{"abc\txyz"}. | ||
~(parenthesis). | ||
~<alligators>. | ||
~`backticks`. | ||
~#hashpounds#. | ||
~|pipes|. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<span class="hljs-function"><span class="hljs-title">quotes</span><span class="hljs-params">()</span> -></span> | ||
S = <span class="hljs-string">""" | ||
"I always have a quotation for everything - | ||
it saves original thinking." - Dorothy L. Sayers | ||
|
||
"Real stupidity beats artificial intelligence every time." | ||
- Terry Pratchett | ||
"""</span>, | ||
io:put_chars(S), | ||
io:nl(). | ||
|
||
<span class="hljs-function"><span class="hljs-title">effect_warning</span><span class="hljs-params">()</span> -></span> | ||
<span class="hljs-string">""" | ||
f() -> | ||
%% Test that the compiler warns for useless tuple building. | ||
{a,b,c}, | ||
ok. | ||
"""</span>. | ||
|
||
<span class="hljs-function"><span class="hljs-title">extra_delim</span><span class="hljs-params">()</span> -></span> | ||
<span class="hljs-string">""""" | ||
"""" | ||
"""""</span>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
quotes() -> | ||
S = """ | ||
"I always have a quotation for everything - | ||
it saves original thinking." - Dorothy L. Sayers | ||
|
||
"Real stupidity beats artificial intelligence every time." | ||
- Terry Pratchett | ||
""", | ||
io:put_chars(S), | ||
io:nl(). | ||
|
||
effect_warning() -> | ||
""" | ||
f() -> | ||
%% Test that the compiler warns for useless tuple building. | ||
{a,b,c}, | ||
ok. | ||
""". | ||
|
||
extra_delim() -> | ||
""""" | ||
"""" | ||
""""". |