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

feat: Add basic url filter parser #5653

Merged
merged 8 commits into from
Sep 16, 2024
Merged

Conversation

AdityaHegde
Copy link
Collaborator

@AdityaHegde AdityaHegde commented Sep 10, 2024

For human readable url params we need a parser for filter param.
Possible expressions,

country IN ('US','IN') and state = 'ABC'
country NIN ('US','IN') and (state = 'ABC' or lat >= 12.56)
country NIN ('US','IN') and state having (lat >= 12.56)
  • Write a grammer and parser for the expression.
  • Convert the parsed object to V1Expressioin

@AdityaHegde AdityaHegde marked this pull request as ready for review September 12, 2024 08:07
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

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

Overall this looks good, but left various comments/questions throughout. Additionally, for posterity, a README.md file in the url-state/filters directory would be helpful to explain our filter language, nearly, and how to generate the parser.

web-common/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when the string cannot be properly parsed? Can we add some test cases for the failure cases to show what happens? (Given user-provided strings will certainly fail occasionally)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a couple to demonstrate the error. We should get a UX pass eventually.

Comment on lines 18 to 19
| (boolean_expr _ "AND"i _):+ non_and_expr {% andOrPostprocessor %}
| (boolean_expr _ "OR"i _):+ non_or_expr {% andOrPostprocessor %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be clearer to have a discrete andPostprocessor and an orPostprocessor

Copy link
Collaborator Author

@AdityaHegde AdityaHegde Sep 16, 2024

Choose a reason for hiding this comment

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

They have the exact same implementation. This is the suggested usage of post post processors, being able to reuse them. Feel like it would be redundant.

Comment on lines +4 to +6
@builtin "whitespace.ne"
@builtin "number.ne"
@builtin "string.ne"
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are these referenced? I don't see any explicit references, but I'm guessing maybe the primitive types at the bottom (e.g. sqstring, int, decimal) are coming from here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the docs arent here for these right now. They point to the source code of these files: https://github.com/kach/nearley/tree/master/builtin

Comment on lines 21 to 25
# these are used to disambiguate matches
non_and_expr => boolean_expr {% id %}
| (boolean_expr __ "OR"i __):+ non_and_expr {% andOrPostprocessor %}
non_or_expr => boolean_expr {% id %}
| (boolean_expr __ "AND"i __):+ non_or_expr {% andOrPostprocessor %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not totally following these. At first glance, it looks like adding these conditions would prevent multiple "ANDs" and multiple "ORs" in the same statement. But I see in the test cases that "X and Y and Z" is possible. So, mind just clarifying in the comment what these do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are used in expr (boolean_expr _ "AND"i _):+ non_and_expr for AND. It matches continuous AND ended by a non AND expr.

Added some comments around this.

@AdityaHegde AdityaHegde merged commit caf228c into main Sep 16, 2024
7 checks passed
@AdityaHegde AdityaHegde deleted the adityahegde/url-filter-parser branch September 16, 2024 05:34
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.

2 participants