-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DSL Array Pattern Match & Simplification (#36)
# Add List Pattern Matching to the HIR and Evaluation Engine ## Summary This PR adds list pattern matching capabilities to the language. It introduces two new pattern variants: `EmptyArray` for matching empty arrays, and `ArrayDecomp` for decomposing arrays into head and tail components. ## Changes - Added new pattern variants to the `Pattern` enum in the HIR (engine) & AST (parsing). - Extended the pattern matching logic in `match_pattern` to handle list patterns - Added comprehensive tests demonstrating list pattern matching functionality - Simplified syntax elements as agreed during the design phase ## Implementation Details ```rust // New pattern variants pub enum Pattern { // ... existing variants EmptyArray, ArrayDecomp(Box<Pattern>, Box<Pattern>), } ``` The pattern matching logic was extended to handle: - Empty arrays with the `EmptyArray` pattern - Non-empty arrays with the `ArrayDecomp` pattern, which splits arrays into head and tail ## Testing Added a test that shows a practical application of list pattern matching: a recursive sum function defined as: ``` fn sum(arr: [I64]): I64 = match arr | [] -> 0 \ [head .. tail] -> head + sum(tail) ``` The test verifies that this function correctly computes: - `sum([]) = 0` - `sum([42]) = 42` - `sum([1, 2, 3]) = 6` ## Related Changes As part of this PR, I also simplified some syntax elements: - Changed the composition operator from `->` to `.` - Changed the match arrow from `=>` to `->`
- Loading branch information
Showing
14 changed files
with
435 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.