diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2013-01-27 10:21:37 +0100 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2013-01-27 10:21:37 +0100 |
commit | f6c3a0f124becdaeacfb755d7ba61ffc7c032337 (patch) | |
tree | 1b7b2c749d9a36de7ac321ac95fb0d5224d60b08 /sqlparse/sql.py | |
parent | 07ef26a1a3b7e2b93d855970b92c985328eef097 (diff) | |
download | sqlparse-f6c3a0f124becdaeacfb755d7ba61ffc7c032337.tar.gz |
Helper function to return a token at a specific offset.
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r-- | sqlparse/sql.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 86deb4e..16f055b 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -196,6 +196,15 @@ class TokenList(Token): val = val[1:-1] return val + def get_token_at_offset(self, offset): + """Returns the token that is on position offset.""" + idx = 0 + for token in self.flatten(): + end = idx + len(token.value) + if idx <= offset <= end: + return token + idx = end + def flatten(self): """Generator yielding ungrouped tokens. |