FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

"""Extracting and changing portions of the current line All functions take cursor offset from the beginning of the line and the line of Python code, and return None, or a tuple of the start index, end index, and the word.""" import re from dataclasses import dataclass from itertools import chain from typing import Optional, Tuple from .lazyre import LazyReCompile @dataclass class LinePart: start: int stop: int word: str _current_word_re = LazyReCompile(r"(?.+))""" ) def current_string(cursor_offset: int, line: str) -> Optional[LinePart]: """If inside a string of nonzero length, return the string (excluding quotes) Weaker than bpython.Repl's current_string, because that checks that a string is a string based on previous lines in the buffer.""" for m in _current_string_re.finditer(line): i = 3 if m.group(3) else 4 if m.start(i) Optional[LinePart]: """If in attribute completion, the attribute being completed""" # TODO replace with more general current_expression_attribute match = current_word(cursor_offset, line) if match is None: return None matches = _current_object_attribute_re.finditer(match.word) next(matches) for m in matches: if m.start(1) + match.start Optional[LinePart]: """If after a dot, the attribute being completed""" # TODO replace with more general current_expression_attribute for m in _current_expression_attribute_re.finditer(line): if m.start(1) 0: prev_char = line[cursor_offset - 1] if ( on_closing_char and prev_char in CHARACTER_PAIR_MAP and CHARACTER_PAIR_MAP[prev_char] == cur_char ): pair_close = True if ch is None else prev_char == ch return on_closing_char, pair_close

Back | FazBrowse Home | New Git URL