Refactor Rule Parsing to Use New Expression Parsers#184
Draft
leynos wants to merge 1 commit into
Draft
Conversation
- Replaced rule body literal string extraction with parsing into structured expressions. - Added `body_expressions()` on Rule AST node returning parsed Expr with error details. - Updated span scanner to properly collect literal spans by tracking nested tokens and commas/dots. - Simplified expression parsing in rule body using chumsky parser combinators. - Removed obsolete expression span logic related to rule bodies. - Improved parser tests to assert correct parsing of multiple expressions in rule body. - Enhanced integration tests verifying accurate expression nodes for multiple literals. This refactor improves AST representation of rule bodies by parsing each literal into a full expression node rather than plain string literals, enabling richer semantic analysis and validation. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
Contributor
Reviewer's GuideRefactors rule-body parsing by replacing the brittle token-oriented approach with a span-based literal collector and leveraging the dedicated expression parser to produce structured Expr nodes with preserved diagnostics. Class diagram for updated Rule body parsing APIclassDiagram
class Rule {
+body_literals() Vec<String>
+body_expressions() Vec<Result<Expr, Vec<Simple<SyntaxKind>>>>
+body_expression_texts() Vec<String>
}
class Expr
class Simple
class SyntaxKind
Rule --> Expr : parses to
Rule --> Simple : error diagnostics
Rule --> SyntaxKind : uses for error reporting
Flow diagram for new rule body literal span collectionflowchart TD
A["Token stream"] --> B["collect_rule_literal_spans"]
B --> C["Extract literal spans"]
C --> D["body_expression_texts"]
D --> E["parse_expression"]
E --> F["Expr nodes or diagnostics"]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
Changes
Parser API
Span Scanning
Expression Parsing
Tests
Why
Risk & Mitigations
Testing Plan
🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://www.terragonlabs.com/task/9a6801dd-1edc-476a-9513-f641b8f9d12f
Summary by Sourcery
Refactor rule-body parsing to delegate literal extraction and syntax analysis to the expression parser, replacing brittle token-driven logic with a span-based approach and exposing structured Expr nodes via the AST.
New Features:
Enhancements:
Tests: