Skip to content

Commit b61fe36

Browse files
committed
Group square-brackets into identifiers
Indentifier.get_array_indices() looks for square brackets, and yields lists of bracket grouped tokens as array indices
1 parent a93029f commit b61fe36

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

sqlparse/engine/grouping.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,17 @@ def _consume_cycle(tl, i):
159159
lambda y: (y.match(T.Punctuation, '.')
160160
or y.ttype in (T.Operator,
161161
T.Wildcard,
162-
T.ArrayIndex,
163-
T.Name)),
162+
T.Name)
163+
or isinstance(y, sql.SquareBrackets)),
164164
lambda y: (y.ttype in (T.String.Symbol,
165165
T.Name,
166166
T.Wildcard,
167-
T.ArrayIndex,
168167
T.Literal.String.Single,
169168
T.Literal.Number.Integer,
170169
T.Literal.Number.Float)
171-
or isinstance(y, (sql.Parenthesis, sql.Function)))))
170+
or isinstance(y, (sql.Parenthesis,
171+
sql.SquareBrackets,
172+
sql.Function)))))
172173
for t in tl.tokens[i:]:
173174
# Don't take whitespaces into account.
174175
if t.ttype is T.Whitespace:

sqlparse/sql.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,12 @@ def get_ordering(self):
511511
return ordering.value.upper()
512512

513513
def get_array_indices(self):
514-
"""Returns an iterator of index expressions as strings"""
514+
"""Returns an iterator of index token lists"""
515515

516-
# Use [1:-1] index to discard the square brackets
517-
return (tok.value[1:-1] for tok in self.tokens
518-
if tok.ttype in T.ArrayIndex)
516+
for tok in self.tokens:
517+
if isinstance(tok, SquareBrackets):
518+
# Use [1:-1] index to discard the square brackets
519+
yield tok.tokens[1:-1]
519520

520521

521522
class IdentifierList(TokenList):

0 commit comments

Comments
 (0)