1
0
forked from VimPlug/jedi

Operator fixes. Subclass of Simple, now.

This commit is contained in:
Dave Halter
2014-07-22 16:02:34 +02:00
parent 15f42d93d7
commit 852cdad754
5 changed files with 18 additions and 21 deletions

View File

@@ -325,7 +325,9 @@ class Parser(object):
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
is_kw = tok.string in OPERATOR_KEYWORDS
if tok.type == tokenize.OP or is_kw:
tok_list.append(pr.Operator(tok.string, tok.start_pos))
tok_list.append(
pr.Operator(self.module, tok.string, self._scope, tok.start_pos)
)
else:
tok_list.append(tok)

View File

@@ -918,7 +918,7 @@ class Statement(Simple, DocstringMixin):
def get_code(self, new_line=True):
def assemble(command_list, assignment=None):
pieces = [c.get_code() if isinstance(c, Simple) else c.string if
isinstance(c, (tokenize.Token, Operator)) else unicode(c)
isinstance(c, tokenize.Token) else unicode(c)
for c in command_list]
if assignment is None:
return ''.join(pieces)
@@ -1565,26 +1565,21 @@ class ListComprehension(ForFlow):
return "%s for %s in %s" % tuple(code)
class Operator(Base):
__slots__ = ('string', '_line', '_column')
class Operator(Simple):
__slots__ = ('string',)
def __init__(self, string, start_pos):
# TODO needs module param
def __init__(self, module, string, parent, start_pos):
end_pos = start_pos[0], start_pos[1] + len(string)
super(Operator, self).__init__(module, start_pos, end_pos)
self.string = string
self._line = start_pos[0]
self._column = start_pos[1]
self.parent = parent
def get_code(self):
return self.string
def __repr__(self):
return "<%s: `%s`>" % (type(self).__name__, self.string)
@property
def start_pos(self):
return self._line, self._column
@property
def end_pos(self):
return self._line, self._column + len(self.string)
def __eq__(self, other):
"""Make comparisons easy. Improves the readability of the parser."""
return self.string == other