-
Notifications
You must be signed in to change notification settings - Fork 206
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: multi-line formatting for permission expressions #1629
feat: multi-line formatting for permission expressions #1629
Conversation
Warning Rate limit exceeded@tolgaOzen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 22 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes introduce a new field Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
f9f53e1
to
5292b44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
🔇 Files ignored due to path filters (1)
playground/public/play.wasm
is excluded by!**/*.wasm
📒 Files selected for processing (2)
- pkg/dsl/parser/parser.go (4 hunks)
- pkg/dsl/parser/parser_test.go (1 hunks)
🔇 Additional comments not posted (7)
pkg/dsl/parser/parser.go (5)
36-37
: LGTM: Addition ofpreviousToken
field toParser
structThe addition of the
previousToken
field to theParser
struct is a good improvement. It allows the parser to keep track of the previous token, which can be useful for more complex parsing scenarios, such as handling multi-line expressions.
87-88
: LGTM: Update ofpreviousToken
innext
methodThe modification to the
next
method correctly updates thepreviousToken
field before changing thecurrentToken
. This change ensures that thepreviousToken
always contains the token that precedes the current one, which is consistent with the addition of thepreviousToken
field in theParser
struct.
125-135
: LGTM: Addition ofpreviousTokenIs
methodThe new
previousTokenIs
method is a well-implemented addition to theParser
struct. It correctly checks if thepreviousToken
matches any of the specified token types, enhancing the parser's ability to make decisions based on the previous token. The implementation is consistent with the existingcurrentTokenIs
andpeekTokenIs
methods, and the use of variadic parameters allows for flexible checking of multiple token types.
Line range hint
1-924
: Summary: Successful implementation of multi-line formatting for permission expressionsThe changes made to
pkg/dsl/parser/parser.go
successfully implement support for multi-line formatting in permission expressions. Key modifications include:
- Addition of a
previousToken
field to theParser
struct.- Update of the
next
method to maintain thepreviousToken
.- Introduction of a
previousTokenIs
method for token type checking.- Enhancement of the
parseExpression
method to handle newlines in specific contexts.These changes collectively improve the parser's flexibility and capability to handle more complex permission expression syntax. The implementation is consistent and well-integrated with the existing codebase.
607-611
: LGTM: Handling of multi-line formatting inparseExpression
The addition of the new condition at the beginning of the
parseExpression
method is a good improvement. It allows for multi-line formatting of permission expressions by advancing to the next token when a newline is encountered after specific tokens (LP, AND, OR, NOT, ASSIGN). This change enhances the parser's flexibility in handling permission expression syntax.To ensure completeness, please verify if all relevant tokens are included in the condition. Consider if there are any other tokens that might be valid at the end of a line in a permission expression.
✅ Verification successful
Verified: Comprehensive Token Coverage in
parseExpression
The verification confirms that all relevant tokens (
LP
,AND
,OR
,NOT
,ASSIGN
) are included in the condition checking for newline tokens. No additional tokens require inclusion. This change effectively enhances the parser's flexibility in handling multi-line permission expressions.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for other potential tokens that might be relevant for multi-line expressions # Test: Search for token definitions and usage in expression parsing rg --type go -e "token\." -e "parseExpression" pkg/dslLength of output: 48776
pkg/dsl/parser/parser_test.go (2)
852-899
: Test case effectively validates multi-line permission expression with ruleThe test case for "Case 24" correctly verifies that the parser can handle a multi-line permission expression involving a rule. The assertions comprehensively check the parsed schema for accuracy.
900-946
: Test case successfully tests alternative multi-line formatting"Case 25" effectively tests the parser's ability to handle different formatting of a multi-line permission expression. The test ensures that variations in whitespace and line breaks do not affect the parsing outcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
pkg/dsl/parser/parser_test.go (2)
947-970
: LGTM! Consider renumbering this test case.This negative test case is crucial for validating the parser's ability to detect and report syntax errors in multi-line permission expressions. It effectively ensures that the parser fails when encountering incorrectly formatted expressions.
However, this test case is labeled as "Case 26", which duplicates a test case number from a previous commit. To maintain clarity and avoid confusion, consider renaming this to "Case 27" or the next appropriate number in the sequence.
972-1009
: LGTM! Consider enhancing assertions for the complex permission expression.This test case is an excellent addition, validating the parser's capability to handle complex, multi-line permission expressions with multiple rules and various logical operators. It significantly improves the test coverage for real-world scenarios.
To further strengthen this test, consider adding assertions that verify the correctness of the parsed permission structure. This would ensure not only that the parser doesn't throw an error, but also that it correctly interprets the complex logical structure of the permission.
Here's a suggestion for additional assertions:
st := schema.Statements[0].(*ast.EntityStatement) Expect(st.Name.Literal).Should(Equal("report")) p1 := st.PermissionStatements[0].(*ast.PermissionStatement) Expect(p1.Name.Literal).Should(Equal("view")) es1 := p1.ExpressionStatement.(*ast.ExpressionStatement) // Add assertions to check the structure of the complex permission expression // For example: Expect(es1.Expression).Should(BeAssignableToTypeOf(&ast.InfixExpression{})) infix := es1.Expression.(*ast.InfixExpression) Expect(infix.Operator).Should(Equal("or")) // Continue with more detailed assertions based on the expected structure
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- pkg/dsl/parser/parser_test.go (1 hunks)
🔇 Additional comments not posted (3)
pkg/dsl/parser/parser_test.go (3)
853-898
: LGTM! Excellent test case for multi-line permission expressions.This test case effectively validates the parser's ability to handle multi-line permission expressions. It's a crucial addition that ensures the parser can correctly interpret permissions split across multiple lines, which is important for maintaining code readability in complex permission scenarios.
900-945
: LGTM! Good coverage of alternative formatting styles.This test case complements Case 24 by validating the parser's ability to handle a different style of multi-line permission expressions. Testing various formatting styles ensures the parser is robust and flexible, accommodating different coding preferences.
852-1009
: Excellent enhancement of the test suite for multi-line permission expressions!These additions significantly improve the robustness of the parser's test suite, particularly in handling complex, multi-line permission expressions. The new test cases cover a wide range of scenarios, including:
- Basic multi-line expressions
- Different formatting styles
- Failure cases with incorrect syntax
- Highly complex expressions with multiple rules and logical operators
These tests will ensure that the parser can handle real-world, complex permission scenarios while maintaining flexibility in expression formatting. The thoroughness of these tests will greatly contribute to the reliability and maintainability of the parser.
Great job on improving the test coverage! The suggested minor enhancements (renumbering Case 26 and adding more detailed assertions for the complex case) will further refine this already solid set of tests.
#1628
Todo:
Summary by CodeRabbit
New Features
previousToken
field for improved token processing.Tests