diff options
author | orivej <[email protected]> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/tools/cython/Cython/Compiler/Scanning.py | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/Scanning.py')
-rw-r--r-- | contrib/tools/cython/Cython/Compiler/Scanning.py | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Scanning.py b/contrib/tools/cython/Cython/Compiler/Scanning.py index 78ad205d048..c721bba69b0 100644 --- a/contrib/tools/cython/Cython/Compiler/Scanning.py +++ b/contrib/tools/cython/Cython/Compiler/Scanning.py @@ -5,11 +5,11 @@ from __future__ import absolute_import -import cython -cython.declare(make_lexicon=object, lexicon=object, - print_function=object, error=object, warning=object, - os=object, platform=object) - +import cython +cython.declare(make_lexicon=object, lexicon=object, + print_function=object, error=object, warning=object, + os=object, platform=object) + import os import platform @@ -27,14 +27,14 @@ scanner_dump_file = None lexicon = None - + def get_lexicon(): global lexicon if not lexicon: lexicon = make_lexicon() return lexicon - + #------------------------------------------------------------------ py_reserved_words = [ @@ -50,22 +50,22 @@ pyx_reserved_words = py_reserved_words + [ "cimport", "DEF", "IF", "ELIF", "ELSE" ] - + class Method(object): - def __init__(self, name, **kwargs): + def __init__(self, name, **kwargs): self.name = name - self.kwargs = kwargs or None - self.__name__ = name # for Plex tracing + self.kwargs = kwargs or None + self.__name__ = name # for Plex tracing def __call__(self, stream, text): - method = getattr(stream, self.name) - # self.kwargs is almost always unused => avoid call overhead - return method(text, **self.kwargs) if self.kwargs is not None else method(text) + method = getattr(stream, self.name) + # self.kwargs is almost always unused => avoid call overhead + return method(text, **self.kwargs) if self.kwargs is not None else method(text) def __copy__(self): return self # immutable, no need to copy - + def __deepcopy__(self, memo): return self # immutable, no need to copy @@ -74,7 +74,7 @@ class Method(object): class CompileTimeScope(object): - def __init__(self, outer=None): + def __init__(self, outer=None): self.entries = {} self.outer = outer @@ -100,10 +100,10 @@ class CompileTimeScope(object): else: raise - + def initial_compile_time_env(): benv = CompileTimeScope() - names = ('UNAME_SYSNAME', 'UNAME_NODENAME', 'UNAME_RELEASE', 'UNAME_VERSION', 'UNAME_MACHINE') + names = ('UNAME_SYSNAME', 'UNAME_NODENAME', 'UNAME_RELEASE', 'UNAME_VERSION', 'UNAME_MACHINE') for name, value in zip(names, platform.uname()): benv.declare(name, value) try: @@ -111,17 +111,17 @@ def initial_compile_time_env(): except ImportError: import builtins - names = ( - 'False', 'True', - 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', - 'chr', 'cmp', 'complex', 'dict', 'divmod', 'enumerate', 'filter', - 'float', 'format', 'frozenset', 'hash', 'hex', 'int', 'len', - 'list', 'map', 'max', 'min', 'oct', 'ord', 'pow', 'range', - 'repr', 'reversed', 'round', 'set', 'slice', 'sorted', 'str', - 'sum', 'tuple', 'zip', - ### defined below in a platform independent way - # 'long', 'unicode', 'reduce', 'xrange' - ) + names = ( + 'False', 'True', + 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', + 'chr', 'cmp', 'complex', 'dict', 'divmod', 'enumerate', 'filter', + 'float', 'format', 'frozenset', 'hash', 'hex', 'int', 'len', + 'list', 'map', 'max', 'min', 'oct', 'ord', 'pow', 'range', + 'repr', 'reversed', 'round', 'set', 'slice', 'sorted', 'str', + 'sum', 'tuple', 'zip', + ### defined below in a platform independent way + # 'long', 'unicode', 'reduce', 'xrange' + ) for name in names: try: @@ -129,26 +129,26 @@ def initial_compile_time_env(): except AttributeError: # ignore, likely Py3 pass - - # Py2/3 adaptations - from functools import reduce - benv.declare('reduce', reduce) - benv.declare('unicode', getattr(builtins, 'unicode', getattr(builtins, 'str'))) - benv.declare('long', getattr(builtins, 'long', getattr(builtins, 'int'))) - benv.declare('xrange', getattr(builtins, 'xrange', getattr(builtins, 'range'))) - + + # Py2/3 adaptations + from functools import reduce + benv.declare('reduce', reduce) + benv.declare('unicode', getattr(builtins, 'unicode', getattr(builtins, 'str'))) + benv.declare('long', getattr(builtins, 'long', getattr(builtins, 'int'))) + benv.declare('xrange', getattr(builtins, 'xrange', getattr(builtins, 'range'))) + denv = CompileTimeScope(benv) return denv - + #------------------------------------------------------------------ class SourceDescriptor(object): """ A SourceDescriptor should be considered immutable. """ - filename = None - + filename = None + _file_type = 'pyx' _escaped_description = None @@ -168,11 +168,11 @@ class SourceDescriptor(object): def get_escaped_description(self): if self._escaped_description is None: - esc_desc = \ + esc_desc = \ self.get_description().encode('ASCII', 'replace').decode("ASCII") # Use forward slashes on Windows since these paths - # will be used in the #line directives in the C/C++ files. - self._escaped_description = esc_desc.replace('\\', '/') + # will be used in the #line directives in the C/C++ files. + self._escaped_description = esc_desc.replace('\\', '/') return self._escaped_description def __gt__(self, other): @@ -198,7 +198,7 @@ class SourceDescriptor(object): def __copy__(self): return self # immutable, no need to copy - + def __deepcopy__(self, memo): return self # immutable, no need to copy @@ -232,10 +232,10 @@ class FileSourceDescriptor(SourceDescriptor): return lines except KeyError: pass - - with Utils.open_source_file(self.filename, encoding=encoding, error_handling=error_handling) as f: + + with Utils.open_source_file(self.filename, encoding=encoding, error_handling=error_handling) as f: lines = list(f) - + if key in self._lines: self._lines[key] = lines else: @@ -272,7 +272,7 @@ class FileSourceDescriptor(SourceDescriptor): def __repr__(self): return "<FileSourceDescriptor:%s>" % self.filename - + class StringSourceDescriptor(SourceDescriptor): """ Instances of this class can be used instead of a filenames if the @@ -288,8 +288,8 @@ class StringSourceDescriptor(SourceDescriptor): if not encoding: return self.codelines else: - return [line.encode(encoding, error_handling).decode(encoding) - for line in self.codelines] + return [line.encode(encoding, error_handling).decode(encoding) + for line in self.codelines] def get_description(self): return self.name @@ -311,7 +311,7 @@ class StringSourceDescriptor(SourceDescriptor): def __repr__(self): return "<StringSourceDescriptor:%s>" % self.name - + #------------------------------------------------------------------ class PyrexScanner(Scanner): @@ -321,8 +321,8 @@ class PyrexScanner(Scanner): # compile_time_eval boolean In a true conditional compilation context # compile_time_expr boolean In a compile-time expression context - def __init__(self, file, filename, parent_scanner=None, - scope=None, context=None, source_encoding=None, parse_comments=True, initial_pos=None): + def __init__(self, file, filename, parent_scanner=None, + scope=None, context=None, source_encoding=None, parse_comments=True, initial_pos=None): Scanner.__init__(self, get_lexicon(), file, filename, initial_pos) if filename.is_python_file(): @@ -349,7 +349,7 @@ class PyrexScanner(Scanner): self.compile_time_env = initial_compile_time_env() self.compile_time_eval = 1 self.compile_time_expr = 0 - if getattr(context.options, 'compile_time_env', None): + if getattr(context.options, 'compile_time_env', None): self.compile_time_env.update(context.options.compile_time_env) self.parse_comments = parse_comments self.source_encoding = source_encoding @@ -366,18 +366,18 @@ class PyrexScanner(Scanner): if self.parse_comments: self.produce('commentline', text) - def strip_underscores(self, text, symbol): - self.produce(symbol, text.replace('_', '')) - + def strip_underscores(self, text, symbol): + self.produce(symbol, text.replace('_', '')) + def current_level(self): return self.indentation_stack[-1] def open_bracket_action(self, text): - self.bracket_nesting_level += 1 + self.bracket_nesting_level += 1 return text def close_bracket_action(self, text): - self.bracket_nesting_level -= 1 + self.bracket_nesting_level -= 1 return text def newline_action(self, text): @@ -453,7 +453,7 @@ class PyrexScanner(Scanner): sy, systring = self.read() except UnrecognizedInput: self.error("Unrecognized character") - return # just a marker, error() always raises + return # just a marker, error() always raises if sy == IDENT: if systring in self.keywords: if systring == u'print' and print_function in self.context.future_directives: @@ -462,7 +462,7 @@ class PyrexScanner(Scanner): self.keywords.discard('exec') else: sy = systring - systring = self.context.intern_ustring(systring) + systring = self.context.intern_ustring(systring) self.sy = sy self.systring = systring if False: # debug_scanner: @@ -490,27 +490,27 @@ class PyrexScanner(Scanner): # This method should be added to Plex self.queue.insert(0, (token, value)) - def error(self, message, pos=None, fatal=True): + def error(self, message, pos=None, fatal=True): if pos is None: pos = self.position() if self.sy == 'INDENT': - error(pos, "Possible inconsistent indentation") + error(pos, "Possible inconsistent indentation") err = error(pos, message) if fatal: raise err - def expect(self, what, message=None): + def expect(self, what, message=None): if self.sy == what: self.next() else: self.expected(what, message) - def expect_keyword(self, what, message=None): + def expect_keyword(self, what, message=None): if self.sy == IDENT and self.systring == what: self.next() else: self.expected(what, message) - def expected(self, what, message=None): + def expected(self, what, message=None): if message: self.error(message) else: @@ -521,10 +521,10 @@ class PyrexScanner(Scanner): self.error("Expected '%s', found '%s'" % (what, found)) def expect_indent(self): - self.expect('INDENT', "Expected an increase in indentation level") + self.expect('INDENT', "Expected an increase in indentation level") def expect_dedent(self): - self.expect('DEDENT', "Expected a decrease in indentation level") + self.expect('DEDENT', "Expected a decrease in indentation level") def expect_newline(self, message="Expected a newline", ignore_semicolon=False): # Expect either a newline or end of file @@ -536,18 +536,18 @@ class PyrexScanner(Scanner): self.expect('NEWLINE', message) if useless_trailing_semicolon is not None: warning(useless_trailing_semicolon, "useless trailing semicolon") - - def enter_async(self): - self.async_enabled += 1 - if self.async_enabled == 1: - self.keywords.add('async') - self.keywords.add('await') - - def exit_async(self): - assert self.async_enabled > 0 - self.async_enabled -= 1 - if not self.async_enabled: - self.keywords.discard('await') - self.keywords.discard('async') - if self.sy in ('async', 'await'): - self.sy, self.systring = IDENT, self.context.intern_ustring(self.sy) + + def enter_async(self): + self.async_enabled += 1 + if self.async_enabled == 1: + self.keywords.add('async') + self.keywords.add('await') + + def exit_async(self): + assert self.async_enabled > 0 + self.async_enabled -= 1 + if not self.async_enabled: + self.keywords.discard('await') + self.keywords.discard('async') + if self.sy in ('async', 'await'): + self.sy, self.systring = IDENT, self.context.intern_ustring(self.sy) |