diff options
author | Georg Brandl <georg@python.org> | 2014-10-16 09:33:43 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-16 09:33:43 +0200 |
commit | 5727fe42393a86817bd0f702d93c3fc399b68eb3 (patch) | |
tree | 796e787baf37e7362a802aaf9b6303127ff35098 | |
parent | f8f38adf82e18ea5c33d532ab3429bb22eed0921 (diff) | |
download | pygments-5727fe42393a86817bd0f702d93c3fc399b68eb3.tar.gz |
Fix "matches empty string" complaints from regexlint.
-rw-r--r-- | pygments/lexers/actionscript.py | 8 | ||||
-rw-r--r-- | pygments/lexers/c_like.py | 5 | ||||
-rw-r--r-- | pygments/lexers/configs.py | 8 | ||||
-rw-r--r-- | pygments/lexers/dylan.py | 4 | ||||
-rw-r--r-- | pygments/lexers/erlang.py | 7 | ||||
-rw-r--r-- | pygments/lexers/graphics.py | 10 | ||||
-rw-r--r-- | pygments/lexers/haxe.py | 6 | ||||
-rw-r--r-- | pygments/lexers/inferno.py | 4 | ||||
-rw-r--r-- | pygments/lexers/installers.py | 4 | ||||
-rw-r--r-- | pygments/lexers/int_fiction.py | 43 | ||||
-rw-r--r-- | pygments/lexers/javascript.py | 5 | ||||
-rw-r--r-- | pygments/lexers/jvm.py | 6 | ||||
-rw-r--r-- | pygments/lexers/lisp.py | 2 | ||||
-rw-r--r-- | pygments/lexers/markup.py | 3 | ||||
-rw-r--r-- | pygments/lexers/modeling.py | 8 | ||||
-rw-r--r-- | pygments/lexers/objective.py | 5 | ||||
-rw-r--r-- | pygments/lexers/rust.py | 6 | ||||
-rw-r--r-- | pygments/lexers/testing.py | 52 | ||||
-rw-r--r-- | pygments/lexers/webmisc.py | 2 |
19 files changed, 107 insertions, 81 deletions
diff --git a/pygments/lexers/actionscript.py b/pygments/lexers/actionscript.py index 9a33dc18..d15b1338 100644 --- a/pygments/lexers/actionscript.py +++ b/pygments/lexers/actionscript.py @@ -11,7 +11,7 @@ import re -from pygments.lexer import RegexLexer, bygroups, using, this, words +from pygments.lexer import RegexLexer, bygroups, using, this, words, default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation @@ -179,12 +179,14 @@ class ActionScript3Lexer(RegexLexer): 'type': [ (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)', bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'), - (r'\s*', Text, '#pop:2') + (r'\s+', Text, '#pop:2'), + default('#pop:2') ], 'defval': [ (r'(=)(\s*)([^(),]+)(\s*)(,?)', bygroups(Operator, Text, using(this), Text, Operator), '#pop'), - (r',?', Operator, '#pop') + (r',', Operator, '#pop'), + default('#pop') ] } diff --git a/pygments/lexers/c_like.py b/pygments/lexers/c_like.py index 622fa869..ff9b266c 100644 --- a/pygments/lexers/c_like.py +++ b/pygments/lexers/c_like.py @@ -11,7 +11,8 @@ import re -from pygments.lexer import RegexLexer, include, bygroups, inherit, words +from pygments.lexer import RegexLexer, include, bygroups, inherit, words, \ + default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation @@ -247,7 +248,7 @@ class ValaLexer(RegexLexer): ], 'root': [ include('whitespace'), - ('', Text, 'statement'), + default('statement'), ], 'statement': [ include('whitespace'), diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 2f8f1a45..735ac4a9 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -83,7 +83,8 @@ class RegeditLexer(RegexLexer): (r'(dword|hex(?:\([0-9a-fA-F]\))?)(:)([0-9a-fA-F,]+)', bygroups(Name.Variable, Punctuation, Number), '#pop'), # As far as I know, .reg files do not support line continuation. - (r'.*', String, '#pop'), + (r'.+', String, '#pop'), + default('#pop'), ] } @@ -193,7 +194,7 @@ class KconfigLexer(RegexLexer): call_indent(3), call_indent(2), call_indent(1), - ('', Text, '#pop'), # for incomplete help sections without text + default('#pop'), # for incomplete help sections without text ], # Handle text for indentation levels 7 to 1 'indent7': do_indent(7), @@ -433,7 +434,8 @@ class SquidConfLexer(RegexLexer): ], 'comment': [ (r'\s*TAG:.*', String.Escape, '#pop'), - (r'.*', Comment, '#pop'), + (r'.+', Comment, '#pop'), + default('#pop'), ], } diff --git a/pygments/lexers/dylan.py b/pygments/lexers/dylan.py index b4f2a976..e13627a2 100644 --- a/pygments/lexers/dylan.py +++ b/pygments/lexers/dylan.py @@ -11,7 +11,7 @@ import re -from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions +from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Generic, Literal @@ -120,7 +120,7 @@ class DylanLexer(RegexLexer): (r'([a-z0-9-]+)(:)([ \t]*)(.*(?:\n[ \t].+)*)', bygroups(Name.Attribute, Operator, Text, String)), - ('', Text, 'code') # no header match, switch to code + default('code') # no header match, switch to code ], 'code': [ # Whitespace diff --git a/pygments/lexers/erlang.py b/pygments/lexers/erlang.py index 89dcf336..6aa336db 100644 --- a/pygments/lexers/erlang.py +++ b/pygments/lexers/erlang.py @@ -12,7 +12,7 @@ import re from pygments.lexer import Lexer, RegexLexer, bygroups, words, do_insertions, \ - include + include, default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Generic @@ -293,7 +293,10 @@ class ElixirLexer(RegexLexer): (name + '-end', name + '-no-intp')), ] - states[name + '-end'] = [(r'[a-zA-Z]*', token, '#pop')] + states[name + '-end'] = [ + (r'[a-zA-Z]+', token, '#pop'), + default('#pop'), + ] states[name + '-intp'] = [ (r'^\s*' + term, String.Heredoc, '#pop'), include('heredoc_interpol'), diff --git a/pygments/lexers/graphics.py b/pygments/lexers/graphics.py index 7cf1c5b7..30f2281c 100644 --- a/pygments/lexers/graphics.py +++ b/pygments/lexers/graphics.py @@ -9,7 +9,8 @@ :license: BSD, see LICENSE for details. """ -from pygments.lexer import RegexLexer, words, include, bygroups, using, this +from pygments.lexer import RegexLexer, words, include, bygroups, using, \ + this, default from pygments.token import Text, Comment, Operator, Keyword, Name, \ Number, Punctuation, String @@ -166,7 +167,8 @@ class PostScriptLexer(RegexLexer): ], 'escape': [ - (r'([0-8]{3}|n|r|t|b|f|\\|\(|\))?', String.Escape, '#pop'), + (r'[0-8]{3}|n|r|t|b|f|\\|\(|\)', String.Escape, '#pop'), + default('#pop'), ], } @@ -251,7 +253,7 @@ class AsymptoteLexer(RegexLexer): r'(' + _ws + r')(;)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation)), - ('', Text, 'statement'), + default('statement'), ], 'statement': [ include('whitespace'), @@ -344,7 +346,7 @@ class GnuplotLexer(RegexLexer): (r'\\\n', Comment), (r'\\', Comment), # don't add the newline to the Comment token - ('', Comment, '#pop'), + default('#pop'), ], 'whitespace': [ ('#', Comment, 'comment'), diff --git a/pygments/lexers/haxe.py b/pygments/lexers/haxe.py index a0758ac6..7d953eb5 100644 --- a/pygments/lexers/haxe.py +++ b/pygments/lexers/haxe.py @@ -196,7 +196,7 @@ class HaxeLexer(ExtendedRegexLexer): 'preproc-parenthesis': [ (r'\s+', Comment.Preproc), (r'\)', Comment.Preproc, '#pop'), - ('', Text, 'preproc-expr-in-parenthesis'), + default('preproc-expr-in-parenthesis'), ], 'preproc-expr-chain': [ @@ -367,9 +367,11 @@ class HaxeLexer(ExtendedRegexLexer): # local function, anonymous or not 'function-local': [ include('spaces'), - (r'(' + ident_no_keyword + ')?', Name.Function, + (ident_no_keyword, Name.Function, ('#pop', 'optional-expr', 'flag', 'function-param', 'parenthesis-open', 'type-param-constraint')), + default(('#pop', 'optional-expr', 'flag', 'function-param', + 'parenthesis-open', 'type-param-constraint')), ], 'optional-expr': [ diff --git a/pygments/lexers/inferno.py b/pygments/lexers/inferno.py index 6aecafdb..706be0c9 100644 --- a/pygments/lexers/inferno.py +++ b/pygments/lexers/inferno.py @@ -11,7 +11,7 @@ import re -from pygments.lexer import RegexLexer, include, bygroups +from pygments.lexer import RegexLexer, include, bygroups, default from pygments.token import Punctuation, Text, Comment, Operator, Keyword, \ Name, String, Number @@ -74,7 +74,7 @@ class LimboLexer(RegexLexer): ], 'root': [ include('whitespace'), - ('', Text, 'statement'), + default('statement'), ], } diff --git a/pygments/lexers/installers.py b/pygments/lexers/installers.py index 53a7abc1..d5ca8d3c 100644 --- a/pygments/lexers/installers.py +++ b/pygments/lexers/installers.py @@ -11,7 +11,7 @@ import re -from pygments.lexer import RegexLexer, include, bygroups, using, this +from pygments.lexer import RegexLexer, include, bygroups, using, this, default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Punctuation, Generic, Number, Whitespace @@ -299,7 +299,7 @@ class DebianControlLexer(RegexLexer): bygroups(Text, String, Name, Name.Class)), (r':.*\n', Generic.Strong), (r' .*\n', Text), - ('', Text, '#pop'), + default('#pop'), ], 'depends': [ (r':\s*', Text), diff --git a/pygments/lexers/int_fiction.py b/pygments/lexers/int_fiction.py index 34641578..e621d9ae 100644 --- a/pygments/lexers/int_fiction.py +++ b/pygments/lexers/int_fiction.py @@ -45,8 +45,9 @@ class Inform6Lexer(RegexLexer): tokens = { 'root': [ - (r'(\A(!%%[^%s]*[%s])+)?' % (_newline, _newline), Comment.Preproc, - 'directive') + (r'\A(!%%[^%s]*[%s])+' % (_newline, _newline), Comment.Preproc, + 'directive'), + default('directive') ], '_whitespace': [ (r'\s+', Text), @@ -216,11 +217,13 @@ class Inform6Lexer(RegexLexer): ], 'label?': [ include('_whitespace'), - (r'(%s)?' % _name, Name.Label, '#pop') + (_name, Name.Label, '#pop'), + default('#pop') ], 'variable?': [ include('_whitespace'), - (r'(%s)?' % _name, Name.Variable, '#pop') + (_name, Name.Variable, '#pop'), + default('#pop') ], # Values after hashes 'obsolete-dictionary-word': [ @@ -275,7 +278,8 @@ class Inform6Lexer(RegexLexer): # [, Replace, Stub 'routine-name?': [ include('_whitespace'), - (r'(%s)?' % _name, Name.Function, '#pop') + (_name, Name.Function, '#pop'), + default('#pop') ], 'locals': [ include('_whitespace'), @@ -353,7 +357,8 @@ class Inform6Lexer(RegexLexer): include('_whitespace'), (r';', Punctuation, '#pop'), (r',', Punctuation), - (r'(?i)(global\b)?', Keyword, '_global') + (r'(?i)global\b', Keyword, '_global'), + default('_global') ], # Include, Link, Message 'diagnostic': [ @@ -428,8 +433,9 @@ class Inform6Lexer(RegexLexer): (r'@', Keyword, 'opcode'), (r'#(?![agrnw]\$|#)', Punctuation, 'directive'), (r'<', Punctuation, 'default'), - (r'(move\b)?', Keyword, - ('default', '_keyword-expression', '_expression')) + (r'move\b', Keyword, + ('default', '_keyword-expression', '_expression')), + default(('default', '_keyword-expression', '_expression')) ], 'miscellaneous-keyword?': [ include('_whitespace'), @@ -444,11 +450,13 @@ class Inform6Lexer(RegexLexer): ], '(?': [ include('_whitespace'), - (r'\(?', Punctuation, '#pop') + (r'\(', Punctuation, '#pop'), + default('#pop') ], 'for': [ include('_whitespace'), - (r';?', Punctuation, ('_for-expression', '_expression')) + (r';', Punctuation, ('_for-expression', '_expression')), + default(('_for-expression', '_expression')) ], 'print-list': [ include('_whitespace'), @@ -868,9 +876,9 @@ class Tads3Lexer(RegexLexer): default(('#pop', 'object-body/no-braces', 'classes', 'class')) ], 'object-body/no-braces': [ - (r';', Punctuation, '#pop'), - (r'\{', Punctuation, ('#pop', 'object-body')), - include('object-body') + (r';', Punctuation, '#pop'), + (r'\{', Punctuation, ('#pop', 'object-body')), + include('object-body') ], 'object-body': [ (r';', Punctuation), @@ -1124,7 +1132,8 @@ class Tads3Lexer(RegexLexer): ], 'enum': [ include('whitespace'), - (r'(token\b)?', Keyword, ('#pop', 'constants')) + (r'token\b', Keyword, ('#pop', 'constants')), + default(('#pop', 'constants')) ], 'grammar': [ (r'\)+', Punctuation), @@ -1165,7 +1174,8 @@ class Tads3Lexer(RegexLexer): 'inherited': [ (r'<', Punctuation, ('#pop', 'classes', 'class')), include('whitespace'), - (r'%s?' % _name, Name.Class, '#pop'), + (_name, Name.Class, '#pop'), + default('#pop') ], 'operator': [ (r'negate\b', Operator.Word, '#pop'), @@ -1199,7 +1209,8 @@ class Tads3Lexer(RegexLexer): 'classes': [ (r'[:,]', Punctuation, 'class'), include('whitespace'), - (r'>?', Punctuation, '#pop') + (r'>', Punctuation, '#pop'), + default('#pop') ], 'constants': [ (r',+', Punctuation), diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 4148c6b0..f058ec6d 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -11,8 +11,7 @@ import re -from pygments.lexer import RegexLexer, include, bygroups, default, \ - using, this +from pygments.lexer import RegexLexer, include, bygroups, default, using, this from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Other from pygments.util import get_bool_opt, iteritems @@ -918,7 +917,7 @@ class ObjectiveJLexer(RegexLexer): (r'([$a-zA-Z_]\w+)', # function name bygroups(Name.Function), "#pop"), - ('', Text, '#pop'), + default('#pop'), ], 'function_parameters': [ include('whitespace'), diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index df54e714..feefefc2 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -1462,7 +1462,8 @@ class JasminLexer(RegexLexer): (r'(L)((?:%s[/.])*)(%s?)(;)' % (_unqualified_name, _name), bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), '#pop'), - (r'[^%s\[)L]*' % _separator, Keyword.Type, '#pop') + (r'[^%s\[)L]+' % _separator, Keyword.Type, '#pop'), + default('#pop') ], 'descriptor/no-dots': [ include('default'), @@ -1470,7 +1471,8 @@ class JasminLexer(RegexLexer): (r'(L)((?:%s/)*)(%s)(;)' % (_unqualified_name, _name), bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), '#pop'), - (r'[^%s\[)L]*' % _separator, Keyword.Type, '#pop') + (r'[^%s\[)L]+' % _separator, Keyword.Type, '#pop'), + default('#pop') ], 'descriptors/convert-dots': [ (r'\)', Punctuation, '#pop'), diff --git a/pygments/lexers/lisp.py b/pygments/lexers/lisp.py index c9a82d8e..9cd0460c 100644 --- a/pygments/lexers/lisp.py +++ b/pygments/lexers/lisp.py @@ -230,7 +230,7 @@ class CommonLispLexer(RegexLexer): tokens = { 'root': [ - ('', Text, 'body'), + default('body'), ], 'multiline-comment': [ (r'#\|', Comment.Multiline, '#push'), # (cf. Hyperspec 2.4.8.19) diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index dcc22250..69202b00 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -350,7 +350,8 @@ class GroffLexer(RegexLexer): (r'(\.)(\w+)', bygroups(Text, Keyword), 'request'), (r'\.', Punctuation, 'request'), # Regular characters, slurp till we find a backslash or newline - (r'[^\\\n]*', Text, 'textline'), + (r'[^\\\n]+', Text, 'textline'), + default('textline'), ], 'textline': [ include('escapes'), diff --git a/pygments/lexers/modeling.py b/pygments/lexers/modeling.py index 02e2936e..9e7c172d 100644 --- a/pygments/lexers/modeling.py +++ b/pygments/lexers/modeling.py @@ -11,7 +11,7 @@ import re -from pygments.lexer import RegexLexer, include, bygroups, using +from pygments.lexer import RegexLexer, include, bygroups, using, default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation @@ -78,11 +78,13 @@ class ModelicaLexer(RegexLexer): include('whitespace'), (r'(function|record)\b', Keyword.Reserved), (r'(if|for|when|while)\b', Keyword.Reserved, '#pop'), - (r'%s?' % _name, Name.Class, '#pop') + (_name, Name.Class, '#pop'), + default('#pop') ], 'package-prefix': [ include('whitespace'), - (r'%s?' % _name, Name.Namespace, '#pop') + (_name, Name.Namespace, '#pop'), + default('#pop') ], 'string': [ (r'"', String.Double, '#pop'), diff --git a/pygments/lexers/objective.py b/pygments/lexers/objective.py index 9287fae0..70f6819f 100644 --- a/pygments/lexers/objective.py +++ b/pygments/lexers/objective.py @@ -11,7 +11,8 @@ import re -from pygments.lexer import include, bygroups, using, this, words, inherit +from pygments.lexer import include, bygroups, using, this, words, inherit, \ + default from pygments.token import Text, Keyword, Name, String, Operator, \ Number, Punctuation, Literal @@ -136,7 +137,7 @@ def objective(baselexer): (r'[a-zA-Z$_][\w$]*:', Name.Function), (';', Punctuation, '#pop'), (r'\{', Punctuation, 'function'), - ('', Text, '#pop'), + default('#pop'), ], 'literal_number': [ (r'\(', Punctuation, 'literal_number_inner'), diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index b4acbbd1..0c156b20 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -9,7 +9,7 @@ :license: BSD, see LICENSE for details. """ -from pygments.lexer import RegexLexer, include, bygroups, words +from pygments.lexer import RegexLexer, include, bygroups, words, default from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Whitespace @@ -128,7 +128,9 @@ class RustLexer(RegexLexer): (r'[*/]', Comment.Multiline), ], 'number_lit': [ - (r'(([ui](8|16|32|64)?)|(f(32|64)?))?', Keyword, '#pop'), + (r'[ui](8|16|32|64)', Keyword, '#pop'), + (r'f(32|64)', Keyword, '#pop'), + default('#pop'), ], 'string': [ (r'"', String, '#pop'), diff --git a/pygments/lexers/testing.py b/pygments/lexers/testing.py index 2e769930..6007a846 100644 --- a/pygments/lexers/testing.py +++ b/pygments/lexers/testing.py @@ -9,12 +9,8 @@ :license: BSD, see LICENSE for details. """ -import re - -from pygments.lexer import RegexLexer, include, bygroups, using, \ - this, inherit, default, words -from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Error +from pygments.lexer import RegexLexer, include, bygroups +from pygments.token import Comment, Keyword, Name, String __all__ = ['GherkinLexer'] @@ -38,79 +34,79 @@ class GherkinLexer(RegexLexer): tokens = { 'comments': [ (r'^\s*#.*$', Comment), - ], - 'feature_elements' : [ + ], + 'feature_elements': [ (step_keywords, Keyword, "step_content_stack"), include('comments'), (r"(\s|.)", Name.Function), - ], - 'feature_elements_on_stack' : [ + ], + 'feature_elements_on_stack': [ (step_keywords, Keyword, "#pop:2"), include('comments'), (r"(\s|.)", Name.Function), - ], + ], 'examples_table': [ (r"\s+\|", Keyword, 'examples_table_header'), include('comments'), (r"(\s|.)", Name.Function), - ], + ], 'examples_table_header': [ (r"\s+\|\s*$", Keyword, "#pop:2"), include('comments'), (r"\\\|", Name.Variable), (r"\s*\|", Keyword), (r"[^\|]", Name.Variable), - ], + ], 'scenario_sections_on_stack': [ (feature_element_keywords, bygroups(Name.Function, Keyword, Keyword, Name.Function), "feature_elements_on_stack"), - ], + ], 'narrative': [ include('scenario_sections_on_stack'), include('comments'), (r"(\s|.)", Name.Function), - ], + ], 'table_vars': [ (r'(<[^>]+>)', Name.Variable), - ], + ], 'numbers': [ (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', String), - ], + ], 'string': [ include('table_vars'), (r'(\s|.)', String), - ], + ], 'py_string': [ (r'"""', Keyword, "#pop"), include('string'), - ], - 'step_content_root':[ + ], + 'step_content_root': [ (r"$", Keyword, "#pop"), include('step_content'), - ], - 'step_content_stack':[ + ], + 'step_content_stack': [ (r"$", Keyword, "#pop:2"), include('step_content'), - ], - 'step_content':[ + ], + 'step_content': [ (r'"', Name.Function, "double_string"), include('table_vars'), include('numbers'), include('comments'), (r'(\s|.)', Name.Function), - ], - 'table_content': [ + ], + 'table_content': [ (r"\s+\|\s*$", Keyword, "#pop"), include('comments'), (r"\\\|", String), (r"\s*\|", Keyword), include('string'), - ], + ], 'double_string': [ (r'"', Name.Function, "#pop"), include('string'), - ], + ], 'root': [ (r'\n', Name.Function), include('comments'), diff --git a/pygments/lexers/webmisc.py b/pygments/lexers/webmisc.py index 7b40b575..c52dcfd4 100644 --- a/pygments/lexers/webmisc.py +++ b/pygments/lexers/webmisc.py @@ -879,7 +879,7 @@ class SlimLexer(ExtendedRegexLexer): bygroups(Punctuation, using(RubyLexer)), 'root'), (r'[ \t]+[\w:-]+(?=[=])', Name.Attribute, 'html-attributes'), - (r'', Text, 'plain'), + default('plain'), ], 'content': [ |