Skip to content

Commit fbf9a57

Browse files
mrmasterplanandialbrecht
authored andcommitted
additional documentation
1 parent 4efdc03 commit fbf9a57

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/source/extending.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ a keyword to the lexer:
4444
from sqlparse import keywords
4545
from sqlparse.lexer import Lexer
4646
47+
# get the lexer singleton object to configure it
4748
lex = Lexer()
49+
50+
# Clear the default configurations.
51+
# After this call, reg-exps and keyword dictionaries need to be loaded
52+
# to make the lexer functional again.
4853
lex.clear()
4954
5055
my_regex = (r"ZORDER\s+BY\b", sqlparse.tokens.Keyword)
@@ -55,12 +60,17 @@ a keyword to the lexer:
5560
+ [my_regex]
5661
+ keywords.SQL_REGEX[38:]
5762
)
63+
64+
# add the default keyword dictionaries
5865
lex.add_keywords(keywords.KEYWORDS_COMMON)
5966
lex.add_keywords(keywords.KEYWORDS_ORACLE)
6067
lex.add_keywords(keywords.KEYWORDS_PLPGSQL)
6168
lex.add_keywords(keywords.KEYWORDS_HQL)
6269
lex.add_keywords(keywords.KEYWORDS_MSACCESS)
6370
lex.add_keywords(keywords.KEYWORDS)
71+
72+
# add a custom keyword dictionary
6473
lex.add_keywords({'BAR', sqlparse.tokens.Keyword})
6574
75+
# no configuration is passed here. The lexer is used as a singleton.
6676
sqlparse.parse("select * from foo zorder by bar;")

sqlparse/lexer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def __init__(self):
5050

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

0 commit comments

Comments
 (0)