summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-10-28 15:39:01 -0400
committerOri Bernstein <ori@eigenstate.org>2013-10-28 15:39:01 -0400
commit89e514d5355f9036a30c4a41cacc465e5999aa76 (patch)
treef6402fddce8bde453291627cdd4d8db2ad0fd59e
parent682c4ce6114cb44e2ad95a75269585f6e1da8150 (diff)
downloadmc-89e514d5355f9036a30c4a41cacc465e5999aa76.tar.gz
Streamline syntax.
Move from: match foo bar: action ;; baz: action ;; To: match foo | bar: action | baz: action ;;
-rw-r--r--libstd/fmt.myr30
-rw-r--r--libstd/htab.myr14
-rw-r--r--libstd/option.myr4
-rw-r--r--libstd/strcmp.myr4
-rw-r--r--parse/gram.y11
-rw-r--r--test/catfile.myr4
-rw-r--r--test/genericmatch.myr4
-rw-r--r--test/genericret.myr2
-rw-r--r--test/generictype.myr4
-rw-r--r--test/infer-named.myr4
-rw-r--r--test/matchargunion.myr16
-rw-r--r--test/matcharray.myr5
-rw-r--r--test/matchbind.myr16
-rw-r--r--test/matchconst.myr6
-rw-r--r--test/matchint.myr24
-rw-r--r--test/matchstruct.myr8
-rw-r--r--test/matchtup.myr4
-rw-r--r--test/matchunion.myr16
-rw-r--r--test/matchunion_sl.myr15
-rw-r--r--test/stdopt-mk.myr4
-rw-r--r--test/stdopt-none.myr4
-rw-r--r--test/stdopt-some.myr4
22 files changed, 71 insertions, 132 deletions
diff --git a/libstd/fmt.myr b/libstd/fmt.myr
index a4f817b..85ae52d 100644
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -103,45 +103,35 @@ const bfmtv = {buf, fmt, ap
if c == '%'
(c, fmt) = striter(fmt)
match c
- 's':
+ | 's':
(s_val, ap) = vanext(ap)
n += strfmt(buf[n:], s_val)
- ;;
- 't':
+ | 't':
(t_val, ap) = vanext(ap)
n += boolfmt(buf[n:], t_val)
- ;;
/* format integers */
- 'b':
+ | 'b':
(b_val, ap) = vanext(ap)
n += intfmt(buf[n:], b_val castto(int64), 10)
- ;;
- 'w':
+ | 'w':
(w_val, ap) = vanext(ap)
n += intfmt(buf[n:], w_val castto(int64), 10)
- ;;
- 'i':
+ | 'i':
(i_val, ap) = vanext(ap)
n += intfmt(buf[n:], i_val castto(int64), 10)
- ;;
- 'l':
+ | 'l':
(l_val, ap) = vanext(ap)
n += intfmt(buf[n:], l_val castto(int64), 10)
- ;;
- 'z':
+ | 'z':
(z_val, ap) = vanext(ap)
n += intfmt(buf[n:], z_val castto(int64), 10)
- ;;
- 'p':
+ | 'p':
(p_val, ap) = vanext(ap)
n += intfmt(buf[n:], p_val castto(int64), 16)
- ;;
- 'c': (c_val, ap) = vanext(ap)
+ | 'c': (c_val, ap) = vanext(ap)
n += encode(buf[n:], c_val)
- ;;
- _:
+ | _:
die("Unknown format specifier")
- ;;
;;
else
n += encode(buf[n:], c)
diff --git a/libstd/htab.myr b/libstd/htab.myr
index 9c7fe46..15bea60 100644
--- a/libstd/htab.myr
+++ b/libstd/htab.myr
@@ -139,27 +139,25 @@ generic htput = {ht, k, v
generic htdel = {ht, k
match idx(ht, k)
- `Some i:
+ | `Some i:
ht.dead[i] = true
ht.nelt--
- ;;
- _:
+ | _:
/* do nothing */
- ;;
;;
}
generic htget = {ht, k
match idx(ht, k)
- `Some i: -> `Some ht.vals[i];;
- `None: -> `None;;
+ | `Some i: -> `Some ht.vals[i]
+ | `None: -> `None
;;
}
generic hthas = {ht, k
match idx(ht, k)
- `Some i: -> true;;
- `None: -> false;;
+ | `Some i: -> true
+ | `None: -> false
;;
}
diff --git a/libstd/option.myr b/libstd/option.myr
index fb64e31..63d398f 100644
--- a/libstd/option.myr
+++ b/libstd/option.myr
@@ -18,7 +18,7 @@ generic try = {v, msg, args
generic tryv = {v, msg, ap
match v
- `None: fatalv(1, msg, ap);;
- `Some a: -> a;;
+ | `None: fatalv(1, msg, ap)
+ | `Some a: -> a
;;
}
diff --git a/libstd/strcmp.myr b/libstd/strcmp.myr
index 33555c2..e6a6944 100644
--- a/libstd/strcmp.myr
+++ b/libstd/strcmp.myr
@@ -50,8 +50,8 @@ const strncmp = {a, b, n
const hasprefix = {s, pre
match strncmp(s, pre, pre.len)
- `Equal: -> true;;
- _: -> false;;
+ | `Equal: -> true
+ | _: -> false
;;
}
diff --git a/parse/gram.y b/parse/gram.y
index 85dedaa..0d86226 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -688,21 +688,20 @@ elifs : Telif exprln blkbody elifs
{$$ = NULL;}
;
-matchstmt: Tmatch exprln matches Tendblk
- {$$ = mkmatchstmt($1->line, $2, $3.nl, $3.nn);}
+matchstmt: Tmatch exprln Tbor matches Tendblk
+ {$$ = mkmatchstmt($1->line, $2, $4.nl, $4.nn);}
;
matches : match
{$$.nl = NULL; $$.nn = 0;
if ($1)
lappend(&$$.nl, &$$.nn, $1);}
- | matches match
+ | matches Tbor match
{if ($2)
- lappend(&$$.nl, &$$.nn, $2);}
+ lappend(&$$.nl, &$$.nn, $3);}
;
-match : pat Tcolon block {$$ = mkmatch($1->line, $1, $3);}
- | Tendln {$$ = NULL;}
+match : pat Tcolon blkbody Tendln {$$ = mkmatch($1->line, $1, $3);}
;
pat : unionpat {$$ = $1;}
diff --git a/test/catfile.myr b/test/catfile.myr
index d9e49a1..1500be7 100644
--- a/test/catfile.myr
+++ b/test/catfile.myr
@@ -6,8 +6,8 @@ const main = {args : byte[:][:]
r = std.slurp("data/catfile-in")
match r
- `std.Success dat: std.write(1, dat);;
- `std.Failure msg: std.put("Failed to read file: %s\n", msg);;
+ | `std.Success dat: std.write(1, dat)
+ | `std.Failure msg: std.put("Failed to read file: %s\n", msg)
;;
-> 0
}
diff --git a/test/genericmatch.myr b/test/genericmatch.myr
index fdc4666..6d582e7 100644
--- a/test/genericmatch.myr
+++ b/test/genericmatch.myr
@@ -7,7 +7,7 @@ type t(@a) = union
const main = {
match `Foo 123
- `Foo a: -> 0xf;;
- `Bar: -> 0x0;;
+ | `Foo a: -> 0xf
+ | `Bar: -> 0x0
;;
}
diff --git a/test/genericret.myr b/test/genericret.myr
index 5c292a7..7a597a7 100644
--- a/test/genericret.myr
+++ b/test/genericret.myr
@@ -11,7 +11,7 @@ const f = {-> t(int)
const main = {
match f()
- `None: -> 42;;
+ | `None: -> 42
;;
-> 0
}
diff --git a/test/generictype.myr b/test/generictype.myr
index 4b9c696..ae3c148 100644
--- a/test/generictype.myr
+++ b/test/generictype.myr
@@ -11,8 +11,8 @@ const main = {
v = `Some 123
match v
- `None: -> 1;;
- `Some 123: -> 0;;
+ | `None: -> 1
+ | `Some 123: -> 0
;;
-> 60
}
diff --git a/test/infer-named.myr b/test/infer-named.myr
index 002cc97..b2e517d 100644
--- a/test/infer-named.myr
+++ b/test/infer-named.myr
@@ -14,8 +14,8 @@ const main = {
v = f(99)
match v
- `Foo: -> 1;;
- `Bar x: -> x;;
+ | `Foo: -> 1
+ | `Bar x: -> x
;;
-> 2
}
diff --git a/test/matchargunion.myr b/test/matchargunion.myr
index 933b52e..5d3ae53 100644
--- a/test/matchargunion.myr
+++ b/test/matchargunion.myr
@@ -12,18 +12,10 @@ const main = {
v = `Int 123
match v
- `Int 127:
- -> 42
- ;;
- `Int 123:
- -> 69
- ;;
- `Chr 'a':
- -> 4
- ;;
- `Nil:
- -> 6
- ;;
+ | `Int 127: -> 42
+ | `Int 123: -> 69
+ | `Chr 'a': -> 4
+ | `Nil: -> 6
;;
}
diff --git a/test/matcharray.myr b/test/matcharray.myr
index 67e8efe..38e3688 100644
--- a/test/matcharray.myr
+++ b/test/matcharray.myr
@@ -4,10 +4,9 @@ const main = {
var v = [2, 40, 10]
match v
- [x, y, 10]:
+ | [x, y, 10]:
-> x + y
- ;;
- _: std.die("Wat");;
+ | _: std.die("Wat")
;;
-> 0
}
diff --git a/test/matchbind.myr b/test/matchbind.myr
index f1bb52d..9465d6c 100644
--- a/test/matchbind.myr
+++ b/test/matchbind.myr
@@ -12,18 +12,10 @@ const main = {
v = `Int 8
match v
- `Int 127:
- -> 42
- ;;
- `Int x:
- -> x
- ;;
- `Chr 'a':
- -> 4
- ;;
- `Nil:
- -> 6
- ;;
+ | `Int 127: -> 42
+ | `Int x: -> x
+ | `Chr 'a': -> 4
+ | `Nil: -> 6
;;
}
diff --git a/test/matchconst.myr b/test/matchconst.myr
index 6dd68e5..fad888b 100644
--- a/test/matchconst.myr
+++ b/test/matchconst.myr
@@ -11,8 +11,8 @@ const main = {
v = 8
match v
- Ca: -> 123 ;;
- Cb: -> 88 ;;
- Cc: -> 42 ;;
+ | Ca: -> 123
+ | Cb: -> 88
+ | Cc: -> 42
;;
}
diff --git a/test/matchint.myr b/test/matchint.myr
index fb9d63f..b198d9d 100644
--- a/test/matchint.myr
+++ b/test/matchint.myr
@@ -5,23 +5,11 @@ const main = {
v = 12
match 12
- 1:
- -> 42
- ;;
- 2:
- -> 81
- ;;
- 3:
- -> 123
- ;;
- 4:
- -> 99
- ;;
- 12:
- -> 84
- ;;
- 6:
- -> 18
- ;;
+ | 1: -> 42
+ | 2: -> 81
+ | 3: -> 123
+ | 4: -> 99
+ | 12: -> 84
+ | 6: -> 18
;;
}
diff --git a/test/matchstruct.myr b/test/matchstruct.myr
index 38bc5e0..e6bde0f 100644
--- a/test/matchstruct.myr
+++ b/test/matchstruct.myr
@@ -13,12 +13,10 @@ const main = {
v.v2 = 40
v.v3 = 10
match v
- [.v1 = x,
- .v2 = y,
- .v3 = 10]:
+ | [.v1 = x, .v2 = y, .v3 = 10]:
-> x + y
- ;;
- _: std.die("Wat");;
+ | _:
+ std.die("Wat")
;;
-> 0
}
diff --git a/test/matchtup.myr b/test/matchtup.myr
index 9515de9..85e3a10 100644
--- a/test/matchtup.myr
+++ b/test/matchtup.myr
@@ -4,8 +4,8 @@ const main = {
var v = (1, 2)
match v
- (1, x): -> 40 + x;;
- _: std.die("Wat");;
+ | (1, x): -> 40 + x
+ | _: std.die("Wat")
;;
-> 0
}
diff --git a/test/matchunion.myr b/test/matchunion.myr
index 734aa95..8eb1d77 100644
--- a/test/matchunion.myr
+++ b/test/matchunion.myr
@@ -13,17 +13,9 @@ const main = {
v = `Foo
match v
- `Bar:
- -> 42
- ;;
- `Baz:
- -> 81
- ;;
- `Foo:
- -> 84
- ;;
- `Quux:
- -> 123
- ;;
+ | `Bar: -> 42
+ | `Baz: -> 81
+ | `Foo: -> 84
+ | `Quux: -> 123
;;
}
diff --git a/test/matchunion_sl.myr b/test/matchunion_sl.myr
index c1fbf83..54ba664 100644
--- a/test/matchunion_sl.myr
+++ b/test/matchunion_sl.myr
@@ -12,18 +12,9 @@ const main = {
v = `Str "foo"
match v
- /*
- `Int 127:
- -> 42
- ;;
- */
- `Str s:
- std.put("%s\n", s)
- ;;
- /*
- `Nil:
- ;;
- */
+ | `Int 127: -> 42
+ | `Str s: std.put("%s\n", s)
+ | `Nil:
;;
-> 0
}
diff --git a/test/stdopt-mk.myr b/test/stdopt-mk.myr
index 770f986..dc97f7f 100644
--- a/test/stdopt-mk.myr
+++ b/test/stdopt-mk.myr
@@ -13,8 +13,8 @@ const main = {
v = f(123)
match v
- `std.Some x: -> x;;
- `std.None: -> 123;;
+ | `std.Some x: -> x
+ | `std.None: -> 123
;;
}
diff --git a/test/stdopt-none.myr b/test/stdopt-none.myr
index 3f2f6cd..62ec5e4 100644
--- a/test/stdopt-none.myr
+++ b/test/stdopt-none.myr
@@ -6,8 +6,8 @@ const f = {
const main = {
match f()
- `std.Some x: -> x;;
- `std.None: -> 42;;
+ | `std.Some x: -> x
+ | `std.None: -> 42
;;
}
diff --git a/test/stdopt-some.myr b/test/stdopt-some.myr
index 78a9fe4..179dc8e 100644
--- a/test/stdopt-some.myr
+++ b/test/stdopt-some.myr
@@ -2,8 +2,8 @@ use std
const main = {
match `std.Some 42
- `std.Some x: -> x;;
- `std.None: -> 1;;
+ | `std.Some x: -> x
+ | `std.None: -> 1
;;
}