--- a/eric6/ThirdParty/Pygments/pygments/lexer.py Tue Apr 21 19:44:19 2020 +0200 +++ b/eric6/ThirdParty/Pygments/pygments/lexer.py Tue Apr 21 19:47:10 2020 +0200 @@ -5,12 +5,10 @@ Base lexer classes. - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import print_function - import re import sys import time @@ -19,7 +17,7 @@ from pygments.filters import get_filter_by_name from pygments.token import Error, Text, Other, _TokenType from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ - make_analysator, text_type, add_metaclass, iteritems, Future, guess_decode + make_analysator, Future, guess_decode from pygments.regexopt import regex_opt __all__ = ['Lexer', 'RegexLexer', 'ExtendedRegexLexer', 'DelegatingLexer', @@ -48,8 +46,7 @@ return type.__new__(mcs, name, bases, d) -@add_metaclass(LexerMeta) -class Lexer(object): +class Lexer(metaclass=LexerMeta): """ Lexer for a specific language. @@ -145,7 +142,7 @@ Also preprocess the text, i.e. expand tabs and strip it if wanted and applies registered filters. """ - if not isinstance(text, text_type): + if not isinstance(text, str): if self.encoding == 'guess': text, _ = guess_decode(text) elif self.encoding == 'chardet': @@ -252,7 +249,7 @@ pass -class _inherit(object): +class _inherit: """ Indicates the a state should inherit from its superclass. """ @@ -275,7 +272,7 @@ pass -class _PseudoMatch(object): +class _PseudoMatch: """ A pseudo match object constructed from a string. """ @@ -328,11 +325,12 @@ return callback -class _This(object): +class _This: """ Special singleton used for indicating the caller class. Used by ``using``. """ + this = _This() @@ -536,7 +534,7 @@ for c in cls.__mro__: toks = c.__dict__.get('tokens', {}) - for state, items in iteritems(toks): + for state, items in toks.items(): curitems = tokens.get(state) if curitems is None: # N.b. because this is assigned by reference, sufficiently @@ -582,8 +580,7 @@ return type.__call__(cls, *args, **kwds) -@add_metaclass(RegexLexerMeta) -class RegexLexer(Lexer): +class RegexLexer(Lexer, metaclass=RegexLexerMeta): """ Base for simple stateful regular expression-based lexers. Simplifies the lexing process so that you need only @@ -639,14 +636,20 @@ if isinstance(new_state, tuple): for state in new_state: if state == '#pop': - statestack.pop() + if len(statestack) > 1: + statestack.pop() elif state == '#push': statestack.append(statestack[-1]) else: statestack.append(state) elif isinstance(new_state, int): - # pop - del statestack[new_state:] + # pop, but keep at least one state on the stack + # (random code leading to unexpected pops should + # not allow exceptions) + if abs(new_state) >= len(statestack): + del statestack[1:] + else: + del statestack[new_state:] elif new_state == '#push': statestack.append(statestack[-1]) else: @@ -670,7 +673,7 @@ break -class LexerContext(object): +class LexerContext: """ A helper object that holds lexer position data. """ @@ -724,14 +727,18 @@ if isinstance(new_state, tuple): for state in new_state: if state == '#pop': - ctx.stack.pop() + if len(ctx.stack) > 1: + ctx.stack.pop() elif state == '#push': ctx.stack.append(ctx.stack[-1]) else: ctx.stack.append(state) elif isinstance(new_state, int): - # pop - del ctx.stack[new_state:] + # see RegexLexer for why this check is made + if abs(new_state) >= len(ctx.stack): + del ctx.state[1:] + else: + del ctx.stack[new_state:] elif new_state == '#push': ctx.stack.append(ctx.stack[-1]) else: @@ -840,8 +847,7 @@ return match_func -@add_metaclass(ProfilingRegexLexerMeta) -class ProfilingRegexLexer(RegexLexer): +class ProfilingRegexLexer(RegexLexer, metaclass=ProfilingRegexLexerMeta): """Drop-in replacement for RegexLexer that does profiling of its regexes.""" _prof_data = []