Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #502: change lexing priority of walrus operator #509

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.

- Adds support for the `map<...>` type declaration syntax from Athena. ([#500](https://github.com/tconbeer/sqlfmt/issues/500) - thank you for the issue and fix, [@benjamin-awd](https://github.com/benjamin-awd)!)
- Fixes a bug where nested dicts inside jinja expressions (e.g., `{{ {'a': {'b': 1}} }}`) could cause parsing errors ([#471](https://github.com/tconbeer/sqlfmt/issues/500) - thank you [@rparvathaneni-sc](https://github.com/rparvathaneni-sc) and [@benjamin-awd](https://github.com/benjamin-awd)!). This fix introduces a dependency on jinja2 > v3.0.
- Fixes a bug in the lexing logic that prevented the walrus operator (`:=`) from being lexed as a single token ([#502](https://github.com/tconbeer/sqlfmt/issues/502) - thank you [@federico-hero](https://github.com/federico-hero)!).


## [0.20.0] - 2023-09-25
Expand Down
8 changes: 7 additions & 1 deletion src/sqlfmt/rules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
pattern=group(r"::"),
action=partial(actions.add_node_to_buffer, token_type=TokenType.DOUBLE_COLON),
),
Rule(
name="walrus",
priority=421,
pattern=group(r":="),
action=partial(actions.add_node_to_buffer, token_type=TokenType.OPERATOR),
),
Rule(
name="colon",
priority=430,
Expand Down Expand Up @@ -183,7 +189,7 @@
r"[*+?]?\?", # regex greedy/non-greedy, also ?
r"!!", # negate text match
r"%%", # psycopg escaped mod operator
r"[+\-*/%&|^=<>:#!]=?", # singles
r"[+\-*/%&|^=<>#!]=?", # singles
),
action=partial(actions.add_node_to_buffer, token_type=TokenType.OPERATOR),
),
Expand Down
7 changes: 7 additions & 0 deletions tests/data/unformatted/131_assignment_statement.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select partman.create_parent( 'public.deliveries_finished', 'created_at', 'native', 'daily', p_premake := 20) ;
)))))__SQLFMT_OUTPUT__(((((
select
partman.create_parent(
'public.deliveries_finished', 'created_at', 'native', 'daily', p_premake := 20
)
;
1 change: 1 addition & 0 deletions tests/functional_tests/test_general_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"unformatted/128_double_slash_comments.sql",
"unformatted/129_duckdb_joins.sql",
"unformatted/130_athena_data_types.sql",
"unformatted/131_assignment_statement.sql",
"unformatted/200_base_model.sql",
"unformatted/201_basic_snapshot.sql",
"unformatted/202_unpivot_macro.sql",
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(CORE, "bracket_open", "["),
(CORE, "bracket_close", ")"),
(CORE, "double_colon", "::"),
(CORE, "walrus", ":="),
(CORE, "colon", ":"),
(CORE, "semicolon", ";"),
(CORE, "operator", "+"),
Expand Down