(token_list)
| 13 | |
| 14 | |
| 15 | def extract_definitions(token_list): |
| 16 | # assumes that token_list is a parenthesis |
| 17 | definitions = [] |
| 18 | tmp = [] |
| 19 | par_level = 0 |
| 20 | for token in token_list.flatten(): |
| 21 | if token.is_whitespace: |
| 22 | continue |
| 23 | elif token.match(sqlparse.tokens.Punctuation, '('): |
| 24 | par_level += 1 |
| 25 | continue |
| 26 | if token.match(sqlparse.tokens.Punctuation, ')'): |
| 27 | if par_level == 0: |
| 28 | break |
| 29 | else: |
| 30 | par_level -= 1 |
| 31 | elif token.match(sqlparse.tokens.Punctuation, ','): |
| 32 | if tmp: |
| 33 | definitions.append(tmp) |
| 34 | tmp = [] |
| 35 | else: |
| 36 | tmp.append(token) |
| 37 | if tmp: |
| 38 | definitions.append(tmp) |
| 39 | return definitions |
| 40 | |
| 41 | |
| 42 | if __name__ == '__main__': |
no test coverage detected
searching dependent graphs…