From 3d13c5d4bb14f76d407285f2a91e7061585fd6da Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sat, 12 Sep 2009 08:05:34 +0200 Subject: Prevent WHERE grouper from consuming closing parenthesis (fixes issue9, reported by estama). --- sqlparse/engine/grouping.py | 2 +- sqlparse/sql.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index d30031f..a03c0b4 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -231,7 +231,7 @@ def group_where(tlist): tidx = tlist.token_index(token) end = tlist.token_next_match(tidx+1, T.Keyword, stopwords) if end is None: - end = tlist.tokens[-1] + end = tlist._groupable_tokens[-1] else: end = tlist.tokens[tlist.token_index(end)-1] group = tlist.group_tokens(Where, tlist.tokens_between(token, end)) diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 5969841..195696e 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -176,6 +176,10 @@ class TokenList(Token): def get_sublists(self): return [x for x in self.tokens if isinstance(x, TokenList)] + @property + def _groupable_tokens(self): + return self.tokens + def token_first(self, ignore_whitespace=True): """Returns the first child token. @@ -426,6 +430,10 @@ class Parenthesis(TokenList): """Tokens between parenthesis.""" __slots__ = ('value', 'ttype', 'tokens') + @property + def _groupable_tokens(self): + return self.tokens[1:-1] + class Assignment(TokenList): """An assignment like 'var := val;'""" -- cgit v1.2.1