summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2022-09-06 21:26:49 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2022-09-06 21:26:49 +0200
commit07a2e81532daf62f1f4360e48ff322abeade7315 (patch)
tree17cc3fbe998df2db978ca6acc8a5838c6ed99db5
parent4235eb89a904216aef9d9ef36a0381be885c87a9 (diff)
downloadsqlparse-07a2e81532daf62f1f4360e48ff322abeade7315.tar.gz
Add docstring and comments.
-rw-r--r--sqlparse/keywords.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py
index 0f3a459..3aa6c63 100644
--- a/sqlparse/keywords.py
+++ b/sqlparse/keywords.py
@@ -11,6 +11,11 @@ from sqlparse import tokens
def is_keyword(value):
+ """Checks for a keyword.
+
+ If the given value is in one of the KEYWORDS_* dictionary
+ it's considered a keyword. Otherwise tokens.Name is returned.
+ """
val = value.upper()
return (KEYWORDS_COMMON.get(val)
or KEYWORDS_ORACLE.get(val)
@@ -57,7 +62,7 @@ SQL_REGEX = {
# see issue #39
# Spaces around period `schema . name` are valid identifier
# TODO: Spaces before period not implemented
- (r'[A-ZÀ-Ü]\w*(?=\s*\.)', tokens.Name), # 'Name' .
+ (r'[A-ZÀ-Ü]\w*(?=\s*\.)', tokens.Name), # 'Name'.
# FIXME(atronah): never match,
# because `re.match` doesn't work with look-behind regexp feature
(r'(?<=\.)[A-ZÀ-Ü]\w*', tokens.Name), # .'Name'
@@ -92,6 +97,8 @@ SQL_REGEX = {
(r"(AT|WITH')\s+TIME\s+ZONE\s+'[^']+'", tokens.Keyword.TZCast),
(r'(NOT\s+)?(LIKE|ILIKE|RLIKE)\b', tokens.Operator.Comparison),
(r'(NOT\s+)?(REGEXP)\b', tokens.Operator.Comparison),
+ # Check for keywords, also returns tokens.Name if regex matches
+ # but the match isn't a keyword.
(r'[0-9_A-ZÀ-Ü][_$#\w]*', is_keyword),
(r'[;:()\[\],\.]', tokens.Punctuation),
(r'[<>=~!]+', tokens.Operator.Comparison),