ref: 89e514d5355f9036a30c4a41cacc465e5999aa76
parent: 682c4ce6114cb44e2ad95a75269585f6e1da8150
author: Ori Bernstein <[email protected]>
date: Mon Oct 28 11:39:01 EDT 2013
Streamline syntax. Move from: match foo bar: action ;; baz: action ;; To: match foo | bar: action | baz: action ;;
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -103,45 +103,35 @@
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)
--- a/libstd/htab.myr
+++ b/libstd/htab.myr
@@ -139,27 +139,25 @@
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
;;
}
--- a/libstd/option.myr
+++ b/libstd/option.myr
@@ -18,7 +18,7 @@
generic tryv = {v, msg, ap
match v
- `None: fatalv(1, msg, ap);;
- `Some a: -> a;;
+ | `None: fatalv(1, msg, ap)
+ | `Some a: -> a
;;
}
--- a/libstd/strcmp.myr
+++ b/libstd/strcmp.myr
@@ -50,8 +50,8 @@
const hasprefix = {s, pre
match strncmp(s, pre, pre.len)
- `Equal: -> true;;
- _: -> false;;
+ | `Equal: -> true
+ | _: -> false
;;
}
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -688,8 +688,8 @@
{$$ = 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
@@ -696,13 +696,12 @@
{$$.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;}
--- a/test/catfile.myr
+++ b/test/catfile.myr
@@ -6,8 +6,8 @@
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
}
--- a/test/genericmatch.myr
+++ b/test/genericmatch.myr
@@ -7,7 +7,7 @@
const main = {
match `Foo 123
- `Foo a: -> 0xf;;
- `Bar: -> 0x0;;
+ | `Foo a: -> 0xf
+ | `Bar: -> 0x0
;;
}
--- a/test/genericret.myr
+++ b/test/genericret.myr
@@ -11,7 +11,7 @@
const main = {
match f()
- `None: -> 42;;
+ | `None: -> 42
;;
-> 0
}
--- a/test/generictype.myr
+++ b/test/generictype.myr
@@ -11,8 +11,8 @@
v = `Some 123
match v
- `None: -> 1;;
- `Some 123: -> 0;;
+ | `None: -> 1
+ | `Some 123: -> 0
;;
-> 60
}
--- a/test/infer-named.myr
+++ b/test/infer-named.myr
@@ -14,8 +14,8 @@
v = f(99)
match v
- `Foo: -> 1;;
- `Bar x: -> x;;
+ | `Foo: -> 1
+ | `Bar x: -> x
;;
-> 2
}
--- a/test/matchargunion.myr
+++ b/test/matchargunion.myr
@@ -12,18 +12,10 @@
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
;;
}
--- a/test/matcharray.myr
+++ b/test/matcharray.myr
@@ -4,10 +4,9 @@
var v = [2, 40, 10]
match v
- [x, y, 10]:
+ | [x, y, 10]:
-> x + y
- ;;
- _: std.die("Wat");;
+ | _: std.die("Wat")
;;
-> 0
}
--- a/test/matchbind.myr
+++ b/test/matchbind.myr
@@ -12,18 +12,10 @@
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
;;
}
--- a/test/matchconst.myr
+++ b/test/matchconst.myr
@@ -11,8 +11,8 @@
v = 8
match v
- Ca: -> 123 ;;
- Cb: -> 88 ;;
- Cc: -> 42 ;;
+ | Ca: -> 123
+ | Cb: -> 88
+ | Cc: -> 42
;;
}
--- a/test/matchint.myr
+++ b/test/matchint.myr
@@ -5,23 +5,11 @@
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
;;
}
--- a/test/matchstruct.myr
+++ b/test/matchstruct.myr
@@ -13,12 +13,10 @@
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
}
--- a/test/matchtup.myr
+++ b/test/matchtup.myr
@@ -4,8 +4,8 @@
var v = (1, 2)
match v
- (1, x): -> 40 + x;;
- _: std.die("Wat");;
+ | (1, x): -> 40 + x
+ | _: std.die("Wat")
;;
-> 0
}
--- a/test/matchunion.myr
+++ b/test/matchunion.myr
@@ -13,17 +13,9 @@
v = `Foo
match v
- `Bar:
- -> 42
- ;;
- `Baz:
- -> 81
- ;;
- `Foo:
- -> 84
- ;;
- `Quux:
- -> 123
- ;;
+ | `Bar: -> 42
+ | `Baz: -> 81
+ | `Foo: -> 84
+ | `Quux: -> 123
;;
}
--- a/test/matchunion_sl.myr
+++ b/test/matchunion_sl.myr
@@ -12,18 +12,9 @@
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
}
--- a/test/stdopt-mk.myr
+++ b/test/stdopt-mk.myr
@@ -13,8 +13,8 @@
v = f(123)
match v
- `std.Some x: -> x;;
- `std.None: -> 123;;
+ | `std.Some x: -> x
+ | `std.None: -> 123
;;
}
--- a/test/stdopt-none.myr
+++ b/test/stdopt-none.myr
@@ -6,8 +6,8 @@
const main = {
match f()
- `std.Some x: -> x;;
- `std.None: -> 42;;
+ | `std.Some x: -> x
+ | `std.None: -> 42
;;
}
--- a/test/stdopt-some.myr
+++ b/test/stdopt-some.myr
@@ -2,8 +2,8 @@
const main = {
match `std.Some 42
- `std.Some x: -> x;;
- `std.None: -> 1;;
+ | `std.Some x: -> x
+ | `std.None: -> 1
;;
}