Add multi-line matcher syntax with let statements and early returns#1604
Open
Add multi-line matcher syntax with let statements and early returns#1604
Conversation
|
|
…turns Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Support multiple lines of matcher in policy definitions
Add multi-line matcher syntax with let statements and early returns
Dec 13, 2025
Member
|
@copilot fix linter check: |
… refactor to reduce complexity Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Contributor
Author
... Fixed all linter issues in commit e0567c7:
All tests pass and no linter errors remain. |
c622095 to
b190fce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements support for multi-line matchers with block-style syntax, addressing the feature request in the issue.
Features Implemented
✅ Block syntax with
{}: Write matchers across multiple lines for better readability✅ Let statements: Define intermediate variables to break down complex expressions
✅ Early returns: Use
ifstatements withreturnfor conditional logic✅ Backward compatible: Traditional single-line matchers continue to work unchanged
Changes Made
Core Implementation
util/matcher_transform.go: Parser that transforms block-style matchers to govaluate expressionsmodel/model.go: Integration point that applies transformation during model loading (3 lines added)util/matcher_transform_test.go: Comprehensive unit tests for the transformation logicTests
multiline_matcher_test.go: Integration tests with full Casbin enforcementrbac_with_hierarchy_multiline_model.conf,rbac_with_early_return_model.confDocumentation
MULTILINE_MATCHER.md: Complete usage guide with examples and important notesExample Usage
Traditional syntax (still supported):
New multi-line syntax with let statements:
New multi-line syntax with early returns:
Testing
✅ All unit tests pass (util package)
✅ All integration tests pass (main package)
✅ All existing tests pass (no regressions)
✅ Code review completed and feedback addressed
✅ Security scan completed (no vulnerabilities)
✅ Linter checks pass
Notes
\) for line continuation in config filesOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.