Convert alt to match. Stop parsing alt

This commit is contained in:
Brian Anderson 2012-08-06 12:34:08 -07:00
parent d3a9bb1bd4
commit ecaf9e39c9
359 changed files with 2938 additions and 2915 deletions

View file

@ -209,7 +209,7 @@ import export use mod
The keywords in [source files](#source-files) are the following strings: The keywords in [source files](#source-files) are the following strings:
~~~~~~~~ {.keyword} ~~~~~~~~ {.keyword}
alt again assert again assert
break break
check class const copy check class const copy
drop drop
@ -217,7 +217,7 @@ else enum export extern
fail false fn for fail false fn for
if impl import if impl import
let log loop let log loop
mod mut match mod mut
pure pure
return return
true trait type true trait type
@ -956,7 +956,7 @@ An example of a predicate that uses an unchecked block:
# import std::list::*; # import std::list::*;
fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U { fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
alt ls { match ls {
nil => u, nil => u,
cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f)) cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
} }
@ -1156,7 +1156,7 @@ class file_descriptor {
let mut name: option<~str>; let mut name: option<~str>;
} }
fn get_name() -> ~str { fn get_name() -> ~str {
alt self.name { match self.name {
none => fail ~"File has no name!", none => fail ~"File has no name!",
some(n) => n some(n) => n
} }
@ -2171,21 +2171,21 @@ evaluated. If all `if` and `else if` conditions evaluate to `false`
then any `else` block is executed. then any `else` block is executed.
### Alternative expressions ### Match expressions
~~~~~~~~{.ebnf .gram} ~~~~~~~~{.ebnf .gram}
alt_expr : "alt" expr '{' alt_arm [ '|' alt_arm ] * '}' ; match_expr : "match" expr '{' match_arm [ '|' match_arm ] * '}' ;
alt_arm : alt_pat '=>' expr_or_blockish ; match_arm : match_pat '=>' expr_or_blockish ;
alt_pat : pat [ "to" pat ] ? [ "if" expr ] ; match_pat : pat [ "to" pat ] ? [ "if" expr ] ;
~~~~~~~~ ~~~~~~~~
An `alt` expression branches on a *pattern*. The exact form of matching that A `match` expression branches on a *pattern*. The exact form of matching that
occurs depends on the pattern. Patterns consist of some combination of occurs depends on the pattern. Patterns consist of some combination of
literals, destructured enum constructors, records and tuples, variable binding literals, destructured enum constructors, records and tuples, variable binding
specifications, wildcards (`*`), and placeholders (`_`). An `alt` expression has a *head specifications, wildcards (`*`), and placeholders (`_`). A `match` expression has a *head
expression*, which is the value to compare to the patterns. The type of the expression*, which is the value to compare to the patterns. The type of the
patterns must equal the type of the head expression. patterns must equal the type of the head expression.
@ -2198,7 +2198,7 @@ enum list<X> { nil, cons(X, @list<X>) }
let x: list<int> = cons(10, @cons(11, @nil)); let x: list<int> = cons(10, @cons(11, @nil));
alt x { match x {
cons(_, @nil) => fail ~"singleton list", cons(_, @nil) => fail ~"singleton list",
cons(*) => return, cons(*) => return,
nil => fail ~"empty list" nil => fail ~"empty list"
@ -2210,13 +2210,13 @@ tail value of `@nil`. The second pattern matches `any` list constructed with `co
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
`C` has exactly one argument, while the pattern `C(*)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has. `C` has exactly one argument, while the pattern `C(*)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
To execute an `alt` expression, first the head expression is evaluated, then To execute an `match` expression, first the head expression is evaluated, then
its value is sequentially compared to the patterns in the arms until a match its value is sequentially compared to the patterns in the arms until a match
is found. The first arm with a matching pattern is chosen as the branch target is found. The first arm with a matching pattern is chosen as the branch target
of the `alt`, any variables bound by the pattern are assigned to local of the `match`, any variables bound by the pattern are assigned to local
variables in the arm's block, and control enters the block. variables in the arm's block, and control enters the block.
An example of an `alt` expression: An example of an `match` expression:
~~~~ ~~~~
@ -2227,7 +2227,7 @@ enum list<X> { nil, cons(X, @list<X>) }
let x: list<int> = cons(10, @cons(11, @nil)); let x: list<int> = cons(10, @cons(11, @nil));
alt x { match x {
cons(a, @cons(b, _)) => { cons(a, @cons(b, _)) => {
process_pair(a,b); process_pair(a,b);
} }
@ -2264,7 +2264,7 @@ fn main() {
} }
}; };
alt r { match r {
{options: {choose: true, _}, _} => { {options: {choose: true, _}, _} => {
choose_player(r) choose_player(r)
} }
@ -2278,20 +2278,20 @@ fn main() {
} }
~~~~ ~~~~
Multiple alternative patterns may be joined with the `|` operator. A Multiple match patterns may be joined with the `|` operator. A
range of values may be specified with `to`. For example: range of values may be specified with `to`. For example:
~~~~ ~~~~
# let x = 2; # let x = 2;
let message = alt x { let message = match x {
0 | 1 => ~"not many", 0 | 1 => ~"not many",
2 to 9 => ~"a few", 2 to 9 => ~"a few",
_ => ~"lots" _ => ~"lots"
}; };
~~~~ ~~~~
Finally, alt patterns can accept *pattern guards* to further refine the Finally, match patterns can accept *pattern guards* to further refine the
criteria for matching a case. Pattern guards appear after the pattern and criteria for matching a case. Pattern guards appear after the pattern and
consist of a bool-typed expression following the `if` keyword. A pattern consist of a bool-typed expression following the `if` keyword. A pattern
guard may refer to the variables bound within the pattern they follow. guard may refer to the variables bound within the pattern they follow.
@ -2301,7 +2301,7 @@ guard may refer to the variables bound within the pattern they follow.
# fn process_digit(i: int) { } # fn process_digit(i: int) { }
# fn process_other(i: int) { } # fn process_other(i: int) { }
let message = alt maybe_digit { let message = match maybe_digit {
some(x) if x < 10 => process_digit(x), some(x) if x < 10 => process_digit(x),
some(x) => process_other(x), some(x) => process_other(x),
none => fail none => fail

View file

@ -116,7 +116,7 @@ fn main() {
let pick = || (~[rock, paper, scissors])[rng.gen_uint() % 3]; let pick = || (~[rock, paper, scissors])[rng.gen_uint() % 3];
// Pick two gestures and decide the result // Pick two gestures and decide the result
alt (pick(), pick()) { match (pick(), pick()) {
(rock, scissors) | (paper, rock) | (scissors, paper) => copy player1, (rock, scissors) | (paper, rock) | (scissors, paper) => copy player1,
(scissors, rock) | (rock, paper) | (paper, scissors) => copy player2, (scissors, rock) | (rock, paper) | (paper, scissors) => copy player2,
_ => ~"tie" _ => ~"tie"
@ -707,14 +707,14 @@ have type `int`, because control doesn't reach the end of that arm
## Pattern matching ## Pattern matching
Rust's `alt` construct is a generalized, cleaned-up version of C's Rust's `match` construct is a generalized, cleaned-up version of C's
`switch` construct. You provide it with a value and a number of arms, `switch` construct. You provide it with a value and a number of arms,
each labelled with a pattern, and it will execute the arm that matches each labelled with a pattern, and it will execute the arm that matches
the value. the value.
~~~~ ~~~~
# let my_number = 1; # let my_number = 1;
alt my_number { match my_number {
0 => io::println(~"zero"), 0 => io::println(~"zero"),
1 | 2 => io::println(~"one or two"), 1 | 2 => io::println(~"one or two"),
3 to 10 => io::println(~"three to ten"), 3 to 10 => io::println(~"three to ten"),
@ -732,14 +732,14 @@ valid patterns, and will match only their own value. The pipe operator
of numeric literal patterns can be expressed with `to`. The underscore of numeric literal patterns can be expressed with `to`. The underscore
(`_`) is a wildcard pattern that matches everything. (`_`) is a wildcard pattern that matches everything.
The patterns in an alt arm are followed by a fat arrow, `=>`, then an The patterns in an match arm are followed by a fat arrow, `=>`, then an
expression to evaluate. Each case is separated by commas. It's often expression to evaluate. Each case is separated by commas. It's often
convenient to use a block expression for a case, in which case the convenient to use a block expression for a case, in which case the
commas are optional. commas are optional.
~~~ ~~~
# let my_number = 1; # let my_number = 1;
alt my_number { match my_number {
0 => { 0 => {
io::println(~"zero") io::println(~"zero")
} }
@ -750,9 +750,9 @@ alt my_number {
~~~ ~~~
If the arm with the wildcard pattern was left off in the above If the arm with the wildcard pattern was left off in the above
example, the typechecker would reject it at compile time. `alt` example, the typechecker would reject it at compile time. `match`
constructs must be exhaustive: they must have an arm covering every constructs must be exhaustive: they must have an arm covering every
possible case. (You may use the `alt check` construct to write a possible case. (You may use the `match check` construct to write a
non-exhaustive match, but it's highly undesirable to do so. You may non-exhaustive match, but it's highly undesirable to do so. You may
reason that the missing cases will never occur, but the typechecker reason that the missing cases will never occur, but the typechecker
provides you with no assurance that your reasoning is correct.) provides you with no assurance that your reasoning is correct.)
@ -763,7 +763,7 @@ that `(float, float)` is a tuple of two floats:
~~~~ ~~~~
fn angle(vec: (float, float)) -> float { fn angle(vec: (float, float)) -> float {
alt vec { match vec {
(0f, y) if y < 0f => 1.5 * float::consts::pi, (0f, y) if y < 0f => 1.5 * float::consts::pi,
(0f, y) => 0.5 * float::consts::pi, (0f, y) => 0.5 * float::consts::pi,
(x, y) => float::atan(y / x) (x, y) => float::atan(y / x)
@ -777,7 +777,7 @@ y)` matches any tuple whose first element is zero, and binds `y` to
the second element. `(x, y)` matches any tuple, and binds both the second element. `(x, y)` matches any tuple, and binds both
elements to a variable. elements to a variable.
Any `alt` arm can have a guard clause (written `if EXPR`), which is Any `match` arm can have a guard clause (written `if EXPR`), which is
an expression of type `bool` that determines, after the pattern is an expression of type `bool` that determines, after the pattern is
found to match, whether the arm is taken or not. The variables bound found to match, whether the arm is taken or not. The variables bound
by the pattern are available in this guard expression. by the pattern are available in this guard expression.
@ -851,7 +851,7 @@ task failure:
* Accessing an out-of-bounds element of a vector. * Accessing an out-of-bounds element of a vector.
* Having no clauses match when evaluating an `alt check` expression. * Having no clauses match when evaluating an `match check` expression.
* An assertion failure. * An assertion failure.
@ -1044,14 +1044,14 @@ not an actual new type.)
## Record patterns ## Record patterns
Records can be destructured in `alt` patterns. The basic syntax is Records can be destructured in `match` patterns. The basic syntax is
`{fieldname: pattern, ...}`, but the pattern for a field can be `{fieldname: pattern, ...}`, but the pattern for a field can be
omitted as a shorthand for simply binding the variable with the same omitted as a shorthand for simply binding the variable with the same
name as the field. name as the field.
~~~~ ~~~~
# let mypoint = {x: 0f, y: 0f}; # let mypoint = {x: 0f, y: 0f};
alt mypoint { match mypoint {
{x: 0f, y: y_name} => { /* Provide sub-patterns for fields */ } {x: 0f, y: y_name} => { /* Provide sub-patterns for fields */ }
{x, y} => { /* Simply bind the fields */ } {x, y} => { /* Simply bind the fields */ }
} }
@ -1157,7 +1157,7 @@ patterns, as in this definition of `area`:
# type point = {x: float, y: float}; # type point = {x: float, y: float};
# enum shape { circle(point, float), rectangle(point, point) } # enum shape { circle(point, float), rectangle(point, point) }
fn area(sh: shape) -> float { fn area(sh: shape) -> float {
alt sh { match sh {
circle(_, size) => float::consts::pi * size * size, circle(_, size) => float::consts::pi * size * size,
rectangle({x, y}, {x: x2, y: y2}) => (x2 - x) * (y2 - y) rectangle({x, y}, {x: x2, y: y2}) => (x2 - x) * (y2 - y)
} }
@ -1170,7 +1170,7 @@ Another example, matching nullary enum variants:
# type point = {x: float, y: float}; # type point = {x: float, y: float};
# enum direction { north, east, south, west } # enum direction { north, east, south, west }
fn point_from_direction(dir: direction) -> point { fn point_from_direction(dir: direction) -> point {
alt dir { match dir {
north => {x: 0f, y: 1f}, north => {x: 0f, y: 1f},
east => {x: 1f, y: 0f}, east => {x: 1f, y: 0f},
south => {x: 0f, y: -1f}, south => {x: 0f, y: -1f},
@ -1188,7 +1188,7 @@ nil, `()`, as the empty tuple if you like).
~~~~ ~~~~
let mytup: (int, int, float) = (10, 20, 30.0); let mytup: (int, int, float) = (10, 20, 30.0);
alt mytup { match mytup {
(a, b, c) => log(info, a + b + (c as int)) (a, b, c) => log(info, a + b + (c as int))
} }
~~~~ ~~~~
@ -1922,7 +1922,7 @@ gets access to them.
## Other uses of safe references ## Other uses of safe references
Safe references are not only used for argument passing. When you Safe references are not only used for argument passing. When you
destructure on a value in an `alt` expression, or loop over a vector destructure on a value in a `match` expression, or loop over a vector
with `for`, variables bound to the inside of the given data structure with `for`, variables bound to the inside of the given data structure
will use safe references, not copies. This means such references are will use safe references, not copies. This means such references are
very cheap, but you'll occasionally have to copy them to ensure very cheap, but you'll occasionally have to copy them to ensure
@ -1930,7 +1930,7 @@ safety.
~~~~ ~~~~
let mut my_rec = {a: 4, b: ~[1, 2, 3]}; let mut my_rec = {a: 4, b: ~[1, 2, 3]};
alt my_rec { match my_rec {
{a, b} => { {a, b} => {
log(info, b); // This is okay log(info, b); // This is okay
my_rec = {a: a + 1, b: b + ~[a]}; my_rec = {a: a + 1, b: b + ~[a]};

View file

@ -128,7 +128,7 @@ fn is_uuid(id: ~str) -> bool {
return false; return false;
} }
alt i { match i {
0u => { 0u => {
if str::len(part) == 8u { if str::len(part) == 8u {
correct += 1u; correct += 1u;
@ -192,7 +192,7 @@ fn is_archive_url(u: ~str) -> bool {
// FIXME (#2661): this requires the protocol bit - if we had proper // FIXME (#2661): this requires the protocol bit - if we had proper
// url parsing, we wouldn't need it // url parsing, we wouldn't need it
alt str::find_str(u, ~"://") { match str::find_str(u, ~"://") {
option::some(i) => has_archive_extension(u), option::some(i) => has_archive_extension(u),
_ => false _ => false
} }
@ -223,9 +223,9 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>,
let mut vers = none; let mut vers = none;
let mut uuid = none; let mut uuid = none;
for mis.each |a| { for mis.each |a| {
alt a.node { match a.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => { ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
alt *v { match *v {
~"name" => name = some(*s), ~"name" => name = some(*s),
~"vers" => vers = some(*s), ~"vers" => vers = some(*s),
~"uuid" => uuid = some(*s), ~"uuid" => uuid = some(*s),
@ -250,9 +250,9 @@ fn load_crate(filename: ~str) -> option<crate> {
let mut crate_type = none; let mut crate_type = none;
for c.node.attrs.each |a| { for c.node.attrs.each |a| {
alt a.node.value.node { match a.node.value.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => { ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
alt *v { match *v {
~"desc" => desc = some(*v), ~"desc" => desc = some(*v),
~"sigs" => sigs = some(*v), ~"sigs" => sigs = some(*v),
~"crate_type" => crate_type = some(*v), ~"crate_type" => crate_type = some(*v),
@ -279,7 +279,7 @@ fn load_crate(filename: ~str) -> option<crate> {
}; };
fn goto_view_item(e: env, i: @ast::view_item) { fn goto_view_item(e: env, i: @ast::view_item) {
alt i.node { match i.node {
ast::view_item_use(ident, metas, id) => { ast::view_item_use(ident, metas, id) => {
let name_items = let name_items =
attr::find_meta_items_by_name(metas, ~"name"); attr::find_meta_items_by_name(metas, ~"name");
@ -293,11 +293,11 @@ fn load_crate(filename: ~str) -> option<crate> {
let mut attr_from = ~""; let mut attr_from = ~"";
for m.each |item| { for m.each |item| {
alt attr::get_meta_item_value_str(item) { match attr::get_meta_item_value_str(item) {
some(value) => { some(value) => {
let name = attr::get_meta_item_name(item); let name = attr::get_meta_item_name(item);
alt *name { match *name {
~"vers" => attr_vers = *value, ~"vers" => attr_vers = *value,
~"from" => attr_from = *value, ~"from" => attr_from = *value,
_ => () _ => ()
@ -315,7 +315,7 @@ fn load_crate(filename: ~str) -> option<crate> {
} else { *attr_name } } else { *attr_name }
}; };
alt *attr_name { match *attr_name {
~"std" | ~"core" => (), ~"std" | ~"core" => (),
_ => vec::push(e.deps, query) _ => vec::push(e.deps, query)
} }
@ -339,7 +339,7 @@ fn load_crate(filename: ~str) -> option<crate> {
let deps = copy e.deps; let deps = copy e.deps;
alt (name, vers, uuid) { match (name, vers, uuid) {
(some(name0), some(vers0), some(uuid0)) => { (some(name0), some(vers0), some(uuid0)) => {
some({ some({
name: name0, name: name0,
@ -390,21 +390,21 @@ fn parse_source(name: ~str, j: json::json) -> source {
fail fmt!{"'%s' is an invalid source name", name}; fail fmt!{"'%s' is an invalid source name", name};
} }
alt j { match j {
json::dict(j) => { json::dict(j) => {
let mut url = alt j.find(~"url") { let mut url = match j.find(~"url") {
some(json::string(u)) => *u, some(json::string(u)) => *u,
_ => fail ~"needed 'url' field in source" _ => fail ~"needed 'url' field in source"
}; };
let method = alt j.find(~"method") { let method = match j.find(~"method") {
some(json::string(u)) => *u, some(json::string(u)) => *u,
_ => assume_source_method(url) _ => assume_source_method(url)
}; };
let key = alt j.find(~"key") { let key = match j.find(~"key") {
some(json::string(u)) => some(*u), some(json::string(u)) => some(*u),
_ => none _ => none
}; };
let keyfp = alt j.find(~"keyfp") { let keyfp = match j.find(~"keyfp") {
some(json::string(u)) => some(*u), some(json::string(u)) => some(*u),
_ => none _ => none
}; };
@ -426,7 +426,7 @@ fn parse_source(name: ~str, j: json::json) -> source {
fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) { fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
if !os::path_exists(filename) { return; } if !os::path_exists(filename) { return; }
let c = io::read_whole_file_str(filename); let c = io::read_whole_file_str(filename);
alt json::from_str(result::get(c)) { match json::from_str(result::get(c)) {
ok(json::dict(j)) => { ok(json::dict(j)) => {
for j.each |k, v| { for j.each |k, v| {
sources.insert(k, parse_source(k, v)); sources.insert(k, parse_source(k, v));
@ -439,7 +439,7 @@ fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
} }
fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) { fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
let name = alt p.find(~"name") { let name = match p.find(~"name") {
some(json::string(n)) => { some(json::string(n)) => {
if !valid_pkg_name(*n) { if !valid_pkg_name(*n) {
warn(~"malformed source json: " warn(~"malformed source json: "
@ -456,7 +456,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
} }
}; };
let uuid = alt p.find(~"uuid") { let uuid = match p.find(~"uuid") {
some(json::string(n)) => { some(json::string(n)) => {
if !is_uuid(*n) { if !is_uuid(*n) {
warn(~"malformed source json: " warn(~"malformed source json: "
@ -472,7 +472,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
} }
}; };
let url = alt p.find(~"url") { let url = match p.find(~"url") {
some(json::string(n)) => *n, some(json::string(n)) => *n,
_ => { _ => {
warn(~"malformed source json: " + src.name + ~" (missing url)"); warn(~"malformed source json: " + src.name + ~" (missing url)");
@ -480,7 +480,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
} }
}; };
let method = alt p.find(~"method") { let method = match p.find(~"method") {
some(json::string(n)) => *n, some(json::string(n)) => *n,
_ => { _ => {
warn(~"malformed source json: " warn(~"malformed source json: "
@ -489,16 +489,16 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
} }
}; };
let reference = alt p.find(~"ref") { let reference = match p.find(~"ref") {
some(json::string(n)) => some(*n), some(json::string(n)) => some(*n),
_ => none _ => none
}; };
let mut tags = ~[]; let mut tags = ~[];
alt p.find(~"tags") { match p.find(~"tags") {
some(json::list(js)) => { some(json::list(js)) => {
for (*js).each |j| { for (*js).each |j| {
alt j { match j {
json::string(j) => vec::grow(tags, 1u, *j), json::string(j) => vec::grow(tags, 1u, *j),
_ => () _ => ()
} }
@ -507,7 +507,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
_ => () _ => ()
} }
let description = alt p.find(~"description") { let description = match p.find(~"description") {
some(json::string(n)) => *n, some(json::string(n)) => *n,
_ => { _ => {
warn(~"malformed source json: " + src.name warn(~"malformed source json: " + src.name
@ -527,7 +527,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
versions: ~[] versions: ~[]
}; };
alt vec::position(src.packages, |pkg| pkg.uuid == uuid) { match vec::position(src.packages, |pkg| pkg.uuid == uuid) {
some(idx) => { some(idx) => {
src.packages[idx] = newpkg; src.packages[idx] = newpkg;
log(debug, ~" updated package: " + src.name + ~"/" + name); log(debug, ~" updated package: " + src.name + ~"/" + name);
@ -545,7 +545,7 @@ fn load_source_info(c: cargo, src: source) {
let srcfile = path::connect(dir, ~"source.json"); let srcfile = path::connect(dir, ~"source.json");
if !os::path_exists(srcfile) { return; } if !os::path_exists(srcfile) { return; }
let srcstr = io::read_whole_file_str(srcfile); let srcstr = io::read_whole_file_str(srcfile);
alt json::from_str(result::get(srcstr)) { match json::from_str(result::get(srcstr)) {
ok(json::dict(s)) => { ok(json::dict(s)) => {
let o = parse_source(src.name, json::dict(s)); let o = parse_source(src.name, json::dict(s));
@ -567,10 +567,10 @@ fn load_source_packages(c: cargo, src: source) {
let pkgfile = path::connect(dir, ~"packages.json"); let pkgfile = path::connect(dir, ~"packages.json");
if !os::path_exists(pkgfile) { return; } if !os::path_exists(pkgfile) { return; }
let pkgstr = io::read_whole_file_str(pkgfile); let pkgstr = io::read_whole_file_str(pkgfile);
alt json::from_str(result::get(pkgstr)) { match json::from_str(result::get(pkgstr)) {
ok(json::list(js)) => { ok(json::list(js)) => {
for (*js).each |j| { for (*js).each |j| {
alt j { match j {
json::dict(p) => { json::dict(p) => {
load_one_source_package(src, p); load_one_source_package(src, p);
} }
@ -592,7 +592,7 @@ fn load_source_packages(c: cargo, src: source) {
} }
fn build_cargo_options(argv: ~[~str]) -> options { fn build_cargo_options(argv: ~[~str]) -> options {
let matches = alt getopts::getopts(argv, opts()) { let matches = match getopts::getopts(argv, opts()) {
result::ok(m) => m, result::ok(m) => m,
result::err(f) => { result::err(f) => {
fail fmt!{"%s", getopts::fail_str(f)}; fail fmt!{"%s", getopts::fail_str(f)};
@ -623,12 +623,12 @@ fn build_cargo_options(argv: ~[~str]) -> options {
} }
fn configure(opts: options) -> cargo { fn configure(opts: options) -> cargo {
let home = alt get_cargo_root() { let home = match get_cargo_root() {
ok(home) => home, ok(home) => home,
err(_err) => result::get(get_cargo_sysroot()) err(_err) => result::get(get_cargo_sysroot())
}; };
let get_cargo_dir = alt opts.mode { let get_cargo_dir = match opts.mode {
system_mode => get_cargo_sysroot, system_mode => get_cargo_sysroot,
user_mode => get_cargo_root, user_mode => get_cargo_root,
local_mode => get_cargo_root_nearest local_mode => get_cargo_root_nearest
@ -716,7 +716,7 @@ fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
} }
fn test_one_crate(_c: cargo, path: ~str, cf: ~str) { fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
let buildpath = alt run_in_buildpath(~"testing", path, ~"/test", cf, let buildpath = match run_in_buildpath(~"testing", path, ~"/test", cf,
~[ ~"--test"]) { ~[ ~"--test"]) {
none => return, none => return,
some(bp) => bp some(bp) => bp
@ -725,7 +725,7 @@ fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
} }
fn install_one_crate(c: cargo, path: ~str, cf: ~str) { fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
let buildpath = alt run_in_buildpath(~"installing", path, let buildpath = match run_in_buildpath(~"installing", path,
~"/build", cf, ~[]) { ~"/build", cf, ~[]) {
none => return, none => return,
some(bp) => bp some(bp) => bp
@ -752,7 +752,7 @@ fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
fn rustc_sysroot() -> ~str { fn rustc_sysroot() -> ~str {
alt os::self_exe_path() { match os::self_exe_path() {
some(path) => { some(path) => {
let path = ~[path, ~"..", ~"bin", ~"rustc"]; let path = ~[path, ~"..", ~"bin", ~"rustc"];
let rustc = path::normalize(path::connect_many(path)); let rustc = path::normalize(path::connect_many(path));
@ -779,7 +779,7 @@ fn install_source(c: cargo, path: ~str) {
} }
for cratefiles.each |cf| { for cratefiles.each |cf| {
alt load_crate(cf) { match load_crate(cf) {
none => again, none => again,
some(crate) => { some(crate) => {
for crate.deps.each |query| { for crate.deps.each |query| {
@ -788,7 +788,7 @@ fn install_source(c: cargo, path: ~str) {
// condition") // condition")
let wd_base = c.workdir + path::path_sep(); let wd_base = c.workdir + path::path_sep();
let wd = alt tempfile::mkdtemp(wd_base, ~"") { let wd = match tempfile::mkdtemp(wd_base, ~"") {
some(wd) => wd, some(wd) => wd,
none => fail fmt!{"needed temp dir: %s", wd_base} none => fail fmt!{"needed temp dir: %s", wd_base}
}; };
@ -838,7 +838,7 @@ fn install_file(c: cargo, wd: ~str, path: ~str) {
fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) { fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
let url = copy pkg.url; let url = copy pkg.url;
let method = alt pkg.method { let method = match pkg.method {
~"git" => ~"git", ~"git" => ~"git",
~"file" => ~"file", ~"file" => ~"file",
_ => ~"curl" _ => ~"curl"
@ -846,7 +846,7 @@ fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
info(fmt!{"installing %s/%s via %s...", src, pkg.name, method}); info(fmt!{"installing %s/%s via %s...", src, pkg.name, method});
alt method { match method {
~"git" => install_git(c, wd, url, copy pkg.reference), ~"git" => install_git(c, wd, url, copy pkg.reference),
~"file" => install_file(c, wd, url), ~"file" => install_file(c, wd, url),
~"curl" => install_curl(c, wd, copy url), ~"curl" => install_curl(c, wd, copy url),
@ -913,7 +913,7 @@ fn install_named(c: cargo, wd: ~str, name: ~str) {
} }
fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) { fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
alt c.sources.find(src) { match c.sources.find(src) {
some(s) => { some(s) => {
let packages = copy s.packages; let packages = copy s.packages;
if vec::any(packages, |p| { if vec::any(packages, |p| {
@ -929,7 +929,7 @@ fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
} }
fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) { fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
alt c.sources.find(src) { match c.sources.find(src) {
some(s) => { some(s) => {
let packages = copy s.packages; let packages = copy s.packages;
if vec::any(packages, |p| { if vec::any(packages, |p| {
@ -960,7 +960,7 @@ fn cmd_uninstall(c: cargo) {
// name only) // name only)
if is_uuid(target) { if is_uuid(target) {
for os::list_dir(lib).each |file| { for os::list_dir(lib).each |file| {
alt str::find_str(file, ~"-" + target + ~"-") { match str::find_str(file, ~"-" + target + ~"-") {
some(idx) => { some(idx) => {
let full = path::normalize(path::connect(lib, file)); let full = path::normalize(path::connect(lib, file));
if os::remove_file(full) { if os::remove_file(full) {
@ -977,7 +977,7 @@ fn cmd_uninstall(c: cargo) {
error(~"can't find package with uuid: " + target); error(~"can't find package with uuid: " + target);
} else { } else {
for os::list_dir(lib).each |file| { for os::list_dir(lib).each |file| {
alt str::find_str(file, ~"lib" + target + ~"-") { match str::find_str(file, ~"lib" + target + ~"-") {
some(idx) => { some(idx) => {
let full = path::normalize(path::connect(lib, let full = path::normalize(path::connect(lib,
file)); file));
@ -992,7 +992,7 @@ fn cmd_uninstall(c: cargo) {
} }
} }
for os::list_dir(bin).each |file| { for os::list_dir(bin).each |file| {
alt str::find_str(file, target) { match str::find_str(file, target) {
some(idx) => { some(idx) => {
let full = path::normalize(path::connect(bin, file)); let full = path::normalize(path::connect(bin, file));
if os::remove_file(full) { if os::remove_file(full) {
@ -1011,7 +1011,7 @@ fn cmd_uninstall(c: cargo) {
} }
fn install_query(c: cargo, wd: ~str, target: ~str) { fn install_query(c: cargo, wd: ~str, target: ~str) {
alt c.dep_cache.find(target) { match c.dep_cache.find(target) {
some(inst) => { some(inst) => {
if inst { if inst {
return; return;
@ -1038,7 +1038,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
} else { } else {
let mut ps = copy target; let mut ps = copy target;
alt str::find_char(ps, '/') { match str::find_char(ps, '/') {
option::some(idx) => { option::some(idx) => {
let source = str::slice(ps, 0u, idx); let source = str::slice(ps, 0u, idx);
ps = str::slice(ps, idx + 1u, str::len(ps)); ps = str::slice(ps, idx + 1u, str::len(ps));
@ -1072,7 +1072,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
fn cmd_install(c: cargo) unsafe { fn cmd_install(c: cargo) unsafe {
let wd_base = c.workdir + path::path_sep(); let wd_base = c.workdir + path::path_sep();
let wd = alt tempfile::mkdtemp(wd_base, ~"") { let wd = match tempfile::mkdtemp(wd_base, ~"") {
some(wd) => wd, some(wd) => wd,
none => fail fmt!{"needed temp dir: %s", wd_base} none => fail fmt!{"needed temp dir: %s", wd_base}
}; };
@ -1129,7 +1129,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
os::copy_file(path::connect(url, ~"source.json.sig"), srcsigfile); os::copy_file(path::connect(url, ~"source.json.sig"), srcsigfile);
os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile); os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile);
alt copy src.key { match copy src.key {
some(u) => { some(u) => {
let p = run::program_output(~"curl", let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]); ~[~"-f", ~"-s", ~"-o", keyfile, u]);
@ -1141,7 +1141,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
} }
_ => () _ => ()
} }
alt (src.key, src.keyfp) { match (src.key, src.keyfp) {
(some(_), some(f)) => { (some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f); let r = pgp::verify(c.root, pkgfile, sigfile, f);
@ -1238,7 +1238,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
let has_src_file = os::path_exists(srcfile); let has_src_file = os::path_exists(srcfile);
alt copy src.key { match copy src.key {
some(u) => { some(u) => {
let p = run::program_output(~"curl", let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]); ~[~"-f", ~"-s", ~"-o", keyfile, u]);
@ -1251,7 +1251,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
} }
_ => () _ => ()
} }
alt (src.key, src.keyfp) { match (src.key, src.keyfp) {
(some(_), some(f)) => { (some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f); let r = pgp::verify(c.root, pkgfile, sigfile, f);
@ -1318,7 +1318,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
} }
} }
alt copy src.key { match copy src.key {
some(u) => { some(u) => {
let p = run::program_output(~"curl", let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]); ~[~"-f", ~"-s", ~"-o", keyfile, u]);
@ -1330,7 +1330,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
} }
_ => () _ => ()
} }
alt (src.key, src.keyfp) { match (src.key, src.keyfp) {
(some(_), some(f)) => { (some(_), some(f)) => {
if smart { if smart {
url = src.url + ~"/packages.json.sig"; url = src.url + ~"/packages.json.sig";
@ -1403,7 +1403,7 @@ fn sync_one(c: cargo, src: source) {
need_dir(dir); need_dir(dir);
let result = alt src.method { let result = match src.method {
~"git" => sync_one_git(c, dir, src), ~"git" => sync_one_git(c, dir, src),
~"file" => sync_one_file(c, dir, src), ~"file" => sync_one_file(c, dir, src),
_ => sync_one_curl(c, dir, src) _ => sync_one_curl(c, dir, src)
@ -1490,7 +1490,7 @@ fn cmd_list(c: cargo) {
if !valid_pkg_name(name) { if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name}); error(fmt!{"'%s' is an invalid source name", name});
} else { } else {
alt c.sources.find(name) { match c.sources.find(name) {
some(source) => { some(source) => {
print_source(source); print_source(source);
} }
@ -1562,7 +1562,7 @@ fn dump_sources(c: cargo) {
copy_warn(out, path::connect(c.root, ~"sources.json.old")); copy_warn(out, path::connect(c.root, ~"sources.json.old"));
} }
alt io::buffered_file_writer(out) { match io::buffered_file_writer(out) {
result::ok(writer) => { result::ok(writer) => {
let hash = map::str_hash(); let hash = map::str_hash();
let root = json::dict(hash); let root = json::dict(hash);
@ -1574,13 +1574,13 @@ fn dump_sources(c: cargo) {
chash.insert(~"url", json::string(@v.url)); chash.insert(~"url", json::string(@v.url));
chash.insert(~"method", json::string(@v.method)); chash.insert(~"method", json::string(@v.method));
alt copy v.key { match copy v.key {
some(key) => { some(key) => {
chash.insert(~"key", json::string(@key)); chash.insert(~"key", json::string(@key));
} }
_ => () _ => ()
} }
alt copy v.keyfp { match copy v.keyfp {
some(keyfp) => { some(keyfp) => {
chash.insert(~"keyfp", json::string(@keyfp)); chash.insert(~"keyfp", json::string(@keyfp));
} }
@ -1615,7 +1615,7 @@ fn cmd_sources(c: cargo) {
let action = c.opts.free[2u]; let action = c.opts.free[2u];
alt action { match action {
~"clear" => { ~"clear" => {
for c.sources.each_key |k| { for c.sources.each_key |k| {
c.sources.remove(k); c.sources.remove(k);
@ -1637,7 +1637,7 @@ fn cmd_sources(c: cargo) {
return; return;
} }
alt c.sources.find(name) { match c.sources.find(name) {
some(source) => { some(source) => {
error(fmt!{"source already exists: %s", name}); error(fmt!{"source already exists: %s", name});
} }
@ -1667,7 +1667,7 @@ fn cmd_sources(c: cargo) {
return; return;
} }
alt c.sources.find(name) { match c.sources.find(name) {
some(source) => { some(source) => {
c.sources.remove(name); c.sources.remove(name);
info(fmt!{"removed source: %s", name}); info(fmt!{"removed source: %s", name});
@ -1691,7 +1691,7 @@ fn cmd_sources(c: cargo) {
return; return;
} }
alt c.sources.find(name) { match c.sources.find(name) {
some(source) => { some(source) => {
let old = copy source.url; let old = copy source.url;
let method = assume_source_method(url); let method = assume_source_method(url);
@ -1722,11 +1722,11 @@ fn cmd_sources(c: cargo) {
return; return;
} }
alt c.sources.find(name) { match c.sources.find(name) {
some(source) => { some(source) => {
let old = copy source.method; let old = copy source.method;
source.method = alt method { source.method = match method {
~"git" => ~"git", ~"git" => ~"git",
~"file" => ~"file", ~"file" => ~"file",
_ => ~"curl" _ => ~"curl"
@ -1760,7 +1760,7 @@ fn cmd_sources(c: cargo) {
return; return;
} }
alt c.sources.find(name) { match c.sources.find(name) {
some(source) => { some(source) => {
c.sources.remove(name); c.sources.remove(name);
c.sources.insert(newn, source); c.sources.insert(newn, source);
@ -1874,7 +1874,7 @@ fn main(argv: ~[~str]) {
return; return;
} }
if o.help { if o.help {
alt o.free[1] { match o.free[1] {
~"init" => cmd_usage_init(), ~"init" => cmd_usage_init(),
~"install" => cmd_usage_install(), ~"install" => cmd_usage_install(),
~"uninstall" => cmd_usage_uninstall(), ~"uninstall" => cmd_usage_uninstall(),
@ -1901,7 +1901,7 @@ fn main(argv: ~[~str]) {
c = configure(o); c = configure(o);
} }
alt o.free[1] { match o.free[1] {
~"init" => cmd_init(c), ~"init" => cmd_init(c),
~"install" => cmd_install(c), ~"install" => cmd_install(c),
~"uninstall" => cmd_uninstall(c), ~"uninstall" => cmd_uninstall(c),

View file

@ -37,7 +37,7 @@ fn parse_config(args: ~[~str]) -> config {
assert (vec::is_not_empty(args)); assert (vec::is_not_empty(args));
let args_ = vec::tail(args); let args_ = vec::tail(args);
let matches = let matches =
alt getopts::getopts(args_, opts) { match getopts::getopts(args_, opts) {
ok(m) => m, ok(m) => m,
err(f) => fail getopts::fail_str(f) err(f) => fail getopts::fail_str(f)
}; };
@ -80,7 +80,7 @@ fn log_config(config: config) {
} }
fn opt_str(maybestr: option<~str>) -> ~str { fn opt_str(maybestr: option<~str>) -> ~str {
alt maybestr { option::some(s) => s, option::none => ~"(none)" } match maybestr { option::some(s) => s, option::none => ~"(none)" }
} }
fn str_opt(maybestr: ~str) -> option<~str> { fn str_opt(maybestr: ~str) -> option<~str> {
@ -88,7 +88,7 @@ fn str_opt(maybestr: ~str) -> option<~str> {
} }
fn str_mode(s: ~str) -> mode { fn str_mode(s: ~str) -> mode {
alt s { match s {
~"compile-fail" => mode_compile_fail, ~"compile-fail" => mode_compile_fail,
~"run-fail" => mode_run_fail, ~"run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass, ~"run-pass" => mode_run_pass,
@ -98,7 +98,7 @@ fn str_mode(s: ~str) -> mode {
} }
fn mode_str(mode: mode) -> ~str { fn mode_str(mode: mode) -> ~str {
alt mode { match mode {
mode_compile_fail => ~"compile-fail", mode_compile_fail => ~"compile-fail",
mode_run_fail => ~"run-fail", mode_run_fail => ~"run-fail",
mode_run_pass => ~"run-pass", mode_run_pass => ~"run-pass",
@ -115,13 +115,13 @@ fn run_tests(config: config) {
fn test_opts(config: config) -> test::test_opts { fn test_opts(config: config) -> test::test_opts {
{filter: {filter:
alt config.filter { match config.filter {
option::some(s) => option::some(s), option::some(s) => option::some(s),
option::none => option::none option::none => option::none
}, },
run_ignored: config.run_ignored, run_ignored: config.run_ignored,
logfile: logfile:
alt config.logfile { match config.logfile {
option::some(s) => option::some(s), option::some(s) => option::some(s),
option::none => option::none option::none => option::none
} }
@ -144,7 +144,7 @@ fn make_tests(config: config) -> ~[test::test_desc] {
fn is_test(config: config, testfile: ~str) -> bool { fn is_test(config: config, testfile: ~str) -> bool {
// Pretty-printer does not work with .rc files yet // Pretty-printer does not work with .rc files yet
let valid_extensions = let valid_extensions =
alt config.mode { match config.mode {
mode_pretty => ~[~".rs"], mode_pretty => ~[~".rs"],
_ => ~[~".rc", ~".rs"] _ => ~[~".rc", ~".rs"]
}; };

View file

@ -23,7 +23,7 @@ fn load_errors(testfile: ~str) -> ~[expected_error] {
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe { fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
let error_tag = ~"//~"; let error_tag = ~"//~";
let mut idx; let mut idx;
alt str::find_str(line, error_tag) { match str::find_str(line, error_tag) {
option::none => return ~[], option::none => return ~[],
option::some(nn) => { idx = (nn as uint) + str::len(error_tag); } option::some(nn) => { idx = (nn as uint) + str::len(error_tag); }
} }

View file

@ -30,7 +30,7 @@ fn load_props(testfile: ~str) -> test_props {
let mut compile_flags = option::none; let mut compile_flags = option::none;
let mut pp_exact = option::none; let mut pp_exact = option::none;
for iter_header(testfile) |ln| { for iter_header(testfile) |ln| {
alt parse_error_pattern(ln) { match parse_error_pattern(ln) {
option::some(ep) => vec::push(error_patterns, ep), option::some(ep) => vec::push(error_patterns, ep),
option::none => () option::none => ()
}; };
@ -107,7 +107,7 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
do parse_name_value_directive(line, ~"exec-env").map |nv| { do parse_name_value_directive(line, ~"exec-env").map |nv| {
// nv is either FOO or FOO=BAR // nv is either FOO or FOO=BAR
let strs = str::splitn_char(nv, '=', 1u); let strs = str::splitn_char(nv, '=', 1u);
alt strs.len() { match strs.len() {
1u => (strs[0], ~""), 1u => (strs[0], ~""),
2u => (strs[0], strs[1]), 2u => (strs[0], strs[1]),
n => fail fmt!{"Expected 1 or 2 strings, not %u", n} n => fail fmt!{"Expected 1 or 2 strings, not %u", n}
@ -116,7 +116,7 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
} }
fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> { fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
alt parse_name_value_directive(line, ~"pp-exact") { match parse_name_value_directive(line, ~"pp-exact") {
option::some(s) => option::some(s), option::some(s) => option::some(s),
option::none => { option::none => {
if parse_name_directive(line, ~"pp-exact") { if parse_name_directive(line, ~"pp-exact") {
@ -135,7 +135,7 @@ fn parse_name_directive(line: ~str, directive: ~str) -> bool {
fn parse_name_value_directive(line: ~str, fn parse_name_value_directive(line: ~str,
directive: ~str) -> option<~str> unsafe { directive: ~str) -> option<~str> unsafe {
let keycolon = directive + ~":"; let keycolon = directive + ~":";
alt str::find_str(line, keycolon) { match str::find_str(line, keycolon) {
option::some(colon) => { option::some(colon) => {
let value = str::slice(line, colon + str::len(keycolon), let value = str::slice(line, colon + str::len(keycolon),
str::len(line)); str::len(line));

View file

@ -76,7 +76,7 @@ fn run(lib_path: ~str,
let mut outs = ~""; let mut outs = ~"";
let mut count = 2; let mut count = 2;
while count > 0 { while count > 0 {
alt p.recv() { match p.recv() {
(1, s) => { (1, s) => {
outs = s; outs = s;
} }

View file

@ -18,7 +18,7 @@ fn run(config: config, testfile: ~str) {
} }
debug!{"running %s", testfile}; debug!{"running %s", testfile};
let props = load_props(testfile); let props = load_props(testfile);
alt config.mode { match config.mode {
mode_compile_fail => run_cfail_test(config, props, testfile), mode_compile_fail => run_cfail_test(config, props, testfile),
mode_run_fail => run_rfail_test(config, props, testfile), mode_run_fail => run_rfail_test(config, props, testfile),
mode_run_pass => run_rpass_test(config, props, testfile), mode_run_pass => run_rpass_test(config, props, testfile),
@ -90,7 +90,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
} else { logv(config, ~"testing for converging pretty-printing"); } } else { logv(config, ~"testing for converging pretty-printing"); }
let rounds = let rounds =
alt props.pp_exact { option::some(_) => 1, option::none => 2 }; match props.pp_exact { option::some(_) => 1, option::none => 2 };
let mut srcs = ~[result::get(io::read_whole_file_str(testfile))]; let mut srcs = ~[result::get(io::read_whole_file_str(testfile))];
@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
} }
let mut expected = let mut expected =
alt props.pp_exact { match props.pp_exact {
option::some(file) => { option::some(file) => {
let filepath = path::connect(path::dirname(testfile), file); let filepath = path::connect(path::dirname(testfile), file);
result::get(io::read_whole_file_str(filepath)) result::get(io::read_whole_file_str(filepath))
@ -383,7 +383,7 @@ fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
// If we've got another tool to run under (valgrind), // If we've got another tool to run under (valgrind),
// then split apart its command // then split apart its command
let runtool = let runtool =
alt config.runtool { match config.runtool {
option::some(s) => option::some(s), option::some(s) => option::some(s),
option::none => option::none option::none => option::none
}; };
@ -402,7 +402,7 @@ fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
vec::filter_map(v, flt) vec::filter_map(v, flt)
} }
alt argstr { match argstr {
option::some(s) => rm_whitespace(str::split_char(s, ' ')), option::some(s) => rm_whitespace(str::split_char(s, ' ')),
option::none => ~[] option::none => ~[]
} }

View file

@ -7,7 +7,7 @@ fn make_new_path(path: ~str) -> ~str {
// Windows just uses PATH as the library search path, so we have to // Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own // maintain the current value while adding our own
alt getenv(lib_path_env_var()) { match getenv(lib_path_env_var()) {
option::some(curr) => { option::some(curr) => {
fmt!{"%s%s%s", path, path_div(), curr} fmt!{"%s%s%s", path, path_div(), curr}
} }

View file

@ -62,9 +62,9 @@ pure fn safe_to_steal_expr(e: @ast::expr, tm: test_mode) -> bool {
} }
pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool { pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
alt tm { match tm {
tm_converge => { tm_converge => {
alt e.node { match e.node {
// If the fuzzer moves a block-ending-in-semicolon into callee // If the fuzzer moves a block-ending-in-semicolon into callee
// position, the pretty-printer can't preserve this even by // position, the pretty-printer can't preserve this even by
// parenthesizing!! See email to marijn. // parenthesizing!! See email to marijn.
@ -139,7 +139,7 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool { fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
alt e { match e {
// https://github.com/mozilla/rust/issues/652 // https://github.com/mozilla/rust/issues/652
ast::expr_if(*) => { false } ast::expr_if(*) => { false }
ast::expr_block(_) => { false } ast::expr_block(_) => { false }
@ -152,7 +152,7 @@ fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
} }
fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool { fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool {
alt t { match t {
ast::ty_infer => { false } // always implicit, always top level ast::ty_infer => { false } // always implicit, always top level
ast::ty_bot => { false } // in source, can only appear ast::ty_bot => { false } // in source, can only appear
// as the out type of a function // as the out type of a function
@ -272,7 +272,7 @@ fn check_variants_T<T: copy>(
io::str_reader(~""), a, io::str_reader(~""), a,
pprust::no_ann(), pprust::no_ann(),
false)); false));
alt cx.mode { match cx.mode {
tm_converge => { tm_converge => {
check_roundtrip_convergence(str3, 1u); check_roundtrip_convergence(str3, 1u);
} }
@ -314,12 +314,12 @@ fn check_whole_compiler(code: ~str, suggested_filename_prefix: ~str,
let compile_result = check_compiling(filename); let compile_result = check_compiling(filename);
let run_result = alt (compile_result, allow_running) { let run_result = match (compile_result, allow_running) {
(passed, true) => { check_running(suggested_filename_prefix) } (passed, true) => { check_running(suggested_filename_prefix) }
(h, _) => { h } (h, _) => { h }
}; };
alt run_result { match run_result {
passed | cleanly_rejected(_) | known_bug(_) => { passed | cleanly_rejected(_) | known_bug(_) => {
removeIfExists(suggested_filename_prefix); removeIfExists(suggested_filename_prefix);
removeIfExists(suggested_filename_prefix + ~".rs"); removeIfExists(suggested_filename_prefix + ~".rs");
@ -364,7 +364,7 @@ fn check_running(exe_filename: ~str) -> happiness {
} else if contains(comb, ~"malloc") { } else if contains(comb, ~"malloc") {
failed(~"Mentioned malloc") failed(~"Mentioned malloc")
} else { } else {
alt p.status { match p.status {
0 => { passed } 0 => { passed }
100 => { cleanly_rejected(~"running: explicit fail") } 100 => { cleanly_rejected(~"running: explicit fail") }
101 | 247 => { cleanly_rejected(~"running: timed out") } 101 | 247 => { cleanly_rejected(~"running: timed out") }
@ -441,7 +441,7 @@ fn parse_and_print(code: @~str) -> ~str {
fn has_raw_pointers(c: ast::crate) -> bool { fn has_raw_pointers(c: ast::crate) -> bool {
let has_rp = @mut false; let has_rp = @mut false;
fn visit_ty(flag: @mut bool, t: @ast::ty) { fn visit_ty(flag: @mut bool, t: @ast::ty) {
alt t.node { match t.node {
ast::ty_ptr(_) => { *flag = true; } ast::ty_ptr(_) => { *flag = true; }
_ => { } _ => { }
} }

View file

@ -39,7 +39,7 @@ pure fn is_false(v: bool) -> bool { !v }
/// Parse logic value from `s` /// Parse logic value from `s`
pure fn from_str(s: ~str) -> option<bool> { pure fn from_str(s: ~str) -> option<bool> {
alt check s { match check s {
~"true" => some(true), ~"true" => some(true),
~"false" => some(false), ~"false" => some(false),
_ => none _ => none

View file

@ -113,7 +113,7 @@ pure fn is_digit(c: char) -> bool {
* refer to a digit in the given radix. * refer to a digit in the given radix.
*/ */
pure fn to_digit(c: char, radix: uint) -> option<uint> { pure fn to_digit(c: char, radix: uint) -> option<uint> {
let val = alt c { let val = match c {
'0' to '9' => c as uint - ('0' as uint), '0' to '9' => c as uint - ('0' as uint),
'a' to 'z' => c as uint + 10u - ('a' as uint), 'a' to 'z' => c as uint + 10u - ('a' as uint),
'A' to 'Z' => c as uint + 10u - ('A' as uint), 'A' to 'Z' => c as uint + 10u - ('A' as uint),
@ -158,7 +158,7 @@ fn escape_unicode(c: char) -> ~str {
* - Any other chars are given hex unicode escapes; see `escape_unicode`. * - Any other chars are given hex unicode escapes; see `escape_unicode`.
*/ */
fn escape_default(c: char) -> ~str { fn escape_default(c: char) -> ~str {
alt c { match c {
'\t' => ~"\\t", '\t' => ~"\\t",
'\r' => ~"\\r", '\r' => ~"\\r",
'\n' => ~"\\n", '\n' => ~"\\n",

View file

@ -409,7 +409,7 @@ fn test_select2_stress() {
let mut as = 0; let mut as = 0;
let mut bs = 0; let mut bs = 0;
for iter::repeat(msgs * times * 2u) { for iter::repeat(msgs * times * 2u) {
alt check select2(po_a, po_b) { match check select2(po_a, po_b) {
either::left(~"a") => as += 1, either::left(~"a") => as += 1,
either::right(~"b") => bs += 1 either::right(~"b") => bs += 1
} }

View file

@ -26,8 +26,8 @@ enum dlist<T> = @{
impl private_methods<T> for dlist_node<T> { impl private_methods<T> for dlist_node<T> {
pure fn assert_links() { pure fn assert_links() {
alt self.next { match self.next {
some(neighbour) => alt neighbour.prev { some(neighbour) => match neighbour.prev {
some(me) => if !box::ptr_eq(*self, *me) { some(me) => if !box::ptr_eq(*self, *me) {
fail ~"Asymmetric next-link in dlist node." fail ~"Asymmetric next-link in dlist node."
} }
@ -35,8 +35,8 @@ impl private_methods<T> for dlist_node<T> {
} }
none => () none => ()
} }
alt self.prev { match self.prev {
some(neighbour) => alt neighbour.next { some(neighbour) => match neighbour.next {
some(me) => if !box::ptr_eq(*me, *self) { some(me) => if !box::ptr_eq(*me, *self) {
fail ~"Asymmetric prev-link in dlist node." fail ~"Asymmetric prev-link in dlist node."
} }
@ -55,7 +55,7 @@ impl extensions<T> for dlist_node<T> {
} }
/// Get the next node in the list, failing if there isn't one. /// Get the next node in the list, failing if there isn't one.
pure fn next_node() -> dlist_node<T> { pure fn next_node() -> dlist_node<T> {
alt self.next_link() { match self.next_link() {
some(nobe) => nobe, some(nobe) => nobe,
none => fail ~"This dlist node has no next neighbour." none => fail ~"This dlist node has no next neighbour."
} }
@ -67,7 +67,7 @@ impl extensions<T> for dlist_node<T> {
} }
/// Get the previous node in the list, failing if there isn't one. /// Get the previous node in the list, failing if there isn't one.
pure fn prev_node() -> dlist_node<T> { pure fn prev_node() -> dlist_node<T> {
alt self.prev_link() { match self.prev_link() {
some(nobe) => nobe, some(nobe) => nobe,
none => fail ~"This dlist node has no previous neighbour." none => fail ~"This dlist node has no previous neighbour."
} }
@ -138,11 +138,11 @@ impl private_methods<T> for dlist<T> {
// the head and/or tail pointers appropriately. // the head and/or tail pointers appropriately.
#[inline(always)] #[inline(always)]
fn link(+before: dlist_link<T>, +after: dlist_link<T>) { fn link(+before: dlist_link<T>, +after: dlist_link<T>) {
alt before { match before {
some(neighbour) => neighbour.next = after, some(neighbour) => neighbour.next = after,
none => self.hd = after none => self.hd = after
} }
alt after { match after {
some(neighbour) => neighbour.prev = before, some(neighbour) => neighbour.prev = before,
none => self.tl = before none => self.tl = before
} }
@ -286,14 +286,14 @@ impl extensions<T> for dlist<T> {
/// Get the node at the list's head, failing if empty. O(1). /// Get the node at the list's head, failing if empty. O(1).
pure fn head_n() -> dlist_node<T> { pure fn head_n() -> dlist_node<T> {
alt self.hd { match self.hd {
some(nobe) => nobe, some(nobe) => nobe,
none => fail ~"Attempted to get the head of an empty dlist." none => fail ~"Attempted to get the head of an empty dlist."
} }
} }
/// Get the node at the list's tail, failing if empty. O(1). /// Get the node at the list's tail, failing if empty. O(1).
pure fn tail_n() -> dlist_node<T> { pure fn tail_n() -> dlist_node<T> {
alt self.tl { match self.tl {
some(nobe) => nobe, some(nobe) => nobe,
none => fail ~"Attempted to get the tail of an empty dlist." none => fail ~"Attempted to get the tail of an empty dlist."
} }

View file

@ -222,7 +222,7 @@ impl extensions<A:copy> for dvec<A> {
*/ */
fn append_iter<A, I:iter::base_iter<A>>(ts: I) { fn append_iter<A, I:iter::base_iter<A>>(ts: I) {
do self.swap |v| { do self.swap |v| {
let mut v = alt ts.size_hint() { let mut v = match ts.size_hint() {
none { v } none { v }
some(h) { some(h) {
let len = v.len() + h; let len = v.len() + h;

View file

@ -18,7 +18,7 @@ fn either<T, U, V>(f_left: fn(T) -> V,
* result is returned. * result is returned.
*/ */
alt value { match value {
left(l) => f_left(l), left(l) => f_left(l),
right(r) => f_right(r) right(r) => f_right(r)
} }
@ -29,7 +29,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
let mut result: ~[T] = ~[]; let mut result: ~[T] = ~[];
for vec::each(eithers) |elt| { for vec::each(eithers) |elt| {
alt elt { match elt {
left(l) => vec::push(result, l), left(l) => vec::push(result, l),
_ => { /* fallthrough */ } _ => { /* fallthrough */ }
} }
@ -42,7 +42,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
let mut result: ~[U] = ~[]; let mut result: ~[U] = ~[];
for vec::each(eithers) |elt| { for vec::each(eithers) |elt| {
alt elt { match elt {
right(r) => vec::push(result, r), right(r) => vec::push(result, r),
_ => { /* fallthrough */ } _ => { /* fallthrough */ }
} }
@ -62,7 +62,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
let mut lefts: ~[T] = ~[]; let mut lefts: ~[T] = ~[];
let mut rights: ~[U] = ~[]; let mut rights: ~[U] = ~[];
for vec::each(eithers) |elt| { for vec::each(eithers) |elt| {
alt elt { match elt {
left(l) => vec::push(lefts, l), left(l) => vec::push(lefts, l),
right(r) => vec::push(rights, r) right(r) => vec::push(rights, r)
} }
@ -73,7 +73,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> { pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> {
//! Flips between left and right of a given either //! Flips between left and right of a given either
alt eith { match eith {
right(r) => left(r), right(r) => left(r),
left(l) => right(l) left(l) => right(l)
} }
@ -88,7 +88,7 @@ pure fn to_result<T: copy, U: copy>(
* an ok result, and the "left" choice a fail * an ok result, and the "left" choice a fail
*/ */
alt eith { match eith {
right(r) => result::ok(r), right(r) => result::ok(r),
left(l) => result::err(l) left(l) => result::err(l)
} }
@ -97,13 +97,13 @@ pure fn to_result<T: copy, U: copy>(
pure fn is_left<T, U>(eith: either<T, U>) -> bool { pure fn is_left<T, U>(eith: either<T, U>) -> bool {
//! Checks whether the given value is a left //! Checks whether the given value is a left
alt eith { left(_) => true, _ => false } match eith { left(_) => true, _ => false }
} }
pure fn is_right<T, U>(eith: either<T, U>) -> bool { pure fn is_right<T, U>(eith: either<T, U>) -> bool {
//! Checks whether the given value is a right //! Checks whether the given value is a right
alt eith { right(_) => true, _ => false } match eith { right(_) => true, _ => false }
} }
#[test] #[test]

View file

@ -122,7 +122,7 @@ mod ct {
let c = s[i]; let c = s[i];
if !('0' as u8 <= c && c <= '9' as u8) { return option::none; } if !('0' as u8 <= c && c <= '9' as u8) { return option::none; }
let n = (c - ('0' as u8)) as uint; let n = (c - ('0' as u8)) as uint;
return alt peek_num(s, i + 1u, lim) { return match peek_num(s, i + 1u, lim) {
none => some({num: n, next: i + 1u}), none => some({num: n, next: i + 1u}),
some(next) => { some(next) => {
let m = next.num; let m = next.num;
@ -150,7 +150,7 @@ mod ct {
{param: option<int>, next: uint} { {param: option<int>, next: uint} {
if i >= lim { return {param: none, next: i}; } if i >= lim { return {param: none, next: i}; }
let num = peek_num(s, i, lim); let num = peek_num(s, i, lim);
return alt num { return match num {
none => {param: none, next: i}, none => {param: none, next: i},
some(t) => { some(t) => {
let n = t.num; let n = t.num;
@ -195,13 +195,13 @@ mod ct {
} else if s[i] == '*' as u8 { } else if s[i] == '*' as u8 {
let param = parse_parameter(s, i + 1u, lim); let param = parse_parameter(s, i + 1u, lim);
let j = param.next; let j = param.next;
alt param.param { match param.param {
none => {count: count_is_next_param, next: j}, none => {count: count_is_next_param, next: j},
some(n) => {count: count_is_param(n), next: j} some(n) => {count: count_is_param(n), next: j}
} }
} else { } else {
let num = peek_num(s, i, lim); let num = peek_num(s, i, lim);
alt num { match num {
none => {count: count_implied, next: i}, none => {count: count_implied, next: i},
some(num) => { some(num) => {
count: count_is(num.num as int), count: count_is(num.num as int),
@ -220,7 +220,7 @@ mod ct {
// If there were no digits specified, i.e. the precision // If there were no digits specified, i.e. the precision
// was ".", then the precision is 0 // was ".", then the precision is 0
alt count.count { match count.count {
count_implied => {count: count_is(0), next: count.next}, count_implied => {count: count_is(0), next: count.next},
_ => count _ => count
} }
@ -294,7 +294,7 @@ mod rt {
pure fn conv_uint(cv: conv, u: uint) -> ~str { pure fn conv_uint(cv: conv, u: uint) -> ~str {
let prec = get_int_precision(cv); let prec = get_int_precision(cv);
let mut rs = let mut rs =
alt cv.ty { match cv.ty {
ty_default => uint_to_str_prec(u, 10u, prec), ty_default => uint_to_str_prec(u, 10u, prec),
ty_hex_lower => uint_to_str_prec(u, 16u, prec), ty_hex_lower => uint_to_str_prec(u, 16u, prec),
ty_hex_upper => str::to_upper(uint_to_str_prec(u, 16u, prec)), ty_hex_upper => str::to_upper(uint_to_str_prec(u, 16u, prec)),
@ -316,7 +316,7 @@ mod rt {
pure fn conv_str(cv: conv, s: &str) -> ~str { pure fn conv_str(cv: conv, s: &str) -> ~str {
// For strings, precision is the maximum characters // For strings, precision is the maximum characters
// displayed // displayed
let mut unpadded = alt cv.precision { let mut unpadded = match cv.precision {
count_implied => s.to_unique(), count_implied => s.to_unique(),
count_is(max) => if max as uint < str::char_len(s) { count_is(max) => if max as uint < str::char_len(s) {
str::substr(s, 0u, max as uint) str::substr(s, 0u, max as uint)
@ -327,7 +327,7 @@ mod rt {
return unchecked { pad(cv, unpadded, pad_nozero) }; return unchecked { pad(cv, unpadded, pad_nozero) };
} }
pure fn conv_float(cv: conv, f: float) -> ~str { pure fn conv_float(cv: conv, f: float) -> ~str {
let (to_str, digits) = alt cv.precision { let (to_str, digits) = match cv.precision {
count_is(c) => (float::to_str_exact, c as uint), count_is(c) => (float::to_str_exact, c as uint),
count_implied => (float::to_str, 6u) count_implied => (float::to_str, 6u)
}; };
@ -371,14 +371,14 @@ mod rt {
}; };
} }
pure fn get_int_precision(cv: conv) -> uint { pure fn get_int_precision(cv: conv) -> uint {
return alt cv.precision { return match cv.precision {
count_is(c) => c as uint, count_is(c) => c as uint,
count_implied => 1u count_implied => 1u
}; };
} }
enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float } enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float }
fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str { fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str {
let uwidth : uint = alt cv.width { let uwidth : uint = match cv.width {
count_implied => return s, count_implied => return s,
count_is(width) => { count_is(width) => {
// FIXME: width should probably be uint (see Issue #1996) // FIXME: width should probably be uint (see Issue #1996)
@ -393,14 +393,14 @@ mod rt {
let padstr = str::from_chars(vec::from_elem(diff, padchar)); let padstr = str::from_chars(vec::from_elem(diff, padchar));
return s + padstr; return s + padstr;
} }
let {might_zero_pad, signed} = alt mode { let {might_zero_pad, signed} = match mode {
pad_nozero => {might_zero_pad:false, signed:false}, pad_nozero => {might_zero_pad:false, signed:false},
pad_signed => {might_zero_pad:true, signed:true }, pad_signed => {might_zero_pad:true, signed:true },
pad_float => {might_zero_pad:true, signed:true}, pad_float => {might_zero_pad:true, signed:true},
pad_unsigned => {might_zero_pad:true, signed:false} pad_unsigned => {might_zero_pad:true, signed:false}
}; };
pure fn have_precision(cv: conv) -> bool { pure fn have_precision(cv: conv) -> bool {
return alt cv.precision { count_implied => false, _ => true }; return match cv.precision { count_implied => false, _ => true };
} }
let zero_padding = { let zero_padding = {
if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) && if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) &&

View file

@ -256,14 +256,14 @@ fn from_str(num: ~str) -> option<float> {
let mut c = 'z'; //Latest char. let mut c = 'z'; //Latest char.
//The string must start with one of the following characters. //The string must start with one of the following characters.
alt str::char_at(num, 0u) { match str::char_at(num, 0u) {
'-' | '+' | '0' to '9' | '.' => (), '-' | '+' | '0' to '9' | '.' => (),
_ => return none _ => return none
} }
//Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly. //Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly.
let mut neg = false; //Sign of the result let mut neg = false; //Sign of the result
alt str::char_at(num, 0u) { match str::char_at(num, 0u) {
'-' => { '-' => {
neg = true; neg = true;
pos = 1u; pos = 1u;
@ -279,7 +279,7 @@ fn from_str(num: ~str) -> option<float> {
let char_range = str::char_range_at(num, pos); let char_range = str::char_range_at(num, pos);
c = char_range.ch; c = char_range.ch;
pos = char_range.next; pos = char_range.next;
alt c { match c {
'0' to '9' => { '0' to '9' => {
total = total * 10f; total = total * 10f;
total += ((c as int) - ('0' as int)) as float; total += ((c as int) - ('0' as int)) as float;
@ -295,7 +295,7 @@ fn from_str(num: ~str) -> option<float> {
let char_range = str::char_range_at(num, pos); let char_range = str::char_range_at(num, pos);
c = char_range.ch; c = char_range.ch;
pos = char_range.next; pos = char_range.next;
alt c { match c {
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => { '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => {
decimal /= 10f; decimal /= 10f;
total += (((c as int) - ('0' as int)) as float)*decimal; total += (((c as int) - ('0' as int)) as float)*decimal;
@ -312,7 +312,7 @@ fn from_str(num: ~str) -> option<float> {
if(pos < len) { if(pos < len) {
let char_range = str::char_range_at(num, pos); let char_range = str::char_range_at(num, pos);
c = char_range.ch; c = char_range.ch;
alt c { match c {
'+' => { '+' => {
pos = char_range.next; pos = char_range.next;
} }
@ -325,7 +325,7 @@ fn from_str(num: ~str) -> option<float> {
while(pos < len) { while(pos < len) {
let char_range = str::char_range_at(num, pos); let char_range = str::char_range_at(num, pos);
c = char_range.ch; c = char_range.ch;
alt c { match c {
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => { '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => {
exponent *= 10u; exponent *= 10u;
exponent += ((c as uint) - ('0' as uint)); exponent += ((c as uint) - ('0' as uint));
@ -447,7 +447,7 @@ fn test_from_str() {
assert from_str(~"inf") == some(infinity); assert from_str(~"inf") == some(infinity);
assert from_str(~"-inf") == some(neg_infinity); assert from_str(~"-inf") == some(neg_infinity);
// note: NaN != NaN, hence this slightly complex test // note: NaN != NaN, hence this slightly complex test
alt from_str(~"NaN") { match from_str(~"NaN") {
some(f) => assert is_NaN(f), some(f) => assert is_NaN(f),
none => fail none => fail
} }

View file

@ -77,7 +77,7 @@ fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> {
let mut port_ = none; let mut port_ = none;
port_ <-> *port; port_ <-> *port;
let port = option::unwrap(port_); let port = option::unwrap(port_);
alt recv(port) { match recv(port) {
future_pipe::completed(data) => move_it!{data} future_pipe::completed(data) => move_it!{data}
} }
} }
@ -119,7 +119,7 @@ fn get<A:copy>(future: future<A>) -> A {
fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B { fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
//! Work with the value without copying it //! Work with the value without copying it
let v = alt copy future.v { let v = match copy future.v {
either::left(v) => v, either::left(v) => v,
either::right(f) => { either::right(f) => {
let v = @f(); let v = @f();

View file

@ -144,7 +144,7 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
} }
let mut n = 0 as T; let mut n = 0 as T;
loop { loop {
alt char::to_digit(buf[i] as char, radix) { match char::to_digit(buf[i] as char, radix) {
some(d) => n += (d as T) * power, some(d) => n += (d as T) * power,
none => return none none => return none
} }

View file

@ -196,7 +196,7 @@ impl reader_util for reader {
// Reader implementations // Reader implementations
fn convert_whence(whence: seek_style) -> i32 { fn convert_whence(whence: seek_style) -> i32 {
return alt whence { return match whence {
seek_set => 0i32, seek_set => 0i32,
seek_cur => 1i32, seek_cur => 1i32,
seek_end => 2i32 seek_end => 2i32
@ -440,7 +440,7 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag])
let mut fflags: c_int = wb(); let mut fflags: c_int = wb();
for vec::each(flags) |f| { for vec::each(flags) |f| {
alt f { match f {
append => fflags |= O_APPEND as c_int, append => fflags |= O_APPEND as c_int,
create => fflags |= O_CREAT as c_int, create => fflags |= O_CREAT as c_int,
truncate => fflags |= O_TRUNC as c_int, truncate => fflags |= O_TRUNC as c_int,
@ -460,7 +460,7 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag])
fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u; assert size <= 8u;
alt size { match size {
1u => f(&[n as u8]), 1u => f(&[n as u8]),
2u => f(&[n as u8, 2u => f(&[n as u8,
(n >> 8) as u8]), (n >> 8) as u8]),
@ -491,7 +491,7 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u; assert size <= 8u;
alt size { match size {
1u => f(&[n as u8]), 1u => f(&[n as u8]),
2u => f(&[(n >> 8) as u8, 2u => f(&[(n >> 8) as u8,
n as u8]), n as u8]),
@ -717,7 +717,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
uint { uint {
let mut bpos = pos as int; let mut bpos = pos as int;
let blen = len as int; let blen = len as int;
alt whence { match whence {
seek_set => bpos = offset, seek_set => bpos = offset,
seek_cur => bpos += offset, seek_cur => bpos += offset,
seek_end => bpos = blen + offset seek_end => bpos = blen + offset
@ -767,7 +767,7 @@ mod fsync {
let arg: arg<t>; let arg: arg<t>;
new(-arg: arg<t>) { self.arg <- arg; } new(-arg: arg<t>) { self.arg <- arg; }
drop { drop {
alt self.arg.opt_level { match self.arg.opt_level {
option::none => (), option::none => (),
option::some(level) => { option::some(level) => {
// fail hard if not succesful // fail hard if not succesful
@ -891,7 +891,7 @@ mod tests {
#[test] #[test]
fn file_reader_not_exist() { fn file_reader_not_exist() {
alt io::file_reader(~"not a file") { match io::file_reader(~"not a file") {
result::err(e) => { result::err(e) => {
assert e == ~"error opening not a file"; assert e == ~"error opening not a file";
} }
@ -901,7 +901,7 @@ mod tests {
#[test] #[test]
fn file_writer_bad_name() { fn file_writer_bad_name() {
alt io::file_writer(~"?/?", ~[]) { match io::file_writer(~"?/?", ~[]) {
result::err(e) => { result::err(e) => {
assert str::starts_with(e, ~"error opening ?/?"); assert str::starts_with(e, ~"error opening ?/?");
} }
@ -911,7 +911,7 @@ mod tests {
#[test] #[test]
fn buffered_file_writer_bad_name() { fn buffered_file_writer_bad_name() {
alt io::buffered_file_writer(~"?/?") { match io::buffered_file_writer(~"?/?") {
result::err(e) => { result::err(e) => {
assert e == ~"error opening ?/?"; assert e == ~"error opening ?/?";
} }

View file

@ -1,14 +1,14 @@
type IMPL_T<A> = option<A>; type IMPL_T<A> = option<A>;
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) { pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
alt self { match self {
none => (), none => (),
some(a) => { f(a); } some(a) => { f(a); }
} }
} }
fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> { fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {
alt self { match self {
none => some(0u), none => some(0u),
some(_) => some(1u) some(_) => some(1u)
} }

View file

@ -134,8 +134,8 @@ fn repeat(times: uint, blk: fn() -> bool) {
} }
fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
alt do foldl::<A,option<A>,IA>(self, none) |a, b| { match do foldl::<A,option<A>,IA>(self, none) |a, b| {
alt a { match a {
some(a_) if a_ < b => { some(a_) if a_ < b => {
// FIXME (#2005): Not sure if this is successfully optimized to // FIXME (#2005): Not sure if this is successfully optimized to
// a move // a move
@ -150,8 +150,8 @@ fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
} }
fn max<A:copy,IA:base_iter<A>>(self: IA) -> A { fn max<A:copy,IA:base_iter<A>>(self: IA) -> A {
alt do foldl::<A,option<A>,IA>(self, none) |a, b| { match do foldl::<A,option<A>,IA>(self, none) |a, b| {
alt a { match a {
some(a_) if a_ > b => { some(a_) if a_ > b => {
// FIXME (#2005): Not sure if this is successfully optimized to // FIXME (#2005): Not sure if this is successfully optimized to
// a move. // a move.

View file

@ -23,7 +23,7 @@ pure fn get<T: copy>(opt: option<T>) -> T {
* Fails if the value equals `none` * Fails if the value equals `none`
*/ */
alt opt { match opt {
some(x) => return x, some(x) => return x,
none => fail ~"option::get none" none => fail ~"option::get none"
} }
@ -37,13 +37,13 @@ pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
Fails if the value equals `none` Fails if the value equals `none`
"]; "];
alt opt { some(x) => x, none => fail reason } match opt { some(x) => x, none => fail reason }
} }
pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> { pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> {
//! Maps a `some` value from one type to another //! Maps a `some` value from one type to another
alt opt { some(x) => some(f(x)), none => none } match opt { some(x) => some(f(x)), none => none }
} }
pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> { pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> {
@ -60,7 +60,7 @@ pure fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> {
* function that returns an option. * function that returns an option.
*/ */
alt opt { some(x) => f(x), none => none } match opt { some(x) => f(x), none => none }
} }
#[inline(always)] #[inline(always)]
@ -76,7 +76,7 @@ pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) {
pure fn is_none<T>(opt: option<T>) -> bool { pure fn is_none<T>(opt: option<T>) -> bool {
//! Returns true if the option equals `none` //! Returns true if the option equals `none`
alt opt { none => true, some(_) => false } match opt { none => true, some(_) => false }
} }
pure fn is_some<T>(opt: option<T>) -> bool { pure fn is_some<T>(opt: option<T>) -> bool {
@ -88,19 +88,19 @@ pure fn is_some<T>(opt: option<T>) -> bool {
pure fn get_default<T: copy>(opt: option<T>, def: T) -> T { pure fn get_default<T: copy>(opt: option<T>, def: T) -> T {
//! Returns the contained value or a default //! Returns the contained value or a default
alt opt { some(x) => x, none => def } match opt { some(x) => x, none => def }
} }
pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U { pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U {
//! Applies a function to the contained value or returns a default //! Applies a function to the contained value or returns a default
alt opt { none => def, some(t) => f(t) } match opt { none => def, some(t) => f(t) }
} }
pure fn iter<T>(opt: option<T>, f: fn(T)) { pure fn iter<T>(opt: option<T>, f: fn(T)) {
//! Performs an operation on the contained value or does nothing //! Performs an operation on the contained value or does nothing
alt opt { none => (), some(t) => f(t) } match opt { none => (), some(t) => f(t) }
} }
#[inline(always)] #[inline(always)]
@ -113,7 +113,7 @@ pure fn unwrap<T>(-opt: option<T>) -> T {
*/ */
unsafe { unsafe {
let addr = alt opt { let addr = match opt {
some(x) => ptr::addr_of(x), some(x) => ptr::addr_of(x),
none => fail ~"option::unwrap none" none => fail ~"option::unwrap none"
}; };

View file

@ -178,7 +178,7 @@ mod global_env {
unsafe { unsafe {
do priv::weaken_task |weak_po| { do priv::weaken_task |weak_po| {
loop { loop {
alt comm::select2(msg_po, weak_po) { match comm::select2(msg_po, weak_po) {
either::left(msg_getenv(n, resp_ch)) => { either::left(msg_getenv(n, resp_ch)) => {
comm::send(resp_ch, impl::getenv(n)) comm::send(resp_ch, impl::getenv(n))
} }
@ -282,7 +282,7 @@ fn fsync_fd(fd: c_int, _level: io::fsync::level) -> c_int {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
import libc::funcs::posix01::unistd::*; import libc::funcs::posix01::unistd::*;
alt level { match level {
io::fsync::fsync io::fsync::fsync
| io::fsync::fullfsync => return fsync(fd), | io::fsync::fullfsync => return fsync(fd),
io::fsync::fdatasync => return fdatasync(fd) io::fsync::fdatasync => return fdatasync(fd)
@ -294,7 +294,7 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
import libc::consts::os::extra::*; import libc::consts::os::extra::*;
import libc::funcs::posix88::fcntl::*; import libc::funcs::posix88::fcntl::*;
import libc::funcs::posix01::unistd::*; import libc::funcs::posix01::unistd::*;
alt level { match level {
io::fsync::fsync => return fsync(fd), io::fsync::fsync => return fsync(fd),
_ => { _ => {
// According to man fnctl, the ok retval is only specified to be !=-1 // According to man fnctl, the ok retval is only specified to be !=-1
@ -440,7 +440,7 @@ fn self_exe_path() -> option<path> {
* Otherwise, homedir returns option::none. * Otherwise, homedir returns option::none.
*/ */
fn homedir() -> option<path> { fn homedir() -> option<path> {
return alt getenv(~"HOME") { return match getenv(~"HOME") {
some(p) => if !str::is_empty(p) { some(p) => if !str::is_empty(p) {
some(p) some(p)
} else { } else {

View file

@ -61,7 +61,7 @@ fn path_is_absolute(p: ~str) -> bool {
fn path_sep() -> ~str { return str::from_char(consts::path_sep); } fn path_sep() -> ~str { return str::from_char(consts::path_sep); }
fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} { fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} {
alt str::rfind(pp, |ch| match str::rfind(pp, |ch|
ch == consts::path_sep || ch == consts::alt_path_sep ch == consts::path_sep || ch == consts::alt_path_sep
) { ) {
some(i) => { some(i) => {

View file

@ -136,7 +136,7 @@ struct packet_header {
unsafe fn unblock() { unsafe fn unblock() {
let old_task = swap_task(self.blocked_task, ptr::null()); let old_task = swap_task(self.blocked_task, ptr::null());
if !old_task.is_null() { rustrt::rust_task_deref(old_task) } if !old_task.is_null() { rustrt::rust_task_deref(old_task) }
alt swap_state_acq(self.state, empty) { match swap_state_acq(self.state, empty) {
empty | blocked => (), empty | blocked => (),
terminated => self.state = terminated, terminated => self.state = terminated,
full => self.state = full full => self.state = full
@ -345,7 +345,7 @@ fn send<T: send, Tbuffer: send>(-p: send_packet_buffered<T, Tbuffer>,
assert p.payload == none; assert p.payload == none;
p.payload <- some(payload); p.payload <- some(payload);
let old_state = swap_state_rel(p.header.state, full); let old_state = swap_state_rel(p.header.state, full);
alt old_state { match old_state {
empty => { empty => {
// Yay, fastpath. // Yay, fastpath.
@ -403,7 +403,7 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>)
rustrt::task_clear_event_reject(this); rustrt::task_clear_event_reject(this);
let old_state = swap_state_acq(p.header.state, let old_state = swap_state_acq(p.header.state,
blocked); blocked);
alt old_state { match old_state {
empty => { empty => {
debug!{"no data available on %?, going to sleep.", p_}; debug!{"no data available on %?, going to sleep.", p_};
if count == 0 { if count == 0 {
@ -451,7 +451,7 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>)
/// Returns true if messages are available. /// Returns true if messages are available.
pure fn peek<T: send, Tb: send>(p: recv_packet_buffered<T, Tb>) -> bool { pure fn peek<T: send, Tb: send>(p: recv_packet_buffered<T, Tb>) -> bool {
alt unsafe {(*p.header()).state} { match unsafe {(*p.header()).state} {
empty => false, empty => false,
blocked => fail ~"peeking on blocked packet", blocked => fail ~"peeking on blocked packet",
full | terminated => true full | terminated => true
@ -467,7 +467,7 @@ impl peek<T: send, Tb: send> for recv_packet_buffered<T, Tb> {
#[doc(hidden)] #[doc(hidden)]
fn sender_terminate<T: send>(p: *packet<T>) { fn sender_terminate<T: send>(p: *packet<T>) {
let p = unsafe { &*p }; let p = unsafe { &*p };
alt swap_state_rel(p.header.state, terminated) { match swap_state_rel(p.header.state, terminated) {
empty => { empty => {
assert p.header.blocked_task.is_null(); assert p.header.blocked_task.is_null();
// The receiver will eventually clean up. // The receiver will eventually clean up.
@ -500,7 +500,7 @@ fn sender_terminate<T: send>(p: *packet<T>) {
fn receiver_terminate<T: send>(p: *packet<T>) { fn receiver_terminate<T: send>(p: *packet<T>) {
let p = unsafe { &*p }; let p = unsafe { &*p };
assert p.header.blocked_task.is_null(); assert p.header.blocked_task.is_null();
alt swap_state_rel(p.header.state, terminated) { match swap_state_rel(p.header.state, terminated) {
empty => { empty => {
// the sender will clean up // the sender will clean up
//unsafe { forget(p) } //unsafe { forget(p) }
@ -534,7 +534,7 @@ fn wait_many(pkts: &[*packet_header]) -> uint {
for pkts.eachi |i, p| unsafe { for pkts.eachi |i, p| unsafe {
let p = unsafe { &*p }; let p = unsafe { &*p };
let old = p.mark_blocked(this); let old = p.mark_blocked(this);
alt old { match old {
full | terminated => { full | terminated => {
data_avail = true; data_avail = true;
ready_packet = i; ready_packet = i;
@ -551,7 +551,7 @@ fn wait_many(pkts: &[*packet_header]) -> uint {
let event = wait_event(this) as *packet_header; let event = wait_event(this) as *packet_header;
let pos = vec::position(pkts, |p| p == event); let pos = vec::position(pkts, |p| p == event);
alt pos { match pos {
some(i) => { some(i) => {
ready_packet = i; ready_packet = i;
data_avail = true; data_avail = true;
@ -611,7 +611,7 @@ fn select2<A: send, Ab: send, B: send, Bb: send>(
let i = wait_many([a.header(), b.header()]/_); let i = wait_many([a.header(), b.header()]/_);
unsafe { unsafe {
alt i { match i {
0 => left((try_recv(a), b)), 0 => left((try_recv(a), b)),
1 => right((a, try_recv(b))), 1 => right((a, try_recv(b))),
_ => fail ~"select2 return an invalid packet" _ => fail ~"select2 return an invalid packet"
@ -631,7 +631,7 @@ fn selecti<T: selectable>(endpoints: &[T]) -> uint {
/// Returns 0 or 1 depending on which endpoint is ready to receive /// Returns 0 or 1 depending on which endpoint is ready to receive
fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> { fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
alt wait_many([a.header(), b.header()]/_) { match wait_many([a.header(), b.header()]/_) {
0 => left(()), 0 => left(()),
1 => right(()), 1 => right(()),
_ => fail ~"wait returned unexpected index" _ => fail ~"wait returned unexpected index"
@ -704,7 +704,7 @@ struct send_packet_buffered<T: send, Tbuffer: send> {
} }
pure fn header() -> *packet_header { pure fn header() -> *packet_header {
alt self.p { match self.p {
some(packet) => unsafe { some(packet) => unsafe {
let packet = &*packet; let packet = &*packet;
let header = ptr::addr_of(packet.header); let header = ptr::addr_of(packet.header);
@ -765,7 +765,7 @@ struct recv_packet_buffered<T: send, Tbuffer: send> : selectable {
} }
pure fn header() -> *packet_header { pure fn header() -> *packet_header {
alt self.p { match self.p {
some(packet) => unsafe { some(packet) => unsafe {
let packet = &*packet; let packet = &*packet;
let header = ptr::addr_of(packet.header); let header = ptr::addr_of(packet.header);
@ -924,7 +924,7 @@ impl port<T: send> of recv<T> for port<T> {
fn try_recv() -> option<T> { fn try_recv() -> option<T> {
let mut endp = none; let mut endp = none;
endp <-> self.endp; endp <-> self.endp;
alt move pipes::try_recv(unwrap(endp)) { match move pipes::try_recv(unwrap(endp)) {
some(streamp::data(x, endp)) => { some(streamp::data(x, endp)) => {
self.endp = some(move_it!{endp}); self.endp = some(move_it!{endp});
some(move_it!{x}) some(move_it!{x})
@ -936,7 +936,7 @@ impl port<T: send> of recv<T> for port<T> {
pure fn peek() -> bool unchecked { pure fn peek() -> bool unchecked {
let mut endp = none; let mut endp = none;
endp <-> self.endp; endp <-> self.endp;
let peek = alt endp { let peek = match endp {
some(endp) => pipes::peek(endp), some(endp) => pipes::peek(endp),
none => fail ~"peeking empty stream" none => fail ~"peeking empty stream"
}; };
@ -969,7 +969,7 @@ struct port_set<T: send> : recv<T> {
ports <-> self.ports; ports <-> self.ports;
while result == none && ports.len() > 0 { while result == none && ports.len() > 0 {
let i = wait_many(ports.map(|p| p.header())); let i = wait_many(ports.map(|p| p.header()));
alt move ports[i].try_recv() { match move ports[i].try_recv() {
some(copy m) => { some(copy m) => {
result = some(move m); result = some(move m);
} }
@ -1007,7 +1007,7 @@ struct port_set<T: send> : recv<T> {
impl<T: send> of selectable for port<T> { impl<T: send> of selectable for port<T> {
pure fn header() -> *packet_header unchecked { pure fn header() -> *packet_header unchecked {
alt self.endp { match self.endp {
some(endp) => endp.header(), some(endp) => endp.header(),
none => fail ~"peeking empty stream" none => fail ~"peeking empty stream"
} }
@ -1045,8 +1045,8 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>>
of select2<T, U> for (Left, Right) { of select2<T, U> for (Left, Right) {
fn select() -> either<T, U> { fn select() -> either<T, U> {
alt self { match self {
(lp, rp) => alt select2i(lp, rp) { (lp, rp) => match select2i(lp, rp) {
left(()) => left (lp.recv()), left(()) => left (lp.recv()),
right(()) => right(rp.recv()) right(()) => right(rp.recv())
} }
@ -1054,8 +1054,8 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>>
} }
fn try_select() -> either<option<T>, option<U>> { fn try_select() -> either<option<T>, option<U>> {
alt self { match self {
(lp, rp) => alt select2i(lp, rp) { (lp, rp) => match select2i(lp, rp) {
left(()) => left (lp.try_recv()), left(()) => left (lp.try_recv()),
right(()) => right(rp.try_recv()) right(()) => right(rp.try_recv())
} }
@ -1072,7 +1072,7 @@ mod test {
c1.send(~"abc"); c1.send(~"abc");
alt (p1, p2).select() { match (p1, p2).select() {
right(_) => fail, right(_) => fail,
_ => () _ => ()
} }

View file

@ -49,7 +49,7 @@ unsafe fn chan_from_global_ptr<T: send>(
// Wait to hear if we are the official instance of // Wait to hear if we are the official instance of
// this global task // this global task
alt comm::recv::<msg>(setup_po) { match comm::recv::<msg>(setup_po) {
proceed => f(po), proceed => f(po),
abort => () abort => ()
} }

View file

@ -18,7 +18,7 @@ enum result<T, U> {
* If the result is an error * If the result is an error
*/ */
pure fn get<T: copy, U>(res: result<T, U>) -> T { pure fn get<T: copy, U>(res: result<T, U>) -> T {
alt res { match res {
ok(t) => t, ok(t) => t,
err(the_err) => unchecked { err(the_err) => unchecked {
fail fmt!{"get called on error result: %?", the_err} fail fmt!{"get called on error result: %?", the_err}
@ -34,7 +34,7 @@ pure fn get<T: copy, U>(res: result<T, U>) -> T {
* If the result is not an error * If the result is not an error
*/ */
pure fn get_err<T, U: copy>(res: result<T, U>) -> U { pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
alt res { match res {
err(u) => u, err(u) => u,
ok(_) => fail ~"get_error called on ok result" ok(_) => fail ~"get_error called on ok result"
} }
@ -42,7 +42,7 @@ pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
/// Returns true if the result is `ok` /// Returns true if the result is `ok`
pure fn is_ok<T, U>(res: result<T, U>) -> bool { pure fn is_ok<T, U>(res: result<T, U>) -> bool {
alt res { match res {
ok(_) => true, ok(_) => true,
err(_) => false err(_) => false
} }
@ -60,7 +60,7 @@ pure fn is_err<T, U>(res: result<T, U>) -> bool {
* result variants are converted to `either::left`. * result variants are converted to `either::left`.
*/ */
pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> { pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> {
alt res { match res {
ok(res) => either::right(res), ok(res) => either::right(res),
err(fail_) => either::left(fail_) err(fail_) => either::left(fail_)
} }
@ -82,7 +82,7 @@ pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> {
*/ */
fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>) fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
-> result<U, V> { -> result<U, V> {
alt res { match res {
ok(t) => op(t), ok(t) => op(t),
err(e) => err(e) err(e) => err(e)
} }
@ -100,7 +100,7 @@ fn chain_err<T: copy, U: copy, V: copy>(
res: result<T, V>, res: result<T, V>,
op: fn(V) -> result<T, U>) op: fn(V) -> result<T, U>)
-> result<T, U> { -> result<T, U> {
alt res { match res {
ok(t) => ok(t), ok(t) => ok(t),
err(v) => op(v) err(v) => op(v)
} }
@ -121,7 +121,7 @@ fn chain_err<T: copy, U: copy, V: copy>(
* } * }
*/ */
fn iter<T, E>(res: result<T, E>, f: fn(T)) { fn iter<T, E>(res: result<T, E>, f: fn(T)) {
alt res { match res {
ok(t) => f(t), ok(t) => f(t),
err(_) => () err(_) => ()
} }
@ -136,7 +136,7 @@ fn iter<T, E>(res: result<T, E>, f: fn(T)) {
* handling an error. * handling an error.
*/ */
fn iter_err<T, E>(res: result<T, E>, f: fn(E)) { fn iter_err<T, E>(res: result<T, E>, f: fn(E)) {
alt res { match res {
ok(_) => (), ok(_) => (),
err(e) => f(e) err(e) => f(e)
} }
@ -158,7 +158,7 @@ fn iter_err<T, E>(res: result<T, E>, f: fn(E)) {
*/ */
fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U) fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U)
-> result<U, E> { -> result<U, E> {
alt res { match res {
ok(t) => ok(op(t)), ok(t) => ok(op(t)),
err(e) => err(e) err(e) => err(e)
} }
@ -174,7 +174,7 @@ fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U)
*/ */
fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F) fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F)
-> result<T, F> { -> result<T, F> {
alt res { match res {
ok(t) => ok(t), ok(t) => ok(t),
err(e) => err(op(e)) err(e) => err(op(e))
} }
@ -186,14 +186,14 @@ impl extensions<T, E> for result<T, E> {
fn is_err() -> bool { is_err(self) } fn is_err() -> bool { is_err(self) }
fn iter(f: fn(T)) { fn iter(f: fn(T)) {
alt self { match self {
ok(t) => f(t), ok(t) => f(t),
err(_) => () err(_) => ()
} }
} }
fn iter_err(f: fn(E)) { fn iter_err(f: fn(E)) {
alt self { match self {
ok(_) => (), ok(_) => (),
err(e) => f(e) err(e) => f(e)
} }
@ -204,7 +204,7 @@ impl extensions<T:copy, E> for result<T, E> {
fn get() -> T { get(self) } fn get() -> T { get(self) }
fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> { fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> {
alt self { match self {
ok(t) => ok(t), ok(t) => ok(t),
err(e) => err(op(e)) err(e) => err(op(e))
} }
@ -215,7 +215,7 @@ impl extensions<T, E:copy> for result<T, E> {
fn get_err() -> E { get_err(self) } fn get_err() -> E { get_err(self) }
fn map<U:copy>(op: fn(T) -> U) -> result<U,E> { fn map<U:copy>(op: fn(T) -> U) -> result<U,E> {
alt self { match self {
ok(t) => ok(op(t)), ok(t) => ok(op(t)),
err(e) => err(e) err(e) => err(e)
} }
@ -255,7 +255,7 @@ fn map_vec<T,U:copy,V:copy>(
let mut vs: ~[V] = ~[]; let mut vs: ~[V] = ~[];
vec::reserve(vs, vec::len(ts)); vec::reserve(vs, vec::len(ts));
for vec::each(ts) |t| { for vec::each(ts) |t| {
alt op(t) { match op(t) {
ok(v) => vec::push(vs, v), ok(v) => vec::push(vs, v),
err(u) => return err(u) err(u) => return err(u)
} }
@ -266,9 +266,9 @@ fn map_vec<T,U:copy,V:copy>(
fn map_opt<T,U:copy,V:copy>( fn map_opt<T,U:copy,V:copy>(
o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> { o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> {
alt o_t { match o_t {
none => ok(none), none => ok(none),
some(t) => alt op(t) { some(t) => match op(t) {
ok(v) => ok(some(v)), ok(v) => ok(some(v)),
err(e) => err(e) err(e) => err(e)
} }
@ -293,7 +293,7 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: ~[S], ts: ~[T],
vec::reserve(vs, n); vec::reserve(vs, n);
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
alt op(ss[i],ts[i]) { match op(ss[i],ts[i]) {
ok(v) => vec::push(vs, v), ok(v) => vec::push(vs, v),
err(u) => return err(u) err(u) => return err(u)
} }
@ -314,7 +314,7 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T],
let n = vec::len(ts); let n = vec::len(ts);
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
alt op(ss[i],ts[i]) { match op(ss[i],ts[i]) {
ok(()) => (), ok(()) => (),
err(u) => return err(u) err(u) => return err(u)
} }
@ -326,7 +326,7 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T],
/// Unwraps a result, assuming it is an `ok(T)` /// Unwraps a result, assuming it is an `ok(T)`
fn unwrap<T, U>(-res: result<T, U>) -> T { fn unwrap<T, U>(-res: result<T, U>) -> T {
unsafe { unsafe {
let addr = alt res { let addr = match res {
ok(x) => ptr::addr_of(x), ok(x) => ptr::addr_of(x),
err(_) => fail ~"error result" err(_) => fail ~"error result"
}; };

View file

@ -96,7 +96,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>,
cb: fn(*c_void) -> T) -> T { cb: fn(*c_void) -> T) -> T {
// On posixy systems we can pass a char** for envp, which is // On posixy systems we can pass a char** for envp, which is
// a null-terminated array of "k=v\n" strings. // a null-terminated array of "k=v\n" strings.
alt env { match env {
some(es) if !vec::is_empty(es) => { some(es) if !vec::is_empty(es) => {
let mut tmps = ~[]; let mut tmps = ~[];
let mut ptrs = ~[]; let mut ptrs = ~[];
@ -123,7 +123,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>,
// rather a concatenation of null-terminated k=v\0 sequences, with a final // rather a concatenation of null-terminated k=v\0 sequences, with a final
// \0 to terminate. // \0 to terminate.
unsafe { unsafe {
alt env { match env {
some(es) if !vec::is_empty(es) => { some(es) if !vec::is_empty(es) => {
let mut blk : ~[u8] = ~[]; let mut blk : ~[u8] = ~[];
for vec::each(es) |e| { for vec::each(es) |e| {
@ -143,7 +143,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>,
fn with_dirp<T>(d: option<~str>, fn with_dirp<T>(d: option<~str>,
cb: fn(*libc::c_char) -> T) -> T { cb: fn(*libc::c_char) -> T) -> T {
alt d { match d {
some(dir) => str::as_c_str(dir, cb), some(dir) => str::as_c_str(dir, cb),
none => cb(ptr::null()) none => cb(ptr::null())
} }
@ -309,7 +309,7 @@ fn program_output(prog: ~str, args: ~[~str]) ->
let mut count = 2; let mut count = 2;
while count > 0 { while count > 0 {
let stream = comm::recv(p); let stream = comm::recv(p);
alt check stream { match check stream {
(1, s) => { (1, s) => {
outs = s; outs = s;
} }

View file

@ -115,7 +115,7 @@ mod linear {
k: &K) -> search_result { k: &K) -> search_result {
let _ = for self.bucket_sequence(hash) |i| { let _ = for self.bucket_sequence(hash) |i| {
alt buckets[i] { match buckets[i] {
some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) { some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) {
return found_entry(i); return found_entry(i);
} }
@ -155,7 +155,7 @@ mod linear {
/// Assumes that there will be a bucket. /// Assumes that there will be a bucket.
/// True if there was no previous entry with that key /// True if there was no previous entry with that key
fn insert_internal(hash: uint, +k: K, +v: V) -> bool { fn insert_internal(hash: uint, +k: K, +v: V) -> bool {
alt self.bucket_for_key_with_hash(self.buckets, hash, match self.bucket_for_key_with_hash(self.buckets, hash,
unsafe{borrow(k)}) { unsafe{borrow(k)}) {
table_full => {fail ~"Internal logic error";} table_full => {fail ~"Internal logic error";}
found_hole(idx) => { found_hole(idx) => {
@ -207,7 +207,7 @@ mod linear {
// I found this explanation elucidating: // I found this explanation elucidating:
// http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf // http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf
let mut idx = alt self.bucket_for_key(self.buckets, k) { let mut idx = match self.bucket_for_key(self.buckets, k) {
table_full | found_hole(_) => { table_full | found_hole(_) => {
return false; return false;
} }
@ -246,7 +246,7 @@ mod linear {
} }
fn contains_key(k: &K) -> bool { fn contains_key(k: &K) -> bool {
alt self.bucket_for_key(self.buckets, k) { match self.bucket_for_key(self.buckets, k) {
found_entry(_) => {true} found_entry(_) => {true}
table_full | found_hole(_) => {false} table_full | found_hole(_) => {false}
} }
@ -255,9 +255,9 @@ mod linear {
impl public_methods<K,V: copy> for &const linear_map<K,V> { impl public_methods<K,V: copy> for &const linear_map<K,V> {
fn find(k: &K) -> option<V> { fn find(k: &K) -> option<V> {
alt self.bucket_for_key(self.buckets, k) { match self.bucket_for_key(self.buckets, k) {
found_entry(idx) => { found_entry(idx) => {
alt check self.buckets[idx] { match check self.buckets[idx] {
some(bkt) => {some(copy bkt.value)} some(bkt) => {some(copy bkt.value)}
} }
} }

View file

@ -341,7 +341,7 @@ fn unshift_char(&s: ~str, ch: char) { s = from_char(ch) + s; }
/// Returns a string with leading whitespace removed /// Returns a string with leading whitespace removed
pure fn trim_left(s: &str) -> ~str { pure fn trim_left(s: &str) -> ~str {
alt find(s, |c| !char::is_whitespace(c)) { match find(s, |c| !char::is_whitespace(c)) {
none => ~"", none => ~"",
some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) } some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) }
} }
@ -349,7 +349,7 @@ pure fn trim_left(s: &str) -> ~str {
/// Returns a string with trailing whitespace removed /// Returns a string with trailing whitespace removed
pure fn trim_right(s: &str) -> ~str { pure fn trim_right(s: &str) -> ~str {
alt rfind(s, |c| !char::is_whitespace(c)) { match rfind(s, |c| !char::is_whitespace(c)) {
none => ~"", none => ~"",
some(last) => { some(last) => {
let {next, _} = char_range_at(s, last); let {next, _} = char_range_at(s, last);
@ -2776,7 +2776,7 @@ mod tests {
fn test_chars_iter() { fn test_chars_iter() {
let mut i = 0; let mut i = 0;
do chars_iter(~"x\u03c0y") |ch| { do chars_iter(~"x\u03c0y") |ch| {
alt check i { match check i {
0 => assert ch == 'x', 0 => assert ch == 'x',
1 => assert ch == '\u03c0', 1 => assert ch == '\u03c0',
2 => assert ch == 'y' 2 => assert ch == 'y'
@ -2792,7 +2792,7 @@ mod tests {
let mut i = 0; let mut i = 0;
do bytes_iter(~"xyz") |bb| { do bytes_iter(~"xyz") |bb| {
alt check i { match check i {
0 => assert bb == 'x' as u8, 0 => assert bb == 'x' as u8,
1 => assert bb == 'y' as u8, 1 => assert bb == 'y' as u8,
2 => assert bb == 'z' as u8 2 => assert bb == 'z' as u8
@ -2810,7 +2810,7 @@ mod tests {
let mut ii = 0; let mut ii = 0;
do split_char_iter(data, ' ') |xx| { do split_char_iter(data, ' ') |xx| {
alt ii { match ii {
0 => assert ~"\nMary" == xx, 0 => assert ~"\nMary" == xx,
1 => assert ~"had" == xx, 1 => assert ~"had" == xx,
2 => assert ~"a" == xx, 2 => assert ~"a" == xx,
@ -2828,7 +2828,7 @@ mod tests {
let mut ii = 0; let mut ii = 0;
do splitn_char_iter(data, ' ', 2u) |xx| { do splitn_char_iter(data, ' ', 2u) |xx| {
alt ii { match ii {
0 => assert ~"\nMary" == xx, 0 => assert ~"\nMary" == xx,
1 => assert ~"had" == xx, 1 => assert ~"had" == xx,
2 => assert ~"a little lamb\nLittle lamb\n" == xx, 2 => assert ~"a little lamb\nLittle lamb\n" == xx,
@ -2845,7 +2845,7 @@ mod tests {
let mut ii = 0; let mut ii = 0;
do words_iter(data) |ww| { do words_iter(data) |ww| {
alt ii { match ii {
0 => assert ~"Mary" == ww, 0 => assert ~"Mary" == ww,
1 => assert ~"had" == ww, 1 => assert ~"had" == ww,
2 => assert ~"a" == ww, 2 => assert ~"a" == ww,
@ -2865,7 +2865,7 @@ mod tests {
let mut ii = 0; let mut ii = 0;
do lines_iter(lf) |x| { do lines_iter(lf) |x| {
alt ii { match ii {
0 => assert ~"" == x, 0 => assert ~"" == x,
1 => assert ~"Mary had a little lamb" == x, 1 => assert ~"Mary had a little lamb" == x,
2 => assert ~"Little lamb" == x, 2 => assert ~"Little lamb" == x,

View file

@ -279,7 +279,7 @@ impl task_builder for task_builder {
let ch = comm::chan(po); let ch = comm::chan(po);
blk(do future::from_fn { blk(do future::from_fn {
alt comm::recv(po) { match comm::recv(po) {
exit(_, result) => result exit(_, result) => result
} }
}); });
@ -502,7 +502,7 @@ fn try<T:send>(+f: fn~() -> T) -> result<T,()> {
do task().unlinked().future_result(|-r| { result = some(r); }).spawn { do task().unlinked().future_result(|-r| { result = some(r); }).spawn {
comm::send(ch, f()); comm::send(ch, f());
} }
alt future::get(option::unwrap(result)) { match future::get(option::unwrap(result)) {
success => result::ok(comm::recv(po)), success => result::ok(comm::recv(po)),
failure => result::err(()) failure => result::err(())
} }
@ -991,7 +991,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
/*######################################################################* /*######################################################################*
* Step 1. Get spawner's taskgroup info. * Step 1. Get spawner's taskgroup info.
*######################################################################*/ *######################################################################*/
let spawner_group = alt unsafe { local_get(spawner, taskgroup_key()) } { let spawner_group = match unsafe { local_get(spawner, taskgroup_key()) } {
none => { none => {
// Main task, doing first spawn ever. Lazily initialise here. // Main task, doing first spawn ever. Lazily initialise here.
let mut members = new_taskset(); let mut members = new_taskset();
@ -1028,7 +1028,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
// assertion, but initialising it requires locking a mutex. Hence // assertion, but initialising it requires locking a mutex. Hence
// it should be enabled only in debug builds. // it should be enabled only in debug builds.
let new_generation = let new_generation =
alt *old_ancestors { match *old_ancestors {
some(arc) => access_ancestors(arc, |a| a.generation+1), some(arc) => access_ancestors(arc, |a| a.generation+1),
none => 0 // the actual value doesn't really matter. none => 0 // the actual value doesn't really matter.
}; };
@ -1047,7 +1047,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
fn share_ancestors(ancestors: &mut ancestor_list) -> ancestor_list { fn share_ancestors(ancestors: &mut ancestor_list) -> ancestor_list {
// Appease the borrow-checker. Really this wants to be written as: // Appease the borrow-checker. Really this wants to be written as:
// alt ancestors // match ancestors
// some(ancestor_arc) { ancestor_list(some(ancestor_arc.clone())) } // some(ancestor_arc) { ancestor_list(some(ancestor_arc.clone())) }
// none { ancestor_list(none) } // none { ancestor_list(none) }
let tmp = util::replace(&mut **ancestors, none); let tmp = util::replace(&mut **ancestors, none);
@ -1073,7 +1073,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
// Agh. Get move-mode items into the closure. FIXME (#2829) // Agh. Get move-mode items into the closure. FIXME (#2829)
let (child_tg, ancestors, f) = option::swap_unwrap(child_data); let (child_tg, ancestors, f) = option::swap_unwrap(child_data);
// Create child task. // Create child task.
let new_task = alt opts.sched { let new_task = match opts.sched {
none => rustrt::new_task(), none => rustrt::new_task(),
some(sched_opts) => new_task_in_new_sched(sched_opts) some(sched_opts) => new_task_in_new_sched(sched_opts)
}; };
@ -1162,7 +1162,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
fail ~"foreign_stack_size scheduler option unimplemented"; fail ~"foreign_stack_size scheduler option unimplemented";
} }
let num_threads = alt opts.mode { let num_threads = match opts.mode {
single_threaded => 1u, single_threaded => 1u,
thread_per_core => { thread_per_core => {
fail ~"thread_per_core scheduling mode unimplemented" fail ~"thread_per_core scheduling mode unimplemented"
@ -1273,7 +1273,7 @@ unsafe fn local_data_lookup<T: owned>(
let key_value = key_to_key_value(key); let key_value = key_to_key_value(key);
let map_pos = (*map).position(|entry| let map_pos = (*map).position(|entry|
alt entry { match entry {
some((k,_,_)) => k == key_value, some((k,_,_)) => k == key_value,
none => false none => false
} }
@ -1336,7 +1336,7 @@ unsafe fn local_set<T: owned>(
// Construct new entry to store in the map. // Construct new entry to store in the map.
let new_entry = some((keyval, data_ptr, data_box)); let new_entry = some((keyval, data_ptr, data_box));
// Find a place to put it. // Find a place to put it.
alt local_data_lookup(map, key) { match local_data_lookup(map, key) {
some((index, _old_data_ptr)) => { some((index, _old_data_ptr)) => {
// Key already had a value set, _old_data_ptr, whose reference // Key already had a value set, _old_data_ptr, whose reference
// will get dropped when the local_data box is overwritten. // will get dropped when the local_data box is overwritten.
@ -1344,7 +1344,7 @@ unsafe fn local_set<T: owned>(
} }
none => { none => {
// Find an empty slot. If not, grow the vector. // Find an empty slot. If not, grow the vector.
alt (*map).position(|x| x == none) { match (*map).position(|x| x == none) {
some(empty_index) => (*map).set_elt(empty_index, new_entry), some(empty_index) => (*map).set_elt(empty_index, new_entry),
none => (*map).push(new_entry) none => (*map).push(new_entry)
} }
@ -1694,7 +1694,7 @@ fn test_spawn_listiner_bidi() {
#[test] #[test]
fn test_try_success() { fn test_try_success() {
alt do try { match do try {
~"Success!" ~"Success!"
} { } {
result::ok(~"Success!") => (), result::ok(~"Success!") => (),
@ -1705,7 +1705,7 @@ fn test_try_success() {
#[test] #[test]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_try_fail() { fn test_try_fail() {
alt do try { match do try {
fail fail
} { } {
result::err(()) => (), result::err(()) => (),
@ -2052,13 +2052,13 @@ fn test_tls_pop() unsafe {
fn test_tls_modify() unsafe { fn test_tls_modify() unsafe {
fn my_key(+_x: @~str) { } fn my_key(+_x: @~str) { }
local_data_modify(my_key, |data| { local_data_modify(my_key, |data| {
alt data { match data {
some(@val) => fail ~"unwelcome value: " + val, some(@val) => fail ~"unwelcome value: " + val,
none => some(@~"first data") none => some(@~"first data")
} }
}); });
local_data_modify(my_key, |data| { local_data_modify(my_key, |data| {
alt data { match data {
some(@~"first data") => some(@~"next data"), some(@~"first data") => some(@~"next data"),
some(@val) => fail ~"wrong value: " + val, some(@val) => fail ~"wrong value: " + val,
none => fail ~"missing value" none => fail ~"missing value"

View file

@ -127,7 +127,7 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
let mut power = 1u as T; let mut power = 1u as T;
let mut n = 0u as T; let mut n = 0u as T;
loop { loop {
alt char::to_digit(buf[i] as char, radix) { match char::to_digit(buf[i] as char, radix) {
some(d) => n += d as T * power, some(d) => n += d as T * power,
none => return none none => return none
} }
@ -146,7 +146,7 @@ fn from_str_radix(buf: ~str, radix: u64) -> option<u64> {
let mut i = str::len(buf) - 1u; let mut i = str::len(buf) - 1u;
let mut power = 1u64, n = 0u64; let mut power = 1u64, n = 0u64;
loop { loop {
alt char::to_digit(buf[i] as char, radix as uint) { match char::to_digit(buf[i] as char, radix as uint) {
some(d) => n += d as u64 * power, some(d) => n += d as u64 * power,
none => return none none => return none
} }

View file

@ -1,6 +1,6 @@
mod general_category { mod general_category {
pure fn Cc(c: char) -> bool { pure fn Cc(c: char) -> bool {
return alt c { return match c {
'\x00' to '\x1f' '\x00' to '\x1f'
| '\x7f' to '\x9f' => true, | '\x7f' to '\x9f' => true,
_ => false _ => false
@ -8,7 +8,7 @@ mod general_category {
} }
pure fn Cf(c: char) -> bool { pure fn Cf(c: char) -> bool {
return alt c { return match c {
'\xad' '\xad'
| '\u0600' to '\u0603' | '\u0600' to '\u0603'
| '\u06dd' | '\u06dd'
@ -27,21 +27,21 @@ mod general_category {
} }
pure fn Co(c: char) -> bool { pure fn Co(c: char) -> bool {
return alt c { return match c {
'\ue000' to '\uf8ff' => true, '\ue000' to '\uf8ff' => true,
_ => false _ => false
}; };
} }
pure fn Cs(c: char) -> bool { pure fn Cs(c: char) -> bool {
return alt c { return match c {
'\ud800' to '\udfff' => true, '\ud800' to '\udfff' => true,
_ => false _ => false
}; };
} }
pure fn Ll(c: char) -> bool { pure fn Ll(c: char) -> bool {
return alt c { return match c {
'\x61' to '\x7a' '\x61' to '\x7a'
| '\xaa' | '\xaa'
| '\xb5' | '\xb5'
@ -646,7 +646,7 @@ mod general_category {
} }
pure fn Lm(c: char) -> bool { pure fn Lm(c: char) -> bool {
return alt c { return match c {
'\u02b0' to '\u02c1' '\u02b0' to '\u02c1'
| '\u02c6' to '\u02d1' | '\u02c6' to '\u02d1'
| '\u02e0' to '\u02e4' | '\u02e0' to '\u02e4'
@ -702,7 +702,7 @@ mod general_category {
} }
pure fn Lo(c: char) -> bool { pure fn Lo(c: char) -> bool {
return alt c { return match c {
'\u01bb' '\u01bb'
| '\u01c0' to '\u01c3' | '\u01c0' to '\u01c3'
| '\u0294' | '\u0294'
@ -888,7 +888,7 @@ mod general_category {
} }
pure fn Lt(c: char) -> bool { pure fn Lt(c: char) -> bool {
return alt c { return match c {
'\u01c5' '\u01c5'
| '\u01c8' | '\u01c8'
| '\u01cb' | '\u01cb'
@ -905,7 +905,7 @@ mod general_category {
} }
pure fn Lu(c: char) -> bool { pure fn Lu(c: char) -> bool {
return alt c { return match c {
'\x41' to '\x5a' '\x41' to '\x5a'
| '\xc0' to '\xd6' | '\xc0' to '\xd6'
| '\xd8' to '\xde' | '\xd8' to '\xde'
@ -1497,7 +1497,7 @@ mod general_category {
} }
pure fn Mc(c: char) -> bool { pure fn Mc(c: char) -> bool {
return alt c { return match c {
'\u0903' '\u0903'
| '\u093b' | '\u093b'
| '\u093e' to '\u0940' | '\u093e' to '\u0940'
@ -1608,7 +1608,7 @@ mod general_category {
} }
pure fn Me(c: char) -> bool { pure fn Me(c: char) -> bool {
return alt c { return match c {
'\u0488' to '\u0489' '\u0488' to '\u0489'
| '\u20dd' to '\u20e0' | '\u20dd' to '\u20e0'
| '\u20e2' to '\u20e4' | '\u20e2' to '\u20e4'
@ -1619,7 +1619,7 @@ mod general_category {
} }
pure fn Mn(c: char) -> bool { pure fn Mn(c: char) -> bool {
return alt c { return match c {
'\u0300' to '\u036f' '\u0300' to '\u036f'
| '\u0483' to '\u0487' | '\u0483' to '\u0487'
| '\u0591' to '\u05bd' | '\u0591' to '\u05bd'
@ -1812,7 +1812,7 @@ mod general_category {
} }
pure fn Nd(c: char) -> bool { pure fn Nd(c: char) -> bool {
return alt c { return match c {
'\x30' to '\x39' '\x30' to '\x39'
| '\u0660' to '\u0669' | '\u0660' to '\u0669'
| '\u06f0' to '\u06f9' | '\u06f0' to '\u06f9'
@ -1856,7 +1856,7 @@ mod general_category {
} }
pure fn Nl(c: char) -> bool { pure fn Nl(c: char) -> bool {
return alt c { return match c {
'\u16ee' to '\u16f0' '\u16ee' to '\u16f0'
| '\u2160' to '\u2182' | '\u2160' to '\u2182'
| '\u2185' to '\u2188' | '\u2185' to '\u2188'
@ -1875,7 +1875,7 @@ mod general_category {
} }
pure fn No(c: char) -> bool { pure fn No(c: char) -> bool {
return alt c { return match c {
'\xb2' to '\xb3' '\xb2' to '\xb3'
| '\xb9' | '\xb9'
| '\xbc' to '\xbe' | '\xbc' to '\xbe'
@ -1923,7 +1923,7 @@ mod general_category {
} }
pure fn Pc(c: char) -> bool { pure fn Pc(c: char) -> bool {
return alt c { return match c {
'\x5f' '\x5f'
| '\u203f' to '\u2040' | '\u203f' to '\u2040'
| '\u2054' | '\u2054'
@ -1936,7 +1936,7 @@ mod general_category {
} }
pure fn Pd(c: char) -> bool { pure fn Pd(c: char) -> bool {
return alt c { return match c {
'\x2d' '\x2d'
| '\u058a' | '\u058a'
| '\u05be' | '\u05be'
@ -1958,7 +1958,7 @@ mod general_category {
} }
pure fn Pe(c: char) -> bool { pure fn Pe(c: char) -> bool {
return alt c { return match c {
'\x29' '\x29'
| '\x5d' | '\x5d'
| '\x7d' | '\x7d'
@ -2035,7 +2035,7 @@ mod general_category {
} }
pure fn Pf(c: char) -> bool { pure fn Pf(c: char) -> bool {
return alt c { return match c {
'\xbb' '\xbb'
| '\u2019' | '\u2019'
| '\u201d' | '\u201d'
@ -2052,7 +2052,7 @@ mod general_category {
} }
pure fn Pi(c: char) -> bool { pure fn Pi(c: char) -> bool {
return alt c { return match c {
'\xab' '\xab'
| '\u2018' | '\u2018'
| '\u201b' to '\u201c' | '\u201b' to '\u201c'
@ -2070,7 +2070,7 @@ mod general_category {
} }
pure fn Po(c: char) -> bool { pure fn Po(c: char) -> bool {
return alt c { return match c {
'\x21' to '\x23' '\x21' to '\x23'
| '\x25' to '\x27' | '\x25' to '\x27'
| '\x2a' | '\x2a'
@ -2203,7 +2203,7 @@ mod general_category {
} }
pure fn Ps(c: char) -> bool { pure fn Ps(c: char) -> bool {
return alt c { return match c {
'\x28' '\x28'
| '\x5b' | '\x5b'
| '\x7b' | '\x7b'
@ -2282,7 +2282,7 @@ mod general_category {
} }
pure fn Sc(c: char) -> bool { pure fn Sc(c: char) -> bool {
return alt c { return match c {
'\x24' '\x24'
| '\xa2' to '\xa5' | '\xa2' to '\xa5'
| '\u060b' | '\u060b'
@ -2305,7 +2305,7 @@ mod general_category {
} }
pure fn Sk(c: char) -> bool { pure fn Sk(c: char) -> bool {
return alt c { return match c {
'\x5e' '\x5e'
| '\x60' | '\x60'
| '\xa8' | '\xa8'
@ -2339,7 +2339,7 @@ mod general_category {
} }
pure fn Sm(c: char) -> bool { pure fn Sm(c: char) -> bool {
return alt c { return match c {
'\x2b' '\x2b'
| '\x3c' to '\x3e' | '\x3c' to '\x3e'
| '\x7c' | '\x7c'
@ -2410,7 +2410,7 @@ mod general_category {
} }
pure fn So(c: char) -> bool { pure fn So(c: char) -> bool {
return alt c { return match c {
'\xa6' to '\xa7' '\xa6' to '\xa7'
| '\xa9' | '\xa9'
| '\xae' | '\xae'
@ -2529,21 +2529,21 @@ mod general_category {
} }
pure fn Zl(c: char) -> bool { pure fn Zl(c: char) -> bool {
return alt c { return match c {
'\u2028' => true, '\u2028' => true,
_ => false _ => false
}; };
} }
pure fn Zp(c: char) -> bool { pure fn Zp(c: char) -> bool {
return alt c { return match c {
'\u2029' => true, '\u2029' => true,
_ => false _ => false
}; };
} }
pure fn Zs(c: char) -> bool { pure fn Zs(c: char) -> bool {
return alt c { return match c {
'\x20' '\x20'
| '\xa0' | '\xa0'
| '\u1680' | '\u1680'
@ -2561,7 +2561,7 @@ mod general_category {
mod derived_property { mod derived_property {
/// Check if a character has the alphabetic unicode property /// Check if a character has the alphabetic unicode property
pure fn Alphabetic(c: char) -> bool { pure fn Alphabetic(c: char) -> bool {
return alt c { return match c {
'\x41' to '\x5a' '\x41' to '\x5a'
| '\x61' to '\x7a' | '\x61' to '\x7a'
| '\xaa' | '\xaa'
@ -3299,7 +3299,7 @@ mod derived_property {
} }
pure fn XID_Continue(c: char) -> bool { pure fn XID_Continue(c: char) -> bool {
return alt c { return match c {
'\x30' to '\x39' '\x30' to '\x39'
| '\x41' to '\x5a' | '\x41' to '\x5a'
| '\x5f' | '\x5f'
@ -4170,7 +4170,7 @@ mod derived_property {
} }
pure fn XID_Start(c: char) -> bool { pure fn XID_Start(c: char) -> bool {
return alt c { return match c {
'\x41' to '\x5a' '\x41' to '\x5a'
| '\x61' to '\x7a' | '\x61' to '\x7a'
| '\xaa' | '\xaa'

View file

@ -356,7 +356,7 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let mut start = 0u; let mut start = 0u;
let mut result = ~[]; let mut result = ~[];
while start < ln { while start < ln {
alt position_between(v, start, ln, f) { match position_between(v, start, ln, f) {
none => break, none => break,
some(i) => { some(i) => {
push(result, slice(v, start, i)); push(result, slice(v, start, i));
@ -380,7 +380,7 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let mut count = n; let mut count = n;
let mut result = ~[]; let mut result = ~[];
while start < ln && count > 0u { while start < ln && count > 0u {
alt position_between(v, start, ln, f) { match position_between(v, start, ln, f) {
none => break, none => break,
some(i) => { some(i) => {
push(result, slice(v, start, i)); push(result, slice(v, start, i));
@ -405,7 +405,7 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let mut end = ln; let mut end = ln;
let mut result = ~[]; let mut result = ~[];
while end > 0u { while end > 0u {
alt rposition_between(v, 0u, end, f) { match rposition_between(v, 0u, end, f) {
none => break, none => break,
some(i) => { some(i) => {
push(result, slice(v, i + 1u, end)); push(result, slice(v, i + 1u, end));
@ -429,7 +429,7 @@ fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let mut count = n; let mut count = n;
let mut result = ~[]; let mut result = ~[];
while end > 0u && count > 0u { while end > 0u && count > 0u {
alt rposition_between(v, 0u, end, f) { match rposition_between(v, 0u, end, f) {
none => break, none => break,
some(i) => { some(i) => {
push(result, slice(v, i + 1u, end)); push(result, slice(v, i + 1u, end));
@ -713,7 +713,7 @@ pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>)
-> ~[U] { -> ~[U] {
let mut result = ~[]; let mut result = ~[];
for each(v) |elem| { for each(v) |elem| {
alt f(elem) { match f(elem) {
none => {/* no-op */ } none => {/* no-op */ }
some(result_elem) => unsafe { push(result, result_elem); } some(result_elem) => unsafe { push(result, result_elem); }
} }

View file

@ -30,7 +30,7 @@ impl of to_base64 for ~[u8] {
i += 3u; i += 3u;
} }
alt check len % 3u { match check len % 3u {
0u => (), 0u => (),
1u => { 1u => {
let n = (self[i] as uint) << 16u; let n = (self[i] as uint) << 16u;
@ -96,7 +96,7 @@ impl of from_base64 for ~[u8] {
} else if ch == '/' { } else if ch == '/' {
n |= 0x3Fu; n |= 0x3Fu;
} else if ch == '=' { } else if ch == '=' {
alt len - i { match len - i {
1u => { 1u => {
vec::push(r, ((n >> 16u) & 0xFFu) as u8); vec::push(r, ((n >> 16u) & 0xFFu) as u8);
vec::push(r, ((n >> 8u ) & 0xFFu) as u8); vec::push(r, ((n >> 8u ) & 0xFFu) as u8);

View file

@ -179,9 +179,9 @@ class bitv {
if self.nbits != other.nbits { if self.nbits != other.nbits {
self.die(); self.die();
} }
alt self.rep { match self.rep {
small(s) => alt other.rep { small(s) => match other.rep {
small(s1) => alt op { small(s1) => match op {
union => s.union(s1), union => s.union(s1),
intersect => s.intersect(s1), intersect => s.intersect(s1),
assign => s.become(s1), assign => s.become(s1),
@ -189,9 +189,9 @@ class bitv {
} }
big(s1) => self.die() big(s1) => self.die()
} }
big(s) => alt other.rep { big(s) => match other.rep {
small(_) => self.die(), small(_) => self.die(),
big(s1) => alt op { big(s1) => match op {
union => s.union(s1), union => s.union(s1),
intersect => s.intersect(s1), intersect => s.intersect(s1),
assign => s.become(s1), assign => s.become(s1),
@ -232,7 +232,7 @@ class bitv {
/// Makes a copy of a bitvector /// Makes a copy of a bitvector
#[inline(always)] #[inline(always)]
fn clone() -> ~bitv { fn clone() -> ~bitv {
~alt self.rep { ~match self.rep {
small(b) => { small(b) => {
bitv{nbits: self.nbits, rep: small(~small_bitv{bits: b.bits})} bitv{nbits: self.nbits, rep: small(~small_bitv{bits: b.bits})}
} }
@ -249,7 +249,7 @@ class bitv {
#[inline(always)] #[inline(always)]
pure fn get(i: uint) -> bool { pure fn get(i: uint) -> bool {
assert (i < self.nbits); assert (i < self.nbits);
alt self.rep { match self.rep {
big(b) => b.get(i), big(b) => b.get(i),
small(s) => s.get(i) small(s) => s.get(i)
} }
@ -263,7 +263,7 @@ class bitv {
#[inline(always)] #[inline(always)]
fn set(i: uint, x: bool) { fn set(i: uint, x: bool) {
assert (i < self.nbits); assert (i < self.nbits);
alt self.rep { match self.rep {
big(b) => b.set(i, x), big(b) => b.set(i, x),
small(s) => s.set(i, x) small(s) => s.set(i, x)
} }
@ -278,12 +278,12 @@ class bitv {
#[inline(always)] #[inline(always)]
fn equal(v1: bitv) -> bool { fn equal(v1: bitv) -> bool {
if self.nbits != v1.nbits { return false; } if self.nbits != v1.nbits { return false; }
alt self.rep { match self.rep {
small(b) => alt v1.rep { small(b) => match v1.rep {
small(b1) => b.equals(b1), small(b1) => b.equals(b1),
_ => false _ => false
} }
big(s) => alt v1.rep { big(s) => match v1.rep {
big(s1) => s.equals(s1), big(s1) => s.equals(s1),
small(_) => return false small(_) => return false
} }
@ -293,7 +293,7 @@ class bitv {
/// Set all bits to 0 /// Set all bits to 0
#[inline(always)] #[inline(always)]
fn clear() { fn clear() {
alt self.rep { match self.rep {
small(b) => b.clear(), small(b) => b.clear(),
big(s) => for s.each_storage() |w| { w = 0u } big(s) => for s.each_storage() |w| { w = 0u }
} }
@ -302,7 +302,7 @@ class bitv {
/// Set all bits to 1 /// Set all bits to 1
#[inline(always)] #[inline(always)]
fn set_all() { fn set_all() {
alt self.rep { match self.rep {
small(b) => b.set_all(), small(b) => b.set_all(),
big(s) => for s.each_storage() |w| { w = !0u } } big(s) => for s.each_storage() |w| { w = !0u } }
} }
@ -310,7 +310,7 @@ class bitv {
/// Invert all bits /// Invert all bits
#[inline(always)] #[inline(always)]
fn invert() { fn invert() {
alt self.rep { match self.rep {
small(b) => b.invert(), small(b) => b.invert(),
big(s) => for s.each_storage() |w| { w = !w } } big(s) => for s.each_storage() |w| { w = !w } }
} }
@ -329,7 +329,7 @@ class bitv {
/// Returns true if all bits are 1 /// Returns true if all bits are 1
#[inline(always)] #[inline(always)]
fn is_true() -> bool { fn is_true() -> bool {
alt self.rep { match self.rep {
small(b) => b.is_true(), small(b) => b.is_true(),
_ => { _ => {
for self.each() |i| { if !i { return false; } } for self.each() |i| { if !i { return false; } }
@ -350,7 +350,7 @@ class bitv {
/// Returns true if all bits are 0 /// Returns true if all bits are 0
fn is_false() -> bool { fn is_false() -> bool {
alt self.rep { match self.rep {
small(b) => b.is_false(), small(b) => b.is_false(),
big(_) => { big(_) => {
for self.each() |i| { if i { return false; } } for self.each() |i| { if i { return false; } }

View file

@ -46,7 +46,7 @@ class dtor_res {
let dtor: option<fn@()>; let dtor: option<fn@()>;
new(dtor: option<fn@()>) { self.dtor = dtor; } new(dtor: option<fn@()>) { self.dtor = dtor; }
drop { drop {
alt self.dtor { match self.dtor {
option::none => (), option::none => (),
option::some(f) => f() option::some(f) => f()
} }

View file

@ -41,7 +41,7 @@ fn create<T: copy>() -> t<T> {
return rv; return rv;
} }
fn get<T: copy>(elts: dvec<cell<T>>, i: uint) -> T { fn get<T: copy>(elts: dvec<cell<T>>, i: uint) -> T {
alt elts.get_elt(i) { some(t) => t, _ => fail } match elts.get_elt(i) { some(t) => t, _ => fail }
} }
type repr<T> = {mut nelts: uint, type repr<T> = {mut nelts: uint,
@ -238,32 +238,32 @@ mod tests {
fn inteq(&&a: int, &&b: int) -> bool { return a == b; } fn inteq(&&a: int, &&b: int) -> bool { return a == b; }
fn intboxeq(&&a: @int, &&b: @int) -> bool { return a == b; } fn intboxeq(&&a: @int, &&b: @int) -> bool { return a == b; }
fn taggyeq(a: taggy, b: taggy) -> bool { fn taggyeq(a: taggy, b: taggy) -> bool {
alt a { match a {
one(a1) => alt b { one(a1) => match b {
one(b1) => return a1 == b1, one(b1) => return a1 == b1,
_ => return false _ => return false
} }
two(a1, a2) => alt b { two(a1, a2) => match b {
two(b1, b2) => return a1 == b1 && a2 == b2, two(b1, b2) => return a1 == b1 && a2 == b2,
_ => return false _ => return false
} }
three(a1, a2, a3) => alt b { three(a1, a2, a3) => match b {
three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3, three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3,
_ => return false _ => return false
} }
} }
} }
fn taggypareq<T>(a: taggypar<T>, b: taggypar<T>) -> bool { fn taggypareq<T>(a: taggypar<T>, b: taggypar<T>) -> bool {
alt a { match a {
onepar::<T>(a1) => alt b { onepar::<T>(a1) => match b {
onepar::<T>(b1) => return a1 == b1, onepar::<T>(b1) => return a1 == b1,
_ => return false _ => return false
} }
twopar::<T>(a1, a2) => alt b { twopar::<T>(a1, a2) => match b {
twopar::<T>(b1, b2) => return a1 == b1 && a2 == b2, twopar::<T>(b1, b2) => return a1 == b1 && a2 == b2,
_ => return false _ => return false
} }
threepar::<T>(a1, a2, a3) => alt b { threepar::<T>(a1, a2, a3) => match b {
threepar::<T>(b1, b2, b3) => { threepar::<T>(b1, b2, b3) => {
return a1 == b1 && a2 == b2 && a3 == b3 return a1 == b1 && a2 == b2 && a3 == b3
} }

View file

@ -113,7 +113,7 @@ fn maybe_get_doc(d: doc, tg: uint) -> option<doc> {
} }
fn get_doc(d: doc, tg: uint) -> doc { fn get_doc(d: doc, tg: uint) -> doc {
alt maybe_get_doc(d, tg) { match maybe_get_doc(d, tg) {
some(d) => return d, some(d) => return d,
none => { none => {
error!{"failed to find block with tag %u", tg}; error!{"failed to find block with tag %u", tg};
@ -189,7 +189,7 @@ enum writer {
} }
fn write_sized_vuint(w: io::writer, n: uint, size: uint) { fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
alt size { match size {
1u => w.write(&[0x80u8 | (n as u8)]), 1u => w.write(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]), 2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8, 3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
@ -593,7 +593,7 @@ fn test_option_int() {
fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) { fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) {
do s.emit_enum(~"core::option::t") { do s.emit_enum(~"core::option::t") {
alt v { match v {
none => s.emit_enum_variant( none => s.emit_enum_variant(
~"core::option::none", 0u, 0u, || { } ), ~"core::option::none", 0u, 0u, || { } ),
some(v0) => { some(v0) => {
@ -612,7 +612,7 @@ fn test_option_int() {
fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> { fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> {
do s.read_enum(~"core::option::t") { do s.read_enum(~"core::option::t") {
do s.read_enum_variant |i| { do s.read_enum_variant |i| {
alt check i { match check i {
0u => none, 0u => none,
1u => { 1u => {
let v0 = do s.read_enum_variant_arg(0u) { let v0 = do s.read_enum_variant_arg(0u) {

View file

@ -30,7 +30,7 @@ fn init<K, V>() -> treemap<K, V> { @empty }
/// Insert a value into the map /// Insert a value into the map
fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> { fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> {
@alt m { @match m {
@empty => node(@k, @v, @empty, @empty), @empty => node(@k, @v, @empty, @empty),
@node(@kk, vv, left, right) => { @node(@kk, vv, left, right) => {
if k < kk { if k < kk {
@ -44,7 +44,7 @@ fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> {
/// Find a value based on the key /// Find a value based on the key
fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> { fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
alt *m { match *m {
empty => none, empty => none,
node(@kk, @v, left, right) => { node(@kk, @v, left, right) => {
if k == kk { if k == kk {
@ -56,7 +56,7 @@ fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
/// Visit all pairs in the map in order. /// Visit all pairs in the map in order.
fn traverse<K, V: copy>(m: treemap<K, V>, f: fn(K, V)) { fn traverse<K, V: copy>(m: treemap<K, V>, f: fn(K, V)) {
alt *m { match *m {
empty => (), empty => (),
/* /*
Previously, this had what looked like redundant Previously, this had what looked like redundant

View file

@ -43,7 +43,7 @@
* optflag("h"), * optflag("h"),
* optflag("help") * optflag("help")
* ]; * ];
* let matches = alt getopts(vec::tail(args), opts) { * let matches = match getopts(vec::tail(args), opts) {
* result::ok(m) { m } * result::ok(m) { m }
* result::err(f) { fail fail_str(f) } * result::err(f) { fail fail_str(f) }
* }; * };
@ -140,7 +140,7 @@ fn is_arg(arg: ~str) -> bool {
} }
fn name_str(nm: name) -> ~str { fn name_str(nm: name) -> ~str {
return alt nm { return match nm {
short(ch) => str::from_char(ch), short(ch) => str::from_char(ch),
long(s) => s long(s) => s
}; };
@ -164,7 +164,7 @@ enum fail_ {
/// Convert a `fail_` enum into an error string /// Convert a `fail_` enum into an error string
fn fail_str(f: fail_) -> ~str { fn fail_str(f: fail_) -> ~str {
return alt f { return match f {
argument_missing(nm) => ~"Argument to option '" + nm + ~"' missing.", argument_missing(nm) => ~"Argument to option '" + nm + ~"' missing.",
unrecognized_option(nm) => ~"Unrecognized option: '" + nm + ~"'.", unrecognized_option(nm) => ~"Unrecognized option: '" + nm + ~"'.",
option_missing(nm) => ~"Required option '" + nm + ~"' missing.", option_missing(nm) => ~"Required option '" + nm + ~"' missing.",
@ -233,12 +233,14 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
correctly correctly
*/ */
alt find_opt(opts, opt) { match find_opt(opts, opt) {
some(id) => last_valid_opt_id = option::some(id), some(id) => last_valid_opt_id = option::some(id),
none => { none => {
let arg_follows = let arg_follows =
option::is_some(last_valid_opt_id) && option::is_some(last_valid_opt_id) &&
alt opts[option::get(last_valid_opt_id)].hasarg { match opts[option::get(last_valid_opt_id)]
.hasarg {
yes | maybe => true, yes | maybe => true,
no => false no => false
}; };
@ -257,11 +259,11 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
let mut name_pos = 0u; let mut name_pos = 0u;
for vec::each(names) |nm| { for vec::each(names) |nm| {
name_pos += 1u; name_pos += 1u;
let optid = alt find_opt(opts, nm) { let optid = match find_opt(opts, nm) {
some(id) => id, some(id) => id,
none => return err(unrecognized_option(name_str(nm))) none => return err(unrecognized_option(name_str(nm)))
}; };
alt opts[optid].hasarg { match opts[optid].hasarg {
no => { no => {
if !option::is_none::<~str>(i_arg) { if !option::is_none::<~str>(i_arg) {
return err(unexpected_argument(name_str(nm))); return err(unexpected_argument(name_str(nm)));
@ -309,7 +311,7 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
} }
fn opt_vals(m: matches, nm: ~str) -> ~[optval] { fn opt_vals(m: matches, nm: ~str) -> ~[optval] {
return alt find_opt(m.opts, mkname(nm)) { return match find_opt(m.opts, mkname(nm)) {
some(id) => m.vals[id], some(id) => m.vals[id],
none => { none => {
error!{"No option '%s' defined", nm}; error!{"No option '%s' defined", nm};
@ -328,7 +330,7 @@ fn opt_present(m: matches, nm: ~str) -> bool {
/// Returns true if any of several options were matched /// Returns true if any of several options were matched
fn opts_present(m: matches, names: ~[~str]) -> bool { fn opts_present(m: matches, names: ~[~str]) -> bool {
for vec::each(names) |nm| { for vec::each(names) |nm| {
alt find_opt(m.opts, mkname(nm)) { match find_opt(m.opts, mkname(nm)) {
some(_) => return true, some(_) => return true,
_ => () _ => ()
} }
@ -344,7 +346,7 @@ fn opts_present(m: matches, names: ~[~str]) -> bool {
* argument * argument
*/ */
fn opt_str(m: matches, nm: ~str) -> ~str { fn opt_str(m: matches, nm: ~str) -> ~str {
return alt opt_val(m, nm) { val(s) => s, _ => fail }; return match opt_val(m, nm) { val(s) => s, _ => fail };
} }
/** /**
@ -355,7 +357,7 @@ fn opt_str(m: matches, nm: ~str) -> ~str {
*/ */
fn opts_str(m: matches, names: ~[~str]) -> ~str { fn opts_str(m: matches, names: ~[~str]) -> ~str {
for vec::each(names) |nm| { for vec::each(names) |nm| {
alt opt_val(m, nm) { match opt_val(m, nm) {
val(s) => return s, val(s) => return s,
_ => () _ => ()
} }
@ -373,7 +375,7 @@ fn opts_str(m: matches, names: ~[~str]) -> ~str {
fn opt_strs(m: matches, nm: ~str) -> ~[~str] { fn opt_strs(m: matches, nm: ~str) -> ~[~str] {
let mut acc: ~[~str] = ~[]; let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(m, nm)) |v| { for vec::each(opt_vals(m, nm)) |v| {
alt v { val(s) => vec::push(acc, s), _ => () } match v { val(s) => vec::push(acc, s), _ => () }
} }
return acc; return acc;
} }
@ -382,7 +384,7 @@ fn opt_strs(m: matches, nm: ~str) -> ~[~str] {
fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> { fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
let vals = opt_vals(m, nm); let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { return none::<~str>; } if vec::len::<optval>(vals) == 0u { return none::<~str>; }
return alt vals[0] { val(s) => some::<~str>(s), _ => none::<~str> }; return match vals[0] { val(s) => some::<~str>(s), _ => none::<~str> };
} }
@ -396,7 +398,7 @@ fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~str> { fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~str> {
let vals = opt_vals(m, nm); let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { return none::<~str>; } if vec::len::<optval>(vals) == 0u { return none::<~str>; }
return alt vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) } return match vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) }
} }
#[cfg(test)] #[cfg(test)]
@ -413,7 +415,7 @@ mod tests {
} }
fn check_fail_type(f: fail_, ft: fail_type) { fn check_fail_type(f: fail_, ft: fail_type) {
alt f { match f {
argument_missing(_) => assert ft == argument_missing_, argument_missing(_) => assert ft == argument_missing_,
unrecognized_option(_) => assert ft == unrecognized_option_, unrecognized_option(_) => assert ft == unrecognized_option_,
option_missing(_) => assert ft == option_missing_, option_missing(_) => assert ft == option_missing_,
@ -429,7 +431,7 @@ mod tests {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt check rs { match check rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"test")); assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20"); assert (opt_str(m, ~"test") == ~"20");
@ -442,7 +444,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_missing_), err(f) => check_fail_type(f, option_missing_),
_ => fail _ => fail
} }
@ -453,7 +455,7 @@ mod tests {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, argument_missing_), err(f) => check_fail_type(f, argument_missing_),
_ => fail _ => fail
} }
@ -464,7 +466,7 @@ mod tests {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_duplicated_), err(f) => check_fail_type(f, option_duplicated_),
_ => fail _ => fail
} }
@ -475,7 +477,7 @@ mod tests {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"t")); assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20"); assert (opt_str(m, ~"t") == ~"20");
@ -489,7 +491,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_missing_), err(f) => check_fail_type(f, option_missing_),
_ => fail _ => fail
} }
@ -500,7 +502,7 @@ mod tests {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, argument_missing_), err(f) => check_fail_type(f, argument_missing_),
_ => fail _ => fail
} }
@ -511,7 +513,7 @@ mod tests {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_duplicated_), err(f) => check_fail_type(f, option_duplicated_),
_ => fail _ => fail
} }
@ -524,7 +526,7 @@ mod tests {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"test")); assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20"); assert (opt_str(m, ~"test") == ~"20");
@ -538,7 +540,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (!opt_present(m, ~"test")), ok(m) => assert (!opt_present(m, ~"test")),
_ => fail _ => fail
} }
@ -549,7 +551,7 @@ mod tests {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, argument_missing_), err(f) => check_fail_type(f, argument_missing_),
_ => fail _ => fail
} }
@ -560,7 +562,7 @@ mod tests {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_duplicated_), err(f) => check_fail_type(f, option_duplicated_),
_ => fail _ => fail
} }
@ -571,7 +573,7 @@ mod tests {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"t")); assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20"); assert (opt_str(m, ~"t") == ~"20");
@ -585,7 +587,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (!opt_present(m, ~"t")), ok(m) => assert (!opt_present(m, ~"t")),
_ => fail _ => fail
} }
@ -596,7 +598,7 @@ mod tests {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, argument_missing_), err(f) => check_fail_type(f, argument_missing_),
_ => fail _ => fail
} }
@ -607,7 +609,7 @@ mod tests {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_duplicated_), err(f) => check_fail_type(f, option_duplicated_),
_ => fail _ => fail
} }
@ -620,7 +622,7 @@ mod tests {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (opt_present(m, ~"test")), ok(m) => assert (opt_present(m, ~"test")),
_ => fail _ => fail
} }
@ -631,7 +633,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (!opt_present(m, ~"test")), ok(m) => assert (!opt_present(m, ~"test")),
_ => fail _ => fail
} }
@ -642,7 +644,7 @@ mod tests {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => { err(f) => {
log(error, fail_str(f)); log(error, fail_str(f));
check_fail_type(f, unexpected_argument_); check_fail_type(f, unexpected_argument_);
@ -656,7 +658,7 @@ mod tests {
let args = ~[~"--test", ~"--test"]; let args = ~[~"--test", ~"--test"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_duplicated_), err(f) => check_fail_type(f, option_duplicated_),
_ => fail _ => fail
} }
@ -667,7 +669,7 @@ mod tests {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (opt_present(m, ~"t")), ok(m) => assert (opt_present(m, ~"t")),
_ => fail _ => fail
} }
@ -678,7 +680,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (!opt_present(m, ~"t")), ok(m) => assert (!opt_present(m, ~"t")),
_ => fail _ => fail
} }
@ -689,7 +691,7 @@ mod tests {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
// The next variable after the flag is just a free argument // The next variable after the flag is just a free argument
@ -704,7 +706,7 @@ mod tests {
let args = ~[~"-t", ~"-t"]; let args = ~[~"-t", ~"-t"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, option_duplicated_), err(f) => check_fail_type(f, option_duplicated_),
_ => fail _ => fail
} }
@ -717,7 +719,7 @@ mod tests {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"test")); assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20"); assert (opt_str(m, ~"test") == ~"20");
@ -731,7 +733,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (!opt_present(m, ~"test")), ok(m) => assert (!opt_present(m, ~"test")),
_ => fail _ => fail
} }
@ -742,7 +744,7 @@ mod tests {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, argument_missing_), err(f) => check_fail_type(f, argument_missing_),
_ => fail _ => fail
} }
@ -753,7 +755,7 @@ mod tests {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"test")); assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20"); assert (opt_str(m, ~"test") == ~"20");
@ -769,7 +771,7 @@ mod tests {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"t")); assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20"); assert (opt_str(m, ~"t") == ~"20");
@ -783,7 +785,7 @@ mod tests {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => assert (!opt_present(m, ~"t")), ok(m) => assert (!opt_present(m, ~"t")),
_ => fail _ => fail
} }
@ -794,7 +796,7 @@ mod tests {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, argument_missing_), err(f) => check_fail_type(f, argument_missing_),
_ => fail _ => fail
} }
@ -805,7 +807,7 @@ mod tests {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (opt_present(m, ~"t")); assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20"); assert (opt_str(m, ~"t") == ~"20");
@ -821,7 +823,7 @@ mod tests {
let args = ~[~"--untest"]; let args = ~[~"--untest"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, unrecognized_option_), err(f) => check_fail_type(f, unrecognized_option_),
_ => fail _ => fail
} }
@ -832,7 +834,7 @@ mod tests {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
err(f) => check_fail_type(f, unrecognized_option_), err(f) => check_fail_type(f, unrecognized_option_),
_ => fail _ => fail
} }
@ -849,7 +851,7 @@ mod tests {
optflag(~"f"), optmulti(~"m"), optmulti(~"n"), optflag(~"f"), optmulti(~"m"), optmulti(~"n"),
optopt(~"notpresent")]; optopt(~"notpresent")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
alt rs { match rs {
ok(m) => { ok(m) => {
assert (m.free[0] == ~"prog"); assert (m.free[0] == ~"prog");
assert (m.free[1] == ~"free1"); assert (m.free[1] == ~"free1");
@ -872,7 +874,7 @@ mod tests {
fn test_multi() { fn test_multi() {
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
let opts = ~[optopt(~"e"), optopt(~"encrypt")]; let opts = ~[optopt(~"e"), optopt(~"encrypt")];
let matches = alt getopts(args, opts) { let matches = match getopts(args, opts) {
result::ok(m) => m, result::ok(m) => m,
result::err(f) => fail result::err(f) => fail
}; };
@ -893,7 +895,7 @@ mod tests {
fn test_nospace() { fn test_nospace() {
let args = ~[~"-Lfoo"]; let args = ~[~"-Lfoo"];
let opts = ~[optmulti(~"L")]; let opts = ~[optmulti(~"L")];
let matches = alt getopts(args, opts) { let matches = match getopts(args, opts) {
result::ok(m) => m, result::ok(m) => m,
result::err(f) => fail result::err(f) => fail
}; };

View file

@ -45,7 +45,7 @@ type error = {
/// Serializes a json value into a io::writer /// Serializes a json value into a io::writer
fn to_writer(wr: io::writer, j: json) { fn to_writer(wr: io::writer, j: json) {
alt j { match j {
num(n) => wr.write_str(float::to_str(n, 6u)), num(n) => wr.write_str(float::to_str(n, 6u)),
string(s) => wr.write_str(escape_str(*s)), string(s) => wr.write_str(escape_str(*s)),
boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }), boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }),
@ -87,7 +87,7 @@ fn to_writer(wr: io::writer, j: json) {
fn escape_str(s: ~str) -> ~str { fn escape_str(s: ~str) -> ~str {
let mut escaped = ~"\""; let mut escaped = ~"\"";
do str::chars_iter(s) |c| { do str::chars_iter(s) |c| {
alt c { match c {
'"' => escaped += ~"\\\"", '"' => escaped += ~"\\\"",
'\\' => escaped += ~"\\\\", '\\' => escaped += ~"\\\\",
'\x08' => escaped += ~"\\b", '\x08' => escaped += ~"\\b",
@ -144,7 +144,7 @@ impl parser for parser {
} }
fn parse() -> result<json, error> { fn parse() -> result<json, error> {
alt self.parse_value() { match self.parse_value() {
ok(value) => { ok(value) => {
// Skip trailing whitespaces. // Skip trailing whitespaces.
self.parse_whitespace(); self.parse_whitespace();
@ -164,12 +164,12 @@ impl parser for parser {
if self.eof() { return self.error(~"EOF while parsing value"); } if self.eof() { return self.error(~"EOF while parsing value"); }
alt self.ch { match self.ch {
'n' => self.parse_ident(~"ull", null), 'n' => self.parse_ident(~"ull", null),
't' => self.parse_ident(~"rue", boolean(true)), 't' => self.parse_ident(~"rue", boolean(true)),
'f' => self.parse_ident(~"alse", boolean(false)), 'f' => self.parse_ident(~"alse", boolean(false)),
'0' to '9' | '-' => self.parse_number(), '0' to '9' | '-' => self.parse_number(),
'"' => alt self.parse_str() { '"' => match self.parse_str() {
ok(s) => ok(string(s)), ok(s) => ok(string(s)),
err(e) => err(e) err(e) => err(e)
} }
@ -200,20 +200,20 @@ impl parser for parser {
neg = -1f; neg = -1f;
} }
let mut res = alt self.parse_integer() { let mut res = match self.parse_integer() {
ok(res) => res, ok(res) => res,
err(e) => return err(e) err(e) => return err(e)
}; };
if self.ch == '.' { if self.ch == '.' {
alt self.parse_decimal(res) { match self.parse_decimal(res) {
ok(r) => res = r, ok(r) => res = r,
err(e) => return err(e) err(e) => return err(e)
} }
} }
if self.ch == 'e' || self.ch == 'E' { if self.ch == 'e' || self.ch == 'E' {
alt self.parse_exponent(res) { match self.parse_exponent(res) {
ok(r) => res = r, ok(r) => res = r,
err(e) => return err(e) err(e) => return err(e)
} }
@ -225,19 +225,19 @@ impl parser for parser {
fn parse_integer() -> result<float, error> { fn parse_integer() -> result<float, error> {
let mut res = 0f; let mut res = 0f;
alt self.ch { match self.ch {
'0' => { '0' => {
self.bump(); self.bump();
// There can be only one leading '0'. // There can be only one leading '0'.
alt self.ch { match self.ch {
'0' to '9' => return self.error(~"invalid number"), '0' to '9' => return self.error(~"invalid number"),
_ => () _ => ()
} }
} }
'1' to '9' => { '1' to '9' => {
while !self.eof() { while !self.eof() {
alt self.ch { match self.ch {
'0' to '9' => { '0' to '9' => {
res *= 10f; res *= 10f;
res += ((self.ch as int) - ('0' as int)) as float; res += ((self.ch as int) - ('0' as int)) as float;
@ -258,7 +258,7 @@ impl parser for parser {
self.bump(); self.bump();
// Make sure a digit follows the decimal place. // Make sure a digit follows the decimal place.
alt self.ch { match self.ch {
'0' to '9' => (), '0' to '9' => (),
_ => return self.error(~"invalid number") _ => return self.error(~"invalid number")
} }
@ -266,7 +266,7 @@ impl parser for parser {
let mut res = res; let mut res = res;
let mut dec = 1f; let mut dec = 1f;
while !self.eof() { while !self.eof() {
alt self.ch { match self.ch {
'0' to '9' => { '0' to '9' => {
dec /= 10f; dec /= 10f;
res += (((self.ch as int) - ('0' as int)) as float) * dec; res += (((self.ch as int) - ('0' as int)) as float) * dec;
@ -287,20 +287,20 @@ impl parser for parser {
let mut exp = 0u; let mut exp = 0u;
let mut neg_exp = false; let mut neg_exp = false;
alt self.ch { match self.ch {
'+' => self.bump(), '+' => self.bump(),
'-' => { self.bump(); neg_exp = true; } '-' => { self.bump(); neg_exp = true; }
_ => () _ => ()
} }
// Make sure a digit follows the exponent place. // Make sure a digit follows the exponent place.
alt self.ch { match self.ch {
'0' to '9' => (), '0' to '9' => (),
_ => return self.error(~"invalid number") _ => return self.error(~"invalid number")
} }
while !self.eof() { while !self.eof() {
alt self.ch { match self.ch {
'0' to '9' => { '0' to '9' => {
exp *= 10u; exp *= 10u;
exp += (self.ch as uint) - ('0' as uint); exp += (self.ch as uint) - ('0' as uint);
@ -329,7 +329,7 @@ impl parser for parser {
self.bump(); self.bump();
if (escape) { if (escape) {
alt self.ch { match self.ch {
'"' => str::push_char(res, '"'), '"' => str::push_char(res, '"'),
'\\' => str::push_char(res, '\\'), '\\' => str::push_char(res, '\\'),
'/' => str::push_char(res, '/'), '/' => str::push_char(res, '/'),
@ -343,7 +343,7 @@ impl parser for parser {
let mut i = 0u; let mut i = 0u;
let mut n = 0u; let mut n = 0u;
while i < 4u { while i < 4u {
alt self.next_char() { match self.next_char() {
'0' to '9' => { '0' to '9' => {
n = n * 10u + n = n * 10u +
(self.ch as uint) - ('0' as uint); (self.ch as uint) - ('0' as uint);
@ -389,7 +389,7 @@ impl parser for parser {
} }
loop { loop {
alt self.parse_value() { match self.parse_value() {
ok(v) => vec::push(values, v), ok(v) => vec::push(values, v),
e => return e e => return e
} }
@ -399,7 +399,7 @@ impl parser for parser {
return self.error(~"EOF while parsing list"); return self.error(~"EOF while parsing list");
} }
alt self.ch { match self.ch {
',' => self.bump(), ',' => self.bump(),
']' => { self.bump(); return ok(list(@values)); } ']' => { self.bump(); return ok(list(@values)); }
_ => return self.error(~"expected `,` or `]`") _ => return self.error(~"expected `,` or `]`")
@ -425,7 +425,7 @@ impl parser for parser {
return self.error(~"key must be a string"); return self.error(~"key must be a string");
} }
let key = alt self.parse_str() { let key = match self.parse_str() {
ok(key) => key, ok(key) => key,
err(e) => return err(e) err(e) => return err(e)
}; };
@ -438,13 +438,13 @@ impl parser for parser {
} }
self.bump(); self.bump();
alt self.parse_value() { match self.parse_value() {
ok(value) => { values.insert(copy *key, value); } ok(value) => { values.insert(copy *key, value); }
e => return e e => return e
} }
self.parse_whitespace(); self.parse_whitespace();
alt self.ch { match self.ch {
',' => self.bump(), ',' => self.bump(),
'}' => { self.bump(); return ok(dict(values)); } '}' => { self.bump(); return ok(dict(values)); }
_ => { _ => {
@ -477,7 +477,7 @@ fn from_str(s: ~str) -> result<json, error> {
/// Test if two json values are equal /// Test if two json values are equal
fn eq(value0: json, value1: json) -> bool { fn eq(value0: json, value1: json) -> bool {
alt (value0, value1) { match (value0, value1) {
(num(f0), num(f1)) => f0 == f1, (num(f0), num(f1)) => f0 == f1,
(string(s0), string(s1)) => s0 == s1, (string(s0), string(s1)) => s0 == s1,
(boolean(b0), boolean(b1)) => b0 == b1, (boolean(b0), boolean(b1)) => b0 == b1,
@ -486,7 +486,7 @@ fn eq(value0: json, value1: json) -> bool {
if d0.size() == d1.size() { if d0.size() == d1.size() {
let mut equal = true; let mut equal = true;
for d0.each |k, v0| { for d0.each |k, v0| {
alt d1.find(k) { match d1.find(k) {
some(v1) => if !eq(v0, v1) { equal = false }, some(v1) => if !eq(v0, v1) { equal = false },
none => equal = false none => equal = false
} }
@ -581,7 +581,7 @@ impl of to_json for @~str {
impl <A: to_json, B: to_json> of to_json for (A, B) { impl <A: to_json, B: to_json> of to_json for (A, B) {
fn to_json() -> json { fn to_json() -> json {
alt self { match self {
(a, b) => { (a, b) => {
list(@~[a.to_json(), b.to_json()]) list(@~[a.to_json(), b.to_json()])
} }
@ -592,7 +592,7 @@ impl <A: to_json, B: to_json> of to_json for (A, B) {
impl <A: to_json, B: to_json, C: to_json> impl <A: to_json, B: to_json, C: to_json>
of to_json for (A, B, C) { of to_json for (A, B, C) {
fn to_json() -> json { fn to_json() -> json {
alt self { match self {
(a, b, c) => { (a, b, c) => {
list(@~[a.to_json(), b.to_json(), c.to_json()]) list(@~[a.to_json(), b.to_json(), c.to_json()])
} }
@ -616,7 +616,7 @@ impl <A: to_json copy> of to_json for hashmap<~str, A> {
impl <A: to_json> of to_json for option<A> { impl <A: to_json> of to_json for option<A> {
fn to_json() -> json { fn to_json() -> json {
alt self { match self {
none => null, none => null,
some(value) => value.to_json() some(value) => value.to_json()
} }

View file

@ -43,7 +43,7 @@ fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> { fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> {
let mut ls = ls; let mut ls = ls;
loop { loop {
ls = alt *ls { ls = match *ls {
cons(hd, tl) => { cons(hd, tl) => {
if f(hd) { return some(hd); } if f(hd) { return some(hd); }
tl tl
@ -63,7 +63,7 @@ fn has<T: copy>(ls: @list<T>, elt: T) -> bool {
/// Returns true if the list is empty /// Returns true if the list is empty
pure fn is_empty<T: copy>(ls: @list<T>) -> bool { pure fn is_empty<T: copy>(ls: @list<T>) -> bool {
alt *ls { match *ls {
nil => true, nil => true,
_ => false _ => false
} }
@ -83,7 +83,7 @@ fn len<T>(ls: @list<T>) -> uint {
/// Returns all but the first element of a list /// Returns all but the first element of a list
pure fn tail<T: copy>(ls: @list<T>) -> @list<T> { pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
alt *ls { match *ls {
cons(_, tl) => return tl, cons(_, tl) => return tl,
nil => fail ~"list empty" nil => fail ~"list empty"
} }
@ -91,12 +91,12 @@ pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
/// Returns the first element of a list /// Returns the first element of a list
pure fn head<T: copy>(ls: @list<T>) -> T { pure fn head<T: copy>(ls: @list<T>) -> T {
alt check *ls { cons(hd, _) => hd } match check *ls { cons(hd, _) => hd }
} }
/// Appends one list to another /// Appends one list to another
pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> { pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
alt *l { match *l {
nil => return m, nil => return m,
cons(x, xs) => { cons(x, xs) => {
let rest = append(xs, m); let rest = append(xs, m);
@ -114,7 +114,7 @@ fn push<T: copy>(&l: list<T>, v: T) {
fn iter<T>(l: @list<T>, f: fn(T)) { fn iter<T>(l: @list<T>, f: fn(T)) {
let mut cur = l; let mut cur = l;
loop { loop {
cur = alt *cur { cur = match *cur {
cons(hd, tl) => { cons(hd, tl) => {
f(hd); f(hd);
tl tl
@ -128,7 +128,7 @@ fn iter<T>(l: @list<T>, f: fn(T)) {
fn each<T>(l: @list<T>, f: fn(T) -> bool) { fn each<T>(l: @list<T>, f: fn(T) -> bool) {
let mut cur = l; let mut cur = l;
loop { loop {
cur = alt *cur { cur = match *cur {
cons(hd, tl) => { cons(hd, tl) => {
if !f(hd) { return; } if !f(hd) { return; }
tl tl

View file

@ -133,7 +133,7 @@ mod chained {
let mut e0 = e_root; let mut e0 = e_root;
let mut comp = 1u; // for logging let mut comp = 1u; // for logging
loop { loop {
alt copy e0.next { match copy e0.next {
none => { none => {
debug!{"search_tbl: absent, comp %u, hash %u, idx %u", debug!{"search_tbl: absent, comp %u, hash %u, idx %u",
comp, h, idx}; comp, h, idx};
@ -156,7 +156,7 @@ mod chained {
fn search_tbl(k: &K, h: uint) -> search_result<K,V> { fn search_tbl(k: &K, h: uint) -> search_result<K,V> {
let idx = h % vec::len(self.chains); let idx = h % vec::len(self.chains);
alt copy self.chains[idx] { match copy self.chains[idx] {
none => { none => {
debug!{"search_tbl: none, comp %u, hash %u, idx %u", debug!{"search_tbl: none, comp %u, hash %u, idx %u",
0u, h, idx}; 0u, h, idx};
@ -193,7 +193,7 @@ mod chained {
while i < n { while i < n {
let mut chain = self.chains[i]; let mut chain = self.chains[i];
loop { loop {
chain = alt chain { chain = match chain {
none => break, none => break,
some(entry) => { some(entry) => {
let next = entry.next; let next = entry.next;
@ -216,7 +216,7 @@ mod chained {
fn contains_key_ref(k: &K) -> bool { fn contains_key_ref(k: &K) -> bool {
let hash = self.hasher(k); let hash = self.hasher(k);
alt self.search_tbl(k, hash) { match self.search_tbl(k, hash) {
not_found => false, not_found => false,
found_first(*) | found_after(*) => true found_first(*) | found_after(*) => true
} }
@ -224,7 +224,7 @@ mod chained {
fn insert(+k: K, +v: V) -> bool { fn insert(+k: K, +v: V) -> bool {
let hash = self.hasher(&k); let hash = self.hasher(&k);
alt self.search_tbl(&k, hash) { match self.search_tbl(&k, hash) {
not_found => { not_found => {
self.count += 1u; self.count += 1u;
let idx = hash % vec::len(self.chains); let idx = hash % vec::len(self.chains);
@ -265,7 +265,7 @@ mod chained {
} }
fn find(+k: K) -> option<V> { fn find(+k: K) -> option<V> {
alt self.search_tbl(&k, self.hasher(&k)) { match self.search_tbl(&k, self.hasher(&k)) {
not_found => none, not_found => none,
found_first(_, entry) => some(entry.value), found_first(_, entry) => some(entry.value),
found_after(_, entry) => some(entry.value) found_after(_, entry) => some(entry.value)
@ -281,7 +281,7 @@ mod chained {
} }
fn remove(+k: K) -> option<V> { fn remove(+k: K) -> option<V> {
alt self.search_tbl(&k, self.hasher(&k)) { match self.search_tbl(&k, self.hasher(&k)) {
not_found => none, not_found => none,
found_first(idx, entry) => { found_first(idx, entry) => {
self.count -= 1u; self.count -= 1u;
@ -638,7 +638,7 @@ mod tests {
i = 0u; i = 0u;
while i < num_to_insert { while i < num_to_insert {
let v = hm.remove(i); let v = hm.remove(i);
alt v { match v {
option::some(u) => assert (u == i * i), option::some(u) => assert (u == i * i),
option::none => fail option::none => fail
} }

View file

@ -47,7 +47,7 @@ type parse_addr_err = {
* * ip - a `std::net::ip::ip_addr` * * ip - a `std::net::ip::ip_addr`
*/ */
fn format_addr(ip: ip_addr) -> ~str { fn format_addr(ip: ip_addr) -> ~str {
alt ip { match ip {
ipv4(addr) => unsafe { ipv4(addr) => unsafe {
let result = uv_ip4_name(&addr); let result = uv_ip4_name(&addr);
if result == ~"" { if result == ~"" {
@ -103,7 +103,7 @@ fn get_addr(++node: ~str, iotask: iotask)
node_ptr, node_ptr,
ptr::null(), ptr::null(),
ptr::null()); ptr::null());
alt result { match result {
0i32 => { 0i32 => {
set_data_for_req(handle_ptr, handle_data_ptr); set_data_for_req(handle_ptr, handle_data_ptr);
} }
@ -134,7 +134,7 @@ mod v4 {
* * an `ip_addr` of the `ipv4` variant * * an `ip_addr` of the `ipv4` variant
*/ */
fn parse_addr(ip: ~str) -> ip_addr { fn parse_addr(ip: ~str) -> ip_addr {
alt try_parse_addr(ip) { match try_parse_addr(ip) {
result::ok(addr) => copy(addr), result::ok(addr) => copy(addr),
result::err(err_data) => fail err_data.err_msg result::err(err_data) => fail err_data.err_msg
} }
@ -155,7 +155,7 @@ mod v4 {
} }
fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> { fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> {
let parts = vec::map(str::split_char(ip, '.'), |s| { let parts = vec::map(str::split_char(ip, '.'), |s| {
alt uint::from_str(s) { match uint::from_str(s) {
some(n) if n <= 255u => n, some(n) if n <= 255u => n,
_ => 256u _ => 256u
} }
@ -220,7 +220,7 @@ mod v6 {
* * an `ip_addr` of the `ipv6` variant * * an `ip_addr` of the `ipv6` variant
*/ */
fn parse_addr(ip: ~str) -> ip_addr { fn parse_addr(ip: ~str) -> ip_addr {
alt try_parse_addr(ip) { match try_parse_addr(ip) {
result::ok(addr) => copy(addr), result::ok(addr) => copy(addr),
result::err(err_data) => fail err_data.err_msg result::err(err_data) => fail err_data.err_msg
} }
@ -326,7 +326,7 @@ mod test {
} }
#[test] #[test]
fn test_ip_ipv4_bad_parse() { fn test_ip_ipv4_bad_parse() {
alt v4::try_parse_addr(~"b4df00d") { match v4::try_parse_addr(~"b4df00d") {
result::err(err_info) => { result::err(err_info) => {
log(debug, fmt!{"got error as expected %?", err_info}); log(debug, fmt!{"got error as expected %?", err_info});
assert true; assert true;
@ -339,7 +339,7 @@ mod test {
#[test] #[test]
#[ignore(target_os="win32")] #[ignore(target_os="win32")]
fn test_ip_ipv6_bad_parse() { fn test_ip_ipv6_bad_parse() {
alt v6::try_parse_addr(~"::,~2234k;") { match v6::try_parse_addr(~"::,~2234k;") {
result::err(err_info) => { result::err(err_info) => {
log(debug, fmt!{"got error as expected %?", err_info}); log(debug, fmt!{"got error as expected %?", err_info});
assert true; assert true;
@ -364,7 +364,7 @@ mod test {
log(debug, fmt!{"test_get_addr: Number of results for %s: %?", log(debug, fmt!{"test_get_addr: Number of results for %s: %?",
localhost_name, vec::len(results)}); localhost_name, vec::len(results)});
for vec::each(results) |r| { for vec::each(results) |r| {
let ipv_prefix = alt r { let ipv_prefix = match r {
ipv4(_) => ~"IPv4", ipv4(_) => ~"IPv4",
ipv6(_) => ~"IPv6" ipv6(_) => ~"IPv6"
}; };

View file

@ -151,16 +151,16 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
log(debug, ~"in interact cb for tcp client connect.."); log(debug, ~"in interact cb for tcp client connect..");
log(debug, fmt!{"stream_handle_ptr in interact %?", log(debug, fmt!{"stream_handle_ptr in interact %?",
stream_handle_ptr}); stream_handle_ptr});
alt uv::ll::tcp_init( loop_ptr, stream_handle_ptr) { match uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
0i32 => { 0i32 => {
log(debug, ~"tcp_init successful"); log(debug, ~"tcp_init successful");
alt input_ip { match input_ip {
ipv4 => { ipv4 => {
log(debug, ~"dealing w/ ipv4 connection.."); log(debug, ~"dealing w/ ipv4 connection..");
let connect_req_ptr = let connect_req_ptr =
ptr::addr_of((*socket_data_ptr).connect_req); ptr::addr_of((*socket_data_ptr).connect_req);
let addr_str = ip::format_addr(input_ip); let addr_str = ip::format_addr(input_ip);
let connect_result = alt input_ip { let connect_result = match input_ip {
ip::ipv4(addr) => { ip::ipv4(addr) => {
// have to "recreate" the sockaddr_in/6 // have to "recreate" the sockaddr_in/6
// since the ip_addr discards the port // since the ip_addr discards the port
@ -185,7 +185,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
tcp_connect_on_connect_cb) tcp_connect_on_connect_cb)
} }
}; };
alt connect_result { match connect_result {
0i32 => { 0i32 => {
log(debug, ~"tcp_connect successful"); log(debug, ~"tcp_connect successful");
// reusable data that we'll have for the // reusable data that we'll have for the
@ -223,7 +223,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
} }
} }
}; };
alt comm::recv(result_po) { match comm::recv(result_po) {
conn_success => { conn_success => {
log(debug, ~"tcp::connect - received success on result_po"); log(debug, ~"tcp::connect - received success on result_po");
result::ok(tcp_socket(socket_data)) result::ok(tcp_socket(socket_data))
@ -234,7 +234,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
// still have to free the malloc'd stream handle.. // still have to free the malloc'd stream handle..
rustrt::rust_uv_current_kernel_free(stream_handle_ptr rustrt::rust_uv_current_kernel_free(stream_handle_ptr
as *libc::c_void); as *libc::c_void);
let tcp_conn_err = alt err_data.err_name { let tcp_conn_err = match err_data.err_name {
~"ECONNREFUSED" => connection_refused, ~"ECONNREFUSED" => connection_refused,
_ => generic_connect_err(err_data.err_name, err_data.err_msg) _ => generic_connect_err(err_data.err_name, err_data.err_msg)
}; };
@ -445,7 +445,7 @@ fn read_future(sock: tcp_socket, timeout_msecs: uint)
* // do work here * // do work here
* } * }
* }; * };
* alt comm::recv(cont_po) { * match comm::recv(cont_po) {
* // shut down listen() * // shut down listen()
* some(err_data) { comm::send(kill_chan, some(err_data)) } * some(err_data) { comm::send(kill_chan, some(err_data)) }
* // wait for next connection * // wait for next connection
@ -469,7 +469,7 @@ fn read_future(sock: tcp_socket, timeout_msecs: uint)
fn accept(new_conn: tcp_new_connection) fn accept(new_conn: tcp_new_connection)
-> result::result<tcp_socket, tcp_err_data> unsafe { -> result::result<tcp_socket, tcp_err_data> unsafe {
alt new_conn{ match new_conn{
new_tcp_conn(server_handle_ptr) => { new_tcp_conn(server_handle_ptr) => {
let server_data_ptr = uv::ll::get_data_for_uv_handle( let server_data_ptr = uv::ll::get_data_for_uv_handle(
server_handle_ptr) as *tcp_listen_fc_data; server_handle_ptr) as *tcp_listen_fc_data;
@ -501,10 +501,10 @@ fn accept(new_conn: tcp_new_connection)
log(debug, ~"in interact cb for tcp::accept"); log(debug, ~"in interact cb for tcp::accept");
let loop_ptr = uv::ll::get_loop_for_uv_handle( let loop_ptr = uv::ll::get_loop_for_uv_handle(
server_handle_ptr); server_handle_ptr);
alt uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) { match uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) {
0i32 => { 0i32 => {
log(debug, ~"uv_tcp_init successful for client stream"); log(debug, ~"uv_tcp_init successful for client stream");
alt uv::ll::accept( match uv::ll::accept(
server_handle_ptr as *libc::c_void, server_handle_ptr as *libc::c_void,
client_stream_handle_ptr as *libc::c_void) { client_stream_handle_ptr as *libc::c_void) {
0i32 => { 0i32 => {
@ -528,7 +528,7 @@ fn accept(new_conn: tcp_new_connection)
} }
} }
// UNSAFE LIBUV INTERACTION END // UNSAFE LIBUV INTERACTION END
alt comm::recv(result_po) { match comm::recv(result_po) {
some(err_data) => result::err(err_data), some(err_data) => result::err(err_data),
none => result::ok(tcp_socket(client_socket_data)) none => result::ok(tcp_socket(client_socket_data))
} }
@ -610,13 +610,13 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
// nested within a comm::listen block) // nested within a comm::listen block)
let loc_ip = copy(host_ip); let loc_ip = copy(host_ip);
do iotask::interact(iotask) |loop_ptr| { do iotask::interact(iotask) |loop_ptr| {
alt uv::ll::tcp_init(loop_ptr, server_stream_ptr) { match uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
0i32 => { 0i32 => {
uv::ll::set_data_for_uv_handle( uv::ll::set_data_for_uv_handle(
server_stream_ptr, server_stream_ptr,
server_data_ptr); server_data_ptr);
let addr_str = ip::format_addr(loc_ip); let addr_str = ip::format_addr(loc_ip);
let bind_result = alt loc_ip { let bind_result = match loc_ip {
ip::ipv4(addr) => { ip::ipv4(addr) => {
log(debug, fmt!{"addr: %?", addr}); log(debug, fmt!{"addr: %?", addr});
let in_addr = uv::ll::ip4_addr(addr_str, port as int); let in_addr = uv::ll::ip4_addr(addr_str, port as int);
@ -630,9 +630,9 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
ptr::addr_of(in_addr)) ptr::addr_of(in_addr))
} }
}; };
alt bind_result { match bind_result {
0i32 => { 0i32 => {
alt uv::ll::listen(server_stream_ptr, match uv::ll::listen(server_stream_ptr,
backlog as libc::c_int, backlog as libc::c_int,
tcp_lfc_on_connection_cb) { tcp_lfc_on_connection_cb) {
0i32 => comm::send(setup_ch, none), 0i32 => comm::send(setup_ch, none),
@ -659,7 +659,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
}; };
setup_ch.recv() setup_ch.recv()
}; };
alt setup_result { match setup_result {
some(err_data) => { some(err_data) => {
do iotask::interact(iotask) |loop_ptr| { do iotask::interact(iotask) |loop_ptr| {
log(debug, fmt!{"tcp::listen post-kill recv hl interact %?", log(debug, fmt!{"tcp::listen post-kill recv hl interact %?",
@ -668,7 +668,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); uv::ll::close(server_stream_ptr, tcp_lfc_close_cb);
}; };
stream_closed_po.recv(); stream_closed_po.recv();
alt err_data.err_name { match err_data.err_name {
~"EACCES" => { ~"EACCES" => {
log(debug, ~"Got EACCES error"); log(debug, ~"Got EACCES error");
result::err(access_denied) result::err(access_denied)
@ -695,7 +695,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); uv::ll::close(server_stream_ptr, tcp_lfc_close_cb);
}; };
stream_closed_po.recv(); stream_closed_po.recv();
alt kill_result { match kill_result {
// some failure post bind/listen // some failure post bind/listen
some(err_data) => result::err(generic_listen_err(err_data.err_name, some(err_data) => result::err(generic_listen_err(err_data.err_name,
err_data.err_msg)), err_data.err_msg)),
@ -878,7 +878,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
some(comm::recv(result::get(rs_result))) some(comm::recv(result::get(rs_result)))
}; };
log(debug, ~"tcp::read after recv_timeout"); log(debug, ~"tcp::read after recv_timeout");
alt read_result { match read_result {
none => { none => {
log(debug, ~"tcp::read: timed out.."); log(debug, ~"tcp::read: timed out..");
let err_data = { let err_data = {
@ -905,7 +905,7 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
let stop_ch = comm::chan(stop_po); let stop_ch = comm::chan(stop_po);
do iotask::interact((*socket_data).iotask) |loop_ptr| { do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, ~"in interact cb for tcp::read_stop"); log(debug, ~"in interact cb for tcp::read_stop");
alt uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) { match uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
0i32 => { 0i32 => {
log(debug, ~"successfully called uv_read_stop"); log(debug, ~"successfully called uv_read_stop");
comm::send(stop_ch, none); comm::send(stop_ch, none);
@ -917,7 +917,7 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
} }
} }
}; };
alt comm::recv(stop_po) { match comm::recv(stop_po) {
some(err_data) => result::err(err_data.to_tcp_err()), some(err_data) => result::err(err_data.to_tcp_err()),
none => result::ok(()) none => result::ok(())
} }
@ -933,7 +933,7 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
log(debug, ~"in tcp::read_start before interact loop"); log(debug, ~"in tcp::read_start before interact loop");
do iotask::interact((*socket_data).iotask) |loop_ptr| { do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, fmt!{"in tcp::read_start interact cb %?", loop_ptr}); log(debug, fmt!{"in tcp::read_start interact cb %?", loop_ptr});
alt uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t, match uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t,
on_alloc_cb, on_alloc_cb,
on_tcp_read_cb) { on_tcp_read_cb) {
0i32 => { 0i32 => {
@ -947,7 +947,7 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
} }
} }
}; };
alt comm::recv(start_po) { match comm::recv(start_po) {
some(err_data) => result::err(err_data.to_tcp_err()), some(err_data) => result::err(err_data.to_tcp_err()),
none => result::ok((*socket_data).reader_po) none => result::ok((*socket_data).reader_po)
} }
@ -973,7 +973,7 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data,
let write_data_ptr = ptr::addr_of(write_data); let write_data_ptr = ptr::addr_of(write_data);
do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| { do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| {
log(debug, fmt!{"in interact cb for tcp::write %?", loop_ptr}); log(debug, fmt!{"in interact cb for tcp::write %?", loop_ptr});
alt uv::ll::write(write_req_ptr, match uv::ll::write(write_req_ptr,
stream_handle_ptr, stream_handle_ptr,
write_buf_vec_ptr, write_buf_vec_ptr,
tcp_write_complete_cb) { tcp_write_complete_cb) {
@ -993,7 +993,7 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data,
// and waiting here for the write to complete, we should transfer // and waiting here for the write to complete, we should transfer
// ownership of everything to the I/O task and let it deal with the // ownership of everything to the I/O task and let it deal with the
// aftermath, so we don't have to sit here blocking. // aftermath, so we don't have to sit here blocking.
alt comm::recv(result_po) { match comm::recv(result_po) {
tcp_write_success => result::ok(()), tcp_write_success => result::ok(()),
tcp_write_error(err_data) => result::err(err_data.to_tcp_err()) tcp_write_error(err_data) => result::err(err_data.to_tcp_err())
} }
@ -1024,7 +1024,7 @@ extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t,
as *tcp_listen_fc_data; as *tcp_listen_fc_data;
let kill_ch = (*server_data_ptr).kill_ch; let kill_ch = (*server_data_ptr).kill_ch;
if (*server_data_ptr).active { if (*server_data_ptr).active {
alt status { match status {
0i32 => (*server_data_ptr).on_connect_cb(handle), 0i32 => (*server_data_ptr).on_connect_cb(handle),
_ => { _ => {
let loop_ptr = uv::ll::get_loop_for_uv_handle(handle); let loop_ptr = uv::ll::get_loop_for_uv_handle(handle);
@ -1081,7 +1081,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
let loop_ptr = uv::ll::get_loop_for_uv_handle(stream); let loop_ptr = uv::ll::get_loop_for_uv_handle(stream);
let socket_data_ptr = uv::ll::get_data_for_uv_handle(stream) let socket_data_ptr = uv::ll::get_data_for_uv_handle(stream)
as *tcp_socket_data; as *tcp_socket_data;
alt nread as int { match nread as int {
// incoming err.. probably eof // incoming err.. probably eof
-1 => { -1 => {
let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err(); let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err();
@ -1175,7 +1175,7 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t,
log(debug, fmt!{"tcp_connect result_ch %?", result_ch}); log(debug, fmt!{"tcp_connect result_ch %?", result_ch});
let tcp_stream_ptr = let tcp_stream_ptr =
uv::ll::get_stream_handle_from_connect_req(connect_req_ptr); uv::ll::get_stream_handle_from_connect_req(connect_req_ptr);
alt status { match status {
0i32 => { 0i32 => {
log(debug, ~"successful tcp connection!"); log(debug, ~"successful tcp connection!");
comm::send(result_ch, conn_success); comm::send(result_ch, conn_success);
@ -1336,7 +1336,7 @@ mod test {
client_ch, client_ch,
hl_loop) hl_loop)
}; };
alt actual_resp_result.get_err() { match actual_resp_result.get_err() {
connection_refused => (), connection_refused => (),
_ => fail ~"unknown error.. expected connection_refused" _ => fail ~"unknown error.. expected connection_refused"
} }
@ -1382,7 +1382,7 @@ mod test {
client_ch, client_ch,
hl_loop) hl_loop)
}; };
alt listen_err { match listen_err {
address_in_use => { address_in_use => {
assert true; assert true;
} }
@ -1401,7 +1401,7 @@ mod test {
server_ip, server_ip,
server_port, server_port,
hl_loop); hl_loop);
alt listen_err { match listen_err {
access_denied => { access_denied => {
assert true; assert true;
} }
@ -1515,7 +1515,7 @@ mod test {
log(debug, ~"SERVER: successfully accepted"+ log(debug, ~"SERVER: successfully accepted"+
~"connection!"); ~"connection!");
let received_req_bytes = read(sock, 0u); let received_req_bytes = read(sock, 0u);
alt received_req_bytes { match received_req_bytes {
result::ok(data) => { result::ok(data) => {
log(debug, ~"SERVER: got REQ str::from_bytes.."); log(debug, ~"SERVER: got REQ str::from_bytes..");
log(debug, fmt!{"SERVER: REQ data len: %?", log(debug, fmt!{"SERVER: REQ data len: %?",
@ -1544,7 +1544,7 @@ mod test {
}); });
// err check on listen_result // err check on listen_result
if result::is_err(listen_result) { if result::is_err(listen_result) {
alt result::get_err(listen_result) { match result::get_err(listen_result) {
generic_listen_err(name, msg) => { generic_listen_err(name, msg) => {
fail fmt!{"SERVER: exited abnormally name %s msg %s", fail fmt!{"SERVER: exited abnormally name %s msg %s",
name, msg}; name, msg};

View file

@ -133,10 +133,10 @@ fn prepend_str(rope: rope, str: @~str) -> rope {
/// Concatenate two ropes /// Concatenate two ropes
fn append_rope(left: rope, right: rope) -> rope { fn append_rope(left: rope, right: rope) -> rope {
alt(left) { match (left) {
node::empty => return right, node::empty => return right,
node::content(left_content) => { node::content(left_content) => {
alt(right) { match (right) {
node::empty => return left, node::empty => return left,
node::content(right_content) => { node::content(right_content) => {
return node::content(node::concat2(left_content, right_content)); return node::content(node::concat2(left_content, right_content));
@ -197,9 +197,9 @@ Section: Keeping ropes healthy
* to rebalance your rope at some point, before using it for other purposes. * to rebalance your rope at some point, before using it for other purposes.
*/ */
fn bal(rope:rope) -> rope { fn bal(rope:rope) -> rope {
alt(rope) { match (rope) {
node::empty => return rope, node::empty => return rope,
node::content(x) => alt(node::bal(x)) { node::content(x) => match (node::bal(x)) {
option::none => rope, option::none => rope,
option::some(y) => node::content(y) option::some(y) => node::content(y)
} }
@ -226,7 +226,7 @@ Section: Transforming ropes
*/ */
fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope { fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope {
if char_len == 0u { return node::empty; } if char_len == 0u { return node::empty; }
alt(rope) { match (rope) {
node::empty => fail, node::empty => fail,
node::content(node) => if char_len > node::char_len(node) { node::content(node) => if char_len > node::char_len(node) {
fail fail
@ -251,7 +251,7 @@ fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope {
*/ */
fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope { fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope {
if byte_len == 0u { return node::empty; } if byte_len == 0u { return node::empty; }
alt(rope) { match (rope) {
node::empty => fail, node::empty => fail,
node::content(node) =>if byte_len > node::byte_len(node) { node::content(node) =>if byte_len > node::byte_len(node) {
fail fail
@ -276,7 +276,7 @@ Section: Comparing ropes
* value if `left > right` * value if `left > right`
*/ */
fn cmp(left: rope, right: rope) -> int { fn cmp(left: rope, right: rope) -> int {
alt((left, right)) { match ((left, right)) {
(node::empty, node::empty) => return 0, (node::empty, node::empty) => return 0,
(node::empty, _) => return -1, (node::empty, _) => return -1,
(_, node::empty) => return 1, (_, node::empty) => return 1,
@ -379,7 +379,7 @@ Section: Iterating
* that is if `it` returned `false` at any point. * that is if `it` returned `false` at any point.
*/ */
fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool { fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool {
alt(rope) { match (rope) {
node::empty => return true, node::empty => return true,
node::content(x) => return node::loop_chars(x, it) node::content(x) => return node::loop_chars(x, it)
} }
@ -422,7 +422,7 @@ fn iter_chars(rope: rope, it: fn(char)) {
* that is if `it` returned `false` at any point. * that is if `it` returned `false` at any point.
*/ */
fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{ fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{
alt(rope) { match (rope) {
node::empty => return true, node::empty => return true,
node::content(x) => return node::loop_leaves(x, it) node::content(x) => return node::loop_leaves(x, it)
} }
@ -431,7 +431,7 @@ fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{
mod iterator { mod iterator {
mod leaf { mod leaf {
fn start(rope: rope) -> node::leaf_iterator::t { fn start(rope: rope) -> node::leaf_iterator::t {
alt(rope) { match (rope) {
node::empty => return node::leaf_iterator::empty(), node::empty => return node::leaf_iterator::empty(),
node::content(x) => return node::leaf_iterator::start(x) node::content(x) => return node::leaf_iterator::start(x)
} }
@ -442,7 +442,7 @@ mod iterator {
} }
mod char { mod char {
fn start(rope: rope) -> node::char_iterator::t { fn start(rope: rope) -> node::char_iterator::t {
alt(rope) { match (rope) {
node::empty => return node::char_iterator::empty(), node::empty => return node::char_iterator::empty(),
node::content(x) => return node::char_iterator::start(x) node::content(x) => return node::char_iterator::start(x)
} }
@ -469,7 +469,7 @@ mod iterator {
* Constant time. * Constant time.
*/ */
fn height(rope: rope) -> uint { fn height(rope: rope) -> uint {
alt(rope) { match (rope) {
node::empty => return 0u, node::empty => return 0u,
node::content(x) => return node::height(x) node::content(x) => return node::height(x)
} }
@ -485,7 +485,7 @@ fn height(rope: rope) -> uint {
* Constant time. * Constant time.
*/ */
pure fn char_len(rope: rope) -> uint { pure fn char_len(rope: rope) -> uint {
alt(rope) { match (rope) {
node::empty => return 0u, node::empty => return 0u,
node::content(x) => return node::char_len(x) node::content(x) => return node::char_len(x)
} }
@ -499,7 +499,7 @@ pure fn char_len(rope: rope) -> uint {
* Constant time. * Constant time.
*/ */
pure fn byte_len(rope: rope) -> uint { pure fn byte_len(rope: rope) -> uint {
alt(rope) { match (rope) {
node::empty => return 0u, node::empty => return 0u,
node::content(x) => return node::byte_len(x) node::content(x) => return node::byte_len(x)
} }
@ -522,7 +522,7 @@ pure fn byte_len(rope: rope) -> uint {
* rope + the (bounded) length of the largest leaf. * rope + the (bounded) length of the largest leaf.
*/ */
fn char_at(rope: rope, pos: uint) -> char { fn char_at(rope: rope, pos: uint) -> char {
alt(rope) { match (rope) {
node::empty => fail, node::empty => fail,
node::content(x) => return node::char_at(x, pos) node::content(x) => return node::char_at(x, pos)
} }
@ -730,14 +730,14 @@ mod node {
pure fn byte_len(node: @node) -> uint { pure fn byte_len(node: @node) -> uint {
//FIXME (#2744): Could we do this without the pattern-matching? //FIXME (#2744): Could we do this without the pattern-matching?
alt(*node) { match (*node) {
leaf(y) => return y.byte_len, leaf(y) => return y.byte_len,
concat(y) => return y.byte_len concat(y) => return y.byte_len
} }
} }
pure fn char_len(node: @node) -> uint { pure fn char_len(node: @node) -> uint {
alt(*node) { match (*node) {
leaf(y) => return y.char_len, leaf(y) => return y.char_len,
concat(y) => return y.char_len concat(y) => return y.char_len
} }
@ -800,7 +800,7 @@ mod node {
let mut offset = 0u;//Current position in the buffer let mut offset = 0u;//Current position in the buffer
let it = leaf_iterator::start(node); let it = leaf_iterator::start(node);
loop { loop {
alt(leaf_iterator::next(it)) { match (leaf_iterator::next(it)) {
option::none => break, option::none => break,
option::some(x) => { option::some(x) => {
//FIXME (#2744): Replace with memcpy or something similar //FIXME (#2744): Replace with memcpy or something similar
@ -827,7 +827,7 @@ mod node {
* This function executes in linear time. * This function executes in linear time.
*/ */
fn flatten(node: @node) -> @node unsafe { fn flatten(node: @node) -> @node unsafe {
alt(*node) { match (*node) {
leaf(_) => return node, leaf(_) => return node,
concat(x) => { concat(x) => {
return @leaf({ return @leaf({
@ -861,7 +861,7 @@ mod node {
let mut forest = ~[mut]; let mut forest = ~[mut];
let it = leaf_iterator::start(node); let it = leaf_iterator::start(node);
loop { loop {
alt (leaf_iterator::next(it)) { match (leaf_iterator::next(it)) {
option::none => break, option::none => break,
option::some(x) => vec::push(forest, @leaf(x)) option::some(x) => vec::push(forest, @leaf(x))
} }
@ -898,7 +898,7 @@ mod node {
if byte_offset == 0u && byte_len == node::byte_len(node) { if byte_offset == 0u && byte_len == node::byte_len(node) {
return node; return node;
} }
alt(*node) { match (*node) {
node::leaf(x) => { node::leaf(x) => {
let char_len = let char_len =
str::count_chars(*x.content, byte_offset, byte_len); str::count_chars(*x.content, byte_offset, byte_len);
@ -956,7 +956,7 @@ mod node {
let mut node = node; let mut node = node;
let mut char_offset = char_offset; let mut char_offset = char_offset;
loop { loop {
alt(*node) { match (*node) {
node::leaf(x) => { node::leaf(x) => {
if char_offset == 0u && char_len == x.char_len { if char_offset == 0u && char_len == x.char_len {
return node; return node;
@ -1007,7 +1007,7 @@ mod node {
} }
fn height(node: @node) -> uint { fn height(node: @node) -> uint {
alt(*node) { match (*node) {
leaf(_) => return 0u, leaf(_) => return 0u,
concat(x) => return x.height concat(x) => return x.height
} }
@ -1018,7 +1018,7 @@ mod node {
let itb = char_iterator::start(b); let itb = char_iterator::start(b);
let mut result = 0; let mut result = 0;
while result == 0 { while result == 0 {
alt((char_iterator::next(ita), char_iterator::next(itb))) { match ((char_iterator::next(ita), char_iterator::next(itb))) {
(option::none, option::none) => break, (option::none, option::none) => break,
(option::some(chara), option::some(charb)) => { (option::some(chara), option::some(charb)) => {
result = char::cmp(chara, charb); result = char::cmp(chara, charb);
@ -1059,7 +1059,7 @@ mod node {
fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{ fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{
let mut current = node; let mut current = node;
loop { loop {
alt(*current) { match (*current) {
leaf(x) => return it(x), leaf(x) => return it(x),
concat(x) => if loop_leaves(x.left, it) { //non tail call concat(x) => if loop_leaves(x.left, it) { //non tail call
current = x.right; //tail call current = x.right; //tail call
@ -1091,7 +1091,7 @@ mod node {
let mut node = node; let mut node = node;
let mut pos = pos; let mut pos = pos;
loop { loop {
alt *node { match *node {
leaf(x) => return str::char_at(*x.content, pos), leaf(x) => return str::char_at(*x.content, pos),
concat({left, right, _}) => { concat({left, right, _}) => {
let left_len = char_len(left); let left_len = char_len(left);
@ -1126,7 +1126,7 @@ mod node {
loop { loop {
let current = it.stack[it.stackpos]; let current = it.stack[it.stackpos];
it.stackpos -= 1; it.stackpos -= 1;
alt(*current) { match (*current) {
concat(x) => { concat(x) => {
it.stackpos += 1; it.stackpos += 1;
it.stack[it.stackpos] = x.right; it.stack[it.stackpos] = x.right;
@ -1164,11 +1164,11 @@ mod node {
fn next(it: t) -> option<char> { fn next(it: t) -> option<char> {
loop { loop {
alt(get_current_or_next_leaf(it)) { match (get_current_or_next_leaf(it)) {
option::none => return option::none, option::none => return option::none,
option::some(_) => { option::some(_) => {
let next_char = get_next_char_in_leaf(it); let next_char = get_next_char_in_leaf(it);
alt(next_char) { match (next_char) {
option::none => again, option::none => again,
option::some(_) => return next_char option::some(_) => return next_char
} }
@ -1178,11 +1178,11 @@ mod node {
} }
fn get_current_or_next_leaf(it: t) -> option<leaf> { fn get_current_or_next_leaf(it: t) -> option<leaf> {
alt(it.leaf) { match (it.leaf) {
option::some(_) => return it.leaf, option::some(_) => return it.leaf,
option::none => { option::none => {
let next = leaf_iterator::next(it.leaf_iterator); let next = leaf_iterator::next(it.leaf_iterator);
alt(next) { match (next) {
option::none => return option::none, option::none => return option::none,
option::some(_) => { option::some(_) => {
it.leaf = next; it.leaf = next;
@ -1195,7 +1195,7 @@ mod node {
} }
fn get_next_char_in_leaf(it: t) -> option<char> { fn get_next_char_in_leaf(it: t) -> option<char> {
alt copy it.leaf { match copy it.leaf {
option::none => return option::none, option::none => return option::none,
option::some(aleaf) => { option::some(aleaf) => {
if it.leaf_byte_pos >= aleaf.byte_len { if it.leaf_byte_pos >= aleaf.byte_len {
@ -1220,12 +1220,12 @@ mod tests {
//Utility function, used for sanity check //Utility function, used for sanity check
fn rope_to_string(r: rope) -> ~str { fn rope_to_string(r: rope) -> ~str {
alt(r) { match (r) {
node::empty => return ~"", node::empty => return ~"",
node::content(x) => { node::content(x) => {
let str = @mut ~""; let str = @mut ~"";
fn aux(str: @mut ~str, node: @node::node) unsafe { fn aux(str: @mut ~str, node: @node::node) unsafe {
alt(*node) { match (*node) {
node::leaf(x) => { node::leaf(x) => {
*str += str::slice( *str += str::slice(
*x.content, x.byte_offset, *x.content, x.byte_offset,
@ -1274,7 +1274,7 @@ mod tests {
let rope_iter = iterator::char::start(r); let rope_iter = iterator::char::start(r);
let mut equal = true; let mut equal = true;
while equal { while equal {
alt(node::char_iterator::next(rope_iter)) { match (node::char_iterator::next(rope_iter)) {
option::none => { option::none => {
if string_iter < string_len { if string_iter < string_len {
equal = false; equal = false;
@ -1301,7 +1301,7 @@ mod tests {
let mut len = 0u; let mut len = 0u;
let it = iterator::char::start(r); let it = iterator::char::start(r);
loop { loop {
alt(node::char_iterator::next(it)) { match (node::char_iterator::next(it)) {
option::none => break, option::none => break,
option::some(_) => len += 1u option::some(_) => len += 1u
} }

View file

@ -243,7 +243,7 @@ fn deserialize_bool<D: deserializer>(d: D) -> bool {
fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) { fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
do s.emit_enum(~"option") { do s.emit_enum(~"option") {
alt v { match v {
none => do s.emit_enum_variant(~"none", 0u, 0u) { none => do s.emit_enum_variant(~"none", 0u, 0u) {
} }
@ -260,7 +260,7 @@ fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T)
-> option<T> { -> option<T> {
do d.read_enum(~"option") { do d.read_enum(~"option") {
do d.read_enum_variant |i| { do d.read_enum_variant |i| {
alt check i { match check i {
0u => none, 0u => none,
1u => some(d.read_enum_variant_arg(0u, || st() )) 1u => some(d.read_enum_variant_arg(0u, || st() ))
} }

View file

@ -48,7 +48,7 @@ pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
* If the key does not exist in the map * If the key does not exist in the map
*/ */
pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T { pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
alt find(self, key) { match find(self, key) {
none => { none => {
error!{"smallintmap::get(): key not present"}; error!{"smallintmap::get(): key not present"};
fail; fail;
@ -67,7 +67,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn size() -> uint { fn size() -> uint {
let mut sz = 0u; let mut sz = 0u;
for self.v.each |item| { for self.v.each |item| {
alt item { match item {
some(_) => sz += 1u, some(_) => sz += 1u,
_ => () _ => ()
} }
@ -103,7 +103,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn each(it: fn(+key: uint, +value: V) -> bool) { fn each(it: fn(+key: uint, +value: V) -> bool) {
let mut idx = 0u, l = self.v.len(); let mut idx = 0u, l = self.v.len();
while idx < l { while idx < l {
alt self.v.get_elt(idx) { match self.v.get_elt(idx) {
some(elt) => if !it(idx, elt) { break } some(elt) => if !it(idx, elt) { break }
none => () none => ()
} }
@ -119,7 +119,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn each_ref(it: fn(key: &uint, value: &V) -> bool) { fn each_ref(it: fn(key: &uint, value: &V) -> bool) {
let mut idx = 0u, l = self.v.len(); let mut idx = 0u, l = self.v.len();
while idx < l { while idx < l {
alt self.v.get_elt(idx) { match self.v.get_elt(idx) {
some(elt) => if !it(&idx, &elt) { break } some(elt) => if !it(&idx, &elt) { break }
none => () none => ()
} }

View file

@ -21,7 +21,7 @@ fn mkdtemp(prefix: ~str, suffix: ~str) -> option<~str> {
#[test] #[test]
fn test_mkdtemp() { fn test_mkdtemp() {
let r = mkdtemp(~"./", ~"foobar"); let r = mkdtemp(~"./", ~"foobar");
alt r { match r {
some(p) => { some(p) => {
os::remove_dir(p); os::remove_dir(p);
assert(str::ends_with(p, ~"foobar")); assert(str::ends_with(p, ~"foobar"));

View file

@ -35,7 +35,7 @@ fn reset(writer: io::writer) {
fn color_supported() -> bool { fn color_supported() -> bool {
let supported_terms = ~[~"xterm-color", ~"xterm", let supported_terms = ~[~"xterm-color", ~"xterm",
~"screen-bce", ~"xterm-256color"]; ~"screen-bce", ~"xterm-256color"];
return alt os::getenv(~"TERM") { return match os::getenv(~"TERM") {
option::some(env) => { option::some(env) => {
for vec::each(supported_terms) |term| { for vec::each(supported_terms) |term| {
if term == env { return true; } if term == env { return true; }

View file

@ -52,7 +52,7 @@ type test_desc = {
// arguments and a vector of test_descs (generated at compile time). // arguments and a vector of test_descs (generated at compile time).
fn test_main(args: ~[~str], tests: ~[test_desc]) { fn test_main(args: ~[~str], tests: ~[test_desc]) {
let opts = let opts =
alt parse_opts(args) { match parse_opts(args) {
either::left(o) => o, either::left(o) => o,
either::right(m) => fail m either::right(m) => fail m
}; };
@ -69,7 +69,7 @@ fn parse_opts(args: ~[~str]) -> opt_res {
let args_ = vec::tail(args); let args_ = vec::tail(args);
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")]; let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
let matches = let matches =
alt getopts::getopts(args_, opts) { match getopts::getopts(args_, opts) {
ok(m) => m, ok(m) => m,
err(f) => return either::right(getopts::fail_str(f)) err(f) => return either::right(getopts::fail_str(f))
}; };
@ -105,7 +105,7 @@ fn run_tests_console(opts: test_opts,
tests: ~[test_desc]) -> bool { tests: ~[test_desc]) -> bool {
fn callback(event: testevent, st: console_test_state) { fn callback(event: testevent, st: console_test_state) {
alt event { match event {
te_filtered(filtered_tests) => { te_filtered(filtered_tests) => {
st.total = vec::len(filtered_tests); st.total = vec::len(filtered_tests);
let noun = if st.total != 1u { ~"tests" } else { ~"test" }; let noun = if st.total != 1u { ~"tests" } else { ~"test" };
@ -113,11 +113,11 @@ fn run_tests_console(opts: test_opts,
} }
te_wait(test) => st.out.write_str(fmt!{"test %s ... ", test.name}), te_wait(test) => st.out.write_str(fmt!{"test %s ... ", test.name}),
te_result(test, result) => { te_result(test, result) => {
alt st.log_out { match st.log_out {
some(f) => write_log(f, result, test), some(f) => write_log(f, result, test),
none => () none => ()
} }
alt result { match result {
tr_ok => { tr_ok => {
st.passed += 1u; st.passed += 1u;
write_ok(st.out, st.use_color); write_ok(st.out, st.use_color);
@ -139,8 +139,9 @@ fn run_tests_console(opts: test_opts,
} }
} }
let log_out = alt opts.logfile { let log_out = match opts.logfile {
some(path) => alt io::file_writer(path, ~[io::create, io::truncate]) { some(path) => match io::file_writer(path,
~[io::create, io::truncate]) {
result::ok(w) => some(w), result::ok(w) => some(w),
result::err(s) => { result::err(s) => {
fail(fmt!{"can't open output file: %s", s}) fail(fmt!{"can't open output file: %s", s})
@ -180,7 +181,7 @@ fn run_tests_console(opts: test_opts,
fn write_log(out: io::writer, result: test_result, test: test_desc) { fn write_log(out: io::writer, result: test_result, test: test_desc) {
out.write_line(fmt!{"%s %s", out.write_line(fmt!{"%s %s",
alt result { match result {
tr_ok => ~"ok", tr_ok => ~"ok",
tr_failed => ~"failed", tr_failed => ~"failed",
tr_ignored => ~"ignored" tr_ignored => ~"ignored"
@ -334,7 +335,7 @@ fn filter_tests(opts: test_opts,
filtered filtered
} else { } else {
let filter_str = let filter_str =
alt opts.filter { match opts.filter {
option::some(f) => f, option::some(f) => f,
option::none => ~"" option::none => ~""
}; };
@ -479,7 +480,7 @@ mod tests {
#[test] #[test]
fn first_free_arg_should_be_a_filter() { fn first_free_arg_should_be_a_filter() {
let args = ~[~"progname", ~"filter"]; let args = ~[~"progname", ~"filter"];
let opts = alt parse_opts(args) { let opts = match parse_opts(args) {
either::left(o) => o, either::left(o) => o,
_ => fail ~"Malformed arg in first_free_arg_should_be_a_filter" _ => fail ~"Malformed arg in first_free_arg_should_be_a_filter"
}; };
@ -489,7 +490,7 @@ mod tests {
#[test] #[test]
fn parse_ignored_flag() { fn parse_ignored_flag() {
let args = ~[~"progname", ~"filter", ~"--ignored"]; let args = ~[~"progname", ~"filter", ~"--ignored"];
let opts = alt parse_opts(args) { let opts = match parse_opts(args) {
either::left(o) => o, either::left(o) => o,
_ => fail ~"Malformed arg in parse_ignored_flag" _ => fail ~"Malformed arg in parse_ignored_flag"
}; };

View file

@ -181,7 +181,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
let {ch, next} = str::char_range_at(s, pos); let {ch, next} = str::char_range_at(s, pos);
pos = next; pos = next;
alt ch { match ch {
'0' to '9' => { '0' to '9' => {
value = value * 10_i32 + (ch as i32 - '0' as i32); value = value * 10_i32 + (ch as i32 - '0' as i32);
} }
@ -208,8 +208,8 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut) fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut)
-> result<uint, ~str> { -> result<uint, ~str> {
alt ch { match ch {
'A' => alt match_strs(s, pos, ~[ 'A' => match match_strs(s, pos, ~[
(~"Sunday", 0_i32), (~"Sunday", 0_i32),
(~"Monday", 1_i32), (~"Monday", 1_i32),
(~"Tuesday", 2_i32), (~"Tuesday", 2_i32),
@ -221,7 +221,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
none => err(~"Invalid day") none => err(~"Invalid day")
} }
'a' => alt match_strs(s, pos, ~[ 'a' => match match_strs(s, pos, ~[
(~"Sun", 0_i32), (~"Sun", 0_i32),
(~"Mon", 1_i32), (~"Mon", 1_i32),
(~"Tue", 2_i32), (~"Tue", 2_i32),
@ -233,7 +233,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
none => err(~"Invalid day") none => err(~"Invalid day")
} }
'B' => alt match_strs(s, pos, ~[ 'B' => match match_strs(s, pos, ~[
(~"January", 0_i32), (~"January", 0_i32),
(~"February", 1_i32), (~"February", 1_i32),
(~"March", 2_i32), (~"March", 2_i32),
@ -250,7 +250,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
none => err(~"Invalid month") none => err(~"Invalid month")
} }
'b' | 'h' => alt match_strs(s, pos, ~[ 'b' | 'h' => match match_strs(s, pos, ~[
(~"Jan", 0_i32), (~"Jan", 0_i32),
(~"Feb", 1_i32), (~"Feb", 1_i32),
(~"Mar", 2_i32), (~"Mar", 2_i32),
@ -267,7 +267,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
none => err(~"Invalid month") none => err(~"Invalid month")
} }
'C' => alt match_digits(s, pos, 2u, false) { 'C' => match match_digits(s, pos, 2u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_year += (v * 100_i32) - 1900_i32; tm.tm_year += (v * 100_i32) - 1900_i32;
@ -293,11 +293,11 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
.chain(|pos| parse_char(s, pos, '/')) .chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'y', tm)) .chain(|pos| parse_type(s, pos, 'y', tm))
} }
'd' => alt match_digits(s, pos, 2u, false) { 'd' => match match_digits(s, pos, 2u, false) {
some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
none => err(~"Invalid day of the month") none => err(~"Invalid day of the month")
} }
'e' => alt match_digits(s, pos, 2u, true) { 'e' => match match_digits(s, pos, 2u, true) {
some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
none => err(~"Invalid day of the month") none => err(~"Invalid day of the month")
} }
@ -310,14 +310,14 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
'H' => { 'H' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) { match match_digits(s, pos, 2u, false) {
some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
none => err(~"Invalid hour") none => err(~"Invalid hour")
} }
} }
'I' => { 'I' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) { match match_digits(s, pos, 2u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
@ -328,7 +328,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
'j' => { 'j' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 3u, false) { match match_digits(s, pos, 3u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_yday = v - 1_i32; tm.tm_yday = v - 1_i32;
@ -339,14 +339,14 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
'k' => { 'k' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, true) { match match_digits(s, pos, 2u, true) {
some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
none => err(~"Invalid hour") none => err(~"Invalid hour")
} }
} }
'l' => { 'l' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, true) { match match_digits(s, pos, 2u, true) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
@ -357,14 +357,14 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
'M' => { 'M' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) { match match_digits(s, pos, 2u, false) {
some(item) => { let (v, pos) = item; tm.tm_min = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_min = v; ok(pos) }
none => err(~"Invalid minute") none => err(~"Invalid minute")
} }
} }
'm' => { 'm' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) { match match_digits(s, pos, 2u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_mon = v - 1_i32; tm.tm_mon = v - 1_i32;
@ -374,11 +374,15 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
} }
'n' => parse_char(s, pos, '\n'), 'n' => parse_char(s, pos, '\n'),
'P' => alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) { 'P' => match match_strs(s, pos,
~[(~"am", 0_i32), (~"pm", 12_i32)]) {
some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
none => err(~"Invalid hour") none => err(~"Invalid hour")
} }
'p' => alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) { 'p' => match match_strs(s, pos,
~[(~"AM", 0_i32), (~"PM", 12_i32)]) {
some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
none => err(~"Invalid hour") none => err(~"Invalid hour")
} }
@ -398,7 +402,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
'S' => { 'S' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) { match match_digits(s, pos, 2u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_sec = v; tm.tm_sec = v;
@ -418,7 +422,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
't' => parse_char(s, pos, '\t'), 't' => parse_char(s, pos, '\t'),
'u' => { 'u' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 1u, false) { match match_digits(s, pos, 1u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_wday = v; tm.tm_wday = v;
@ -437,7 +441,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
//'W' {} //'W' {}
'w' => { 'w' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 1u, false) { match match_digits(s, pos, 1u, false) {
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
none => err(~"Invalid weekday") none => err(~"Invalid weekday")
} }
@ -446,7 +450,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
//'x' {} //'x' {}
'Y' => { 'Y' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 4u, false) { match match_digits(s, pos, 4u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_year = v - 1900_i32; tm.tm_year = v - 1900_i32;
@ -457,7 +461,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
} }
'y' => { 'y' => {
// FIXME (#2350): range check. // FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) { match match_digits(s, pos, 2u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
tm.tm_year = v - 1900_i32; tm.tm_year = v - 1900_i32;
@ -489,7 +493,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
let {ch, next} = str::char_range_at(s, pos); let {ch, next} = str::char_range_at(s, pos);
if ch == '+' || ch == '-' { if ch == '+' || ch == '-' {
alt match_digits(s, next, 4u, false) { match match_digits(s, next, 4u, false) {
some(item) => { some(item) => {
let (v, pos) = item; let (v, pos) = item;
if v == 0_i32 { if v == 0_i32 {
@ -534,8 +538,8 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
while !rdr.eof() && pos < len { while !rdr.eof() && pos < len {
let {ch, next} = str::char_range_at(s, pos); let {ch, next} = str::char_range_at(s, pos);
alt rdr.read_char() { match rdr.read_char() {
'%' => alt parse_type(s, pos, rdr.read_char(), tm) { '%' => match parse_type(s, pos, rdr.read_char(), tm) {
ok(next) => pos = next, ok(next) => pos = next,
err(e) => { result = err(e); break; } err(e) => { result = err(e); break; }
} }
@ -568,8 +572,8 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
fn strftime(format: ~str, tm: tm) -> ~str { fn strftime(format: ~str, tm: tm) -> ~str {
fn parse_type(ch: char, tm: tm) -> ~str { fn parse_type(ch: char, tm: tm) -> ~str {
//FIXME (#2350): Implement missing types. //FIXME (#2350): Implement missing types.
alt check ch { match check ch {
'A' => alt check tm.tm_wday as int { 'A' => match check tm.tm_wday as int {
0 => ~"Sunday", 0 => ~"Sunday",
1 => ~"Monday", 1 => ~"Monday",
2 => ~"Tuesday", 2 => ~"Tuesday",
@ -578,7 +582,7 @@ fn strftime(format: ~str, tm: tm) -> ~str {
5 => ~"Friday", 5 => ~"Friday",
6 => ~"Saturday" 6 => ~"Saturday"
} }
'a' => alt check tm.tm_wday as int { 'a' => match check tm.tm_wday as int {
0 => ~"Sun", 0 => ~"Sun",
1 => ~"Mon", 1 => ~"Mon",
2 => ~"Tue", 2 => ~"Tue",
@ -587,7 +591,7 @@ fn strftime(format: ~str, tm: tm) -> ~str {
5 => ~"Fri", 5 => ~"Fri",
6 => ~"Sat" 6 => ~"Sat"
} }
'B' => alt check tm.tm_mon as int { 'B' => match check tm.tm_mon as int {
0 => ~"January", 0 => ~"January",
1 => ~"February", 1 => ~"February",
2 => ~"March", 2 => ~"March",
@ -601,7 +605,7 @@ fn strftime(format: ~str, tm: tm) -> ~str {
10 => ~"November", 10 => ~"November",
11 => ~"December" 11 => ~"December"
} }
'b' | 'h' => alt check tm.tm_mon as int { 'b' | 'h' => match check tm.tm_mon as int {
0 => ~"Jan", 0 => ~"Jan",
1 => ~"Feb", 1 => ~"Feb",
2 => ~"Mar", 2 => ~"Mar",
@ -716,7 +720,7 @@ fn strftime(format: ~str, tm: tm) -> ~str {
do io::with_str_reader(format) |rdr| { do io::with_str_reader(format) |rdr| {
while !rdr.eof() { while !rdr.eof() {
alt rdr.read_char() { match rdr.read_char() {
'%' => buf += parse_type(rdr.read_char(), tm), '%' => buf += parse_type(rdr.read_char(), tm),
ch => str::push_char(buf, ch) ch => str::push_char(buf, ch)
} }
@ -932,7 +936,7 @@ mod tests {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
alt strptime(~"", ~"") { match strptime(~"", ~"") {
ok(tm) => { ok(tm) => {
assert tm.tm_sec == 0_i32; assert tm.tm_sec == 0_i32;
assert tm.tm_min == 0_i32; assert tm.tm_min == 0_i32;
@ -954,7 +958,7 @@ mod tests {
assert strptime(~"Fri Feb 13 15:31:30", format) assert strptime(~"Fri Feb 13 15:31:30", format)
== err(~"Invalid time"); == err(~"Invalid time");
alt strptime(~"Fri Feb 13 15:31:30 2009", format) { match strptime(~"Fri Feb 13 15:31:30 2009", format) {
err(e) => fail e, err(e) => fail e,
ok(tm) => { ok(tm) => {
assert tm.tm_sec == 30_i32; assert tm.tm_sec == 30_i32;
@ -973,7 +977,7 @@ mod tests {
} }
fn test(s: ~str, format: ~str) -> bool { fn test(s: ~str, format: ~str) -> bool {
alt strptime(s, format) { match strptime(s, format) {
ok(tm) => tm.strftime(format) == s, ok(tm) => tm.strftime(format) == s,
err(e) => fail e err(e) => fail e
} }

View file

@ -215,7 +215,7 @@ mod test {
delayed_send(hl_loop, 1u, test_ch, expected); delayed_send(hl_loop, 1u, test_ch, expected);
}; };
alt recv_timeout(hl_loop, 10u, test_po) { match recv_timeout(hl_loop, 10u, test_po) {
some(val) => { some(val) => {
assert val == expected; assert val == expected;
successes += 1; successes += 1;
@ -243,7 +243,7 @@ mod test {
delayed_send(hl_loop, 1000u, test_ch, expected); delayed_send(hl_loop, 1000u, test_ch, expected);
}; };
alt recv_timeout(hl_loop, 1u, test_po) { match recv_timeout(hl_loop, 1u, test_po) {
none => successes += 1, none => successes += 1,
_ => failures += 1 _ => failures += 1
}; };

View file

@ -30,7 +30,7 @@ fn treemap<K, V>() -> treemap<K, V> { @mut none }
/// Insert a value into the map /// Insert a value into the map
fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) { fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
alt copy *m { match copy *m {
none => { none => {
*m = some(@tree_node({key: k, *m = some(@tree_node({key: k,
mut value: v, mut value: v,
@ -52,7 +52,7 @@ fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
/// Find a value based on the key /// Find a value based on the key
fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> { fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
alt copy *m { match copy *m {
none => none, none => none,
// FIXME (#2808): was that an optimization? // FIXME (#2808): was that an optimization?
@ -70,7 +70,7 @@ fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
/// Visit all pairs in the map in order. /// Visit all pairs in the map in order.
fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) { fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) {
alt copy *m { match copy *m {
none => (), none => (),
some(node) => { some(node) => {
traverse(&const node.left, f); traverse(&const node.left, f);

View file

@ -56,7 +56,7 @@ fn get_monitor_task_gl() -> iotask unsafe {
let hl_loop = spawn_loop(); let hl_loop = spawn_loop();
loop { loop {
debug!{"in outer_loop..."}; debug!{"in outer_loop..."};
alt select2(weak_exit_po, msg_po) { match select2(weak_exit_po, msg_po) {
left(weak_exit) => { left(weak_exit) => {
// all normal tasks have ended, tell the // all normal tasks have ended, tell the
// libuv loop to tear_down, then exit // libuv loop to tear_down, then exit

View file

@ -144,7 +144,7 @@ extern fn wake_up_cb(async_handle: *ll::uv_async_t,
let msg_po = (*data).msg_po; let msg_po = (*data).msg_po;
while msg_po.peek() { while msg_po.peek() {
alt msg_po.recv() { match msg_po.recv() {
interaction(cb) => cb(loop_ptr), interaction(cb) => cb(loop_ptr),
teardown_loop => begin_teardown(data) teardown_loop => begin_teardown(data)
} }

View file

@ -848,7 +848,7 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
src_unsafe_ptr, src}); src_unsafe_ptr, src});
let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr, let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr,
dst_buf, size as libc::size_t); dst_buf, size as libc::size_t);
alt result { match result {
0i32 => str::unsafe::from_buf(dst_buf), 0i32 => str::unsafe::from_buf(dst_buf),
_ => ~"" _ => ~""
} }

View file

@ -193,7 +193,7 @@ enum vstore {
} }
pure fn is_blockish(p: ast::proto) -> bool { pure fn is_blockish(p: ast::proto) -> bool {
alt p { match p {
proto_block => true, proto_block => true,
proto_bare | proto_uniq | proto_box => false proto_bare | proto_uniq | proto_box => false
} }

View file

@ -12,7 +12,7 @@ type path = ~[path_elt];
/* FIXMEs that say "bad" are as per #2543 */ /* FIXMEs that say "bad" are as per #2543 */
fn path_to_str_with_sep(p: path, sep: ~str) -> ~str { fn path_to_str_with_sep(p: path, sep: ~str) -> ~str {
let strs = do vec::map(p) |e| { let strs = do vec::map(p) |e| {
alt e { match e {
path_mod(s) => /* FIXME (#2543) */ copy *s, path_mod(s) => /* FIXME (#2543) */ copy *s,
path_name(s) => /* FIXME (#2543) */ copy *s path_name(s) => /* FIXME (#2543) */ copy *s
} }
@ -104,7 +104,7 @@ fn map_decoded_item(diag: span_handler,
// methods get added to the AST map when their impl is visited. Since we // methods get added to the AST map when their impl is visited. Since we
// don't decode and instantiate the impl, but just the method, we have to // don't decode and instantiate the impl, but just the method, we have to
// add it to the table now: // add it to the table now:
alt ii { match ii {
ii_item(*) | ii_ctor(*) | ii_dtor(*) => { /* fallthrough */ } ii_item(*) | ii_ctor(*) | ii_dtor(*) => { /* fallthrough */ }
ii_foreign(i) => { ii_foreign(i) => {
cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic, cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic,
@ -127,7 +127,7 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
copy a, cx.local_id)); copy a, cx.local_id));
cx.local_id += 1u; cx.local_id += 1u;
} }
alt fk { match fk {
visit::fk_ctor(nm, attrs, tps, self_id, parent_id) => { visit::fk_ctor(nm, attrs, tps, self_id, parent_id) => {
let ct = @{node: {id: id, let ct = @{node: {id: id,
attrs: attrs, attrs: attrs,
@ -159,7 +159,7 @@ fn map_block(b: blk, cx: ctx, v: vt) {
fn number_pat(cx: ctx, pat: @pat) { fn number_pat(cx: ctx, pat: @pat) {
do ast_util::walk_pat(pat) |p| { do ast_util::walk_pat(pat) |p| {
alt p.node { match p.node {
pat_ident(*) => { pat_ident(*) => {
cx.map.insert(p.id, node_local(cx.local_id)); cx.map.insert(p.id, node_local(cx.local_id));
cx.local_id += 1u; cx.local_id += 1u;
@ -189,7 +189,7 @@ fn map_method(impl_did: def_id, impl_path: @path,
fn map_item(i: @item, cx: ctx, v: vt) { fn map_item(i: @item, cx: ctx, v: vt) {
let item_path = @/* FIXME (#2543) */ copy cx.path; let item_path = @/* FIXME (#2543) */ copy cx.path;
cx.map.insert(i.id, node_item(i, item_path)); cx.map.insert(i.id, node_item(i, item_path));
alt i.node { match i.node {
item_impl(_, opt_ir, _, ms) => { item_impl(_, opt_ir, _, ms) => {
let impl_did = ast_util::local_def(i.id); let impl_did = ast_util::local_def(i.id);
for ms.each |m| { for ms.each |m| {
@ -205,7 +205,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
} }
} }
item_foreign_mod(nm) => { item_foreign_mod(nm) => {
let abi = alt attr::foreign_abi(i.attrs) { let abi = match attr::foreign_abi(i.attrs) {
either::left(msg) => cx.diag.span_fatal(i.span, msg), either::left(msg) => cx.diag.span_fatal(i.span, msg),
either::right(abi) => abi either::right(abi) => abi
}; };
@ -248,7 +248,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
} }
_ => () _ => ()
} }
alt i.node { match i.node {
item_mod(_) | item_foreign_mod(_) => { item_mod(_) | item_foreign_mod(_) => {
vec::push(cx.path, path_mod(i.ident)); vec::push(cx.path, path_mod(i.ident));
} }
@ -259,9 +259,9 @@ fn map_item(i: @item, cx: ctx, v: vt) {
} }
fn map_view_item(vi: @view_item, cx: ctx, _v: vt) { fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
alt vi.node { match vi.node {
view_item_export(vps) => for vps.each |vp| { view_item_export(vps) => for vps.each |vp| {
let (id, name) = alt vp.node { let (id, name) = match vp.node {
view_path_simple(nm, _, id) => { view_path_simple(nm, _, id) => {
(id, /* FIXME (#2543) */ copy nm) (id, /* FIXME (#2543) */ copy nm)
} }
@ -281,7 +281,7 @@ fn map_expr(ex: @expr, cx: ctx, v: vt) {
} }
fn node_id_to_str(map: map, id: node_id) -> ~str { fn node_id_to_str(map: map, id: node_id) -> ~str {
alt map.find(id) { match map.find(id) {
none => { none => {
fmt!{"unknown node (id=%d)", id} fmt!{"unknown node (id=%d)", id}
} }

View file

@ -35,7 +35,7 @@ pure fn local_def(id: node_id) -> def_id { {crate: local_crate, node: id} }
pure fn is_local(did: ast::def_id) -> bool { did.crate == local_crate } pure fn is_local(did: ast::def_id) -> bool { did.crate == local_crate }
pure fn stmt_id(s: stmt) -> node_id { pure fn stmt_id(s: stmt) -> node_id {
alt s.node { match s.node {
stmt_decl(_, id) => id, stmt_decl(_, id) => id,
stmt_expr(_, id) => id, stmt_expr(_, id) => id,
stmt_semi(_, id) => id stmt_semi(_, id) => id
@ -43,7 +43,7 @@ pure fn stmt_id(s: stmt) -> node_id {
} }
fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} { fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
alt d { match d {
def_variant(enum_id, var_id) => { def_variant(enum_id, var_id) => {
return {enm: enum_id, var: var_id} return {enm: enum_id, var: var_id}
} }
@ -52,7 +52,7 @@ fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
} }
pure fn def_id_of_def(d: def) -> def_id { pure fn def_id_of_def(d: def) -> def_id {
alt d { match d {
def_fn(id, _) | def_mod(id) | def_fn(id, _) | def_mod(id) |
def_foreign_mod(id) | def_const(id) | def_foreign_mod(id) | def_const(id) |
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) | def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
@ -70,7 +70,7 @@ pure fn def_id_of_def(d: def) -> def_id {
} }
pure fn binop_to_str(op: binop) -> ~str { pure fn binop_to_str(op: binop) -> ~str {
alt op { match op {
add => return ~"+", add => return ~"+",
subtract => return ~"-", subtract => return ~"-",
mul => return ~"*", mul => return ~"*",
@ -93,7 +93,7 @@ pure fn binop_to_str(op: binop) -> ~str {
} }
pure fn binop_to_method_name(op: binop) -> option<~str> { pure fn binop_to_method_name(op: binop) -> option<~str> {
alt op { match op {
add => return some(~"add"), add => return some(~"add"),
subtract => return some(~"sub"), subtract => return some(~"sub"),
mul => return some(~"mul"), mul => return some(~"mul"),
@ -109,7 +109,7 @@ pure fn binop_to_method_name(op: binop) -> option<~str> {
} }
pure fn lazy_binop(b: binop) -> bool { pure fn lazy_binop(b: binop) -> bool {
alt b { match b {
and => true, and => true,
or => true, or => true,
_ => false _ => false
@ -117,7 +117,7 @@ pure fn lazy_binop(b: binop) -> bool {
} }
pure fn is_shift_binop(b: binop) -> bool { pure fn is_shift_binop(b: binop) -> bool {
alt b { match b {
shl => true, shl => true,
shr => true, shr => true,
_ => false _ => false
@ -125,7 +125,7 @@ pure fn is_shift_binop(b: binop) -> bool {
} }
pure fn unop_to_str(op: unop) -> ~str { pure fn unop_to_str(op: unop) -> ~str {
alt op { match op {
box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" }, box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" },
uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" }, uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" },
deref => ~"*", deref => ~"*",
@ -135,11 +135,11 @@ pure fn unop_to_str(op: unop) -> ~str {
} }
pure fn is_path(e: @expr) -> bool { pure fn is_path(e: @expr) -> bool {
return alt e.node { expr_path(_) => true, _ => false }; return match e.node { expr_path(_) => true, _ => false };
} }
pure fn int_ty_to_str(t: int_ty) -> ~str { pure fn int_ty_to_str(t: int_ty) -> ~str {
alt t { match t {
ty_char => ~"u8", // ??? ty_char => ~"u8", // ???
ty_i => ~"", ty_i => ~"",
ty_i8 => ~"i8", ty_i8 => ~"i8",
@ -150,7 +150,7 @@ pure fn int_ty_to_str(t: int_ty) -> ~str {
} }
pure fn int_ty_max(t: int_ty) -> u64 { pure fn int_ty_max(t: int_ty) -> u64 {
alt t { match t {
ty_i8 => 0x80u64, ty_i8 => 0x80u64,
ty_i16 => 0x8000u64, ty_i16 => 0x8000u64,
ty_i | ty_char | ty_i32 => 0x80000000u64, // actually ni about ty_i ty_i | ty_char | ty_i32 => 0x80000000u64, // actually ni about ty_i
@ -159,7 +159,7 @@ pure fn int_ty_max(t: int_ty) -> u64 {
} }
pure fn uint_ty_to_str(t: uint_ty) -> ~str { pure fn uint_ty_to_str(t: uint_ty) -> ~str {
alt t { match t {
ty_u => ~"u", ty_u => ~"u",
ty_u8 => ~"u8", ty_u8 => ~"u8",
ty_u16 => ~"u16", ty_u16 => ~"u16",
@ -169,7 +169,7 @@ pure fn uint_ty_to_str(t: uint_ty) -> ~str {
} }
pure fn uint_ty_max(t: uint_ty) -> u64 { pure fn uint_ty_max(t: uint_ty) -> u64 {
alt t { match t {
ty_u8 => 0xffu64, ty_u8 => 0xffu64,
ty_u16 => 0xffffu64, ty_u16 => 0xffffu64,
ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u
@ -178,7 +178,7 @@ pure fn uint_ty_max(t: uint_ty) -> u64 {
} }
pure fn float_ty_to_str(t: float_ty) -> ~str { pure fn float_ty_to_str(t: float_ty) -> ~str {
alt t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" } match t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" }
} }
fn is_exported(i: ident, m: _mod) -> bool { fn is_exported(i: ident, m: _mod) -> bool {
@ -186,7 +186,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
let mut parent_enum : option<ident> = none; let mut parent_enum : option<ident> = none;
for m.items.each |it| { for m.items.each |it| {
if it.ident == i { local = true; } if it.ident == i { local = true; }
alt it.node { match it.node {
item_enum(variants, _) => for variants.each |v| { item_enum(variants, _) => for variants.each |v| {
if v.node.name == i { if v.node.name == i {
local = true; local = true;
@ -199,14 +199,14 @@ fn is_exported(i: ident, m: _mod) -> bool {
} }
let mut has_explicit_exports = false; let mut has_explicit_exports = false;
for m.view_items.each |vi| { for m.view_items.each |vi| {
alt vi.node { match vi.node {
view_item_export(vps) => { view_item_export(vps) => {
has_explicit_exports = true; has_explicit_exports = true;
for vps.each |vp| { for vps.each |vp| {
alt vp.node { match vp.node {
ast::view_path_simple(id, _, _) => { ast::view_path_simple(id, _, _) => {
if id == i { return true; } if id == i { return true; }
alt parent_enum { match parent_enum {
some(parent_enum_id) => { some(parent_enum_id) => {
if id == parent_enum_id { return true; } if id == parent_enum_id { return true; }
} }
@ -240,7 +240,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
} }
pure fn is_call_expr(e: @expr) -> bool { pure fn is_call_expr(e: @expr) -> bool {
alt e.node { expr_call(_, _, _) => true, _ => false } match e.node { expr_call(_, _, _) => true, _ => false }
} }
pure fn eq_ty(a: &@ty, b: &@ty) -> bool { box::ptr_eq(*a, *b) } pure fn eq_ty(a: &@ty, b: &@ty) -> bool { box::ptr_eq(*a, *b) }
@ -284,7 +284,7 @@ fn ident_to_path(s: span, +i: ident) -> @path {
} }
pure fn is_unguarded(&&a: arm) -> bool { pure fn is_unguarded(&&a: arm) -> bool {
alt a.guard { match a.guard {
none => true, none => true,
_ => false _ => false
} }
@ -295,7 +295,7 @@ pure fn unguarded_pat(a: arm) -> option<~[@pat]> {
} }
pure fn class_item_ident(ci: @class_member) -> ident { pure fn class_item_ident(ci: @class_member) -> ident {
alt ci.node { match ci.node {
instance_var(i,_,_,_,_) => /* FIXME (#2543) */ copy i, instance_var(i,_,_,_,_) => /* FIXME (#2543) */ copy i,
class_method(it) => /* FIXME (#2543) */ copy it.ident class_method(it) => /* FIXME (#2543) */ copy it.ident
} }
@ -306,7 +306,7 @@ type ivar = {ident: ident, ty: @ty, cm: class_mutability,
fn public_methods(ms: ~[@method]) -> ~[@method] { fn public_methods(ms: ~[@method]) -> ~[@method] {
vec::filter(ms, vec::filter(ms,
|m| alt m.vis { |m| match m.vis {
public => true, public => true,
_ => false _ => false
}) })
@ -315,7 +315,7 @@ fn public_methods(ms: ~[@method]) -> ~[@method] {
fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) { fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) {
let mut vs = ~[], ms = ~[]; let mut vs = ~[], ms = ~[];
for cs.each |c| { for cs.each |c| {
alt c.node { match c.node {
instance_var(i, t, cm, id, vis) => { instance_var(i, t, cm, id, vis) => {
vec::push(vs, {ident: /* FIXME (#2543) */ copy i, vec::push(vs, {ident: /* FIXME (#2543) */ copy i,
ty: t, ty: t,
@ -332,7 +332,7 @@ fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) {
// extract a ty_method from a trait_method. if the trait_method is // extract a ty_method from a trait_method. if the trait_method is
// a default, pull out the useful fields to make a ty_method // a default, pull out the useful fields to make a ty_method
fn trait_method_to_ty_method(method: trait_method) -> ty_method { fn trait_method_to_ty_method(method: trait_method) -> ty_method {
alt method { match method {
required(m) => m, required(m) => m,
provided(m) => { provided(m) => {
{ident: m.ident, attrs: m.attrs, {ident: m.ident, attrs: m.attrs,
@ -346,7 +346,7 @@ fn split_trait_methods(trait_methods: ~[trait_method])
-> (~[ty_method], ~[@method]) { -> (~[ty_method], ~[@method]) {
let mut reqd = ~[], provd = ~[]; let mut reqd = ~[], provd = ~[];
for trait_methods.each |trt_method| { for trait_methods.each |trt_method| {
alt trt_method { match trt_method {
required(tm) => vec::push(reqd, tm), required(tm) => vec::push(reqd, tm),
provided(m) => vec::push(provd, m) provided(m) => vec::push(provd, m)
} }
@ -355,7 +355,7 @@ fn split_trait_methods(trait_methods: ~[trait_method])
} }
pure fn class_member_visibility(ci: @class_member) -> visibility { pure fn class_member_visibility(ci: @class_member) -> visibility {
alt ci.node { match ci.node {
instance_var(_, _, _, _, vis) => vis, instance_var(_, _, _, _, vis) => vis,
class_method(m) => m.vis class_method(m) => m.vis
} }
@ -369,7 +369,7 @@ trait inlined_item_utils {
impl inlined_item_methods of inlined_item_utils for inlined_item { impl inlined_item_methods of inlined_item_utils for inlined_item {
fn ident() -> ident { fn ident() -> ident {
alt self { match self {
ii_item(i) => /* FIXME (#2543) */ copy i.ident, ii_item(i) => /* FIXME (#2543) */ copy i.ident,
ii_foreign(i) => /* FIXME (#2543) */ copy i.ident, ii_foreign(i) => /* FIXME (#2543) */ copy i.ident,
ii_method(_, m) => /* FIXME (#2543) */ copy m.ident, ii_method(_, m) => /* FIXME (#2543) */ copy m.ident,
@ -379,7 +379,7 @@ impl inlined_item_methods of inlined_item_utils for inlined_item {
} }
fn id() -> ast::node_id { fn id() -> ast::node_id {
alt self { match self {
ii_item(i) => i.id, ii_item(i) => i.id,
ii_foreign(i) => i.id, ii_foreign(i) => i.id,
ii_method(_, m) => m.id, ii_method(_, m) => m.id,
@ -389,7 +389,7 @@ impl inlined_item_methods of inlined_item_utils for inlined_item {
} }
fn accept<E>(e: E, v: visit::vt<E>) { fn accept<E>(e: E, v: visit::vt<E>) {
alt self { match self {
ii_item(i) => v.visit_item(i, e, v), ii_item(i) => v.visit_item(i, e, v),
ii_foreign(i) => v.visit_foreign_item(i, e, v), ii_foreign(i) => v.visit_foreign_item(i, e, v),
ii_method(_, m) => visit::visit_method_helper(m, e, v), ii_method(_, m) => visit::visit_method_helper(m, e, v),
@ -406,7 +406,7 @@ impl inlined_item_methods of inlined_item_utils for inlined_item {
/* True if d is either a def_self, or a chain of def_upvars /* True if d is either a def_self, or a chain of def_upvars
referring to a def_self */ referring to a def_self */
fn is_self(d: ast::def) -> bool { fn is_self(d: ast::def) -> bool {
alt d { match d {
def_self(_) => true, def_self(_) => true,
def_upvar(_, d, _) => is_self(*d), def_upvar(_, d, _) => is_self(*d),
_ => false _ => false
@ -415,7 +415,7 @@ fn is_self(d: ast::def) -> bool {
/// Maps a binary operator to its precedence /// Maps a binary operator to its precedence
fn operator_prec(op: ast::binop) -> uint { fn operator_prec(op: ast::binop) -> uint {
alt op { match op {
mul | div | rem => 12u, mul | div | rem => 12u,
// 'as' sits between here with 11 // 'as' sits between here with 11
add | subtract => 10u, add | subtract => 10u,
@ -455,11 +455,11 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
}, },
visit_view_item: fn@(vi: @view_item) { visit_view_item: fn@(vi: @view_item) {
alt vi.node { match vi.node {
view_item_use(_, _, id) => vfn(id), view_item_use(_, _, id) => vfn(id),
view_item_import(vps) | view_item_export(vps) => { view_item_import(vps) | view_item_export(vps) => {
do vec::iter(vps) |vp| { do vec::iter(vps) |vp| {
alt vp.node { match vp.node {
view_path_simple(_, _, id) => vfn(id), view_path_simple(_, _, id) => vfn(id),
view_path_glob(_, id) => vfn(id), view_path_glob(_, id) => vfn(id),
view_path_list(_, _, id) => vfn(id) view_path_list(_, _, id) => vfn(id)
@ -475,7 +475,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
visit_item: fn@(i: @item) { visit_item: fn@(i: @item) {
vfn(i.id); vfn(i.id);
alt i.node { match i.node {
item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); } item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); }
_ => () _ => ()
} }
@ -511,7 +511,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
}, },
visit_ty: fn@(t: @ty) { visit_ty: fn@(t: @ty) {
alt t.node { match t.node {
ty_path(_, id) => vfn(id), ty_path(_, id) => vfn(id),
_ => { /* fall through */ } _ => { /* fall through */ }
} }
@ -525,7 +525,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
_b: ast::blk, _sp: span, id: ast::node_id) { _b: ast::blk, _sp: span, id: ast::node_id) {
vfn(id); vfn(id);
alt fk { match fk {
visit::fk_ctor(nm, _, tps, self_id, parent_id) => { visit::fk_ctor(nm, _, tps, self_id, parent_id) => {
vec::iter(tps, |tp| vfn(tp.id)); vec::iter(tps, |tp| vfn(tp.id));
vfn(id); vfn(id);
@ -565,7 +565,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
}, },
visit_class_item: fn@(c: @class_member) { visit_class_item: fn@(c: @class_member) {
alt c.node { match c.node {
instance_var(_, _, _, id,_) => vfn(id), instance_var(_, _, _, id,_) => vfn(id),
class_method(_) => () class_method(_) => ()
} }
@ -592,7 +592,7 @@ fn compute_id_range_for_inlined_item(item: inlined_item) -> id_range {
} }
pure fn is_item_impl(item: @ast::item) -> bool { pure fn is_item_impl(item: @ast::item) -> bool {
alt item.node { match item.node {
item_impl(*) => true, item_impl(*) => true,
_ => false _ => false
} }
@ -600,7 +600,7 @@ pure fn is_item_impl(item: @ast::item) -> bool {
fn walk_pat(pat: @pat, it: fn(@pat)) { fn walk_pat(pat: @pat, it: fn(@pat)) {
it(pat); it(pat);
alt pat.node { match pat.node {
pat_ident(_, pth, some(p)) => walk_pat(p, it), pat_ident(_, pth, some(p)) => walk_pat(p, it),
pat_rec(fields, _) => for fields.each |f| { walk_pat(f.pat, it) } pat_rec(fields, _) => for fields.each |f| { walk_pat(f.pat, it) }
pat_enum(_, some(s)) | pat_tup(s) => for s.each |p| { pat_enum(_, some(s)) | pat_tup(s) => for s.each |p| {
@ -613,7 +613,7 @@ fn walk_pat(pat: @pat, it: fn(@pat)) {
} }
fn view_path_id(p: @view_path) -> node_id { fn view_path_id(p: @view_path) -> node_id {
alt p.node { match p.node {
view_path_simple(_, _, id) | view_path_glob(_, id) | view_path_simple(_, _, id) | view_path_glob(_, id) |
view_path_list(_, _, id) => id view_path_list(_, _, id) => id
} }

View file

@ -114,7 +114,7 @@ fn get_attr_name(attr: ast::attribute) -> ast::ident {
// All "bad" FIXME copies are as per #2543 // All "bad" FIXME copies are as per #2543
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident { fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
alt meta.node { match meta.node {
ast::meta_word(n) => /* FIXME (#2543) */ copy n, ast::meta_word(n) => /* FIXME (#2543) */ copy n,
ast::meta_name_value(n, _) => /* FIXME (#2543) */ copy n, ast::meta_name_value(n, _) => /* FIXME (#2543) */ copy n,
ast::meta_list(n, _) => /* FIXME (#2543) */ copy n ast::meta_list(n, _) => /* FIXME (#2543) */ copy n
@ -126,8 +126,8 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
* containing a string, otherwise none * containing a string, otherwise none
*/ */
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> { fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> {
alt meta.node { match meta.node {
ast::meta_name_value(_, v) => alt v.node { ast::meta_name_value(_, v) => match v.node {
ast::lit_str(s) => option::some(s), ast::lit_str(s) => option::some(s),
_ => option::none _ => option::none
} }
@ -137,7 +137,7 @@ fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> {
/// Gets a list of inner meta items from a list meta_item type /// Gets a list of inner meta items from a list meta_item type
fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> { fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
alt meta.node { match meta.node {
ast::meta_list(_, l) => option::some(/* FIXME (#2543) */ copy l), ast::meta_list(_, l) => option::some(/* FIXME (#2543) */ copy l),
_ => option::none _ => option::none
} }
@ -150,7 +150,7 @@ fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
fn get_name_value_str_pair( fn get_name_value_str_pair(
item: @ast::meta_item item: @ast::meta_item
) -> option<(ast::ident, @~str)> { ) -> option<(ast::ident, @~str)> {
alt attr::get_meta_item_value_str(item) { match attr::get_meta_item_value_str(item) {
some(value) => { some(value) => {
let name = attr::get_meta_item_name(item); let name = attr::get_meta_item_name(item);
some((name, value)) some((name, value))
@ -203,12 +203,12 @@ fn contains(haystack: ~[@ast::meta_item], needle: @ast::meta_item) -> bool {
} }
fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
return alt a.node { return match a.node {
ast::meta_word(na) => alt b.node { ast::meta_word(na) => match b.node {
ast::meta_word(nb) => na == nb, ast::meta_word(nb) => na == nb,
_ => false _ => false
} }
ast::meta_name_value(na, va) => alt b.node { ast::meta_name_value(na, va) => match b.node {
ast::meta_name_value(nb, vb) => na == nb && va.node == vb.node, ast::meta_name_value(nb, vb) => na == nb && va.node == vb.node,
_ => false _ => false
} }
@ -253,8 +253,8 @@ fn last_meta_item_value_str_by_name(
items: ~[@ast::meta_item], items: ~[@ast::meta_item],
+name: ~str +name: ~str
) -> option<@~str> { ) -> option<@~str> {
alt last_meta_item_by_name(items, name) { match last_meta_item_by_name(items, name) {
some(item) => alt attr::get_meta_item_value_str(item) { some(item) => match attr::get_meta_item_value_str(item) {
some(value) => some(value), some(value) => some(value),
none => none none => none
} }
@ -266,7 +266,7 @@ fn last_meta_item_list_by_name(
items: ~[@ast::meta_item], items: ~[@ast::meta_item],
+name: ~str +name: ~str
) -> option<~[@ast::meta_item]> { ) -> option<~[@ast::meta_item]> {
alt last_meta_item_by_name(items, name) { match last_meta_item_by_name(items, name) {
some(item) => attr::get_meta_item_list(item), some(item) => attr::get_meta_item_list(item),
none => none none => none
} }
@ -280,7 +280,7 @@ fn last_meta_item_list_by_name(
fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] { fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool { pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
pure fn key(m: &ast::meta_item) -> ast::ident { pure fn key(m: &ast::meta_item) -> ast::ident {
alt m.node { match m.node {
ast::meta_word(name) => /* FIXME (#2543) */ copy name, ast::meta_word(name) => /* FIXME (#2543) */ copy name,
ast::meta_name_value(name, _) => /* FIXME (#2543) */ copy name, ast::meta_name_value(name, _) => /* FIXME (#2543) */ copy name,
ast::meta_list(name, _) => /* FIXME (#2543) */ copy name ast::meta_list(name, _) => /* FIXME (#2543) */ copy name
@ -310,7 +310,7 @@ fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ast::ident) ->
fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] { fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] {
let mut found = ~[]; let mut found = ~[];
for find_attrs_by_name(attrs, ~"link").each |attr| { for find_attrs_by_name(attrs, ~"link").each |attr| {
alt attr.node.value.node { match attr.node.value.node {
ast::meta_list(_, _) => vec::push(found, attr), ast::meta_list(_, _) => vec::push(found, attr),
_ => debug!{"ignoring link attribute that has incorrect type"} _ => debug!{"ignoring link attribute that has incorrect type"}
} }
@ -324,14 +324,14 @@ fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] {
*/ */
fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] { fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
do find_linkage_attrs(attrs).flat_map |attr| { do find_linkage_attrs(attrs).flat_map |attr| {
alt check attr.node.value.node { match check attr.node.value.node {
ast::meta_list(_, items) => /* FIXME (#2543) */ copy items ast::meta_list(_, items) => /* FIXME (#2543) */ copy items
} }
} }
} }
fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> { fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
return alt attr::first_attr_value_str_by_name(attrs, ~"abi") { return match attr::first_attr_value_str_by_name(attrs, ~"abi") {
option::none => { option::none => {
either::right(ast::foreign_abi_cdecl) either::right(ast::foreign_abi_cdecl)
} }
@ -361,7 +361,7 @@ enum inline_attr {
fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr { fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr {
// FIXME (#2809)---validate the usage of #[inline] and #[inline(always)] // FIXME (#2809)---validate the usage of #[inline] and #[inline(always)]
do vec::foldl(ia_none, attrs) |ia,attr| { do vec::foldl(ia_none, attrs) |ia,attr| {
alt attr.node.value.node { match attr.node.value.node {
ast::meta_word(@~"inline") => ia_hint, ast::meta_word(@~"inline") => ia_hint,
ast::meta_list(@~"inline", items) => { ast::meta_list(@~"inline", items) => {
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) { if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {

View file

@ -124,7 +124,7 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
-> {filename: ~str, line: uint, col: uint, file: option<filemap>} -> {filename: ~str, line: uint, col: uint, file: option<filemap>}
{ {
let loc = lookup_char_pos(map, pos); let loc = lookup_char_pos(map, pos);
alt (loc.file.substr) { match (loc.file.substr) {
fss_none => { fss_none => {
{filename: /* FIXME (#2543) */ copy loc.file.name, {filename: /* FIXME (#2543) */ copy loc.file.name,
line: loc.line, line: loc.line,
@ -146,7 +146,7 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
fn adjust_span(map: codemap, sp: span) -> span { fn adjust_span(map: codemap, sp: span) -> span {
pure fn lookup(pos: file_pos) -> uint { return pos.ch; } pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
let line = lookup_line(map, sp.lo, lookup); let line = lookup_line(map, sp.lo, lookup);
alt (line.fm.substr) { match (line.fm.substr) {
fss_none => sp, fss_none => sp,
fss_internal(s) => { fss_internal(s) => {
adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch), adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
@ -196,7 +196,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
fn get_line(fm: filemap, line: int) -> ~str unsafe { fn get_line(fm: filemap, line: int) -> ~str unsafe {
let begin: uint = fm.lines[line].byte - fm.start_pos.byte; let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
let end = alt str::find_char_from(*fm.src, '\n', begin) { let end = match str::find_char_from(*fm.src, '\n', begin) {
some(e) => e, some(e) => e,
none => str::len(*fm.src) none => str::len(*fm.src)
}; };

View file

@ -87,7 +87,7 @@ impl codemap_handler of handler for handler_t {
fn has_errors() -> bool { self.err_count > 0u } fn has_errors() -> bool { self.err_count > 0u }
fn abort_if_errors() { fn abort_if_errors() {
let s; let s;
alt self.err_count { match self.err_count {
0u => return, 0u => return,
1u => s = ~"aborting due to previous error", 1u => s = ~"aborting due to previous error",
_ => { _ => {
@ -122,7 +122,7 @@ fn mk_span_handler(handler: handler, cm: codemap::codemap) -> span_handler {
fn mk_handler(emitter: option<emitter>) -> handler { fn mk_handler(emitter: option<emitter>) -> handler {
let emit = alt emitter { let emit = match emitter {
some(e) => e, some(e) => e,
none => { none => {
let f = fn@(cmsp: option<(codemap::codemap, span)>, let f = fn@(cmsp: option<(codemap::codemap, span)>,
@ -147,7 +147,7 @@ enum level {
} }
fn diagnosticstr(lvl: level) -> ~str { fn diagnosticstr(lvl: level) -> ~str {
alt lvl { match lvl {
fatal => ~"error", fatal => ~"error",
error => ~"error", error => ~"error",
warning => ~"warning", warning => ~"warning",
@ -156,7 +156,7 @@ fn diagnosticstr(lvl: level) -> ~str {
} }
fn diagnosticcolor(lvl: level) -> u8 { fn diagnosticcolor(lvl: level) -> u8 {
alt lvl { match lvl {
fatal => term::color_bright_red, fatal => term::color_bright_red,
error => term::color_bright_red, error => term::color_bright_red,
warning => term::color_bright_yellow, warning => term::color_bright_yellow,
@ -182,7 +182,7 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) {
fn emit(cmsp: option<(codemap::codemap, span)>, fn emit(cmsp: option<(codemap::codemap, span)>,
msg: ~str, lvl: level) { msg: ~str, lvl: level) {
alt cmsp { match cmsp {
some((cm, sp)) => { some((cm, sp)) => {
let sp = codemap::adjust_span(cm,sp); let sp = codemap::adjust_span(cm,sp);
let ss = codemap::span_to_str(sp, cm); let ss = codemap::span_to_str(sp, cm);
@ -266,7 +266,7 @@ fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
fn expect<T: copy>(diag: span_handler, fn expect<T: copy>(diag: span_handler,
opt: option<T>, msg: fn() -> ~str) -> T { opt: option<T>, msg: fn() -> ~str) -> T {
alt opt { match opt {
some(t) => t, some(t) => t,
none => diag.handler().bug(msg()) none => diag.handler().bug(msg())
} }

View file

@ -101,7 +101,7 @@ fn expand(cx: ext_ctxt,
} }
do vec::flat_map(in_items) |in_item| { do vec::flat_map(in_items) |in_item| {
alt in_item.node { match in_item.node {
ast::item_ty(ty, tps) => { ast::item_ty(ty, tps) => {
vec::append(~[filter_attrs(in_item)], vec::append(~[filter_attrs(in_item)],
ty_fns(cx, in_item.ident, ty, tps)) ty_fns(cx, in_item.ident, ty, tps))
@ -375,7 +375,7 @@ fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty,
} }
fn is_vec_or_str(ty: @ast::ty) -> bool { fn is_vec_or_str(ty: @ast::ty) -> bool {
alt ty.node { match ty.node {
ast::ty_vec(_) => true, ast::ty_vec(_) => true,
// This may be wrong if the user has shadowed (!) str // This may be wrong if the user has shadowed (!) str
ast::ty_path(@{span: _, global: _, idents: ids, ast::ty_path(@{span: _, global: _, idents: ids,
@ -391,7 +391,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
let ext_cx = cx; // required for #ast{} let ext_cx = cx; // required for #ast{}
alt ty.node { match ty.node {
ast::ty_nil => { ast::ty_nil => {
~[#ast[stmt]{$(s).emit_nil()}] ~[#ast[stmt]{$(s).emit_nil()}]
} }
@ -447,7 +447,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
ast::ty_tup(tys) => { ast::ty_tup(tys) => {
// Generate code like // Generate code like
// //
// alt v { // match v {
// (v1, v2, v3) { // (v1, v2, v3) {
// .. serialize v1, v2, v3 .. // .. serialize v1, v2, v3 ..
// } // }
@ -483,7 +483,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
vec::is_empty(path.types) { vec::is_empty(path.types) {
let ident = path.idents[0]; let ident = path.idents[0];
alt tps.find(*ident) { match tps.find(*ident) {
some(f) => f(v), some(f) => f(v),
none => ser_path(cx, tps, path, s, v) none => ser_path(cx, tps, path, s, v)
} }
@ -634,7 +634,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
let ext_cx = cx; // required for #ast{} let ext_cx = cx; // required for #ast{}
alt ty.node { match ty.node {
ast::ty_nil => { ast::ty_nil => {
#ast{ $(d).read_nil() } #ast{ $(d).read_nil() }
} }
@ -709,7 +709,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
vec::is_empty(path.types) { vec::is_empty(path.types) {
let ident = path.idents[0]; let ident = path.idents[0];
alt tps.find(*ident) { match tps.find(*ident) {
some(f) => f(), some(f) => f(),
none => deser_path(cx, tps, path, d) none => deser_path(cx, tps, path, d)
} }

View file

@ -150,7 +150,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
fn mod_pop() { vec::pop(self.mod_path); } fn mod_pop() { vec::pop(self.mod_path); }
fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn mod_path() -> ~[ast::ident] { return self.mod_path; }
fn bt_push(ei: codemap::expn_info_) { fn bt_push(ei: codemap::expn_info_) {
alt ei { match ei {
expanded_from({call_site: cs, callie: callie}) => { expanded_from({call_site: cs, callie: callie}) => {
self.backtrace = self.backtrace =
some(@expanded_from({ some(@expanded_from({
@ -161,7 +161,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
} }
} }
fn bt_pop() { fn bt_pop() {
alt self.backtrace { match self.backtrace {
some(@expanded_from({call_site: {expn_info: prev, _}, _})) => { some(@expanded_from({call_site: {expn_info: prev, _}, _})) => {
self.backtrace = prev self.backtrace = prev
} }
@ -206,8 +206,8 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
} }
fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str {
alt expr.node { match expr.node {
ast::expr_lit(l) => alt l.node { ast::expr_lit(l) => match l.node {
ast::lit_str(s) => return *s, ast::lit_str(s) => return *s,
_ => cx.span_fatal(l.span, error) _ => cx.span_fatal(l.span, error)
} }
@ -216,7 +216,7 @@ fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str {
} }
fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident { fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident {
alt expr.node { match expr.node {
ast::expr_path(p) => { ast::expr_path(p) => {
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
cx.span_fatal(expr.span, error); cx.span_fatal(expr.span, error);
@ -233,11 +233,11 @@ fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
min: uint, max: option<uint>, name: ~str) -> ~[@ast::expr] { min: uint, max: option<uint>, name: ~str) -> ~[@ast::expr] {
alt arg { match arg {
some(expr) => alt expr.node { some(expr) => match expr.node {
ast::expr_vec(elts, _) => { ast::expr_vec(elts, _) => {
let elts_len = vec::len(elts); let elts_len = vec::len(elts);
alt max { match max {
some(max) if ! (min <= elts_len && elts_len <= max) => { some(max) if ! (min <= elts_len && elts_len <= max) => {
cx.span_fatal(sp, cx.span_fatal(sp,
fmt!{"#%s takes between %u and %u arguments.", fmt!{"#%s takes between %u and %u arguments.",
@ -261,7 +261,7 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body) fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body)
-> ast::mac_body_ -> ast::mac_body_
{ {
alt (args) { match (args) {
some(body) => body, some(body) => body,
none => cx.span_fatal(sp, ~"missing macro body") none => cx.span_fatal(sp, ~"missing macro body")
} }
@ -289,10 +289,10 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic, let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, none, arg); cx.parse_sess().interner, none, arg);
let args = let args =
alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader, match parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
argument_gram).get(@~"arg") { argument_gram).get(@~"arg") {
@matched_seq(s, _) => do s.map() |lf| { @matched_seq(s, _) => do s.map() |lf| {
alt lf { match lf {
@matched_nonterminal(parse::token::nt_expr(arg)) => { @matched_nonterminal(parse::token::nt_expr(arg)) => {
arg /* whew! list of exprs, here we come! */ arg /* whew! list of exprs, here we come! */
} }

View file

@ -16,7 +16,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
// option<str> rather than just an maybe-empty string. // option<str> rather than just an maybe-empty string.
let var = expr_to_str(cx, args[0], ~"#env requires a string"); let var = expr_to_str(cx, args[0], ~"#env requires a string");
alt os::getenv(var) { match os::getenv(var) {
option::none => return mk_uniq_str(cx, sp, ~""), option::none => return mk_uniq_str(cx, sp, ~""),
option::some(s) => return mk_uniq_str(cx, sp, s) option::some(s) => return mk_uniq_str(cx, sp, s)
} }

View file

@ -15,18 +15,18 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
orig: fn@(expr_, span, ast_fold) -> (expr_, span)) orig: fn@(expr_, span, ast_fold) -> (expr_, span))
-> (expr_, span) -> (expr_, span)
{ {
return alt e { return match e {
// expr_mac should really be expr_ext or something; it's the // expr_mac should really be expr_ext or something; it's the
// entry-point for all syntax extensions. // entry-point for all syntax extensions.
expr_mac(mac) => { expr_mac(mac) => {
// Old-style macros, for compatibility, will erase this whole // Old-style macros, for compatibility, will erase this whole
// block once we've transitioned. // block once we've transitioned.
alt mac.node { match mac.node {
mac_invoc(pth, args, body) => { mac_invoc(pth, args, body) => {
assert (vec::len(pth.idents) > 0u); assert (vec::len(pth.idents) > 0u);
let extname = pth.idents[0]; let extname = pth.idents[0];
alt exts.find(*extname) { match exts.find(*extname) {
none => { none => {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname}) fmt!{"macro undefined: '%s'", *extname})
@ -69,13 +69,13 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
mac_invoc_tt(pth, tts) => { mac_invoc_tt(pth, tts) => {
assert (vec::len(pth.idents) == 1u); assert (vec::len(pth.idents) == 1u);
let extname = pth.idents[0]; let extname = pth.idents[0];
alt exts.find(*extname) { match exts.find(*extname) {
none => { none => {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname}) fmt!{"macro undefined: '%s'", *extname})
} }
some(expr_tt({expander: exp, span: exp_sp})) => { some(expr_tt({expander: exp, span: exp_sp})) => {
let expanded = alt exp(cx, mac.span, tts) { let expanded = match exp(cx, mac.span, tts) {
mr_expr(e) => e, mr_expr(e) => e,
_ => cx.span_fatal( _ => cx.span_fatal(
pth.span, fmt!{"non-expr macro in expr pos: %s", pth.span, fmt!{"non-expr macro in expr pos: %s",
@ -141,12 +141,12 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
// the item into a new set of items. // the item into a new set of items.
let new_items = do vec::flat_map(module_.items) |item| { let new_items = do vec::flat_map(module_.items) |item| {
do vec::foldr(item.attrs, ~[item]) |attr, items| { do vec::foldr(item.attrs, ~[item]) |attr, items| {
let mname = alt attr.node.value.node { let mname = match attr.node.value.node {
ast::meta_word(n) => n, ast::meta_word(n) => n,
ast::meta_name_value(n, _) => n, ast::meta_name_value(n, _) => n,
ast::meta_list(n, _) => n ast::meta_list(n, _) => n
}; };
alt exts.find(*mname) { match exts.find(*mname) {
none | some(normal(_)) | some(macro_defining(_)) none | some(normal(_)) | some(macro_defining(_))
| some(expr_tt(_)) | some(item_tt(*)) => items, | some(expr_tt(_)) | some(item_tt(*)) => items,
some(item_decorator(dec_fn)) => { some(item_decorator(dec_fn)) => {
@ -166,16 +166,16 @@ fn expand_item(exts: hashmap<~str, syntax_extension>,
orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>) orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>)
-> option<@ast::item> -> option<@ast::item>
{ {
let is_mod = alt it.node { let is_mod = match it.node {
ast::item_mod(_) | ast::item_foreign_mod(_) => true, ast::item_mod(_) | ast::item_foreign_mod(_) => true,
_ => false _ => false
}; };
let maybe_it = alt it.node { let maybe_it = match it.node {
ast::item_mac(*) => expand_item_mac(exts, cx, it, fld), ast::item_mac(*) => expand_item_mac(exts, cx, it, fld),
_ => some(it) _ => some(it)
}; };
alt maybe_it { match maybe_it {
some(it) => { some(it) => {
if is_mod { cx.mod_push(it.ident); } if is_mod { cx.mod_push(it.ident); }
let ret_val = orig(it, fld); let ret_val = orig(it, fld);
@ -192,10 +192,10 @@ fn expand_item(exts: hashmap<~str, syntax_extension>,
fn expand_item_mac(exts: hashmap<~str, syntax_extension>, fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
cx: ext_ctxt, &&it: @ast::item, cx: ext_ctxt, &&it: @ast::item,
fld: ast_fold) -> option<@ast::item> { fld: ast_fold) -> option<@ast::item> {
alt it.node { match it.node {
item_mac({node: mac_invoc_tt(pth, tts), span}) => { item_mac({node: mac_invoc_tt(pth, tts), span}) => {
let extname = pth.idents[0]; let extname = pth.idents[0];
alt exts.find(*extname) { match exts.find(*extname) {
none => { none => {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname}) fmt!{"macro undefined: '%s'", *extname})
@ -205,7 +205,7 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
cx.bt_push(expanded_from({call_site: it.span, cx.bt_push(expanded_from({call_site: it.span,
callie: {name: *extname, callie: {name: *extname,
span: expand.span}})); span: expand.span}}));
let maybe_it = alt expanded { let maybe_it = match expanded {
mr_item(it) => fld.fold_item(it), mr_item(it) => fld.fold_item(it),
mr_expr(e) => cx.span_fatal(pth.span, mr_expr(e) => cx.span_fatal(pth.span,
~"expr macro in item position: " + ~"expr macro in item position: " +

View file

@ -52,7 +52,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
fn make_flags(cx: ext_ctxt, sp: span, flags: ~[flag]) -> @ast::expr { fn make_flags(cx: ext_ctxt, sp: span, flags: ~[flag]) -> @ast::expr {
let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none"); let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none");
for flags.each |f| { for flags.each |f| {
let fstr = alt f { let fstr = match f {
flag_left_justify => ~"flag_left_justify", flag_left_justify => ~"flag_left_justify",
flag_left_zero_pad => ~"flag_left_zero_pad", flag_left_zero_pad => ~"flag_left_zero_pad",
flag_space_for_sign => ~"flag_space_for_sign", flag_space_for_sign => ~"flag_space_for_sign",
@ -65,7 +65,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
return tmp_expr; return tmp_expr;
} }
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr { fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
alt cnt { match cnt {
count_implied => { count_implied => {
return make_rt_path_expr(cx, sp, @~"count_implied"); return make_rt_path_expr(cx, sp, @~"count_implied");
} }
@ -80,8 +80,8 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
} }
fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr { fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr {
let mut rt_type; let mut rt_type;
alt t { match t {
ty_hex(c) => alt c { ty_hex(c) => match c {
case_upper => rt_type = ~"ty_hex_upper", case_upper => rt_type = ~"ty_hex_upper",
case_lower => rt_type = ~"ty_hex_lower" case_lower => rt_type = ~"ty_hex_lower"
} }
@ -121,8 +121,8 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
// FIXME: Move validation code into core::extfmt (Issue #2249) // FIXME: Move validation code into core::extfmt (Issue #2249)
fn is_signed_type(cnv: conv) -> bool { fn is_signed_type(cnv: conv) -> bool {
alt cnv.ty { match cnv.ty {
ty_int(s) => alt s { ty_int(s) => match s {
signed => return true, signed => return true,
unsigned => return false unsigned => return false
} }
@ -131,12 +131,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
} }
} }
let unsupported = ~"conversion not supported in #fmt string"; let unsupported = ~"conversion not supported in #fmt string";
alt cnv.param { match cnv.param {
option::none => (), option::none => (),
_ => cx.span_unimpl(sp, unsupported) _ => cx.span_unimpl(sp, unsupported)
} }
for cnv.flags.each |f| { for cnv.flags.each |f| {
alt f { match f {
flag_left_justify => (), flag_left_justify => (),
flag_sign_always => { flag_sign_always => {
if !is_signed_type(cnv) { if !is_signed_type(cnv) {
@ -156,19 +156,19 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
_ => cx.span_unimpl(sp, unsupported) _ => cx.span_unimpl(sp, unsupported)
} }
} }
alt cnv.width { match cnv.width {
count_implied => (), count_implied => (),
count_is(_) => (), count_is(_) => (),
_ => cx.span_unimpl(sp, unsupported) _ => cx.span_unimpl(sp, unsupported)
} }
alt cnv.precision { match cnv.precision {
count_implied => (), count_implied => (),
count_is(_) => (), count_is(_) => (),
_ => cx.span_unimpl(sp, unsupported) _ => cx.span_unimpl(sp, unsupported)
} }
alt cnv.ty { match cnv.ty {
ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg), ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg),
ty_int(sign) => alt sign { ty_int(sign) => match sign {
signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg), signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg),
unsigned => { unsigned => {
return make_conv_call(cx, arg.span, ~"uint", cnv, arg) return make_conv_call(cx, arg.span, ~"uint", cnv, arg)
@ -188,12 +188,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
} }
} }
fn log_conv(c: conv) { fn log_conv(c: conv) {
alt c.param { match c.param {
some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); } some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); }
_ => debug!{"param: none"} _ => debug!{"param: none"}
} }
for c.flags.each |f| { for c.flags.each |f| {
alt f { match f {
flag_left_justify => debug!{"flag: left justify"}, flag_left_justify => debug!{"flag: left justify"},
flag_left_zero_pad => debug!{"flag: left zero pad"}, flag_left_zero_pad => debug!{"flag: left zero pad"},
flag_space_for_sign => debug!{"flag: left space pad"}, flag_space_for_sign => debug!{"flag: left space pad"},
@ -201,7 +201,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
flag_alternate => debug!{"flag: alternate"} flag_alternate => debug!{"flag: alternate"}
} }
} }
alt c.width { match c.width {
count_is(i) => log( count_is(i) => log(
debug, ~"width: count is " + int::to_str(i, 10u)), debug, ~"width: count is " + int::to_str(i, 10u)),
count_is_param(i) => log( count_is_param(i) => log(
@ -209,7 +209,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
count_is_next_param => debug!{"width: count is next param"}, count_is_next_param => debug!{"width: count is next param"},
count_implied => debug!{"width: count is implied"} count_implied => debug!{"width: count is implied"}
} }
alt c.precision { match c.precision {
count_is(i) => log( count_is(i) => log(
debug, ~"prec: count is " + int::to_str(i, 10u)), debug, ~"prec: count is " + int::to_str(i, 10u)),
count_is_param(i) => log( count_is_param(i) => log(
@ -217,16 +217,16 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
count_is_next_param => debug!{"prec: count is next param"}, count_is_next_param => debug!{"prec: count is next param"},
count_implied => debug!{"prec: count is implied"} count_implied => debug!{"prec: count is implied"}
} }
alt c.ty { match c.ty {
ty_bool => debug!{"type: bool"}, ty_bool => debug!{"type: bool"},
ty_str => debug!{"type: str"}, ty_str => debug!{"type: str"},
ty_char => debug!{"type: char"}, ty_char => debug!{"type: char"},
ty_int(s) => alt s { ty_int(s) => match s {
signed => debug!{"type: signed"}, signed => debug!{"type: signed"},
unsigned => debug!{"type: unsigned"} unsigned => debug!{"type: unsigned"}
} }
ty_bits => debug!{"type: bits"}, ty_bits => debug!{"type: bits"},
ty_hex(cs) => alt cs { ty_hex(cs) => match cs {
case_upper => debug!{"type: uhex"}, case_upper => debug!{"type: uhex"},
case_lower => debug!{"type: lhex"}, case_lower => debug!{"type: lhex"},
} }
@ -240,7 +240,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
let mut piece_exprs = ~[]; let mut piece_exprs = ~[];
let nargs = args.len(); let nargs = args.len();
for pieces.each |pc| { for pieces.each |pc| {
alt pc { match pc {
piece_string(s) => { piece_string(s) => {
vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)) vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s))
} }

View file

@ -44,7 +44,7 @@ impl proto_check of proto::visitor<(), (), ()> for ext_ctxt {
fn visit_message(name: ident, _span: span, _tys: &[@ast::ty], fn visit_message(name: ident, _span: span, _tys: &[@ast::ty],
this: state, next: next_state) { this: state, next: next_state) {
alt next { match next {
some({state: next, tys: next_tys}) => { some({state: next, tys: next_tys}) => {
let proto = this.proto; let proto = this.proto;
if !proto.has_state(next) { if !proto.has_state(next) {

View file

@ -25,12 +25,12 @@ impl proto_parser of proto_parser for parser {
fn parse_state(proto: protocol) { fn parse_state(proto: protocol) {
let id = self.parse_ident(); let id = self.parse_ident();
self.expect(token::COLON); self.expect(token::COLON);
let dir = alt copy self.token { let dir = match copy self.token {
token::IDENT(n, _) => self.get_str(n), token::IDENT(n, _) => self.get_str(n),
_ => fail _ => fail
}; };
self.bump(); self.bump();
let dir = alt dir { let dir = match dir {
@~"send" => send, @~"send" => send,
@~"recv" => recv, @~"recv" => recv,
_ => fail _ => fail
@ -64,7 +64,7 @@ impl proto_parser of proto_parser for parser {
self.expect(token::RARROW); self.expect(token::RARROW);
let next = alt copy self.token { let next = match copy self.token {
token::IDENT(_, _) => { token::IDENT(_, _) => {
let name = self.parse_ident(); let name = self.parse_ident();
let ntys = if self.token == token::LT { let ntys = if self.token == token::LT {

View file

@ -47,7 +47,7 @@ trait gen_init {
impl compile of gen_send for message { impl compile of gen_send for message {
fn gen_send(cx: ext_ctxt) -> @ast::item { fn gen_send(cx: ext_ctxt) -> @ast::item {
debug!{"pipec: gen_send"}; debug!{"pipec: gen_send"};
alt self { match self {
message(id, span, tys, this, message(id, span, tys, this,
some({state: next, tys: next_tys})) => { some({state: next, tys: next_tys})) => {
debug!{"pipec: next state exists"}; debug!{"pipec: next state exists"};
@ -71,7 +71,7 @@ impl compile of gen_send for message {
let mut body = ~"{\n"; let mut body = ~"{\n";
if this.proto.is_bounded() { if this.proto.is_bounded() {
let (sp, rp) = alt (this.dir, next.dir) { let (sp, rp) = match (this.dir, next.dir) {
(send, send) => (~"c", ~"s"), (send, send) => (~"c", ~"s"),
(send, recv) => (~"s", ~"c"), (send, recv) => (~"s", ~"c"),
(recv, send) => (~"s", ~"c"), (recv, send) => (~"s", ~"c"),
@ -87,7 +87,7 @@ impl compile of gen_send for message {
rp, *next.name}; rp, *next.name};
} }
else { else {
let pat = alt (this.dir, next.dir) { let pat = match (this.dir, next.dir) {
(send, send) => ~"(c, s)", (send, send) => ~"(c, s)",
(send, recv) => ~"(s, c)", (send, recv) => ~"(s, c)",
(recv, send) => ~"(s, c)", (recv, send) => ~"(s, c)",
@ -181,12 +181,12 @@ impl compile of to_type_decls for state {
for self.messages.each |m| { for self.messages.each |m| {
let message(name, _span, tys, this, next) = m; let message(name, _span, tys, this, next) = m;
let tys = alt next { let tys = match next {
some({state: next, tys: next_tys}) => { some({state: next, tys: next_tys}) => {
let next = this.proto.get_state(next); let next = this.proto.get_state(next);
let next_name = next.data_name(); let next_name = next.data_name();
let dir = alt this.dir { let dir = match this.dir {
send => @~"server", send => @~"server",
recv => @~"client" recv => @~"client"
}; };
@ -208,7 +208,7 @@ impl compile of to_type_decls for state {
fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] { fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] {
debug!{"pipec: to_endpoint_decls"}; debug!{"pipec: to_endpoint_decls"};
let dir = alt dir { let dir = match dir {
send => (*self).dir, send => (*self).dir,
recv => (*self).dir.reverse() recv => (*self).dir.reverse()
}; };
@ -255,7 +255,7 @@ impl compile of gen_init for protocol {
let start_state = self.states[0]; let start_state = self.states[0];
let body = if !self.is_bounded() { let body = if !self.is_bounded() {
alt start_state.dir { match start_state.dir {
send => #ast { pipes::entangle() }, send => #ast { pipes::entangle() },
recv => { recv => {
#ast {{ #ast {{
@ -267,7 +267,7 @@ impl compile of gen_init for protocol {
} }
else { else {
let body = self.gen_init_bounded(ext_cx); let body = self.gen_init_bounded(ext_cx);
alt start_state.dir { match start_state.dir {
send => body, send => body,
recv => { recv => {
#ast {{ #ast {{
@ -322,7 +322,7 @@ impl compile of gen_init for protocol {
let mut params: ~[ast::ty_param] = ~[]; let mut params: ~[ast::ty_param] = ~[];
for (copy self.states).each |s| { for (copy self.states).each |s| {
for s.ty_params.each |tp| { for s.ty_params.each |tp| {
alt params.find(|tpp| *tp.ident == *tpp.ident) { match params.find(|tpp| *tp.ident == *tpp.ident) {
none => vec::push(params, tp), none => vec::push(params, tp),
_ => () _ => ()
} }
@ -338,7 +338,7 @@ impl compile of gen_init for protocol {
let mut params: ~[ast::ty_param] = ~[]; let mut params: ~[ast::ty_param] = ~[];
let fields = do (copy self.states).map_to_vec |s| { let fields = do (copy self.states).map_to_vec |s| {
for s.ty_params.each |tp| { for s.ty_params.each |tp| {
alt params.find(|tpp| *tp.ident == *tpp.ident) { match params.find(|tpp| *tp.ident == *tpp.ident) {
none => vec::push(params, tp), none => vec::push(params, tp),
_ => () _ => ()
} }
@ -439,7 +439,7 @@ impl parse_utils of ext_ctxt_parse_utils for ext_ctxt {
self.cfg(), self.cfg(),
~[], ~[],
self.parse_sess()); self.parse_sess());
alt res { match res {
some(ast) => ast, some(ast) => ast,
none => { none => {
error!{"Parse error with ```\n%s\n```", s}; error!{"Parse error with ```\n%s\n```", s};

View file

@ -11,7 +11,7 @@ enum direction {
impl of to_str for direction { impl of to_str for direction {
fn to_str() -> ~str { fn to_str() -> ~str {
alt self { match self {
send => ~"send", send => ~"send",
recv => ~"recv" recv => ~"recv"
} }
@ -20,7 +20,7 @@ impl of to_str for direction {
impl methods for direction { impl methods for direction {
fn reverse() -> direction { fn reverse() -> direction {
alt self { match self {
send => recv, send => recv,
recv => send recv => send
} }
@ -36,20 +36,20 @@ enum message {
impl methods for message { impl methods for message {
fn name() -> ident { fn name() -> ident {
alt self { match self {
message(id, _, _, _, _) => id message(id, _, _, _, _) => id
} }
} }
fn span() -> span { fn span() -> span {
alt self { match self {
message(_, span, _, _, _) => span message(_, span, _, _, _) => span
} }
} }
/// Return the type parameters actually used by this message /// Return the type parameters actually used by this message
fn get_params() -> ~[ast::ty_param] { fn get_params() -> ~[ast::ty_param] {
alt self { match self {
message(_, _, _, this, _) => this.ty_params message(_, _, _, this, _) => this.ty_params
} }
} }
@ -92,7 +92,7 @@ impl methods for state {
/// from this state. /// from this state.
fn reachable(f: fn(state) -> bool) { fn reachable(f: fn(state) -> bool) {
for self.messages.each |m| { for self.messages.each |m| {
alt m { match m {
message(_, _, _, _, some({state: id, _})) => { message(_, _, _, _, some({state: id, _})) => {
let state = self.proto.get_state(id); let state = self.proto.get_state(id);
if !f(state) { break } if !f(state) { break }

View file

@ -48,7 +48,7 @@ impl of qq_helper for @ast::expr {
fn span() -> span {self.span} fn span() -> span {self.span}
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);} fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);}
fn extract_mac() -> option<ast::mac_> { fn extract_mac() -> option<ast::mac_> {
alt (self.node) { match (self.node) {
ast::expr_mac({node: mac, _}) => some(mac), ast::expr_mac({node: mac, _}) => some(mac),
_ => none _ => none
} }
@ -63,7 +63,7 @@ impl of qq_helper for @ast::ty {
fn span() -> span {self.span} fn span() -> span {self.span}
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);} fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);}
fn extract_mac() -> option<ast::mac_> { fn extract_mac() -> option<ast::mac_> {
alt (self.node) { match (self.node) {
ast::ty_mac({node: mac, _}) => some(mac), ast::ty_mac({node: mac, _}) => some(mac),
_ => none _ => none
} }
@ -124,7 +124,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>) fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
{ {
alt (node.extract_mac()) { match (node.extract_mac()) {
some(mac_aq(sp, e)) => { some(mac_aq(sp, e)) => {
cx.gather.push(gather_item { cx.gather.push(gather_item {
lo: sp.lo - cx.lo, lo: sp.lo - cx.lo,
@ -147,7 +147,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
let mut what = ~"expr"; let mut what = ~"expr";
do option::iter(arg) |arg| { do option::iter(arg) |arg| {
let args: ~[@ast::expr] = let args: ~[@ast::expr] =
alt arg.node { match arg.node {
ast::expr_vec(elts, _) => elts, ast::expr_vec(elts, _) => elts,
_ => { _ => {
ecx.span_fatal ecx.span_fatal
@ -157,7 +157,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
if vec::len::<@ast::expr>(args) != 1u { if vec::len::<@ast::expr>(args) != 1u {
ecx.span_fatal(_sp, ~"#ast requires exactly one arg"); ecx.span_fatal(_sp, ~"#ast requires exactly one arg");
} }
alt (args[0].node) { match (args[0].node) {
ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u
=> what = *id[0], => what = *id[0],
_ => ecx.span_fatal(args[0].span, ~"expected an identifier") _ => ecx.span_fatal(args[0].span, ~"expected an identifier")
@ -165,7 +165,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
} }
let body = get_mac_body(ecx,_sp,body); let body = get_mac_body(ecx,_sp,body);
return alt what { return match what {
~"crate" => finish(ecx, body, parse_crate), ~"crate" => finish(ecx, body, parse_crate),
~"expr" => finish(ecx, body, parse_expr), ~"expr" => finish(ecx, body, parse_expr),
~"ty" => finish(ecx, body, parse_ty), ~"ty" => finish(ecx, body, parse_ty),
@ -183,7 +183,7 @@ fn parse_expr(p: parser) -> @ast::expr { p.parse_expr() }
fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) } fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) }
fn parse_item(p: parser) -> @ast::item { fn parse_item(p: parser) -> @ast::item {
alt p.parse_item(~[]) { match p.parse_item(~[]) {
some(item) => item, some(item) => item,
none => fail ~"parse_item: parsing an item failed" none => fail ~"parse_item: parsing an item failed"
} }
@ -225,7 +225,7 @@ fn finish<T: qq_helper>
state = skip(str::char_len(repl)); state = skip(str::char_len(repl));
str2 += repl; str2 += repl;
} }
alt copy state { match copy state {
active => str::push_char(str2, ch), active => str::push_char(str2, ch),
skip(1u) => state = blank, skip(1u) => state = blank,
skip(sk) => state = skip (sk-1u), skip(sk) => state = skip (sk-1u),
@ -308,8 +308,8 @@ fn replace_expr(repls: ~[fragment],
orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span)) orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span))
-> (ast::expr_, span) -> (ast::expr_, span)
{ {
alt e { match e {
ast::expr_mac({node: mac_var(i), _}) => alt (repls[i]) { ast::expr_mac({node: mac_var(i), _}) => match (repls[i]) {
from_expr(r) => (r.node, r.span), from_expr(r) => (r.node, r.span),
_ => fail /* fixme error message */ _ => fail /* fixme error message */
} }
@ -322,8 +322,8 @@ fn replace_ty(repls: ~[fragment],
orig: fn@(ast::ty_, span, ast_fold)->(ast::ty_, span)) orig: fn@(ast::ty_, span, ast_fold)->(ast::ty_, span))
-> (ast::ty_, span) -> (ast::ty_, span)
{ {
alt e { match e {
ast::ty_mac({node: mac_var(i), _}) => alt (repls[i]) { ast::ty_mac({node: mac_var(i), _}) => match (repls[i]) {
from_ty(r) => (r.node, r.span), from_ty(r) => (r.node, r.span),
_ => fail /* fixme error message */ _ => fail /* fixme error message */
} }

View file

@ -36,7 +36,7 @@ enum matchable {
/* for when given an incompatible bit of AST */ /* for when given an incompatible bit of AST */
fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! { fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! {
alt m { match m {
match_expr(x) => cx.span_fatal( match_expr(x) => cx.span_fatal(
x.span, ~"this argument is an expr, expected " + expected), x.span, ~"this argument is an expr, expected " + expected),
match_path(x) => cx.span_fatal( match_path(x) => cx.span_fatal(
@ -65,8 +65,8 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
let mut idx: uint = 0u; let mut idx: uint = 0u;
let mut res = none; let mut res = none;
for elts.each |elt| { for elts.each |elt| {
alt elt.node { match elt.node {
expr_mac(m) => alt m.node { expr_mac(m) => match m.node {
ast::mac_ellipsis => { ast::mac_ellipsis => {
if res != none { if res != none {
cx.span_fatal(m.span, ~"only one ellipsis allowed"); cx.span_fatal(m.span, ~"only one ellipsis allowed");
@ -82,7 +82,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
} }
idx += 1u; idx += 1u;
} }
return alt res { return match res {
some(val) => val, some(val) => val,
none => {pre: elts, rep: none, post: ~[]} none => {pre: elts, rep: none, post: ~[]}
} }
@ -92,7 +92,7 @@ fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) ->
option<~[U]> { option<~[U]> {
let mut res = ~[]; let mut res = ~[];
for v.each |elem| { for v.each |elem| {
alt f(elem) { match f(elem) {
none => return none, none => return none,
some(fv) => vec::push(res, fv) some(fv) => vec::push(res, fv)
} }
@ -101,9 +101,9 @@ fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) ->
} }
fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result { fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
alt ad { match ad {
leaf(x) => return f(x), leaf(x) => return f(x),
seq(ads, span) => alt option_flatten_map(|x| a_d_map(x, f), *ads) { seq(ads, span) => match option_flatten_map(|x| a_d_map(x, f), *ads) {
none => return none, none => return none,
some(ts) => return some(seq(@ts, span)) some(ts) => return some(seq(@ts, span))
} }
@ -112,7 +112,7 @@ fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
fn compose_sels(s1: selector, s2: selector) -> selector { fn compose_sels(s1: selector, s2: selector) -> selector {
fn scomp(s1: selector, s2: selector, m: matchable) -> match_result { fn scomp(s1: selector, s2: selector, m: matchable) -> match_result {
return alt s1(m) { return match s1(m) {
none => none, none => none,
some(matches) => a_d_map(matches, s2) some(matches) => a_d_map(matches, s2)
} }
@ -156,11 +156,11 @@ fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> {
let res = box_str_hash::<arb_depth<matchable>>(); let res = box_str_hash::<arb_depth<matchable>>();
//need to do this first, to check vec lengths. //need to do this first, to check vec lengths.
for b.literal_ast_matchers.each |sel| { for b.literal_ast_matchers.each |sel| {
alt sel(match_expr(e)) { none => return none, _ => () } match sel(match_expr(e)) { none => return none, _ => () }
} }
let mut never_mind: bool = false; let mut never_mind: bool = false;
for b.real_binders.each |key, val| { for b.real_binders.each |key, val| {
alt val(match_expr(e)) { match val(match_expr(e)) {
none => never_mind = true, none => never_mind = true,
some(mtc) => { res.insert(key, mtc); } some(mtc) => { res.insert(key, mtc); }
} }
@ -209,7 +209,7 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) ->
arb_depth<matchable> { arb_depth<matchable> {
let mut res: arb_depth<matchable> = m; let mut res: arb_depth<matchable> = m;
for vec::each(*idx_path) |idx| { for vec::each(*idx_path) |idx| {
res = alt res { res = match res {
leaf(_) => return res,/* end of the line */ leaf(_) => return res,/* end of the line */
seq(new_ms, _) => new_ms[idx] seq(new_ms, _) => new_ms[idx]
} }
@ -219,10 +219,10 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) ->
fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>, fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>,
idx_path: @mut ~[uint]) -> option<matchable> { idx_path: @mut ~[uint]) -> option<matchable> {
alt mmaybe { match mmaybe {
none => return none, none => return none,
some(m) => { some(m) => {
return alt follow(m, idx_path) { return match follow(m, idx_path) {
seq(_, sp) => { seq(_, sp) => {
cx.span_fatal(sp, cx.span_fatal(sp,
~"syntax matched under ... but not " + ~"syntax matched under ... but not " +
@ -258,10 +258,10 @@ fn free_vars(b: bindings, e: @expr, it: fn(ident)) {
fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
recur: fn@(&&@expr) -> @expr, recur: fn@(&&@expr) -> @expr,
exprs: ~[@expr]) -> ~[@expr] { exprs: ~[@expr]) -> ~[@expr] {
alt elts_to_ell(cx, exprs) { match elts_to_ell(cx, exprs) {
{pre: pre, rep: repeat_me_maybe, post: post} => { {pre: pre, rep: repeat_me_maybe, post: post} => {
let mut res = vec::map(pre, recur); let mut res = vec::map(pre, recur);
alt repeat_me_maybe { match repeat_me_maybe {
none => (), none => (),
some(repeat_me) => { some(repeat_me) => {
let mut repeat: option<{rep_count: uint, name: ident}> = none; let mut repeat: option<{rep_count: uint, name: ident}> = none;
@ -269,10 +269,10 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
the leaves, which are just duplicated */ the leaves, which are just duplicated */
do free_vars(b, repeat_me) |fv| { do free_vars(b, repeat_me) |fv| {
let cur_pos = follow(b.get(fv), idx_path); let cur_pos = follow(b.get(fv), idx_path);
alt cur_pos { match cur_pos {
leaf(_) => (), leaf(_) => (),
seq(ms, _) => { seq(ms, _) => {
alt repeat { match repeat {
none => { none => {
repeat = some({rep_count: vec::len(*ms), name: fv}); repeat = some({rep_count: vec::len(*ms), name: fv});
} }
@ -290,7 +290,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
} }
} }
}; };
alt repeat { match repeat {
none => { none => {
cx.span_fatal(repeat_me.span, cx.span_fatal(repeat_me.span,
~"'...' surrounds an expression without any" + ~"'...' surrounds an expression without any" +
@ -320,7 +320,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
// substitute, in a position that's required to be an ident // substitute, in a position that's required to be an ident
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
&&i: ident, _fld: ast_fold) -> ident { &&i: ident, _fld: ast_fold) -> ident {
return alt follow_for_trans(cx, b.find(i), idx_path) { return match follow_for_trans(cx, b.find(i), idx_path) {
some(match_ident(a_id)) => a_id.node, some(match_ident(a_id)) => a_id.node,
some(m) => match_error(cx, m, ~"an identifier"), some(m) => match_error(cx, m, ~"an identifier"),
none => i none => i
@ -332,7 +332,7 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
p: path, _fld: ast_fold) -> path { p: path, _fld: ast_fold) -> path {
// Don't substitute into qualified names. // Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; } if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; }
alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { match follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
some(match_ident(id)) => { some(match_ident(id)) => {
{span: id.span, global: false, idents: ~[id.node], {span: id.span, global: false, idents: ~[id.node],
rp: none, types: ~[]} rp: none, types: ~[]}
@ -349,13 +349,13 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span)) orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span))
-> (ast::expr_, span) -> (ast::expr_, span)
{ {
return alt e { return match e {
expr_path(p) => { expr_path(p) => {
// Don't substitute into qualified names. // Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
(e, s); (e, s);
} }
alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { match follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
some(match_ident(id)) => { some(match_ident(id)) => {
(expr_path(@{span: id.span, (expr_path(@{span: id.span,
global: false, global: false,
@ -378,11 +378,11 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
orig: fn@(ast::ty_, span, ast_fold) -> (ast::ty_, span)) orig: fn@(ast::ty_, span, ast_fold) -> (ast::ty_, span))
-> (ast::ty_, span) -> (ast::ty_, span)
{ {
return alt t { return match t {
ast::ty_path(pth, _) => { ast::ty_path(pth, _) => {
alt path_to_ident(pth) { match path_to_ident(pth) {
some(id) => { some(id) => {
alt follow_for_trans(cx, b.find(id), idx_path) { match follow_for_trans(cx, b.find(id), idx_path) {
some(match_ty(ty)) => (ty.node, ty.span), some(match_ty(ty)) => (ty.node, ty.span),
some(m) => match_error(cx, m, ~"a type"), some(m) => match_error(cx, m, ~"a type"),
none => orig(t, s, fld) none => orig(t, s, fld)
@ -404,9 +404,9 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
orig: fn@(blk_, span, ast_fold) -> (blk_, span)) orig: fn@(blk_, span, ast_fold) -> (blk_, span))
-> (blk_, span) -> (blk_, span)
{ {
return alt block_to_ident(blk) { return match block_to_ident(blk) {
some(id) => { some(id) => {
alt follow_for_trans(cx, b.find(id), idx_path) { match follow_for_trans(cx, b.find(id), idx_path) {
some(match_block(new_blk)) => (new_blk.node, new_blk.span), some(match_block(new_blk)) => (new_blk.node, new_blk.span),
// possibly allow promotion of ident/path/expr to blocks? // possibly allow promotion of ident/path/expr to blocks?
@ -424,12 +424,12 @@ argument. ps accumulates instructions on navigating the tree.*/
fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
//it might be possible to traverse only exprs, not matchables //it might be possible to traverse only exprs, not matchables
alt m { match m {
match_expr(e) => { match_expr(e) => {
alt e.node { match e.node {
expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b), expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b),
expr_vec(p_elts, _) => { expr_vec(p_elts, _) => {
alt elts_to_ell(cx, p_elts) { match elts_to_ell(cx, p_elts) {
{pre: pre, rep: some(repeat_me), post: post} => { {pre: pre, rep: some(repeat_me), post: post} => {
p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s, p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s,
b); b);
@ -459,7 +459,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
_ => { _ => {
fn select(cx: ext_ctxt, m: matchable, pat: @expr) -> fn select(cx: ext_ctxt, m: matchable, pat: @expr) ->
match_result { match_result {
return alt m { return match m {
match_expr(e) => { match_expr(e) => {
if e == pat { some(leaf(match_exact)) } else { none } if e == pat { some(leaf(match_exact)) } else { none }
} }
@ -477,11 +477,11 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
/* make a match more precise */ /* make a match more precise */
fn specialize_match(m: matchable) -> matchable { fn specialize_match(m: matchable) -> matchable {
return alt m { return match m {
match_expr(e) => { match_expr(e) => {
alt e.node { match e.node {
expr_path(pth) => { expr_path(pth) => {
alt path_to_ident(pth) { match path_to_ident(pth) {
some(id) => match_ident(respan(pth.span, id)), some(id) => match_ident(respan(pth.span, id)),
none => match_path(pth) none => match_path(pth)
} }
@ -495,10 +495,10 @@ fn specialize_match(m: matchable) -> matchable {
/* pattern_to_selectors helper functions */ /* pattern_to_selectors helper functions */
fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) { fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
alt path_to_ident(p) { match path_to_ident(p) {
some(p_id) => { some(p_id) => {
fn select(cx: ext_ctxt, m: matchable) -> match_result { fn select(cx: ext_ctxt, m: matchable) -> match_result {
return alt m { return match m {
match_expr(e) => some(leaf(specialize_match(m))), match_expr(e) => some(leaf(specialize_match(m))),
_ => cx.bug(~"broken traversal in p_t_s_r") _ => cx.bug(~"broken traversal in p_t_s_r")
} }
@ -514,8 +514,8 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
fn block_to_ident(blk: blk_) -> option<ident> { fn block_to_ident(blk: blk_) -> option<ident> {
if vec::len(blk.stmts) != 0u { return none; } if vec::len(blk.stmts) != 0u { return none; }
return alt blk.expr { return match blk.expr {
some(expr) => alt expr.node { some(expr) => match expr.node {
expr_path(pth) => path_to_ident(pth), expr_path(pth) => path_to_ident(pth),
_ => none _ => none
} }
@ -526,8 +526,8 @@ fn block_to_ident(blk: blk_) -> option<ident> {
fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) { fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) {
fn select_pt_1(cx: ext_ctxt, m: matchable, fn select_pt_1(cx: ext_ctxt, m: matchable,
fn_m: fn(ast::mac) -> match_result) -> match_result { fn_m: fn(ast::mac) -> match_result) -> match_result {
return alt m { return match m {
match_expr(e) => alt e.node { match_expr(e) => match e.node {
expr_mac(mac) => fn_m(mac), expr_mac(mac) => fn_m(mac),
_ => none _ => none
} }
@ -537,7 +537,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) {
fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! { fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! {
cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported"); cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported");
} }
alt mac.node { match mac.node {
ast::mac_ellipsis => cx.span_fatal(mac.span, ~"misused `...`"), ast::mac_ellipsis => cx.span_fatal(mac.span, ~"misused `...`"),
ast::mac_invoc(_, _, _) => no_des(cx, mac.span, ~"macro calls"), ast::mac_invoc(_, _, _) => no_des(cx, mac.span, ~"macro calls"),
ast::mac_invoc_tt(_, _) => no_des(cx, mac.span, ~"macro calls"), ast::mac_invoc_tt(_, _) => no_des(cx, mac.span, ~"macro calls"),
@ -550,9 +550,9 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector,
b: binders) { b: binders) {
fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) -> fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) ->
match_result { match_result {
return alt m { return match m {
match_expr(e) => { match_expr(e) => {
alt e.node { match e.node {
expr_vec(arg_elts, _) => { expr_vec(arg_elts, _) => {
let mut elts = ~[]; let mut elts = ~[];
let mut idx = offset; let mut idx = offset;
@ -580,9 +580,9 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector,
b: binders) { b: binders) {
fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) -> fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) ->
match_result { match_result {
return alt m { return match m {
match_expr(e) => { match_expr(e) => {
alt e.node { match e.node {
expr_vec(arg_elts, _) => { expr_vec(arg_elts, _) => {
let actual_len = vec::len(arg_elts); let actual_len = vec::len(arg_elts);
if at_least && actual_len >= len || actual_len == len { if at_least && actual_len >= len || actual_len == len {
@ -604,9 +604,9 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
let mut idx: uint = 0u; let mut idx: uint = 0u;
while idx < vec::len(elts) { while idx < vec::len(elts) {
fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result { fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result {
return alt m { return match m {
match_expr(e) => { match_expr(e) => {
alt e.node { match e.node {
expr_vec(arg_elts, _) => { expr_vec(arg_elts, _) => {
some(leaf(match_expr(arg_elts[idx]))) some(leaf(match_expr(arg_elts[idx])))
} }
@ -629,7 +629,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let mut macro_name: option<@~str> = none; let mut macro_name: option<@~str> = none;
let mut clauses: ~[@clause] = ~[]; let mut clauses: ~[@clause] = ~[];
for args.each |arg| { for args.each |arg| {
alt arg.node { match arg.node {
expr_vec(elts, mutbl) => { expr_vec(elts, mutbl) => {
if vec::len(elts) != 2u { if vec::len(elts) != 2u {
cx.span_fatal((*arg).span, cx.span_fatal((*arg).span,
@ -638,12 +638,12 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
} }
alt elts[0u].node { match elts[0u].node {
expr_mac(mac) => { expr_mac(mac) => {
alt mac.node { match mac.node {
mac_invoc(pth, invoc_arg, body) => { mac_invoc(pth, invoc_arg, body) => {
alt path_to_ident(pth) { match path_to_ident(pth) {
some(id) => alt macro_name { some(id) => match macro_name {
none => macro_name = some(id), none => macro_name = some(id),
some(other_id) => if id != other_id { some(other_id) => if id != other_id {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
@ -654,7 +654,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
none => cx.span_fatal(pth.span, none => cx.span_fatal(pth.span,
~"macro name must not be a path") ~"macro name must not be a path")
} }
let arg = alt invoc_arg { let arg = match invoc_arg {
some(arg) => arg, some(arg) => arg,
none => cx.span_fatal(mac.span, none => cx.span_fatal(mac.span,
~"macro must have arguments") ~"macro must have arguments")
@ -689,7 +689,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let ext = |a,b,c,d, move clauses| generic_extension(a,b,c,d,clauses); let ext = |a,b,c,d, move clauses| generic_extension(a,b,c,d,clauses);
return {ident: return {ident:
alt macro_name { match macro_name {
some(id) => id, some(id) => id,
none => cx.span_fatal(sp, ~"macro definition must have " + none => cx.span_fatal(sp, ~"macro definition must have " +
~"at least one clause") ~"at least one clause")
@ -699,12 +699,12 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
_body: ast::mac_body, _body: ast::mac_body,
clauses: ~[@clause]) -> @expr { clauses: ~[@clause]) -> @expr {
let arg = alt arg { let arg = match arg {
some(arg) => arg, some(arg) => arg,
none => cx.span_fatal(sp, ~"macro must have arguments") none => cx.span_fatal(sp, ~"macro must have arguments")
}; };
for clauses.each |c| { for clauses.each |c| {
alt use_selectors_to_bind(c.params, arg) { match use_selectors_to_bind(c.params, arg) {
some(bindings) => return transcribe(cx, bindings, c.body), some(bindings) => return transcribe(cx, bindings, c.body),
none => again none => again
} }

View file

@ -70,7 +70,7 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
let file = expr_to_str(cx, args[0], ~"#include_str requires a string"); let file = expr_to_str(cx, args[0], ~"#include_str requires a string");
let res = io::read_whole_file_str(res_rel_file(cx, sp, file)); let res = io::read_whole_file_str(res_rel_file(cx, sp, file));
alt res { match res {
result::ok(_) => { /* Continue. */ } result::ok(_) => { /* Continue. */ }
result::err(e) => { result::err(e) => {
cx.parse_sess().span_diagnostic.handler().fatal(e); cx.parse_sess().span_diagnostic.handler().fatal(e);
@ -86,7 +86,7 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
let file = expr_to_str(cx, args[0], ~"#include_bin requires a string"); let file = expr_to_str(cx, args[0], ~"#include_bin requires a string");
alt io::read_whole_file(res_rel_file(cx, sp, file)) { match io::read_whole_file(res_rel_file(cx, sp, file)) {
result::ok(src) => { result::ok(src) => {
let u8_exprs = vec::map(src, |char: u8| { let u8_exprs = vec::map(src, |char: u8| {
mk_u8(cx, sp, char) mk_u8(cx, sp, char)

View file

@ -31,7 +31,7 @@ enum matcher_pos_up { /* to break a circularity */
} }
fn is_some(&&mpu: matcher_pos_up) -> bool { fn is_some(&&mpu: matcher_pos_up) -> bool {
alt mpu { match mpu {
matcher_pos_up(none) => false, matcher_pos_up(none) => false,
_ => true _ => true
} }
@ -48,7 +48,7 @@ type matcher_pos = ~{
}; };
fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos { fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
alt mpu { match mpu {
matcher_pos_up(some(mp)) => copy mp, matcher_pos_up(some(mp)) => copy mp,
_ => fail _ => fail
} }
@ -56,7 +56,7 @@ fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
fn count_names(ms: &[matcher]) -> uint { fn count_names(ms: &[matcher]) -> uint {
vec::foldl(0u, ms, |ct, m| { vec::foldl(0u, ms, |ct, m| {
ct + alt m.node { ct + match m.node {
match_tok(_) => 0u, match_tok(_) => 0u,
match_seq(more_ms, _, _, _, _) => count_names(more_ms), match_seq(more_ms, _, _, _, _) => count_names(more_ms),
match_nonterminal(_,_,_) => 1u match_nonterminal(_,_,_) => 1u
@ -68,7 +68,7 @@ fn initial_matcher_pos(ms: ~[matcher], sep: option<token>, lo: uint)
-> matcher_pos { -> matcher_pos {
let mut match_idx_hi = 0u; let mut match_idx_hi = 0u;
for ms.each() |elt| { for ms.each() |elt| {
alt elt.node { match elt.node {
match_tok(_) => (), match_tok(_) => (),
match_seq(_,_,_,_,hi) => { match_seq(_,_,_,_,hi) => {
match_idx_hi = hi; // it is monotonic... match_idx_hi = hi; // it is monotonic...
@ -113,7 +113,7 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match])
-> hashmap<ident,@named_match> { -> hashmap<ident,@named_match> {
fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match], fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match],
ret_val: hashmap<ident, @named_match>) { ret_val: hashmap<ident, @named_match>) {
alt m { match m {
{node: match_tok(_), span: _} => (), {node: match_tok(_), span: _} => (),
{node: match_seq(more_ms, _, _, _, _), span: _} => { {node: match_seq(more_ms, _, _, _, _), span: _} => {
for more_ms.each() |next_m| { n_rec(p_s, next_m, res, ret_val) }; for more_ms.each() |next_m| { n_rec(p_s, next_m, res, ret_val) };
@ -139,7 +139,7 @@ enum parse_result {
fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
ms: ~[matcher]) -> hashmap<ident, @named_match> { ms: ~[matcher]) -> hashmap<ident, @named_match> {
alt parse(sess, cfg, rdr, ms) { match parse(sess, cfg, rdr, ms) {
success(m) => m, success(m) => m,
failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str) failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str)
} }
@ -202,7 +202,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
// can we go around again? // can we go around again?
// the *_t vars are workarounds for the lack of unary move // the *_t vars are workarounds for the lack of unary move
alt copy ei.sep { match copy ei.sep {
some(t) if idx == len => { // we need a separator some(t) if idx == len => { // we need a separator
if tok == t { //pass the separator if tok == t { //pass the separator
let ei_t <- ei; let ei_t <- ei;
@ -220,7 +220,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
vec::push(eof_eis, ei); vec::push(eof_eis, ei);
} }
} else { } else {
alt copy ei.elts[idx].node { match copy ei.elts[idx].node {
/* need to descend into sequence */ /* need to descend into sequence */
match_seq(matchers, sep, zero_ok, match_seq(matchers, sep, zero_ok,
match_idx_lo, match_idx_hi) => { match_idx_lo, match_idx_hi) => {
@ -270,7 +270,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
if (bb_eis.len() > 0u && next_eis.len() > 0u) if (bb_eis.len() > 0u && next_eis.len() > 0u)
|| bb_eis.len() > 1u { || bb_eis.len() > 1u {
let nts = str::connect(vec::map(bb_eis, |ei| { let nts = str::connect(vec::map(bb_eis, |ei| {
alt ei.elts[ei.idx].node { match ei.elts[ei.idx].node {
match_nonterminal(bind,name,_) => { match_nonterminal(bind,name,_) => {
fmt!{"%s ('%s')", *name, *bind} fmt!{"%s ('%s')", *name, *bind}
} }
@ -293,7 +293,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE); let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let ei = vec::pop(bb_eis); let ei = vec::pop(bb_eis);
alt ei.elts[ei.idx].node { match ei.elts[ei.idx].node {
match_nonterminal(_, name, idx) => { match_nonterminal(_, name, idx) => {
ei.matches[idx].push(@matched_nonterminal( ei.matches[idx].push(@matched_nonterminal(
parse_nt(rust_parser, *name))); parse_nt(rust_parser, *name)));
@ -318,8 +318,8 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
} }
fn parse_nt(p: parser, name: ~str) -> nonterminal { fn parse_nt(p: parser, name: ~str) -> nonterminal {
alt name { match name {
~"item" => alt p.parse_item(~[]) { ~"item" => match p.parse_item(~[]) {
some(i) => token::nt_item(i), some(i) => token::nt_item(i),
none => p.fatal(~"expected an item keyword") none => p.fatal(~"expected an item keyword")
} }
@ -329,7 +329,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal {
~"expr" => token::nt_expr(p.parse_expr()), ~"expr" => token::nt_expr(p.parse_expr()),
~"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), ~"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
// this could be handled like a token, since it is one // this could be handled like a token, since it is one
~"ident" => alt copy p.token { ~"ident" => match copy p.token {
token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) } token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
_ => p.fatal(~"expected ident, found " _ => p.fatal(~"expected ident, found "
+ token::to_str(*p.reader.interner(), copy p.token)) + token::to_str(*p.reader.interner(), copy p.token))

View file

@ -37,11 +37,11 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
arg_reader as reader, argument_gram); arg_reader as reader, argument_gram);
// Extract the arguments: // Extract the arguments:
let lhses:~[@named_match] = alt argument_map.get(@~"lhs") { let lhses:~[@named_match] = match argument_map.get(@~"lhs") {
@matched_seq(s, sp) => s, @matched_seq(s, sp) => s,
_ => cx.span_bug(sp, ~"wrong-structured lhs") _ => cx.span_bug(sp, ~"wrong-structured lhs")
}; };
let rhses:~[@named_match] = alt argument_map.get(@~"rhs") { let rhses:~[@named_match] = match argument_map.get(@~"rhs") {
@matched_seq(s, sp) => s, @matched_seq(s, sp) => s,
_ => cx.span_bug(sp, ~"wrong-structured rhs") _ => cx.span_bug(sp, ~"wrong-structured rhs")
}; };
@ -58,13 +58,14 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
let itr = cx.parse_sess().interner; let itr = cx.parse_sess().interner;
for lhses.eachi() |i, lhs| { // try each arm's matchers for lhses.eachi() |i, lhs| { // try each arm's matchers
alt lhs { match lhs {
@matched_nonterminal(nt_matchers(mtcs)) => { @matched_nonterminal(nt_matchers(mtcs)) => {
// `none` is because we're not interpolating // `none` is because we're not interpolating
let arg_rdr = new_tt_reader(s_d, itr, none, arg) as reader; let arg_rdr = new_tt_reader(s_d, itr, none, arg) as reader;
alt parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) { match parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) {
success(named_matches) => { success(named_matches) => {
let rhs = alt rhses[i] { // okay, what's your transcriber? let rhs = match rhses[i] {
// okay, what's your transcriber?
@matched_nonterminal(nt_tt(@tt)) => tt, @matched_nonterminal(nt_tt(@tt)) => tt,
_ => cx.span_bug(sp, ~"bad thing in rhs") _ => cx.span_bug(sp, ~"bad thing in rhs")
}; };

View file

@ -46,7 +46,7 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>,
let r = @{sp_diag: sp_diag, interner: itr, let r = @{sp_diag: sp_diag, interner: itr,
mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false, mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false,
sep: none, up: tt_frame_up(option::none)}, sep: none, up: tt_frame_up(option::none)},
interpolations: alt interp { /* just a convienience */ interpolations: match interp { /* just a convienience */
none => std::map::box_str_hash::<@named_match>(), none => std::map::box_str_hash::<@named_match>(),
some(x) => x some(x) => x
}, },
@ -61,7 +61,7 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>,
pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame { pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame {
@{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted, @{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted,
sep: f.sep, up: alt f.up { sep: f.sep, up: match f.up {
tt_frame_up(some(up_frame)) => { tt_frame_up(some(up_frame)) => {
tt_frame_up(some(dup_tt_frame(up_frame))) tt_frame_up(some(dup_tt_frame(up_frame)))
} }
@ -82,7 +82,7 @@ pure fn dup_tt_reader(&&r: tt_reader) -> tt_reader {
pure fn lookup_cur_matched_by_matched(r: tt_reader, pure fn lookup_cur_matched_by_matched(r: tt_reader,
start: @named_match) -> @named_match { start: @named_match) -> @named_match {
pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match { pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match {
alt *ad { match *ad {
matched_nonterminal(_) => { matched_nonterminal(_) => {
// end of the line; duplicate henceforth // end of the line; duplicate henceforth
ad ad
@ -102,10 +102,10 @@ enum lis {
fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis { fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis {
fn lis_merge(lhs: lis, rhs: lis) -> lis { fn lis_merge(lhs: lis, rhs: lis) -> lis {
alt lhs { match lhs {
lis_unconstrained => rhs, lis_unconstrained => rhs,
lis_contradiction(_) => lhs, lis_contradiction(_) => lhs,
lis_constraint(l_len, l_id) => alt rhs { lis_constraint(l_len, l_id) => match rhs {
lis_unconstrained => lhs, lis_unconstrained => lhs,
lis_contradiction(_) => rhs, lis_contradiction(_) => rhs,
lis_constraint(r_len, _) if l_len == r_len => lhs, lis_constraint(r_len, _) if l_len == r_len => lhs,
@ -117,13 +117,13 @@ fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis {
} }
} }
} }
alt t { match t {
tt_delim(tts) | tt_seq(_, tts, _, _) => { tt_delim(tts) | tt_seq(_, tts, _, _) => {
vec::foldl(lis_unconstrained, tts, {|lis, tt| vec::foldl(lis_unconstrained, tts, {|lis, tt|
lis_merge(lis, lockstep_iter_size(tt, r)) }) lis_merge(lis, lockstep_iter_size(tt, r)) })
} }
tt_tok(*) => lis_unconstrained, tt_tok(*) => lis_unconstrained,
tt_nonterminal(_, name) => alt *lookup_cur_matched(r, name) { tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) {
matched_nonterminal(_) => lis_unconstrained, matched_nonterminal(_) => lis_unconstrained,
matched_seq(ads, _) => lis_constraint(ads.len(), name) matched_seq(ads, _) => lis_constraint(ads.len(), name)
} }
@ -138,7 +138,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
if ! r.cur.dotdotdoted if ! r.cur.dotdotdoted
|| r.repeat_idx.last() == r.repeat_len.last() - 1 { || r.repeat_idx.last() == r.repeat_len.last() - 1 {
alt r.cur.up { match r.cur.up {
tt_frame_up(none) => { tt_frame_up(none) => {
r.cur_tok = EOF; r.cur_tok = EOF;
return ret_val; return ret_val;
@ -156,7 +156,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
} else { /* repeat */ } else { /* repeat */
r.cur.idx = 0u; r.cur.idx = 0u;
r.repeat_idx[r.repeat_idx.len() - 1u] += 1u; r.repeat_idx[r.repeat_idx.len() - 1u] += 1u;
alt r.cur.sep { match r.cur.sep {
some(tk) => { some(tk) => {
r.cur_tok = tk; /* repeat same span, I guess */ r.cur_tok = tk; /* repeat same span, I guess */
return ret_val; return ret_val;
@ -167,7 +167,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
} }
loop { /* because it's easiest, this handles `tt_delim` not starting loop { /* because it's easiest, this handles `tt_delim` not starting
with a `tt_tok`, even though it won't happen */ with a `tt_tok`, even though it won't happen */
alt r.cur.readme[r.cur.idx] { match r.cur.readme[r.cur.idx] {
tt_delim(tts) => { tt_delim(tts) => {
r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false, r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false,
sep: none, up: tt_frame_up(option::some(r.cur)) }; sep: none, up: tt_frame_up(option::some(r.cur)) };
@ -179,7 +179,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
return ret_val; return ret_val;
} }
tt_seq(sp, tts, sep, zerok) => { tt_seq(sp, tts, sep, zerok) => {
alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) { match lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) {
lis_unconstrained => { lis_unconstrained => {
r.sp_diag.span_fatal( r.sp_diag.span_fatal(
sp, /* blame macro writer */ sp, /* blame macro writer */
@ -212,7 +212,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
} }
// FIXME #2887: think about span stuff here // FIXME #2887: think about span stuff here
tt_nonterminal(sp, ident) => { tt_nonterminal(sp, ident) => {
alt *lookup_cur_matched(r, ident) { match *lookup_cur_matched(r, ident) {
/* sidestep the interpolation tricks for ident because /* sidestep the interpolation tricks for ident because
(a) idents can be in lots of places, so it'd be a pain (a) idents can be in lots of places, so it'd be a pain
(b) we actually can, since it's a token. */ (b) we actually can, since it's a token. */

View file

@ -80,7 +80,7 @@ type ast_fold_precursor = @{
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive //used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item { fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
return @{node: return @{node:
alt mi.node { match mi.node {
meta_word(id) => meta_word(fld.fold_ident(id)), meta_word(id) => meta_word(fld.fold_ident(id)),
meta_list(id, mis) => { meta_list(id, mis) => {
let fold_meta_item = |x|fold_meta_item_(x, fld); let fold_meta_item = |x|fold_meta_item_(x, fld);
@ -112,7 +112,7 @@ fn fold_arg_(a: arg, fld: ast_fold) -> arg {
//used in noop_fold_expr, and possibly elsewhere in the future //used in noop_fold_expr, and possibly elsewhere in the future
fn fold_mac_(m: mac, fld: ast_fold) -> mac { fn fold_mac_(m: mac, fld: ast_fold) -> mac {
return {node: return {node:
alt m.node { match m.node {
mac_invoc(pth, arg, body) => { mac_invoc(pth, arg, body) => {
mac_invoc(fld.fold_path(pth), mac_invoc(fld.fold_path(pth),
option::map(arg, |x| fld.fold_expr(x)), body) option::map(arg, |x| fld.fold_expr(x)), body)
@ -133,7 +133,7 @@ fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
} }
fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound { fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
alt tpb { match tpb {
bound_copy | bound_send | bound_const | bound_owned => tpb, bound_copy | bound_send | bound_const | bound_owned => tpb,
bound_trait(ty) => bound_trait(fld.fold_ty(ty)) bound_trait(ty) => bound_trait(fld.fold_ty(ty))
} }
@ -163,7 +163,7 @@ fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) -> fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
crate_directive_ { crate_directive_ {
return alt cd { return match cd {
cdir_src_mod(id, attrs) => { cdir_src_mod(id, attrs) => {
cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs) cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs)
} }
@ -190,7 +190,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
return @{ident: fld.fold_ident(ni.ident), return @{ident: fld.fold_ident(ni.ident),
attrs: vec::map(ni.attrs, fold_attribute), attrs: vec::map(ni.attrs, fold_attribute),
node: node:
alt ni.node { match ni.node {
foreign_item_fn(fdec, typms) => { foreign_item_fn(fdec, typms) => {
foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg), foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
output: fld.fold_ty(fdec.output), output: fld.fold_ty(fdec.output),
@ -216,7 +216,7 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> option<@item> {
fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold) fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
-> @class_member { -> @class_member {
@{node: alt ci.node { @{node: match ci.node {
instance_var(ident, t, cm, id, p) => { instance_var(ident, t, cm, id, p) => {
instance_var(/* FIXME (#2543) */ copy ident, instance_var(/* FIXME (#2543) */ copy ident,
fld.fold_ty(t), cm, id, p) fld.fold_ty(t), cm, id, p)
@ -227,7 +227,7 @@ fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
} }
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
return alt i { return match i {
item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)), item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
item_fn(decl, typms, body) => { item_fn(decl, typms, body) => {
item_fn(fold_fn_decl(decl, fld), item_fn(fold_fn_decl(decl, fld),
@ -244,7 +244,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
} }
item_class(typms, traits, items, m_ctor, m_dtor) => { item_class(typms, traits, items, m_ctor, m_dtor) => {
let resulting_optional_constructor; let resulting_optional_constructor;
alt m_ctor { match m_ctor {
none => { none => {
resulting_optional_constructor = none; resulting_optional_constructor = none;
} }
@ -319,7 +319,7 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
} }
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
return alt s { return match s {
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)), stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)), stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)) stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid))
@ -333,7 +333,7 @@ fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
} }
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
return alt p { return match p {
pat_wild => pat_wild, pat_wild => pat_wild,
pat_ident(binding_mode, pth, sub) => { pat_ident(binding_mode, pth, sub) => {
pat_ident(binding_mode, pat_ident(binding_mode,
@ -364,9 +364,9 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
} }
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ { fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
alt d { match d {
decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(x))), decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(x))),
decl_item(it) => alt fld.fold_item(it) { decl_item(it) => match fld.fold_item(it) {
some(it_folded) => decl_item(it_folded), some(it_folded) => decl_item(it_folded),
none => decl_local(~[]) none => decl_local(~[])
} }
@ -393,7 +393,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
let fold_mac = |x| fold_mac_(x, fld); let fold_mac = |x| fold_mac_(x, fld);
return alt e { return match e {
expr_vstore(e, v) => { expr_vstore(e, v) => {
expr_vstore(fld.fold_expr(e), v) expr_vstore(fld.fold_expr(e), v)
} }
@ -496,7 +496,7 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
mt: fold_mt(f.node.mt, fld)}, mt: fold_mt(f.node.mt, fld)},
span: fld.new_span(f.span)} span: fld.new_span(f.span)}
} }
alt t { match t {
ty_nil | ty_bot | ty_infer => copy t, ty_nil | ty_bot | ty_infer => copy t,
ty_box(mt) => ty_box(fold_mt(mt, fld)), ty_box(mt) => ty_box(fold_mt(mt, fld)),
ty_uniq(mt) => ty_uniq(fold_mt(mt, fld)), ty_uniq(mt) => ty_uniq(fold_mt(mt, fld)),
@ -533,7 +533,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
let fold_attribute = |x| fold_attribute_(x, fld); let fold_attribute = |x| fold_attribute_(x, fld);
let attrs = vec::map(v.attrs, fold_attribute); let attrs = vec::map(v.attrs, fold_attribute);
let de = alt v.disr_expr { let de = match v.disr_expr {
some(e) => some(fld.fold_expr(e)), some(e) => some(fld.fold_expr(e)),
none => none none => none
}; };
@ -560,7 +560,7 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
ty: fld.fold_ty(l.ty), ty: fld.fold_ty(l.ty),
pat: fld.fold_pat(l.pat), pat: fld.fold_pat(l.pat),
init: init:
alt l.init { match l.init {
option::none::<initializer> => l.init, option::none::<initializer> => l.init,
option::some::<initializer>(init) => { option::some::<initializer>(init) => {
option::some::<initializer>({op: init.op, option::some::<initializer>({op: init.op,
@ -635,7 +635,7 @@ impl of ast_fold for ast_fold_precursor {
return self.fold_item(i, self as ast_fold); return self.fold_item(i, self as ast_fold);
} }
fn fold_class_item(&&ci: @class_member) -> @class_member { fn fold_class_item(&&ci: @class_member) -> @class_member {
@{node: alt ci.node { @{node: match ci.node {
instance_var(nm, t, mt, id, p) => { instance_var(nm, t, mt, id, p) => {
instance_var(/* FIXME (#2543) */ copy nm, instance_var(/* FIXME (#2543) */ copy nm,
(self as ast_fold).fold_ty(t), mt, id, p) (self as ast_fold).fold_ty(t), mt, id, p)

View file

@ -189,7 +189,7 @@ fn new_parser_etc_from_file(sess: parse_sess, cfg: ast::crate_cfg,
+path: ~str, ftype: parser::file_type) -> +path: ~str, ftype: parser::file_type) ->
(parser, string_reader) { (parser, string_reader) {
let res = io::read_whole_file_str(path); let res = io::read_whole_file_str(path);
alt res { match res {
result::ok(_) => { /* Continue. */ } result::ok(_) => { /* Continue. */ }
result::err(e) => sess.span_diagnostic.handler().fatal(e) result::err(e) => sess.span_diagnostic.handler().fatal(e)
} }

View file

@ -29,7 +29,7 @@ impl parser_attr of parser_attr for parser {
-> attr_or_ext -> attr_or_ext
{ {
let expect_item_next = vec::is_not_empty(first_item_attrs); let expect_item_next = vec::is_not_empty(first_item_attrs);
alt self.token { match self.token {
token::POUND => { token::POUND => {
let lo = self.span.lo; let lo = self.span.lo;
if self.look_ahead(1u) == token::LBRACKET { if self.look_ahead(1u) == token::LBRACKET {
@ -57,7 +57,7 @@ impl parser_attr of parser_attr for parser {
fn parse_outer_attributes() -> ~[ast::attribute] { fn parse_outer_attributes() -> ~[ast::attribute] {
let mut attrs: ~[ast::attribute] = ~[]; let mut attrs: ~[ast::attribute] = ~[];
loop { loop {
alt copy self.token { match copy self.token {
token::POUND => { token::POUND => {
if self.look_ahead(1u) != token::LBRACKET { if self.look_ahead(1u) != token::LBRACKET {
break; break;
@ -106,7 +106,7 @@ impl parser_attr of parser_attr for parser {
let mut inner_attrs: ~[ast::attribute] = ~[]; let mut inner_attrs: ~[ast::attribute] = ~[];
let mut next_outer_attrs: ~[ast::attribute] = ~[]; let mut next_outer_attrs: ~[ast::attribute] = ~[];
loop { loop {
alt copy self.token { match copy self.token {
token::POUND => { token::POUND => {
if self.look_ahead(1u) != token::LBRACKET { if self.look_ahead(1u) != token::LBRACKET {
// This is an extension // This is an extension
@ -146,7 +146,7 @@ impl parser_attr of parser_attr for parser {
fn parse_meta_item() -> @ast::meta_item { fn parse_meta_item() -> @ast::meta_item {
let lo = self.span.lo; let lo = self.span.lo;
let ident = self.parse_ident(); let ident = self.parse_ident();
alt self.token { match self.token {
token::EQ => { token::EQ => {
self.bump(); self.bump();
let lit = self.parse_lit(); let lit = self.parse_lit();
@ -172,7 +172,7 @@ impl parser_attr of parser_attr for parser {
} }
fn parse_optional_meta() -> ~[@ast::meta_item] { fn parse_optional_meta() -> ~[@ast::meta_item] {
alt self.token { match self.token {
token::LPAREN => return self.parse_meta_seq(), token::LPAREN => return self.parse_meta_seq(),
_ => return ~[] _ => return ~[]
} }

View file

@ -5,7 +5,7 @@
import ast_util::operator_prec; import ast_util::operator_prec;
fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
alt e.node { match e.node {
ast::expr_if(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_) ast::expr_if(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_)
| ast::expr_while(_, _) | ast::expr_loop(_) | ast::expr_while(_, _) | ast::expr_loop(_)
| ast::expr_call(_, _, true) => false, | ast::expr_call(_, _, true) => false,
@ -14,9 +14,9 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
} }
fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
alt stmt.node { match stmt.node {
ast::stmt_decl(d, _) => { ast::stmt_decl(d, _) => {
return alt d.node { return match d.node {
ast::decl_local(_) => true, ast::decl_local(_) => true,
ast::decl_item(_) => false ast::decl_item(_) => false
} }
@ -31,7 +31,7 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
} }
fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool { fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool {
alt expr.node { match expr.node {
ast::expr_binary(op, _, _) => operator_prec(op) < outer_prec, ast::expr_binary(op, _, _) => operator_prec(op) < outer_prec,
ast::expr_cast(_, _) => parse::prec::as_prec < outer_prec, ast::expr_cast(_, _) => parse::prec::as_prec < outer_prec,
// This may be too conservative in some cases // This may be too conservative in some cases
@ -47,8 +47,8 @@ fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool {
} }
fn ends_in_lit_int(ex: @ast::expr) -> bool { fn ends_in_lit_int(ex: @ast::expr) -> bool {
alt ex.node { match ex.node {
ast::expr_lit(node) => alt node { ast::expr_lit(node) => match node {
@{node: ast::lit_int(_, ast::ty_i), _} @{node: ast::lit_int(_, ast::ty_i), _}
| @{node: ast::lit_int_unsuffixed(_), _} => true, | @{node: ast::lit_int_unsuffixed(_), _} => true,
_ => false _ => false
@ -60,7 +60,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
ast::expr_log(_, _, sub) | ast::expr_assert(sub) => { ast::expr_log(_, _, sub) | ast::expr_assert(sub) => {
ends_in_lit_int(sub) ends_in_lit_int(sub)
} }
ast::expr_fail(osub) | ast::expr_ret(osub) => alt osub { ast::expr_fail(osub) | ast::expr_ret(osub) => match osub {
some(ex) => ends_in_lit_int(ex), some(ex) => ends_in_lit_int(ex),
_ => false _ => false
} }

View file

@ -84,7 +84,7 @@ impl parser_common of parser_common for parser {
} }
fn parse_ident() -> ast::ident { fn parse_ident() -> ast::ident {
alt copy self.token { match copy self.token {
token::IDENT(i, _) => { self.bump(); return self.get_str(i); } token::IDENT(i, _) => { self.bump(); return self.get_str(i); }
token::INTERPOLATED(token::nt_ident(*)) => { self.bug( token::INTERPOLATED(token::nt_ident(*)) => { self.bug(
~"ident interpolation not converted to real token"); } ~"ident interpolation not converted to real token"); }
@ -118,7 +118,7 @@ impl parser_common of parser_common for parser {
} }
fn token_is_word(word: ~str, ++tok: token::token) -> bool { fn token_is_word(word: ~str, ++tok: token::token) -> bool {
alt tok { match tok {
token::IDENT(sid, false) => { word == *self.get_str(sid) } token::IDENT(sid, false) => { word == *self.get_str(sid) }
_ => { false } _ => { false }
} }
@ -134,7 +134,7 @@ impl parser_common of parser_common for parser {
} }
fn is_any_keyword(tok: token::token) -> bool { fn is_any_keyword(tok: token::token) -> bool {
alt tok { match tok {
token::IDENT(sid, false) => { token::IDENT(sid, false) => {
self.keywords.contains_key_ref(self.get_str(sid)) self.keywords.contains_key_ref(self.get_str(sid))
} }
@ -146,7 +146,7 @@ impl parser_common of parser_common for parser {
self.require_keyword(word); self.require_keyword(word);
let mut bump = false; let mut bump = false;
let val = alt self.token { let val = match self.token {
token::IDENT(sid, false) => { token::IDENT(sid, false) => {
if word == *self.get_str(sid) { if word == *self.get_str(sid) {
bump = true; bump = true;
@ -173,7 +173,7 @@ impl parser_common of parser_common for parser {
} }
fn check_restricted_keywords() { fn check_restricted_keywords() {
alt self.token { match self.token {
token::IDENT(_, false) => { token::IDENT(_, false) => {
let w = token_to_str(self.reader, self.token); let w = token_to_str(self.reader, self.token);
self.check_restricted_keywords_(w); self.check_restricted_keywords_(w);
@ -209,7 +209,7 @@ impl parser_common of parser_common for parser {
let mut v = ~[]; let mut v = ~[];
while self.token != token::GT while self.token != token::GT
&& self.token != token::BINOP(token::SHR) { && self.token != token::BINOP(token::SHR) {
alt sep { match sep {
some(t) => { some(t) => {
if first { first = false; } if first { first = false; }
else { self.expect(t); } else { self.expect(t); }
@ -253,7 +253,7 @@ impl parser_common of parser_common for parser {
let mut first: bool = true; let mut first: bool = true;
let mut v: ~[T] = ~[]; let mut v: ~[T] = ~[];
while self.token != ket { while self.token != ket {
alt sep.sep { match sep.sep {
some(t) => { some(t) => {
if first { first = false; } if first { first = false; }
else { self.expect(t); } else { self.expect(t); }

View file

@ -47,7 +47,7 @@ fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>)
-> (~[@ast::view_item], ~[@ast::item], ~[ast::attribute]) { -> (~[@ast::view_item], ~[@ast::item], ~[ast::attribute]) {
fn companion_file(+prefix: ~str, suffix: option<~str>) -> ~str { fn companion_file(+prefix: ~str, suffix: option<~str>) -> ~str {
return alt suffix { return match suffix {
option::some(s) => path::connect(prefix, s), option::some(s) => path::connect(prefix, s),
option::none => prefix option::none => prefix
} + ~".rs"; } + ~".rs";
@ -56,7 +56,7 @@ fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>)
fn file_exists(path: ~str) -> bool { fn file_exists(path: ~str) -> bool {
// Crude, but there's no lib function for this and I'm not // Crude, but there's no lib function for this and I'm not
// up to writing it just now // up to writing it just now
alt io::file_reader(path) { match io::file_reader(path) {
result::ok(_) => true, result::ok(_) => true,
result::err(_) => false result::err(_) => false
} }
@ -79,7 +79,7 @@ fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>)
} }
fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str { fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str {
alt ::attr::first_attr_value_str_by_name(attrs, ~"path") { match ::attr::first_attr_value_str_by_name(attrs, ~"path") {
some(d) => return d, some(d) => return d,
none => return id none => return id
} }
@ -88,7 +88,7 @@ fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str {
fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: ~str, fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: ~str,
&view_items: ~[@ast::view_item], &view_items: ~[@ast::view_item],
&items: ~[@ast::item]) { &items: ~[@ast::item]) {
alt cdir.node { match cdir.node {
ast::cdir_src_mod(id, attrs) => { ast::cdir_src_mod(id, attrs) => {
let file_path = cdir_path_opt(@(*id + ~".rs"), attrs); let file_path = cdir_path_opt(@(*id + ~".rs"), attrs);
let full_path = let full_path =

View file

@ -206,7 +206,7 @@ fn consume_whitespace_and_comments(rdr: string_reader)
fn consume_any_line_comment(rdr: string_reader) fn consume_any_line_comment(rdr: string_reader)
-> option<{tok: token::token, sp: span}> { -> option<{tok: token::token, sp: span}> {
if rdr.curr == '/' { if rdr.curr == '/' {
alt nextch(rdr) { match nextch(rdr) {
'/' => { '/' => {
bump(rdr); bump(rdr);
bump(rdr); bump(rdr);
@ -313,7 +313,7 @@ fn scan_digits(rdr: string_reader, radix: uint) -> ~str {
loop { loop {
let c = rdr.curr; let c = rdr.curr;
if c == '_' { bump(rdr); again; } if c == '_' { bump(rdr); again; }
alt char::to_digit(c, radix) { match char::to_digit(c, radix) {
some(d) => { some(d) => {
str::push_char(rslt, c); str::push_char(rslt, c);
bump(rdr); bump(rdr);
@ -371,7 +371,7 @@ fn scan_number(c: char, rdr: string_reader) -> token::token {
rdr.fatal(~"no valid digits found for number"); rdr.fatal(~"no valid digits found for number");
} }
let parsed = option::get(u64::from_str_radix(num_str, base as u64)); let parsed = option::get(u64::from_str_radix(num_str, base as u64));
alt tp { match tp {
either::left(t) => return token::LIT_INT(parsed as i64, t), either::left(t) => return token::LIT_INT(parsed as i64, t),
either::right(t) => return token::LIT_UINT(parsed, t) either::right(t) => return token::LIT_UINT(parsed, t)
} }
@ -383,7 +383,7 @@ fn scan_number(c: char, rdr: string_reader) -> token::token {
let dec_part = scan_digits(rdr, 10u); let dec_part = scan_digits(rdr, 10u);
num_str += ~"." + dec_part; num_str += ~"." + dec_part;
} }
alt scan_exponent(rdr) { match scan_exponent(rdr) {
some(s) => { some(s) => {
is_float = true; is_float = true;
num_str += s; num_str += s;
@ -472,7 +472,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
return token::BINOPEQ(op); return token::BINOPEQ(op);
} else { return token::BINOP(op); } } else { return token::BINOP(op); }
} }
alt c { match c {
@ -539,12 +539,12 @@ fn next_token_inner(rdr: string_reader) -> token::token {
} }
'<' => { '<' => {
bump(rdr); bump(rdr);
alt rdr.curr { match rdr.curr {
'=' => { bump(rdr); return token::LE; } '=' => { bump(rdr); return token::LE; }
'<' => { return binop(rdr, token::SHL); } '<' => { return binop(rdr, token::SHL); }
'-' => { '-' => {
bump(rdr); bump(rdr);
alt rdr.curr { match rdr.curr {
'>' => { bump(rdr); return token::DARROW; } '>' => { bump(rdr); return token::DARROW; }
_ => { return token::LARROW; } _ => { return token::LARROW; }
} }
@ -554,7 +554,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
} }
'>' => { '>' => {
bump(rdr); bump(rdr);
alt rdr.curr { match rdr.curr {
'=' => { bump(rdr); return token::GE; } '=' => { bump(rdr); return token::GE; }
'>' => { return binop(rdr, token::SHR); } '>' => { return binop(rdr, token::SHR); }
_ => { return token::GT; } _ => { return token::GT; }
@ -567,7 +567,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
if c2 == '\\' { if c2 == '\\' {
let escaped = rdr.curr; let escaped = rdr.curr;
bump(rdr); bump(rdr);
alt escaped { match escaped {
'n' => { c2 = '\n'; } 'n' => { c2 = '\n'; }
'r' => { c2 = '\r'; } 'r' => { c2 = '\r'; }
't' => { c2 = '\t'; } 't' => { c2 = '\t'; }
@ -599,11 +599,11 @@ fn next_token_inner(rdr: string_reader) -> token::token {
let ch = rdr.curr; let ch = rdr.curr;
bump(rdr); bump(rdr);
alt ch { match ch {
'\\' => { '\\' => {
let escaped = rdr.curr; let escaped = rdr.curr;
bump(rdr); bump(rdr);
alt escaped { match escaped {
'n' => str::push_char(accum_str, '\n'), 'n' => str::push_char(accum_str, '\n'),
'r' => str::push_char(accum_str, '\r'), 'r' => str::push_char(accum_str, '\r'),
't' => str::push_char(accum_str, '\t'), 't' => str::push_char(accum_str, '\t'),
@ -646,7 +646,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
} else { return binop(rdr, token::AND); } } else { return binop(rdr, token::AND); }
} }
'|' => { '|' => {
alt nextch(rdr) { match nextch(rdr) {
'|' => { bump(rdr); bump(rdr); return token::OROR; } '|' => { bump(rdr); bump(rdr); return token::OROR; }
_ => { return binop(rdr, token::OR); } _ => { return binop(rdr, token::OR); }
} }

View file

@ -107,7 +107,7 @@ type item_info = (ident, item_, option<~[attribute]>);
The important thing is to make sure that lookahead doesn't balk The important thing is to make sure that lookahead doesn't balk
at INTERPOLATED tokens */ at INTERPOLATED tokens */
macro_rules! maybe_whole_expr { macro_rules! maybe_whole_expr {
{$p:expr} => { alt copy $p.token { {$p:expr} => { match copy $p.token {
INTERPOLATED(token::nt_expr(e)) => { INTERPOLATED(token::nt_expr(e)) => {
$p.bump(); $p.bump();
return pexpr(e); return pexpr(e);
@ -122,19 +122,19 @@ macro_rules! maybe_whole_expr {
} }
macro_rules! maybe_whole { macro_rules! maybe_whole {
{$p:expr, $constructor:ident} => { alt copy $p.token { {$p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return x; } INTERPOLATED(token::$constructor(x)) => { $p.bump(); return x; }
_ => () _ => ()
}} ; }} ;
{deref $p:expr, $constructor:ident} => { alt copy $p.token { {deref $p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return *x; } INTERPOLATED(token::$constructor(x)) => { $p.bump(); return *x; }
_ => () _ => ()
}} ; }} ;
{some $p:expr, $constructor:ident} => { alt copy $p.token { {some $p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return some(x); } INTERPOLATED(token::$constructor(x)) => { $p.bump(); return some(x); }
_ => () _ => ()
}} ; }} ;
{pair_empty $p:expr, $constructor:ident} => { alt copy $p.token { {pair_empty $p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return (~[], x); } INTERPOLATED(token::$constructor(x)) => { $p.bump(); return (~[], x); }
_ => () _ => ()
}} }}
@ -284,7 +284,7 @@ class parser {
debug!{"parse_trait_methods(): trait method signature ends in \ debug!{"parse_trait_methods(): trait method signature ends in \
`%s`", `%s`",
token_to_str(p.reader, p.token)}; token_to_str(p.reader, p.token)};
alt p.token { match p.token {
token::SEMI => { token::SEMI => {
p.bump(); p.bump();
debug!{"parse_trait_methods(): parsing required method"}; debug!{"parse_trait_methods(): parsing required method"};
@ -356,7 +356,7 @@ class parser {
} }
fn region_from_name(s: option<@~str>) -> @region { fn region_from_name(s: option<@~str>) -> @region {
let r = alt s { let r = match s {
some (string) => re_named(string), some (string) => re_named(string),
none => re_anon none => re_anon
}; };
@ -368,7 +368,7 @@ class parser {
fn parse_region() -> @region { fn parse_region() -> @region {
self.expect(token::BINOP(token::AND)); self.expect(token::BINOP(token::AND));
alt copy self.token { match copy self.token {
token::IDENT(sid, _) => { token::IDENT(sid, _) => {
self.bump(); self.bump();
let n = self.get_str(sid); let n = self.get_str(sid);
@ -383,7 +383,7 @@ class parser {
// Parses something like "&x/" (note the trailing slash) // Parses something like "&x/" (note the trailing slash)
fn parse_region_with_sep() -> @region { fn parse_region_with_sep() -> @region {
let name = let name =
alt copy self.token { match copy self.token {
token::IDENT(sid, _) => { token::IDENT(sid, _) => {
if self.look_ahead(1u) == token::BINOP(token::SLASH) { if self.look_ahead(1u) == token::BINOP(token::SLASH) {
self.bump(); self.bump(); self.bump(); self.bump();
@ -402,7 +402,7 @@ class parser {
let lo = self.span.lo; let lo = self.span.lo;
alt self.maybe_parse_dollar_mac() { match self.maybe_parse_dollar_mac() {
some(e) => { some(e) => {
return @{id: self.get_id(), return @{id: self.get_id(),
node: ty_mac(spanned(lo, self.span.hi, e)), node: ty_mac(spanned(lo, self.span.hi, e)),
@ -471,7 +471,7 @@ class parser {
let sp = mk_sp(lo, self.last_span.hi); let sp = mk_sp(lo, self.last_span.hi);
return @{id: self.get_id(), return @{id: self.get_id(),
node: alt self.maybe_parse_fixed_vstore() { node: match self.maybe_parse_fixed_vstore() {
// Consider a fixed vstore suffix (/N or /_) // Consider a fixed vstore suffix (/N or /_)
none => t, none => t,
some(v) => { some(v) => {
@ -542,11 +542,11 @@ class parser {
} }
fn maybe_parse_dollar_mac() -> option<mac_> { fn maybe_parse_dollar_mac() -> option<mac_> {
alt copy self.token { match copy self.token {
token::DOLLAR => { token::DOLLAR => {
let lo = self.span.lo; let lo = self.span.lo;
self.bump(); self.bump();
alt copy self.token { match copy self.token {
token::LIT_INT_UNSUFFIXED(num) => { token::LIT_INT_UNSUFFIXED(num) => {
self.bump(); self.bump();
some(mac_var(num as uint)) some(mac_var(num as uint))
@ -570,7 +570,7 @@ class parser {
fn maybe_parse_fixed_vstore() -> option<option<uint>> { fn maybe_parse_fixed_vstore() -> option<option<uint>> {
if self.token == token::BINOP(token::SLASH) { if self.token == token::BINOP(token::SLASH) {
self.bump(); self.bump();
alt copy self.token { match copy self.token {
token::UNDERSCORE => { token::UNDERSCORE => {
self.bump(); some(none) self.bump(); some(none)
} }
@ -585,7 +585,7 @@ class parser {
} }
fn lit_from_token(tok: token::token) -> lit_ { fn lit_from_token(tok: token::token) -> lit_ {
alt tok { match tok {
token::LIT_INT(i, it) => lit_int(i, it), token::LIT_INT(i, it) => lit_int(i, it),
token::LIT_UINT(u, ut) => lit_uint(u, ut), token::LIT_UINT(u, ut) => lit_uint(u, ut),
token::LIT_INT_UNSUFFIXED(i) => lit_int_unsuffixed(i), token::LIT_INT_UNSUFFIXED(i) => lit_int_unsuffixed(i),
@ -733,7 +733,7 @@ class parser {
} }
fn to_expr(e: pexpr) -> @expr { fn to_expr(e: pexpr) -> @expr {
alt e.node { match e.node {
expr_tup(es) if vec::len(es) == 1u => es[0u], expr_tup(es) if vec::len(es) == 1u => es[0u],
_ => *e _ => *e
} }
@ -746,7 +746,7 @@ class parser {
let mut ex: expr_; let mut ex: expr_;
alt self.maybe_parse_dollar_mac() { match self.maybe_parse_dollar_mac() {
some(x) => return pexpr(self.mk_mac_expr(lo, self.span.hi, x)), some(x) => return pexpr(self.mk_mac_expr(lo, self.span.hi, x)),
_ => () _ => ()
} }
@ -794,11 +794,11 @@ class parser {
return pexpr(self.parse_while_expr()); return pexpr(self.parse_while_expr());
} else if self.eat_keyword(~"loop") { } else if self.eat_keyword(~"loop") {
return pexpr(self.parse_loop_expr()); return pexpr(self.parse_loop_expr());
} else if self.eat_keyword(~"alt") || self.eat_keyword(~"match") { } else if self.eat_keyword(~"match") {
return pexpr(self.parse_alt_expr()); return pexpr(self.parse_alt_expr());
} else if self.eat_keyword(~"fn") { } else if self.eat_keyword(~"fn") {
let proto = self.parse_fn_ty_proto(); let proto = self.parse_fn_ty_proto();
alt proto { match proto {
proto_bare => self.fatal(~"fn expr are deprecated, use fn@"), proto_bare => self.fatal(~"fn expr are deprecated, use fn@"),
_ => { /* fallthrough */ } _ => { /* fallthrough */ }
} }
@ -893,7 +893,7 @@ class parser {
/* `!`, as an operator, is prefix, so we know this isn't that */ /* `!`, as an operator, is prefix, so we know this isn't that */
if self.token == token::NOT { if self.token == token::NOT {
self.bump(); self.bump();
let tts = alt self.token { let tts = match self.token {
token::LPAREN | token::LBRACE | token::LBRACKET => { token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token); let ket = token::flip_delimiter(self.token);
self.parse_unspanned_seq(copy self.token, ket, self.parse_unspanned_seq(copy self.token, ket,
@ -948,9 +948,9 @@ class parser {
// Vstore is legal following expr_lit(lit_str(...)) and expr_vec(...) // Vstore is legal following expr_lit(lit_str(...)) and expr_vec(...)
// only. // only.
alt ex { match ex {
expr_lit(@{node: lit_str(_), span: _}) | expr_lit(@{node: lit_str(_), span: _}) |
expr_vec(_, _) => alt self.maybe_parse_fixed_vstore() { expr_vec(_, _) => match self.maybe_parse_fixed_vstore() {
none => (), none => (),
some(v) => { some(v) => {
hi = self.span.hi; hi = self.span.hi;
@ -976,7 +976,7 @@ class parser {
} }
fn parse_syntax_ext_naked(lo: uint) -> @expr { fn parse_syntax_ext_naked(lo: uint) -> @expr {
alt self.token { match self.token {
token::IDENT(_, _) => (), token::IDENT(_, _) => (),
_ => self.fatal(~"expected a syntax expander name") _ => self.fatal(~"expected a syntax expander name")
} }
@ -1003,7 +1003,7 @@ class parser {
let lo = self.span.lo; let lo = self.span.lo;
let mut depth = 1u; let mut depth = 1u;
while (depth > 0u) { while (depth > 0u) {
alt (self.token) { match (self.token) {
token::LBRACE => depth += 1u, token::LBRACE => depth += 1u,
token::RBRACE => depth -= 1u, token::RBRACE => depth -= 1u,
token::EOF => self.fatal(~"unexpected EOF in macro body"), token::EOF => self.fatal(~"unexpected EOF in macro body"),
@ -1033,7 +1033,7 @@ class parser {
loop { loop {
// expr.f // expr.f
if self.eat(token::DOT) { if self.eat(token::DOT) {
alt copy self.token { match copy self.token {
token::IDENT(i, _) => { token::IDENT(i, _) => {
hi = self.span.hi; hi = self.span.hi;
self.bump(); self.bump();
@ -1051,7 +1051,7 @@ class parser {
again; again;
} }
if self.expr_is_complete(e) { break; } if self.expr_is_complete(e) { break; }
alt copy self.token { match copy self.token {
// expr(...) // expr(...)
token::LPAREN if self.permits_call() => { token::LPAREN if self.permits_call() => {
let es = self.parse_unspanned_seq( let es = self.parse_unspanned_seq(
@ -1103,7 +1103,7 @@ class parser {
maybe_whole!{deref self, nt_tt}; maybe_whole!{deref self, nt_tt};
fn parse_tt_tok(p: parser, delim_ok: bool) -> token_tree { fn parse_tt_tok(p: parser, delim_ok: bool) -> token_tree {
alt p.token { match p.token {
token::RPAREN | token::RBRACE | token::RBRACKET token::RPAREN | token::RBRACE | token::RBRACKET
if !delim_ok => { if !delim_ok => {
p.fatal(~"incorrect close delimiter: `" p.fatal(~"incorrect close delimiter: `"
@ -1134,7 +1134,7 @@ class parser {
return res; return res;
} }
return alt self.token { return match self.token {
token::LPAREN | token::LBRACE | token::LBRACKET => { token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token); let ket = token::flip_delimiter(self.token);
tt_delim(vec::append( tt_delim(vec::append(
@ -1154,7 +1154,7 @@ class parser {
// the interpolation of matchers // the interpolation of matchers
maybe_whole!{self, nt_matchers}; maybe_whole!{self, nt_matchers};
let name_idx = @mut 0u; let name_idx = @mut 0u;
return alt self.token { return match self.token {
token::LBRACE | token::LPAREN | token::LBRACKET => { token::LBRACE | token::LPAREN | token::LBRACKET => {
self.parse_matcher_subseq(name_idx, copy self.token, self.parse_matcher_subseq(name_idx, copy self.token,
token::flip_delimiter(self.token)) token::flip_delimiter(self.token))
@ -1222,7 +1222,7 @@ class parser {
let mut hi; let mut hi;
let mut ex; let mut ex;
alt copy self.token { match copy self.token {
token::NOT => { token::NOT => {
self.bump(); self.bump();
let e = self.to_expr(self.parse_prefix_expr()); let e = self.to_expr(self.parse_prefix_expr());
@ -1231,7 +1231,7 @@ class parser {
ex = expr_unary(not, e); ex = expr_unary(not, e);
} }
token::BINOP(b) => { token::BINOP(b) => {
alt b { match b {
token::MINUS => { token::MINUS => {
self.bump(); self.bump();
let e = self.to_expr(self.parse_prefix_expr()); let e = self.to_expr(self.parse_prefix_expr());
@ -1251,7 +1251,7 @@ class parser {
let e = self.to_expr(self.parse_prefix_expr()); let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi; hi = e.span.hi;
// HACK: turn &[...] into a &-evec // HACK: turn &[...] into a &-evec
ex = alt e.node { ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
if m == m_imm => { if m == m_imm => {
expr_vstore(e, vstore_slice(self.region_from_name(none))) expr_vstore(e, vstore_slice(self.region_from_name(none)))
@ -1268,7 +1268,7 @@ class parser {
let e = self.to_expr(self.parse_prefix_expr()); let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi; hi = e.span.hi;
// HACK: turn @[...] into a @-evec // HACK: turn @[...] into a @-evec
ex = alt e.node { ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
if m == m_imm => expr_vstore(e, vstore_box), if m == m_imm => expr_vstore(e, vstore_box),
_ => expr_unary(box(m), e) _ => expr_unary(box(m), e)
@ -1280,7 +1280,7 @@ class parser {
let e = self.to_expr(self.parse_prefix_expr()); let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi; hi = e.span.hi;
// HACK: turn ~[...] into a ~-evec // HACK: turn ~[...] into a ~-evec
ex = alt e.node { ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
if m == m_imm => expr_vstore(e, vstore_uniq), if m == m_imm => expr_vstore(e, vstore_uniq),
_ => expr_unary(uniq(m), e) _ => expr_unary(uniq(m), e)
@ -1311,7 +1311,7 @@ class parser {
return lhs; return lhs;
} }
let cur_opt = token_to_binop(peeked); let cur_opt = token_to_binop(peeked);
alt cur_opt { match cur_opt {
some(cur_op) => { some(cur_op) => {
let cur_prec = operator_prec(cur_op); let cur_prec = operator_prec(cur_op);
if cur_prec > min_prec { if cur_prec > min_prec {
@ -1338,7 +1338,7 @@ class parser {
fn parse_assign_expr() -> @expr { fn parse_assign_expr() -> @expr {
let lo = self.span.lo; let lo = self.span.lo;
let lhs = self.parse_binops(); let lhs = self.parse_binops();
alt copy self.token { match copy self.token {
token::EQ => { token::EQ => {
self.bump(); self.bump();
let rhs = self.parse_expr(); let rhs = self.parse_expr();
@ -1348,7 +1348,7 @@ class parser {
self.bump(); self.bump();
let rhs = self.parse_expr(); let rhs = self.parse_expr();
let mut aop; let mut aop;
alt op { match op {
token::PLUS => aop = add, token::PLUS => aop = add,
token::MINUS => aop = subtract, token::MINUS => aop = subtract,
token::STAR => aop = mul, token::STAR => aop = mul,
@ -1412,7 +1412,7 @@ class parser {
fn parse_lambda_block_expr() -> @expr { fn parse_lambda_block_expr() -> @expr {
self.parse_lambda_expr_( self.parse_lambda_expr_(
|| { || {
alt self.token { match self.token {
token::BINOP(token::OR) | token::OROR => { token::BINOP(token::OR) | token::OROR => {
self.parse_fn_block_decl() self.parse_fn_block_decl()
} }
@ -1481,7 +1481,7 @@ class parser {
// Turn on the restriction to stop at | or || so we can parse // Turn on the restriction to stop at | or || so we can parse
// them as the lambda arguments // them as the lambda arguments
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP); let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
alt e.node { match e.node {
expr_call(f, args, false) => { expr_call(f, args, false) => {
let block = self.parse_lambda_block_expr(); let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi, let last_arg = self.mk_expr(block.span.lo, block.span.hi,
@ -1608,7 +1608,7 @@ class parser {
} }
fn parse_initializer() -> option<initializer> { fn parse_initializer() -> option<initializer> {
alt self.token { match self.token {
token::EQ => { token::EQ => {
self.bump(); self.bump();
return some({op: init_assign, expr: self.parse_expr()}); return some({op: init_assign, expr: self.parse_expr()});
@ -1645,14 +1645,14 @@ class parser {
let lo = self.span.lo; let lo = self.span.lo;
let mut hi = self.span.hi; let mut hi = self.span.hi;
let mut pat; let mut pat;
alt self.token { match self.token {
token::UNDERSCORE => { self.bump(); pat = pat_wild; } token::UNDERSCORE => { self.bump(); pat = pat_wild; }
token::AT => { token::AT => {
self.bump(); self.bump();
let sub = self.parse_pat(refutable); let sub = self.parse_pat(refutable);
hi = sub.span.hi; hi = sub.span.hi;
// HACK: parse @"..." as a literal of a vstore @str // HACK: parse @"..." as a literal of a vstore @str
pat = alt sub.node { pat = match sub.node {
pat_lit(e@@{ pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _ node: expr_lit(@{node: lit_str(_), span: _}), _
}) => { }) => {
@ -1669,7 +1669,7 @@ class parser {
let sub = self.parse_pat(refutable); let sub = self.parse_pat(refutable);
hi = sub.span.hi; hi = sub.span.hi;
// HACK: parse ~"..." as a literal of a vstore ~str // HACK: parse ~"..." as a literal of a vstore ~str
pat = alt sub.node { pat = match sub.node {
pat_lit(e@@{ pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _ node: expr_lit(@{node: lit_str(_), span: _}), _
}) => { }) => {
@ -1775,7 +1775,7 @@ class parser {
} }
if is_plain_ident(self.token) && if is_plain_ident(self.token) &&
alt self.look_ahead(1) { match self.look_ahead(1) {
token::LPAREN | token::LBRACKET | token::LT => { token::LPAREN | token::LBRACKET | token::LT => {
false false
} }
@ -1794,8 +1794,8 @@ class parser {
hi = enum_path.span.hi; hi = enum_path.span.hi;
let mut args: ~[@pat] = ~[]; let mut args: ~[@pat] = ~[];
let mut star_pat = false; let mut star_pat = false;
alt self.token { match self.token {
token::LPAREN => alt self.look_ahead(1u) { token::LPAREN => match self.look_ahead(1u) {
token::BINOP(token::STAR) => { token::BINOP(token::STAR) => {
// This is a "top constructor only" pat // This is a "top constructor only" pat
self.bump(); self.bump(); self.bump(); self.bump();
@ -1890,7 +1890,7 @@ class parser {
return @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id())); return @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id()));
} else { } else {
let mut item_attrs; let mut item_attrs;
alt self.parse_outer_attrs_or_ext(first_item_attrs) { match self.parse_outer_attrs_or_ext(first_item_attrs) {
none => item_attrs = ~[], none => item_attrs = ~[],
some(left(attrs)) => item_attrs = attrs, some(left(attrs)) => item_attrs = attrs,
some(right(ext)) => { some(right(ext)) => {
@ -1901,7 +1901,7 @@ class parser {
let item_attrs = vec::append(first_item_attrs, item_attrs); let item_attrs = vec::append(first_item_attrs, item_attrs);
alt self.parse_item(item_attrs) { match self.parse_item(item_attrs) {
some(i) => { some(i) => {
let mut hi = i.span.hi; let mut hi = i.span.hi;
let decl = @spanned(lo, hi, decl_item(i)); let decl = @spanned(lo, hi, decl_item(i));
@ -1993,16 +1993,16 @@ class parser {
} }
while self.token != token::RBRACE { while self.token != token::RBRACE {
alt self.token { match self.token {
token::SEMI => { token::SEMI => {
self.bump(); // empty self.bump(); // empty
} }
_ => { _ => {
let stmt = self.parse_stmt(initial_attrs); let stmt = self.parse_stmt(initial_attrs);
initial_attrs = ~[]; initial_attrs = ~[];
alt stmt.node { match stmt.node {
stmt_expr(e, stmt_id) => { // Expression without semicolon: stmt_expr(e, stmt_id) => { // Expression without semicolon:
alt self.token { match self.token {
token::SEMI => { token::SEMI => {
self.bump(); self.bump();
push(stmts, push(stmts,
@ -2086,7 +2086,7 @@ class parser {
} }
fn is_self_ident() -> bool { fn is_self_ident() -> bool {
alt self.token { match self.token {
token::IDENT(sid, false) if ~"self" == *self.get_str(sid) => true, token::IDENT(sid, false) if ~"self" == *self.get_str(sid) => true,
_ => false _ => false
} }
@ -2111,7 +2111,7 @@ class parser {
// backwards compatible. // backwards compatible.
let lo = self.span.lo; let lo = self.span.lo;
let self_ty; let self_ty;
alt copy self.token { match copy self.token {
token::BINOP(token::AND) => { token::BINOP(token::AND) => {
// We need to make sure it isn't a mode. // We need to make sure it isn't a mode.
self.bump(); self.bump();
@ -2126,10 +2126,10 @@ class parser {
// Parse an explicit region, if possible. // Parse an explicit region, if possible.
let region_name; let region_name;
alt copy self.token { match copy self.token {
token::BINOP(token::SLASH) => { token::BINOP(token::SLASH) => {
self.bump(); self.bump();
alt copy self.token { match copy self.token {
token::IDENT(sid, false) => { token::IDENT(sid, false) => {
self.bump(); self.bump();
region_name = some(self.get_str(sid)); region_name = some(self.get_str(sid));
@ -2174,7 +2174,7 @@ class parser {
// If we parsed a self type, expect a comma before the argument list. // If we parsed a self type, expect a comma before the argument list.
let args_or_capture_items; let args_or_capture_items;
if self_ty != sty_by_ref { if self_ty != sty_by_ref {
alt copy self.token { match copy self.token {
token::COMMA => { token::COMMA => {
self.bump(); self.bump();
let sep = seq_sep_trailing_disallowed(token::COMMA); let sep = seq_sep_trailing_disallowed(token::COMMA);
@ -2265,7 +2265,7 @@ class parser {
} }
fn parse_method_name() -> ident { fn parse_method_name() -> ident {
alt copy self.token { match copy self.token {
token::BINOP(op) => { self.bump(); @token::binop_to_str(op) } token::BINOP(op) => { self.bump(); @token::binop_to_str(op) }
token::NOT => { self.bump(); @~"!" } token::NOT => { self.bump(); @~"!" }
token::LBRACKET => { token::LBRACKET => {
@ -2387,7 +2387,7 @@ class parser {
} else { } else {
traits = ~[]; traits = ~[];
}; };
ident = alt ident_old { ident = match ident_old {
some(name) => name, some(name) => name,
none => { self.expect_keyword(~"of"); fail; } none => { self.expect_keyword(~"of"); fail; }
}; };
@ -2445,7 +2445,7 @@ class parser {
codemap::span)> = none; codemap::span)> = none;
let mut the_dtor : option<(blk, ~[attribute], codemap::span)> = none; let mut the_dtor : option<(blk, ~[attribute], codemap::span)> = none;
while self.token != token::RBRACE { while self.token != token::RBRACE {
alt self.parse_class_item(class_path) { match self.parse_class_item(class_path) {
ctor_decl(a_fn_decl, attrs, blk, s) => { ctor_decl(a_fn_decl, attrs, blk, s) => {
the_ctor = some((a_fn_decl, attrs, blk, s)); the_ctor = some((a_fn_decl, attrs, blk, s));
} }
@ -2463,7 +2463,7 @@ class parser {
body: d_body}, body: d_body},
span: d_s}}; span: d_s}};
self.bump(); self.bump();
alt the_ctor { match the_ctor {
some((ct_d, ct_attrs, ct_b, ct_s)) => { some((ct_d, ct_attrs, ct_b, ct_s)) => {
(class_name, (class_name,
item_class(ty_params, traits, ms, some({ item_class(ty_params, traits, ms, some({
@ -2487,7 +2487,7 @@ class parser {
} }
fn token_is_pound_or_doc_comment(++tok: token::token) -> bool { fn token_is_pound_or_doc_comment(++tok: token::token) -> bool {
alt tok { match tok {
token::POUND | token::DOC_COMMENT(_) => true, token::POUND | token::DOC_COMMENT(_) => true,
_ => false _ => false
} }
@ -2582,7 +2582,7 @@ class parser {
first = false; first = false;
} }
debug!{"parse_mod_items: parse_item(attrs=%?)", attrs}; debug!{"parse_mod_items: parse_item(attrs=%?)", attrs};
alt self.parse_item(attrs) { match self.parse_item(attrs) {
some(i) => vec::push(items, i), some(i) => vec::push(items, i),
_ => { _ => {
self.fatal(~"expected item but found `" + self.fatal(~"expected item but found `" +
@ -2764,7 +2764,7 @@ class parser {
} }
fn parse_fn_ty_proto() -> proto { fn parse_fn_ty_proto() -> proto {
alt self.token { match self.token {
token::AT => { token::AT => {
self.bump(); self.bump();
proto_box proto_box
@ -2784,7 +2784,7 @@ class parser {
} }
fn fn_expr_lookahead(tok: token::token) -> bool { fn fn_expr_lookahead(tok: token::token) -> bool {
alt tok { match tok {
token::LPAREN | token::AT | token::TILDE | token::BINOP(_) => true, token::LPAREN | token::AT | token::TILDE | token::BINOP(_) => true,
_ => false _ => false
} }
@ -2846,7 +2846,7 @@ class parser {
let pth = self.parse_path_without_tps(); let pth = self.parse_path_without_tps();
self.expect(token::NOT); self.expect(token::NOT);
let id = self.parse_ident(); let id = self.parse_ident();
let tts = alt self.token { let tts = match self.token {
token::LPAREN | token::LBRACE | token::LBRACKET => { token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token); let ket = token::flip_delimiter(self.token);
self.parse_unspanned_seq(copy self.token, ket, self.parse_unspanned_seq(copy self.token, ket,
@ -2863,7 +2863,7 @@ class parser {
(id, item_mac(m), none) (id, item_mac(m), none)
} else { return none; }; } else { return none; };
some(self.mk_item(lo, self.last_span.hi, ident, item_, visibility, some(self.mk_item(lo, self.last_span.hi, ident, item_, visibility,
alt extra_attrs { match extra_attrs {
some(as) => vec::append(attrs, as), some(as) => vec::append(attrs, as),
none => attrs none => attrs
})) }))
@ -2880,7 +2880,7 @@ class parser {
let first_ident = self.parse_ident(); let first_ident = self.parse_ident();
let mut path = ~[first_ident]; let mut path = ~[first_ident];
debug!{"parsed view_path: %s", *first_ident}; debug!{"parsed view_path: %s", *first_ident};
alt self.token { match self.token {
token::EQ => { token::EQ => {
// x = foo::bar // x = foo::bar
self.bump(); self.bump();
@ -2901,7 +2901,7 @@ class parser {
while self.token == token::MOD_SEP { while self.token == token::MOD_SEP {
self.bump(); self.bump();
alt copy self.token { match copy self.token {
token::IDENT(i, _) => { token::IDENT(i, _) => {
self.bump(); self.bump();
@ -3004,7 +3004,7 @@ class parser {
} }
fn parse_str() -> @~str { fn parse_str() -> @~str {
alt copy self.token { match copy self.token {
token::LIT_STR(s) => { self.bump(); self.get_str(s) } token::LIT_STR(s) => { self.bump(); self.get_str(s) }
_ => self.fatal(~"expected string literal") _ => self.fatal(~"expected string literal")
} }
@ -3035,7 +3035,7 @@ class parser {
self.expect_keyword(~"module"); self.expect_keyword(~"module");
} }
let id = self.parse_ident(); let id = self.parse_ident();
alt self.token { match self.token {
// mod x = "foo.rs"; // mod x = "foo.rs";
token::SEMI => { token::SEMI => {
let mut hi = self.span.hi; let mut hi = self.span.hi;

View file

@ -20,7 +20,7 @@ const as_prec: uint = 11u;
* operator and its precedence * operator and its precedence
*/ */
fn token_to_binop(tok: token) -> option<ast::binop> { fn token_to_binop(tok: token) -> option<ast::binop> {
alt tok { match tok {
BINOP(STAR) => some(mul), BINOP(STAR) => some(mul),
BINOP(SLASH) => some(div), BINOP(SLASH) => some(div),
BINOP(PERCENT) => some(rem), BINOP(PERCENT) => some(rem),

View file

@ -102,7 +102,7 @@ enum nonterminal {
} }
fn binop_to_str(o: binop) -> ~str { fn binop_to_str(o: binop) -> ~str {
alt o { match o {
PLUS => ~"+", PLUS => ~"+",
MINUS => ~"-", MINUS => ~"-",
STAR => ~"*", STAR => ~"*",
@ -117,7 +117,7 @@ fn binop_to_str(o: binop) -> ~str {
} }
fn to_str(in: interner<@~str>, t: token) -> ~str { fn to_str(in: interner<@~str>, t: token) -> ~str {
alt t { match t {
EQ => ~"=", EQ => ~"=",
LT => ~"<", LT => ~"<",
LE => ~"<=", LE => ~"<=",
@ -186,7 +186,7 @@ fn to_str(in: interner<@~str>, t: token) -> ~str {
EOF => ~"<eof>", EOF => ~"<eof>",
INTERPOLATED(nt) => { INTERPOLATED(nt) => {
~"an interpolated " + ~"an interpolated " +
alt nt { match nt {
nt_item(*) => ~"item", nt_item(*) => ~"item",
nt_block(*) => ~"block", nt_block(*) => ~"block",
nt_stmt(*) => ~"statement", nt_stmt(*) => ~"statement",
@ -203,7 +203,7 @@ fn to_str(in: interner<@~str>, t: token) -> ~str {
} }
pure fn can_begin_expr(t: token) -> bool { pure fn can_begin_expr(t: token) -> bool {
alt t { match t {
LPAREN => true, LPAREN => true,
LBRACE => true, LBRACE => true,
LBRACKET => true, LBRACKET => true,
@ -234,7 +234,7 @@ pure fn can_begin_expr(t: token) -> bool {
/// what's the opposite delimiter? /// what's the opposite delimiter?
fn flip_delimiter(&t: token::token) -> token::token { fn flip_delimiter(&t: token::token) -> token::token {
alt t { match t {
token::LPAREN => token::RPAREN, token::LPAREN => token::RPAREN,
token::LBRACE => token::RBRACE, token::LBRACE => token::RBRACE,
token::LBRACKET => token::RBRACKET, token::LBRACKET => token::RBRACKET,
@ -248,7 +248,7 @@ fn flip_delimiter(&t: token::token) -> token::token {
fn is_lit(t: token) -> bool { fn is_lit(t: token) -> bool {
alt t { match t {
LIT_INT(_, _) => true, LIT_INT(_, _) => true,
LIT_UINT(_, _) => true, LIT_UINT(_, _) => true,
LIT_INT_UNSUFFIXED(_) => true, LIT_INT_UNSUFFIXED(_) => true,
@ -259,22 +259,22 @@ fn is_lit(t: token) -> bool {
} }
pure fn is_ident(t: token) -> bool { pure fn is_ident(t: token) -> bool {
alt t { IDENT(_, _) => true, _ => false } match t { IDENT(_, _) => true, _ => false }
} }
pure fn is_ident_or_path(t: token) -> bool { pure fn is_ident_or_path(t: token) -> bool {
alt t { match t {
IDENT(_, _) | INTERPOLATED(nt_path(*)) => true, IDENT(_, _) | INTERPOLATED(nt_path(*)) => true,
_ => false _ => false
} }
} }
pure fn is_plain_ident(t: token) -> bool { pure fn is_plain_ident(t: token) -> bool {
alt t { IDENT(_, false) => true, _ => false } match t { IDENT(_, false) => true, _ => false }
} }
pure fn is_bar(t: token) -> bool { pure fn is_bar(t: token) -> bool {
alt t { BINOP(OR) | OROR => true, _ => false } match t { BINOP(OR) | OROR => true, _ => false }
} }
/** /**
@ -333,7 +333,7 @@ fn contextual_keyword_table() -> hashmap<~str, ()> {
fn restricted_keyword_table() -> hashmap<~str, ()> { fn restricted_keyword_table() -> hashmap<~str, ()> {
let words = str_hash(); let words = str_hash();
let keys = ~[ let keys = ~[
~"alt", ~"again", ~"assert", ~"again", ~"assert",
~"break", ~"break",
~"check", ~"class", ~"const", ~"copy", ~"check", ~"class", ~"const", ~"copy",
~"do", ~"drop", ~"do", ~"drop",

View file

@ -62,7 +62,7 @@ type begin_t = {offset: int, breaks: breaks};
enum token { STRING(@~str, int), BREAK(break_t), BEGIN(begin_t), END, EOF, } enum token { STRING(@~str, int), BREAK(break_t), BEGIN(begin_t), END, EOF, }
fn tok_str(++t: token) -> ~str { fn tok_str(++t: token) -> ~str {
alt t { match t {
STRING(s, len) => return fmt!{"STR(%s,%d)", *s, len}, STRING(s, len) => return fmt!{"STR(%s,%d)", *s, len},
BREAK(_) => return ~"BREAK", BREAK(_) => return ~"BREAK",
BEGIN(_) => return ~"BEGIN", BEGIN(_) => return ~"BEGIN",
@ -238,7 +238,7 @@ impl printer for printer {
fn replace_last_token(t: token) { self.token[self.right] = t; } fn replace_last_token(t: token) { self.token[self.right] = t; }
fn pretty_print(t: token) { fn pretty_print(t: token) {
debug!{"pp ~[%u,%u]", self.left, self.right}; debug!{"pp ~[%u,%u]", self.left, self.right};
alt t { match t {
EOF => { EOF => {
if !self.scan_stack_empty { if !self.scan_stack_empty {
self.check_stack(0); self.check_stack(0);
@ -357,7 +357,7 @@ impl printer for printer {
self.left, L}; self.left, L};
if L >= 0 { if L >= 0 {
self.print(x, L); self.print(x, L);
alt x { match x {
BREAK(b) => self.left_total += b.blank_space, BREAK(b) => self.left_total += b.blank_space,
STRING(_, len) => { assert (len == L); self.left_total += len; } STRING(_, len) => { assert (len == L); self.left_total += len; }
_ => () _ => ()
@ -373,7 +373,7 @@ impl printer for printer {
fn check_stack(k: int) { fn check_stack(k: int) {
if !self.scan_stack_empty { if !self.scan_stack_empty {
let x = self.scan_top(); let x = self.scan_top();
alt copy self.token[x] { match copy self.token[x] {
BEGIN(b) => { BEGIN(b) => {
if k > 0 { if k > 0 {
self.size[self.scan_pop()] = self.size[x] + self.size[self.scan_pop()] = self.size[x] +
@ -422,7 +422,7 @@ impl printer for printer {
debug!{"print %s %d (remaining line space=%d)", tok_str(x), L, debug!{"print %s %d (remaining line space=%d)", tok_str(x), L,
self.space}; self.space};
log(debug, buf_str(self.token, self.size, self.left, self.right, 6u)); log(debug, buf_str(self.token, self.size, self.left, self.right, 6u));
alt x { match x {
BEGIN(b) => { BEGIN(b) => {
if L > self.space { if L > self.space {
let col = self.margin - self.space + b.offset; let col = self.margin - self.space + b.offset;
@ -442,7 +442,7 @@ impl printer for printer {
} }
BREAK(b) => { BREAK(b) => {
let top = self.get_top(); let top = self.get_top();
alt top.pbreak { match top.pbreak {
fits => { fits => {
debug!{"print BREAK in fitting block"}; debug!{"print BREAK in fitting block"};
self.space -= b.blank_space; self.space -= b.blank_space;

View file

@ -222,11 +222,11 @@ fn bclose_(s: ps, span: codemap::span, indented: uint) {
fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); } fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); }
fn is_begin(s: ps) -> bool { fn is_begin(s: ps) -> bool {
alt s.s.last_token() { pp::BEGIN(_) => true, _ => false } match s.s.last_token() { pp::BEGIN(_) => true, _ => false }
} }
fn is_end(s: ps) -> bool { fn is_end(s: ps) -> bool {
alt s.s.last_token() { pp::END => true, _ => false } match s.s.last_token() { pp::END => true, _ => false }
} }
fn is_bol(s: ps) -> bool { fn is_bol(s: ps) -> bool {
@ -318,7 +318,7 @@ fn print_foreign_mod(s: ps, nmod: ast::foreign_mod,
} }
fn print_region(s: ps, region: @ast::region) { fn print_region(s: ps, region: @ast::region) {
alt region.node { match region.node {
ast::re_anon => word_space(s, ~"&"), ast::re_anon => word_space(s, ~"&"),
ast::re_named(name) => { ast::re_named(name) => {
word(s.s, ~"&"); word(s.s, ~"&");
@ -334,14 +334,14 @@ fn print_type(s: ps, &&ty: @ast::ty) {
fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) { fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
maybe_print_comment(s, ty.span.lo); maybe_print_comment(s, ty.span.lo);
ibox(s, 0u); ibox(s, 0u);
alt ty.node { match ty.node {
ast::ty_nil => word(s.s, ~"()"), ast::ty_nil => word(s.s, ~"()"),
ast::ty_bot => word(s.s, ~"!"), ast::ty_bot => word(s.s, ~"!"),
ast::ty_box(mt) => { word(s.s, ~"@"); print_mt(s, mt); } ast::ty_box(mt) => { word(s.s, ~"@"); print_mt(s, mt); }
ast::ty_uniq(mt) => { word(s.s, ~"~"); print_mt(s, mt); } ast::ty_uniq(mt) => { word(s.s, ~"~"); print_mt(s, mt); }
ast::ty_vec(mt) => { ast::ty_vec(mt) => {
word(s.s, ~"["); word(s.s, ~"[");
alt mt.mutbl { match mt.mutbl {
ast::m_mutbl => word_space(s, ~"mut"), ast::m_mutbl => word_space(s, ~"mut"),
ast::m_const => word_space(s, ~"const"), ast::m_const => word_space(s, ~"const"),
ast::m_imm => () ast::m_imm => ()
@ -351,7 +351,7 @@ fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
} }
ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); } ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); }
ast::ty_rptr(region, mt) => { ast::ty_rptr(region, mt) => {
alt region.node { match region.node {
ast::re_anon => word(s.s, ~"&"), ast::re_anon => word(s.s, ~"&"),
_ => { print_region(s, region); word(s.s, ~"/"); } _ => { print_region(s, region); word(s.s, ~"/"); }
} }
@ -400,7 +400,7 @@ fn print_foreign_item(s: ps, item: @ast::foreign_item) {
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo); maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs); print_outer_attributes(s, item.attrs);
alt item.node { match item.node {
ast::foreign_item_fn(decl, typarams) => { ast::foreign_item_fn(decl, typarams) => {
print_fn(s, decl, item.ident, typarams); print_fn(s, decl, item.ident, typarams);
end(s); // end head-ibox end(s); // end head-ibox
@ -416,7 +416,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_outer_attributes(s, item.attrs); print_outer_attributes(s, item.attrs);
let ann_node = node_item(s, item); let ann_node = node_item(s, item);
s.ann.pre(ann_node); s.ann.pre(ann_node);
alt item.node { match item.node {
ast::item_const(ty, expr) => { ast::item_const(ty, expr) => {
head(s, ~"const"); head(s, ~"const");
word_space(s, *item.ident + ~":"); word_space(s, *item.ident + ~":");
@ -538,7 +538,7 @@ fn print_item(s: ps, &&item: @ast::item) {
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
maybe_print_comment(s, ci.span.lo); maybe_print_comment(s, ci.span.lo);
let pr = ast_util::class_member_visibility(ci); let pr = ast_util::class_member_visibility(ci);
alt pr { match pr {
ast::private => { ast::private => {
head(s, ~"priv"); head(s, ~"priv");
bopen(s); bopen(s);
@ -546,10 +546,10 @@ fn print_item(s: ps, &&item: @ast::item) {
} }
_ => () _ => ()
} }
alt ci.node { match ci.node {
ast::instance_var(nm, t, mt, _,_) => { ast::instance_var(nm, t, mt, _,_) => {
word_nbsp(s, ~"let"); word_nbsp(s, ~"let");
alt mt { match mt {
ast::class_mutable => word_nbsp(s, ~"mut"), ast::class_mutable => word_nbsp(s, ~"mut"),
_ => () _ => ()
} }
@ -562,7 +562,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_method(s, m); print_method(s, m);
} }
} }
alt pr { match pr {
ast::private => bclose(s, ci.span), ast::private => bclose(s, ci.span),
_ => () _ => ()
} }
@ -625,10 +625,10 @@ fn print_item(s: ps, &&item: @ast::item) {
/// and then pretty-print the resulting AST nodes (so, e.g., we print /// and then pretty-print the resulting AST nodes (so, e.g., we print
/// expression arguments as expressions). It can be done! I think. /// expression arguments as expressions). It can be done! I think.
fn print_tt(s: ps, tt: ast::token_tree) { fn print_tt(s: ps, tt: ast::token_tree) {
alt tt { match tt {
ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); } ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); }
ast::tt_tok(_, tk) => { ast::tt_tok(_, tk) => {
alt tk { match tk {
parse::token::IDENT(*) => { // don't let idents run together parse::token::IDENT(*) => { // don't let idents run together
if s.s.token_tree_last_was_ident { word(s.s, ~" ") } if s.s.token_tree_last_was_ident { word(s.s, ~" ") }
s.s.token_tree_last_was_ident = true; s.s.token_tree_last_was_ident = true;
@ -641,7 +641,7 @@ fn print_tt(s: ps, tt: ast::token_tree) {
word(s.s, ~"$("); word(s.s, ~"$(");
for tts.each() |tt_elt| { print_tt(s, tt_elt); } for tts.each() |tt_elt| { print_tt(s, tt_elt); }
word(s.s, ~")"); word(s.s, ~")");
alt sep { match sep {
some(tk) => word(s.s, parse::token::to_str(*s.intr, tk)), some(tk) => word(s.s, parse::token::to_str(*s.intr, tk)),
none => () none => ()
} }
@ -665,7 +665,7 @@ fn print_variant(s: ps, v: ast::variant) {
commasep(s, consistent, v.node.args, print_variant_arg); commasep(s, consistent, v.node.args, print_variant_arg);
pclose(s); pclose(s);
} }
alt v.node.disr_expr { match v.node.disr_expr {
some(d) => { some(d) => {
space(s.s); space(s.s);
word_space(s, ~"="); word_space(s, ~"=");
@ -684,7 +684,7 @@ fn print_ty_method(s: ps, m: ast::ty_method) {
} }
fn print_trait_method(s: ps, m: ast::trait_method) { fn print_trait_method(s: ps, m: ast::trait_method) {
alt m { match m {
required(ty_m) => print_ty_method(s, ty_m), required(ty_m) => print_ty_method(s, ty_m),
provided(m) => print_method(s, m) provided(m) => print_method(s, m)
} }
@ -702,7 +702,7 @@ fn print_method(s: ps, meth: @ast::method) {
fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) { fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) {
let mut count = 0; let mut count = 0;
for attrs.each |attr| { for attrs.each |attr| {
alt attr.node.style { match attr.node.style {
ast::attr_outer => { print_attribute(s, attr); count += 1; } ast::attr_outer => { print_attribute(s, attr); count += 1; }
_ => {/* fallthrough */ } _ => {/* fallthrough */ }
} }
@ -713,7 +713,7 @@ fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) {
fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) { fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) {
let mut count = 0; let mut count = 0;
for attrs.each |attr| { for attrs.each |attr| {
alt attr.node.style { match attr.node.style {
ast::attr_inner => { ast::attr_inner => {
print_attribute(s, attr); print_attribute(s, attr);
if !attr.node.is_sugared_doc { if !attr.node.is_sugared_doc {
@ -744,7 +744,7 @@ fn print_attribute(s: ps, attr: ast::attribute) {
fn print_stmt(s: ps, st: ast::stmt) { fn print_stmt(s: ps, st: ast::stmt) {
maybe_print_comment(s, st.span.lo); maybe_print_comment(s, st.span.lo);
alt st.node { match st.node {
ast::stmt_decl(decl, _) => { ast::stmt_decl(decl, _) => {
print_decl(s, decl); print_decl(s, decl);
} }
@ -780,7 +780,7 @@ fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type,
fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type, fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
indented: uint, attrs: ~[ast::attribute]) { indented: uint, attrs: ~[ast::attribute]) {
alt blk.node.rules { match blk.node.rules {
ast::unchecked_blk => word(s.s, ~"unchecked"), ast::unchecked_blk => word(s.s, ~"unchecked"),
ast::unsafe_blk => word(s.s, ~"unsafe"), ast::unsafe_blk => word(s.s, ~"unsafe"),
ast::default_blk => () ast::default_blk => ()
@ -788,7 +788,7 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
maybe_print_comment(s, blk.span.lo); maybe_print_comment(s, blk.span.lo);
let ann_node = node_block(s, blk); let ann_node = node_block(s, blk);
s.ann.pre(ann_node); s.ann.pre(ann_node);
alt embedded { match embedded {
block_block_fn => end(s), block_block_fn => end(s),
block_normal => bopen(s) block_normal => bopen(s)
} }
@ -799,7 +799,7 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
for blk.node.stmts.each |st| { for blk.node.stmts.each |st| {
print_stmt(s, *st); print_stmt(s, *st);
} }
alt blk.node.expr { match blk.node.expr {
some(expr) => { some(expr) => {
space_if_not_bol(s); space_if_not_bol(s);
print_expr(s, expr); print_expr(s, expr);
@ -814,7 +814,7 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
// return and fail, without arguments cannot appear is the discriminant of if, // return and fail, without arguments cannot appear is the discriminant of if,
// alt, do, & while unambiguously without being parenthesized // alt, do, & while unambiguously without being parenthesized
fn print_maybe_parens_discrim(s: ps, e: @ast::expr) { fn print_maybe_parens_discrim(s: ps, e: @ast::expr) {
let disambig = alt e.node { let disambig = match e.node {
ast::expr_ret(none) | ast::expr_fail(none) => true, ast::expr_ret(none) | ast::expr_fail(none) => true,
_ => false _ => false
}; };
@ -831,9 +831,9 @@ fn print_if(s: ps, test: @ast::expr, blk: ast::blk,
space(s.s); space(s.s);
print_block(s, blk); print_block(s, blk);
fn do_else(s: ps, els: option<@ast::expr>) { fn do_else(s: ps, els: option<@ast::expr>) {
alt els { match els {
some(_else) => { some(_else) => {
alt _else.node { match _else.node {
// "another else-if" // "another else-if"
ast::expr_if(i, t, e) => { ast::expr_if(i, t, e) => {
cbox(s, indent_unit - 1u); cbox(s, indent_unit - 1u);
@ -864,11 +864,11 @@ fn print_if(s: ps, test: @ast::expr, blk: ast::blk,
} }
fn print_mac(s: ps, m: ast::mac) { fn print_mac(s: ps, m: ast::mac) {
alt m.node { match m.node {
ast::mac_invoc(path, arg, body) => { ast::mac_invoc(path, arg, body) => {
word(s.s, ~"#"); word(s.s, ~"#");
print_path(s, path, false); print_path(s, path, false);
alt arg { match arg {
some(@{node: ast::expr_vec(_, _), _}) => (), some(@{node: ast::expr_vec(_, _), _}) => (),
_ => word(s.s, ~" ") _ => word(s.s, ~" ")
} }
@ -888,12 +888,12 @@ fn print_mac(s: ps, m: ast::mac) {
} }
fn print_vstore(s: ps, t: ast::vstore) { fn print_vstore(s: ps, t: ast::vstore) {
alt t { match t {
ast::vstore_fixed(some(i)) => word(s.s, fmt!{"%u", i}), ast::vstore_fixed(some(i)) => word(s.s, fmt!{"%u", i}),
ast::vstore_fixed(none) => word(s.s, ~"_"), ast::vstore_fixed(none) => word(s.s, ~"_"),
ast::vstore_uniq => word(s.s, ~"~"), ast::vstore_uniq => word(s.s, ~"~"),
ast::vstore_box => word(s.s, ~"@"), ast::vstore_box => word(s.s, ~"@"),
ast::vstore_slice(r) => alt r.node { ast::vstore_slice(r) => match r.node {
ast::re_anon => word(s.s, ~"&"), ast::re_anon => word(s.s, ~"&"),
ast::re_named(name) => { ast::re_named(name) => {
word(s.s, ~"&"); word(s.s, ~"&");
@ -919,8 +919,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
ibox(s, indent_unit); ibox(s, indent_unit);
let ann_node = node_expr(s, expr); let ann_node = node_expr(s, expr);
s.ann.pre(ann_node); s.ann.pre(ann_node);
alt expr.node { match expr.node {
ast::expr_vstore(e, v) => alt v { ast::expr_vstore(e, v) => match v {
ast::vstore_fixed(_) => { ast::vstore_fixed(_) => {
print_expr(s, e); print_expr(s, e);
word(s.s, ~"/"); word(s.s, ~"/");
@ -961,7 +961,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
ast::expr_rec(fields, wth) => { ast::expr_rec(fields, wth) => {
word(s.s, ~"{"); word(s.s, ~"{");
commasep_cmnt(s, consistent, fields, print_field, get_span); commasep_cmnt(s, consistent, fields, print_field, get_span);
alt wth { match wth {
some(expr) => { some(expr) => {
if vec::len(fields) > 0u { space(s.s); } if vec::len(fields) > 0u { space(s.s); }
ibox(s, indent_unit); ibox(s, indent_unit);
@ -977,7 +977,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
print_path(s, path, true); print_path(s, path, true);
word(s.s, ~"{"); word(s.s, ~"{");
commasep_cmnt(s, consistent, fields, print_field, get_span); commasep_cmnt(s, consistent, fields, print_field, get_span);
alt wth { match wth {
some(expr) => { some(expr) => {
if vec::len(fields) > 0u { space(s.s); } if vec::len(fields) > 0u { space(s.s); }
ibox(s, indent_unit); ibox(s, indent_unit);
@ -998,7 +998,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
let mut base_args = args; let mut base_args = args;
let blk = if has_block { let blk = if has_block {
let blk_arg = vec::pop(base_args); let blk_arg = vec::pop(base_args);
alt blk_arg.node { match blk_arg.node {
ast::expr_loop_body(_) => word_nbsp(s, ~"for"), ast::expr_loop_body(_) => word_nbsp(s, ~"for"),
ast::expr_do_body(_) => word_nbsp(s, ~"do"), ast::expr_do_body(_) => word_nbsp(s, ~"do"),
_ => () _ => ()
@ -1056,7 +1056,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
ast::expr_alt(expr, arms, mode) => { ast::expr_alt(expr, arms, mode) => {
cbox(s, alt_indent_unit); cbox(s, alt_indent_unit);
ibox(s, 4u); ibox(s, 4u);
word_nbsp(s, ~"alt"); word_nbsp(s, ~"match");
if mode == ast::alt_check { word_nbsp(s, ~"check"); } if mode == ast::alt_check { word_nbsp(s, ~"check"); }
print_maybe_parens_discrim(s, expr); print_maybe_parens_discrim(s, expr);
space(s.s); space(s.s);
@ -1074,7 +1074,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
print_pat(s, p); print_pat(s, p);
} }
space(s.s); space(s.s);
alt arm.guard { match arm.guard {
some(e) => { some(e) => {
word_space(s, ~"if"); word_space(s, ~"if");
print_expr(s, e); print_expr(s, e);
@ -1087,7 +1087,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
assert arm.body.node.view_items.is_empty(); assert arm.body.node.view_items.is_empty();
assert arm.body.node.stmts.is_empty(); assert arm.body.node.stmts.is_empty();
assert arm.body.node.rules == ast::default_blk; assert arm.body.node.rules == ast::default_blk;
alt arm.body.node.expr { match arm.body.node.expr {
some(expr) => { some(expr) => {
end(s); // close the ibox for the pattern end(s); // close the ibox for the pattern
print_expr(s, expr); print_expr(s, expr);
@ -1185,7 +1185,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
ast::expr_path(path) => print_path(s, path, true), ast::expr_path(path) => print_path(s, path, true),
ast::expr_fail(maybe_fail_val) => { ast::expr_fail(maybe_fail_val) => {
word(s.s, ~"fail"); word(s.s, ~"fail");
alt maybe_fail_val { match maybe_fail_val {
some(expr) => { word(s.s, ~" "); print_expr(s, expr); } some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
_ => () _ => ()
} }
@ -1194,13 +1194,13 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
ast::expr_again => word(s.s, ~"again"), ast::expr_again => word(s.s, ~"again"),
ast::expr_ret(result) => { ast::expr_ret(result) => {
word(s.s, ~"return"); word(s.s, ~"return");
alt result { match result {
some(expr) => { word(s.s, ~" "); print_expr(s, expr); } some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
_ => () _ => ()
} }
} }
ast::expr_log(lvl, lexp, expr) => { ast::expr_log(lvl, lexp, expr) => {
alt check lvl { match check lvl {
1 => { word_nbsp(s, ~"log"); print_expr(s, expr); } 1 => { word_nbsp(s, ~"log"); print_expr(s, expr); }
0 => { word_nbsp(s, ~"log_err"); print_expr(s, expr); } 0 => { word_nbsp(s, ~"log_err"); print_expr(s, expr); }
2 => { 2 => {
@ -1225,7 +1225,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
} }
fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) { fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
let parens = alt ex.node { let parens = match ex.node {
ast::expr_fail(_) | ast::expr_ret(_) | ast::expr_fail(_) | ast::expr_ret(_) |
ast::expr_binary(_, _, _) | ast::expr_unary(_, _) | ast::expr_binary(_, _, _) | ast::expr_unary(_, _) |
ast::expr_move(_, _) | ast::expr_copy(_) | ast::expr_move(_, _) | ast::expr_copy(_) |
@ -1243,7 +1243,7 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
fn print_local_decl(s: ps, loc: @ast::local) { fn print_local_decl(s: ps, loc: @ast::local) {
print_pat(s, loc.node.pat); print_pat(s, loc.node.pat);
alt loc.node.ty.node { match loc.node.ty.node {
ast::ty_infer => (), ast::ty_infer => (),
_ => { word_space(s, ~":"); print_type(s, loc.node.ty); } _ => { word_space(s, ~":"); print_type(s, loc.node.ty); }
} }
@ -1251,7 +1251,7 @@ fn print_local_decl(s: ps, loc: @ast::local) {
fn print_decl(s: ps, decl: @ast::decl) { fn print_decl(s: ps, decl: @ast::decl) {
maybe_print_comment(s, decl.span.lo); maybe_print_comment(s, decl.span.lo);
alt decl.node { match decl.node {
ast::decl_local(locs) => { ast::decl_local(locs) => {
space_if_not_bol(s); space_if_not_bol(s);
ibox(s, indent_unit); ibox(s, indent_unit);
@ -1267,10 +1267,10 @@ fn print_decl(s: ps, decl: @ast::decl) {
ibox(s, indent_unit); ibox(s, indent_unit);
print_local_decl(s, loc); print_local_decl(s, loc);
end(s); end(s);
alt loc.node.init { match loc.node.init {
some(init) => { some(init) => {
nbsp(s); nbsp(s);
alt init.op { match init.op {
ast::init_assign => word_space(s, ~"="), ast::init_assign => word_space(s, ~"="),
ast::init_move => word_space(s, ~"<-") ast::init_move => word_space(s, ~"<-")
} }
@ -1306,7 +1306,7 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
if path.rp.is_some() || !path.types.is_empty() { if path.rp.is_some() || !path.types.is_empty() {
if colons_before_params { word(s.s, ~"::"); } if colons_before_params { word(s.s, ~"::"); }
alt path.rp { match path.rp {
none => { /* ok */ } none => { /* ok */ }
some(r) => { some(r) => {
word(s.s, ~"/"); word(s.s, ~"/");
@ -1328,22 +1328,22 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
s.ann.pre(ann_node); s.ann.pre(ann_node);
/* Pat isn't normalized, but the beauty of it /* Pat isn't normalized, but the beauty of it
is that it doesn't matter */ is that it doesn't matter */
alt pat.node { match pat.node {
ast::pat_wild => word(s.s, ~"_"), ast::pat_wild => word(s.s, ~"_"),
ast::pat_ident(binding_mode, path, sub) => { ast::pat_ident(binding_mode, path, sub) => {
alt binding_mode { match binding_mode {
ast::bind_by_ref => word_space(s, ~"ref"), ast::bind_by_ref => word_space(s, ~"ref"),
ast::bind_by_value => () ast::bind_by_value => ()
} }
print_path(s, path, true); print_path(s, path, true);
alt sub { match sub {
some(p) => { word(s.s, ~"@"); print_pat(s, p); } some(p) => { word(s.s, ~"@"); print_pat(s, p); }
none => () none => ()
} }
} }
ast::pat_enum(path, args_) => { ast::pat_enum(path, args_) => {
print_path(s, path, true); print_path(s, path, true);
alt args_ { match args_ {
none => word(s.s, ~"(*)"), none => word(s.s, ~"(*)"),
some(args) => { some(args) => {
if vec::len(args) > 0u { if vec::len(args) > 0u {
@ -1391,7 +1391,7 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident, fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident,
typarams: ~[ast::ty_param]) { typarams: ~[ast::ty_param]) {
alt decl.purity { match decl.purity {
ast::impure_fn => head(s, ~"fn"), ast::impure_fn => head(s, ~"fn"),
_ => head(s, purity_to_str(decl.purity) + ~" fn") _ => head(s, purity_to_str(decl.purity) + ~" fn")
} }
@ -1442,7 +1442,7 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl,
} }
fn mode_to_str(m: ast::mode) -> ~str { fn mode_to_str(m: ast::mode) -> ~str {
alt m { match m {
ast::expl(ast::by_mutbl_ref) => ~"&", ast::expl(ast::by_mutbl_ref) => ~"&",
ast::expl(ast::by_move) => ~"-", ast::expl(ast::by_move) => ~"-",
ast::expl(ast::by_ref) => ~"&&", ast::expl(ast::by_ref) => ~"&&",
@ -1462,7 +1462,7 @@ fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
word(s.s, ~":"); word(s.s, ~":");
for vec::each(*bounds) |bound| { for vec::each(*bounds) |bound| {
nbsp(s); nbsp(s);
alt bound { match bound {
ast::bound_copy => word(s.s, ~"copy"), ast::bound_copy => word(s.s, ~"copy"),
ast::bound_send => word(s.s, ~"send"), ast::bound_send => word(s.s, ~"send"),
ast::bound_const => word(s.s, ~"const"), ast::bound_const => word(s.s, ~"const"),
@ -1487,7 +1487,7 @@ fn print_type_params(s: ps, &&params: ~[ast::ty_param]) {
fn print_meta_item(s: ps, &&item: @ast::meta_item) { fn print_meta_item(s: ps, &&item: @ast::meta_item) {
ibox(s, indent_unit); ibox(s, indent_unit);
alt item.node { match item.node {
ast::meta_word(name) => word(s.s, *name), ast::meta_word(name) => word(s.s, *name),
ast::meta_name_value(name, value) => { ast::meta_name_value(name, value) => {
word_space(s, *name); word_space(s, *name);
@ -1505,7 +1505,7 @@ fn print_meta_item(s: ps, &&item: @ast::meta_item) {
} }
fn print_view_path(s: ps, &&vp: @ast::view_path) { fn print_view_path(s: ps, &&vp: @ast::view_path) {
alt vp.node { match vp.node {
ast::view_path_simple(ident, path, _) => { ast::view_path_simple(ident, path, _) => {
if path.idents[vec::len(path.idents)-1u] != ident { if path.idents[vec::len(path.idents)-1u] != ident {
word_space(s, *ident); word_space(s, *ident);
@ -1538,7 +1538,7 @@ fn print_view_item(s: ps, item: @ast::view_item) {
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo); maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs); print_outer_attributes(s, item.attrs);
alt item.node { match item.node {
ast::view_item_use(id, mta, _) => { ast::view_item_use(id, mta, _) => {
head(s, ~"use"); head(s, ~"use");
word(s.s, *id); word(s.s, *id);
@ -1572,7 +1572,7 @@ fn print_op_maybe_parens(s: ps, expr: @ast::expr, outer_prec: uint) {
} }
fn print_mutability(s: ps, mutbl: ast::mutability) { fn print_mutability(s: ps, mutbl: ast::mutability) {
alt mutbl { match mutbl {
ast::m_mutbl => word_nbsp(s, ~"mut"), ast::m_mutbl => word_nbsp(s, ~"mut"),
ast::m_const => word_nbsp(s, ~"const"), ast::m_const => word_nbsp(s, ~"const"),
ast::m_imm => {/* nothing */ } ast::m_imm => {/* nothing */ }
@ -1587,7 +1587,7 @@ fn print_mt(s: ps, mt: ast::mt) {
fn print_arg(s: ps, input: ast::arg) { fn print_arg(s: ps, input: ast::arg) {
ibox(s, indent_unit); ibox(s, indent_unit);
print_arg_mode(s, input.mode); print_arg_mode(s, input.mode);
alt input.ty.node { match input.ty.node {
ast::ty_infer => word(s.s, *input.ident), ast::ty_infer => word(s.s, *input.ident),
_ => { _ => {
if str::len(*input.ident) > 0u { if str::len(*input.ident) > 0u {
@ -1604,8 +1604,8 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
tps: option<~[ast::ty_param]>) { tps: option<~[ast::ty_param]>) {
ibox(s, indent_unit); ibox(s, indent_unit);
word(s.s, opt_proto_to_str(opt_proto)); word(s.s, opt_proto_to_str(opt_proto));
alt id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () } match id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () }
alt tps { some(tps) => print_type_params(s, tps), _ => () } match tps { some(tps) => print_type_params(s, tps), _ => () }
zerobreak(s.s); zerobreak(s.s);
popen(s); popen(s);
commasep(s, inconsistent, decl.inputs, print_arg); commasep(s, inconsistent, decl.inputs, print_arg);
@ -1625,14 +1625,14 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
fn maybe_print_trailing_comment(s: ps, span: codemap::span, fn maybe_print_trailing_comment(s: ps, span: codemap::span,
next_pos: option<uint>) { next_pos: option<uint>) {
let mut cm; let mut cm;
alt s.cm { some(ccm) => cm = ccm, _ => return } match s.cm { some(ccm) => cm = ccm, _ => return }
alt next_comment(s) { match next_comment(s) {
some(cmnt) => { some(cmnt) => {
if cmnt.style != comments::trailing { return; } if cmnt.style != comments::trailing { return; }
let span_line = codemap::lookup_char_pos(cm, span.hi); let span_line = codemap::lookup_char_pos(cm, span.hi);
let comment_line = codemap::lookup_char_pos(cm, cmnt.pos); let comment_line = codemap::lookup_char_pos(cm, cmnt.pos);
let mut next = cmnt.pos + 1u; let mut next = cmnt.pos + 1u;
alt next_pos { none => (), some(p) => next = p } match next_pos { none => (), some(p) => next = p }
if span.hi < cmnt.pos && cmnt.pos < next && if span.hi < cmnt.pos && cmnt.pos < next &&
span_line.line == comment_line.line { span_line.line == comment_line.line {
print_comment(s, cmnt); print_comment(s, cmnt);
@ -1648,7 +1648,7 @@ fn print_remaining_comments(s: ps) {
// make sure there is a line break at the end. // make sure there is a line break at the end.
if option::is_none(next_comment(s)) { hardbreak(s.s); } if option::is_none(next_comment(s)) { hardbreak(s.s); }
loop { loop {
alt next_comment(s) { match next_comment(s) {
some(cmnt) => { print_comment(s, cmnt); s.cur_cmnt += 1u; } some(cmnt) => { print_comment(s, cmnt); s.cur_cmnt += 1u; }
_ => break _ => break
} }
@ -1657,14 +1657,14 @@ fn print_remaining_comments(s: ps) {
fn print_literal(s: ps, &&lit: @ast::lit) { fn print_literal(s: ps, &&lit: @ast::lit) {
maybe_print_comment(s, lit.span.lo); maybe_print_comment(s, lit.span.lo);
alt next_lit(s, lit.span.lo) { match next_lit(s, lit.span.lo) {
some(ltrl) => { some(ltrl) => {
word(s.s, ltrl.lit); word(s.s, ltrl.lit);
return; return;
} }
_ => () _ => ()
} }
alt lit.node { match lit.node {
ast::lit_str(st) => print_string(s, *st), ast::lit_str(st) => print_string(s, *st),
ast::lit_int(ch, ast::ty_char) => { ast::lit_int(ch, ast::ty_char) => {
word(s.s, ~"'" + char::escape_default(ch as char) + ~"'"); word(s.s, ~"'" + char::escape_default(ch as char) + ~"'");
@ -1705,7 +1705,7 @@ fn print_literal(s: ps, &&lit: @ast::lit) {
fn lit_to_str(l: @ast::lit) -> ~str { return to_str(l, print_literal); } fn lit_to_str(l: @ast::lit) -> ~str { return to_str(l, print_literal); }
fn next_lit(s: ps, pos: uint) -> option<comments::lit> { fn next_lit(s: ps, pos: uint) -> option<comments::lit> {
alt s.literals { match s.literals {
some(lits) => { some(lits) => {
while s.cur_lit < vec::len(lits) { while s.cur_lit < vec::len(lits) {
let ltrl = lits[s.cur_lit]; let ltrl = lits[s.cur_lit];
@ -1721,7 +1721,7 @@ fn next_lit(s: ps, pos: uint) -> option<comments::lit> {
fn maybe_print_comment(s: ps, pos: uint) { fn maybe_print_comment(s: ps, pos: uint) {
loop { loop {
alt next_comment(s) { match next_comment(s) {
some(cmnt) => { some(cmnt) => {
if cmnt.pos < pos { if cmnt.pos < pos {
print_comment(s, cmnt); print_comment(s, cmnt);
@ -1734,7 +1734,7 @@ fn maybe_print_comment(s: ps, pos: uint) {
} }
fn print_comment(s: ps, cmnt: comments::cmnt) { fn print_comment(s: ps, cmnt: comments::cmnt) {
alt cmnt.style { match cmnt.style {
comments::mixed => { comments::mixed => {
assert (vec::len(cmnt.lines) == 1u); assert (vec::len(cmnt.lines) == 1u);
zerobreak(s.s); zerobreak(s.s);
@ -1767,7 +1767,7 @@ fn print_comment(s: ps, cmnt: comments::cmnt) {
comments::blank_line => { comments::blank_line => {
// We need to do at least one, possibly two hardbreaks. // We need to do at least one, possibly two hardbreaks.
let is_semi = let is_semi =
alt s.s.last_token() { match s.s.last_token() {
pp::STRING(s, _) => *s == ~";", pp::STRING(s, _) => *s == ~";",
_ => false _ => false
}; };
@ -1792,7 +1792,7 @@ fn to_str<T>(t: T, f: fn@(ps, T)) -> ~str {
} }
fn next_comment(s: ps) -> option<comments::cmnt> { fn next_comment(s: ps) -> option<comments::cmnt> {
alt s.comments { match s.comments {
some(cmnts) => { some(cmnts) => {
if s.cur_cmnt < vec::len(cmnts) { if s.cur_cmnt < vec::len(cmnts) {
return some(cmnts[s.cur_cmnt]); return some(cmnts[s.cur_cmnt]);
@ -1803,14 +1803,14 @@ fn next_comment(s: ps) -> option<comments::cmnt> {
} }
fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str { fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str {
alt opt_p { match opt_p {
none => ~"fn", none => ~"fn",
some(p) => proto_to_str(p) some(p) => proto_to_str(p)
} }
} }
pure fn purity_to_str(p: ast::purity) -> ~str { pure fn purity_to_str(p: ast::purity) -> ~str {
alt p { match p {
ast::impure_fn => ~"impure", ast::impure_fn => ~"impure",
ast::unsafe_fn => ~"unsafe", ast::unsafe_fn => ~"unsafe",
ast::pure_fn => ~"pure", ast::pure_fn => ~"pure",
@ -1819,14 +1819,14 @@ pure fn purity_to_str(p: ast::purity) -> ~str {
} }
fn print_purity(s: ps, p: ast::purity) { fn print_purity(s: ps, p: ast::purity) {
alt p { match p {
ast::impure_fn => (), ast::impure_fn => (),
_ => word_nbsp(s, purity_to_str(p)) _ => word_nbsp(s, purity_to_str(p))
} }
} }
fn proto_to_str(p: ast::proto) -> ~str { fn proto_to_str(p: ast::proto) -> ~str {
return alt p { return match p {
ast::proto_bare => ~"extern fn", ast::proto_bare => ~"extern fn",
ast::proto_block => ~"fn&", ast::proto_block => ~"fn&",
ast::proto_uniq => ~"fn~", ast::proto_uniq => ~"fn~",

View file

@ -27,7 +27,7 @@ trait interner<T: const copy> {
impl <T: const copy> of interner<T> for hash_interner<T> { impl <T: const copy> of interner<T> for hash_interner<T> {
fn intern(val: T) -> uint { fn intern(val: T) -> uint {
alt self.map.find(val) { match self.map.find(val) {
some(idx) => return idx, some(idx) => return idx,
none => { none => {
let new_idx = self.vect.len(); let new_idx = self.vect.len();

View file

@ -25,7 +25,7 @@ enum fn_kind {
} }
fn name_of_fn(fk: fn_kind) -> ident { fn name_of_fn(fk: fn_kind) -> ident {
alt fk { match fk {
fk_item_fn(name, _) | fk_method(name, _, _) fk_item_fn(name, _) | fk_method(name, _, _)
| fk_ctor(name, _, _, _, _) => /* FIXME (#2543) */ copy name, | fk_ctor(name, _, _, _, _) => /* FIXME (#2543) */ copy name,
fk_anon(*) | fk_fn_block(*) => @~"anon", fk_anon(*) | fk_fn_block(*) => @~"anon",
@ -34,7 +34,7 @@ fn name_of_fn(fk: fn_kind) -> ident {
} }
fn tps_of_fn(fk: fn_kind) -> ~[ty_param] { fn tps_of_fn(fk: fn_kind) -> ~[ty_param] {
alt fk { match fk {
fk_item_fn(_, tps) | fk_method(_, tps, _) fk_item_fn(_, tps) | fk_method(_, tps, _)
| fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) => { | fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) => {
/* FIXME (#2543) */ copy tps /* FIXME (#2543) */ copy tps
@ -89,7 +89,7 @@ fn visit_crate<E>(c: crate, e: E, v: vt<E>) {
} }
fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
alt cd.node { match cd.node {
cdir_src_mod(_, _) => (), cdir_src_mod(_, _) => (),
cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| { cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| {
visit_crate_directive(cdir, e, v); visit_crate_directive(cdir, e, v);
@ -109,14 +109,14 @@ fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { }
fn visit_local<E>(loc: @local, e: E, v: vt<E>) { fn visit_local<E>(loc: @local, e: E, v: vt<E>) {
v.visit_pat(loc.node.pat, e, v); v.visit_pat(loc.node.pat, e, v);
v.visit_ty(loc.node.ty, e, v); v.visit_ty(loc.node.ty, e, v);
alt loc.node.init { match loc.node.init {
none => (), none => (),
some(i) => v.visit_expr(i.expr, e, v) some(i) => v.visit_expr(i.expr, e, v)
} }
} }
fn visit_item<E>(i: @item, e: E, v: vt<E>) { fn visit_item<E>(i: @item, e: E, v: vt<E>) {
alt i.node { match i.node {
item_const(t, ex) => { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } item_const(t, ex) => { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
item_fn(decl, tp, body) => { item_fn(decl, tp, body) => {
v.visit_fn(fk_item_fn(/* FIXME (#2543) */ copy i.ident, v.visit_fn(fk_item_fn(/* FIXME (#2543) */ copy i.ident,
@ -175,7 +175,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
} }
fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) { fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) {
alt cm.node { match cm.node {
instance_var(_, t, _, _, _) => v.visit_ty(t, e, v), instance_var(_, t, _, _, _) => v.visit_ty(t, e, v),
class_method(m) => visit_method_helper(m, e, v) class_method(m) => visit_method_helper(m, e, v)
} }
@ -184,7 +184,7 @@ fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) {
fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {} fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {}
fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
alt t.node { match t.node {
ty_box(mt) | ty_uniq(mt) | ty_box(mt) | ty_uniq(mt) |
ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => { ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => {
v.visit_ty(mt.ty, e, v); v.visit_ty(mt.ty, e, v);
@ -213,7 +213,7 @@ fn visit_path<E>(p: @path, e: E, v: vt<E>) {
} }
fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
alt p.node { match p.node {
pat_enum(path, children) => { pat_enum(path, children) => {
visit_path(path, e, v); visit_path(path, e, v);
do option::iter(children) |children| { do option::iter(children) |children| {
@ -237,7 +237,7 @@ fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
} }
fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) { fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
alt ni.node { match ni.node {
foreign_item_fn(fd, tps) => { foreign_item_fn(fd, tps) => {
v.visit_ty_params(tps, e, v); v.visit_ty_params(tps, e, v);
visit_fn_decl(fd, e, v); visit_fn_decl(fd, e, v);
@ -248,7 +248,7 @@ fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) { fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) {
for tps.each |tp| { for tps.each |tp| {
for vec::each(*tp.bounds) |bound| { for vec::each(*tp.bounds) |bound| {
alt bound { match bound {
bound_trait(t) => v.visit_ty(t, e, v), bound_trait(t) => v.visit_ty(t, e, v),
bound_copy | bound_send | bound_const | bound_owned => () bound_copy | bound_send | bound_const | bound_owned => ()
} }
@ -304,7 +304,7 @@ fn visit_ty_method<E>(m: ty_method, e: E, v: vt<E>) {
} }
fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) { fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) {
alt m { match m {
required(ty_m) => v.visit_ty_method(ty_m, e, v), required(ty_m) => v.visit_ty_method(ty_m, e, v),
provided(m) => visit_method_helper(m, e, v) provided(m) => visit_method_helper(m, e, v)
} }
@ -317,7 +317,7 @@ fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) {
} }
fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
alt s.node { match s.node {
stmt_decl(d, _) => v.visit_decl(d, e, v), stmt_decl(d, _) => v.visit_decl(d, e, v),
stmt_expr(ex, _) => v.visit_expr(ex, e, v), stmt_expr(ex, _) => v.visit_expr(ex, e, v),
stmt_semi(ex, _) => v.visit_expr(ex, e, v) stmt_semi(ex, _) => v.visit_expr(ex, e, v)
@ -325,7 +325,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
} }
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
alt d.node { match d.node {
decl_local(locs) => for locs.each |loc| { decl_local(locs) => for locs.each |loc| {
v.visit_local(loc, e, v) v.visit_local(loc, e, v)
} }
@ -334,7 +334,7 @@ fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
} }
fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) { fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) {
alt eo { none => (), some(ex) => v.visit_expr(ex, e, v) } match eo { none => (), some(ex) => v.visit_expr(ex, e, v) }
} }
fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) { fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) {
@ -342,7 +342,7 @@ fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) {
} }
fn visit_mac<E>(m: mac, e: E, v: vt<E>) { fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
alt m.node { match m.node {
ast::mac_invoc(pth, arg, body) => { ast::mac_invoc(pth, arg, body) => {
option::map(arg, |arg| v.visit_expr(arg, e, v)); } option::map(arg, |arg| v.visit_expr(arg, e, v)); }
ast::mac_invoc_tt(pth, tt) => { /* no user-serviceable parts inside */ } ast::mac_invoc_tt(pth, tt) => { /* no user-serviceable parts inside */ }
@ -353,7 +353,7 @@ fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
} }
fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
alt ex.node { match ex.node {
expr_vstore(x, _) => v.visit_expr(x, e, v), expr_vstore(x, _) => v.visit_expr(x, e, v),
expr_vec(es, _) => visit_exprs(es, e, v), expr_vec(es, _) => visit_exprs(es, e, v),
expr_repeat(element, count, _) => { expr_repeat(element, count, _) => {

View file

@ -61,7 +61,7 @@ mod write {
// and the extension to use. // and the extension to use.
fn mk_intermediate_name(output_path: ~str, extension: ~str) -> fn mk_intermediate_name(output_path: ~str, extension: ~str) ->
~str unsafe { ~str unsafe {
let stem = alt str::find_char(output_path, '.') { let stem = match str::find_char(output_path, '.') {
some(dot_pos) => str::slice(output_path, 0u, dot_pos), some(dot_pos) => str::slice(output_path, 0u, dot_pos),
none => output_path none => output_path
}; };
@ -82,7 +82,7 @@ mod write {
// specified. // specified.
if opts.save_temps { if opts.save_temps {
alt opts.output_type { match opts.output_type {
output_type_bitcode => { output_type_bitcode => {
if opts.optimize != 0u { if opts.optimize != 0u {
let filename = mk_intermediate_name(output, ~"no-opt.bc"); let filename = mk_intermediate_name(output, ~"no-opt.bc");
@ -146,7 +146,7 @@ mod write {
let LLVMOptDefault = 2 as c_int; // -O2, -Os let LLVMOptDefault = 2 as c_int; // -O2, -Os
let LLVMOptAggressive = 3 as c_int; // -O3 let LLVMOptAggressive = 3 as c_int; // -O3
let mut CodeGenOptLevel = alt check opts.optimize { let mut CodeGenOptLevel = match check opts.optimize {
0u => LLVMOptNone, 0u => LLVMOptNone,
1u => LLVMOptLess, 1u => LLVMOptLess,
2u => LLVMOptDefault, 2u => LLVMOptDefault,
@ -323,12 +323,12 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
attr::require_unique_names(sess.diagnostic(), linkage_metas); attr::require_unique_names(sess.diagnostic(), linkage_metas);
for linkage_metas.each |meta| { for linkage_metas.each |meta| {
if *attr::get_meta_item_name(meta) == ~"name" { if *attr::get_meta_item_name(meta) == ~"name" {
alt attr::get_meta_item_value_str(meta) { match attr::get_meta_item_value_str(meta) {
some(v) => { name = some(v); } some(v) => { name = some(v); }
none => vec::push(cmh_items, meta) none => vec::push(cmh_items, meta)
} }
} else if *attr::get_meta_item_name(meta) == ~"vers" { } else if *attr::get_meta_item_name(meta) == ~"vers" {
alt attr::get_meta_item_value_str(meta) { match attr::get_meta_item_value_str(meta) {
some(v) => { vers = some(v); } some(v) => { vers = some(v); }
none => vec::push(cmh_items, meta) none => vec::push(cmh_items, meta)
} }
@ -355,7 +355,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
symbol_hasher.reset(); symbol_hasher.reset();
for cmh_items.each |m_| { for cmh_items.each |m_| {
let m = m_; let m = m_;
alt m.node { match m.node {
ast::meta_name_value(key, value) => { ast::meta_name_value(key, value) => {
symbol_hasher.write_str(len_and_str(*key)); symbol_hasher.write_str(len_and_str(*key));
symbol_hasher.write_str(len_and_str_lit(value)); symbol_hasher.write_str(len_and_str_lit(value));
@ -385,7 +385,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
fn crate_meta_name(sess: session, _crate: ast::crate, fn crate_meta_name(sess: session, _crate: ast::crate,
output: ~str, metas: provided_metas) -> @~str { output: ~str, metas: provided_metas) -> @~str {
return alt metas.name { return match metas.name {
some(v) => v, some(v) => v,
none => { none => {
let name = let name =
@ -407,7 +407,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
fn crate_meta_vers(sess: session, _crate: ast::crate, fn crate_meta_vers(sess: session, _crate: ast::crate,
metas: provided_metas) -> @~str { metas: provided_metas) -> @~str {
return alt metas.vers { return match metas.vers {
some(v) => v, some(v) => v,
none => { none => {
let vers = ~"0.0"; let vers = ~"0.0";
@ -451,7 +451,7 @@ fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
} }
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str { fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
alt ccx.type_hashcodes.find(t) { match ccx.type_hashcodes.find(t) {
some(h) => return h, some(h) => return h,
none => { none => {
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta); let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
@ -467,7 +467,7 @@ fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
fn sanitize(s: ~str) -> ~str { fn sanitize(s: ~str) -> ~str {
let mut result = ~""; let mut result = ~"";
do str::chars_iter(s) |c| { do str::chars_iter(s) |c| {
alt c { match c {
'@' => result += ~"_sbox_", '@' => result += ~"_sbox_",
'~' => result += ~"_ubox_", '~' => result += ~"_ubox_",
'*' => result += ~"_ptr_", '*' => result += ~"_ptr_",
@ -503,7 +503,7 @@ fn mangle(ss: path) -> ~str {
let mut n = ~"_ZN"; // Begin name-sequence. let mut n = ~"_ZN"; // Begin name-sequence.
for ss.each |s| { for ss.each |s| {
alt s { path_name(s) | path_mod(s) => { match s { path_name(s) | path_mod(s) => {
let sani = sanitize(*s); let sani = sanitize(*s);
n += fmt!{"%u%s", str::len(sani), sani}; n += fmt!{"%u%s", str::len(sani), sani};
} } } }
@ -566,7 +566,7 @@ fn link_binary(sess: session,
vec::pop(parts); vec::pop(parts);
return str::connect(parts, ~"."); return str::connect(parts, ~".");
} }
return alt config.os { return match config.os {
session::os_macos => rmext(rmlib(filename)), session::os_macos => rmext(rmlib(filename)),
session::os_linux => rmext(rmlib(filename)), session::os_linux => rmext(rmlib(filename)),
session::os_freebsd => rmext(rmlib(filename)), session::os_freebsd => rmext(rmlib(filename)),

View file

@ -7,7 +7,7 @@ import metadata::filesearch;
export get_rpath_flags; export get_rpath_flags;
pure fn not_win32(os: session::os) -> bool { pure fn not_win32(os: session::os) -> bool {
alt os { match os {
session::os_win32 => false, session::os_win32 => false,
_ => true _ => true
} }
@ -108,7 +108,7 @@ fn get_rpath_relative_to_output(os: session::os,
assert not_win32(os); assert not_win32(os);
// Mac doesn't appear to support $ORIGIN // Mac doesn't appear to support $ORIGIN
let prefix = alt os { let prefix = match os {
session::os_linux => ~"$ORIGIN" + path::path_sep(), session::os_linux => ~"$ORIGIN" + path::path_sep(),
session::os_freebsd => ~"$ORIGIN" + path::path_sep(), session::os_freebsd => ~"$ORIGIN" + path::path_sep(),
session::os_macos => ~"@executable_path" + path::path_sep(), session::os_macos => ~"@executable_path" + path::path_sep(),

View file

@ -8,7 +8,7 @@ fn get_target_strs(target_os: session::os) -> target_strs::t {
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)), meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
data_layout: alt target_os { data_layout: match target_os {
session::os_macos => { session::os_macos => {
~"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" + ~"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" +
~"-i32:32:32-i64:32:64" + ~"-i32:32:32-i64:32:64" +
@ -29,7 +29,7 @@ fn get_target_strs(target_os: session::os) -> target_strs::t {
} }
}, },
target_triple: alt target_os { target_triple: match target_os {
session::os_macos => ~"i686-apple-darwin", session::os_macos => ~"i686-apple-darwin",
session::os_win32 => ~"i686-pc-mingw32", session::os_win32 => ~"i686-pc-mingw32",
session::os_linux => ~"i686-unknown-linux-gnu", session::os_linux => ~"i686-unknown-linux-gnu",

View file

@ -8,7 +8,7 @@ fn get_target_strs(target_os: session::os) -> target_strs::t {
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)), meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
data_layout: alt target_os { data_layout: match target_os {
session::os_macos => { session::os_macos => {
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+ ~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+ ~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
@ -35,7 +35,7 @@ fn get_target_strs(target_os: session::os) -> target_strs::t {
} }
}, },
target_triple: alt target_os { target_triple: match target_os {
session::os_macos => ~"x86_64-apple-darwin", session::os_macos => ~"x86_64-apple-darwin",
session::os_win32 => ~"x86_64-pc-mingw32", session::os_win32 => ~"x86_64-pc-mingw32",
session::os_linux => ~"x86_64-unknown-linux-gnu", session::os_linux => ~"x86_64-unknown-linux-gnu",

View file

@ -26,7 +26,7 @@ enum pp_mode {ppm_normal, ppm_expanded, ppm_typed, ppm_identified,
fn anon_src() -> ~str { ~"<anon>" } fn anon_src() -> ~str { ~"<anon>" }
fn source_name(input: input) -> ~str { fn source_name(input: input) -> ~str {
alt input { match input {
file_input(ifile) => ifile, file_input(ifile) => ifile,
str_input(_) => anon_src() str_input(_) => anon_src()
} }
@ -34,7 +34,7 @@ fn source_name(input: input) -> ~str {
fn default_configuration(sess: session, argv0: ~str, input: input) -> fn default_configuration(sess: session, argv0: ~str, input: input) ->
ast::crate_cfg { ast::crate_cfg {
let libc = alt sess.targ_cfg.os { let libc = match sess.targ_cfg.os {
session::os_win32 => ~"msvcrt.dll", session::os_win32 => ~"msvcrt.dll",
session::os_macos => ~"libc.dylib", session::os_macos => ~"libc.dylib",
session::os_linux => ~"libc.so.6", session::os_linux => ~"libc.so.6",
@ -44,7 +44,7 @@ fn default_configuration(sess: session, argv0: ~str, input: input) ->
let mk = attr::mk_name_value_item_str; let mk = attr::mk_name_value_item_str;
let (arch,wordsz) = alt sess.targ_cfg.arch { let (arch,wordsz) = match sess.targ_cfg.arch {
session::arch_x86 => (~"x86",~"32"), session::arch_x86 => (~"x86",~"32"),
session::arch_x86_64 => (~"x86_64",~"64"), session::arch_x86_64 => (~"x86_64",~"64"),
session::arch_arm => (~"arm",~"32") session::arch_arm => (~"arm",~"32")
@ -99,7 +99,7 @@ enum input {
fn parse_input(sess: session, cfg: ast::crate_cfg, input: input) fn parse_input(sess: session, cfg: ast::crate_cfg, input: input)
-> @ast::crate { -> @ast::crate {
alt input { match input {
file_input(file) => { file_input(file) => {
parse::parse_crate_from_file(file, cfg, sess.parse_sess) parse::parse_crate_from_file(file, cfg, sess.parse_sess)
} }
@ -270,13 +270,13 @@ fn compile_input(sess: session, cfg: ast::crate_cfg, input: input,
fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input, fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
ppm: pp_mode) { ppm: pp_mode) {
fn ann_paren_for_expr(node: pprust::ann_node) { fn ann_paren_for_expr(node: pprust::ann_node) {
alt node { match node {
pprust::node_expr(s, expr) => pprust::popen(s), pprust::node_expr(s, expr) => pprust::popen(s),
_ => () _ => ()
} }
} }
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) { fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
alt node { match node {
pprust::node_expr(s, expr) => { pprust::node_expr(s, expr) => {
pp::space(s.s); pp::space(s.s);
pp::word(s.s, ~"as"); pp::word(s.s, ~"as");
@ -288,7 +288,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
} }
} }
fn ann_identified_post(node: pprust::ann_node) { fn ann_identified_post(node: pprust::ann_node) {
alt node { match node {
pprust::node_item(s, item) => { pprust::node_item(s, item) => {
pp::space(s.s); pp::space(s.s);
pprust::synth_comment(s, int::to_str(item.id, 10u)); pprust::synth_comment(s, int::to_str(item.id, 10u));
@ -314,14 +314,14 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
// to collect comments and literals, and we need to support reading // to collect comments and literals, and we need to support reading
// from stdin, we're going to just suck the source into a string // from stdin, we're going to just suck the source into a string
// so both the parser and pretty-printer can use it. // so both the parser and pretty-printer can use it.
let upto = alt ppm { let upto = match ppm {
ppm_expanded | ppm_expanded_identified => cu_expand, ppm_expanded | ppm_expanded_identified => cu_expand,
ppm_typed => cu_typeck, ppm_typed => cu_typeck,
_ => cu_parse _ => cu_parse
}; };
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none); let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
let ann = alt ppm { let ann = match ppm {
ppm_typed => { ppm_typed => {
{pre: ann_paren_for_expr, {pre: ann_paren_for_expr,
post: |a| ann_typed_post(option::get(tcx), a) } post: |a| ann_typed_post(option::get(tcx), a) }
@ -371,21 +371,21 @@ fn get_arch(triple: ~str) -> option<session::arch> {
fn build_target_config(sopts: @session::options, fn build_target_config(sopts: @session::options,
demitter: diagnostic::emitter) -> @session::config { demitter: diagnostic::emitter) -> @session::config {
let os = alt get_os(sopts.target_triple) { let os = match get_os(sopts.target_triple) {
some(os) => os, some(os) => os,
none => early_error(demitter, ~"unknown operating system") none => early_error(demitter, ~"unknown operating system")
}; };
let arch = alt get_arch(sopts.target_triple) { let arch = match get_arch(sopts.target_triple) {
some(arch) => arch, some(arch) => arch,
none => early_error(demitter, none => early_error(demitter,
~"unknown architecture: " + sopts.target_triple) ~"unknown architecture: " + sopts.target_triple)
}; };
let (int_type, uint_type, float_type) = alt arch { let (int_type, uint_type, float_type) = match arch {
session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64), session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64), session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64) session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
}; };
let target_strs = alt arch { let target_strs = match arch {
session::arch_x86 => x86::get_target_strs(os), session::arch_x86 => x86::get_target_strs(os),
session::arch_x86_64 => x86_64::get_target_strs(os), session::arch_x86_64 => x86_64::get_target_strs(os),
session::arch_arm => x86::get_target_strs(os) session::arch_arm => x86::get_target_strs(os)
@ -438,7 +438,7 @@ fn build_session_options(matches: getopts::matches,
getopts::opt_strs(matches, level_name)); getopts::opt_strs(matches, level_name));
for flags.each |lint_name| { for flags.each |lint_name| {
let lint_name = str::replace(lint_name, ~"-", ~"_"); let lint_name = str::replace(lint_name, ~"-", ~"_");
alt lint_dict.find(lint_name) { match lint_dict.find(lint_name) {
none => { none => {
early_error(demitter, fmt!{"unknown %s flag: %s", early_error(demitter, fmt!{"unknown %s flag: %s",
level_name, lint_name}); level_name, lint_name});
@ -486,7 +486,7 @@ fn build_session_options(matches: getopts::matches,
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot"); let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
let target_opt = getopts::opt_maybe_str(matches, ~"target"); let target_opt = getopts::opt_maybe_str(matches, ~"target");
let save_temps = getopts::opt_present(matches, ~"save-temps"); let save_temps = getopts::opt_present(matches, ~"save-temps");
alt output_type { match output_type {
// unless we're emitting huamn-readable assembly, omit comments. // unless we're emitting huamn-readable assembly, omit comments.
link::output_type_llvm_assembly | link::output_type_assembly => (), link::output_type_llvm_assembly | link::output_type_assembly => (),
_ => debugging_opts |= session::no_asm_comments _ => debugging_opts |= session::no_asm_comments
@ -498,7 +498,7 @@ fn build_session_options(matches: getopts::matches,
} }
2u 2u
} else if opt_present(matches, ~"opt-level") { } else if opt_present(matches, ~"opt-level") {
alt getopts::opt_str(matches, ~"opt-level") { match getopts::opt_str(matches, ~"opt-level") {
~"0" => 0u, ~"0" => 0u,
~"1" => 1u, ~"1" => 1u,
~"2" => 2u, ~"2" => 2u,
@ -510,7 +510,7 @@ fn build_session_options(matches: getopts::matches,
} }
} else { 0u }; } else { 0u };
let target = let target =
alt target_opt { match target_opt {
none => host_triple(), none => host_triple(),
some(s) => s some(s) => s
}; };
@ -577,7 +577,7 @@ fn build_session_(sopts: @session::options,
} }
fn parse_pretty(sess: session, &&name: ~str) -> pp_mode { fn parse_pretty(sess: session, &&name: ~str) -> pp_mode {
alt name { match name {
~"normal" => ppm_normal, ~"normal" => ppm_normal,
~"expanded" => ppm_expanded, ~"expanded" => ppm_expanded,
~"typed" => ppm_typed, ~"typed" => ppm_typed,
@ -628,7 +628,7 @@ fn build_output_filenames(input: input,
let obj_suffix = let obj_suffix =
alt sopts.output_type { match sopts.output_type {
link::output_type_none => ~"none", link::output_type_none => ~"none",
link::output_type_bitcode => ~"bc", link::output_type_bitcode => ~"bc",
link::output_type_assembly => ~"s", link::output_type_assembly => ~"s",
@ -637,20 +637,20 @@ fn build_output_filenames(input: input,
link::output_type_object | link::output_type_exe => ~"o" link::output_type_object | link::output_type_exe => ~"o"
}; };
alt ofile { match ofile {
none => { none => {
// "-" as input file will cause the parser to read from stdin so we // "-" as input file will cause the parser to read from stdin so we
// have to make up a name // have to make up a name
// We want to toss everything after the final '.' // We want to toss everything after the final '.'
let dirname = alt odir { let dirname = match odir {
some(d) => d, some(d) => d,
none => alt input { none => match input {
str_input(_) => os::getcwd(), str_input(_) => os::getcwd(),
file_input(ifile) => path::dirname(ifile) file_input(ifile) => path::dirname(ifile)
} }
}; };
let base_filename = alt input { let base_filename = match input {
file_input(ifile) => { file_input(ifile) => {
let (path, _) = path::splitext(ifile); let (path, _) = path::splitext(ifile);
path::basename(path) path::basename(path)
@ -714,7 +714,7 @@ mod test {
#[test] #[test]
fn test_switch_implies_cfg_test() { fn test_switch_implies_cfg_test() {
let matches = let matches =
alt getopts::getopts(~[~"--test"], opts()) { match getopts::getopts(~[~"--test"], opts()) {
ok(m) => m, ok(m) => m,
err(f) => fail ~"test_switch_implies_cfg_test: " + err(f) => fail ~"test_switch_implies_cfg_test: " +
getopts::fail_str(f) getopts::fail_str(f)
@ -730,7 +730,7 @@ mod test {
#[test] #[test]
fn test_switch_implies_cfg_test_unless_cfg_test() { fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches = let matches =
alt getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) { match getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) {
ok(m) => m, ok(m) => m,
err(f) => { err(f) => {
fail ~"test_switch_implies_cfg_test_unless_cfg_test: " + fail ~"test_switch_implies_cfg_test_unless_cfg_test: " +

Some files were not shown because too many files have changed in this diff Show more