diff options
Diffstat (limited to 'sqlparse')
| -rw-r--r-- | sqlparse/engine/grouping.py | 34 | ||||
| -rw-r--r-- | sqlparse/keywords.py | 8 | ||||
| -rw-r--r-- | sqlparse/sql.py | 7 |
3 files changed, 43 insertions, 6 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index ab97ec6..3ae568d 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -101,6 +101,34 @@ def group_tzcasts(tlist): _group(tlist, sql.Identifier, match, valid, valid, post) +def group_typed_literal(tlist): + # definitely not complete, see e.g.: + # https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/interval-literal-syntax + # https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/interval-literals + # https://www.postgresql.org/docs/9.1/datatype-datetime.html + # https://www.postgresql.org/docs/9.1/functions-datetime.html + def match(token): + return token.match(*sql.TypedLiteral.M_OPEN) + + def match_to_extend(token): + return isinstance(token, sql.TypedLiteral) + + def valid_prev(token): + return token is not None + + def valid_next(token): + return token is not None and token.match(*sql.TypedLiteral.M_CLOSE) + + def valid_final(token): + return token is not None and token.match(*sql.TypedLiteral.M_EXTEND) + + def post(tlist, pidx, tidx, nidx): + return tidx, nidx + + _group(tlist, sql.TypedLiteral, match, valid_prev, valid_next, post, extend=False) + _group(tlist, sql.TypedLiteral, match_to_extend, valid_prev, valid_final, post, extend=True) + + def group_period(tlist): def match(token): return token.match(T.Punctuation, '.') @@ -217,13 +245,14 @@ def group_arrays(tlist): def group_operator(tlist): ttypes = T_NUMERICAL + T_STRING + T_NAME sqlcls = (sql.SquareBrackets, sql.Parenthesis, sql.Function, - sql.Identifier, sql.Operation) + sql.Identifier, sql.Operation, sql.TypedLiteral) def match(token): return imt(token, t=(T.Operator, T.Wildcard)) def valid(token): - return imt(token, i=sqlcls, t=ttypes) + return imt(token, i=sqlcls, t=ttypes) \ + or token.match(T.Keyword, ("CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP")) def post(tlist, pidx, tidx, nidx): tlist[tidx].ttype = T.Operator @@ -372,6 +401,7 @@ def group(stmt): group_order, group_typecasts, group_tzcasts, + group_typed_literal, group_operator, group_comparison, group_as, diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index ec3fe50..3b57824 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -194,7 +194,7 @@ KEYWORDS = { 'CONVERSION': tokens.Keyword, 'CONVERT': tokens.Keyword, 'COPY': tokens.Keyword, - 'CORRESPONTING': tokens.Keyword, + 'CORRESPONDING': tokens.Keyword, 'COUNT': tokens.Keyword, 'CREATEDB': tokens.Keyword, 'CREATEUSER': tokens.Keyword, @@ -429,11 +429,11 @@ KEYWORDS = { 'PARAMETER': tokens.Keyword, 'PARAMETERS': tokens.Keyword, 'PARAMETER_MODE': tokens.Keyword, - 'PARAMATER_NAME': tokens.Keyword, - 'PARAMATER_ORDINAL_POSITION': tokens.Keyword, + 'PARAMETER_NAME': tokens.Keyword, + 'PARAMETER_ORDINAL_POSITION': tokens.Keyword, 'PARAMETER_SPECIFIC_CATALOG': tokens.Keyword, 'PARAMETER_SPECIFIC_NAME': tokens.Keyword, - 'PARAMATER_SPECIFIC_SCHEMA': tokens.Keyword, + 'PARAMETER_SPECIFIC_SCHEMA': tokens.Keyword, 'PARTIAL': tokens.Keyword, 'PASCAL': tokens.Keyword, 'PCTFREE': tokens.Keyword, diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 80a96df..fbe1c18 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -489,6 +489,13 @@ class IdentifierList(TokenList): yield token +class TypedLiteral(TokenList): + """A typed literal (?), such as "date '2001-09-28'" or "interval '2 hours'".""" + M_OPEN = T.Name.Builtin, None + M_CLOSE = T.String.Single, None + M_EXTEND = T.Keyword, ("DAY", "MONTH", "YEAR", "HOUR", "MINUTE", "SECOND") + + class Parenthesis(TokenList): """Tokens between parenthesis.""" M_OPEN = T.Punctuation, '(' |
