Skip to content

Conversation

@DominicPM
Copy link
Contributor

Implement Rust-style disjunctive patterns (p1 | p2) that work in all pattern contexts: match, match_switch, if let, let else, and for loops.

Changes:

  • Micro_Rust_Syntax.thy: Add _urust_match_pattern_disjunction syntax with right-associative precedence [1000, 100] 100
  • Core_Syntax.thy: Add shallow pattern syntax and expand disjunctions in parse_translation (expand_disjunction_pattern, expand_branch). Add switch branch translations for numeric disjunctive patterns.
  • Micro_Rust_Shallow_Embedding.thy: Add translation rule and handle nested disjunctions in shallow_match_pattern_of
  • Micro_Rust_Shallow_Embedding_Tests.thy: Add comprehensive tests including guards, nested patterns, and match_switch. Use three_case datatype for non-exhaustive if-let/let-else tests.

Examples now supported:

match x { Some(a) | None => ..., _ => ... }

match_switch n { 1 | 2 | 3 => ..., _ => ... }

if let CaseA(x) | CaseB(x) = val { ... }

let Ok(x) | Err(x) = result else { return; };

match nested { Some(Ok(x) | Err(x)) => x, _ => default }

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Make pattern translations total and tolerate wrapper forms to avoid Match in
  the bcase frontend.
- Allow nested patterns in constructor args by expanding collection/translation
  logic in Basic_Case_Expression.
- Normalize tuple patterns into Pair/TNil shape in the shallow match frontend.
- Improve shallow match arg translation to distinguish bindings vs constructors
  and handle nested tuple patterns.
- Add nested-pattern showcase/regression tests (Option/Result, tuples, wildcards,
  if-let and let-else forms).

Closes awslabs#65.

Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Can now use Boolean-valued pattern guards, for example:

```rust
match x with {
  Some(x) if x > 0 => ...,
  None => ...,
  _otherwise => ...
}
```

Closes awslabs#67.

Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Move all tests from Micro_Rust_Shallow_Embedding.thy into a new dedicated
test theory file organized by language feature category.

Changes:
- Create Micro_Rust_Shallow_Embedding_Tests.thy with tests organized into
  21 sections covering all Micro Rust syntax features
- Add missing shallow translations for compound assignment operators
  (-=, *=, %=, <<=, >>=) in Core_Syntax.thy and Micro_Rust_Shallow_Embedding.thy
- Fix double negation (!!) parsing by adding explicit syntax rule and
  AST translation to expand to nested single negations
- Fix double dereference (**) parsing similarly
- Add tests for error propagation (?), assert_eq!/assert_ne!, signed
  casts (i32, i64), and all compound assignment operators
- Update ROOT to include new test theory

Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Implement Rust-style disjunctive patterns (p1 | p2) that work in all
pattern contexts: match, match_switch, if let, let else, and for loops.

Changes:
- Micro_Rust_Syntax.thy: Add _urust_match_pattern_disjunction syntax
  with right-associative precedence [1000, 100] 100
- Core_Syntax.thy: Add shallow pattern syntax and expand disjunctions
  in parse_translation (expand_disjunction_pattern, expand_branch).
  Add switch branch translations for numeric disjunctive patterns.
- Micro_Rust_Shallow_Embedding.thy: Add translation rule and handle
  nested disjunctions in shallow_match_pattern_of
- Micro_Rust_Shallow_Embedding_Tests.thy: Add comprehensive tests
  including guards, nested patterns, and match_switch. Use three_case
  datatype for non-exhaustive if-let/let-else tests.

Examples now supported:
  match x { Some(a) | None => ..., _ => ... }
  match_switch n { 1 | 2 | 3 => ..., _ => ... }
  if let CaseA(x) | CaseB(x) = val { ... }
  let Ok(x) | Err(x) = result else { return; };
  match nested { Some(Ok(x) | Err(x)) => x, _ => default }

Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
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.

1 participant