Skip to content

Commit

Permalink
Previous fix for period failed when another token (non-groupable) fol…
Browse files Browse the repository at this point in the history
…lowed.
  • Loading branch information
vmuriart committed Jun 19, 2016
1 parent 24f0d3d commit b3700f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sqlparse/engine/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ def valid_prev(token):
return imt(token, i=sqlcls, t=ttypes)

def valid_next(token):
# issue261, allow invalid next token
return True

def post(tlist, pidx, tidx, nidx):
# next_ validation is being performed here. issue261
sqlcls = sql.SquareBrackets, sql.Function
ttypes = T.Name, T.String.Symbol, T.Wildcard
return token is None or imt(token, i=sqlcls, t=ttypes)
next_ = tlist[nidx] if nidx is not None else None
valid_next = imt(next_, i=sqlcls, t=ttypes)

def post(tlist, pidx, tidx, nidx):
return (pidx, nidx) if nidx is not None else (pidx, tidx)
return (pidx, nidx) if valid_next else (pidx, tidx)

_group(tlist, sql.Identifier, match, valid_prev, valid_next, post)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ def test_identifier_invalid(self):
self.assertEqual(p.tokens[0].get_real_name(), None)
self.assertEqual(p.tokens[0].get_parent_name(), 'a')

def test_identifier_invalid_in_middle(self):
# issue261
s = 'SELECT foo. FROM foo'
p = sqlparse.parse(s)[0]
assert isinstance(p[2], sql.Identifier)
assert p[2][1].ttype == T.Punctuation
assert p[3].ttype == T.Whitespace
assert str(p[2]) == 'foo.'

def test_identifier_as_invalid(self): # issue8
p = sqlparse.parse('foo as select *')[0]
self.assert_(len(p.tokens), 5)
Expand Down

0 comments on commit b3700f4

Please sign in to comment.