File tree 2 files changed +13
-1
lines changed 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,12 @@ a keyword to the lexer:
44
44
from sqlparse import keywords
45
45
from sqlparse.lexer import Lexer
46
46
47
+ # get the lexer singleton object to configure it
47
48
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.
48
53
lex.clear()
49
54
50
55
my_regex = (r " ZORDER\s + BY\b " , sqlparse.tokens.Keyword)
@@ -55,12 +60,17 @@ a keyword to the lexer:
55
60
+ [my_regex]
56
61
+ keywords.SQL_REGEX [38 :]
57
62
)
63
+
64
+ # add the default keyword dictionaries
58
65
lex.add_keywords(keywords.KEYWORDS_COMMON )
59
66
lex.add_keywords(keywords.KEYWORDS_ORACLE )
60
67
lex.add_keywords(keywords.KEYWORDS_PLPGSQL )
61
68
lex.add_keywords(keywords.KEYWORDS_HQL )
62
69
lex.add_keywords(keywords.KEYWORDS_MSACCESS )
63
70
lex.add_keywords(keywords.KEYWORDS )
71
+
72
+ # add a custom keyword dictionary
64
73
lex.add_keywords({' BAR' , sqlparse.tokens.Keyword})
65
74
75
+ # no configuration is passed here. The lexer is used as a singleton.
66
76
sqlparse.parse(" select * from foo zorder by bar;" )
Original file line number Diff line number Diff line change @@ -50,7 +50,9 @@ def __init__(self):
50
50
51
51
def clear (self ):
52
52
"""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."""
54
56
self ._SQL_REGEX = []
55
57
self ._keywords = []
56
58
You can’t perform that action at this time.
0 commit comments