From eb6ee3cade7a0ebbb45ddeae29a50fcb1405c5ae Mon Sep 17 00:00:00 2001 From: Darik Gamble Date: Mon, 9 Feb 2015 12:05:34 -0500 Subject: Move get_parent_name() from Identifer to TokenList (so Function can use it) --- sqlparse/sql.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'sqlparse/sql.py') diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 4fc4d72..8492c5e 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -422,17 +422,20 @@ class TokenList(Token): return self._get_first_name(self.token_index(dot)) return self._get_first_name() + + def get_parent_name(self): + """Return name of the parent object if any. + + A parent object is identified by the first occuring dot. + """ + dot = self.token_next_match(0, T.Punctuation, '.') if dot is None: - next_ = self.token_next_by_type(0, T.Name) - if next_ is not None: - return self._remove_quotes(next_.value) return None - - next_ = self.token_next_by_type(self.token_index(dot), - (T.Name, T.Wildcard, T.String.Symbol)) - if next_ is None: # invalid identifier, e.g. "a." + prev_ = self.token_prev(self.token_index(dot)) + if prev_ is None: # something must be verry wrong here.. return None - return self._remove_quotes(next_.value) + return self._remove_quotes(prev_.value) + def _get_first_name(self, idx=None, reverse=False, keywords=False): """Returns the name of the first token with a name""" @@ -485,19 +488,6 @@ class Identifier(TokenList): __slots__ = ('value', 'ttype', 'tokens') - def get_parent_name(self): - """Return name of the parent object if any. - - A parent object is identified by the first occuring dot. - """ - dot = self.token_next_match(0, T.Punctuation, '.') - if dot is None: - return None - prev_ = self.token_prev(self.token_index(dot)) - if prev_ is None: # something must be verry wrong here.. - return None - return self._remove_quotes(prev_.value) - def is_wildcard(self): """Return ``True`` if this identifier contains a wildcard.""" token = self.token_next_by_type(0, T.Wildcard) -- cgit v1.2.1