Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sqlparse/engine/filter_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright (C) 2009-2020 the sqlparse authors and contributors
# <see AUTHORS file>
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
# This module is part of python-sqlparse and is released under the BSD License:
# https://opensource.org/licenses/BSD-3-Clause

"""filter"""

Expand All @@ -20,6 +20,7 @@ def __init__(self, strip_semicolon=False):
self.stmtprocess = []
self.postprocess = []
self._grouping = False
self.lexer = lexer.Lexer.get_default_instance()
if strip_semicolon:
self.stmtprocess.append(StripTrailingSemicolonFilter())

Expand All @@ -28,7 +29,7 @@ def enable_grouping(self):

def run(self, sql, encoding=None):
try:
stream = lexer.tokenize(sql, encoding)
stream = self.lexer.get_tokens(sql, encoding)
# Process token stream
for filter_ in self.preprocess:
stream = filter_.process(stream)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_filter_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sqlparse import engine, tokens
from sqlparse.lexer import Lexer


def test_filter_stack_allows_custom_lexer():
custom_lexer = Lexer()
custom_lexer.default_initialization()
custom_lexer.add_keywords({'CUSTOMLEXERKEYWORD': tokens.Keyword})

stack = engine.FilterStack()
stack.lexer = custom_lexer
statement = next(stack.run('CUSTOMLEXERKEYWORD value'))

assert statement.tokens[0].ttype is tokens.Keyword