summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasylumfunk <asylumfunk@gmail.com>2014-03-02 01:33:17 -0800
committerasylumfunk <asylumfunk@gmail.com>2014-03-02 01:33:17 -0800
commiteea3ac45dadb7f90318ec1cc5cb92c3d2dc0079d (patch)
treec62be27419c9a3542b3cc4e9f43a18efa726e3d7
parent76830a64b219cc2fd76b7ae7de12b717375a6793 (diff)
downloadpygments-eea3ac45dadb7f90318ec1cc5cb92c3d2dc0079d.tar.gz
Fix Makefile highlighting with target expansion
Currently, when the lexer encounters a Makefile target specified with a variable, i.e. `$(VARIABLE_TARGET): prerequisite', it fails to properly highlight the remainder of the file. This happens as BaseMakefileLexer sees the `$' character, assumes it's shell code, and delegates to BashLexer. The remainder of the file is then mistakenly interpreted as shell code. This patch corrects this behavior and properly highlights entire Makefiles, regardless of target syntax. By specifying all shell-specific regular expressions AFTER all Makefile-specific regular expressions, we can ensure that the latter are given priority over the former.
-rw-r--r--pygments/lexers/text.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index fdaa528d..956dbd32 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -227,8 +227,6 @@ class BaseMakefileLexer(RegexLexer):
tokens = {
'root': [
- (r'^(?:[\t ]+.*\n|\n)+', using(BashLexer)),
- (r'\$\((?:.*\\\n|.*\n)+', using(BashLexer)),
(r'\s+', Text),
(r'#.*?\n', Comment),
(r'(export)(\s+)(?=[a-zA-Z0-9_${}\t -]+\n)',
@@ -243,6 +241,10 @@ class BaseMakefileLexer(RegexLexer):
# targets
(r'([^\n:]+)(:+)([ \t]*)', bygroups(Name.Function, Operator, Text),
'block-header'),
+ # recipes
+ (r'^(?:[\t ]+.*\n|\n)+', using(BashLexer)),
+ # expansions
+ (r'\$\((?:.*\\\n|.*\n)+', using(BashLexer)),
# TODO: add paren handling (grr)
],
'export': [