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

AnySetOf grammar #2326

Merged
merged 13 commits into from
Jan 17, 2022
Merged

AnySetOf grammar #2326

merged 13 commits into from
Jan 17, 2022

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Jan 16, 2022

Brief summary of the change made

Closes #2322. Adds AnySetOf grammar.

AnySetOf is defined as Match any number of the elements but each element can only be matched once.

I've updated the grammar introduced in #2315 to use this new segment.

Happy to convert a couple places in the grammar/add extra tests if needed (this is my first time updating the parser code).

Are there any other side effects of this change that we should be aware of?

No

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Jan 16, 2022

Codecov Report

Merging #2326 (cb3367b) into main (38cff66) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #2326   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          159       159           
  Lines        11303     11313   +10     
=========================================
+ Hits         11303     11313   +10     
Impacted Files Coverage Δ
src/sqlfluff/core/parser/__init__.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_ansi.py 100.00% <ø> (ø)
src/sqlfluff/core/parser/grammar/__init__.py 100.00% <100.00%> (ø)
src/sqlfluff/core/parser/grammar/anyof.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38cff66...cb3367b. Read the comment docs.

@jpy-git
Copy link
Contributor Author

jpy-git commented Jan 16, 2022

Will take a look at adding some additional tests for coverage tomorrow, the PR is otherwise passing though.

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think there may be a possibility of simplifying the logic a little.

src/sqlfluff/core/parser/grammar/anyof.py Show resolved Hide resolved
and (str(matched_option) in available_option_counter)
):
available_option_counter[str(matched_option)] += 1
# Check if we have matched an option too many times.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be moved inside the if above? It may be possible to simplify the logic as well -- IIUC, we only need to check if matched_option has hit the maximum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barrywhart good shout, I've simplified the logic by moving the if condition 👍

src/sqlfluff/core/parser/grammar/anyof.py Show resolved Hide resolved
@barrywhart barrywhart merged commit 19826b0 into sqlfluff:main Jan 17, 2022
@jpy-git jpy-git deleted the any_set_of_grammar branch January 17, 2022 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AnySetOf grammar
2 participants