Skip to content

Commit

Permalink
additional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmasterplan authored and andialbrecht committed Jan 2, 2023
1 parent 4efdc03 commit fbf9a57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ a keyword to the lexer:
from sqlparse import keywords
from sqlparse.lexer import Lexer
# get the lexer singleton object to configure it
lex = Lexer()
# Clear the default configurations.
# After this call, reg-exps and keyword dictionaries need to be loaded
# to make the lexer functional again.
lex.clear()
my_regex = (r"ZORDER\s+BY\b", sqlparse.tokens.Keyword)
Expand All @@ -55,12 +60,17 @@ a keyword to the lexer:
+ [my_regex]
+ keywords.SQL_REGEX[38:]
)
# add the default keyword dictionaries
lex.add_keywords(keywords.KEYWORDS_COMMON)
lex.add_keywords(keywords.KEYWORDS_ORACLE)
lex.add_keywords(keywords.KEYWORDS_PLPGSQL)
lex.add_keywords(keywords.KEYWORDS_HQL)
lex.add_keywords(keywords.KEYWORDS_MSACCESS)
lex.add_keywords(keywords.KEYWORDS)
# add a custom keyword dictionary
lex.add_keywords({'BAR', sqlparse.tokens.Keyword})
# no configuration is passed here. The lexer is used as a singleton.
sqlparse.parse("select * from foo zorder by bar;")
4 changes: 3 additions & 1 deletion sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def __init__(self):

def clear(self):
"""Clear all syntax configurations.
Useful if you want to load a reduced set of syntax configurations."""
Useful if you want to load a reduced set of syntax configurations.
After this call, reg-exps and keyword dictionaries need to be loaded
to make the lexer functional again."""
self._SQL_REGEX = []
self._keywords = []

Expand Down

0 comments on commit fbf9a57

Please sign in to comment.