diff options
author | Georg Brandl <georg@python.org> | 2014-03-04 16:18:03 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-03-04 16:18:03 +0100 |
commit | 54ad1bef8114d84daa0260c13e16a4d8be10b45e (patch) | |
tree | c659bd993c177a4ba719f03943708e0006454a79 | |
parent | e7ec14d69541995b8e51c2d6f3be1ec6444b6edc (diff) | |
download | pygments-54ad1bef8114d84daa0260c13e16a4d8be10b45e.tar.gz |
Overhaul the Makefile lexer a bit more.
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pygments/lexers/text.py | 27 |
2 files changed, 20 insertions, 9 deletions
@@ -44,6 +44,8 @@ Version 2.0 - New styles: "xcode" and "igor", similar to the default highlighting of the respective IDEs. +- Updated the Makefile lexer to yield a little more useful highlighting. + - Lexer aliases passed to ``get_lexer_by_name()`` are now case-insensitive. - File name matching in lexers and formatters will now use a regex cache diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py index 956dbd32..8de786c2 100644 --- a/pygments/lexers/text.py +++ b/pygments/lexers/text.py @@ -227,6 +227,10 @@ class BaseMakefileLexer(RegexLexer): tokens = { 'root': [ + # recipes (need to allow spaces because of expandtabs) + (r'^(?:[\t ]+.*\n|\n)+', using(BashLexer)), + # special variables + (r'\$[<@$+%?|*]', Keyword), (r'\s+', Text), (r'#.*?\n', Comment), (r'(export)(\s+)(?=[a-zA-Z0-9_${}\t -]+\n)', @@ -241,11 +245,15 @@ 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) + (r'\$\(', Keyword, 'expansion'), + ], + 'expansion': [ + (r'[^$a-zA-Z_)]+', Text), + (r'[a-zA-Z_]+', Name.Variable), + (r'\$', Keyword), + (r'\(', Keyword, '#push'), + (r'\)', Keyword, '#pop'), ], 'export': [ (r'[a-zA-Z0-9_${}-]+', Name.Variable), @@ -253,12 +261,13 @@ class BaseMakefileLexer(RegexLexer): (r'\s+', Text), ], 'block-header': [ - (r'[^,\\\n#]+', Number), - (r',', Punctuation), - (r'#.*?\n', Comment), + (r'[,|]', Punctuation), + (r'#.*?\n', Comment, '#pop'), (r'\\\n', Text), # line continuation - (r'\\.', Text), - (r'(?:[\t ]+.*\n|\n)+', using(BashLexer), '#pop'), + (r'\$\(', Keyword, 'expansion'), + (r'[a-zA-Z_]+', Name), + (r'\n', Text, '#pop'), + (r'.', Text), ], } |