summaryrefslogtreecommitdiff
path: root/pygments/lexers/shell.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-10-06 21:05:26 -0700
committerTim Hatch <tim@timhatch.com>2014-10-06 21:05:26 -0700
commit4ad22ff46ce05d7c665d9489c8122b45d5fae082 (patch)
treef52ec38931dfe477520276a5c1adc3bed6b33762 /pygments/lexers/shell.py
parent053be80c14dace5f47d36507e7389f8b664e3898 (diff)
downloadpygments-4ad22ff46ce05d7c665d9489c8122b45d5fae082.tar.gz
BashLexer: Significantly improve handling of quoted strings (and ${})
Fixes #994
Diffstat (limited to 'pygments/lexers/shell.py')
-rw-r--r--pygments/lexers/shell.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index df9b56f4..097ca624 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -39,12 +39,16 @@ class BashLexer(RegexLexer):
tokens = {
'root': [
include('basic'),
- (r'\$\(\(', Keyword, 'math'),
- (r'\$\(', Keyword, 'paren'),
- (r'\${#?', Keyword, 'curly'),
(r'`', String.Backtick, 'backticks'),
+ include('interp'),
include('data'),
],
+ 'interp': [
+ (r'\$\(\(', Keyword, 'math'),
+ (r'\$\(', Keyword, 'paren'),
+ (r'\${#?', String.Interpol, 'curly'),
+ (r'\$#?(\w+|.)', Name.Variable),
+ ],
'basic': [
(r'\b(if|fi|else|while|do|done|for|then|return|function|case|'
r'select|continue|until|esac|elif)(\s*)\b',
@@ -65,7 +69,8 @@ class BashLexer(RegexLexer):
(r'&&|\|\|', Operator),
],
'data': [
- (r'(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
+ (r'(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"', String.Double),
+ (r'"', String.Double, 'string'),
(r"(?s)\$?'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
(r';', Punctuation),
(r'&', Punctuation),
@@ -73,14 +78,18 @@ class BashLexer(RegexLexer):
(r'\s+', Text),
(r'\d+(?= |\Z)', Number),
(r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
- (r'\$#?(\w+|.)', Name.Variable),
(r'<', Text),
],
+ 'string': [
+ (r'"', String.Double, '#pop'),
+ (r'(\\\\|\\[0-7]+|\\[\w\W]|[^"\\$])+', String.Double),
+ include('interp'),
+ ],
'curly': [
- (r'}', Keyword, '#pop'),
+ (r'}', String.Interpol, '#pop'),
(r':-', Keyword),
(r'\w+', Name.Variable),
- (r'[^}:"\'`$]+', Punctuation),
+ (r'[^}:"\'`$\\]+', Punctuation),
(r':', Punctuation),
include('root'),
],