Skip to content

Commit

Permalink
fix: allow filter() and isnull() with no space (#644)
Browse files Browse the repository at this point in the history
* fix: allow filter() and isnull() with no space

* fix: format
  • Loading branch information
tconbeer authored Nov 22, 2024
1 parent 51420d4 commit 15abb00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/sqlfmt/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@
),
),
),
Rule(
# There are some function names in some dialects that are the same as
# word operators in other dialects. Here we lex those as function
# names IFF the name is immediately followed by a `(` (with no space
# after the name. Otherwise they are lexed as word_operators by the
# next rule.
name="functions_that_overlap_with_word_operators",
priority=1099,
pattern=group(
r"filter",
r"isnull",
)
+ group(r"\("),
action=partial(
actions.handle_reserved_keyword,
action=partial(actions.add_node_to_buffer, token_type=TokenType.NAME),
),
),
Rule(
name="word_operator",
priority=1100,
Expand Down
7 changes: 7 additions & 0 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ def test_regex_anti_match(
(MAIN, "frame_clause", "range 1 following", "range "),
(MAIN, "frame_clause", "range current row", "range "),
(MAIN, "frame_clause", "groups between 1 preceding", "groups "),
(MAIN, "functions_that_overlap_with_word_operators", "filter(foo)", "filter"),
(
MAIN,
"functions_that_overlap_with_word_operators",
"isnull(bar, baz)",
"isnull",
),
],
)
def test_regex_partial_match(
Expand Down

0 comments on commit 15abb00

Please sign in to comment.