Skip to content

Commit

Permalink
enh(haskell) Add support for NumericalUnderscores
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnbastiaan committed Apr 19, 2021
1 parent e2151e3 commit b3f881e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Grammars:
- enh(parser) highlight object properties (#3072) [Josh Goebel][]
- enh(javascript/typescript) highlight object properties (#3072) [Josh Goebel][]
- enh(haskell) add support for BinaryLiterals (#3150) [Martijn Bastiaan][]
- enh(haskell) add support for NumericalUnderscores (#3150) [Martijn Bastiaan][]

New Languages:

Expand Down
9 changes: 7 additions & 2 deletions src/languages/haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,16 @@ export default function(hljs) {
PREPROCESSOR,

// Literals and names.
hljs.inherit(hljs.BINARY_NUMBER_MODE, {
begin: '\\b(0b[01_]+)'
}),

hljs.inherit(hljs.C_NUMBER_MODE, {
begin: '(-?)(\\b0[xX][a-fA-F0-9_]+|(\\b(\\d|_)+(\\.(\\d|_)*)?|\\.(\\d|_)+)([eE][-+]?(\\d|_)+)?)'
}),

// TODO: characters.
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE,
hljs.BINARY_NUMBER_MODE,
CONSTRUCTOR,
hljs.inherit(hljs.TITLE_MODE, {
begin: '^[_a-z][\\w\']*'
Expand Down
3 changes: 3 additions & 0 deletions test/markup/haskell/numbers.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-number">0b001_001</span>
<span class="hljs-number">0x000_0FF</span>
<span class="hljs-number">132_15</span>
3 changes: 3 additions & 0 deletions test/markup/haskell/numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0b001_001
0x000_0FF
132_15

0 comments on commit b3f881e

Please sign in to comment.