summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-06-30 18:46:38 -0400
committerOri Bernstein <ori@eigenstate.org>2012-06-30 18:46:55 -0400
commitdfe3ca01782c70e9daf16165441af0eba8cfda8d (patch)
tree44906171daa76a75766a608b38e0696e4b4dfd5f
parent31d5350f573cf2b2c176082ae26de473ee1f885c (diff)
downloadmc-dfe3ca01782c70e9daf16165441af0eba8cfda8d.tar.gz
Add parenthesized submatches.
This allows clear, unambiguous sub-patterns.
-rw-r--r--parse/gram.y1
-rw-r--r--test/matchbind.myr26
2 files changed, 27 insertions, 0 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 478d95a..db09773 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -583,6 +583,7 @@ match : pat Tcolon block {$$ = mkmatch($1->line, $1, $3);}
pat : unionpat {$$ = $1;}
| littok {$$ = mkexpr($1->line, Olit, $1, NULL);}
| Tident {$$ = mkexpr($1->line, Ovar, mkname($1->line, $1->str), NULL);}
+ | Toparen pat Tcparen {$$ = $2;}
;
unionpat: Ttick Tident pat
diff --git a/test/matchbind.myr b/test/matchbind.myr
new file mode 100644
index 0000000..8d56185
--- /dev/null
+++ b/test/matchbind.myr
@@ -0,0 +1,26 @@
+type u = union
+ `Int int
+ `Chr char
+ `Nil
+;;
+
+const main = {
+ var v
+
+ v = `Int 11
+ match v
+ `Int 127:
+ -> 42
+ ;;
+ `Int (var x):
+ -> x
+ ;;
+ `Chr 'a':
+ -> 4
+ ;;
+ `Nil:
+ -> 6
+ ;;
+ ;;
+}
+