def resolve(self, view): # type: (...) -> Region # Return a representing the Vim line range that the ex command should # operate on. start = _resolve_line_reference(view, self.start or [TokenDot()]) if not self.separator: if start == -1: return Region(-1, -1) if len(self.start) == 1 and isinstance(self.start[0], TokenPercent): return Region(0, view.size()) return view.full_line(view.text_point(start, 0)) new_start = start if self.separator == ';' else 0 end = _resolve_line_reference(view, self.end or [TokenDot()], current=new_start) return view.full_line( Region(view.text_point(start, 0), view.text_point(end, 0)))
def _process_dot(state, command_line): _init_line_range(command_line) if not state.is_range_start_line_parsed: if command_line.line_range.start and isinstance(command_line.line_range.start[-1], TokenOffset): raise ValueError('bad range {0}'.format(state.scanner.state.source)) command_line.line_range.start.append(TokenDot()) else: if command_line.line_range.end and isinstance(command_line.line_range.end[-1], TokenOffset): raise ValueError('bad range {0}'.format(state.scanner.source)) command_line.line_range.end.append(TokenDot()) return _parse_line_ref, command_line
def _scan_range(state): # Produce tokens found in a command line range. # https://vimhelp.appspot.com/cmdline.txt.html#cmdline-ranges # # Args: # :state (_ScannerState): # # Returns: # tuple c = state.consume() if c == state.EOF: return None, [TokenEof()] if c == '.': state.emit() return _scan_range, [TokenDot()] if c == '$': state.emit() return _scan_range, [TokenDollar()] if c == ',': state.emit() return _scan_range, [TokenComma()] if c in ';': state.emit() return _scan_range, [TokenSemicolon()] if c == "'": return _scan_mark(state) if c in '/?': return _scan_search(state) if c in '+-': return _scan_offset(state) if c == '%': state.emit() return _scan_range, [TokenPercent()] if c in '\t ': state.skip_run(' \t') state.ignore() if c.isdigit(): return _scan_digits(state) state.backup() return _scan_command, []
def _process_digits(token, state, command_line): if not state.is_range_start_line_parsed: if (command_line.line_range.start and command_line.line_range.start[-1]) == TokenDot(): raise ValueError('bad range: {0}'.format(state.scanner.state.source)) elif (command_line.line_range.start and isinstance(command_line.line_range.start[-1], TokenDigits)): command_line.line_range.start = [token] else: command_line.line_range.start.append(token) else: if (command_line.line_range.end and command_line.line_range.end[-1] == TokenDot()): raise ValueError('bad range: {0}'.format(state.scanner.state.source)) elif (command_line.line_range.end and isinstance(command_line.line_range.end[-1], TokenDigits)): command_line.line_range.end = [token] else: command_line.line_range.end.append(token) return _parse_line_ref, command_line