Skip to content

Commit b50fa49

Browse files
authored
enh(erlang) add support for underscore separators in numeric literals (#2554)
* (erlang) add support for underscore separators in numeric literals * (erlang) add tests
1 parent f64993f commit b50fa49

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Language Improvements:
3434
- fix(yaml) Fix tags to include non-word characters (#2486) [Peter Plantinga][]
3535
- fix(swift) `@objcMembers` was being partially highlighted (#2543) [Nick Randall][]
3636
- enh(dart) Add `late` and `required` keywords, and `Never` built-in type (#2550) [Sam Rawlins][]
37+
- enh(erlang) Add underscore separators to numeric literals (#2554) [Sergey Prokhorov][]
3738

3839
[Josh Goebel]: https://github.com/yyyc514
3940
[Peter Plantinga]: https://github.com/pplantinga
@@ -42,6 +43,7 @@ Language Improvements:
4243
[Hankun Lin]: https://github.com/Linhk1606
4344
[Nick Randall]: https://github.com/nicked
4445
[Sam Rawlins]: https://github.com/srawlins
46+
[Sergey Prokhorov]: https://github.com/seriyps
4547

4648

4749
## Version 10.0.2

src/languages/erlang-repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function(hljs) {
2323
hljs.COMMENT('%', '$'),
2424
{
2525
className: 'number',
26-
begin: '\\b(\\d+#[a-fA-F0-9]+|\\d+(\\.\\d+)?([eE][-+]?\\d+)?)',
26+
begin: '\\b(\\d+(_\\d+)*#[a-fA-F0-9]+(_[a-fA-F0-9]+)*|\\d+(_\\d+)*(\\.\\d+(_\\d+)*)?([eE][-+]?\\d+)?)',
2727
relevance: 0
2828
},
2929
hljs.APOS_STRING_MODE,

src/languages/erlang.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function(hljs) {
2020
var COMMENT = hljs.COMMENT('%', '$');
2121
var NUMBER = {
2222
className: 'number',
23-
begin: '\\b(\\d+#[a-fA-F0-9]+|\\d+(\\.\\d+)?([eE][-+]?\\d+)?)',
23+
begin: '\\b(\\d+(_\\d+)*#[a-fA-F0-9]+(_[a-fA-F0-9]+)*|\\d+(_\\d+)*(\\.\\d+(_\\d+)*)?([eE][-+]?\\d+)?)',
2424
relevance: 0
2525
};
2626
var NAMED_FUN = {

test/markup/erlang/numbers.expect.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Integer = <span class="hljs-number">1234</span>
2+
BigInteger = <span class="hljs-number">1_234_000</span>
3+
NegInteger = -<span class="hljs-number">20_000</span>
4+
Float = <span class="hljs-number">2.34</span>
5+
BigFloat = <span class="hljs-number">3_333.14159_26535_89793</span>
6+
SciFloat = <span class="hljs-number">2.4e23</span>
7+
PlusSciFloat = <span class="hljs-number">2.4e+23</span>
8+
SmallSciFloat = <span class="hljs-number">2.4e-23</span>
9+
Binary = <span class="hljs-number">2#1010</span>
10+
StrangeBinary = <span class="hljs-number">2#1010_1010_1010</span>
11+
Octal = <span class="hljs-number">8#777</span>
12+
StrangeOctal = <span class="hljs-number">8#777_666_555</span>
13+
Hex = <span class="hljs-number">16#1ABEF</span>
14+
StrangeHex = <span class="hljs-number">16#1234_FACE_987D</span>

test/markup/erlang/numbers.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Integer = 1234
2+
BigInteger = 1_234_000
3+
NegInteger = -20_000
4+
Float = 2.34
5+
BigFloat = 3_333.14159_26535_89793
6+
SciFloat = 2.4e23
7+
PlusSciFloat = 2.4e+23
8+
SmallSciFloat = 2.4e-23
9+
Binary = 2#1010
10+
StrangeBinary = 2#1010_1010_1010
11+
Octal = 8#777
12+
StrangeOctal = 8#777_666_555
13+
Hex = 16#1ABEF
14+
StrangeHex = 16#1234_FACE_987D

0 commit comments

Comments
 (0)