Skip to content

Commit

Permalink
enh(bash) add arithmetic support
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 28, 2020
1 parent ec0ec9b commit 889e2de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Core Changes:

Language Improvements:

- enh(bash) Add arithmetic expression support (#) [Josh Goebel][]
- enh(clojure) Add support for global definitions name (#2347) [Alexandre Grison][]
- enh(fortran) Support Fortran 77 style comments (#2416) [Josh Goebel][]
- (csharp) add support for `@identifier` style identifiers (#2414) [Josh Goebel][]
Expand Down
10 changes: 10 additions & 0 deletions src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export default function(hljs) {
className: 'string',
begin: /'/, end: /'/
};
const ARITHEMETIC = {
begin: /\$\(\(/,
end: /\)\)/,
contains: [
{ begin: /\d+#[0-9a-f]+/, className: "number" },
hljs.NUMBER_MODE,
VAR
]
};

return {
name: 'Bash',
Expand Down Expand Up @@ -79,6 +88,7 @@ export default function(hljs) {
contains: [hljs.inherit(hljs.TITLE_MODE, {begin: /\w[\w\d_]*/})],
relevance: 0
},
ARITHEMETIC,
hljs.HASH_COMMENT_MODE,
QUOTE_STRING,
ESCAPED_QUOTE,
Expand Down
8 changes: 8 additions & 0 deletions test/markup/bash/arithmetic.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span class="hljs-built_in">echo</span> $(( <span class="hljs-number">16#deadbeef</span> / <span class="hljs-number">1003</span> ))

yumi=deadbeef
<span class="hljs-built_in">echo</span> $(( <span class="hljs-number">16</span>#<span class="hljs-variable">$yumi</span> / <span class="hljs-number">1003</span> ))

B=20
yumi=deadbeef
<span class="hljs-built_in">echo</span> $(( <span class="hljs-variable">$B</span>#<span class="hljs-variable">$yumi</span> / <span class="hljs-number">1003</span> ))
8 changes: 8 additions & 0 deletions test/markup/bash/arithmetic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo $(( 16#deadbeef / 1003 ))

yumi=deadbeef
echo $(( 16#$yumi / 1003 ))

B=20
yumi=deadbeef
echo $(( $B#$yumi / 1003 ))

0 comments on commit 889e2de

Please sign in to comment.