Commits

Georg Brandl committed 76dfc21 Merge

Merged in jaingaurav2/pygments-main-898 (pull request #332)

Improvements to bash lexing of numbers with base syntax

Comments (0)

Files changed (2)

pygments/lexers/shell.py

             (r'&', Punctuation),
             (r'\|', Punctuation),
             (r'\s+', Text),
+            (r'\d+(?= |\Z)', Number),
             (r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
-            (r'\d+(?= |\Z)', Number),
             (r'\$#?(\w+|.)', Name.Variable),
             (r'<', Text),
         ],
         'math': [
             (r'\)\)', Keyword, '#pop'),
             (r'[-+*/%^|&]|\*\*|\|\|', Operator),
+            (r'\d+#\d+', Number),
+            (r'\d+#(?! )', Number),
             (r'\d+', Number),
             include('root'),
         ],

tests/examplefiles/example.sh

+#!/bin/bash
+
+printf "%d %s\n" 10 "foo"
+printf "%d %s\n" $((10#1)) "bar"
+
+let "m = 10#${1:1:2}"
+echo $m
+
+m=$((10#${1:4:3} + 10#${1:1:3}))
+echo $m
+
+m=$((10#${1:4:3}))
+echo $m
+
+m=$((10#$1))
+echo $m
+
+m=$((10#1))
+echo $m
+
+m=$((10))
+echo $m