diff options
author | Georg Brandl <georg@python.org> | 2020-09-06 11:55:52 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2020-09-06 11:55:52 +0200 |
commit | 603e8eddbf413deeb452ff110431da001e795438 (patch) | |
tree | 16c142fbcdd30defd672694611747d7da2f2f656 | |
parent | 3a2752177f37188fe995d262beb94a338dca612a (diff) | |
download | pygments-git-603e8eddbf413deeb452ff110431da001e795438.tar.gz |
all: fixup remaining regexlint warnings
46 files changed, 338 insertions, 333 deletions
diff --git a/pygments/lexers/arrow.py b/pygments/lexers/arrow.py index b1491c62..560d6de6 100644 --- a/pygments/lexers/arrow.py +++ b/pygments/lexers/arrow.py @@ -8,16 +8,18 @@ :copyright: Copyright 2020 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from pygments.lexer import RegexLexer, bygroups, include + +from pygments.lexer import RegexLexer, bygroups, default, include from pygments.token import Text, Operator, Keyword, Punctuation, Name, \ - Whitespace, String, Number + String, Number __all__ = ['ArrowLexer'] TYPES = r'\b(int|bool|char)((?:\[\])*)(?=\s+)' -IDENT = r'([a-zA-Z_][a-zA-Z0-9_]*)' +IDENT = r'([a-zA-Z_]\w*)' DECL = TYPES + r'(\s+)' + IDENT + class ArrowLexer(RegexLexer): """ Lexer for Arrow: https://pypi.org/project/py-arrow-lang/ @@ -38,9 +40,9 @@ class ArrowLexer(RegexLexer): include('expressions'), ], 'blocks': [ - (r'(function)(\n+)(/-->)(\s*)' - + DECL # 4 groups - + r'(\()', bygroups( + (r'(function)(\n+)(/-->)(\s*)' + + DECL + # 4 groups + r'(\()', bygroups( Keyword.Reserved, Text, Punctuation, Text, Keyword.Type, Punctuation, Text, Name.Function, Punctuation @@ -60,7 +62,7 @@ class ArrowLexer(RegexLexer): (r'true|false', Keyword.Constant), (r"'", String.Char, 'char'), (r'"', String.Double, 'string'), - (r'{', Punctuation, 'array'), + (r'\{', Punctuation, 'array'), (r'==|!=|<|>|\+|-|\*|/|%', Operator), (r'and|or|not|length', Operator.Word), (r'(input)(\s+)(int|char\[\])', bygroups( @@ -77,7 +79,7 @@ class ArrowLexer(RegexLexer): 'print': [ include('expressions'), (r',', Punctuation), - (r'', Text, '#pop'), + default('#pop'), ], 'fparams': [ (DECL, bygroups(Keyword.Type, Punctuation, Text, Name.Variable)), diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py index d94204b6..bdb48ce2 100644 --- a/pygments/lexers/asm.py +++ b/pygments/lexers/asm.py @@ -453,6 +453,7 @@ class LlvmLexer(RegexLexer): ] } + class LlvmMirBodyLexer(RegexLexer): """ For LLVM MIR examples without the YAML wrapper. @@ -471,19 +472,19 @@ class LlvmMirBodyLexer(RegexLexer): # Attributes on basic blocks (words(('liveins', 'successors'), suffix=':'), Keyword), # Basic Block Labels - (r'bb\.[0-9]+(\.[0-9a-zA-Z_.-]+)?( \(address-taken\))?:', Name.Label), - (r'bb\.[0-9]+ \(%[0-9a-zA-Z_.-]+\)( \(address-taken\))?:', Name.Label), + (r'bb\.[0-9]+(\.[\w.-]+)?( \(address-taken\))?:', Name.Label), + (r'bb\.[0-9]+ \(%[\w.-]+\)( \(address-taken\))?:', Name.Label), (r'%bb\.[0-9]+(\.\w+)?', Name.Label), # Stack references (r'%stack\.[0-9]+(\.\w+\.addr)?', Name), # Subreg indices (r'%subreg\.\w+', Name), # Virtual registers - (r'%[0-9a-zA-Z_]+ *', Name.Variable, 'vreg'), + (r'%\w+ *', Name.Variable, 'vreg'), # Reference to LLVM-IR global include('global'), # Reference to Intrinsic - (r'intrinsic\(\@[0-9a-zA-Z_.]+\)', Name.Variable.Global), + (r'intrinsic\(\@[\w.]+\)', Name.Variable.Global), # Comparison predicates (words(('eq', 'ne', 'sgt', 'sge', 'slt', 'sle', 'ugt', 'uge', 'ult', 'ule'), prefix=r'intpred\(', suffix=r'\)'), Name.Builtin), @@ -493,7 +494,7 @@ class LlvmMirBodyLexer(RegexLexer): # Physical registers (r'\$\w+', String.Single), # Assignment operator - (r'[=]', Operator), + (r'=', Operator), # gMIR Opcodes (r'(G_ANYEXT|G_[SZ]EXT|G_SEXT_INREG|G_TRUNC|G_IMPLICIT_DEF|G_PHI|' r'G_FRAME_INDEX|G_GLOBAL_VALUE|G_INTTOPTR|G_PTRTOINT|G_BITCAST|' @@ -526,7 +527,7 @@ class LlvmMirBodyLexer(RegexLexer): # Flags (words(('killed', 'implicit')), Keyword), # ConstantInt values - (r'[i][0-9]+ +', Keyword.Type, 'constantint'), + (r'i[0-9]+ +', Keyword.Type, 'constantint'), # ConstantFloat values (r'(half|float|double) +', Keyword.Type, 'constantfloat'), # Bare immediates @@ -536,7 +537,7 @@ class LlvmMirBodyLexer(RegexLexer): # MIR Comments (r';.*', Comment), # If we get here, assume it's a target instruction - (r'[0-9a-zA-Z_]+', Name), + (r'\w+', Name), # Everything else that isn't highlighted (r'[(), \n]+', Text), ], @@ -560,7 +561,7 @@ class LlvmMirBodyLexer(RegexLexer): 'vreg_bank_or_class': [ # The unassigned bank/class (r' *_', Name.Variable.Magic), - (r' *[0-9a-zA-Z_]+', Name.Variable), + (r' *\w+', Name.Variable), # The LLT if there is one (r' *\(', Text, 'vreg_type'), (r'(?=.)', Text, '#pop'), @@ -579,8 +580,8 @@ class LlvmMirBodyLexer(RegexLexer): 'acquire', 'release', 'acq_rel', 'seq_cst')), Keyword), # IR references - (r'%ir\.[0-9a-zA-Z_.-]+', Name), - (r'%ir-block\.[0-9a-zA-Z_.-]+', Name), + (r'%ir\.[\w.-]+', Name), + (r'%ir-block\.[\w.-]+', Name), (r'[-+]', Operator), include('integer'), include('global'), @@ -590,9 +591,10 @@ class LlvmMirBodyLexer(RegexLexer): ], 'integer': [(r'-?[0-9]+', Number.Integer),], 'float': [(r'-?[0-9]+\.[0-9]+(e[+-][0-9]+)?', Number.Float)], - 'global': [(r'\@[0-9a-zA-Z_.]+', Name.Variable.Global)], + 'global': [(r'\@[\w.]+', Name.Variable.Global)], } + class LlvmMirLexer(RegexLexer): """ Lexer for the overall LLVM MIR document format. @@ -649,9 +651,18 @@ class LlvmMirLexer(RegexLexer): (r'.+', Text), (r'\n', Text), ], - 'name': [ (r'[^\n]+', Name), default('#pop') ], - 'boolean': [ (r' *(true|false)', Name.Builtin), default('#pop') ], - 'number': [ (r' *[0-9]+', Number), default('#pop') ], + 'name': [ + (r'[^\n]+', Name), + default('#pop'), + ], + 'boolean': [ + (r' *(true|false)', Name.Builtin), + default('#pop'), + ], + 'number': [ + (r' *[0-9]+', Number), + default('#pop'), + ], 'llvm_mir_body': [ # Documents end with '...' or '---'. # We have to pop llvm_mir_body and llvm_mir @@ -660,7 +671,7 @@ class LlvmMirLexer(RegexLexer): (r'((?:.|\n)+?)(?=\.\.\.|---)', bygroups(using(LlvmMirBodyLexer))), # The '...' is optional. If we didn't already find it then it isn't # there. There might be a '---' instead though. - (r'(?!\.\.\.|---)((.|\n)+)', bygroups(using(LlvmMirBodyLexer), Keyword)), + (r'(?!\.\.\.|---)((?:.|\n)+)', bygroups(using(LlvmMirBodyLexer))), ], } @@ -924,7 +935,7 @@ class Dasm16Lexer(RegexLexer): ] # Regexes yo - char = r'[a-zA-Z$._0-9@]' + char = r'[\w$@.]' identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)' number = r'[+-]?(?:0[xX][a-zA-Z0-9]+|\d+)' binary_number = r'0b[01_]+' diff --git a/pygments/lexers/bare.py b/pygments/lexers/bare.py index 658e7895..8466361e 100644 --- a/pygments/lexers/bare.py +++ b/pygments/lexers/bare.py @@ -49,21 +49,25 @@ class BareLexer(RegexLexer): 'data', 'string', 'optional', - 'map' + 'map', ] tokens = { 'root': [ - (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+{)', bygroups(Keyword, Text, Name.Class, Text), 'struct'), - (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\()', bygroups(Keyword, Text, Name.Class, Text), 'union'), - (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)', bygroups(Keyword, Text, Name, Text), 'typedef'), - (r'(enum)(\s+)([A-Z][a-zA-Z0-9]+)(\s+{)', bygroups(Keyword, Text, Name.Class, Text), 'enum'), + (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\{)', + bygroups(Keyword, Text, Name.Class, Text), 'struct'), + (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\()', + bygroups(Keyword, Text, Name.Class, Text), 'union'), + (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)', + bygroups(Keyword, Text, Name, Text), 'typedef'), + (r'(enum)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\{)', + bygroups(Keyword, Text, Name.Class, Text), 'enum'), (r'#.*?$', Comment), (r'\s+', Text), ], 'struct': [ - (r'{', Text, '#push'), - (r'}', Text, '#pop'), + (r'\{', Text, '#push'), + (r'\}', Text, '#pop'), (r'([a-zA-Z0-9]+)(:\s*)', bygroups(Name.Attribute, Text), 'typedef'), (r'\s+', Text), ], @@ -85,13 +89,13 @@ class BareLexer(RegexLexer): (r'([A-Z][a-z-A-Z0-9]+)', Name.Class), (words(keywords), Keyword), (r'\n', Text, '#pop'), - (r'{', Text, 'struct'), + (r'\{', Text, 'struct'), (r'\s+', Text), (r'\d+', Literal), ], 'enum': [ - (r'{', Text, '#push'), - (r'}', Text, '#pop'), + (r'\{', Text, '#push'), + (r'\}', Text, '#pop'), (r'([A-Z][A-Z0-9_]*)(\s*=\s*)(\d+)', bygroups(Name.Attribute, Text, Literal)), (r'([A-Z][A-Z0-9_]*)', bygroups(Name.Attribute)), (r'#.*?$', Comment), diff --git a/pygments/lexers/basic.py b/pygments/lexers/basic.py index 22c6a660..a766a949 100644 --- a/pygments/lexers/basic.py +++ b/pygments/lexers/basic.py @@ -21,7 +21,6 @@ __all__ = ['BlitzBasicLexer', 'BlitzMaxLexer', 'MonkeyLexer', 'CbmBasicV2Lexer', 'QBasicLexer', 'VBScriptLexer', 'BBCBasicLexer'] - class BlitzMaxLexer(RegexLexer): """ For `BlitzMax <http://blitzbasic.com>`_ source code. @@ -526,19 +525,22 @@ class VBScriptLexer(RegexLexer): (r'[0-9]+e[+-]?[0-9]+', Number.Float), # Float variant 3, for example: 123e45 (r'\d+', Number.Integer), ('#.+#', String), # date or time value - (r'(dim)(\s+)([a-z_][a-z0-9_]*)', + (r'(dim)(\s+)([a-z_]\w*)', bygroups(Keyword.Declaration, Whitespace, Name.Variable), 'dim_more'), - (r'(function|sub)(\s+)([a-z_][a-z0-9_]*)', + (r'(function|sub)(\s+)([a-z_]\w*)', bygroups(Keyword.Declaration, Whitespace, Name.Function)), - (r'(class)(\s+)([a-z_][a-z0-9_]*)', bygroups(Keyword.Declaration, Whitespace, Name.Class)), - (r'(const)(\s+)([a-z_][a-z0-9_]*)', bygroups(Keyword.Declaration, Whitespace, Name.Constant)), - (r'(end)(\s+)(class|function|if|property|sub|with)', bygroups(Keyword, Whitespace, Keyword)), + (r'(class)(\s+)([a-z_]\w*)', + bygroups(Keyword.Declaration, Whitespace, Name.Class)), + (r'(const)(\s+)([a-z_]\w*)', + bygroups(Keyword.Declaration, Whitespace, Name.Constant)), + (r'(end)(\s+)(class|function|if|property|sub|with)', + bygroups(Keyword, Whitespace, Keyword)), (r'(on)(\s+)(error)(\s+)(goto)(\s+)(0)', bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword, Whitespace, Number.Integer)), (r'(on)(\s+)(error)(\s+)(resume)(\s+)(next)', bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword, Whitespace, Keyword)), (r'(option)(\s+)(explicit)', bygroups(Keyword, Whitespace, Keyword)), - (r'(property)(\s+)(get|let|set)(\s+)([a-z_][a-z0-9_]*)', + (r'(property)(\s+)(get|let|set)(\s+)([a-z_]\w*)', bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration, Whitespace, Name.Property)), (r'rem\s.*[^\n]*', Comment.Single), (words(_vbscript_builtins.KEYWORDS, suffix=r'\b'), Keyword), @@ -547,13 +549,14 @@ class VBScriptLexer(RegexLexer): (words(_vbscript_builtins.BUILTIN_CONSTANTS, suffix=r'\b'), Name.Constant), (words(_vbscript_builtins.BUILTIN_FUNCTIONS, suffix=r'\b'), Name.Builtin), (words(_vbscript_builtins.BUILTIN_VARIABLES, suffix=r'\b'), Name.Builtin), - (r'[a-z_][a-z0-9_]*', Name), + (r'[a-z_]\w*', Name), (r'\b_\n', Operator), (words(r'(),.:'), Punctuation), (r'.+(\n)?', Error) ], 'dim_more': [ - (r'(\s*)(,)(\s*)([a-z_][a-z0-9]*)', bygroups(Whitespace, Punctuation, Whitespace, Name.Variable)), + (r'(\s*)(,)(\s*)([a-z_][a-z0-9]*)', + bygroups(Whitespace, Punctuation, Whitespace, Name.Variable)), default('#pop'), ], 'string': [ @@ -609,7 +612,7 @@ class BBCBasicLexer(RegexLexer): (r"[0-9]+", Name.Label), (r"(\*)([^\n]*)", bygroups(Keyword.Pseudo, Comment.Special)), - (r"", Whitespace, 'code'), + default('code'), ], 'code': [ diff --git a/pygments/lexers/clean.py b/pygments/lexers/clean.py index a07c5432..e5b0cf19 100644 --- a/pygments/lexers/clean.py +++ b/pygments/lexers/clean.py @@ -9,7 +9,7 @@ :license: BSD, see LICENSE for details. """ -from pygments.lexer import ExtendedRegexLexer, words, include, bygroups +from pygments.lexer import ExtendedRegexLexer, words, default, include, bygroups from pygments.token import Comment, Error, Keyword, Literal, Name, Number, \ Operator, Punctuation, String, Whitespace @@ -35,12 +35,12 @@ class CleanLexer(ExtendedRegexLexer): modulewords = ('implementation', 'definition', 'system') - lowerId = r'[a-z`][\w\d`]*' - upperId = r'[A-Z`][\w\d`]*' - funnyId = r'[~@#\$%\^?!+\-*<>\\/|&=:]+' + lowerId = r'[a-z`][\w`]*' + upperId = r'[A-Z`][\w`]*' + funnyId = r'[~@#$%\^?!+\-*<>\\/|&=:]+' scoreUpperId = r'_' + upperId scoreLowerId = r'_' + lowerId - moduleId = r'[a-zA-Z_][a-zA-Z0-9_.`]+' + moduleId = r'[a-zA-Z_][\w.`]+' classId = '|'.join([lowerId, upperId, funnyId]) tokens = { @@ -92,7 +92,8 @@ class CleanLexer(ExtendedRegexLexer): (r'(\s*)\b(as)\b', bygroups(Whitespace, Keyword), ('#pop', 'import.module.as')), (moduleId, Name.Class), (r'(\s*)(,)(\s*)', bygroups(Whitespace, Punctuation, Whitespace)), - (r'\s*', Whitespace, '#pop'), + (r'\s+', Whitespace), + default('#pop'), ], 'import.module.as': [ include('whitespace'), @@ -160,7 +161,7 @@ class CleanLexer(ExtendedRegexLexer): (r'[$\n]', Error, '#pop'), ], 'operators': [ - (r'[-~@#\$%\^?!+*<>\\/|&=:\.]+', Operator), + (r'[-~@#$%\^?!+*<>\\/|&=:.]+', Operator), (r'\b_+\b', Operator), ], 'delimiters': [ diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 162ca73f..3d291d5c 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -319,7 +319,7 @@ class ApacheConfLexer(RegexLexer): r'os|productonly|full|emerg|alert|crit|error|warn|' r'notice|info|debug|registry|script|inetd|standalone|' r'user|group)\b', Keyword), - (r'"([^"\\]*(?:\\(.|[\n])[^"\\]*)*)"', String.Double), + (r'"([^"\\]*(?:\\(.|\n)[^"\\]*)*)"', String.Double), (r'[^\s"\\]+', Text) ], } @@ -953,7 +953,7 @@ class SingularityLexer(RegexLexer): filenames = ['*.def', 'Singularity'] flags = re.IGNORECASE | re.MULTILINE | re.DOTALL - _headers = r'^(\s)*(bootstrap|from|osversion|mirrorurl|include|registry|namespace|includecmd)(:)' + _headers = r'^(\s*)(bootstrap|from|osversion|mirrorurl|include|registry|namespace|includecmd)(:)' _section = r'^%(?:pre|post|setup|environment|help|labels|test|runscript|files|startscript)\b' _appsect = r'^%app(?:install|help|run|labels|env|test|files)\b' diff --git a/pygments/lexers/crystal.py b/pygments/lexers/crystal.py index ce56b7fb..fb3e01ac 100644 --- a/pygments/lexers/crystal.py +++ b/pygments/lexers/crystal.py @@ -135,7 +135,7 @@ class CrystalLexer(ExtendedRegexLexer): ('\\(', '\\)', '()', 'pa'), \ ('<', '>', '<>', 'ab'): states[name+'-intp-string'] = [ - (r'\\[' + lbrace + ']', String.Other), + (r'\\' + lbrace, String.Other), (lbrace, String.Other, '#push'), (rbrace, String.Other, '#pop'), include('string-intp-escaped'), diff --git a/pygments/lexers/csound.py b/pygments/lexers/csound.py index ac4e16ad..831f0f71 100644 --- a/pygments/lexers/csound.py +++ b/pygments/lexers/csound.py @@ -241,7 +241,7 @@ class CsoundOrchestraLexer(CsoundLexer): 'root': [ (r'\n', Text), - (r'^([ \t]*)(\w+)(:)(?:[ \t]+|$)', bygroups(Text, Name.Label, Punctuation)), + (r'^([ \t]*)(\w+)(:)([ \t]+|$)', bygroups(Text, Name.Label, Punctuation, Text)), include('whitespace and macro uses'), include('preprocessor directives'), @@ -347,7 +347,7 @@ class CsoundOrchestraLexer(CsoundLexer): # but accept %s specifiers. # See https://github.com/csound/csound/issues/747 for more information. 'format specifiers': [ - (r'%[#0\- +]*\d*(?:\.\d+)?[diuoxXfFeEgGaAcs]', String.Interpol), + (r'%[#0\- +]*\d*(?:\.\d+)?[AE-GXac-giosux]', String.Interpol), (r'%%', String.Escape) ], diff --git a/pygments/lexers/css.py b/pygments/lexers/css.py index a0b6c409..0bc7e159 100644 --- a/pygments/lexers/css.py +++ b/pygments/lexers/css.py @@ -358,7 +358,7 @@ class CssLexer(RegexLexer): (r'/\*(?:.|\n)*?\*/', Comment), include('numeric-values'), (r'[*+/-]', Operator), - (r'[,]', Punctuation), + (r',', Punctuation), (r'"(\\\\|\\"|[^"])*"', String.Double), (r"'(\\\\|\\'|[^'])*'", String.Single), (r'[a-zA-Z_-]\w*', Name), @@ -396,7 +396,7 @@ common_sass_tokens = { 'behind', 'below', 'bidi-override', 'blink', 'block', 'bold', 'bolder', 'both', 'capitalize', 'center-left', 'center-right', 'center', 'circle', 'cjk-ideographic', 'close-quote', 'collapse', 'condensed', 'continuous', - 'crop', 'crosshair', 'cross', 'cursive', 'dashed', 'decimal-leading-zero', + 'crosshair', 'cross', 'cursive', 'dashed', 'decimal-leading-zero', 'decimal', 'default', 'digits', 'disc', 'dotted', 'double', 'e-resize', 'embed', 'extra-condensed', 'extra-expanded', 'expanded', 'fantasy', 'far-left', 'far-right', 'faster', 'fast', 'fixed', 'georgian', 'groove', 'hebrew', 'help', diff --git a/pygments/lexers/devicetree.py b/pygments/lexers/devicetree.py index a5b915c6..0fc26de3 100644 --- a/pygments/lexers/devicetree.py +++ b/pygments/lexers/devicetree.py @@ -2,20 +2,20 @@ """ pygments.lexers.devicetree ~~~~~~~~~~~~~~~~~~~ - + Lexers for Devicetree language. :copyright: Copyright 2019-2020 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -import re - from pygments.lexer import RegexLexer, bygroups, include, default, words -from pygments.token import * +from pygments.token import Comment, Keyword, Name, Number, Operator, \ + Punctuation, String, Text __all__ = ['DevicetreeLexer'] + class DevicetreeLexer(RegexLexer): """ Lexer for `Devicetree <https://www.devicetree.org/>`_ files. @@ -32,21 +32,21 @@ class DevicetreeLexer(RegexLexer): _ws = r'\s*(?:/[*][^*/]*?[*]/\s*)*' tokens = { - 'macro': [ - # Include preprocessor directives (C style): - (r'(#include)(' + _ws + r')([^\n]+)', - bygroups(Comment.Preproc, Comment.Multiline, Comment.PreprocFile)), - # Define preprocessor directives (C style): - (r'(#define)(' + _ws + r')([^\n]+)', - bygroups(Comment.Preproc, Comment.Multiline, Comment.Preproc)), - #devicetree style with file: - (r'(/[^*/\{]+/)(' + _ws + r')("[^\n\{]+")', - bygroups(Comment.Preproc, Comment.Multiline, Comment.PreprocFile)), - #devicetree style with property: - (r'(/[^*/\{]+/)(' + _ws + r')([^\n;\{]*)([;]?)', - bygroups(Comment.Preproc, Comment.Multiline, Comment.Preproc, Punctuation)), + 'macro': [ + # Include preprocessor directives (C style): + (r'(#include)(' + _ws + r')([^\n]+)', + bygroups(Comment.Preproc, Comment.Multiline, Comment.PreprocFile)), + # Define preprocessor directives (C style): + (r'(#define)(' + _ws + r')([^\n]+)', + bygroups(Comment.Preproc, Comment.Multiline, Comment.Preproc)), + # devicetree style with file: + (r'(/[^*/{]+/)(' + _ws + r')("[^\n{]+")', + bygroups(Comment.Preproc, Comment.Multiline, Comment.PreprocFile)), + # devicetree style with property: + (r'(/[^*/{]+/)(' + _ws + r')([^\n;{]*)([;]?)', + bygroups(Comment.Preproc, Comment.Multiline, Comment.Preproc, Punctuation)), ], - 'whitespace': [ + 'whitespace': [ (r'\n', Text), (r'\s+', Text), (r'\\\n', Text), # line continuation @@ -59,28 +59,28 @@ class DevicetreeLexer(RegexLexer): (r'(L?)(")', bygroups(String.Affix, String), 'string'), (r'0x[0-9a-fA-F]+', Number.Hex), (r'\d+', Number.Integer), - (r'([^\n\s{}/*]*)(\s*)(:)', bygroups(Name.Label, Text, Punctuation)), - (words(('compatible', 'model', 'phandle', 'status', '#address-cells', - '#size-cells', 'reg', 'virtual-reg', 'ranges', 'dma-ranges', - 'device_type', 'name'), suffix=r'\b'), Keyword.Reserved), - (r'([~!%^&*+=|?:<>/#-])', Operator), + (r'([^\s{}/*]*)(\s*)(:)', bygroups(Name.Label, Text, Punctuation)), + (words(('compatible', 'model', 'phandle', 'status', '#address-cells', + '#size-cells', 'reg', 'virtual-reg', 'ranges', 'dma-ranges', + 'device_type', 'name'), suffix=r'\b'), Keyword.Reserved), + (r'([~!%^&*+=|?:<>/#-])', Operator), (r'[()\[\]{},.]', Punctuation), - (r'[a-zA-Z_][\w-]*(?=(?:\s*,\s*[a-zA-Z_][\w-]*|(?:' + _ws + r'))*\s*[=;])', Name), + (r'[a-zA-Z_][\w-]*(?=(?:\s*,\s*[a-zA-Z_][\w-]*|(?:' + _ws + r'))*\s*[=;])', + Name), (r'[a-zA-Z_]\w*', Name.Attribute), ], - 'root': [ - - include('whitespace'), - include('macro'), - - # Nodes - (r'([^/*@\n\s&]+|/)(@?)([0-9a-fA-F,]*)(' + _ws + r')(\{)', - bygroups( Name.Function, Operator, Number.Integer, + 'root': [ + include('whitespace'), + include('macro'), + + # Nodes + (r'([^/*@\s&]+|/)(@?)([0-9a-fA-F,]*)(' + _ws + r')(\{)', + bygroups(Name.Function, Operator, Number.Integer, Comment.Multiline, Punctuation), 'node'), - default('statement'), - ], - 'statement': [ + default('statement'), + ], + 'statement': [ include('whitespace'), include('statements'), (';', Punctuation, '#pop'), @@ -88,10 +88,10 @@ class DevicetreeLexer(RegexLexer): 'node': [ include('whitespace'), include('macro'), - - (r'([^/*@\n\s&]+|/)(@?)([0-9a-fA-F,]*)(' + _ws + r')(\{)', - bygroups(Name.Function, Operator, Number.Integer, - Comment.Multiline, Punctuation), '#push'), + + (r'([^/*@\s&]+|/)(@?)([0-9a-fA-F,]*)(' + _ws + r')(\{)', + bygroups(Name.Function, Operator, Number.Integer, + Comment.Multiline, Punctuation), '#push'), include('statements'), @@ -106,5 +106,4 @@ class DevicetreeLexer(RegexLexer): (r'\\\n', String), # line continuation (r'\\', String), # stray backslash ], - } diff --git a/pygments/lexers/dsls.py b/pygments/lexers/dsls.py index 54fa9aec..a6a5e3b4 100644 --- a/pygments/lexers/dsls.py +++ b/pygments/lexers/dsls.py @@ -14,7 +14,7 @@ import re from pygments.lexer import ExtendedRegexLexer, RegexLexer, bygroups, words, \ include, default, this, using, combined from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Literal, Whitespace + Number, Punctuation, Whitespace __all__ = ['ProtoBufLexer', 'ZeekLexer', 'PuppetLexer', 'RslLexer', 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer', @@ -332,7 +332,7 @@ class ZeekLexer(RegexLexer): 'string': [ (r'\\.', String.Escape), - (r'%-?[0-9]*(\.[0-9]+)?[DTdxsefg]', String.Escape), + (r'%-?[0-9]*(\.[0-9]+)?[DTd-gsx]', String.Escape), (r'"', String, '#pop'), (r'.', String), ], diff --git a/pygments/lexers/elm.py b/pygments/lexers/elm.py index aa4a688f..bb680d13 100644 --- a/pygments/lexers/elm.py +++ b/pygments/lexers/elm.py @@ -27,7 +27,7 @@ class ElmLexer(RegexLexer): filenames = ['*.elm'] mimetypes = ['text/x-elm'] - validName = r'[a-z_][a-zA-Z0-9_\']*' + validName = r'[a-z_][\w\']*' specialName = r'^main ' diff --git a/pygments/lexers/erlang.py b/pygments/lexers/erlang.py index 9d4c3d59..ae7da009 100644 --- a/pygments/lexers/erlang.py +++ b/pygments/lexers/erlang.py @@ -207,10 +207,10 @@ def gen_elixir_string_rules(name, symbol, token): return states -def gen_elixir_sigstr_rules(term, token, interpol=True): +def gen_elixir_sigstr_rules(term, term_class, token, interpol=True): if interpol: return [ - (r'[^#%s\\]+' % (term,), token), + (r'[^#%s\\]+' % (term_class,), token), include('escapes'), (r'\\.', token), (r'%s[a-zA-Z]*' % (term,), token, '#pop'), @@ -218,7 +218,7 @@ def gen_elixir_sigstr_rules(term, token, interpol=True): ] else: return [ - (r'[^%s\\]+' % (term,), token), + (r'[^%s\\]+' % (term_class,), token), (r'\\.', token), (r'%s[a-zA-Z]*' % (term,), token, '#pop'), ] @@ -291,14 +291,14 @@ class ElixirLexer(RegexLexer): def gen_elixir_sigil_rules(): # all valid sigil terminators (excluding heredocs) terminators = [ - (r'\{', r'\}', 'cb'), - (r'\[', r'\]', 'sb'), - (r'\(', r'\)', 'pa'), - (r'<', r'>', 'ab'), - (r'/', r'/', 'slas'), - (r'\|', r'\|', 'pipe'), - ('"', '"', 'quot'), - ("'", "'", 'apos'), + (r'\{', r'\}', '}', 'cb'), + (r'\[', r'\]', r'\]', 'sb'), + (r'\(', r'\)', ')', 'pa'), + ('<', '>', '>', 'ab'), + ('/', '/', '/', 'slas'), + (r'\|', r'\|', '|', 'pipe'), + ('"', '"', '"', 'quot'), + ("'", "'", "'", 'apos'), ] # heredocs have slightly different rules @@ -328,14 +328,15 @@ class ElixirLexer(RegexLexer): include('heredoc_no_interpol'), ] - for lterm, rterm, name in terminators: + for lterm, rterm, rterm_class, name in terminators: states['sigils'] += [ (r'~[a-z]' + lterm, token, name + '-intp'), (r'~[A-Z]' + lterm, token, name + '-no-intp'), ] - states[name + '-intp'] = gen_elixir_sigstr_rules(rterm, token) + states[name + '-intp'] = \ + gen_elixir_sigstr_rules(rterm, rterm_class, token) states[name + '-no-intp'] = \ - gen_elixir_sigstr_rules(rterm, token, interpol=False) + gen_elixir_sigstr_rules(rterm, rterm_class, token, interpol=False) return states diff --git a/pygments/lexers/forth.py b/pygments/lexers/forth.py index 0b91c19b..14834178 100644 --- a/pygments/lexers/forth.py +++ b/pygments/lexers/forth.py @@ -11,9 +11,8 @@ import re -from pygments.lexer import RegexLexer, include, bygroups -from pygments.token import Error, Punctuation, Literal, Token, \ - Text, Comment, Operator, Keyword, Name, String, Number, Generic +from pygments.lexer import RegexLexer, bygroups +from pygments.token import Text, Comment, Keyword, Name, String, Number __all__ = ['ForthLexer'] @@ -30,12 +29,6 @@ class ForthLexer(RegexLexer): filenames = ['*.frt', '*.fs'] mimetypes = ['application/x-forth'] - delimiter = r'\s' - delimiter_end = r'(?=[%s])' % delimiter - - valid_name_chars = r'[^%s]' % delimiter - valid_name = r"%s+%s" % (valid_name_chars, delimiter_end) - flags = re.IGNORECASE | re.MULTILINE tokens = { @@ -71,7 +64,7 @@ class ForthLexer(RegexLexer): r'then|type|u\.|u\<|um\*|um\/mod|unloop|until|' r'variable|while|word|xor|\[char\]|\[\'\]|' r'@|!|\#|<\#|\#>|:|;|\+|-|\*|\/|,|<|>|\|1\+|1-|\.|' - # *** Wordset CORE-EXT + # *** Wordset CORE-EXT r'\.r|0<>|' r'0>|2>r|2r>|2r@|:noname|\?do|again|c\"|' r'case|compile,|endcase|endof|erase|false|' @@ -79,38 +72,38 @@ class ForthLexer(RegexLexer): r'restore-input|roll|save-input|source-id|to|' r'true|tuck|u\.r|u>|unused|value|within|' r'\[compile\]|' - # *** Wordset CORE-EXT-obsolescent + # *** Wordset CORE-EXT-obsolescent r'\#tib|convert|expect|query|span|' r'tib|' - # *** Wordset DOUBLE + # *** Wordset DOUBLE r'2constant|2literal|2variable|d\+|d-|' r'd\.|d\.r|d0<|d0=|d2\*|d2\/|d<|d=|d>s|' r'dabs|dmax|dmin|dnegate|m\*\/|m\+|' - # *** Wordset DOUBLE-EXT + # *** Wordset DOUBLE-EXT r'2rot|du<|' - # *** Wordset EXCEPTION + # *** Wordset EXCEPTION r'catch|throw|' - # *** Wordset EXCEPTION-EXT + # *** Wordset EXCEPTION-EXT r'abort|abort\"|' - # *** Wordset FACILITY + # *** Wordset FACILITY r'at-xy|key\?|page|' - # *** Wordset FACILITY-EXT + # *** Wordset FACILITY-EXT r'ekey|ekey>char|ekey\?|emit\?|ms|time&date|' - # *** Wordset FILE + # *** Wordset FILE r'BIN|CLOSE-FILE|CREATE-FILE|DELETE-FILE|FILE-POSITION|' r'FILE-SIZE|INCLUDE-FILE|INCLUDED|OPEN-FILE|R\/O|' r'R\/W|READ-FILE|READ-LINE|REPOSITION-FILE|RESIZE-FILE|' r'S\"|SOURCE-ID|W/O|WRITE-FILE|WRITE-LINE|' - # *** Wordset FILE-EXT + # *** Wordset FILE-EXT r'FILE-STATUS|FLUSH-FILE|REFILL|RENAME-FILE|' - # *** Wordset FLOAT + # *** Wordset FLOAT r'>float|d>f|' r'f!|f\*|f\+|f-|f\/|f0<|f0=|f<|f>d|f@|' r'falign|faligned|fconstant|fdepth|fdrop|fdup|' r'fliteral|float\+|floats|floor|fmax|fmin|' r'fnegate|fover|frot|fround|fswap|fvariable|' r'represent|' - # *** Wordset FLOAT-EXT + # *** Wordset FLOAT-EXT r'df!|df@|dfalign|dfaligned|dfloat\+|' r'dfloats|f\*\*|f\.|fabs|facos|facosh|falog|' r'fasin|fasinh|fatan|fatan2|fatanh|fcos|fcosh|' @@ -118,34 +111,34 @@ class ForthLexer(RegexLexer): r'fsincos|fsinh|fsqrt|ftan|ftanh|f~|precision|' r'set-precision|sf!|sf@|sfalign|sfaligned|sfloat\+|' r'sfloats|' - # *** Wordset LOCAL + # *** Wordset LOCAL r'\(local\)|to|' - # *** Wordset LOCAL-EXT + # *** Wordset LOCAL-EXT r'locals\||' - # *** Wordset MEMORY + # *** Wordset MEMORY r'allocate|free|resize|' - # *** Wordset SEARCH + # *** Wordset SEARCH r'definitions|find|forth-wordlist|get-current|' r'get-order|search-wordlist|set-current|set-order|' r'wordlist|' - # *** Wordset SEARCH-EXT + # *** Wordset SEARCH-EXT r'also|forth|only|order|previous|' - # *** Wordset STRING + # *** Wordset STRING r'-trailing|\/string|blank|cmove|cmove>|compare|' r'search|sliteral|' - # *** Wordset TOOLS + # *** Wordset TOOLS r'.s|dump|see|words|' - # *** Wordset TOOLS-EXT + # *** Wordset TOOLS-EXT r';code|' r'ahead|assembler|bye|code|cs-pick|cs-roll|' r'editor|state|\[else\]|\[if\]|\[then\]|' - # *** Wordset TOOLS-EXT-obsolescent - r'forget|' - # Forth 2012 - r'defer|defer@|defer!|action-of|begin-structure|field:|buffer:|' - r'parse-name|buffer:|traverse-wordlist|n>r|nr>|2value|fvalue|' - r'name>interpret|name>compile|name>string|' - r'cfield:|end-structure)'+delimiter, Keyword), + # *** Wordset TOOLS-EXT-obsolescent + r'forget|' + # Forth 2012 + r'defer|defer@|defer!|action-of|begin-structure|field:|buffer:|' + r'parse-name|buffer:|traverse-wordlist|n>r|nr>|2value|fvalue|' + r'name>interpret|name>compile|name>string|' + r'cfield:|end-structure)(?!\S)', Keyword), # Numbers (r'(\$[0-9A-F]+)', Number.Hex), @@ -156,18 +149,18 @@ class ForthLexer(RegexLexer): r'itype|icompare|sp@|sp!|rp@|rp!|up@|up!|' r'>a|a>|a@|a!|a@+|a@-|>b|b>|b@|b!|b@+|b@-|' r'find-name|1ms|' - r'sp0|rp0|\(evaluate\)|int-trap|int!)' + delimiter, + r'sp0|rp0|\(evaluate\)|int-trap|int!)(?!\S)', Name.Constant), # a proposal (r'(do-recognizer|r:fail|recognizer:|get-recognizers|' r'set-recognizers|r:float|r>comp|r>int|r>post|' r'r:name|r:word|r:dnum|r:num|recognizer|forth-recognizer|' - r'rec:num|rec:float|rec:word)' + delimiter, Name.Decorator), + r'rec:num|rec:float|rec:word)(?!\S)', Name.Decorator), # defining words. The next word is a new command name (r'(Evalue|Rvalue|Uvalue|Edefer|Rdefer|Udefer)(\s+)', bygroups(Keyword.Namespace, Text), 'worddef'), - (valid_name, Name.Function), # Anything else is executed + (r'\S+', Name.Function), # Anything else is executed ], 'worddef': [ diff --git a/pygments/lexers/foxpro.py b/pygments/lexers/foxpro.py index f449ebcc..d6ccc62d 100644 --- a/pygments/lexers/foxpro.py +++ b/pygments/lexers/foxpro.py @@ -36,7 +36,7 @@ class FoxProLexer(RegexLexer): tokens = { 'root': [ - (r';\s*\n', Punctuation), # consume newline + (r';\s*\n', Punctuation), # consume newline (r'(^|\n)\s*', Text, 'newline'), # Square brackets may be used for array indices diff --git a/pygments/lexers/hdl.py b/pygments/lexers/hdl.py index e07a1ff2..a8a4fc6b 100644 --- a/pygments/lexers/hdl.py +++ b/pygments/lexers/hdl.py @@ -234,8 +234,8 @@ class SystemVerilogLexer(RegexLexer): bygroups(Keyword.Declaration, Text, Name.Class)), (r'(extends)(\s+)([a-zA-Z_]\w*)', bygroups(Keyword.Declaration, Text, Name.Class)), - (r'(endclass\b)((\s*)(:)(\s*)([a-zA-Z_]\w*))?', - bygroups(Keyword.Declaration, None, Text, Punctuation, Text, Name.Class)), + (r'(endclass\b)(?:(\s*)(:)(\s*)([a-zA-Z_]\w*))?', + bygroups(Keyword.Declaration, Text, Punctuation, Text, Name.Class)), (words(( # Variable types diff --git a/pygments/lexers/igor.py b/pygments/lexers/igor.py index c8d2869e..666d2b65 100644 --- a/pygments/lexers/igor.py +++ b/pygments/lexers/igor.py @@ -391,15 +391,10 @@ class IgorLexer(RegexLexer): 'WaveRefIndexedDFR', 'WaveRefsEqual', 'WaveRefWaveToList', 'WaveTextEncoding', 'WaveType', 'WaveUnits', 'WhichListItem', 'WinList', 'WinName', 'WinRecreation', 'WinType', 'wnoise', 'xcsr', 'XWaveName', 'XWaveRefFromTrace', 'x2pnt', 'zcsr', - 'ZernikeR', 'zeromq_client_connect', 'zeromq_client_connect', - 'zeromq_client_recv', 'zeromq_client_recv', 'zeromq_client_send', - 'zeromq_client_send', 'zeromq_handler_start', 'zeromq_handler_start', - 'zeromq_handler_stop', 'zeromq_handler_stop', 'zeromq_server_bind', - 'zeromq_server_bind', 'zeromq_server_recv', 'zeromq_server_recv', - 'zeromq_server_send', 'zeromq_server_send', 'zeromq_set', 'zeromq_set', - 'zeromq_stop', 'zeromq_stop', 'zeromq_test_callfunction', - 'zeromq_test_callfunction', 'zeromq_test_serializeWave', - 'zeromq_test_serializeWave', 'zeta' + 'ZernikeR', 'zeromq_client_connect', 'zeromq_client_recv', + 'zeromq_client_send', 'zeromq_handler_start', 'zeromq_handler_stop', + 'zeromq_server_bind', 'zeromq_server_recv', 'zeromq_server_send', 'zeromq_set', + 'zeromq_stop', 'zeromq_test_callfunction', 'zeromq_test_serializeWave', 'zeta' ) tokens = { diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 9428932c..335af320 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -263,7 +263,7 @@ class LiveScriptLexer(RegexLexer): default('#pop'), ], 'root': [ - (r'^(?=\s|/)', Text, 'slashstartsregex'), + (r'\A(?=\s|/)', Text, 'slashstartsregex'), include('commentsandwhitespace'), (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), @@ -1038,7 +1038,7 @@ class CoffeeScriptLexer(RegexLexer): _operator_re = ( r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' r'\|\||\\(?=\n)|' - r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?') + r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&|\^/])=?') flags = re.DOTALL tokens = { @@ -1066,7 +1066,7 @@ class CoffeeScriptLexer(RegexLexer): ], 'root': [ include('commentsandwhitespace'), - (r'^(?=\s|/)', Text, 'slashstartsregex'), + (r'\A(?=\s|/)', Text, 'slashstartsregex'), (_operator_re, Operator, 'slashstartsregex'), (r'(?:\([^()]*\))?\s*[=-]>', Name.Function, 'slashstartsregex'), (r'[{(\[;,]', Punctuation, 'slashstartsregex'), diff --git a/pygments/lexers/julia.py b/pygments/lexers/julia.py index 0ad103b5..0c1fadb5 100644 --- a/pygments/lexers/julia.py +++ b/pygments/lexers/julia.py @@ -145,7 +145,7 @@ class JuliaLexer(RegexLexer): # operators # see: https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm - (words([ + (words(( # prec-assignment u'=', u':=', u'+=', u'-=', u'*=', u'/=', u'//=', u'.//=', u'.*=', u'./=', u'\\=', u'.\\=', u'^=', u'.^=', u'÷=', u'.÷=', u'%=', u'.%=', u'|=', u'&=', @@ -169,7 +169,7 @@ class JuliaLexer(RegexLexer): # prec-colon u':', # prec-plus - u'+', u'-', u'.+', u'.-', u'|', u'∪', u'$', + u'.+', u'.-', u'|', u'∪', u'$', # prec-bitshift u'<<', u'>>', u'>>>', u'.<<', u'.>>', u'.>>>', # prec-times @@ -184,7 +184,7 @@ class JuliaLexer(RegexLexer): u'.', # unary op u'+', u'-', u'!', u'√', u'∛', u'∜' - ]), Operator), + )), Operator), # chars (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|" diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index 7d04da47..3bbe0c59 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -278,7 +278,7 @@ class ScalaLexer(RegexLexer): u'lazy|match|new|override|pr(?:ivate|otected)' u'|re(?:quires|turn)|s(?:ealed|uper)|' u't(?:h(?:is|row)|ry)|va[lr]|w(?:hile|ith)|yield)\\b|' - u'(<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\\b|(?=\\s)|$)', Keyword), + u'(<[%:-]|=>|>:|[#=@_\u21D2\u2190])\\b', Keyword), (u':(?!%s)' % op, Keyword, 'type'), (u'%s%s\\b' % (upper, idrest), Name.Class), (r'(true|false|null)\b', Keyword.Constant), @@ -331,7 +331,7 @@ class ScalaLexer(RegexLexer): (r'\s+', Text), include('comments'), (r',+', Punctuation), - (u'<[%:]|=>|>:|[#_\u21D2]|\bforSome\b|\btype\b', Keyword), + (r'<[%:]|=>|>:|[#_\u21D2]|\bforSome\b|\btype\b', Keyword), (r'([\])}])', Operator, '#pop'), (r'[(\[{]', Operator, '#push'), (u'\\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type) diff --git a/pygments/lexers/lisp.py b/pygments/lexers/lisp.py index 8113995b..074ae53a 100644 --- a/pygments/lexers/lisp.py +++ b/pygments/lexers/lisp.py @@ -382,7 +382,7 @@ class HyLexer(RegexLexer): # valid names for identifiers # well, names can only not consist fully of numbers # but this should be good enough for now - valid_name = r'(?!#)[\w!$%*+<=>?/.#-:]+' + valid_name = r'(?!#)[\w!$%*+<=>?/.#:-]+' def _multi_escape(entries): return words(entries, suffix=' ') diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index 6f7da3fc..5e6b6635 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -204,7 +204,7 @@ class RstLexer(RegexLexer): bygroups(Text, Operator, using(this, state='inline'))), # Sourcecode directives (r'^( *\.\.)(\s*)((?:source)?code(?:-block)?)(::)([ \t]*)([^\n]+)' - r'(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*|)\n)+)', + r'(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*)?\n)+)', _handle_sourcecode), # A directive (r'^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))', @@ -229,7 +229,7 @@ class RstLexer(RegexLexer): (r'^(\S.*(?<!::)\n)((?:(?: +.*)\n)+)', bygroups(using(this, state='inline'), using(this, state='inline'))), # Code blocks - (r'(::)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\3.*|)\n)+)', + (r'(::)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\3.*)?\n)+)', bygroups(String.Escape, Text, String, String, Text, String)), include('inline'), ], @@ -579,24 +579,27 @@ class MarkdownLexer(RegexLexer): # warning: the following rules eat outer tags. # eg. **foo _bar_ baz** => foo and baz are not recognized as bold # bold fenced by '**' - (r'(\*\*[^\*\n\ ][^\*\n]*\*\*)', bygroups(Generic.Strong)), + (r'(\*\*[^* \n][^*\n]*\*\*)', bygroups(Generic.Strong)), # # bold fenced by '__' - (r'(\_\_[^\_\n\ ][^\_\n]*\_\_)', bygroups(Generic.Strong)), + (r'(\_\_[^_ \n][^_\n]*\_\_)', bygroups(Generic.Strong)), # italics fenced by '*' - (r'(\*[^\*\n\ ][^\*\n]*\*)', bygroups(Generic.Emph)), + (r'(\*[^* \n][^*\n]*\*)', bygroups(Generic.Emph)), # italics fenced by '_' - (r'(\_[^\_\n\ ][^\_\n]*\_)', bygroups(Generic.Emph)), + (r'(\_[^_ \n][^_\n]*\_)', bygroups(Generic.Emph)), # strikethrough (r'([^~]*)(~~[^~]+~~)', bygroups(Text, Generic.Deleted)), # mentions and topics (twitter and github stuff) (r'[@#][\w/:]+', Name.Entity), # (image?) links eg:  - (r'(!?\[)([^]]+)(\])(\()([^)]+)(\))', bygroups(Text, Name.Tag, Text, Text, Name.Attribute, Text)), + (r'(!?\[)([^]]+)(\])(\()([^)]+)(\))', + bygroups(Text, Name.Tag, Text, Text, Name.Attribute, Text)), # reference-style links, e.g.: # [an example][id] # [id]: http://example.com/ - (r'(\[)([^]]+)(\])(\[)([^]]*)(\])', bygroups(Text, Name.Tag, Text, Text, Name.Label, Text)), - (r'^(\s*\[)([^]]*)(\]:\s*)(.+)', bygroups(Text, Name.Label, Text, Name.Attribute)), + (r'(\[)([^]]+)(\])(\[)([^]]*)(\])', + bygroups(Text, Name.Tag, Text, Text, Name.Label, Text)), + (r'^(\s*\[)([^]]*)(\]:\s*)(.+)', + bygroups(Text, Name.Label, Text, Name.Attribute)), # general text, must come last! (r'[^\\\s]+', Text), @@ -608,6 +611,7 @@ class MarkdownLexer(RegexLexer): self.handlecodeblocks = get_bool_opt(options, 'handlecodeblocks', True) RegexLexer.__init__(self, **options) + class TiddlyWiki5Lexer(RegexLexer): """ For `TiddlyWiki5 <https://tiddlywiki.com/#TiddlerFiles>`_ markup. @@ -627,15 +631,15 @@ class TiddlyWiki5Lexer(RegexLexer): from pygments.lexers import get_lexer_by_name # section header - yield match.start(1), String , match.group(1) - yield match.start(2), String , match.group(2) - yield match.start(3), Text , match.group(3) + yield match.start(1), String, match.group(1) + yield match.start(2), String, match.group(2) + yield match.start(3), Text, match.group(3) # lookup lexer if wanted and existing lexer = None if self.handlecodeblocks: try: - lexer = get_lexer_by_name( match.group(2).strip() ) + lexer = get_lexer_by_name(match.group(2).strip()) except ClassNotFound: pass code = match.group(4) @@ -648,7 +652,7 @@ class TiddlyWiki5Lexer(RegexLexer): for item in do_insertions([], lexer.get_tokens_unprocessed(code)): yield item - yield match.start(5), String , match.group(5) + yield match.start(5), String, match.group(5) def _handle_cssblock(self, match): """ @@ -657,13 +661,13 @@ class TiddlyWiki5Lexer(RegexLexer): from pygments.lexers import get_lexer_by_name # section header - yield match.start(1), String , match.group(1) - yield match.start(2), String , match.group(2) + yield match.start(1), String, match.group(1) + yield match.start(2), String, match.group(2) lexer = None if self.handlecodeblocks: try: - lexer = get_lexer_by_name( 'css' ) + lexer = get_lexer_by_name('css') except ClassNotFound: pass code = match.group(3) @@ -676,7 +680,7 @@ class TiddlyWiki5Lexer(RegexLexer): for item in do_insertions([], lexer.get_tokens_unprocessed(code)): yield item - yield match.start(4), String , match.group(4) + yield match.start(4), String, match.group(4) tokens = { 'root': [ @@ -688,7 +692,7 @@ class TiddlyWiki5Lexer(RegexLexer): # bulleted or numbered lists or single-line block quotes # (can be mixed) (r'^(\s*)([*#>]+)(\s*)(.+\n)', - bygroups(Text, Keyword, Text, using(this, state='inline'))), + bygroups(Text, Keyword, Text, using(this, state='inline'))), # multi-line block quotes (r'^(<<<.*\n)([\w\W]*?)(^<<<.*$)', bygroups(String, Text, String)), # table header @@ -722,7 +726,7 @@ class TiddlyWiki5Lexer(RegexLexer): (r'\d{17}', Number.Integer), # italics (r'(\s)(//[^/]+//)((?=\W|\n))', - bygroups(Text, Generic.Emph, Text)), + bygroups(Text, Generic.Emph, Text)), # superscript (r'(\s)(\^\^[^\^]+\^\^)', bygroups(Text, Generic.Emph)), # subscript @@ -731,13 +735,13 @@ class TiddlyWiki5Lexer(RegexLexer): (r'(\s)(__[^_]+__)', bygroups(Text, Generic.Strong)), # bold (r"(\s)(''[^']+'')((?=\W|\n))", - bygroups(Text, Generic.Strong, Text)), + bygroups(Text, Generic.Strong, Text)), # strikethrough (r'(\s)(~~[^~]+~~)((?=\W|\n))', - bygroups(Text, Generic.Deleted, Text)), + bygroups(Text, Generic.Deleted, Text)), # TiddlyWiki variables (r'<<[^>]+>>', Name.Tag), - (r'\$\$[^\$]+\$\$', Name.Tag), + (r'\$\$[^$]+\$\$', Name.Tag), (r'\$\([^)]+\)\$', Name.Tag), # TiddlyWiki style or class (r'^@@.*$', Name.Tag), diff --git a/pygments/lexers/matlab.py b/pygments/lexers/matlab.py index 73d2eb62..f1f3555a 100644 --- a/pygments/lexers/matlab.py +++ b/pygments/lexers/matlab.py @@ -11,7 +11,8 @@ import re -from pygments.lexer import Lexer, RegexLexer, bygroups, words, do_insertions +from pygments.lexer import Lexer, RegexLexer, bygroups, default, words, \ + do_insertions from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Generic, Whitespace @@ -72,7 +73,7 @@ class MatlabLexer(RegexLexer): "hilb", "invhilb", "magic", "pascal", "rosser", "toeplitz", "vander", "wilkinson") - _operators = r'-|==|~=|<=|>=|<|>|&&|&|~|\|\|?|\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\' + _operators = r'-|==|~=|<=|>=|<|>|&&|&|~|\|\|?|\.\*|\*|\+|\.\^|\.\\|\./|/|\\' tokens = { 'root': [ @@ -104,7 +105,7 @@ class MatlabLexer(RegexLexer): # is recognized if it is either surrounded by spaces or by no # spaces on both sides; only the former case matters for us. (This # allows distinguishing `cd ./foo` from `cd ./ foo`.) - (r'(?:^|(?<=;))(\s*)(\w+)(\s+)(?!=|\(|(%s)\s+)' % _operators, + (r'(?:^|(?<=;))(\s*)(\w+)(\s+)(?!=|\(|(?:%s)\s+)' % _operators, bygroups(Text, Name, Text), 'commandargs'), # operators: @@ -156,7 +157,8 @@ class MatlabLexer(RegexLexer): (r"[ \t]+", Text), ("'[^']*'", String), (r"[^';\s]+", String), - (";?", Punctuation, '#pop'), + (";", Punctuation, '#pop'), + default('#pop'), ] } diff --git a/pygments/lexers/ml.py b/pygments/lexers/ml.py index 156445f2..8ca8ce3e 100644 --- a/pygments/lexers/ml.py +++ b/pygments/lexers/ml.py @@ -767,6 +767,7 @@ class OpaLexer(RegexLexer): ], } + class ReasonLexer(RegexLexer): """ For the ReasonML language (https://reasonml.github.io/). @@ -780,18 +781,18 @@ class ReasonLexer(RegexLexer): mimetypes = ['text/x-reasonml'] keywords = ( - 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done', 'downto', - 'else', 'end', 'exception', 'external', 'false', 'for', 'fun', 'esfun', - 'function', 'functor', 'if', 'in', 'include', 'inherit', 'initializer', 'lazy', - 'let', 'switch', 'module', 'pub', 'mutable', 'new', 'nonrec', 'object', 'of', - 'open', 'pri', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try', - 'type', 'val', 'virtual', 'when', 'while', 'with' + 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done', 'downto', + 'else', 'end', 'exception', 'external', 'false', 'for', 'fun', 'esfun', + 'function', 'functor', 'if', 'in', 'include', 'inherit', 'initializer', 'lazy', + 'let', 'switch', 'module', 'pub', 'mutable', 'new', 'nonrec', 'object', 'of', + 'open', 'pri', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try', + 'type', 'val', 'virtual', 'when', 'while', 'with', ) keyopts = ( '!=', '#', '&', '&&', r'\(', r'\)', r'\*', r'\+', ',', '-', r'-\.', '=>', r'\.', r'\.\.', r'\.\.\.', ':', '::', ':=', ':>', ';', ';;', '<', '<-', '=', '>', '>]', r'>\}', r'\?', r'\?\?', r'\[', r'\[<', r'\[>', - r'\[\|', ']', '_', '`', r'\{', r'\{<', r'\|\|', r'\|', r'\|]', r'\}', '~' + r'\[\|', ']', '_', '`', r'\{', r'\{<', r'\|', r'\|\|', r'\|]', r'\}', '~' ) operators = r'[!$%&*+\./:<=>?@^|~-]' @@ -812,7 +813,7 @@ class ReasonLexer(RegexLexer): (r'\b([A-Z][\w\']*)(?=\s*\.)', Name.Namespace, 'dotted'), (r'\b([A-Z][\w\']*)', Name.Class), (r'//.*?\n', Comment.Single), - (r'\/\*(?![\/])', Comment.Multiline, 'comment'), + (r'\/\*(?!/)', Comment.Multiline, 'comment'), (r'\b(%s)\b' % '|'.join(keywords), Keyword), (r'(%s)' % '|'.join(keyopts[::-1]), Operator.Word), (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator), @@ -837,10 +838,10 @@ class ReasonLexer(RegexLexer): (r'[~?][a-z][\w\']*:', Name.Variable), ], 'comment': [ - (r'[^\/*]+', Comment.Multiline), + (r'[^/*]+', Comment.Multiline), (r'\/\*', Comment.Multiline, '#push'), (r'\*\/', Comment.Multiline, '#pop'), - (r'[\*]', Comment.Multiline), + (r'\*', Comment.Multiline), ], 'string': [ (r'[^\\"]+', String.Double), @@ -885,10 +886,10 @@ class FStarLexer(RegexLexer): assume_keywords = ('assume', 'admit', 'assert', 'calc') keyopts = ( r'~', r'-', r'/\\', r'\\/', r'<:', r'<@', r'\(\|', r'\|\)', r'#', r'u#', - r'&', r'\(\)', r'\(', r'\)', r',', r'~>', r'->', r'<--', r'<-', r'<==>', - r'==>', r'\.', r'\?\.', r'\?', r'\.\[', r'\.\(\|', r'\.\(', r'\.\[\|', - r'\{:pattern', r':', r'::', r':=', r';;', r';', r'=', r'%\[', r'!\{', - r'\[@', r'\[', r'\[\|', r'\|>', r'\]', r'\|\]', r'\{', r'\|', r'\}', r'\$' + r'&', r'\(', r'\)', r'\(\)', r',', r'~>', r'->', r'<-', r'<--', r'<==>', + r'==>', r'\.', r'\?', r'\?\.', r'\.\[', r'\.\(', r'\.\(\|', r'\.\[\|', + r'\{:pattern', r':', r'::', r':=', r';', r';;', r'=', r'%\[', r'!\{', + r'\[', r'\[@', r'\[\|', r'\|>', r'\]', r'\|\]', r'\{', r'\|', r'\}', r'\$' ) operators = r'[!$%&*+\./:<=>?@^|~-]' @@ -928,7 +929,7 @@ class FStarLexer(RegexLexer): String.Char), (r"'.'", String.Char), (r"'", Keyword), # a stray quote is another syntax element - (r"\`([\w\'\.]+)\`", Operator.Word), # for infix applications + (r"\`([\w\'.]+)\`", Operator.Word), # for infix applications (r"\`", Keyword), # for quoting (r'"', String.Double, 'string'), diff --git a/pygments/lexers/pony.py b/pygments/lexers/pony.py index 6fa11fdf..d13338b2 100644 --- a/pygments/lexers/pony.py +++ b/pygments/lexers/pony.py @@ -70,7 +70,7 @@ class PonyLexer(RegexLexer): (r'\d+', Number.Integer), (r'(true|false)\b', Name.Builtin), (r'_\d*', Name), - (r'_?[a-z][\w\'_]*', Name) + (r'_?[a-z][\w\']*', Name) ], 'typename': [ (_caps + r'?((?:\s)*)(_?[A-Z]\w*)', diff --git a/pygments/lexers/praat.py b/pygments/lexers/praat.py index ab67df4a..7799ec35 100644 --- a/pygments/lexers/praat.py +++ b/pygments/lexers/praat.py @@ -214,13 +214,13 @@ class PraatLexer(RegexLexer): (r'\b\d+(\.\d*)?([eE][-+]?\d+)?%?', Number), ], 'object_reference': [ - include('string_interpolated'), - (r'([a-z][a-zA-Z0-9_]*|\d+)', Name.Builtin), + include('string_interpolated'), + (r'([a-z]\w*|\d+)', Name.Builtin), - (words(object_attributes, prefix=r'\.'), Name.Builtin, '#pop'), + (words(object_attributes, prefix=r'\.'), Name.Builtin, '#pop'), - (r'\$', Name.Builtin), - (r'\[', Text, '#pop'), + (r'\$', Name.Builtin), + (r'\[', Text, '#pop'), ], 'variable_name': [ include('operator'), @@ -228,7 +228,7 @@ class PraatLexer(RegexLexer): (words(variables_string, suffix=r'\$'), Name.Variable.Global), (words(variables_numeric, - suffix=r'(?=[^a-zA-Z0-9\._"\'\$#\[:\(]|\s|^|$)'), + suffix=r'(?=[^\w."\'$#\[:(]|\s|^|$)'), Name.Variable.Global), (words(objects, prefix=r'\b', suffix=r"(_)"), @@ -245,7 +245,7 @@ class PraatLexer(RegexLexer): (r'(?<![\w.])(and|or|not|div|mod)(?![\w.])', Operator.Word), ], 'string_interpolated': [ - (r'\'[_a-z][^\[\]\'":]*(\[([\d,]+|"[\w\d,]+")\])?(:[0-9]+)?\'', + (r'\'[_a-z][^\[\]\'":]*(\[([\d,]+|"[\w,]+")\])?(:[0-9]+)?\'', String.Interpol), ], 'string_unquoted': [ diff --git a/pygments/lexers/prolog.py b/pygments/lexers/prolog.py index 40ef0df3..5baa916d 100644 --- a/pygments/lexers/prolog.py +++ b/pygments/lexers/prolog.py @@ -113,7 +113,7 @@ class LogtalkLexer(RegexLexer): (r'0x[0-9a-fA-F]+', Number.Hex), (r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number), # Variables - (r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable), + (r'([A-Z_]\w*)', Name.Variable), # Event handlers (r'(after|before)(?=[(])', Keyword), # Message forwarding handler @@ -231,7 +231,7 @@ class LogtalkLexer(RegexLexer): # Punctuation (r'[()\[\],.|]', Text), # Atoms - (r"[a-z][a-zA-Z0-9_]*", Text), + (r"[a-z]\w*", Text), (r"'", String, 'quoted_atom'), ], @@ -259,8 +259,8 @@ class LogtalkLexer(RegexLexer): (r'(alias|d(ynamic|iscontiguous)|m(eta_(non_terminal|predicate)|ode|ultifile)|s(et_(logtalk|prolog)_flag|ynchronized))(?=[(])', Keyword, 'root'), (r'op(?=[(])', Keyword, 'root'), (r'(c(alls|oinductive)|module|reexport|use(s|_module))(?=[(])', Keyword, 'root'), - (r'[a-z][a-zA-Z0-9_]*(?=[(])', Text, 'root'), - (r'[a-z][a-zA-Z0-9_]*(?=[.])', Text, 'root'), + (r'[a-z]\w*(?=[(])', Text, 'root'), + (r'[a-z]\w*(?=[.])', Text, 'root'), ], 'entityrelations': [ @@ -272,9 +272,9 @@ class LogtalkLexer(RegexLexer): (r'0x[0-9a-fA-F]+', Number.Hex), (r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number), # Variables - (r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable), + (r'([A-Z_]\w*)', Name.Variable), # Atoms - (r"[a-z][a-zA-Z0-9_]*", Text), + (r"[a-z]\w*", Text), (r"'", String, 'quoted_atom'), # Strings (r'"(\\\\|\\"|[^"])*"', String), diff --git a/pygments/lexers/promql.py b/pygments/lexers/promql.py index 6359fb09..7888e086 100644 --- a/pygments/lexers/promql.py +++ b/pygments/lexers/promql.py @@ -142,7 +142,7 @@ class PromQLLexer(RegexLexer): aggregator_keywords, function_keywords, # Offsets - (r"[1-9][0-9]*[s|m|h|d|w|y]", String), + (r"[1-9][0-9]*[smhdwy]", String), # Numbers (r"-?[0-9]+\.[0-9]+", Number.Float), (r"-?[0-9]+", Number.Integer), @@ -153,34 +153,28 @@ class PromQLLexer(RegexLexer): (r"==|!=|>=|<=|<|>", Operator), (r"and|or|unless", Operator.Word), # Metrics - (r"[_a-zA-Z][_a-zA-Z0-9]+", Name.Variable), + (r"[_a-zA-Z]\w+", Name.Variable), # Params (r'(["\'])(.*?)(["\'])', bygroups(Punctuation, String, Punctuation)), # Other states (r"\(", Operator, "function"), (r"\)", Operator), - (r"{", Punctuation, "labels"), + (r"\{", Punctuation, "labels"), (r"\[", Punctuation, "range"), ], "labels": [ - (r"}", Punctuation, "#pop"), + (r"\}", Punctuation, "#pop"), (r"\n", Whitespace), (r"\s+", Whitespace), (r",", Punctuation), - ( - r'([_a-zA-Z][_a-zA-Z0-9]*?)(\s*?)(=|!=|=~|~!)(\s*?)(")(.*?)(")', - bygroups( - Name.Label, - Whitespace, - Operator, - Whitespace, - Punctuation, - String, - Punctuation, - ), - ), + (r'([_a-zA-Z]\w*?)(\s*?)(=~|!=|=|~!)(\s*?)(")(.*?)(")', + bygroups(Name.Label, Whitespace, Operator, Whitespace, + Punctuation, String, Punctuation)), + ], + "range": [ + (r"\]", Punctuation, "#pop"), + (r"[1-9][0-9]*[smhdwy]", String), ], - "range": [(r"\]", Punctuation, "#pop"), (r"[1-9][0-9]*[s|m|h|d|w|y]", String)], "function": [ (r"\)", Operator, "#pop"), (r"\(", Operator, "#push"), diff --git a/pygments/lexers/python.py b/pygments/lexers/python.py index 7540489c..ba037eb3 100644 --- a/pygments/lexers/python.py +++ b/pygments/lexers/python.py @@ -172,19 +172,19 @@ class PythonLexer(RegexLexer): # without format specifier (r'(=\s*)?' # debug (https://bugs.python.org/issue36817) r'(\![sraf])?' # conversion - r'}', String.Interpol, '#pop'), + r'\}', String.Interpol, '#pop'), # with format specifier # we'll catch the remaining '}' in the outer scope (r'(=\s*)?' # debug (https://bugs.python.org/issue36817) r'(\![sraf])?' # conversion r':', String.Interpol, '#pop'), - (r'[^\S]+', Text), # allow new lines + (r'\s+', Text), # allow new lines include('expr'), ], 'expr-inside-fstring-inner': [ (r'[{([]', Punctuation, 'expr-inside-fstring-inner'), (r'[])}]', Punctuation, '#pop'), - (r'[^\S]+', Text), # allow new lines + (r'\s+', Text), # allow new lines include('expr'), ], 'expr-keywords': [ @@ -317,8 +317,8 @@ class PythonLexer(RegexLexer): default('#pop'), ], 'fstringescape': [ - ('{{', String.Escape), - ('}}', String.Escape), + (r'\{\{', String.Escape), + (r'\}\}', String.Escape), include('stringescape'), ], 'stringescape': [ diff --git a/pygments/lexers/r.py b/pygments/lexers/r.py index 305a75a9..276dd048 100644 --- a/pygments/lexers/r.py +++ b/pygments/lexers/r.py @@ -80,7 +80,7 @@ class SLexer(RegexLexer): mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r', 'text/x-R', 'text/x-r-history', 'text/x-r-profile'] - valid_name = r'`[^`\\]*(?:\\.[^`\\]*)*`|(?:[a-zA-Z]|\.[A-Za-z_.])[\w_.]*|\.' + valid_name = r'`[^`\\]*(?:\\.[^`\\]*)*`|(?:[a-zA-Z]|\.[A-Za-z_.])[\w.]*|\.' tokens = { 'comments': [ (r'#.*$', Comment.Single), diff --git a/pygments/lexers/ride.py b/pygments/lexers/ride.py index 490d1e07..4116cb8c 100644 --- a/pygments/lexers/ride.py +++ b/pygments/lexers/ride.py @@ -28,7 +28,7 @@ class RideLexer(RegexLexer): filenames = ['*.ride'] mimetypes = ['text/x-ride'] - validName = r'[a-zA-Z_][a-zA-Z0-9_\']*' + validName = r'[a-zA-Z_][\w\']*' builtinOps = ( '||', '|', '>=', '>', '==', '!', diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index dcac8d59..6a28a880 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -40,7 +40,7 @@ class RustLexer(RegexLexer): 'ExactSizeIterator', 'Option', 'Result', 'Box', 'ToOwned', 'String', 'ToString', 'Vec', 'Clone', 'Copy', 'Default', 'Eq', 'Hash', 'Ord', 'PartialEq', - 'PartialOrd', 'Eq', 'Ord', + 'PartialOrd', 'Ord', ), suffix=r'\b'), Name.Builtin) builtin_funcs_macros = (words(( diff --git a/pygments/lexers/scdoc.py b/pygments/lexers/scdoc.py index f5fb5a30..930060bd 100644 --- a/pygments/lexers/scdoc.py +++ b/pygments/lexers/scdoc.py @@ -59,7 +59,7 @@ class ScdocLexer(RegexLexer): # underlines (r'(\s)(_[^_]+_)(\W|\n)', bygroups(Text, Generic.Emph, Text)), # bold - (r'(\s)(\*[^\*]+\*)(\W|\n)', bygroups(Text, Generic.Strong, Text)), + (r'(\s)(\*[^*]+\*)(\W|\n)', bygroups(Text, Generic.Strong, Text)), # inline code (r'`[^`]+`', String.Backtick), diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py index dca5f3ed..ce6bf6d2 100644 --- a/pygments/lexers/shell.py +++ b/pygments/lexers/shell.py @@ -250,14 +250,14 @@ class BatchLexer(RegexLexer): _nl = r'\n\x1a' _punct = r'&<>|' _ws = r'\t\v\f\r ,;=\xa0' + _nlws = r'\s\x1a\xa0,;=' _space = r'(?:(?:(?:\^[%s])?[%s])+)' % (_nl, _ws) _keyword_terminator = (r'(?=(?:\^[%s]?)?[%s+./:[\\\]]|[%s%s(])' % (_nl, _ws, _nl, _punct)) _token_terminator = r'(?=\^?[%s]|[%s%s])' % (_ws, _punct, _nl) _start_label = r'((?:(?<=^[^:])|^[^:]?)[%s]*)(:)' % _ws - _label = r'(?:(?:[^%s%s%s+:^]|\^[%s]?[\w\W])*)' % (_nl, _punct, _ws, _nl) - _label_compound = (r'(?:(?:[^%s%s%s+:^)]|\^[%s]?[^)])*)' % - (_nl, _punct, _ws, _nl)) + _label = r'(?:(?:[^%s%s+:^]|\^[%s]?[\w\W])*)' % (_nlws, _punct, _nl) + _label_compound = r'(?:(?:[^%s%s+:^)]|\^[%s]?[^)])*)' % (_nlws, _punct, _nl) _number = r'(?:-?(?:0[0-7]+|0x[\da-f]+|\d+)%s)' % _token_terminator _opword = r'(?:equ|geq|gtr|leq|lss|neq)' _string = r'(?:"[^%s"]*(?:"|(?=[%s])))' % (_nl, _nl) @@ -267,9 +267,8 @@ class BatchLexer(RegexLexer): r'(?:\^?![^!:%s]+(?::(?:~(?:-?\d+)?(?:,(?:-?\d+)?)?|(?:' r'[^!%s^]|\^[^!%s])[^=%s]*=(?:[^!%s^]|\^[^!%s])*)?)?\^?!))' % (_nl, _nl, _nl, _nl, _nl, _nl, _nl, _nl, _nl, _nl, _nl, _nl)) - _core_token = r'(?:(?:(?:\^[%s]?)?[^"%s%s%s])+)' % (_nl, _nl, _punct, _ws) - _core_token_compound = r'(?:(?:(?:\^[%s]?)?[^"%s%s%s)])+)' % (_nl, _nl, - _punct, _ws) + _core_token = r'(?:(?:(?:\^[%s]?)?[^"%s%s])+)' % (_nl, _nlws, _punct) + _core_token_compound = r'(?:(?:(?:\^[%s]?)?[^"%s%s)])+)' % (_nl, _nlws, _punct) _token = r'(?:[%s]+|%s)' % (_punct, _core_token) _token_compound = r'(?:[%s]+|%s)' % (_punct, _core_token_compound) _stoken = (r'(?:[%s]+|(?:%s|%s|%s)+)' % @@ -380,7 +379,8 @@ class BatchLexer(RegexLexer): return state def _make_arithmetic_state(compound, _nl=_nl, _punct=_punct, - _string=_string, _variable=_variable, _ws=_ws): + _string=_string, _variable=_variable, + _ws=_ws, _nlws=_nlws): op = r'=+\-*/!~' state = [] if compound: @@ -391,8 +391,8 @@ class BatchLexer(RegexLexer): (r'\d+', Number.Integer), (r'[(),]+', Punctuation), (r'([%s]|%%|\^\^)+' % op, Operator), - (r'(%s|%s|(\^[%s]?)?[^()%s%%^"%s%s%s]|\^[%s%s]?%s)+' % - (_string, _variable, _nl, op, _nl, _punct, _ws, _nl, _ws, + (r'(%s|%s|(\^[%s]?)?[^()%s%%\^"%s%s]|\^[%s]?%s)+' % + (_string, _variable, _nl, op, _nlws, _punct, _nlws, r'[^)]' if compound else r'[\w\W]'), using(this, state='variable')), (r'(?=[\x00|&])', Text, '#pop'), @@ -426,15 +426,15 @@ class BatchLexer(RegexLexer): _core_token_compound=_core_token_compound, _nl=_nl, _punct=_punct, _stoken=_stoken, _string=_string, _space=_space, - _variable=_variable, _ws=_ws): + _variable=_variable, _nlws=_nlws): stoken_compound = (r'(?:[%s]+|(?:%s|%s|%s)+)' % (_punct, _string, _variable, _core_token_compound)) return [ - (r'((?:(?<=[%s%s])\d)?)(>>?&|<&)([%s%s]*)(\d)' % - (_nl, _ws, _nl, _ws), + (r'((?:(?<=[%s])\d)?)(>>?&|<&)([%s]*)(\d)' % + (_nlws, _nlws), bygroups(Number.Integer, Punctuation, Text, Number.Integer)), - (r'((?:(?<=[%s%s])(?<!\^[%s])\d)?)(>>?|<)(%s?%s)' % - (_nl, _ws, _nl, _space, stoken_compound if compound else _stoken), + (r'((?:(?<=[%s])(?<!\^[%s])\d)?)(>>?|<)(%s?%s)' % + (_nlws, _nl, _space, stoken_compound if compound else _stoken), bygroups(Number.Integer, Punctuation, using(this, state='text'))) ] @@ -473,7 +473,7 @@ class BatchLexer(RegexLexer): 'text': [ (r'"', String.Double, 'string'), include('variable-or-escape'), - (r'[^"%%^%s%s%s\d)]+|.' % (_nl, _punct, _ws), Text) + (r'[^"%%^%s%s\d)]+|.' % (_nlws, _punct), Text) ], 'variable': [ (r'"', String.Double, 'string'), @@ -494,13 +494,13 @@ class BatchLexer(RegexLexer): include('follow') ], 'for/f': [ - (r'(")((?:%s|[^"])*?")([%s%s]*)(\))' % (_variable, _nl, _ws), + (r'(")((?:%s|[^"])*?")([%s]*)(\))' % (_variable, _nlws), bygroups(String.Double, using(this, state='string'), Text, Punctuation)), (r'"', String.Double, ('#pop', 'for2', 'string')), - (r"('(?:%%%%|%s|[\w\W])*?')([%s%s]*)(\))" % (_variable, _nl, _ws), + (r"('(?:%%%%|%s|[\w\W])*?')([%s]*)(\))" % (_variable, _nlws), bygroups(using(this, state='sqstring'), Text, Punctuation)), - (r'(`(?:%%%%|%s|[\w\W])*?`)([%s%s]*)(\))' % (_variable, _nl, _ws), + (r'(`(?:%%%%|%s|[\w\W])*?`)([%s]*)(\))' % (_variable, _nlws), bygroups(using(this, state='bqstring'), Text, Punctuation)), include('for2') ], diff --git a/pygments/lexers/solidity.py b/pygments/lexers/solidity.py index 9f96a9cf..f47887d6 100644 --- a/pygments/lexers/solidity.py +++ b/pygments/lexers/solidity.py @@ -51,7 +51,7 @@ class SolidityLexer(RegexLexer): None, Name.Variable)), (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)', bygroups(Keyword.Type, Text.WhiteSpace, Name.Variable)), - (r'\b(msg|block|tx)\.([A-Za-z_][A-Za-z0-9_]*)\b', Keyword), + (r'\b(msg|block|tx)\.([A-Za-z_]\w*)\b', Keyword), (words(( 'block', 'break', 'constant', 'constructor', 'continue', 'contract', 'do', 'else', 'external', 'false', 'for', @@ -74,8 +74,8 @@ class SolidityLexer(RegexLexer): (r'/(\\\n)?[*][\w\W]*', Comment.Multiline) ], 'constants': [ - (r'("([\\]"|.)*?")', String.Double), - (r"('([\\]'|.)*?')", String.Single), + (r'("(\\"|.)*?")', String.Double), + (r"('(\\'|.)*?')", String.Single), (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex), (r'\b\d+\b', Number.Decimal), ], diff --git a/pygments/lexers/sql.py b/pygments/lexers/sql.py index e7030098..b3f6e678 100644 --- a/pygments/lexers/sql.py +++ b/pygments/lexers/sql.py @@ -516,7 +516,7 @@ class TransactSqlLexer(RegexLexer): tokens = { 'root': [ (r'\s+', Whitespace), - (r'(?m)--.*?$\n?', Comment.Single), + (r'--.*?$\n?', Comment.Single), (r'/\*', Comment.Multiline, 'multiline-comments'), (words(_tsql_builtins.OPERATORS), Operator), (words(_tsql_builtins.OPERATOR_WORDS, suffix=r'\b'), Operator.Word), diff --git a/pygments/lexers/stata.py b/pygments/lexers/stata.py index b8e3e59d..fbb5fdcf 100644 --- a/pygments/lexers/stata.py +++ b/pygments/lexers/stata.py @@ -10,7 +10,7 @@ """ import re -from pygments.lexer import RegexLexer, include, words +from pygments.lexer import RegexLexer, default, include, words from pygments.token import Comment, Keyword, Name, Number, \ String, Text, Operator @@ -118,27 +118,27 @@ class StataLexer(RegexLexer): # A global is more restricted, so we do follow rules. Note only # locals explicitly enclosed ${} can be nested. 'macros': [ - (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested'), + (r'\$(\{|(?=[$`]))', Name.Variable.Global, 'macro-global-nested'), (r'\$', Name.Variable.Global, 'macro-global-name'), (r'`', Name.Variable, 'macro-local'), ], 'macro-local': [ (r'`', Name.Variable, '#push'), (r"'", Name.Variable, '#pop'), - (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested'), + (r'\$(\{|(?=[$`]))', Name.Variable.Global, 'macro-global-nested'), (r'\$', Name.Variable.Global, 'macro-global-name'), (r'.', Name.Variable), # fallback ], 'macro-global-nested': [ - (r'\$(\{|(?=[\$`]))', Name.Variable.Global, '#push'), + (r'\$(\{|(?=[$`]))', Name.Variable.Global, '#push'), (r'\}', Name.Variable.Global, '#pop'), (r'\$', Name.Variable.Global, 'macro-global-name'), (r'`', Name.Variable, 'macro-local'), (r'\w', Name.Variable.Global), # fallback - (r'(?!\w)', Name.Variable.Global, '#pop'), + default('#pop'), ], 'macro-global-name': [ - (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested', '#pop'), + (r'\$(\{|(?=[$`]))', Name.Variable.Global, 'macro-global-nested', '#pop'), (r'\$', Name.Variable.Global, 'macro-global-name', '#pop'), (r'`', Name.Variable, 'macro-local', '#pop'), (r'\w{1,32}', Name.Variable.Global, '#pop'), diff --git a/pygments/lexers/teraterm.py b/pygments/lexers/teraterm.py index 0435538b..25288054 100644 --- a/pygments/lexers/teraterm.py +++ b/pygments/lexers/teraterm.py @@ -40,7 +40,7 @@ class TeraTermLexer(RegexLexer): include('numeric-literals'), include('string-literals'), include('all-whitespace'), - (r'[^\s]', Text), + (r'\S', Text), ], 'comments': [ (r';[^\r\n]*', Comment.Single), @@ -52,7 +52,7 @@ class TeraTermLexer(RegexLexer): (r'[*/]', Comment.Multiline) ], 'labels': [ - (r'(?i)^(\s*)(:[0-9a-z_]+)', bygroups(Text, Name.Label)), + (r'^(\s*)(:\w+)', bygroups(Text, Name.Label)), ], 'commands': [ ( @@ -259,10 +259,8 @@ class TeraTermLexer(RegexLexer): r')\b', Keyword, ), - ( - r'(?i)(call|goto)([ \t]+)([0-9a-z_]+)', - bygroups(Keyword, Text, Name.Label), - ) + (r'(?i)(call|goto)([ \t]+)(\w+)', + bygroups(Keyword, Text, Name.Label)), ], 'builtin-variables': [ ( @@ -297,7 +295,7 @@ class TeraTermLexer(RegexLexer): ), ], 'user-variables': [ - (r'(?i)[A-Z_][A-Z0-9_]*', Name.Variable), + (r'(?i)[A-Z_]\w*', Name.Variable), ], 'numeric-literals': [ (r'(-?)([0-9]+)', bygroups(Operator, Number.Integer)), @@ -309,7 +307,7 @@ class TeraTermLexer(RegexLexer): (r'"', String.Double, 'in-double-string'), ], 'in-general-string': [ - (r'[\\][\\nt]', String.Escape), # Only three escapes are supported. + (r'\\[\\nt]', String.Escape), # Only three escapes are supported. (r'.', String), ], 'in-single-string': [ @@ -326,7 +324,7 @@ class TeraTermLexer(RegexLexer): (r'[()]', String.Symbol), ], 'all-whitespace': [ - (r'[\s]+', Text), + (r'\s+', Text), ], } diff --git a/pygments/lexers/textfmts.py b/pygments/lexers/textfmts.py index 586b77b4..ada3ebbf 100644 --- a/pygments/lexers/textfmts.py +++ b/pygments/lexers/textfmts.py @@ -331,10 +331,10 @@ class NotmuchLexer(RegexLexer): tokens = { 'root': [ - (r'\fmessage{\s*', Keyword, ('message', 'message-attr')), + (r'\fmessage\{\s*', Keyword, ('message', 'message-attr')), ], 'message-attr': [ - (r'(\s*id:\s*)([^\s]+)', bygroups(Name.Attribute, String)), + (r'(\s*id:\s*)(\S+)', bygroups(Name.Attribute, String)), (r'(\s*(?:depth|match|excluded):\s*)(\d+)', bygroups(Name.Attribute, Number.Integer)), (r'(\s*filename:\s*)(.+\n)', @@ -342,21 +342,21 @@ class NotmuchLexer(RegexLexer): default('#pop'), ], 'message': [ - (r'\fmessage}\n', Keyword, '#pop'), - (r'\fheader{\n', Keyword, 'header'), - (r'\fbody{\n', Keyword, 'body'), + (r'\fmessage\}\n', Keyword, '#pop'), + (r'\fheader\{\n', Keyword, 'header'), + (r'\fbody\{\n', Keyword, 'body'), ], 'header': [ - (r'\fheader}\n', Keyword, '#pop'), + (r'\fheader\}\n', Keyword, '#pop'), (r'((?:Subject|From|To|Cc|Date):\s*)(.*\n)', bygroups(Name.Attribute, String)), (r'(.*)(\s*\(.*\))(\s*\(.*\)\n)', bygroups(Generic.Strong, Literal, Name.Tag)), ], 'body': [ - (r'\fpart{\n', Keyword, 'part'), - (r'\f(part|attachment){\s*', Keyword, ('part', 'part-attr')), - (r'\fbody}\n', Keyword, '#pop'), + (r'\fpart\{\n', Keyword, 'part'), + (r'\f(part|attachment)\{\s*', Keyword, ('part', 'part-attr')), + (r'\fbody\}\n', Keyword, '#pop'), ], 'part-attr': [ (r'(ID:\s*)(\d+)', bygroups(Name.Attribute, Number.Integer)), @@ -367,10 +367,10 @@ class NotmuchLexer(RegexLexer): default('#pop'), ], 'part': [ - (r'\f(?:part|attachment)}\n', Keyword, '#pop'), - (r'\f(?:part|attachment){\s*', Keyword, ('#push', 'part-attr')), + (r'\f(?:part|attachment)\}\n', Keyword, '#pop'), + (r'\f(?:part|attachment)\{\s*', Keyword, ('#push', 'part-attr')), (r'^Non-text part: .*\n', Comment), - (r'(?s)(.*?(?=\f(?:part|attachment)}\n))', _highlight_code), + (r'(?s)(.*?(?=\f(?:part|attachment)\}\n))', _highlight_code), ], } @@ -408,7 +408,7 @@ class KernelLogLexer(RegexLexer): default('info'), ], 'base': [ - (r'\[[0-9\. ]+\] ', Number), + (r'\[[0-9. ]+\] ', Number), (r'(?<=\] ).+?:', Keyword), (r'\n', Text, '#pop'), ], diff --git a/pygments/lexers/unicon.py b/pygments/lexers/unicon.py index 5260ac5f..c27b7fe0 100644 --- a/pygments/lexers/unicon.py +++ b/pygments/lexers/unicon.py @@ -129,17 +129,15 @@ class UniconLexer(RegexLexer): 'WSync'), prefix=r'\b', suffix=r'\b'), Name.Function), include('numbers'), - (r'<@|<<@|>@|>>@|\.>|\->', Operator), - (r'\*\*|\+\+|\-\-|\.|\=|\~\=|<\=|>\=|\=\=|\~\=\=|<<|<<\=|>>|>>\=', Operator), - (r':\=|:\=:|\->|<\->|\+:\=|\|', Operator), - (r'\=\=\=|\~\=\=\=', Operator), + (r'<@|<<@|>@|>>@|\.>|->|===|~===|\*\*|\+\+|--|\.|~==|~=|<=|>=|==|' + r'=|<<=|<<|>>=|>>|:=:|:=|->|<->|\+:=|\|', Operator), (r'"(?:[^\\"]|\\.)*"', String), (r"'(?:[^\\']|\\.)*'", String.Character), (r'[*<>+=/&!?@~\\-]', Operator), (r'\^', Operator), (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), - (r"([\[\]])", Punctuation), - (r"(<>|=>|[()|:;,.'`]|[{}]|[%]|[&?])", Punctuation), + (r"[\[\]]", Punctuation), + (r"<>|=>|[()|:;,.'`{}%&?]", Punctuation), (r'\n+', Text), ], 'numbers': [ @@ -272,15 +270,14 @@ class IconLexer(RegexLexer): 'WSync'), prefix=r'\b', suffix=r'\b'), Name.Function), include('numbers'), - (r'\*\*|\+\+|\-\-|\.|\=|\~\=|<\=|>\=|\=\=|\~\=\=|<<|<<\=|>>|>>\=', Operator), - (r':\=|:\=:|<\-|<\->|\+:\=|\||\|\|', Operator), - (r'\=\=\=|\~\=\=\=', Operator), + (r'===|~===|\*\*|\+\+|--|\.|==|~==|<=|>=|=|~=|<<=|<<|>>=|>>|' + r':=:|:=|<->|<-|\+:=|\|\||\|', Operator), (r'"(?:[^\\"]|\\.)*"', String), (r"'(?:[^\\']|\\.)*'", String.Character), (r'[*<>+=/&!?@~\\-]', Operator), (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), - (r"([\[\]])", Punctuation), - (r"(<>|=>|[()|:;,.'`]|[{}]|[%^]|[&?])", Punctuation), + (r"[\[\]]", Punctuation), + (r"<>|=>|[()|:;,.'`{}%\^&?]", Punctuation), (r'\n+', Text), ], 'numbers': [ diff --git a/pygments/lexers/usd.py b/pygments/lexers/usd.py index d94a7ca9..d9d3f448 100644 --- a/pygments/lexers/usd.py +++ b/pygments/lexers/usd.py @@ -24,7 +24,7 @@ def _keywords(words, type_): _TYPE = r"(\w+(?:\[\])?)" -_BASE_ATTRIBUTE = r"([\w_]+(?:\:[\w_]+)*)(?:(\.)(timeSamples))?" +_BASE_ATTRIBUTE = r"(\w+(?:\:\w+)*)(?:(\.)(timeSamples))?" _WHITESPACE = r"([ \t]+)" @@ -69,7 +69,7 @@ class UsdLexer(RegexLexer): [(type_ + r"\[\]", Keyword.Type) for type_ in TYPES] + _keywords(TYPES, Keyword.Type) + [ - (r"[\(\)\[\]{}]", Punctuation), + (r"[(){}\[\]]", Punctuation), ("#.*?$", Comment.Single), (",", Punctuation), (";", Punctuation), # ";"s are allowed to combine separate metadata lines @@ -84,7 +84,7 @@ class UsdLexer(RegexLexer): (r'\(.*"[.\\n]*".*\)', String.Doc), (r"\A#usda .+$", Comment.Hashbang), (r"\s+", Whitespace), - (r"[\w_]+", Text), - (r"[_:\.]+", Punctuation), + (r"\w+", Text), + (r"[_:.]+", Punctuation), ], } diff --git a/pygments/lexers/webidl.py b/pygments/lexers/webidl.py index 1cc162cf..df1f48ed 100644 --- a/pygments/lexers/webidl.py +++ b/pygments/lexers/webidl.py @@ -32,7 +32,7 @@ _builtin_types = ( # other 'any', 'void', 'object', 'RegExp', ) -_identifier = r'_?[A-Za-z][0-9A-Z_a-z-]*' +_identifier = r'_?[A-Za-z][\w-]*' _keyword_suffix = r'(?![\w-])' _string = r'"[^"]*"' @@ -132,7 +132,8 @@ class WebIDLLexer(RegexLexer): default(('#pop', 'type_null')) ], 'type_null': [ - (r'\??', Punctuation, '#pop:2'), + (r'\?', Punctuation), + default('#pop:2'), ], 'default_value': [ include('common'), diff --git a/pygments/lexers/xorg.py b/pygments/lexers/xorg.py index e2a67e26..8f605be4 100644 --- a/pygments/lexers/xorg.py +++ b/pygments/lexers/xorg.py @@ -29,7 +29,7 @@ class XorgLexer(RegexLexer): (r'((?:Sub)?Section)(\s+)("\w+")', bygroups(String.Escape, Text, String.Escape)), - (r'(End(|Sub)Section)', String.Escape), + (r'(End(?:Sub)?Section)', String.Escape), (r'(\w+)(\s+)([^\n#]+)', bygroups(Name.Builtin, Text, Name.Constant)), diff --git a/pygments/lexers/yang.py b/pygments/lexers/yang.py index b4cb1b7e..b484de64 100644 --- a/pygments/lexers/yang.py +++ b/pygments/lexers/yang.py @@ -59,7 +59,7 @@ class YangLexer(RegexLexer): "int8", "leafref", "string", "uint16", "uint32", "uint64", "uint8", "union") - suffix_re_pattern = r'(?=[^\w\-\:])' + suffix_re_pattern = r'(?=[^\w\-:])' tokens = { 'comments': [ @@ -70,7 +70,7 @@ class YangLexer(RegexLexer): ], "root": [ (r'\s+', Text.Whitespace), - (r'[\{\}\;]+', Token.Punctuation), + (r'[{};]+', Token.Punctuation), (r'(?<![\-\w])(and|or|not|\+|\.)(?![\-\w])', Token.Operator), (r'"(?:\\"|[^"])*?"', String.Double), @@ -84,9 +84,9 @@ class YangLexer(RegexLexer): bygroups(Name.Namespace, Token.Punctuation, Name.Variable)), #match BNF stmt `date-arg-str` - (r'([0-9]{4}\-[0-9]{2}\-[0-9]{2})(?=[\s\{\}\;])', Name.Label), - (r'([0-9]+\.[0-9]+)(?=[\s\{\}\;])', Number.Float), - (r'([0-9]+)(?=[\s\{\}\;])', Number.Integer), + (r'([0-9]{4}\-[0-9]{2}\-[0-9]{2})(?=[\s{};])', Name.Label), + (r'([0-9]+\.[0-9]+)(?=[\s{};])', Number.Float), + (r'([0-9]+)(?=[\s{};])', Number.Integer), (words(TOP_STMTS_KEYWORDS, suffix=suffix_re_pattern), Token.Keyword), (words(MODULE_HEADER_STMT_KEYWORDS, suffix=suffix_re_pattern), Token.Keyword), @@ -99,6 +99,6 @@ class YangLexer(RegexLexer): (words(TYPES, suffix=suffix_re_pattern), Name.Class), (words(CONSTANTS_KEYWORDS, suffix=suffix_re_pattern), Name.Class), - (r'[^;{}\s\'\"]+', Name.Variable), + (r'[^;{}\s\'"]+', Name.Variable), ] } diff --git a/pygments/lexers/zig.py b/pygments/lexers/zig.py index 2ed81087..e6ffa7b6 100644 --- a/pygments/lexers/zig.py +++ b/pygments/lexers/zig.py @@ -102,7 +102,7 @@ class ZigLexer(RegexLexer): # Characters (r'\'\\\'\'', String.Escape), - (r'\'\\(|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{6}|[nr\\t\'"])\'', + (r'\'\\(x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{6}|[nr\\t\'"])\'', String.Escape), (r'\'[^\\\']\'', String), diff --git a/tests/test_matlab.py b/tests/test_matlab.py index 0ac1df95..4a94f351 100644 --- a/tests/test_matlab.py +++ b/tests/test_matlab.py @@ -198,7 +198,6 @@ def test_command_mode(lexer): (Token.Name, 'help'), (Token.Text, ' '), (Token.Literal.String, 'sin'), - (Token.Punctuation, ''), (Token.Text, '\n'), ] assert list(lexer.get_tokens(fragment)) == tokens |