mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
Move the world over to using the new style string literals and types. Closes #2907.
This commit is contained in:
parent
5c5065e8bd
commit
92743dc2a6
80
doc/rust.md
80
doc/rust.md
@ -449,7 +449,7 @@ Two examples of paths with type arguments:
|
||||
# import std::map;
|
||||
# fn f() {
|
||||
# fn id<T:copy>(t: T) -> T { t }
|
||||
type t = map::hashmap<int,str>; // Type arguments used in a type expression
|
||||
type t = map::hashmap<int,~str>; // Type arguments used in a type expression
|
||||
let x = id::<int>(10); // Type arguments used in a call expression
|
||||
# }
|
||||
~~~~
|
||||
@ -563,7 +563,7 @@ a referencing crate file, or by the filename of the source file itself.
|
||||
|
||||
A source file that contains a `main` function can be compiled to an
|
||||
executable. If a `main` function is present, it must have no [type parameters](#type-parameters)
|
||||
and no [constraints](#constraints). Its return type must be [`nil`](#primitive-types) and it must either have no arguments, or a single argument of type `[str]`.
|
||||
and no [constraints](#constraints). Its return type must be [`nil`](#primitive-types) and it must either have no arguments, or a single argument of type `[~str]`.
|
||||
|
||||
# Items and attributes
|
||||
|
||||
@ -745,8 +745,8 @@ fn main() {
|
||||
log(info, some(1.0));
|
||||
|
||||
// Equivalent to 'log(core::info,
|
||||
// core::str::hash(core::str::slice("foo", 0u, 1u)));'
|
||||
log(info, hash(slice("foo", 0u, 1u)));
|
||||
// core::str::hash(core::str::slice(~"foo", 0u, 1u)));'
|
||||
log(info, hash(slice(~"foo", 0u, 1u)));
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -861,7 +861,7 @@ A special kind of function can be declared with a `!` character where the
|
||||
output slot type would normally be. For example:
|
||||
|
||||
~~~~
|
||||
fn my_err(s: str) -> ! {
|
||||
fn my_err(s: ~str) -> ! {
|
||||
log(info, s);
|
||||
fail;
|
||||
}
|
||||
@ -881,14 +881,14 @@ were declared without the `!` annotation, the following code would not
|
||||
typecheck:
|
||||
|
||||
~~~~
|
||||
# fn my_err(s: str) -> ! { fail }
|
||||
# fn my_err(s: ~str) -> ! { fail }
|
||||
|
||||
fn f(i: int) -> int {
|
||||
if i == 42 {
|
||||
ret 42;
|
||||
}
|
||||
else {
|
||||
my_err("Bad number!");
|
||||
my_err(~"Bad number!");
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
@ -1497,7 +1497,7 @@ string, boolean value, or the nil value.
|
||||
|
||||
~~~~~~~~ {.literals}
|
||||
(); // nil type
|
||||
"hello"; // string type
|
||||
~"hello"; // string type
|
||||
'5'; // character type
|
||||
5; // integer type
|
||||
~~~~~~~~
|
||||
@ -1510,7 +1510,7 @@ values.
|
||||
|
||||
~~~~~~~~ {.tuple}
|
||||
(0f, 4.5f);
|
||||
("a", 4u, true);
|
||||
(~"a", 4u, true);
|
||||
~~~~~~~~
|
||||
|
||||
### Record expressions
|
||||
@ -1529,8 +1529,8 @@ written before its name.
|
||||
|
||||
~~~~
|
||||
{x: 10f, y: 20f};
|
||||
{name: "Joe", age: 35u, score: 100_000};
|
||||
{ident: "X", mut count: 0u};
|
||||
{name: ~"Joe", age: 35u, score: 100_000};
|
||||
{ident: ~"X", mut count: 0u};
|
||||
~~~~
|
||||
|
||||
The order of the fields in a record expression is significant, and
|
||||
@ -1594,7 +1594,7 @@ When no mutability is specified, the vector is immutable.
|
||||
|
||||
~~~~
|
||||
~[1, 2, 3, 4];
|
||||
~["a", "b", "c", "d"];
|
||||
~[~"a", ~"b", ~"c", ~"d"];
|
||||
~[mut 0u8, 0u8, 0u8, 0u8];
|
||||
~~~~
|
||||
|
||||
@ -1620,7 +1620,7 @@ task in a _failing state_.
|
||||
|
||||
(~[1, 2, 3, 4])[0];
|
||||
(~[mut 'x', 'y'])[1] = 'z';
|
||||
(~["a", "b"])[10]; // fails
|
||||
(~[~"a", ~"b"])[10]; // fails
|
||||
|
||||
# }
|
||||
~~~~
|
||||
@ -1965,7 +1965,7 @@ An example:
|
||||
# let println = io::println;
|
||||
|
||||
while i < 10 {
|
||||
println("hello\n");
|
||||
println(~"hello\n");
|
||||
i = i + 1;
|
||||
}
|
||||
~~~~
|
||||
@ -2103,9 +2103,9 @@ enum list<X> { nil, cons(X, @list<X>) }
|
||||
let x: list<int> = cons(10, @cons(11, @nil));
|
||||
|
||||
alt x {
|
||||
cons(_, @nil) { fail "singleton list"; }
|
||||
cons(_, @nil) { fail ~"singleton list"; }
|
||||
cons(*) { ret; }
|
||||
nil { fail "empty list"; }
|
||||
nil { fail ~"empty list"; }
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -2152,19 +2152,19 @@ When matching fields of a record, the fields being matched are specified
|
||||
first, then a placeholder (`_`) represents the remaining fields.
|
||||
|
||||
~~~~
|
||||
# type options = {choose: bool, size: str};
|
||||
# type player = {player: str, stats: (), options: options};
|
||||
# type options = {choose: bool, size: ~str};
|
||||
# type player = {player: ~str, stats: (), options: options};
|
||||
# fn load_stats() { }
|
||||
# fn choose_player(r: player) { }
|
||||
# fn next_player() { }
|
||||
|
||||
fn main() {
|
||||
let r = {
|
||||
player: "ralph",
|
||||
player: ~"ralph",
|
||||
stats: load_stats(),
|
||||
options: {
|
||||
choose: true,
|
||||
size: "small"
|
||||
size: ~"small"
|
||||
}
|
||||
};
|
||||
|
||||
@ -2172,8 +2172,8 @@ fn main() {
|
||||
{options: {choose: true, _}, _} {
|
||||
choose_player(r)
|
||||
}
|
||||
{player: p, options: {size: "small", _}, _} {
|
||||
log(info, p + " is small");
|
||||
{player: p, options: {size: ~"small", _}, _} {
|
||||
log(info, p + ~" is small");
|
||||
}
|
||||
_ {
|
||||
next_player();
|
||||
@ -2189,9 +2189,9 @@ range of values may be specified with `to`. For example:
|
||||
# let x = 2;
|
||||
|
||||
let message = alt x {
|
||||
0 | 1 { "not many" }
|
||||
2 to 9 { "a few" }
|
||||
_ { "lots" }
|
||||
0 | 1 { ~"not many" }
|
||||
2 to 9 { ~"a few" }
|
||||
_ { ~"lots" }
|
||||
};
|
||||
~~~~
|
||||
|
||||
@ -2250,9 +2250,9 @@ the `note` to the internal logging diagnostic buffer.
|
||||
An example of a `note` expression:
|
||||
|
||||
~~~~{.xfail-test}
|
||||
fn read_file_lines(path: str) -> ~[str] {
|
||||
fn read_file_lines(path: ~str) -> ~[~str] {
|
||||
note path;
|
||||
let r: [str];
|
||||
let r: [~str];
|
||||
let f: file = open_read(path);
|
||||
lines(f) |s| {
|
||||
r += ~[s];
|
||||
@ -2323,13 +2323,13 @@ The following examples all produce the same output, logged at the `error`
|
||||
logging level:
|
||||
|
||||
~~~~
|
||||
# let filename = "bulbasaur";
|
||||
# let filename = ~"bulbasaur";
|
||||
|
||||
// Full version, logging a value.
|
||||
log(core::error, "file not found: " + filename);
|
||||
log(core::error, ~"file not found: " + filename);
|
||||
|
||||
// Log-level abbreviated, since core::* is imported by default.
|
||||
log(error, "file not found: " + filename);
|
||||
log(error, ~"file not found: " + filename);
|
||||
|
||||
// Formatting the message using a format-string and #fmt
|
||||
log(error, #fmt("file not found: %s", filename));
|
||||
@ -2627,12 +2627,12 @@ type `float` may not be equal to the largest *supported* floating-point type.
|
||||
|
||||
### Textual types
|
||||
|
||||
The types `char` and `str` hold textual data.
|
||||
The types `char` and `~str` hold textual data.
|
||||
|
||||
A value of type `char` is a Unicode character, represented as a 32-bit
|
||||
unsigned word holding a UCS-4 codepoint.
|
||||
|
||||
A value of type `str` is a Unicode string, represented as a vector of 8-bit
|
||||
A value of type `~str` is a Unicode string, represented as a vector of 8-bit
|
||||
unsigned bytes holding a sequence of UTF-8 codepoints.
|
||||
|
||||
|
||||
@ -2670,10 +2670,10 @@ order specified by the tuple type.
|
||||
An example of a tuple type and its use:
|
||||
|
||||
~~~~
|
||||
type pair = (int,str);
|
||||
let p: pair = (10,"hello");
|
||||
type pair = (int,~str);
|
||||
let p: pair = (10,~"hello");
|
||||
let (a, b) = p;
|
||||
assert b != "world";
|
||||
assert b != ~"world";
|
||||
~~~~
|
||||
|
||||
### Vector types
|
||||
@ -2837,7 +2837,7 @@ For example, this code:
|
||||
~~~~~~~~
|
||||
# let mut s;
|
||||
|
||||
s = "hello, world";
|
||||
s = ~"hello, world";
|
||||
io::println(s);
|
||||
~~~~~~~~
|
||||
|
||||
@ -2862,8 +2862,8 @@ Whereas this code:
|
||||
|
||||
|
||||
~~~~~~~~
|
||||
# fn x() -> str { "" }
|
||||
# fn y() -> str { "" }
|
||||
# fn x() -> ~str { ~"" }
|
||||
# fn y() -> ~str { ~"" }
|
||||
|
||||
io::println(x() + y());
|
||||
~~~~~~~~
|
||||
@ -3364,7 +3364,7 @@ An example of a send:
|
||||
~~~~
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
comm::send(ch, "hello, world");
|
||||
comm::send(ch, ~"hello, world");
|
||||
~~~~
|
||||
|
||||
|
||||
@ -3380,7 +3380,7 @@ An example of a *receive*:
|
||||
~~~~~~~~
|
||||
# let po = comm::port();
|
||||
# let ch = comm::chan(po);
|
||||
# comm::send(ch, "");
|
||||
# comm::send(ch, ~"");
|
||||
let s = comm::recv(po);
|
||||
~~~~~~~~
|
||||
|
||||
|
194
doc/tutorial.md
194
doc/tutorial.md
@ -84,8 +84,8 @@ fn main() {
|
||||
do listen |result_from_game| {
|
||||
|
||||
let times = 10;
|
||||
let player1 = "graydon";
|
||||
let player2 = "patrick";
|
||||
let player1 = ~"graydon";
|
||||
let player2 = ~"patrick";
|
||||
|
||||
for repeat(times) {
|
||||
// Start another task to play the game
|
||||
@ -102,7 +102,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn play_game(player1: str, player2: str) -> str {
|
||||
fn play_game(player1: ~str, player2: ~str) -> ~str {
|
||||
|
||||
// Our rock/paper/scissors types
|
||||
enum gesture {
|
||||
@ -117,7 +117,7 @@ fn main() {
|
||||
alt (pick(), pick()) {
|
||||
(rock, scissors) | (paper, rock) | (scissors, paper) { copy player1 }
|
||||
(scissors, rock) | (rock, paper) | (paper, scissors) { copy player2 }
|
||||
_ { "tie" }
|
||||
_ { ~"tie" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,8 +206,8 @@ Rust program files are, by convention, given the extension `.rs`. Say
|
||||
we have a file `hello.rs` containing this program:
|
||||
|
||||
~~~~
|
||||
fn main(args: ~[str]) {
|
||||
io::println("hello world from '" + args[0] + "'!");
|
||||
fn main(args: ~[~str]) {
|
||||
io::println(~"hello world from '" + args[0] + ~"'!");
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -220,7 +220,7 @@ If you modify the program to make it invalid (for example, by changing
|
||||
|
||||
~~~~ {.notrust}
|
||||
hello.rs:2:4: 2:16 error: unresolved name: io::print_it
|
||||
hello.rs:2 io::print_it("hello world from '" + args[0] + "'!");
|
||||
hello.rs:2 io::print_it(~"hello world from '" + args[0] + ~"'!");
|
||||
^~~~~~~~~~~~
|
||||
~~~~
|
||||
|
||||
@ -367,7 +367,7 @@ defined with `const`:
|
||||
use std;
|
||||
const repeat: uint = 5u;
|
||||
fn main() {
|
||||
let hi = "Hi!";
|
||||
let hi = ~"Hi!";
|
||||
let mut count = 0u;
|
||||
while count < repeat {
|
||||
io::println(hi);
|
||||
@ -437,7 +437,7 @@ The basic types are written like this:
|
||||
`char`
|
||||
: A character is a 32-bit Unicode code point.
|
||||
|
||||
`str`
|
||||
`~str`
|
||||
: String type. A string contains a UTF-8 encoded sequence of characters.
|
||||
|
||||
These can be combined in composite types, which will be described in
|
||||
@ -560,13 +560,13 @@ character escapes, using the backslash character:
|
||||
form the character code.
|
||||
|
||||
String literals allow the same escape sequences. They are written
|
||||
between double quotes (`"hello"`). Rust strings may contain newlines.
|
||||
between double quotes (`~"hello"`). Rust strings may contain newlines.
|
||||
When a newline is preceded by a backslash, it, and all white space
|
||||
following it, will not appear in the resulting string literal. So
|
||||
this is equivalent to `"abc"`:
|
||||
this is equivalent to `~"abc"`:
|
||||
|
||||
~~~~
|
||||
let s = "a\
|
||||
let s = ~"a\
|
||||
b\
|
||||
c";
|
||||
~~~~
|
||||
@ -649,7 +649,7 @@ one is `#fmt`, a printf-style text formatting macro that is expanded
|
||||
at compile time.
|
||||
|
||||
~~~~
|
||||
io::println(#fmt("%s is %d", "the answer", 42));
|
||||
io::println(#fmt("%s is %d", ~"the answer", 42));
|
||||
~~~~
|
||||
|
||||
`#fmt` supports most of the directives that [printf][pf] supports, but
|
||||
@ -676,11 +676,11 @@ compulsory, an optional `else` clause can be appended, and multiple
|
||||
|
||||
~~~~
|
||||
if false {
|
||||
io::println("that's odd");
|
||||
io::println(~"that's odd");
|
||||
} else if true {
|
||||
io::println("right");
|
||||
io::println(~"right");
|
||||
} else {
|
||||
io::println("neither true nor false");
|
||||
io::println(~"neither true nor false");
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -713,10 +713,10 @@ the value.
|
||||
~~~~
|
||||
# let my_number = 1;
|
||||
alt my_number {
|
||||
0 { io::println("zero"); }
|
||||
1 | 2 { io::println("one or two"); }
|
||||
3 to 10 { io::println("three to ten"); }
|
||||
_ { io::println("something else"); }
|
||||
0 { io::println(~"zero"); }
|
||||
1 | 2 { io::println(~"one or two"); }
|
||||
3 to 10 { io::println(~"three to ten"); }
|
||||
_ { io::println(~"something else"); }
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -822,7 +822,7 @@ failure; failure is nonrecoverable. It is, however, possible for
|
||||
running.
|
||||
|
||||
`fail` takes an optional argument specifying the reason for the
|
||||
failure. It must have type `str`.
|
||||
failure. It must have type `~str`.
|
||||
|
||||
In addition to the `fail` statement, the following circumstances cause
|
||||
task failure:
|
||||
@ -860,7 +860,7 @@ runtime will do its best to output a textual representation of the
|
||||
value.
|
||||
|
||||
~~~~
|
||||
log(warn, "hi");
|
||||
log(warn, ~"hi");
|
||||
log(error, (1, ~[2.5, -1.8]));
|
||||
~~~~
|
||||
|
||||
@ -886,7 +886,7 @@ are available. These take a string and any number of format arguments,
|
||||
and will log the formatted string:
|
||||
|
||||
~~~~
|
||||
# fn get_error_string() -> str { "boo" }
|
||||
# fn get_error_string() -> ~str { ~"boo" }
|
||||
#warn("only %d seconds remaining", 10);
|
||||
#error("fatal: %s", get_error_string());
|
||||
~~~~
|
||||
@ -905,8 +905,8 @@ with the `fn` keyword, the type of arguments are specified following
|
||||
colons and the return type follows the arrow.
|
||||
|
||||
~~~~
|
||||
fn int_to_str(i: int) -> str {
|
||||
ret "tube sock";
|
||||
fn int_to_str(i: int) -> ~str {
|
||||
ret ~"tube sock";
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -917,20 +917,20 @@ expression.
|
||||
|
||||
~~~~
|
||||
# const copernicus: int = 0;
|
||||
fn int_to_str(i: int) -> str {
|
||||
fn int_to_str(i: int) -> ~str {
|
||||
if i == copernicus {
|
||||
ret "tube sock";
|
||||
ret ~"tube sock";
|
||||
} else {
|
||||
ret "violin";
|
||||
ret ~"violin";
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
|
||||
~~~~
|
||||
# const copernicus: int = 0;
|
||||
fn int_to_str(i: int) -> str {
|
||||
if i == copernicus { "tube sock" }
|
||||
else { "violin" }
|
||||
fn int_to_str(i: int) -> ~str {
|
||||
if i == copernicus { ~"tube sock" }
|
||||
else { ~"violin" }
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -1348,7 +1348,7 @@ the pointer is guaranteed not to outlive the value it points to.
|
||||
|
||||
~~~~
|
||||
# fn work_with_foo_by_pointer(f: &~str) { }
|
||||
let foo = "foo";
|
||||
let foo = ~"foo";
|
||||
work_with_foo_by_pointer(&foo);
|
||||
~~~~
|
||||
|
||||
@ -1359,7 +1359,7 @@ would outlive `foo` itself.
|
||||
~~~~ {.ignore}
|
||||
let foo_ptr;
|
||||
{
|
||||
let foo = "foo";
|
||||
let foo = ~"foo";
|
||||
foo_ptr = &foo;
|
||||
}
|
||||
~~~~
|
||||
@ -1469,7 +1469,7 @@ my_crayons += your_crayons;
|
||||
|
||||
## Strings
|
||||
|
||||
The `str` type in Rust is represented exactly the same way as a unique
|
||||
The `~str` type in Rust is represented exactly the same way as a unique
|
||||
vector of immutable bytes (`~[u8]`). This sequence of bytes is
|
||||
interpreted as an UTF-8 encoded sequence of characters. This has the
|
||||
advantage that UTF-8 encoded I/O (which should really be the default
|
||||
@ -1479,7 +1479,7 @@ disadvantage that you only get constant-time access by byte, not by
|
||||
character.
|
||||
|
||||
~~~~
|
||||
let huh = "what?";
|
||||
let huh = ~"what?";
|
||||
let que: u8 = huh[4]; // indexing a string returns a `u8`
|
||||
assert que == '?' as u8;
|
||||
~~~~
|
||||
@ -1510,7 +1510,7 @@ brief look at a few common ones.
|
||||
# fn unwrap_crayon(c: crayon) -> int { 0 }
|
||||
# fn eat_crayon_wax(i: int) { }
|
||||
# fn store_crayon_in_nasal_cavity(i: uint, c: crayon) { }
|
||||
# fn crayon_to_str(c: crayon) -> str { "" }
|
||||
# fn crayon_to_str(c: crayon) -> ~str { ~"" }
|
||||
|
||||
let crayons = ~[almond, antique_brass, apricot];
|
||||
|
||||
@ -1571,7 +1571,7 @@ them. In the rare case where the compiler needs assistance though, the
|
||||
arguments and return types may be annotated.
|
||||
|
||||
~~~~
|
||||
# type mygoodness = fn(str) -> str; type what_the = int;
|
||||
# type mygoodness = fn(~str) -> ~str; type what_the = int;
|
||||
let bloop = |well, oh: mygoodness| -> what_the { fail oh(well) };
|
||||
~~~~
|
||||
|
||||
@ -1611,17 +1611,17 @@ returns it from a function, and then calls it:
|
||||
~~~~
|
||||
use std;
|
||||
|
||||
fn mk_appender(suffix: str) -> fn@(str) -> str {
|
||||
ret fn@(s: str) -> str { s + suffix };
|
||||
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
|
||||
ret fn@(s: ~str) -> ~str { s + suffix };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let shout = mk_appender("!");
|
||||
io::println(shout("hey ho, let's go"));
|
||||
let shout = mk_appender(~"!");
|
||||
io::println(shout(~"hey ho, let's go"));
|
||||
}
|
||||
~~~~
|
||||
|
||||
This example uses the long closure syntax, `fn@(s: str) ...`,
|
||||
This example uses the long closure syntax, `fn@(s: ~str) ...`,
|
||||
making the fact that we are declaring a box closure explicit. In
|
||||
practice boxed closures are usually defined with the short closure
|
||||
syntax introduced earlier, in which case the compiler will infer
|
||||
@ -1629,7 +1629,7 @@ the type of closure. Thus our boxed closure example could also
|
||||
be written:
|
||||
|
||||
~~~~
|
||||
fn mk_appender(suffix: str) -> fn@(str) -> str {
|
||||
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
|
||||
ret |s| s + suffix;
|
||||
}
|
||||
~~~~
|
||||
@ -1654,11 +1654,11 @@ that callers have the flexibility to pass whatever they want.
|
||||
|
||||
~~~~
|
||||
fn call_twice(f: fn()) { f(); f(); }
|
||||
call_twice(|| { "I am an inferred stack closure"; } );
|
||||
call_twice(fn&() { "I am also a stack closure"; } );
|
||||
call_twice(fn@() { "I am a boxed closure"; });
|
||||
call_twice(fn~() { "I am a unique closure"; });
|
||||
fn bare_function() { "I am a plain function"; }
|
||||
call_twice(|| { ~"I am an inferred stack closure"; } );
|
||||
call_twice(fn&() { ~"I am also a stack closure"; } );
|
||||
call_twice(fn@() { ~"I am a boxed closure"; });
|
||||
call_twice(fn~() { ~"I am a unique closure"; });
|
||||
fn bare_function() { ~"I am a plain function"; }
|
||||
call_twice(bare_function);
|
||||
~~~~
|
||||
|
||||
@ -1762,7 +1762,7 @@ And using this function to iterate over a vector:
|
||||
# import println = io::println;
|
||||
each(~[2, 4, 8, 5, 16], |n| {
|
||||
if n % 2 != 0 {
|
||||
println("found odd number!");
|
||||
println(~"found odd number!");
|
||||
false
|
||||
} else { true }
|
||||
});
|
||||
@ -1779,7 +1779,7 @@ to the next iteration, write `again`.
|
||||
# import println = io::println;
|
||||
for each(~[2, 4, 8, 5, 16]) |n| {
|
||||
if n % 2 != 0 {
|
||||
println("found odd number!");
|
||||
println(~"found odd number!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1832,7 +1832,7 @@ class example {
|
||||
}
|
||||
|
||||
fn a() {
|
||||
io::println("a");
|
||||
io::println(~"a");
|
||||
}
|
||||
|
||||
drop {
|
||||
@ -1953,8 +1953,8 @@ being owned by the data structure, so if that can be done without a
|
||||
copy, that's a win.
|
||||
|
||||
~~~~
|
||||
type person = {name: str, address: str};
|
||||
fn make_person(+name: str, +address: str) -> person {
|
||||
type person = {name: ~str, address: ~str};
|
||||
fn make_person(+name: ~str, +address: ~str) -> person {
|
||||
ret {name: name, address: address};
|
||||
}
|
||||
~~~~
|
||||
@ -2007,7 +2007,7 @@ enum option<T> { some(T), none }
|
||||
~~~~
|
||||
|
||||
You can then declare a function to take a `circular_buf<u8>` or return
|
||||
an `option<str>`, or even an `option<T>` if the function itself is
|
||||
an `option<~str>`, or even an `option<T>` if the function itself is
|
||||
generic.
|
||||
|
||||
The `option` type given above exists in the core library and is the
|
||||
@ -2051,8 +2051,8 @@ take any type of value and output it.
|
||||
More interesting is that Rust also defines an ordering for values of
|
||||
all datatypes, and allows you to meaningfully apply comparison
|
||||
operators (`<`, `>`, `<=`, `>=`, `==`, `!=`) to them. For structural
|
||||
types, the comparison happens left to right, so `"abc" < "bac"` (but
|
||||
note that `"bac" < "ác"`, because the ordering acts on UTF-8 sequences
|
||||
types, the comparison happens left to right, so `~"abc" < ~"bac"` (but
|
||||
note that `~"bac" < ~"ác"`, because the ordering acts on UTF-8 sequences
|
||||
without any sophistication).
|
||||
|
||||
## Kinds
|
||||
@ -2135,8 +2135,8 @@ explicitly import it, you must refer to it by its long name,
|
||||
|
||||
~~~~
|
||||
mod farm {
|
||||
fn chicken() -> str { "cluck cluck" }
|
||||
fn cow() -> str { "mooo" }
|
||||
fn chicken() -> ~str { ~"cluck cluck" }
|
||||
fn cow() -> ~str { ~"mooo" }
|
||||
}
|
||||
fn main() {
|
||||
io::println(farm::chicken());
|
||||
@ -2249,14 +2249,14 @@ these two files:
|
||||
~~~~
|
||||
// mylib.rs
|
||||
#[link(name = "mylib", vers = "1.0")];
|
||||
fn world() -> str { "world" }
|
||||
fn world() -> ~str { ~"world" }
|
||||
~~~~
|
||||
|
||||
~~~~ {.ignore}
|
||||
// main.rs
|
||||
use std;
|
||||
use mylib;
|
||||
fn main() { io::println("hello " + mylib::world()); }
|
||||
fn main() { io::println(~"hello " + mylib::world()); }
|
||||
~~~~
|
||||
|
||||
Now compile and run like this (adjust to your platform if necessary):
|
||||
@ -2279,7 +2279,7 @@ identifiers at the top of a file, module, or block.
|
||||
use std;
|
||||
import io::println;
|
||||
fn main() {
|
||||
println("that was easy");
|
||||
println(~"that was easy");
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -2345,7 +2345,7 @@ Identifiers can shadow each other. In this program, `x` is of type
|
||||
`int`:
|
||||
|
||||
~~~~
|
||||
type t = str;
|
||||
type t = ~str;
|
||||
fn main() {
|
||||
type t = int;
|
||||
let x: t;
|
||||
@ -2408,7 +2408,7 @@ can be converted to a string, with a single method of the same name:
|
||||
|
||||
~~~~
|
||||
iface to_str {
|
||||
fn to_str() -> str;
|
||||
fn to_str() -> ~str;
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -2416,20 +2416,20 @@ iface to_str {
|
||||
|
||||
To actually implement an interface for a given type, the `impl` form
|
||||
is used. This defines implementations of `to_str` for the `int` and
|
||||
`str` types.
|
||||
`~str` types.
|
||||
|
||||
~~~~
|
||||
# iface to_str { fn to_str() -> str; }
|
||||
# iface to_str { fn to_str() -> ~str; }
|
||||
impl of to_str for int {
|
||||
fn to_str() -> str { int::to_str(self, 10u) }
|
||||
fn to_str() -> ~str { int::to_str(self, 10u) }
|
||||
}
|
||||
impl of to_str for str {
|
||||
fn to_str() -> str { self }
|
||||
impl of to_str for ~str {
|
||||
fn to_str() -> ~str { self }
|
||||
}
|
||||
~~~~
|
||||
|
||||
Given these, we may call `1.to_str()` to get `"1"`, or
|
||||
`"foo".to_str()` to get `"foo"` again. This is basically a form of
|
||||
Given these, we may call `1.to_str()` to get `~"1"`, or
|
||||
`(~"foo").to_str()` to get `~"foo"` again. This is basically a form of
|
||||
static overloading—when the Rust compiler sees the `to_str` method
|
||||
call, it looks for an implementation that matches the type with a
|
||||
method that matches the name, and simply calls that.
|
||||
@ -2444,9 +2444,9 @@ without problems). Or you can give them an explicit name if you
|
||||
prefer, using this syntax:
|
||||
|
||||
~~~~
|
||||
# iface to_str { fn to_str() -> str; }
|
||||
# iface to_str { fn to_str() -> ~str; }
|
||||
impl nil_to_str of to_str for () {
|
||||
fn to_str() -> str { "()" }
|
||||
fn to_str() -> ~str { ~"()" }
|
||||
}
|
||||
~~~~
|
||||
|
||||
@ -2460,12 +2460,12 @@ known at compile time, it is possible to specify 'bounds' for type
|
||||
parameters.
|
||||
|
||||
~~~~
|
||||
# iface to_str { fn to_str() -> str; }
|
||||
fn comma_sep<T: to_str>(elts: ~[T]) -> str {
|
||||
let mut result = "", first = true;
|
||||
# iface to_str { fn to_str() -> ~str; }
|
||||
fn comma_sep<T: to_str>(elts: ~[T]) -> ~str {
|
||||
let mut result = ~"", first = true;
|
||||
for elts.each |elt| {
|
||||
if first { first = false; }
|
||||
else { result += ", "; }
|
||||
else { result += ~", "; }
|
||||
result += elt.to_str();
|
||||
}
|
||||
ret result;
|
||||
@ -2576,14 +2576,14 @@ to leave off the `of` clause.
|
||||
|
||||
~~~~
|
||||
# type currency = ();
|
||||
# fn mk_currency(x: int, s: str) {}
|
||||
# fn mk_currency(x: int, s: ~str) {}
|
||||
impl int_util for int {
|
||||
fn times(b: fn(int)) {
|
||||
let mut i = 0;
|
||||
while i < self { b(i); i += 1; }
|
||||
}
|
||||
fn dollars() -> currency {
|
||||
mk_currency(self, "USD")
|
||||
mk_currency(self, ~"USD")
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
@ -2615,20 +2615,20 @@ extern mod crypto {
|
||||
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
|
||||
}
|
||||
|
||||
fn as_hex(data: ~[u8]) -> str {
|
||||
let mut acc = "";
|
||||
fn as_hex(data: ~[u8]) -> ~str {
|
||||
let mut acc = ~"";
|
||||
for data.each |byte| { acc += #fmt("%02x", byte as uint); }
|
||||
ret acc;
|
||||
}
|
||||
|
||||
fn sha1(data: str) -> str unsafe {
|
||||
fn sha1(data: ~str) -> ~str unsafe {
|
||||
let bytes = str::bytes(data);
|
||||
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
|
||||
vec::len(bytes), ptr::null());
|
||||
ret as_hex(vec::unsafe::from_buf(hash, 20u));
|
||||
}
|
||||
|
||||
fn main(args: ~[str]) {
|
||||
fn main(args: ~[~str]) {
|
||||
io::println(sha1(args[1]));
|
||||
}
|
||||
~~~~
|
||||
@ -2719,8 +2719,8 @@ The `sha1` function is the most obscure part of the program.
|
||||
|
||||
~~~~
|
||||
# mod crypto { fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8 { out } }
|
||||
# fn as_hex(data: ~[u8]) -> str { "hi" }
|
||||
fn sha1(data: str) -> str {
|
||||
# fn as_hex(data: ~[u8]) -> ~str { ~"hi" }
|
||||
fn sha1(data: ~str) -> ~str {
|
||||
unsafe {
|
||||
let bytes = str::bytes(data);
|
||||
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
|
||||
@ -2746,7 +2746,7 @@ Unsafe blocks isolate unsafety. Unsafe functions, on the other hand,
|
||||
advertise it to the world. An unsafe function is written like this:
|
||||
|
||||
~~~~
|
||||
unsafe fn kaboom() { "I'm harmless!"; }
|
||||
unsafe fn kaboom() { ~"I'm harmless!"; }
|
||||
~~~~
|
||||
|
||||
This function can only be called from an unsafe block or another
|
||||
@ -2762,8 +2762,8 @@ Let's look at our `sha1` function again.
|
||||
|
||||
~~~~
|
||||
# mod crypto { fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8 { out } }
|
||||
# fn as_hex(data: ~[u8]) -> str { "hi" }
|
||||
# fn x(data: str) -> str {
|
||||
# fn as_hex(data: ~[u8]) -> ~str { ~"hi" }
|
||||
# fn x(data: ~str) -> ~str {
|
||||
# unsafe {
|
||||
let bytes = str::bytes(data);
|
||||
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
|
||||
@ -2816,7 +2816,7 @@ fn unix_time_in_microseconds() -> u64 unsafe {
|
||||
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
|
||||
}
|
||||
|
||||
# fn main() { assert #fmt("%?", unix_time_in_microseconds()) != ""; }
|
||||
# fn main() { assert #fmt("%?", unix_time_in_microseconds()) != ~""; }
|
||||
~~~~
|
||||
|
||||
The `#[nolink]` attribute indicates that there's no foreign library to
|
||||
@ -2855,7 +2855,7 @@ import io::println;
|
||||
let some_value = 22;
|
||||
|
||||
do spawn {
|
||||
println("This executes in the child task.");
|
||||
println(~"This executes in the child task.");
|
||||
println(#fmt("%d", some_value));
|
||||
}
|
||||
~~~~
|
||||
@ -2957,7 +2957,7 @@ Here is the function which implements the child task:
|
||||
~~~~
|
||||
# import comm::{port, chan, methods};
|
||||
fn stringifier(from_parent: port<uint>,
|
||||
to_parent: chan<str>) {
|
||||
to_parent: chan<~str>) {
|
||||
let mut value: uint;
|
||||
loop {
|
||||
value = from_parent.recv();
|
||||
@ -2981,10 +2981,10 @@ Here is the code for the parent task:
|
||||
# import task::{spawn_listener};
|
||||
# import comm::{chan, port, methods};
|
||||
# fn stringifier(from_parent: comm::port<uint>,
|
||||
# to_parent: comm::chan<str>) {
|
||||
# comm::send(to_parent, "22");
|
||||
# comm::send(to_parent, "23");
|
||||
# comm::send(to_parent, "0");
|
||||
# to_parent: comm::chan<~str>) {
|
||||
# comm::send(to_parent, ~"22");
|
||||
# comm::send(to_parent, ~"23");
|
||||
# comm::send(to_parent, ~"0");
|
||||
# }
|
||||
# fn main() {
|
||||
|
||||
@ -2995,13 +2995,13 @@ let to_child = do spawn_listener |from_parent| {
|
||||
};
|
||||
|
||||
to_child.send(22u);
|
||||
assert from_child.recv() == "22";
|
||||
assert from_child.recv() == ~"22";
|
||||
|
||||
to_child.send(23u);
|
||||
assert from_child.recv() == "23";
|
||||
assert from_child.recv() == ~"23";
|
||||
|
||||
to_child.send(0u);
|
||||
assert from_child.recv() == "0";
|
||||
assert from_child.recv() == ~"0";
|
||||
|
||||
# }
|
||||
~~~~
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
||||
fn gpg(args: ~[str]) -> { status: int, out: str, err: str } {
|
||||
ret run::program_output("gpg", args);
|
||||
fn gpg(args: ~[~str]) -> { status: int, out: ~str, err: ~str } {
|
||||
ret run::program_output(~"gpg", args);
|
||||
}
|
||||
|
||||
fn signing_key() -> str {
|
||||
"
|
||||
fn signing_key() -> ~str {
|
||||
~"
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: SKS 1.1.0
|
||||
|
||||
@ -54,42 +54,42 @@ HI1jilzwKSXuV2EmyBk3tKh9NwscT/A78pr30FxxPUg3v72raNgusTo=
|
||||
"
|
||||
}
|
||||
|
||||
fn signing_key_fp() -> str {
|
||||
"FE79 EDB0 3DEF B0D8 27D2 6C41 0B2D 6A28 3033 6376"
|
||||
fn signing_key_fp() -> ~str {
|
||||
~"FE79 EDB0 3DEF B0D8 27D2 6C41 0B2D 6A28 3033 6376"
|
||||
}
|
||||
|
||||
fn supported() -> bool {
|
||||
let r = gpg(~["--version"]);
|
||||
let r = gpg(~[~"--version"]);
|
||||
r.status == 0
|
||||
}
|
||||
|
||||
fn init(root: str) {
|
||||
let p = path::connect(root, "gpg");
|
||||
fn init(root: ~str) {
|
||||
let p = path::connect(root, ~"gpg");
|
||||
if !os::path_is_dir(p) {
|
||||
os::make_dir(p, 0x1c0i32);
|
||||
let p = run::start_program("gpg", ~["--homedir", p, "--import"]);
|
||||
let p = run::start_program(~"gpg", ~[~"--homedir", p, ~"--import"]);
|
||||
p.input().write_str(signing_key());
|
||||
let s = p.finish();
|
||||
if s != 0 {
|
||||
fail "pgp init failed";
|
||||
fail ~"pgp init failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add(root: str, key: str) {
|
||||
let path = path::connect(root, "gpg");
|
||||
fn add(root: ~str, key: ~str) {
|
||||
let path = path::connect(root, ~"gpg");
|
||||
let p =
|
||||
run::program_output("gpg", ~["--homedir", path, "--import", key]);
|
||||
run::program_output(~"gpg", ~[~"--homedir", path, ~"--import", key]);
|
||||
if p.status != 0 {
|
||||
fail "pgp add failed: " + p.out;
|
||||
fail ~"pgp add failed: " + p.out;
|
||||
}
|
||||
}
|
||||
|
||||
fn verify(root: str, data: str, sig: str, keyfp: str) -> bool {
|
||||
let path = path::connect(root, "gpg");
|
||||
let p = gpg(~["--homedir", path, "--with-fingerprint", "--verify", sig,
|
||||
fn verify(root: ~str, data: ~str, sig: ~str, keyfp: ~str) -> bool {
|
||||
let path = path::connect(root, ~"gpg");
|
||||
let p = gpg(~[~"--homedir", path, ~"--with-fingerprint", ~"--verify", sig,
|
||||
data]);
|
||||
let res = "Primary key fingerprint: " + keyfp;
|
||||
let res = ~"Primary key fingerprint: " + keyfp;
|
||||
for str::split_char(p.err, '\n').each |line| {
|
||||
if line == res { ret true; }
|
||||
}
|
||||
|
@ -4,25 +4,25 @@ enum mode { mode_compile_fail, mode_run_fail, mode_run_pass, mode_pretty, }
|
||||
|
||||
type config = {
|
||||
// The library paths required for running the compiler
|
||||
compile_lib_path: str,
|
||||
compile_lib_path: ~str,
|
||||
|
||||
// The library paths required for running compiled programs
|
||||
run_lib_path: str,
|
||||
run_lib_path: ~str,
|
||||
|
||||
// The rustc executable
|
||||
rustc_path: str,
|
||||
rustc_path: ~str,
|
||||
|
||||
// The directory containing the tests to run
|
||||
src_base: str,
|
||||
src_base: ~str,
|
||||
|
||||
// The directory where programs should be built
|
||||
build_base: str,
|
||||
build_base: ~str,
|
||||
|
||||
// Directory for auxiliary libraries
|
||||
aux_base: str,
|
||||
aux_base: ~str,
|
||||
|
||||
// The name of the stage being built (stage1, etc)
|
||||
stage_id: str,
|
||||
stage_id: ~str,
|
||||
|
||||
// The test mode, compile-fail, run-fail, run-pass
|
||||
mode: mode,
|
||||
@ -31,17 +31,17 @@ type config = {
|
||||
run_ignored: bool,
|
||||
|
||||
// Only run tests that match this filter
|
||||
filter: option<str>,
|
||||
filter: option<~str>,
|
||||
|
||||
// Write out a parseable log of tests that were run
|
||||
logfile: option<str>,
|
||||
logfile: option<~str>,
|
||||
|
||||
// A command line to prefix program execution with,
|
||||
// for running under valgrind
|
||||
runtool: option<str>,
|
||||
runtool: option<~str>,
|
||||
|
||||
// Flags to pass to the compiler
|
||||
rustcflags: option<str>,
|
||||
rustcflags: option<~str>,
|
||||
|
||||
// Explain what's going on
|
||||
verbose: bool};
|
||||
|
@ -21,23 +21,23 @@ import common::mode_pretty;
|
||||
import common::mode;
|
||||
import util::logv;
|
||||
|
||||
fn main(args: ~[str]) {
|
||||
fn main(args: ~[~str]) {
|
||||
let config = parse_config(args);
|
||||
log_config(config);
|
||||
run_tests(config);
|
||||
}
|
||||
|
||||
fn parse_config(args: ~[str]) -> config {
|
||||
fn parse_config(args: ~[~str]) -> config {
|
||||
let opts =
|
||||
~[getopts::reqopt("compile-lib-path"),
|
||||
getopts::reqopt("run-lib-path"),
|
||||
getopts::reqopt("rustc-path"), getopts::reqopt("src-base"),
|
||||
getopts::reqopt("build-base"), getopts::reqopt("aux-base"),
|
||||
getopts::reqopt("stage-id"),
|
||||
getopts::reqopt("mode"), getopts::optflag("ignored"),
|
||||
getopts::optopt("runtool"), getopts::optopt("rustcflags"),
|
||||
getopts::optflag("verbose"),
|
||||
getopts::optopt("logfile")];
|
||||
~[getopts::reqopt(~"compile-lib-path"),
|
||||
getopts::reqopt(~"run-lib-path"),
|
||||
getopts::reqopt(~"rustc-path"), getopts::reqopt(~"src-base"),
|
||||
getopts::reqopt(~"build-base"), getopts::reqopt(~"aux-base"),
|
||||
getopts::reqopt(~"stage-id"),
|
||||
getopts::reqopt(~"mode"), getopts::optflag(~"ignored"),
|
||||
getopts::optopt(~"runtool"), getopts::optopt(~"rustcflags"),
|
||||
getopts::optflag(~"verbose"),
|
||||
getopts::optopt(~"logfile")];
|
||||
|
||||
check (vec::is_not_empty(args));
|
||||
let args_ = vec::tail(args);
|
||||
@ -47,23 +47,23 @@ fn parse_config(args: ~[str]) -> config {
|
||||
err(f) { fail getopts::fail_str(f) }
|
||||
};
|
||||
|
||||
ret {compile_lib_path: getopts::opt_str(match, "compile-lib-path"),
|
||||
run_lib_path: getopts::opt_str(match, "run-lib-path"),
|
||||
rustc_path: getopts::opt_str(match, "rustc-path"),
|
||||
src_base: getopts::opt_str(match, "src-base"),
|
||||
build_base: getopts::opt_str(match, "build-base"),
|
||||
aux_base: getopts::opt_str(match, "aux-base"),
|
||||
stage_id: getopts::opt_str(match, "stage-id"),
|
||||
mode: str_mode(getopts::opt_str(match, "mode")),
|
||||
run_ignored: getopts::opt_present(match, "ignored"),
|
||||
ret {compile_lib_path: getopts::opt_str(match, ~"compile-lib-path"),
|
||||
run_lib_path: getopts::opt_str(match, ~"run-lib-path"),
|
||||
rustc_path: getopts::opt_str(match, ~"rustc-path"),
|
||||
src_base: getopts::opt_str(match, ~"src-base"),
|
||||
build_base: getopts::opt_str(match, ~"build-base"),
|
||||
aux_base: getopts::opt_str(match, ~"aux-base"),
|
||||
stage_id: getopts::opt_str(match, ~"stage-id"),
|
||||
mode: str_mode(getopts::opt_str(match, ~"mode")),
|
||||
run_ignored: getopts::opt_present(match, ~"ignored"),
|
||||
filter:
|
||||
if vec::len(match.free) > 0u {
|
||||
option::some(match.free[0])
|
||||
} else { option::none },
|
||||
logfile: getopts::opt_maybe_str(match, "logfile"),
|
||||
runtool: getopts::opt_maybe_str(match, "runtool"),
|
||||
rustcflags: getopts::opt_maybe_str(match, "rustcflags"),
|
||||
verbose: getopts::opt_present(match, "verbose")};
|
||||
logfile: getopts::opt_maybe_str(match, ~"logfile"),
|
||||
runtool: getopts::opt_maybe_str(match, ~"runtool"),
|
||||
rustcflags: getopts::opt_maybe_str(match, ~"rustcflags"),
|
||||
verbose: getopts::opt_present(match, ~"verbose")};
|
||||
}
|
||||
|
||||
fn log_config(config: config) {
|
||||
@ -84,30 +84,30 @@ fn log_config(config: config) {
|
||||
logv(c, #fmt["\n"]);
|
||||
}
|
||||
|
||||
fn opt_str(maybestr: option<str>) -> str {
|
||||
alt maybestr { option::some(s) { s } option::none { "(none)" } }
|
||||
fn opt_str(maybestr: option<~str>) -> ~str {
|
||||
alt maybestr { option::some(s) { s } option::none { ~"(none)" } }
|
||||
}
|
||||
|
||||
fn str_opt(maybestr: str) -> option<str> {
|
||||
if maybestr != "(none)" { option::some(maybestr) } else { option::none }
|
||||
fn str_opt(maybestr: ~str) -> option<~str> {
|
||||
if maybestr != ~"(none)" { option::some(maybestr) } else { option::none }
|
||||
}
|
||||
|
||||
fn str_mode(s: str) -> mode {
|
||||
fn str_mode(s: ~str) -> mode {
|
||||
alt s {
|
||||
"compile-fail" { mode_compile_fail }
|
||||
"run-fail" { mode_run_fail }
|
||||
"run-pass" { mode_run_pass }
|
||||
"pretty" { mode_pretty }
|
||||
_ { fail "invalid mode" }
|
||||
~"compile-fail" { mode_compile_fail }
|
||||
~"run-fail" { mode_run_fail }
|
||||
~"run-pass" { mode_run_pass }
|
||||
~"pretty" { mode_pretty }
|
||||
_ { fail ~"invalid mode" }
|
||||
}
|
||||
}
|
||||
|
||||
fn mode_str(mode: mode) -> str {
|
||||
fn mode_str(mode: mode) -> ~str {
|
||||
alt mode {
|
||||
mode_compile_fail { "compile-fail" }
|
||||
mode_run_fail { "run-fail" }
|
||||
mode_run_pass { "run-pass" }
|
||||
mode_pretty { "pretty" }
|
||||
mode_compile_fail { ~"compile-fail" }
|
||||
mode_run_fail { ~"run-fail" }
|
||||
mode_run_pass { ~"run-pass" }
|
||||
mode_pretty { ~"pretty" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ fn run_tests(config: config) {
|
||||
let opts = test_opts(config);
|
||||
let tests = make_tests(config);
|
||||
let res = test::run_tests_console(opts, tests);
|
||||
if !res { fail "Some tests failed"; }
|
||||
if !res { fail ~"Some tests failed"; }
|
||||
}
|
||||
|
||||
fn test_opts(config: config) -> test::test_opts {
|
||||
@ -146,11 +146,11 @@ fn make_tests(config: config) -> ~[test::test_desc] {
|
||||
ret tests;
|
||||
}
|
||||
|
||||
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
|
||||
let valid_extensions =
|
||||
alt config.mode { mode_pretty { ~[".rs"] } _ { ~[".rc", ".rs"] } };
|
||||
let invalid_prefixes = ~[".", "#", "~"];
|
||||
alt config.mode { mode_pretty { ~[~".rs"] } _ { ~[~".rc", ~".rs"] } };
|
||||
let invalid_prefixes = ~[~".", ~"#", ~"~"];
|
||||
let name = path::basename(testfile);
|
||||
|
||||
let mut valid = false;
|
||||
@ -166,7 +166,7 @@ fn is_test(config: config, testfile: str) -> bool {
|
||||
ret valid;
|
||||
}
|
||||
|
||||
fn make_test(config: config, testfile: str) ->
|
||||
fn make_test(config: config, testfile: ~str) ->
|
||||
test::test_desc {
|
||||
{
|
||||
name: make_test_name(config, testfile),
|
||||
@ -176,11 +176,11 @@ fn make_test(config: config, testfile: str) ->
|
||||
}
|
||||
}
|
||||
|
||||
fn make_test_name(config: config, testfile: str) -> str {
|
||||
fn make_test_name(config: config, testfile: ~str) -> ~str {
|
||||
#fmt["[%s] %s", mode_str(config.mode), testfile]
|
||||
}
|
||||
|
||||
fn make_test_closure(config: config, testfile: str) -> test::test_fn {
|
||||
fn make_test_closure(config: config, testfile: ~str) -> test::test_fn {
|
||||
fn~() { runtest::run(config, copy testfile) }
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,10 @@ import common::config;
|
||||
export load_errors;
|
||||
export expected_error;
|
||||
|
||||
type expected_error = { line: uint, kind: str, msg: str };
|
||||
type expected_error = { line: uint, kind: ~str, msg: ~str };
|
||||
|
||||
// Load any test directives embedded in the file
|
||||
fn load_errors(testfile: str) -> ~[expected_error] {
|
||||
fn load_errors(testfile: ~str) -> ~[expected_error] {
|
||||
let mut error_patterns = ~[];
|
||||
let rdr = result::get(io::file_reader(testfile));
|
||||
let mut line_num = 1u;
|
||||
@ -20,8 +20,8 @@ fn load_errors(testfile: str) -> ~[expected_error] {
|
||||
ret error_patterns;
|
||||
}
|
||||
|
||||
fn parse_expected(line_num: uint, line: str) -> ~[expected_error] unsafe {
|
||||
let error_tag = "//~";
|
||||
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
|
||||
let error_tag = ~"//~";
|
||||
let mut idx;
|
||||
alt str::find_str(line, error_tag) {
|
||||
option::none { ret ~[]; }
|
||||
|
@ -10,20 +10,20 @@ export is_test_ignored;
|
||||
|
||||
type test_props = {
|
||||
// Lines that should be expected, in order, on standard out
|
||||
error_patterns: ~[str],
|
||||
error_patterns: ~[~str],
|
||||
// Extra flags to pass to the compiler
|
||||
compile_flags: option<str>,
|
||||
compile_flags: option<~str>,
|
||||
// If present, the name of a file that this test should match when
|
||||
// pretty-printed
|
||||
pp_exact: option<str>,
|
||||
pp_exact: option<~str>,
|
||||
// Modules from aux directory that should be compiled
|
||||
aux_builds: ~[str],
|
||||
aux_builds: ~[~str],
|
||||
// Environment settings to use during execution
|
||||
exec_env: ~[(str,str)]
|
||||
exec_env: ~[(~str,~str)]
|
||||
};
|
||||
|
||||
// Load any test directives embedded in the file
|
||||
fn load_props(testfile: str) -> test_props {
|
||||
fn load_props(testfile: ~str) -> test_props {
|
||||
let mut error_patterns = ~[];
|
||||
let mut aux_builds = ~[];
|
||||
let mut exec_env = ~[];
|
||||
@ -60,22 +60,22 @@ fn load_props(testfile: str) -> test_props {
|
||||
};
|
||||
}
|
||||
|
||||
fn is_test_ignored(config: config, testfile: str) -> bool {
|
||||
fn is_test_ignored(config: config, testfile: ~str) -> bool {
|
||||
let mut found = false;
|
||||
for iter_header(testfile) |ln| {
|
||||
if parse_name_directive(ln, "xfail-test") { ret true; }
|
||||
if parse_name_directive(ln, ~"xfail-test") { ret true; }
|
||||
if parse_name_directive(ln, xfail_target()) { ret true; }
|
||||
if config.mode == common::mode_pretty &&
|
||||
parse_name_directive(ln, "xfail-pretty") { ret true; }
|
||||
parse_name_directive(ln, ~"xfail-pretty") { ret true; }
|
||||
};
|
||||
ret found;
|
||||
|
||||
fn xfail_target() -> str {
|
||||
"xfail-" + os::sysname()
|
||||
fn xfail_target() -> ~str {
|
||||
~"xfail-" + os::sysname()
|
||||
}
|
||||
}
|
||||
|
||||
fn iter_header(testfile: str, it: fn(str) -> bool) -> bool {
|
||||
fn iter_header(testfile: ~str, it: fn(~str) -> bool) -> bool {
|
||||
let rdr = result::get(io::file_reader(testfile));
|
||||
while !rdr.eof() {
|
||||
let ln = rdr.read_line();
|
||||
@ -83,43 +83,43 @@ fn iter_header(testfile: str, it: fn(str) -> bool) -> bool {
|
||||
// Assume that any directives will be found before the first
|
||||
// module or function. This doesn't seem to be an optimization
|
||||
// with a warm page cache. Maybe with a cold one.
|
||||
if str::starts_with(ln, "fn")
|
||||
|| str::starts_with(ln, "mod") {
|
||||
if str::starts_with(ln, ~"fn")
|
||||
|| str::starts_with(ln, ~"mod") {
|
||||
ret false;
|
||||
} else { if !(it(ln)) { ret false; } }
|
||||
}
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn parse_error_pattern(line: str) -> option<str> {
|
||||
parse_name_value_directive(line, "error-pattern")
|
||||
fn parse_error_pattern(line: ~str) -> option<~str> {
|
||||
parse_name_value_directive(line, ~"error-pattern")
|
||||
}
|
||||
|
||||
fn parse_aux_build(line: str) -> option<str> {
|
||||
parse_name_value_directive(line, "aux-build")
|
||||
fn parse_aux_build(line: ~str) -> option<~str> {
|
||||
parse_name_value_directive(line, ~"aux-build")
|
||||
}
|
||||
|
||||
fn parse_compile_flags(line: str) -> option<str> {
|
||||
parse_name_value_directive(line, "compile-flags")
|
||||
fn parse_compile_flags(line: ~str) -> option<~str> {
|
||||
parse_name_value_directive(line, ~"compile-flags")
|
||||
}
|
||||
|
||||
fn parse_exec_env(line: str) -> option<(str, str)> {
|
||||
do parse_name_value_directive(line, "exec-env").map |nv| {
|
||||
fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
|
||||
do parse_name_value_directive(line, ~"exec-env").map |nv| {
|
||||
// nv is either FOO or FOO=BAR
|
||||
let strs = str::splitn_char(nv, '=', 1u);
|
||||
alt strs.len() {
|
||||
1u { (strs[0], "") }
|
||||
1u { (strs[0], ~"") }
|
||||
2u { (strs[0], strs[1]) }
|
||||
n { fail #fmt["Expected 1 or 2 strings, not %u", n]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_pp_exact(line: str, testfile: str) -> option<str> {
|
||||
alt parse_name_value_directive(line, "pp-exact") {
|
||||
fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
|
||||
alt parse_name_value_directive(line, ~"pp-exact") {
|
||||
option::some(s) { option::some(s) }
|
||||
option::none {
|
||||
if parse_name_directive(line, "pp-exact") {
|
||||
if parse_name_directive(line, ~"pp-exact") {
|
||||
option::some(path::basename(testfile))
|
||||
} else {
|
||||
option::none
|
||||
@ -128,13 +128,13 @@ fn parse_pp_exact(line: str, testfile: str) -> option<str> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_name_directive(line: str, directive: str) -> bool {
|
||||
fn parse_name_directive(line: ~str, directive: ~str) -> bool {
|
||||
str::contains(line, directive)
|
||||
}
|
||||
|
||||
fn parse_name_value_directive(line: str,
|
||||
directive: str) -> option<str> unsafe {
|
||||
let keycolon = directive + ":";
|
||||
fn parse_name_value_directive(line: ~str,
|
||||
directive: ~str) -> option<~str> unsafe {
|
||||
let keycolon = directive + ~":";
|
||||
alt str::find_str(line, keycolon) {
|
||||
option::some(colon) {
|
||||
let value = str::slice(line, colon + str::len(keycolon),
|
||||
|
@ -27,17 +27,17 @@ fn target_env(lib_path: str, prog: str) -> ~[(str,str)] {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn target_env(_lib_path: str, _prog: str) -> ~[(str,str)] {
|
||||
fn target_env(_lib_path: ~str, _prog: ~str) -> ~[(~str,~str)] {
|
||||
~[]
|
||||
}
|
||||
|
||||
|
||||
// FIXME (#2659): This code is duplicated in core::run::program_output
|
||||
fn run(lib_path: str,
|
||||
prog: str,
|
||||
args: ~[str],
|
||||
env: ~[(str, str)],
|
||||
input: option<str>) -> {status: int, out: str, err: str} {
|
||||
fn run(lib_path: ~str,
|
||||
prog: ~str,
|
||||
args: ~[~str],
|
||||
env: ~[(~str, ~str)],
|
||||
input: option<~str>) -> {status: int, out: ~str, err: ~str} {
|
||||
|
||||
let pipe_in = os::pipe();
|
||||
let pipe_out = os::pipe();
|
||||
@ -69,8 +69,8 @@ fn run(lib_path: str,
|
||||
comm::send(ch, (1, output));
|
||||
}
|
||||
let status = run::waitpid(pid);
|
||||
let mut errs = "";
|
||||
let mut outs = "";
|
||||
let mut errs = ~"";
|
||||
let mut outs = ~"";
|
||||
let mut count = 2;
|
||||
while count > 0 {
|
||||
let stream = comm::recv(p);
|
||||
@ -87,7 +87,7 @@ fn run(lib_path: str,
|
||||
ret {status: status, out: outs, err: errs};
|
||||
}
|
||||
|
||||
fn writeclose(fd: c_int, s: option<str>) {
|
||||
fn writeclose(fd: c_int, s: option<~str>) {
|
||||
if option::is_some(s) {
|
||||
let writer = io::fd_writer(fd, false);
|
||||
writer.write_str(option::get(s));
|
||||
@ -96,11 +96,11 @@ fn writeclose(fd: c_int, s: option<str>) {
|
||||
os::close(fd);
|
||||
}
|
||||
|
||||
fn readclose(fd: c_int) -> str {
|
||||
fn readclose(fd: c_int) -> ~str {
|
||||
// Copied from run::program_output
|
||||
let file = os::fdopen(fd);
|
||||
let reader = io::FILE_reader(file, false);
|
||||
let mut buf = "";
|
||||
let mut buf = ~"";
|
||||
while !reader.eof() {
|
||||
let bytes = reader.read_bytes(4096u);
|
||||
buf += str::from_bytes(bytes);
|
||||
|
@ -11,10 +11,10 @@ import util::logv;
|
||||
|
||||
export run;
|
||||
|
||||
fn run(config: config, testfile: str) {
|
||||
fn run(config: config, testfile: ~str) {
|
||||
if config.verbose {
|
||||
// We're going to be dumping a lot of info. Start on a new line.
|
||||
io::stdout().write_str("\n\n");
|
||||
io::stdout().write_str(~"\n\n");
|
||||
}
|
||||
#debug("running %s", testfile);
|
||||
let props = load_props(testfile);
|
||||
@ -26,11 +26,11 @@ fn run(config: config, testfile: str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn run_cfail_test(config: config, props: test_props, testfile: str) {
|
||||
fn run_cfail_test(config: config, props: test_props, testfile: ~str) {
|
||||
let procres = compile_test(config, props, testfile);
|
||||
|
||||
if procres.status == 0 {
|
||||
fatal_procres("compile-fail test compiled successfully!", procres);
|
||||
fatal_procres(~"compile-fail test compiled successfully!", procres);
|
||||
}
|
||||
|
||||
check_correct_failure_status(procres);
|
||||
@ -38,7 +38,7 @@ fn run_cfail_test(config: config, props: test_props, testfile: str) {
|
||||
let expected_errors = errors::load_errors(testfile);
|
||||
if vec::is_not_empty(expected_errors) {
|
||||
if vec::is_not_empty(props.error_patterns) {
|
||||
fatal("both error pattern and expected errors specified");
|
||||
fatal(~"both error pattern and expected errors specified");
|
||||
}
|
||||
check_expected_errors(expected_errors, testfile, procres);
|
||||
} else {
|
||||
@ -46,17 +46,17 @@ fn run_cfail_test(config: config, props: test_props, testfile: str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn run_rfail_test(config: config, props: test_props, testfile: str) {
|
||||
fn run_rfail_test(config: config, props: test_props, testfile: ~str) {
|
||||
let mut procres = compile_test(config, props, testfile);
|
||||
|
||||
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
||||
if procres.status != 0 { fatal_procres(~"compilation failed!", procres); }
|
||||
|
||||
procres = exec_compiled_test(config, props, testfile);
|
||||
|
||||
// The value our Makefile configures valgrind to return on failure
|
||||
const valgrind_err: int = 100;
|
||||
if procres.status == valgrind_err {
|
||||
fatal_procres("run-fail test isn't valgrind-clean!", procres);
|
||||
fatal_procres(~"run-fail test isn't valgrind-clean!", procres);
|
||||
}
|
||||
|
||||
check_correct_failure_status(procres);
|
||||
@ -74,20 +74,20 @@ fn check_correct_failure_status(procres: procres) {
|
||||
}
|
||||
}
|
||||
|
||||
fn run_rpass_test(config: config, props: test_props, testfile: str) {
|
||||
fn run_rpass_test(config: config, props: test_props, testfile: ~str) {
|
||||
let mut procres = compile_test(config, props, testfile);
|
||||
|
||||
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
||||
if procres.status != 0 { fatal_procres(~"compilation failed!", procres); }
|
||||
|
||||
procres = exec_compiled_test(config, props, testfile);
|
||||
|
||||
if procres.status != 0 { fatal_procres("test run failed!", procres); }
|
||||
if procres.status != 0 { fatal_procres(~"test run failed!", procres); }
|
||||
}
|
||||
|
||||
fn run_pretty_test(config: config, props: test_props, testfile: str) {
|
||||
fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
|
||||
if option::is_some(props.pp_exact) {
|
||||
logv(config, "testing for exact pretty-printing");
|
||||
} else { logv(config, "testing for converging pretty-printing"); }
|
||||
logv(config, ~"testing for exact pretty-printing");
|
||||
} else { logv(config, ~"testing for converging pretty-printing"); }
|
||||
|
||||
let rounds =
|
||||
alt props.pp_exact { option::some(_) { 1 } option::none { 2 } };
|
||||
@ -120,10 +120,10 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
|
||||
|
||||
if option::is_some(props.pp_exact) {
|
||||
// Now we have to care about line endings
|
||||
let cr = "\r";
|
||||
let cr = ~"\r";
|
||||
check (str::is_not_empty(cr));
|
||||
actual = str::replace(actual, cr, "");
|
||||
expected = str::replace(expected, cr, "");
|
||||
actual = str::replace(actual, cr, ~"");
|
||||
expected = str::replace(expected, cr, ~"");
|
||||
}
|
||||
|
||||
compare_source(expected, actual);
|
||||
@ -132,25 +132,25 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
|
||||
let procres = typecheck_source(config, props, testfile, actual);
|
||||
|
||||
if procres.status != 0 {
|
||||
fatal_procres("pretty-printed source does not typecheck", procres);
|
||||
fatal_procres(~"pretty-printed source does not typecheck", procres);
|
||||
}
|
||||
|
||||
ret;
|
||||
|
||||
fn print_source(config: config, testfile: str, src: str) -> procres {
|
||||
fn print_source(config: config, testfile: ~str, src: ~str) -> procres {
|
||||
compose_and_run(config, testfile, make_pp_args(config, testfile),
|
||||
~[], config.compile_lib_path, option::some(src))
|
||||
}
|
||||
|
||||
fn make_pp_args(config: config, _testfile: str) -> procargs {
|
||||
fn make_pp_args(config: config, _testfile: ~str) -> procargs {
|
||||
let prog = config.rustc_path;
|
||||
let args = ~["-", "--pretty", "normal"];
|
||||
let args = ~[~"-", ~"--pretty", ~"normal"];
|
||||
ret {prog: prog, args: args};
|
||||
}
|
||||
|
||||
fn compare_source(expected: str, actual: str) {
|
||||
fn compare_source(expected: ~str, actual: ~str) {
|
||||
if expected != actual {
|
||||
error("pretty-printed source does not match expected source");
|
||||
error(~"pretty-printed source does not match expected source");
|
||||
let msg =
|
||||
#fmt["\n\
|
||||
expected:\n\
|
||||
@ -169,31 +169,32 @@ actual:\n\
|
||||
}
|
||||
|
||||
fn typecheck_source(config: config, props: test_props,
|
||||
testfile: str, src: str) -> procres {
|
||||
testfile: ~str, src: ~str) -> procres {
|
||||
compose_and_run_compiler(
|
||||
config, props, testfile,
|
||||
make_typecheck_args(config, testfile),
|
||||
option::some(src))
|
||||
}
|
||||
|
||||
fn make_typecheck_args(config: config, testfile: str) -> procargs {
|
||||
fn make_typecheck_args(config: config, testfile: ~str) -> procargs {
|
||||
let prog = config.rustc_path;
|
||||
let mut args = ~["-", "--no-trans", "--lib", "-L", config.build_base,
|
||||
"-L", aux_output_dir_name(config, testfile)];
|
||||
let mut args = ~[~"-",
|
||||
~"--no-trans", ~"--lib", ~"-L", config.build_base,
|
||||
~"-L", aux_output_dir_name(config, testfile)];
|
||||
args += split_maybe_args(config.rustcflags);
|
||||
ret {prog: prog, args: args};
|
||||
}
|
||||
}
|
||||
|
||||
fn check_error_patterns(props: test_props,
|
||||
testfile: str,
|
||||
testfile: ~str,
|
||||
procres: procres) {
|
||||
if vec::is_empty(props.error_patterns) {
|
||||
fatal("no error pattern specified in " + testfile);
|
||||
fatal(~"no error pattern specified in " + testfile);
|
||||
}
|
||||
|
||||
if procres.status == 0 {
|
||||
fatal("process did not return an error status");
|
||||
fatal(~"process did not return an error status");
|
||||
}
|
||||
|
||||
let mut next_err_idx = 0u;
|
||||
@ -223,12 +224,12 @@ fn check_error_patterns(props: test_props,
|
||||
for missing_patterns.each |pattern| {
|
||||
error(#fmt["error pattern '%s' not found!", pattern]);
|
||||
}
|
||||
fatal_procres("multiple error patterns not found", procres);
|
||||
fatal_procres(~"multiple error patterns not found", procres);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_expected_errors(expected_errors: ~[errors::expected_error],
|
||||
testfile: str,
|
||||
testfile: ~str,
|
||||
procres: procres) {
|
||||
|
||||
// true if we found the error in question
|
||||
@ -236,7 +237,7 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
|
||||
vec::len(expected_errors), false));
|
||||
|
||||
if procres.status == 0 {
|
||||
fatal("process did not return an error status");
|
||||
fatal(~"process did not return an error status");
|
||||
}
|
||||
|
||||
let prefixes = vec::map(expected_errors, |ee| {
|
||||
@ -266,12 +267,12 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
|
||||
}
|
||||
|
||||
// ignore this msg which gets printed at the end
|
||||
if str::contains(line, "aborting due to") {
|
||||
if str::contains(line, ~"aborting due to") {
|
||||
was_expected = true;
|
||||
}
|
||||
|
||||
if !was_expected && (str::contains(line, "error") ||
|
||||
str::contains(line, "warning")) {
|
||||
if !was_expected && (str::contains(line, ~"error") ||
|
||||
str::contains(line, ~"warning")) {
|
||||
fatal_procres(#fmt["unexpected error pattern '%s'!", line],
|
||||
procres);
|
||||
}
|
||||
@ -286,13 +287,13 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
|
||||
}
|
||||
}
|
||||
|
||||
type procargs = {prog: str, args: ~[str]};
|
||||
type procargs = {prog: ~str, args: ~[~str]};
|
||||
|
||||
type procres = {status: int, stdout: str, stderr: str, cmdline: str};
|
||||
type procres = {status: int, stdout: ~str, stderr: ~str, cmdline: ~str};
|
||||
|
||||
fn compile_test(config: config, props: test_props,
|
||||
testfile: str) -> procres {
|
||||
let link_args = ~["-L", aux_output_dir_name(config, testfile)];
|
||||
testfile: ~str) -> procres {
|
||||
let link_args = ~[~"-L", aux_output_dir_name(config, testfile)];
|
||||
compose_and_run_compiler(
|
||||
config, props, testfile,
|
||||
make_compile_args(config, props, link_args,
|
||||
@ -301,7 +302,7 @@ fn compile_test(config: config, props: test_props,
|
||||
}
|
||||
|
||||
fn exec_compiled_test(config: config, props: test_props,
|
||||
testfile: str) -> procres {
|
||||
testfile: ~str) -> procres {
|
||||
compose_and_run(config, testfile,
|
||||
make_run_args(config, props, testfile),
|
||||
props.exec_env,
|
||||
@ -311,20 +312,20 @@ fn exec_compiled_test(config: config, props: test_props,
|
||||
fn compose_and_run_compiler(
|
||||
config: config,
|
||||
props: test_props,
|
||||
testfile: str,
|
||||
testfile: ~str,
|
||||
args: procargs,
|
||||
input: option<str>) -> procres {
|
||||
input: option<~str>) -> procres {
|
||||
|
||||
if props.aux_builds.is_not_empty() {
|
||||
ensure_dir(aux_output_dir_name(config, testfile));
|
||||
}
|
||||
|
||||
let extra_link_args = ~["-L", aux_output_dir_name(config, testfile)];
|
||||
let extra_link_args = ~[~"-L", aux_output_dir_name(config, testfile)];
|
||||
|
||||
do vec::iter(props.aux_builds) |rel_ab| {
|
||||
let abs_ab = path::connect(config.aux_base, rel_ab);
|
||||
let aux_args =
|
||||
make_compile_args(config, props, ~["--lib"] + extra_link_args,
|
||||
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
|
||||
|a,b| make_lib_name(a, b, testfile), abs_ab);
|
||||
let auxres = compose_and_run(config, abs_ab, aux_args, ~[],
|
||||
config.compile_lib_path, option::none);
|
||||
@ -346,38 +347,38 @@ fn ensure_dir(path: path) {
|
||||
}
|
||||
}
|
||||
|
||||
fn compose_and_run(config: config, testfile: str,
|
||||
fn compose_and_run(config: config, testfile: ~str,
|
||||
procargs: procargs,
|
||||
procenv: ~[(str, str)],
|
||||
lib_path: str,
|
||||
input: option<str>) -> procres {
|
||||
procenv: ~[(~str, ~str)],
|
||||
lib_path: ~str,
|
||||
input: option<~str>) -> procres {
|
||||
ret program_output(config, testfile, lib_path,
|
||||
procargs.prog, procargs.args, procenv, input);
|
||||
}
|
||||
|
||||
fn make_compile_args(config: config, props: test_props, extras: ~[str],
|
||||
xform: fn(config, str) -> str, testfile: str) ->
|
||||
fn make_compile_args(config: config, props: test_props, extras: ~[~str],
|
||||
xform: fn(config, ~str) -> ~str, testfile: ~str) ->
|
||||
procargs {
|
||||
let prog = config.rustc_path;
|
||||
let mut args = ~[testfile, "-o", xform(config, testfile),
|
||||
"-L", config.build_base] + extras;
|
||||
let mut args = ~[testfile, ~"-o", xform(config, testfile),
|
||||
~"-L", config.build_base] + extras;
|
||||
args += split_maybe_args(config.rustcflags);
|
||||
args += split_maybe_args(props.compile_flags);
|
||||
ret {prog: prog, args: args};
|
||||
}
|
||||
|
||||
fn make_lib_name(config: config, auxfile: str, testfile: str) -> str {
|
||||
fn make_lib_name(config: config, auxfile: ~str, testfile: ~str) -> ~str {
|
||||
// what we return here is not particularly important, as it
|
||||
// happens; rustc ignores everything except for the directory.
|
||||
let auxname = output_testname(auxfile);
|
||||
path::connect(aux_output_dir_name(config, testfile), auxname)
|
||||
}
|
||||
|
||||
fn make_exe_name(config: config, testfile: str) -> str {
|
||||
fn make_exe_name(config: config, testfile: ~str) -> ~str {
|
||||
output_base_name(config, testfile) + os::exe_suffix()
|
||||
}
|
||||
|
||||
fn make_run_args(config: config, _props: test_props, testfile: str) ->
|
||||
fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
|
||||
procargs {
|
||||
let toolargs = {
|
||||
// If we've got another tool to run under (valgrind),
|
||||
@ -394,9 +395,9 @@ fn make_run_args(config: config, _props: test_props, testfile: str) ->
|
||||
ret {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
|
||||
}
|
||||
|
||||
fn split_maybe_args(argstr: option<str>) -> ~[str] {
|
||||
fn rm_whitespace(v: ~[str]) -> ~[str] {
|
||||
fn flt(&&s: str) -> option<str> {
|
||||
fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
|
||||
fn rm_whitespace(v: ~[~str]) -> ~[~str] {
|
||||
fn flt(&&s: ~str) -> option<~str> {
|
||||
if !str::is_whitespace(s) { option::some(s) } else { option::none }
|
||||
}
|
||||
vec::filter_map(v, flt)
|
||||
@ -408,9 +409,9 @@ fn split_maybe_args(argstr: option<str>) -> ~[str] {
|
||||
}
|
||||
}
|
||||
|
||||
fn program_output(config: config, testfile: str, lib_path: str, prog: str,
|
||||
args: ~[str], env: ~[(str, str)],
|
||||
input: option<str>) -> procres {
|
||||
fn program_output(config: config, testfile: ~str, lib_path: ~str, prog: ~str,
|
||||
args: ~[~str], env: ~[(~str, ~str)],
|
||||
input: option<~str>) -> procres {
|
||||
let cmdline =
|
||||
{
|
||||
let cmdline = make_cmdline(lib_path, prog, args);
|
||||
@ -429,8 +430,8 @@ fn program_output(config: config, testfile: str, lib_path: str, prog: str,
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn make_cmdline(_libpath: str, prog: str, args: ~[str]) -> str {
|
||||
#fmt["%s %s", prog, str::connect(args, " ")]
|
||||
fn make_cmdline(_libpath: ~str, prog: ~str, args: ~[~str]) -> ~str {
|
||||
#fmt["%s %s", prog, str::connect(args, ~" ")]
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
@ -441,47 +442,48 @@ fn make_cmdline(libpath: str, prog: str, args: ~[str]) -> str {
|
||||
|
||||
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
|
||||
// for diagnostic purposes
|
||||
fn lib_path_cmd_prefix(path: str) -> str {
|
||||
fn lib_path_cmd_prefix(path: ~str) -> ~str {
|
||||
#fmt["%s=\"%s\"", util::lib_path_env_var(), util::make_new_path(path)]
|
||||
}
|
||||
|
||||
fn dump_output(config: config, testfile: str, out: str, err: str) {
|
||||
dump_output_file(config, testfile, out, "out");
|
||||
dump_output_file(config, testfile, err, "err");
|
||||
fn dump_output(config: config, testfile: ~str, out: ~str, err: ~str) {
|
||||
dump_output_file(config, testfile, out, ~"out");
|
||||
dump_output_file(config, testfile, err, ~"err");
|
||||
maybe_dump_to_stdout(config, out, err);
|
||||
}
|
||||
|
||||
fn dump_output_file(config: config, testfile: str, out: str, extension: str) {
|
||||
fn dump_output_file(config: config, testfile: ~str,
|
||||
out: ~str, extension: ~str) {
|
||||
let outfile = make_out_name(config, testfile, extension);
|
||||
let writer = result::get(
|
||||
io::file_writer(outfile, ~[io::create, io::truncate]));
|
||||
writer.write_str(out);
|
||||
}
|
||||
|
||||
fn make_out_name(config: config, testfile: str, extension: str) -> str {
|
||||
output_base_name(config, testfile) + "." + extension
|
||||
fn make_out_name(config: config, testfile: ~str, extension: ~str) -> ~str {
|
||||
output_base_name(config, testfile) + ~"." + extension
|
||||
}
|
||||
|
||||
fn aux_output_dir_name(config: config, testfile: str) -> str {
|
||||
output_base_name(config, testfile) + ".libaux"
|
||||
fn aux_output_dir_name(config: config, testfile: ~str) -> ~str {
|
||||
output_base_name(config, testfile) + ~".libaux"
|
||||
}
|
||||
|
||||
fn output_testname(testfile: str) -> str {
|
||||
fn output_testname(testfile: ~str) -> ~str {
|
||||
let parts = str::split_char(path::basename(testfile), '.');
|
||||
str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ".")
|
||||
str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ~".")
|
||||
}
|
||||
|
||||
fn output_base_name(config: config, testfile: str) -> str {
|
||||
fn output_base_name(config: config, testfile: ~str) -> ~str {
|
||||
let base = config.build_base;
|
||||
let filename = output_testname(testfile);
|
||||
#fmt["%s%s.%s", base, filename, config.stage_id]
|
||||
}
|
||||
|
||||
fn maybe_dump_to_stdout(config: config, out: str, err: str) {
|
||||
fn maybe_dump_to_stdout(config: config, out: ~str, err: ~str) {
|
||||
if config.verbose {
|
||||
let sep1 = #fmt["------%s------------------------------", "stdout"];
|
||||
let sep2 = #fmt["------%s------------------------------", "stderr"];
|
||||
let sep3 = "------------------------------------------";
|
||||
let sep1 = #fmt["------%s------------------------------", ~"stdout"];
|
||||
let sep2 = #fmt["------%s------------------------------", ~"stderr"];
|
||||
let sep3 = ~"------------------------------------------";
|
||||
io::stdout().write_line(sep1);
|
||||
io::stdout().write_line(out);
|
||||
io::stdout().write_line(sep2);
|
||||
@ -490,11 +492,11 @@ fn maybe_dump_to_stdout(config: config, out: str, err: str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn error(err: str) { io::stdout().write_line(#fmt["\nerror: %s", err]); }
|
||||
fn error(err: ~str) { io::stdout().write_line(#fmt["\nerror: %s", err]); }
|
||||
|
||||
fn fatal(err: str) -> ! { error(err); fail; }
|
||||
fn fatal(err: ~str) -> ! { error(err); fail; }
|
||||
|
||||
fn fatal_procres(err: str, procres: procres) -> ! {
|
||||
fn fatal_procres(err: ~str, procres: procres) -> ! {
|
||||
let msg =
|
||||
#fmt["\n\
|
||||
error: %s\n\
|
||||
|
@ -3,7 +3,7 @@ import os::getenv;
|
||||
|
||||
import common::config;
|
||||
|
||||
fn make_new_path(path: str) -> str {
|
||||
fn make_new_path(path: ~str) -> ~str {
|
||||
|
||||
// Windows just uses PATH as the library search path, so we have to
|
||||
// maintain the current value while adding our own
|
||||
@ -17,7 +17,7 @@ fn make_new_path(path: str) -> str {
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn lib_path_env_var() -> str { "LD_LIBRARY_PATH" }
|
||||
fn lib_path_env_var() -> ~str { ~"LD_LIBRARY_PATH" }
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn lib_path_env_var() -> str { "DYLD_LIBRARY_PATH" }
|
||||
@ -28,12 +28,12 @@ fn lib_path_env_var() -> str { "PATH" }
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn path_div() -> str { ":" }
|
||||
fn path_div() -> ~str { ~":" }
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
fn path_div() -> str { ";" }
|
||||
|
||||
fn logv(config: config, s: str) {
|
||||
fn logv(config: config, s: ~str) {
|
||||
log(debug, s);
|
||||
if config.verbose { io::println(s); }
|
||||
}
|
||||
|
@ -8,23 +8,23 @@ import syntax::diagnostic;
|
||||
enum test_mode { tm_converge, tm_run, }
|
||||
type context = { mode: test_mode }; // + rng
|
||||
|
||||
fn write_file(filename: str, content: str) {
|
||||
fn write_file(filename: ~str, content: ~str) {
|
||||
result::get(
|
||||
io::file_writer(filename, ~[io::create, io::truncate]))
|
||||
.write_str(content);
|
||||
}
|
||||
|
||||
fn contains(haystack: str, needle: str) -> bool {
|
||||
fn contains(haystack: ~str, needle: ~str) -> bool {
|
||||
str::contains(haystack, needle)
|
||||
}
|
||||
|
||||
fn find_rust_files(&files: ~[str], path: str) {
|
||||
if str::ends_with(path, ".rs") && !contains(path, "utf8") {
|
||||
fn find_rust_files(&files: ~[~str], path: ~str) {
|
||||
if str::ends_with(path, ~".rs") && !contains(path, ~"utf8") {
|
||||
// ignoring "utf8" tests because something is broken
|
||||
files += ~[path];
|
||||
} else if os::path_is_dir(path)
|
||||
&& !contains(path, "compile-fail")
|
||||
&& !contains(path, "build") {
|
||||
&& !contains(path, ~"compile-fail")
|
||||
&& !contains(path, ~"build") {
|
||||
for os::list_dir_path(path).each |p| {
|
||||
find_rust_files(files, p);
|
||||
}
|
||||
@ -45,7 +45,7 @@ fn common_exprs() -> ~[ast::expr] {
|
||||
dse(ast::expr_again),
|
||||
dse(ast::expr_fail(option::none)),
|
||||
dse(ast::expr_fail(option::some(
|
||||
@dse(ast::expr_lit(@dsl(ast::lit_str(@"boo"/~))))))),
|
||||
@dse(ast::expr_lit(@dsl(ast::lit_str(@~"boo"))))))),
|
||||
dse(ast::expr_ret(option::none)),
|
||||
dse(ast::expr_lit(@dsl(ast::lit_nil))),
|
||||
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
|
||||
@ -228,31 +228,31 @@ fn under(n: uint, it: fn(uint)) {
|
||||
|
||||
fn devnull() -> io::writer { io::mem_buffer_writer(io::mem_buffer()) }
|
||||
|
||||
fn as_str(f: fn@(io::writer)) -> str {
|
||||
fn as_str(f: fn@(io::writer)) -> ~str {
|
||||
let buf = io::mem_buffer();
|
||||
f(io::mem_buffer_writer(buf));
|
||||
io::mem_buffer_str(buf)
|
||||
}
|
||||
|
||||
fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
|
||||
filename: str, cx: context) {
|
||||
filename: ~str, cx: context) {
|
||||
let stolen = steal(crate, cx.mode);
|
||||
let extra_exprs = vec::filter(common_exprs(),
|
||||
|a| safe_to_use_expr(a, cx.mode) );
|
||||
check_variants_T(crate, codemap, filename, "expr",
|
||||
check_variants_T(crate, codemap, filename, ~"expr",
|
||||
extra_exprs + stolen.exprs, pprust::expr_to_str,
|
||||
replace_expr_in_crate, cx);
|
||||
check_variants_T(crate, codemap, filename, "ty", stolen.tys,
|
||||
check_variants_T(crate, codemap, filename, ~"ty", stolen.tys,
|
||||
pprust::ty_to_str, replace_ty_in_crate, cx);
|
||||
}
|
||||
|
||||
fn check_variants_T<T: copy>(
|
||||
crate: ast::crate,
|
||||
codemap: codemap::codemap,
|
||||
filename: str,
|
||||
thing_label: str,
|
||||
filename: ~str,
|
||||
thing_label: ~str,
|
||||
things: ~[T],
|
||||
stringifier: fn@(@T) -> str,
|
||||
stringifier: fn@(@T) -> ~str,
|
||||
replacer: fn@(ast::crate, uint, T, test_mode) -> ast::crate,
|
||||
cx: context
|
||||
) {
|
||||
@ -263,9 +263,9 @@ fn check_variants_T<T: copy>(
|
||||
|
||||
if L < 100u {
|
||||
do under(uint::min(L, 20u)) |i| {
|
||||
log(error, "Replacing... #" + uint::str(i));
|
||||
log(error, ~"Replacing... #" + uint::str(i));
|
||||
do under(uint::min(L, 30u)) |j| {
|
||||
log(error, "With... " + stringifier(@things[j]));
|
||||
log(error, ~"With... " + stringifier(@things[j]));
|
||||
let crate2 = @replacer(crate, i, things[j], cx.mode);
|
||||
// It would be best to test the *crate* for stability, but
|
||||
// testing the string for stability is easier and ok for now.
|
||||
@ -276,7 +276,7 @@ fn check_variants_T<T: copy>(
|
||||
diagnostic::mk_span_handler(handler, codemap),
|
||||
crate2,
|
||||
filename,
|
||||
io::str_reader(""), a,
|
||||
io::str_reader(~""), a,
|
||||
pprust::no_ann(),
|
||||
false));
|
||||
alt cx.mode {
|
||||
@ -297,21 +297,26 @@ fn check_variants_T<T: copy>(
|
||||
}
|
||||
}
|
||||
|
||||
fn last_part(filename: str) -> str {
|
||||
fn last_part(filename: ~str) -> ~str {
|
||||
let ix = option::get(str::rfind_char(filename, '/'));
|
||||
str::slice(filename, ix + 1u, str::len(filename) - 3u)
|
||||
}
|
||||
|
||||
enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }
|
||||
enum happiness {
|
||||
passed,
|
||||
cleanly_rejected(~str),
|
||||
known_bug(~str),
|
||||
failed(~str),
|
||||
}
|
||||
|
||||
// We'd find more bugs if we could take an AST here, but
|
||||
// - that would find many "false positives" or unimportant bugs
|
||||
// - that would be tricky, requiring use of tasks or serialization
|
||||
// or randomness.
|
||||
// This seems to find plenty of bugs as it is :)
|
||||
fn check_whole_compiler(code: str, suggested_filename_prefix: str,
|
||||
fn check_whole_compiler(code: ~str, suggested_filename_prefix: ~str,
|
||||
allow_running: bool) {
|
||||
let filename = suggested_filename_prefix + ".rs";
|
||||
let filename = suggested_filename_prefix + ~".rs";
|
||||
write_file(filename, code);
|
||||
|
||||
let compile_result = check_compiling(filename);
|
||||
@ -324,102 +329,102 @@ fn check_whole_compiler(code: str, suggested_filename_prefix: str,
|
||||
alt run_result {
|
||||
passed | cleanly_rejected(_) | known_bug(_) {
|
||||
removeIfExists(suggested_filename_prefix);
|
||||
removeIfExists(suggested_filename_prefix + ".rs");
|
||||
removeDirIfExists(suggested_filename_prefix + ".dSYM");
|
||||
removeIfExists(suggested_filename_prefix + ~".rs");
|
||||
removeDirIfExists(suggested_filename_prefix + ~".dSYM");
|
||||
}
|
||||
failed(s) {
|
||||
log(error, "check_whole_compiler failure: " + s);
|
||||
log(error, "Saved as: " + filename);
|
||||
log(error, ~"check_whole_compiler failure: " + s);
|
||||
log(error, ~"Saved as: " + filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn removeIfExists(filename: str) {
|
||||
fn removeIfExists(filename: ~str) {
|
||||
// So sketchy!
|
||||
assert !contains(filename, " ");
|
||||
run::program_output("bash", ~["-c", "rm " + filename]);
|
||||
assert !contains(filename, ~" ");
|
||||
run::program_output(~"bash", ~[~"-c", ~"rm " + filename]);
|
||||
}
|
||||
|
||||
fn removeDirIfExists(filename: str) {
|
||||
fn removeDirIfExists(filename: ~str) {
|
||||
// So sketchy!
|
||||
assert !contains(filename, " ");
|
||||
run::program_output("bash", ~["-c", "rm -r " + filename]);
|
||||
assert !contains(filename, ~" ");
|
||||
run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename]);
|
||||
}
|
||||
|
||||
fn check_running(exe_filename: str) -> happiness {
|
||||
fn check_running(exe_filename: ~str) -> happiness {
|
||||
let p = run::program_output(
|
||||
"/Users/jruderman/scripts/timed_run_rust_program.py",
|
||||
~"/Users/jruderman/scripts/timed_run_rust_program.py",
|
||||
~[exe_filename]);
|
||||
let comb = p.out + "\n" + p.err;
|
||||
let comb = p.out + ~"\n" + p.err;
|
||||
if str::len(comb) > 1u {
|
||||
log(error, "comb comb comb: " + comb);
|
||||
log(error, ~"comb comb comb: " + comb);
|
||||
}
|
||||
|
||||
if contains(comb, "Assertion failed:") {
|
||||
failed("C++ assertion failure")
|
||||
} else if contains(comb, "leaked memory in rust main loop") {
|
||||
if contains(comb, ~"Assertion failed:") {
|
||||
failed(~"C++ assertion failure")
|
||||
} else if contains(comb, ~"leaked memory in rust main loop") {
|
||||
// might also use exit code 134
|
||||
//failed("Leaked")
|
||||
known_bug("https://github.com/mozilla/rust/issues/910")
|
||||
} else if contains(comb, "src/rt/") {
|
||||
failed("Mentioned src/rt/")
|
||||
} else if contains(comb, "malloc") {
|
||||
failed("Mentioned malloc")
|
||||
known_bug(~"https://github.com/mozilla/rust/issues/910")
|
||||
} else if contains(comb, ~"src/rt/") {
|
||||
failed(~"Mentioned src/rt/")
|
||||
} else if contains(comb, ~"malloc") {
|
||||
failed(~"Mentioned malloc")
|
||||
} else {
|
||||
alt p.status {
|
||||
0 { passed }
|
||||
100 { cleanly_rejected("running: explicit fail") }
|
||||
101 | 247 { cleanly_rejected("running: timed out") }
|
||||
100 { cleanly_rejected(~"running: explicit fail") }
|
||||
101 | 247 { cleanly_rejected(~"running: timed out") }
|
||||
245 | 246 | 138 | 252 {
|
||||
known_bug("https://github.com/mozilla/rust/issues/1466")
|
||||
known_bug(~"https://github.com/mozilla/rust/issues/1466")
|
||||
}
|
||||
136 | 248 {
|
||||
known_bug(
|
||||
"SIGFPE - https://github.com/mozilla/rust/issues/944")
|
||||
~"SIGFPE - https://github.com/mozilla/rust/issues/944")
|
||||
}
|
||||
rc {
|
||||
failed("Rust program ran but exited with status " +
|
||||
failed(~"Rust program ran but exited with status " +
|
||||
int::str(rc))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_compiling(filename: str) -> happiness {
|
||||
fn check_compiling(filename: ~str) -> happiness {
|
||||
let p = run::program_output(
|
||||
"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\
|
||||
~"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\
|
||||
stage1/bin/rustc",
|
||||
~[filename]);
|
||||
|
||||
//#error("Status: %d", p.status);
|
||||
if p.status == 0 {
|
||||
passed
|
||||
} else if p.err != "" {
|
||||
if contains(p.err, "error:") {
|
||||
cleanly_rejected("rejected with span_error")
|
||||
} else if p.err != ~"" {
|
||||
if contains(p.err, ~"error:") {
|
||||
cleanly_rejected(~"rejected with span_error")
|
||||
} else {
|
||||
log(error, "Stderr: " + p.err);
|
||||
failed("Unfamiliar error message")
|
||||
log(error, ~"Stderr: " + p.err);
|
||||
failed(~"Unfamiliar error message")
|
||||
}
|
||||
} else if contains(p.out, "Assertion") && contains(p.out, "failed") {
|
||||
log(error, "Stdout: " + p.out);
|
||||
failed("Looks like an llvm assertion failure")
|
||||
} else if contains(p.out, "internal compiler error unimplemented") {
|
||||
known_bug("Something unimplemented")
|
||||
} else if contains(p.out, "internal compiler error") {
|
||||
log(error, "Stdout: " + p.out);
|
||||
failed("internal compiler error")
|
||||
} else if contains(p.out, ~"Assertion") && contains(p.out, ~"failed") {
|
||||
log(error, ~"Stdout: " + p.out);
|
||||
failed(~"Looks like an llvm assertion failure")
|
||||
} else if contains(p.out, ~"internal compiler error unimplemented") {
|
||||
known_bug(~"Something unimplemented")
|
||||
} else if contains(p.out, ~"internal compiler error") {
|
||||
log(error, ~"Stdout: " + p.out);
|
||||
failed(~"internal compiler error")
|
||||
|
||||
} else {
|
||||
log(error, p.status);
|
||||
log(error, "!Stdout: " + p.out);
|
||||
failed("What happened?")
|
||||
log(error, ~"!Stdout: " + p.out);
|
||||
failed(~"What happened?")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn parse_and_print(code: @str/~) -> str {
|
||||
let filename = "tmp.rs";
|
||||
fn parse_and_print(code: @~str) -> ~str {
|
||||
let filename = ~"tmp.rs";
|
||||
let sess = parse::new_parse_sess(option::none);
|
||||
write_file(filename, *code);
|
||||
let crate = parse::parse_crate_from_source_str(
|
||||
@ -450,49 +455,49 @@ fn has_raw_pointers(c: ast::crate) -> bool {
|
||||
ret *has_rp;
|
||||
}
|
||||
|
||||
fn content_is_dangerous_to_run(code: str) -> bool {
|
||||
fn content_is_dangerous_to_run(code: ~str) -> bool {
|
||||
let dangerous_patterns =
|
||||
~["xfail-test",
|
||||
"import", // espeically fs, run
|
||||
"extern",
|
||||
"unsafe",
|
||||
"log"]; // python --> rust pipe deadlock?
|
||||
~[~"xfail-test",
|
||||
~"import", // espeically fs, run
|
||||
~"extern",
|
||||
~"unsafe",
|
||||
~"log"]; // python --> rust pipe deadlock?
|
||||
|
||||
for dangerous_patterns.each |p| { if contains(code, p) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn content_is_dangerous_to_compile(code: str) -> bool {
|
||||
fn content_is_dangerous_to_compile(code: ~str) -> bool {
|
||||
let dangerous_patterns =
|
||||
~["xfail-test"];
|
||||
~[~"xfail-test"];
|
||||
|
||||
for dangerous_patterns.each |p| { if contains(code, p) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn content_might_not_converge(code: str) -> bool {
|
||||
fn content_might_not_converge(code: ~str) -> bool {
|
||||
let confusing_patterns =
|
||||
~["xfail-test",
|
||||
"xfail-pretty",
|
||||
"self", // crazy rules enforced by parser not typechecker?
|
||||
"spawn", // precedence issues?
|
||||
"bind", // precedence issues?
|
||||
" be ", // don't want to replace its child with a non-call:
|
||||
~[~"xfail-test",
|
||||
~"xfail-pretty",
|
||||
~"self", // crazy rules enforced by parser not typechecker?
|
||||
~"spawn", // precedence issues?
|
||||
~"bind", // precedence issues?
|
||||
~" be ", // don't want to replace its child with a non-call:
|
||||
// "Non-call expression in tail call"
|
||||
"\n\n\n\n\n" // https://github.com/mozilla/rust/issues/850
|
||||
~"\n\n\n\n\n" // https://github.com/mozilla/rust/issues/850
|
||||
];
|
||||
|
||||
for confusing_patterns.each |p| { if contains(code, p) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn file_might_not_converge(filename: str) -> bool {
|
||||
fn file_might_not_converge(filename: ~str) -> bool {
|
||||
let confusing_files = ~[
|
||||
"expr-alt.rs", // pretty-printing "(a = b) = c"
|
||||
~"expr-alt.rs", // pretty-printing "(a = b) = c"
|
||||
// vs "a = b = c" and wrapping
|
||||
"block-arg-in-ternary.rs", // wrapping
|
||||
"move-3-unique.rs", // 0 becomes (0), but both seem reasonable. wtf?
|
||||
"move-3.rs" // 0 becomes (0), but both seem reasonable. wtf?
|
||||
~"block-arg-in-ternary.rs", // wrapping
|
||||
~"move-3-unique.rs", // 0 becomes (0), but both seem reasonable. wtf?
|
||||
~"move-3.rs" // 0 becomes (0), but both seem reasonable. wtf?
|
||||
];
|
||||
|
||||
|
||||
@ -501,7 +506,7 @@ fn file_might_not_converge(filename: str) -> bool {
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn check_roundtrip_convergence(code: @str/~, maxIters: uint) {
|
||||
fn check_roundtrip_convergence(code: @~str, maxIters: uint) {
|
||||
|
||||
let mut i = 0u;
|
||||
let mut newv = code;
|
||||
@ -519,16 +524,16 @@ fn check_roundtrip_convergence(code: @str/~, maxIters: uint) {
|
||||
#error("Converged after %u iterations", i);
|
||||
} else {
|
||||
#error("Did not converge after %u iterations!", i);
|
||||
write_file("round-trip-a.rs", *oldv);
|
||||
write_file("round-trip-b.rs", *newv);
|
||||
run::run_program("diff",
|
||||
~["-w", "-u", "round-trip-a.rs",
|
||||
"round-trip-b.rs"]);
|
||||
fail "Mismatch";
|
||||
write_file(~"round-trip-a.rs", *oldv);
|
||||
write_file(~"round-trip-b.rs", *newv);
|
||||
run::run_program(~"diff",
|
||||
~[~"-w", ~"-u", ~"round-trip-a.rs",
|
||||
~"round-trip-b.rs"]);
|
||||
fail ~"Mismatch";
|
||||
}
|
||||
}
|
||||
|
||||
fn check_convergence(files: ~[str]) {
|
||||
fn check_convergence(files: ~[~str]) {
|
||||
#error("pp convergence tests: %u files", vec::len(files));
|
||||
for files.each |file| {
|
||||
if !file_might_not_converge(file) {
|
||||
@ -543,7 +548,7 @@ fn check_convergence(files: ~[str]) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_variants(files: ~[str], cx: context) {
|
||||
fn check_variants(files: ~[~str], cx: context) {
|
||||
for files.each |file| {
|
||||
if cx.mode == tm_converge && file_might_not_converge(file) {
|
||||
#error("Skipping convergence test based on\
|
||||
@ -552,7 +557,7 @@ fn check_variants(files: ~[str], cx: context) {
|
||||
}
|
||||
|
||||
let s = @result::get(io::read_whole_file_str(file));
|
||||
if contains(*s, "#") {
|
||||
if contains(*s, ~"#") {
|
||||
again; // Macros are confusing
|
||||
}
|
||||
if cx.mode == tm_converge && content_might_not_converge(*s) {
|
||||
@ -562,7 +567,7 @@ fn check_variants(files: ~[str], cx: context) {
|
||||
again;
|
||||
}
|
||||
|
||||
log(error, "check_variants: " + file);
|
||||
log(error, ~"check_variants: " + file);
|
||||
let sess = parse::new_parse_sess(option::none);
|
||||
let crate =
|
||||
parse::parse_crate_from_source_str(
|
||||
@ -582,7 +587,7 @@ fn check_variants(files: ~[str], cx: context) {
|
||||
}
|
||||
}
|
||||
|
||||
fn main(args: ~[str]) {
|
||||
fn main(args: ~[~str]) {
|
||||
if vec::len(args) != 2u {
|
||||
#error("usage: %s <testdir>", args[0]);
|
||||
ret;
|
||||
|
@ -38,16 +38,16 @@ pure fn is_true(v: bool) -> bool { v }
|
||||
pure fn is_false(v: bool) -> bool { !v }
|
||||
|
||||
/// Parse logic value from `s`
|
||||
pure fn from_str(s: str) -> option<bool> {
|
||||
pure fn from_str(s: ~str) -> option<bool> {
|
||||
alt check s {
|
||||
"true" { some(true) }
|
||||
"false" { some(false) }
|
||||
~"true" { some(true) }
|
||||
~"false" { some(false) }
|
||||
_ { none }
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert `v` into a string
|
||||
pure fn to_str(v: bool) -> str { if v { "true" } else { "false" } }
|
||||
pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
|
||||
|
||||
/**
|
||||
* Iterates over all truth values by passing them to `blk` in an unspecified
|
||||
@ -70,8 +70,8 @@ fn test_bool_from_str() {
|
||||
|
||||
#[test]
|
||||
fn test_bool_to_str() {
|
||||
assert to_str(false) == "false";
|
||||
assert to_str(true) == "true";
|
||||
assert to_str(false) == ~"false";
|
||||
assert to_str(true) == ~"true";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -132,15 +132,15 @@ pure fn to_digit(c: char, radix: uint) -> option<uint> {
|
||||
* - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
|
||||
* - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
|
||||
*/
|
||||
fn escape_unicode(c: char) -> str {
|
||||
fn escape_unicode(c: char) -> ~str {
|
||||
let s = u32::to_str(c as u32, 16u);
|
||||
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
|
||||
else if c <= '\uffff' { ('u', 4u) }
|
||||
else { ('U', 8u) });
|
||||
assert str::len(s) <= pad;
|
||||
let mut out = "\\";
|
||||
let mut out = ~"\\";
|
||||
str::push_str(out, str::from_char(c));
|
||||
for uint::range(str::len(s), pad) |_i| { str::push_str(out, "0"); }
|
||||
for uint::range(str::len(s), pad) |_i| { str::push_str(out, ~"0"); }
|
||||
str::push_str(out, s);
|
||||
ret out;
|
||||
}
|
||||
@ -157,14 +157,14 @@ fn escape_unicode(c: char) -> str {
|
||||
* - Any other chars in the range [0x20,0x7e] are not escaped.
|
||||
* - 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 {
|
||||
'\t' { "\\t" }
|
||||
'\r' { "\\r" }
|
||||
'\n' { "\\n" }
|
||||
'\\' { "\\\\" }
|
||||
'\'' { "\\'" }
|
||||
'"' { "\\\"" }
|
||||
'\t' { ~"\\t" }
|
||||
'\r' { ~"\\r" }
|
||||
'\n' { ~"\\n" }
|
||||
'\\' { ~"\\\\" }
|
||||
'\'' { ~"\\'" }
|
||||
'"' { ~"\\\"" }
|
||||
'\x20' to '\x7e' { str::from_char(c) }
|
||||
_ { escape_unicode(c) }
|
||||
}
|
||||
@ -232,8 +232,8 @@ fn test_to_digit() {
|
||||
|
||||
#[test]
|
||||
fn test_is_ascii() {
|
||||
assert str::all("banana", char::is_ascii);
|
||||
assert ! str::all("ประเทศไทย中华Việt Nam", char::is_ascii);
|
||||
assert str::all(~"banana", char::is_ascii);
|
||||
assert ! str::all(~"ประเทศไทย中华Việt Nam", char::is_ascii);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -248,28 +248,28 @@ fn test_is_digit() {
|
||||
|
||||
#[test]
|
||||
fn test_escape_default() {
|
||||
assert escape_default('\n') == "\\n";
|
||||
assert escape_default('\r') == "\\r";
|
||||
assert escape_default('\'') == "\\'";
|
||||
assert escape_default('"') == "\\\"";
|
||||
assert escape_default(' ') == " ";
|
||||
assert escape_default('a') == "a";
|
||||
assert escape_default('~') == "~";
|
||||
assert escape_default('\x00') == "\\x00";
|
||||
assert escape_default('\x1f') == "\\x1f";
|
||||
assert escape_default('\x7f') == "\\x7f";
|
||||
assert escape_default('\xff') == "\\xff";
|
||||
assert escape_default('\u011b') == "\\u011b";
|
||||
assert escape_default('\U0001d4b6') == "\\U0001d4b6";
|
||||
assert escape_default('\n') == ~"\\n";
|
||||
assert escape_default('\r') == ~"\\r";
|
||||
assert escape_default('\'') == ~"\\'";
|
||||
assert escape_default('"') == ~"\\\"";
|
||||
assert escape_default(' ') == ~" ";
|
||||
assert escape_default('a') == ~"a";
|
||||
assert escape_default('~') == ~"~";
|
||||
assert escape_default('\x00') == ~"\\x00";
|
||||
assert escape_default('\x1f') == ~"\\x1f";
|
||||
assert escape_default('\x7f') == ~"\\x7f";
|
||||
assert escape_default('\xff') == ~"\\xff";
|
||||
assert escape_default('\u011b') == ~"\\u011b";
|
||||
assert escape_default('\U0001d4b6') == ~"\\U0001d4b6";
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_escape_unicode() {
|
||||
assert escape_unicode('\x00') == "\\x00";
|
||||
assert escape_unicode('\n') == "\\x0a";
|
||||
assert escape_unicode(' ') == "\\x20";
|
||||
assert escape_unicode('a') == "\\x61";
|
||||
assert escape_unicode('\u011b') == "\\u011b";
|
||||
assert escape_unicode('\U0001d4b6') == "\\U0001d4b6";
|
||||
assert escape_unicode('\x00') == ~"\\x00";
|
||||
assert escape_unicode('\n') == ~"\\x0a";
|
||||
assert escape_unicode(' ') == ~"\\x20";
|
||||
assert escape_unicode('a') == ~"\\x61";
|
||||
assert escape_unicode('\u011b') == ~"\\u011b";
|
||||
assert escape_unicode('\U0001d4b6') == ~"\\U0001d4b6";
|
||||
}
|
||||
|
@ -142,9 +142,9 @@ fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
|
||||
let p = portref(rustrt::rust_port_take(*ch));
|
||||
|
||||
if ptr::is_null(p.p) {
|
||||
fail "unable to locate port for channel"
|
||||
fail ~"unable to locate port for channel"
|
||||
} else if rustrt::get_task_id() != rustrt::rust_port_task(p.p) {
|
||||
fail "unable to access unowned port"
|
||||
fail ~"unable to access unowned port"
|
||||
}
|
||||
|
||||
f(p.p)
|
||||
@ -245,7 +245,7 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
|
||||
} else if resport == (**p_b).po {
|
||||
either::right(recv(p_b))
|
||||
} else {
|
||||
fail "unexpected result from rust_port_select";
|
||||
fail ~"unexpected result from rust_port_select";
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,13 +348,13 @@ fn test_select2_available() {
|
||||
let ch_a = chan(po_a);
|
||||
let ch_b = chan(po_b);
|
||||
|
||||
send(ch_a, "a");
|
||||
send(ch_a, ~"a");
|
||||
|
||||
assert select2(po_a, po_b) == either::left("a");
|
||||
assert select2(po_a, po_b) == either::left(~"a");
|
||||
|
||||
send(ch_b, "b");
|
||||
send(ch_b, ~"b");
|
||||
|
||||
assert select2(po_a, po_b) == either::right("b");
|
||||
assert select2(po_a, po_b) == either::right(~"b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -367,17 +367,17 @@ fn test_select2_rendezvous() {
|
||||
for iter::repeat(10u) {
|
||||
do task::spawn {
|
||||
for iter::repeat(10u) { task::yield() }
|
||||
send(ch_a, "a");
|
||||
send(ch_a, ~"a");
|
||||
};
|
||||
|
||||
assert select2(po_a, po_b) == either::left("a");
|
||||
assert select2(po_a, po_b) == either::left(~"a");
|
||||
|
||||
do task::spawn {
|
||||
for iter::repeat(10u) { task::yield() }
|
||||
send(ch_b, "b");
|
||||
send(ch_b, ~"b");
|
||||
};
|
||||
|
||||
assert select2(po_a, po_b) == either::right("b");
|
||||
assert select2(po_a, po_b) == either::right(~"b");
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,12 +394,12 @@ fn test_select2_stress() {
|
||||
for iter::repeat(times) {
|
||||
do task::spawn {
|
||||
for iter::repeat(msgs) {
|
||||
send(ch_a, "a")
|
||||
send(ch_a, ~"a")
|
||||
}
|
||||
};
|
||||
do task::spawn {
|
||||
for iter::repeat(msgs) {
|
||||
send(ch_b, "b")
|
||||
send(ch_b, ~"b")
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -408,8 +408,8 @@ fn test_select2_stress() {
|
||||
let mut bs = 0;
|
||||
for iter::repeat(msgs * times * 2u) {
|
||||
alt check select2(po_a, po_b) {
|
||||
either::left("a") { as += 1 }
|
||||
either::right("b") { bs += 1 }
|
||||
either::left(~"a") { as += 1 }
|
||||
either::right(~"b") { bs += 1 }
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,8 +421,8 @@ fn test_select2_stress() {
|
||||
fn test_recv_chan() {
|
||||
let po = port();
|
||||
let ch = chan(po);
|
||||
send(ch, "flower");
|
||||
assert recv_chan(ch) == "flower";
|
||||
send(ch, ~"flower");
|
||||
assert recv_chan(ch) == ~"flower";
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -430,7 +430,7 @@ fn test_recv_chan() {
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_recv_chan_dead() {
|
||||
let ch = chan(port());
|
||||
send(ch, "flower");
|
||||
send(ch, ~"flower");
|
||||
recv_chan(ch);
|
||||
}
|
||||
|
||||
@ -439,7 +439,7 @@ fn test_recv_chan_dead() {
|
||||
fn test_recv_chan_wrong_task() {
|
||||
let po = port();
|
||||
let ch = chan(po);
|
||||
send(ch, "flower");
|
||||
send(ch, ~"flower");
|
||||
assert result::is_err(task::try(||
|
||||
recv_chan(ch)
|
||||
))
|
||||
@ -464,9 +464,9 @@ fn test_chan_peek() {
|
||||
fn test_listen() {
|
||||
do listen |parent| {
|
||||
do task::spawn {
|
||||
parent.send("oatmeal-salad");
|
||||
parent.send(~"oatmeal-salad");
|
||||
}
|
||||
assert parent.recv() == "oatmeal-salad";
|
||||
assert parent.recv() == ~"oatmeal-salad";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,6 @@ mod std {
|
||||
* any code paths following the appearance of this function as unreachable.
|
||||
*/
|
||||
fn unreachable() -> ! {
|
||||
fail "Internal error: entered unreachable code";
|
||||
fail ~"Internal error: entered unreachable code";
|
||||
}
|
||||
|
||||
|
@ -32,10 +32,10 @@ impl private_methods<T> for dlist_node<T> {
|
||||
alt neighbour.prev {
|
||||
some(me) {
|
||||
if !box::ptr_eq(*self, *me) {
|
||||
fail "Asymmetric next-link in dlist node."
|
||||
fail ~"Asymmetric next-link in dlist node."
|
||||
}
|
||||
}
|
||||
none { fail "One-way next-link in dlist node." }
|
||||
none { fail ~"One-way next-link in dlist node." }
|
||||
}
|
||||
}
|
||||
none { }
|
||||
@ -45,10 +45,10 @@ impl private_methods<T> for dlist_node<T> {
|
||||
alt neighbour.next {
|
||||
some(me) {
|
||||
if !box::ptr_eq(*me, *self) {
|
||||
fail "Asymmetric prev-link in dlist node."
|
||||
fail ~"Asymmetric prev-link in dlist node."
|
||||
}
|
||||
}
|
||||
none { fail "One-way prev-link in dlist node." }
|
||||
none { fail ~"One-way prev-link in dlist node." }
|
||||
}
|
||||
}
|
||||
none { }
|
||||
@ -66,7 +66,7 @@ impl extensions<T> for dlist_node<T> {
|
||||
pure fn next_node() -> dlist_node<T> {
|
||||
alt self.next_link() {
|
||||
some(nobe) { nobe }
|
||||
none { fail "This dlist node has no next neighbour." }
|
||||
none { fail ~"This dlist node has no next neighbour." }
|
||||
}
|
||||
}
|
||||
/// Get the previous node in the list, if there is one.
|
||||
@ -78,7 +78,7 @@ impl extensions<T> for dlist_node<T> {
|
||||
pure fn prev_node() -> dlist_node<T> {
|
||||
alt self.prev_link() {
|
||||
some(nobe) { nobe }
|
||||
none { fail "This dlist node has no previous neighbour." }
|
||||
none { fail ~"This dlist node has no previous neighbour." }
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ impl extensions<T> for dlist_node<T> {
|
||||
if option::is_some(self.root) {
|
||||
option::get(self.root).remove(self);
|
||||
} else {
|
||||
fail "Removing an orphaned dlist node - what do I remove from?"
|
||||
fail ~"Removing an orphaned dlist node - what do I remove from?"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,12 +124,12 @@ impl private_methods<T> for dlist<T> {
|
||||
pure fn assert_mine(nobe: dlist_node<T>) {
|
||||
alt nobe.root {
|
||||
some(me) { assert box::ptr_eq(*self, *me); }
|
||||
none { fail "This node isn't on this dlist." }
|
||||
none { fail ~"This node isn't on this dlist." }
|
||||
}
|
||||
}
|
||||
fn make_mine(nobe: dlist_node<T>) {
|
||||
if option::is_some(nobe.root) {
|
||||
fail "Cannot insert node that's already on a dlist!"
|
||||
fail ~"Cannot insert node that's already on a dlist!"
|
||||
}
|
||||
nobe.root = some(self);
|
||||
}
|
||||
@ -287,14 +287,18 @@ impl extensions<T> for dlist<T> {
|
||||
pure fn head_n() -> dlist_node<T> {
|
||||
alt self.hd {
|
||||
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).
|
||||
pure fn tail_n() -> dlist_node<T> {
|
||||
alt self.tl {
|
||||
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."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ impl private_methods<A> for dvec<A> {
|
||||
unsafe {
|
||||
let data: *() = unsafe::reinterpret_cast(self.data);
|
||||
if data.is_null() {
|
||||
fail "Recursive use of dvec";
|
||||
fail ~"Recursive use of dvec";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,7 +91,7 @@ impl private_methods<A> for dvec<A> {
|
||||
let mut data = unsafe::reinterpret_cast(null::<()>());
|
||||
data <-> self.data;
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(data);
|
||||
if data_ptr.is_null() { fail "Recursive use of dvec"; }
|
||||
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
|
||||
ret f(data);
|
||||
}
|
||||
}
|
||||
@ -149,11 +149,11 @@ impl extensions<A> for dvec<A> {
|
||||
let mut data = unsafe::reinterpret_cast(null::<()>());
|
||||
data <-> self.data;
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(data);
|
||||
if data_ptr.is_null() { fail "Recursive use of dvec"; }
|
||||
log(error, "a");
|
||||
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
|
||||
log(error, ~"a");
|
||||
self.data <- ~[mut t];
|
||||
vec::push_all_move(self.data, data);
|
||||
log(error, "b");
|
||||
log(error, ~"b");
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ impl extensions<A:copy> for dvec<A> {
|
||||
|
||||
let length = self.len();
|
||||
if length == 0u {
|
||||
fail "attempt to retrieve the last element of an empty vector";
|
||||
fail ~"attempt to retrieve the last element of an empty vector";
|
||||
}
|
||||
|
||||
ret self.data[length - 1u];
|
||||
|
@ -78,31 +78,31 @@ mod ct {
|
||||
|
||||
|
||||
// A fragment of the output sequence
|
||||
enum piece { piece_string(str), piece_conv(conv), }
|
||||
type error_fn = fn@(str) -> ! ;
|
||||
enum piece { piece_string(~str), piece_conv(conv), }
|
||||
type error_fn = fn@(~str) -> ! ;
|
||||
|
||||
fn parse_fmt_string(s: str, error: error_fn) -> ~[piece] {
|
||||
fn parse_fmt_string(s: ~str, error: error_fn) -> ~[piece] {
|
||||
let mut pieces: ~[piece] = ~[];
|
||||
let lim = str::len(s);
|
||||
let mut buf = "";
|
||||
fn flush_buf(buf: str, &pieces: ~[piece]) -> str {
|
||||
let mut buf = ~"";
|
||||
fn flush_buf(buf: ~str, &pieces: ~[piece]) -> ~str {
|
||||
if str::len(buf) > 0u {
|
||||
let piece = piece_string(buf);
|
||||
vec::push(pieces, piece);
|
||||
}
|
||||
ret "";
|
||||
ret ~"";
|
||||
}
|
||||
let mut i = 0u;
|
||||
while i < lim {
|
||||
let size = str::utf8_char_width(s[i]);
|
||||
let curr = str::slice(s, i, i+size);
|
||||
if str::eq(curr, "%") {
|
||||
if str::eq(curr, ~"%") {
|
||||
i += 1u;
|
||||
if i >= lim {
|
||||
error("unterminated conversion at end of string");
|
||||
error(~"unterminated conversion at end of string");
|
||||
}
|
||||
let curr2 = str::slice(s, i, i+1u);
|
||||
if str::eq(curr2, "%") {
|
||||
if str::eq(curr2, ~"%") {
|
||||
buf += curr2;
|
||||
i += 1u;
|
||||
} else {
|
||||
@ -116,7 +116,7 @@ mod ct {
|
||||
flush_buf(buf, pieces);
|
||||
ret pieces;
|
||||
}
|
||||
fn peek_num(s: str, i: uint, lim: uint) ->
|
||||
fn peek_num(s: ~str, i: uint, lim: uint) ->
|
||||
option<{num: uint, next: uint}> {
|
||||
if i >= lim { ret none; }
|
||||
let c = s[i];
|
||||
@ -131,7 +131,7 @@ mod ct {
|
||||
}
|
||||
};
|
||||
}
|
||||
fn parse_conversion(s: str, i: uint, lim: uint, error: error_fn) ->
|
||||
fn parse_conversion(s: ~str, i: uint, lim: uint, error: error_fn) ->
|
||||
{piece: piece, next: uint} {
|
||||
let parm = parse_parameter(s, i, lim);
|
||||
let flags = parse_flags(s, parm.next, lim);
|
||||
@ -146,7 +146,7 @@ mod ct {
|
||||
ty: ty.ty}),
|
||||
next: ty.next};
|
||||
}
|
||||
fn parse_parameter(s: str, i: uint, lim: uint) ->
|
||||
fn parse_parameter(s: ~str, i: uint, lim: uint) ->
|
||||
{param: option<int>, next: uint} {
|
||||
if i >= lim { ret {param: none, next: i}; }
|
||||
let num = peek_num(s, i, lim);
|
||||
@ -161,12 +161,12 @@ mod ct {
|
||||
}
|
||||
};
|
||||
}
|
||||
fn parse_flags(s: str, i: uint, lim: uint) ->
|
||||
fn parse_flags(s: ~str, i: uint, lim: uint) ->
|
||||
{flags: ~[flag], next: uint} {
|
||||
let noflags: ~[flag] = ~[];
|
||||
if i >= lim { ret {flags: noflags, next: i}; }
|
||||
|
||||
fn more_(f: flag, s: str, i: uint, lim: uint) ->
|
||||
fn more_(f: flag, s: ~str, i: uint, lim: uint) ->
|
||||
{flags: ~[flag], next: uint} {
|
||||
let next = parse_flags(s, i + 1u, lim);
|
||||
let rest = next.flags;
|
||||
@ -188,7 +188,8 @@ mod ct {
|
||||
more(flag_alternate)
|
||||
} else { {flags: noflags, next: i} };
|
||||
}
|
||||
fn parse_count(s: str, i: uint, lim: uint) -> {count: count, next: uint} {
|
||||
fn parse_count(s: ~str, i: uint, lim: uint)
|
||||
-> {count: count, next: uint} {
|
||||
ret if i >= lim {
|
||||
{count: count_implied, next: i}
|
||||
} else if s[i] == '*' as u8 {
|
||||
@ -208,7 +209,7 @@ mod ct {
|
||||
}
|
||||
};
|
||||
}
|
||||
fn parse_precision(s: str, i: uint, lim: uint) ->
|
||||
fn parse_precision(s: ~str, i: uint, lim: uint) ->
|
||||
{count: count, next: uint} {
|
||||
ret if i >= lim {
|
||||
{count: count_implied, next: i}
|
||||
@ -224,36 +225,36 @@ mod ct {
|
||||
}
|
||||
} else { {count: count_implied, next: i} };
|
||||
}
|
||||
fn parse_type(s: str, i: uint, lim: uint, error: error_fn) ->
|
||||
fn parse_type(s: ~str, i: uint, lim: uint, error: error_fn) ->
|
||||
{ty: ty, next: uint} {
|
||||
if i >= lim { error("missing type in conversion"); }
|
||||
if i >= lim { error(~"missing type in conversion"); }
|
||||
let tstr = str::slice(s, i, i+1u);
|
||||
// FIXME (#2249): Do we really want two signed types here?
|
||||
// How important is it to be printf compatible?
|
||||
let t =
|
||||
if str::eq(tstr, "b") {
|
||||
if str::eq(tstr, ~"b") {
|
||||
ty_bool
|
||||
} else if str::eq(tstr, "s") {
|
||||
} else if str::eq(tstr, ~"s") {
|
||||
ty_str
|
||||
} else if str::eq(tstr, "c") {
|
||||
} else if str::eq(tstr, ~"c") {
|
||||
ty_char
|
||||
} else if str::eq(tstr, "d") || str::eq(tstr, "i") {
|
||||
} else if str::eq(tstr, ~"d") || str::eq(tstr, ~"i") {
|
||||
ty_int(signed)
|
||||
} else if str::eq(tstr, "u") {
|
||||
} else if str::eq(tstr, ~"u") {
|
||||
ty_int(unsigned)
|
||||
} else if str::eq(tstr, "x") {
|
||||
} else if str::eq(tstr, ~"x") {
|
||||
ty_hex(case_lower)
|
||||
} else if str::eq(tstr, "X") {
|
||||
} else if str::eq(tstr, ~"X") {
|
||||
ty_hex(case_upper)
|
||||
} else if str::eq(tstr, "t") {
|
||||
} else if str::eq(tstr, ~"t") {
|
||||
ty_bits
|
||||
} else if str::eq(tstr, "o") {
|
||||
} else if str::eq(tstr, ~"o") {
|
||||
ty_octal
|
||||
} else if str::eq(tstr, "f") {
|
||||
} else if str::eq(tstr, ~"f") {
|
||||
ty_float
|
||||
} else if str::eq(tstr, "?") {
|
||||
} else if str::eq(tstr, ~"?") {
|
||||
ty_poly
|
||||
} else { error("unknown type in conversion: " + tstr) };
|
||||
} else { error(~"unknown type in conversion: " + tstr) };
|
||||
ret {ty: t, next: i + 1u};
|
||||
}
|
||||
}
|
||||
@ -276,10 +277,10 @@ mod rt {
|
||||
|
||||
type conv = {flags: u32, width: count, precision: count, ty: ty};
|
||||
|
||||
fn conv_int(cv: conv, i: int) -> str {
|
||||
fn conv_int(cv: conv, i: int) -> ~str {
|
||||
let radix = 10u;
|
||||
let prec = get_int_precision(cv);
|
||||
let mut s : str = int_to_str_prec(i, radix, prec);
|
||||
let mut s : ~str = int_to_str_prec(i, radix, prec);
|
||||
if 0 <= i {
|
||||
if have_flag(cv.flags, flag_sign_always) {
|
||||
str::unshift_char(s, '+');
|
||||
@ -289,7 +290,7 @@ mod rt {
|
||||
}
|
||||
ret pad(cv, s, pad_signed);
|
||||
}
|
||||
fn conv_uint(cv: conv, u: uint) -> str {
|
||||
fn conv_uint(cv: conv, u: uint) -> ~str {
|
||||
let prec = get_int_precision(cv);
|
||||
let mut rs =
|
||||
alt cv.ty {
|
||||
@ -301,17 +302,17 @@ mod rt {
|
||||
};
|
||||
ret pad(cv, rs, pad_unsigned);
|
||||
}
|
||||
fn conv_bool(cv: conv, b: bool) -> str {
|
||||
let s = if b { "true" } else { "false" };
|
||||
fn conv_bool(cv: conv, b: bool) -> ~str {
|
||||
let s = if b { ~"true" } else { ~"false" };
|
||||
// run the boolean conversion through the string conversion logic,
|
||||
// giving it the same rules for precision, etc.
|
||||
ret conv_str(cv, s);
|
||||
}
|
||||
fn conv_char(cv: conv, c: char) -> str {
|
||||
fn conv_char(cv: conv, c: char) -> ~str {
|
||||
let mut s = str::from_char(c);
|
||||
ret pad(cv, s, pad_nozero);
|
||||
}
|
||||
fn conv_str(cv: conv, s: str) -> str {
|
||||
fn conv_str(cv: conv, s: ~str) -> ~str {
|
||||
// For strings, precision is the maximum characters
|
||||
// displayed
|
||||
let mut unpadded = alt cv.precision {
|
||||
@ -324,7 +325,7 @@ mod rt {
|
||||
};
|
||||
ret pad(cv, unpadded, pad_nozero);
|
||||
}
|
||||
fn conv_float(cv: conv, f: float) -> str {
|
||||
fn conv_float(cv: conv, f: float) -> ~str {
|
||||
let (to_str, digits) = alt cv.precision {
|
||||
count_is(c) { (float::to_str_exact, c as uint) }
|
||||
count_implied { (float::to_str, 6u) }
|
||||
@ -332,32 +333,32 @@ mod rt {
|
||||
let mut s = to_str(f, digits);
|
||||
if 0.0 <= f {
|
||||
if have_flag(cv.flags, flag_sign_always) {
|
||||
s = "+" + s;
|
||||
s = ~"+" + s;
|
||||
} else if have_flag(cv.flags, flag_space_for_sign) {
|
||||
s = " " + s;
|
||||
s = ~" " + s;
|
||||
}
|
||||
}
|
||||
ret pad(cv, s, pad_float);
|
||||
}
|
||||
fn conv_poly<T>(cv: conv, v: T) -> str {
|
||||
fn conv_poly<T>(cv: conv, v: T) -> ~str {
|
||||
let s = sys::log_str(v);
|
||||
ret conv_str(cv, s);
|
||||
}
|
||||
|
||||
// Convert an int to string with minimum number of digits. If precision is
|
||||
// 0 and num is 0 then the result is the empty string.
|
||||
fn int_to_str_prec(num: int, radix: uint, prec: uint) -> str {
|
||||
fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
|
||||
ret if num < 0 {
|
||||
"-" + uint_to_str_prec(-num as uint, radix, prec)
|
||||
~"-" + uint_to_str_prec(-num as uint, radix, prec)
|
||||
} else { uint_to_str_prec(num as uint, radix, prec) };
|
||||
}
|
||||
|
||||
// Convert a uint to string with a minimum number of digits. If precision
|
||||
// is 0 and num is 0 then the result is the empty string. Could move this
|
||||
// to uint: but it doesn't seem all that useful.
|
||||
fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> str {
|
||||
fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
|
||||
ret if prec == 0u && num == 0u {
|
||||
""
|
||||
~""
|
||||
} else {
|
||||
let s = uint::to_str(num, radix);
|
||||
let len = str::char_len(s);
|
||||
@ -375,7 +376,7 @@ mod rt {
|
||||
};
|
||||
}
|
||||
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 {
|
||||
count_implied { ret s; }
|
||||
count_is(width) {
|
||||
|
@ -102,12 +102,12 @@ mod consts {
|
||||
* * digits - The number of significant digits
|
||||
* * exact - Whether to enforce the exact number of significant digits
|
||||
*/
|
||||
fn to_str_common(num: float, digits: uint, exact: bool) -> str {
|
||||
if is_NaN(num) { ret "NaN"; }
|
||||
if num == infinity { ret "inf"; }
|
||||
if num == neg_infinity { ret "-inf"; }
|
||||
fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
|
||||
if is_NaN(num) { ret ~"NaN"; }
|
||||
if num == infinity { ret ~"inf"; }
|
||||
if num == neg_infinity { ret ~"-inf"; }
|
||||
|
||||
let mut (num, sign) = if num < 0.0 { (-num, "-") } else { (num, "") };
|
||||
let mut (num, sign) = if num < 0.0 { (-num, ~"-") } else { (num, ~"") };
|
||||
|
||||
// truncated integer
|
||||
let trunc = num as uint;
|
||||
@ -145,7 +145,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str {
|
||||
}
|
||||
|
||||
let mut acc;
|
||||
let mut racc = "";
|
||||
let mut racc = ~"";
|
||||
let mut carry = if frac * 10.0 as uint >= 5u { 1u } else { 0u };
|
||||
|
||||
// turn digits into string
|
||||
@ -165,15 +165,15 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str {
|
||||
|
||||
// pad decimals with trailing zeroes
|
||||
while str::len(racc) < digits && exact {
|
||||
racc += "0"
|
||||
racc += ~"0"
|
||||
}
|
||||
|
||||
// combine ints and decimals
|
||||
let mut ones = uint::str(trunc + carry);
|
||||
if racc == "" {
|
||||
if racc == ~"" {
|
||||
acc = sign + ones;
|
||||
} else {
|
||||
acc = sign + ones + "." + racc;
|
||||
acc = sign + ones + ~"." + racc;
|
||||
}
|
||||
|
||||
ret acc;
|
||||
@ -188,14 +188,14 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str {
|
||||
* * num - The float value
|
||||
* * digits - The number of significant digits
|
||||
*/
|
||||
fn to_str_exact(num: float, digits: uint) -> str {
|
||||
fn to_str_exact(num: float, digits: uint) -> ~str {
|
||||
to_str_common(num, digits, true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str_exact_do_decimal() {
|
||||
let s = to_str_exact(5.0, 4u);
|
||||
assert s == "5.0000";
|
||||
assert s == ~"5.0000";
|
||||
}
|
||||
|
||||
|
||||
@ -208,7 +208,7 @@ fn test_to_str_exact_do_decimal() {
|
||||
* * num - The float value
|
||||
* * digits - The number of significant digits
|
||||
*/
|
||||
fn to_str(num: float, digits: uint) -> str {
|
||||
fn to_str(num: float, digits: uint) -> ~str {
|
||||
to_str_common(num, digits, false)
|
||||
}
|
||||
|
||||
@ -238,12 +238,12 @@ fn to_str(num: float, digits: uint) -> str {
|
||||
* `none` if the string did not represent a valid number. Otherwise,
|
||||
* `some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||
*/
|
||||
fn from_str(num: str) -> option<float> {
|
||||
if num == "inf" {
|
||||
fn from_str(num: ~str) -> option<float> {
|
||||
if num == ~"inf" {
|
||||
ret some(infinity as float);
|
||||
} else if num == "-inf" {
|
||||
} else if num == ~"-inf" {
|
||||
ret some(neg_infinity as float);
|
||||
} else if num == "NaN" {
|
||||
} else if num == ~"NaN" {
|
||||
ret some(NaN as float);
|
||||
}
|
||||
|
||||
@ -433,45 +433,45 @@ impl num of num::num for float {
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
assert from_str("3") == some(3.);
|
||||
assert from_str("3") == some(3.);
|
||||
assert from_str("3.14") == some(3.14);
|
||||
assert from_str("+3.14") == some(3.14);
|
||||
assert from_str("-3.14") == some(-3.14);
|
||||
assert from_str("2.5E10") == some(25000000000.);
|
||||
assert from_str("2.5e10") == some(25000000000.);
|
||||
assert from_str("25000000000.E-10") == some(2.5);
|
||||
assert from_str(".") == some(0.);
|
||||
assert from_str(".e1") == some(0.);
|
||||
assert from_str(".e-1") == some(0.);
|
||||
assert from_str("5.") == some(5.);
|
||||
assert from_str(".5") == some(0.5);
|
||||
assert from_str("0.5") == some(0.5);
|
||||
assert from_str("0.5") == some(0.5);
|
||||
assert from_str("0.5") == some(0.5);
|
||||
assert from_str("-.5") == some(-0.5);
|
||||
assert from_str("-.5") == some(-0.5);
|
||||
assert from_str("-5") == some(-5.);
|
||||
assert from_str("-0") == some(-0.);
|
||||
assert from_str("0") == some(0.);
|
||||
assert from_str("inf") == some(infinity);
|
||||
assert from_str("-inf") == some(neg_infinity);
|
||||
assert from_str(~"3") == some(3.);
|
||||
assert from_str(~"3") == some(3.);
|
||||
assert from_str(~"3.14") == some(3.14);
|
||||
assert from_str(~"+3.14") == some(3.14);
|
||||
assert from_str(~"-3.14") == some(-3.14);
|
||||
assert from_str(~"2.5E10") == some(25000000000.);
|
||||
assert from_str(~"2.5e10") == some(25000000000.);
|
||||
assert from_str(~"25000000000.E-10") == some(2.5);
|
||||
assert from_str(~".") == some(0.);
|
||||
assert from_str(~".e1") == some(0.);
|
||||
assert from_str(~".e-1") == some(0.);
|
||||
assert from_str(~"5.") == some(5.);
|
||||
assert from_str(~".5") == some(0.5);
|
||||
assert from_str(~"0.5") == some(0.5);
|
||||
assert from_str(~"0.5") == some(0.5);
|
||||
assert from_str(~"0.5") == some(0.5);
|
||||
assert from_str(~"-.5") == some(-0.5);
|
||||
assert from_str(~"-.5") == some(-0.5);
|
||||
assert from_str(~"-5") == some(-5.);
|
||||
assert from_str(~"-0") == some(-0.);
|
||||
assert from_str(~"0") == some(0.);
|
||||
assert from_str(~"inf") == some(infinity);
|
||||
assert from_str(~"-inf") == some(neg_infinity);
|
||||
// note: NaN != NaN, hence this slightly complex test
|
||||
alt from_str("NaN") {
|
||||
alt from_str(~"NaN") {
|
||||
some(f) { assert is_NaN(f); }
|
||||
none { fail; }
|
||||
}
|
||||
|
||||
assert from_str("") == none;
|
||||
assert from_str("x") == none;
|
||||
assert from_str(" ") == none;
|
||||
assert from_str(" ") == none;
|
||||
assert from_str("e") == none;
|
||||
assert from_str("E") == none;
|
||||
assert from_str("E1") == none;
|
||||
assert from_str("1e1e1") == none;
|
||||
assert from_str("1e1.1") == none;
|
||||
assert from_str("1e1-1") == none;
|
||||
assert from_str(~"") == none;
|
||||
assert from_str(~"x") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~"e") == none;
|
||||
assert from_str(~"E") == none;
|
||||
assert from_str(~"E1") == none;
|
||||
assert from_str(~"1e1e1") == none;
|
||||
assert from_str(~"1e1.1") == none;
|
||||
assert from_str(~"1e1-1") == none;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -520,8 +520,8 @@ fn test_nonnegative() {
|
||||
|
||||
#[test]
|
||||
fn test_to_str_inf() {
|
||||
assert to_str(infinity, 10u) == "inf";
|
||||
assert to_str(-infinity, 10u) == "-inf";
|
||||
assert to_str(infinity, 10u) == ~"inf";
|
||||
assert to_str(-infinity, 10u) == ~"-inf";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -143,47 +143,47 @@ proto! future_pipe {
|
||||
|
||||
#[test]
|
||||
fn test_from_value() {
|
||||
let f = from_value("snail");
|
||||
assert get(f) == "snail";
|
||||
let f = from_value(~"snail");
|
||||
assert get(f) == ~"snail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_port() {
|
||||
let (po, ch) = future_pipe::init();
|
||||
future_pipe::server::completed(ch, "whale");
|
||||
future_pipe::server::completed(ch, ~"whale");
|
||||
let f = from_port(po);
|
||||
assert get(f) == "whale";
|
||||
assert get(f) == ~"whale";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_fn() {
|
||||
let f = fn@() -> str { "brail" };
|
||||
let f = fn@() -> ~str { ~"brail" };
|
||||
let f = from_fn(f);
|
||||
assert get(f) == "brail";
|
||||
assert get(f) == ~"brail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iface_get() {
|
||||
let f = from_value("fail");
|
||||
assert f.get() == "fail";
|
||||
let f = from_value(~"fail");
|
||||
assert f.get() == ~"fail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with() {
|
||||
let f = from_value("nail");
|
||||
assert with(f, |v| v) == "nail";
|
||||
let f = from_value(~"nail");
|
||||
assert with(f, |v| v) == ~"nail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iface_with() {
|
||||
let f = from_value("kale");
|
||||
assert f.with(|v| v) == "kale";
|
||||
let f = from_value(~"kale");
|
||||
assert f.with(|v| v) == ~"kale";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_spawn() {
|
||||
let f = spawn(|| "bale");
|
||||
assert get(f) == "bale";
|
||||
let f = spawn(|| ~"bale");
|
||||
assert get(f) == ~"bale";
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -191,5 +191,5 @@ fn test_spawn() {
|
||||
#[ignore(cfg(target_os = "win32"))]
|
||||
fn test_futurefail() {
|
||||
let f = spawn(|| fail);
|
||||
let _x: str = get(f);
|
||||
let _x: ~str = get(f);
|
||||
}
|
||||
|
@ -89,10 +89,10 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
|
||||
}
|
||||
|
||||
/// Parse a string to an int
|
||||
fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) }
|
||||
fn from_str(s: ~str) -> option<T> { parse_buf(str::bytes(s), 10u) }
|
||||
|
||||
/// Convert to a string in a given base
|
||||
fn to_str(n: T, radix: uint) -> str {
|
||||
fn to_str(n: T, radix: uint) -> ~str {
|
||||
do to_str_bytes(n, radix) |slice| {
|
||||
do vec::unpack_slice(slice) |p, len| {
|
||||
unsafe { str::unsafe::from_buf_len(p, len) }
|
||||
@ -109,7 +109,7 @@ fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
|
||||
}
|
||||
|
||||
/// Convert to a string
|
||||
fn str(i: T) -> str { ret to_str(i, 10u); }
|
||||
fn str(i: T) -> ~str { ret to_str(i, 10u); }
|
||||
|
||||
impl ord of ord for T {
|
||||
fn lt(&&other: T) -> bool {
|
||||
@ -159,20 +159,20 @@ impl times of iter::times for T {
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_from_str() {
|
||||
assert from_str("0") == some(0 as T);
|
||||
assert from_str("3") == some(3 as T);
|
||||
assert from_str("10") == some(10 as T);
|
||||
assert from_str("123456789") == some(123456789 as T);
|
||||
assert from_str("00100") == some(100 as T);
|
||||
assert from_str(~"0") == some(0 as T);
|
||||
assert from_str(~"3") == some(3 as T);
|
||||
assert from_str(~"10") == some(10 as T);
|
||||
assert from_str(~"123456789") == some(123456789 as T);
|
||||
assert from_str(~"00100") == some(100 as T);
|
||||
|
||||
assert from_str("-1") == some(-1 as T);
|
||||
assert from_str("-3") == some(-3 as T);
|
||||
assert from_str("-10") == some(-10 as T);
|
||||
assert from_str("-123456789") == some(-123456789 as T);
|
||||
assert from_str("-00100") == some(-100 as T);
|
||||
assert from_str(~"-1") == some(-1 as T);
|
||||
assert from_str(~"-3") == some(-3 as T);
|
||||
assert from_str(~"-10") == some(-10 as T);
|
||||
assert from_str(~"-123456789") == some(-123456789 as T);
|
||||
assert from_str(~"-00100") == some(-100 as T);
|
||||
|
||||
assert from_str(" ") == none;
|
||||
assert from_str("x") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~"x") == none;
|
||||
}
|
||||
|
||||
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
|
||||
@ -180,36 +180,36 @@ fn test_from_str() {
|
||||
#[ignore]
|
||||
fn test_parse_buf() {
|
||||
import str::bytes;
|
||||
assert parse_buf(bytes("123"), 10u) == some(123 as T);
|
||||
assert parse_buf(bytes("1001"), 2u) == some(9 as T);
|
||||
assert parse_buf(bytes("123"), 8u) == some(83 as T);
|
||||
assert parse_buf(bytes("123"), 16u) == some(291 as T);
|
||||
assert parse_buf(bytes("ffff"), 16u) == some(65535 as T);
|
||||
assert parse_buf(bytes("FFFF"), 16u) == some(65535 as T);
|
||||
assert parse_buf(bytes("z"), 36u) == some(35 as T);
|
||||
assert parse_buf(bytes("Z"), 36u) == some(35 as T);
|
||||
assert parse_buf(bytes(~"123"), 10u) == some(123 as T);
|
||||
assert parse_buf(bytes(~"1001"), 2u) == some(9 as T);
|
||||
assert parse_buf(bytes(~"123"), 8u) == some(83 as T);
|
||||
assert parse_buf(bytes(~"123"), 16u) == some(291 as T);
|
||||
assert parse_buf(bytes(~"ffff"), 16u) == some(65535 as T);
|
||||
assert parse_buf(bytes(~"FFFF"), 16u) == some(65535 as T);
|
||||
assert parse_buf(bytes(~"z"), 36u) == some(35 as T);
|
||||
assert parse_buf(bytes(~"Z"), 36u) == some(35 as T);
|
||||
|
||||
assert parse_buf(bytes("-123"), 10u) == some(-123 as T);
|
||||
assert parse_buf(bytes("-1001"), 2u) == some(-9 as T);
|
||||
assert parse_buf(bytes("-123"), 8u) == some(-83 as T);
|
||||
assert parse_buf(bytes("-123"), 16u) == some(-291 as T);
|
||||
assert parse_buf(bytes("-ffff"), 16u) == some(-65535 as T);
|
||||
assert parse_buf(bytes("-FFFF"), 16u) == some(-65535 as T);
|
||||
assert parse_buf(bytes("-z"), 36u) == some(-35 as T);
|
||||
assert parse_buf(bytes("-Z"), 36u) == some(-35 as T);
|
||||
assert parse_buf(bytes(~"-123"), 10u) == some(-123 as T);
|
||||
assert parse_buf(bytes(~"-1001"), 2u) == some(-9 as T);
|
||||
assert parse_buf(bytes(~"-123"), 8u) == some(-83 as T);
|
||||
assert parse_buf(bytes(~"-123"), 16u) == some(-291 as T);
|
||||
assert parse_buf(bytes(~"-ffff"), 16u) == some(-65535 as T);
|
||||
assert parse_buf(bytes(~"-FFFF"), 16u) == some(-65535 as T);
|
||||
assert parse_buf(bytes(~"-z"), 36u) == some(-35 as T);
|
||||
assert parse_buf(bytes(~"-Z"), 36u) == some(-35 as T);
|
||||
|
||||
assert parse_buf(str::bytes("Z"), 35u) == none;
|
||||
assert parse_buf(str::bytes("-9"), 2u) == none;
|
||||
assert parse_buf(str::bytes(~"Z"), 35u) == none;
|
||||
assert parse_buf(str::bytes(~"-9"), 2u) == none;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
import str::eq;
|
||||
assert (eq(to_str(0 as T, 10u), "0"));
|
||||
assert (eq(to_str(1 as T, 10u), "1"));
|
||||
assert (eq(to_str(-1 as T, 10u), "-1"));
|
||||
assert (eq(to_str(127 as T, 16u), "7f"));
|
||||
assert (eq(to_str(100 as T, 10u), "100"));
|
||||
assert (eq(to_str(0 as T, 10u), ~"0"));
|
||||
assert (eq(to_str(1 as T, 10u), ~"1"));
|
||||
assert (eq(to_str(-1 as T, 10u), ~"-1"));
|
||||
assert (eq(to_str(127 as T, 16u), ~"7f"));
|
||||
assert (eq(to_str(100 as T, 10u), ~"100"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -243,5 +243,5 @@ fn test_times() {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_times_negative() {
|
||||
for (-10).times { log(error, "nope!"); }
|
||||
for (-10).times { log(error, ~"nope!"); }
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl reader_util for reader {
|
||||
ret c[0];
|
||||
}
|
||||
|
||||
fn read_line() -> str {
|
||||
fn read_line() -> ~str {
|
||||
let mut buf = ~[];
|
||||
loop {
|
||||
let ch = self.read_byte();
|
||||
@ -119,7 +119,7 @@ impl reader_util for reader {
|
||||
str::from_bytes(buf)
|
||||
}
|
||||
|
||||
fn read_c_str() -> str {
|
||||
fn read_c_str() -> ~str {
|
||||
let mut buf: ~[u8] = ~[];
|
||||
loop {
|
||||
let ch = self.read_byte();
|
||||
@ -174,7 +174,7 @@ impl reader_util for reader {
|
||||
}
|
||||
}
|
||||
|
||||
fn each_line(it: fn(str) -> bool) {
|
||||
fn each_line(it: fn(~str) -> bool) {
|
||||
while !self.eof() {
|
||||
if !it(self.read_line()) { break; }
|
||||
}
|
||||
@ -244,13 +244,13 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
|
||||
|
||||
fn stdin() -> reader { rustrt::rust_get_stdin() as reader }
|
||||
|
||||
fn file_reader(path: str) -> result<reader, str> {
|
||||
fn file_reader(path: ~str) -> result<reader, ~str> {
|
||||
let f = os::as_c_charp(path, |pathbuf| {
|
||||
os::as_c_charp("r", |modebuf|
|
||||
os::as_c_charp(~"r", |modebuf|
|
||||
libc::fopen(pathbuf, modebuf)
|
||||
)
|
||||
});
|
||||
ret if f as uint == 0u { result::err("error opening " + path) }
|
||||
ret if f as uint == 0u { result::err(~"error opening " + path) }
|
||||
else {
|
||||
result::ok(FILE_reader(f, true))
|
||||
}
|
||||
@ -303,11 +303,11 @@ fn with_bytes_reader_between<t>(bytes: ~[u8], start: uint, end: uint,
|
||||
f(bytes_reader_between(bytes, start, end))
|
||||
}
|
||||
|
||||
fn str_reader(s: str) -> reader {
|
||||
fn str_reader(s: ~str) -> reader {
|
||||
bytes_reader(str::bytes(s))
|
||||
}
|
||||
|
||||
fn with_str_reader<T>(s: str, f: fn(reader) -> T) -> T {
|
||||
fn with_str_reader<T>(s: ~str, f: fn(reader) -> T) -> T {
|
||||
do str::as_bytes(s) |bytes| {
|
||||
with_bytes_reader_between(bytes, 0u, str::len(s), f)
|
||||
}
|
||||
@ -402,8 +402,8 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
|
||||
}
|
||||
|
||||
|
||||
fn mk_file_writer(path: str, flags: ~[fileflag])
|
||||
-> result<writer, str> {
|
||||
fn mk_file_writer(path: ~str, flags: ~[fileflag])
|
||||
-> result<writer, ~str> {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
|
||||
@ -514,10 +514,10 @@ impl writer_util for writer {
|
||||
self.write_str(str::from_char(ch));
|
||||
}
|
||||
}
|
||||
fn write_str(s: str/&) { str::byte_slice(s, |v| self.write(v)) }
|
||||
fn write_line(s: str/&) {
|
||||
fn write_str(s: &str) { str::byte_slice(s, |v| self.write(v)) }
|
||||
fn write_line(s: &str) {
|
||||
self.write_str(s);
|
||||
self.write_str("\n"/&);
|
||||
self.write_str(&"\n");
|
||||
}
|
||||
fn write_int(n: int) {
|
||||
int::to_str_bytes(n, 10u, |buf| self.write(buf))
|
||||
@ -577,19 +577,19 @@ impl writer_util for writer {
|
||||
fn write_u8(n: u8) { self.write(&[n]) }
|
||||
}
|
||||
|
||||
fn file_writer(path: str, flags: ~[fileflag]) -> result<writer, str> {
|
||||
fn file_writer(path: ~str, flags: ~[fileflag]) -> result<writer, ~str> {
|
||||
result::chain(mk_file_writer(path, flags), |w| result::ok(w))
|
||||
}
|
||||
|
||||
|
||||
// FIXME: fileflags // #2004
|
||||
fn buffered_file_writer(path: str) -> result<writer, str> {
|
||||
fn buffered_file_writer(path: ~str) -> result<writer, ~str> {
|
||||
let f = do os::as_c_charp(path) |pathbuf| {
|
||||
do os::as_c_charp("w") |modebuf| {
|
||||
do os::as_c_charp(~"w") |modebuf| {
|
||||
libc::fopen(pathbuf, modebuf)
|
||||
}
|
||||
};
|
||||
ret if f as uint == 0u { result::err("error opening " + path) }
|
||||
ret if f as uint == 0u { result::err(~"error opening " + path) }
|
||||
else { result::ok(FILE_writer(f, true)) }
|
||||
}
|
||||
|
||||
@ -599,8 +599,8 @@ fn buffered_file_writer(path: str) -> result<writer, str> {
|
||||
fn stdout() -> writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
|
||||
fn stderr() -> writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
|
||||
|
||||
fn print(s: str) { stdout().write_str(s); }
|
||||
fn println(s: str) { stdout().write_line(s); }
|
||||
fn print(s: ~str) { stdout().write_str(s); }
|
||||
fn println(s: ~str) { stdout().write_line(s); }
|
||||
|
||||
type mem_buffer = @{buf: dvec<u8>, mut pos: uint};
|
||||
|
||||
@ -639,11 +639,11 @@ fn mem_buffer() -> mem_buffer {
|
||||
}
|
||||
fn mem_buffer_writer(b: mem_buffer) -> writer { b as writer }
|
||||
fn mem_buffer_buf(b: mem_buffer) -> ~[u8] { b.buf.get() }
|
||||
fn mem_buffer_str(b: mem_buffer) -> str {
|
||||
fn mem_buffer_str(b: mem_buffer) -> ~str {
|
||||
str::from_bytes(b.buf.get())
|
||||
}
|
||||
|
||||
fn with_str_writer(f: fn(writer)) -> str {
|
||||
fn with_str_writer(f: fn(writer)) -> ~str {
|
||||
let buf = mem_buffer();
|
||||
let wr = mem_buffer_writer(buf);
|
||||
f(wr);
|
||||
@ -671,7 +671,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
|
||||
ret bpos as uint;
|
||||
}
|
||||
|
||||
fn read_whole_file_str(file: str) -> result<str, str> {
|
||||
fn read_whole_file_str(file: ~str) -> result<~str, ~str> {
|
||||
result::chain(read_whole_file(file), |bytes| {
|
||||
result::ok(str::from_bytes(bytes))
|
||||
})
|
||||
@ -679,7 +679,7 @@ fn read_whole_file_str(file: str) -> result<str, str> {
|
||||
|
||||
// FIXME (#2004): implement this in a low-level way. Going through the
|
||||
// abstractions is pointless.
|
||||
fn read_whole_file(file: str) -> result<~[u8], str> {
|
||||
fn read_whole_file(file: ~str) -> result<~[u8], ~str> {
|
||||
result::chain(file_reader(file), |rdr| {
|
||||
result::ok(rdr.read_whole_stream())
|
||||
})
|
||||
@ -765,9 +765,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
let tmpfile: str = "tmp/lib-io-test-simple.tmp";
|
||||
let tmpfile: ~str = ~"tmp/lib-io-test-simple.tmp";
|
||||
log(debug, tmpfile);
|
||||
let frood: str = "A hoopy frood who really knows where his towel is.";
|
||||
let frood: ~str =
|
||||
~"A hoopy frood who really knows where his towel is.";
|
||||
log(debug, frood);
|
||||
{
|
||||
let out: io::writer =
|
||||
@ -776,28 +777,28 @@ mod tests {
|
||||
out.write_str(frood);
|
||||
}
|
||||
let inp: io::reader = result::get(io::file_reader(tmpfile));
|
||||
let frood2: str = inp.read_c_str();
|
||||
let frood2: ~str = inp.read_c_str();
|
||||
log(debug, frood2);
|
||||
assert (str::eq(frood, frood2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_readchars_empty() {
|
||||
let inp : io::reader = io::str_reader("");
|
||||
let inp : io::reader = io::str_reader(~"");
|
||||
let res : ~[char] = inp.read_chars(128u);
|
||||
assert(vec::len(res) == 0u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_readchars_wide() {
|
||||
let wide_test = "生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
|
||||
let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
|
||||
let ivals : ~[int] = ~[
|
||||
29983, 38152, 30340, 27748,
|
||||
21273, 20999, 32905, 27748,
|
||||
104, 101, 108, 108, 111,
|
||||
29983, 38152, 30340, 27748,
|
||||
21273, 20999, 32905, 27748];
|
||||
fn check_read_ln(len : uint, s: str, ivals: ~[int]) {
|
||||
fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) {
|
||||
let inp : io::reader = io::str_reader(s);
|
||||
let res : ~[char] = inp.read_chars(len);
|
||||
if (len <= vec::len(ivals)) {
|
||||
@ -817,23 +818,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_readchar() {
|
||||
let inp : io::reader = io::str_reader("生");
|
||||
let inp : io::reader = io::str_reader(~"生");
|
||||
let res : char = inp.read_char();
|
||||
assert(res as int == 29983);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_readchar_empty() {
|
||||
let inp : io::reader = io::str_reader("");
|
||||
let inp : io::reader = io::str_reader(~"");
|
||||
let res : char = inp.read_char();
|
||||
assert(res as int == -1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_reader_not_exist() {
|
||||
alt io::file_reader("not a file") {
|
||||
alt io::file_reader(~"not a file") {
|
||||
result::err(e) {
|
||||
assert e == "error opening not a file";
|
||||
assert e == ~"error opening not a file";
|
||||
}
|
||||
result::ok(_) { fail; }
|
||||
}
|
||||
@ -841,9 +842,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn file_writer_bad_name() {
|
||||
alt io::file_writer("?/?", ~[]) {
|
||||
alt io::file_writer(~"?/?", ~[]) {
|
||||
result::err(e) {
|
||||
assert str::starts_with(e, "error opening ?/?");
|
||||
assert str::starts_with(e, ~"error opening ?/?");
|
||||
}
|
||||
result::ok(_) { fail; }
|
||||
}
|
||||
@ -851,9 +852,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn buffered_file_writer_bad_name() {
|
||||
alt io::buffered_file_writer("?/?") {
|
||||
alt io::buffered_file_writer(~"?/?") {
|
||||
result::err(e) {
|
||||
assert e == "error opening ?/?";
|
||||
assert e == ~"error opening ?/?";
|
||||
}
|
||||
result::ok(_) { fail; }
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
|
||||
// Check dlist invariant.
|
||||
if !option::is_some(nobe.root) ||
|
||||
!box::ptr_eq(*option::get(nobe.root), *self) {
|
||||
fail "Iteration encountered a dlist node not on this dlist."
|
||||
fail ~"Iteration encountered a dlist node not on this dlist."
|
||||
}
|
||||
f(nobe.data);
|
||||
// Check that the user didn't do a remove.
|
||||
@ -24,7 +24,7 @@ fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
|
||||
// immediately put it back in a different position. I allow this.
|
||||
if !option::is_some(nobe.root) ||
|
||||
!box::ptr_eq(*option::get(nobe.root), *self) {
|
||||
fail "Removing a dlist node during iteration is forbidden!"
|
||||
fail ~"Removing a dlist node during iteration is forbidden!"
|
||||
}
|
||||
link = nobe.next_link();
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
|
||||
}
|
||||
} {
|
||||
some(val) { val }
|
||||
none { fail "min called on empty iterator" }
|
||||
none { fail ~"min called on empty iterator" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ fn max<A:copy,IA:base_iter<A>>(self: IA) -> A {
|
||||
}
|
||||
} {
|
||||
some(val) { val }
|
||||
none { fail "max called on empty iterator" }
|
||||
none { fail ~"max called on empty iterator" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,10 @@ pure fn get<T: copy>(opt: option<T>) -> T {
|
||||
* Fails if the value equals `none`
|
||||
*/
|
||||
|
||||
alt opt { some(x) { ret x; } none { fail "option none"; } }
|
||||
alt opt { some(x) { ret x; } none { fail ~"option none"; } }
|
||||
}
|
||||
|
||||
pure fn expect<T: copy>(opt: option<T>, reason: str) -> T {
|
||||
pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
|
||||
#[doc = "
|
||||
Gets the value out of an option, printing a specified message on failure
|
||||
|
||||
@ -93,7 +93,7 @@ pure fn unwrap<T>(-opt: option<T>) -> T {
|
||||
unsafe {
|
||||
let addr = alt opt {
|
||||
some(x) { ptr::addr_of(x) }
|
||||
none { fail "option none" }
|
||||
none { fail ~"option none" }
|
||||
};
|
||||
let liberated_value = unsafe::reinterpret_cast(*addr);
|
||||
unsafe::forget(opt);
|
||||
@ -138,7 +138,7 @@ impl extensions<T: copy> for option<T> {
|
||||
*
|
||||
* Fails if the value equals `none`
|
||||
*/
|
||||
pure fn expect(reason: str) -> T { expect(self, reason) }
|
||||
pure fn expect(reason: ~str) -> T { expect(self, reason) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -153,7 +153,7 @@ fn test_unwrap_ptr() {
|
||||
|
||||
#[test]
|
||||
fn test_unwrap_str() {
|
||||
let x = "test";
|
||||
let x = ~"test";
|
||||
let addr_x = str::as_buf(x, |buf| ptr::addr_of(buf));
|
||||
let opt = some(x);
|
||||
let y = unwrap(opt);
|
||||
|
@ -40,18 +40,18 @@ export walk_dir;
|
||||
export as_c_charp, fill_charp_buf;
|
||||
|
||||
extern mod rustrt {
|
||||
fn rust_env_pairs() -> ~[str];
|
||||
fn rust_getcwd() -> str;
|
||||
fn rust_env_pairs() -> ~[~str];
|
||||
fn rust_getcwd() -> ~str;
|
||||
fn rust_path_is_dir(path: *libc::c_char) -> c_int;
|
||||
fn rust_path_exists(path: *libc::c_char) -> c_int;
|
||||
fn rust_list_files(path: str) -> ~[str];
|
||||
fn rust_list_files(path: ~str) -> ~[~str];
|
||||
fn rust_process_wait(handle: c_int) -> c_int;
|
||||
fn last_os_error() -> str;
|
||||
fn last_os_error() -> ~str;
|
||||
fn rust_set_exit_status(code: libc::intptr_t);
|
||||
}
|
||||
|
||||
|
||||
fn env() -> ~[(str,str)] {
|
||||
fn env() -> ~[(~str,~str)] {
|
||||
let mut pairs = ~[];
|
||||
for vec::each(rustrt::rust_env_pairs()) |p| {
|
||||
let vs = str::splitn_char(p, '=', 1u);
|
||||
@ -63,12 +63,12 @@ fn env() -> ~[(str,str)] {
|
||||
|
||||
const tmpbuf_sz : uint = 1000u;
|
||||
|
||||
fn as_c_charp<T>(s: str, f: fn(*c_char) -> T) -> T {
|
||||
fn as_c_charp<T>(s: ~str, f: fn(*c_char) -> T) -> T {
|
||||
str::as_c_str(s, |b| f(b as *c_char))
|
||||
}
|
||||
|
||||
fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
|
||||
-> option<str> {
|
||||
-> option<~str> {
|
||||
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
|
||||
do vec::as_mut_buf(buf) |b| {
|
||||
if f(b, tmpbuf_sz as size_t) unsafe {
|
||||
@ -121,11 +121,11 @@ mod win32 {
|
||||
}
|
||||
}
|
||||
|
||||
fn getenv(n: str) -> option<str> {
|
||||
fn getenv(n: ~str) -> option<~str> {
|
||||
global_env::getenv(n)
|
||||
}
|
||||
|
||||
fn setenv(n: str, v: str) {
|
||||
fn setenv(n: ~str, v: ~str) {
|
||||
global_env::setenv(n, v)
|
||||
}
|
||||
|
||||
@ -140,18 +140,18 @@ mod global_env {
|
||||
}
|
||||
|
||||
enum msg {
|
||||
msg_getenv(str, comm::chan<option<str>>),
|
||||
msg_setenv(str, str, comm::chan<()>)
|
||||
msg_getenv(~str, comm::chan<option<~str>>),
|
||||
msg_setenv(~str, ~str, comm::chan<()>)
|
||||
}
|
||||
|
||||
fn getenv(n: str) -> option<str> {
|
||||
fn getenv(n: ~str) -> option<~str> {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
comm::send(env_ch, msg_getenv(n, comm::chan(po)));
|
||||
comm::recv(po)
|
||||
}
|
||||
|
||||
fn setenv(n: str, v: str) {
|
||||
fn setenv(n: ~str, v: ~str) {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
comm::send(env_ch, msg_setenv(n, v, comm::chan(po)));
|
||||
@ -199,14 +199,14 @@ mod global_env {
|
||||
mod impl {
|
||||
|
||||
#[cfg(unix)]
|
||||
fn getenv(n: str) -> option<str> {
|
||||
fn getenv(n: ~str) -> option<~str> {
|
||||
unsafe {
|
||||
let s = str::as_c_str(n, libc::getenv);
|
||||
ret if unsafe::reinterpret_cast(s) == 0 {
|
||||
option::none::<str>
|
||||
option::none::<~str>
|
||||
} else {
|
||||
let s = unsafe::reinterpret_cast(s);
|
||||
option::some::<str>(str::unsafe::from_buf(s))
|
||||
option::some::<~str>(str::unsafe::from_buf(s))
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,7 @@ mod global_env {
|
||||
|
||||
|
||||
#[cfg(unix)]
|
||||
fn setenv(n: str, v: str) {
|
||||
fn setenv(n: ~str, v: ~str) {
|
||||
|
||||
// FIXME: remove this when export globs work properly. #1238
|
||||
import libc::funcs::posix01::unistd::setenv;
|
||||
@ -253,7 +253,7 @@ mod global_env {
|
||||
}
|
||||
|
||||
fn fdopen(fd: c_int) -> *FILE {
|
||||
ret do as_c_charp("r") |modebuf| {
|
||||
ret do as_c_charp(~"r") |modebuf| {
|
||||
libc::fdopen(fd, modebuf)
|
||||
};
|
||||
}
|
||||
@ -348,11 +348,11 @@ fn pipe() -> {in: c_int, out: c_int} {
|
||||
}
|
||||
|
||||
|
||||
fn dll_filename(base: str) -> str {
|
||||
fn dll_filename(base: ~str) -> ~str {
|
||||
ret pre() + base + dll_suffix();
|
||||
|
||||
#[cfg(unix)]
|
||||
fn pre() -> str { "lib" }
|
||||
fn pre() -> ~str { ~"lib" }
|
||||
|
||||
#[cfg(windows)]
|
||||
fn pre() -> str { "" }
|
||||
@ -381,7 +381,7 @@ fn self_exe_path() -> option<path> {
|
||||
fn load_self() -> option<path> {
|
||||
import libc::funcs::posix01::unistd::readlink;
|
||||
do fill_charp_buf() |buf, sz| {
|
||||
do as_c_charp("/proc/self/exe") |proc_self_buf| {
|
||||
do as_c_charp(~"/proc/self/exe") |proc_self_buf| {
|
||||
readlink(proc_self_buf, buf, sz) != (-1 as ssize_t)
|
||||
}
|
||||
}
|
||||
@ -428,7 +428,7 @@ fn self_exe_path() -> option<path> {
|
||||
* Otherwise, homedir returns option::none.
|
||||
*/
|
||||
fn homedir() -> option<path> {
|
||||
ret alt getenv("HOME") {
|
||||
ret alt getenv(~"HOME") {
|
||||
some(p) {
|
||||
if !str::is_empty(p) {
|
||||
some(p)
|
||||
@ -548,10 +548,10 @@ fn make_dir(p: path, mode: c_int) -> bool {
|
||||
}
|
||||
|
||||
/// Lists the contents of a directory
|
||||
fn list_dir(p: path) -> ~[str] {
|
||||
fn list_dir(p: path) -> ~[~str] {
|
||||
|
||||
#[cfg(unix)]
|
||||
fn star(p: str) -> str { p }
|
||||
fn star(p: ~str) -> ~str { p }
|
||||
|
||||
#[cfg(windows)]
|
||||
fn star(p: str) -> str {
|
||||
@ -565,7 +565,7 @@ fn list_dir(p: path) -> ~[str] {
|
||||
}
|
||||
|
||||
do rustrt::rust_list_files(star(p)).filter |filename| {
|
||||
!str::eq(filename, ".") && !str::eq(filename, "..")
|
||||
!str::eq(filename, ~".") && !str::eq(filename, ~"..")
|
||||
}
|
||||
}
|
||||
|
||||
@ -574,7 +574,7 @@ fn list_dir(p: path) -> ~[str] {
|
||||
*
|
||||
* This version prepends each entry with the directory.
|
||||
*/
|
||||
fn list_dir_path(p: path) -> ~[str] {
|
||||
fn list_dir_path(p: path) -> ~[~str] {
|
||||
let mut p = p;
|
||||
let pl = str::len(p);
|
||||
if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
|
||||
@ -649,7 +649,7 @@ fn copy_file(from: path, to: path) -> bool {
|
||||
#[cfg(unix)]
|
||||
fn do_copy_file(from: path, to: path) -> bool {
|
||||
let istream = do as_c_charp(from) |fromp| {
|
||||
do as_c_charp("rb") |modebuf| {
|
||||
do as_c_charp(~"rb") |modebuf| {
|
||||
libc::fopen(fromp, modebuf)
|
||||
}
|
||||
};
|
||||
@ -657,7 +657,7 @@ fn copy_file(from: path, to: path) -> bool {
|
||||
ret false;
|
||||
}
|
||||
let ostream = do as_c_charp(to) |top| {
|
||||
do as_c_charp("w+b") |modebuf| {
|
||||
do as_c_charp(~"w+b") |modebuf| {
|
||||
libc::fopen(top, modebuf)
|
||||
}
|
||||
};
|
||||
@ -717,7 +717,7 @@ fn remove_file(p: path) -> bool {
|
||||
}
|
||||
|
||||
/// Get a string representing the platform-dependent last error
|
||||
fn last_os_error() -> str {
|
||||
fn last_os_error() -> ~str {
|
||||
rustrt::last_os_error()
|
||||
}
|
||||
|
||||
@ -734,7 +734,7 @@ fn set_exit_status(code: int) {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn family() -> str { "unix" }
|
||||
fn family() -> ~str { ~"unix" }
|
||||
|
||||
#[cfg(windows)]
|
||||
fn family() -> str { "windows" }
|
||||
@ -755,9 +755,9 @@ mod consts {
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod consts {
|
||||
fn sysname() -> str { "linux" }
|
||||
fn exe_suffix() -> str { "" }
|
||||
fn dll_suffix() -> str { ".so" }
|
||||
fn sysname() -> ~str { ~"linux" }
|
||||
fn exe_suffix() -> ~str { ~"" }
|
||||
fn dll_suffix() -> ~str { ~".so" }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
@ -771,7 +771,7 @@ mod consts {
|
||||
fn arch() -> str { "x86" }
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn arch() -> str { "x86_64" }
|
||||
fn arch() -> ~str { ~"x86_64" }
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
fn arch() -> str { "arm" }
|
||||
@ -784,10 +784,10 @@ mod tests {
|
||||
log(debug, last_os_error());
|
||||
}
|
||||
|
||||
fn make_rand_name() -> str {
|
||||
fn make_rand_name() -> ~str {
|
||||
import rand;
|
||||
let rng: rand::rng = rand::rng();
|
||||
let n = "TEST" + rng.gen_str(10u);
|
||||
let n = ~"TEST" + rng.gen_str(10u);
|
||||
assert option::is_none(getenv(n));
|
||||
n
|
||||
}
|
||||
@ -795,8 +795,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_setenv() {
|
||||
let n = make_rand_name();
|
||||
setenv(n, "VALUE");
|
||||
assert getenv(n) == option::some("VALUE");
|
||||
setenv(n, ~"VALUE");
|
||||
assert getenv(n) == option::some(~"VALUE");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -804,11 +804,11 @@ mod tests {
|
||||
#[ignore]
|
||||
fn test_setenv_overwrite() {
|
||||
let n = make_rand_name();
|
||||
setenv(n, "1");
|
||||
setenv(n, "2");
|
||||
assert getenv(n) == option::some("2");
|
||||
setenv(n, "");
|
||||
assert getenv(n) == option::some("");
|
||||
setenv(n, ~"1");
|
||||
setenv(n, ~"2");
|
||||
assert getenv(n) == option::some(~"2");
|
||||
setenv(n, ~"");
|
||||
assert getenv(n) == option::some(~"");
|
||||
}
|
||||
|
||||
// Windows GetEnvironmentVariable requires some extra work to make sure
|
||||
@ -817,9 +817,9 @@ mod tests {
|
||||
#[ignore(cfg(windows))]
|
||||
#[ignore]
|
||||
fn test_getenv_big() {
|
||||
let mut s = "";
|
||||
let mut s = ~"";
|
||||
let mut i = 0;
|
||||
while i < 100 { s += "aaaaaaaaaa"; i += 1; }
|
||||
while i < 100 { s += ~"aaaaaaaaaa"; i += 1; }
|
||||
let n = make_rand_name();
|
||||
setenv(n, s);
|
||||
log(debug, s);
|
||||
@ -834,7 +834,7 @@ mod tests {
|
||||
log(debug, path);
|
||||
|
||||
// Hard to test this function
|
||||
if os::sysname() != "win32" {
|
||||
if os::sysname() != ~"win32" {
|
||||
assert str::starts_with(path, path::path_sep());
|
||||
} else {
|
||||
assert path[1] == ':' as u8;
|
||||
@ -862,35 +862,35 @@ mod tests {
|
||||
let n = make_rand_name();
|
||||
|
||||
let mut e = env();
|
||||
setenv(n, "VALUE");
|
||||
assert !vec::contains(e, (n, "VALUE"));
|
||||
setenv(n, ~"VALUE");
|
||||
assert !vec::contains(e, (n, ~"VALUE"));
|
||||
|
||||
e = env();
|
||||
assert vec::contains(e, (n, "VALUE"));
|
||||
assert vec::contains(e, (n, ~"VALUE"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert (!path::path_is_absolute("test-path"));
|
||||
assert (!path::path_is_absolute(~"test-path"));
|
||||
|
||||
log(debug, "Current working directory: " + getcwd());
|
||||
log(debug, ~"Current working directory: " + getcwd());
|
||||
|
||||
log(debug, make_absolute("test-path"));
|
||||
log(debug, make_absolute("/usr/bin"));
|
||||
log(debug, make_absolute(~"test-path"));
|
||||
log(debug, make_absolute(~"/usr/bin"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn homedir() {
|
||||
let oldhome = getenv("HOME");
|
||||
let oldhome = getenv(~"HOME");
|
||||
|
||||
setenv("HOME", "/home/MountainView");
|
||||
assert os::homedir() == some("/home/MountainView");
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
assert os::homedir() == some(~"/home/MountainView");
|
||||
|
||||
setenv("HOME", "");
|
||||
setenv(~"HOME", ~"");
|
||||
assert os::homedir() == none;
|
||||
|
||||
option::iter(oldhome, |s| setenv("HOME", s));
|
||||
option::iter(oldhome, |s| setenv(~"HOME", s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -927,11 +927,11 @@ mod tests {
|
||||
|
||||
// Issue #712
|
||||
#[test]
|
||||
fn test_list_dir_no_invalid_memory_access() { os::list_dir("."); }
|
||||
fn test_list_dir_no_invalid_memory_access() { os::list_dir(~"."); }
|
||||
|
||||
#[test]
|
||||
fn list_dir() {
|
||||
let dirs = os::list_dir(".");
|
||||
let dirs = os::list_dir(~".");
|
||||
// Just assuming that we've got some contents in the current directory
|
||||
assert (vec::len(dirs) > 0u);
|
||||
|
||||
@ -940,21 +940,21 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn path_is_dir() {
|
||||
assert (os::path_is_dir("."));
|
||||
assert (!os::path_is_dir("test/stdtest/fs.rs"));
|
||||
assert (os::path_is_dir(~"."));
|
||||
assert (!os::path_is_dir(~"test/stdtest/fs.rs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_exists() {
|
||||
assert (os::path_exists("."));
|
||||
assert (!os::path_exists("test/nonexistent-bogus-path"));
|
||||
assert (os::path_exists(~"."));
|
||||
assert (!os::path_exists(~"test/nonexistent-bogus-path"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_file_does_not_exist() {
|
||||
assert !os::copy_file("test/nonexistent-bogus-path",
|
||||
"test/other-bogus-path");
|
||||
assert !os::path_exists("test/other-bogus-path");
|
||||
assert !os::copy_file(~"test/nonexistent-bogus-path",
|
||||
~"test/other-bogus-path");
|
||||
assert !os::path_exists(~"test/other-bogus-path");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -962,17 +962,17 @@ mod tests {
|
||||
let tempdir = getcwd(); // would like to use $TMPDIR,
|
||||
// doesn't seem to work on Linux
|
||||
assert (str::len(tempdir) > 0u);
|
||||
let in = tempdir + path::path_sep() + "in.txt";
|
||||
let out = tempdir + path::path_sep() + "out.txt";
|
||||
let in = tempdir + path::path_sep() + ~"in.txt";
|
||||
let out = tempdir + path::path_sep() + ~"out.txt";
|
||||
|
||||
/* Write the temp input file */
|
||||
let ostream = do as_c_charp(in) |fromp| {
|
||||
do as_c_charp("w+b") |modebuf| {
|
||||
do as_c_charp(~"w+b") |modebuf| {
|
||||
libc::fopen(fromp, modebuf)
|
||||
}
|
||||
};
|
||||
assert (ostream as uint != 0u);
|
||||
let s = "hello";
|
||||
let s = ~"hello";
|
||||
let mut buf = vec::to_mut(str::bytes(s) + ~[0 as u8]);
|
||||
do vec::as_mut_buf(buf) |b| {
|
||||
assert (libc::fwrite(b as *c_void, 1u as size_t,
|
||||
@ -984,7 +984,7 @@ mod tests {
|
||||
fail (#fmt("%s doesn't exist", in));
|
||||
}
|
||||
assert(rs);
|
||||
let rslt = run::run_program("diff", ~[in, out]);
|
||||
let rslt = run::run_program(~"diff", ~[in, out]);
|
||||
assert (rslt == 0);
|
||||
assert (remove_file(in));
|
||||
assert (remove_file(out));
|
||||
|
@ -14,7 +14,7 @@ export normalize;
|
||||
|
||||
// FIXME: This type should probably be constrained (#2624)
|
||||
/// A path or fragment of a filesystem path
|
||||
type path = str;
|
||||
type path = ~str;
|
||||
|
||||
#[cfg(unix)]
|
||||
mod consts {
|
||||
@ -58,9 +58,9 @@ fn path_is_absolute(p: str) -> bool {
|
||||
}
|
||||
|
||||
/// Get the default path separator for the host platform
|
||||
fn path_sep() -> str { ret str::from_char(consts::path_sep); }
|
||||
fn path_sep() -> ~str { ret 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|
|
||||
ch == consts::path_sep || ch == consts::alt_path_sep
|
||||
) {
|
||||
@ -68,7 +68,7 @@ fn split_dirname_basename (pp: path) -> {dirname: str, basename: str} {
|
||||
{dirname: str::slice(pp, 0u, i),
|
||||
basename: str::slice(pp, i + 1u, str::len(pp))}
|
||||
}
|
||||
none { {dirname: ".", basename: pp} }
|
||||
none { {dirname: ~".", basename: pp} }
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,16 +159,16 @@ fn split(p: path) -> ~[path] {
|
||||
* ignored. If the path includes directory components then they are included
|
||||
* in the filename part of the result pair.
|
||||
*/
|
||||
fn splitext(p: path) -> (str, str) {
|
||||
if str::is_empty(p) { ("", "") }
|
||||
fn splitext(p: path) -> (~str, ~str) {
|
||||
if str::is_empty(p) { (~"", ~"") }
|
||||
else {
|
||||
let parts = str::split_char(p, '.');
|
||||
if vec::len(parts) > 1u {
|
||||
let base = str::connect(vec::init(parts), ".");
|
||||
let base = str::connect(vec::init(parts), ~".");
|
||||
// We just checked that parts is non-empty, so this is safe
|
||||
let ext = "." + vec::last(parts);
|
||||
let ext = ~"." + vec::last(parts);
|
||||
|
||||
fn is_dotfile(base: str) -> bool {
|
||||
fn is_dotfile(base: ~str) -> bool {
|
||||
str::is_empty(base)
|
||||
|| str::ends_with(
|
||||
base, str::from_char(consts::path_sep))
|
||||
@ -176,11 +176,11 @@ fn splitext(p: path) -> (str, str) {
|
||||
base, str::from_char(consts::alt_path_sep))
|
||||
}
|
||||
|
||||
fn ext_contains_sep(ext: str) -> bool {
|
||||
fn ext_contains_sep(ext: ~str) -> bool {
|
||||
vec::len(split(ext)) > 1u
|
||||
}
|
||||
|
||||
fn no_basename(ext: str) -> bool {
|
||||
fn no_basename(ext: ~str) -> bool {
|
||||
str::ends_with(
|
||||
ext, str::from_char(consts::path_sep))
|
||||
|| str::ends_with(
|
||||
@ -190,12 +190,12 @@ fn splitext(p: path) -> (str, str) {
|
||||
if is_dotfile(base)
|
||||
|| ext_contains_sep(ext)
|
||||
|| no_basename(ext) {
|
||||
(p, "")
|
||||
(p, ~"")
|
||||
} else {
|
||||
(base, ext)
|
||||
}
|
||||
} else {
|
||||
(p, "")
|
||||
(p, ~"")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,13 +220,13 @@ fn normalize(p: path) -> path {
|
||||
let s = if check vec::is_not_empty(s) {
|
||||
connect_many(s)
|
||||
} else {
|
||||
""
|
||||
~""
|
||||
};
|
||||
let s = reabsolute(p, s);
|
||||
let s = reterminate(p, s);
|
||||
|
||||
let s = if str::len(s) == 0u {
|
||||
"."
|
||||
~"."
|
||||
} else {
|
||||
s
|
||||
};
|
||||
@ -235,7 +235,7 @@ fn normalize(p: path) -> path {
|
||||
|
||||
fn strip_dots(s: ~[path]) -> ~[path] {
|
||||
vec::filter_map(s, |elem|
|
||||
if elem == "." {
|
||||
if elem == ~"." {
|
||||
option::none
|
||||
} else {
|
||||
option::some(elem)
|
||||
@ -252,7 +252,7 @@ fn normalize(p: path) -> path {
|
||||
let mut skip = 0;
|
||||
while i != 0u {
|
||||
i -= 1u;
|
||||
if s[i] == ".." {
|
||||
if s[i] == ~".." {
|
||||
skip += 1;
|
||||
} else {
|
||||
if skip == 0 {
|
||||
@ -264,7 +264,7 @@ fn normalize(p: path) -> path {
|
||||
}
|
||||
let mut t = vec::reversed(t);
|
||||
while skip > 0 {
|
||||
vec::push(t, "..");
|
||||
vec::push(t, ~"..");
|
||||
skip -= 1;
|
||||
}
|
||||
ret t;
|
||||
@ -304,122 +304,122 @@ mod tests {
|
||||
#[test]
|
||||
fn test_connect() {
|
||||
let slash = path_sep();
|
||||
log(error, connect("a", "b"));
|
||||
assert (connect("a", "b") == "a" + slash + "b");
|
||||
assert (connect("a" + slash, "b") == "a" + slash + "b");
|
||||
log(error, connect(~"a", ~"b"));
|
||||
assert (connect(~"a", ~"b") == ~"a" + slash + ~"b");
|
||||
assert (connect(~"a" + slash, ~"b") == ~"a" + slash + ~"b");
|
||||
}
|
||||
|
||||
fn ps() -> str {
|
||||
fn ps() -> ~str {
|
||||
path_sep()
|
||||
}
|
||||
|
||||
fn aps() -> str {
|
||||
"/"
|
||||
fn aps() -> ~str {
|
||||
~"/"
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split1() {
|
||||
let actual = split("a" + ps() + "b");
|
||||
let expected = ~["a", "b"];
|
||||
let actual = split(~"a" + ps() + ~"b");
|
||||
let expected = ~[~"a", ~"b"];
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split2() {
|
||||
let actual = split("a" + aps() + "b");
|
||||
let expected = ~["a", "b"];
|
||||
let actual = split(~"a" + aps() + ~"b");
|
||||
let expected = ~[~"a", ~"b"];
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split3() {
|
||||
let actual = split(ps() + "a" + ps() + "b");
|
||||
let expected = ~["a", "b"];
|
||||
let actual = split(ps() + ~"a" + ps() + ~"b");
|
||||
let expected = ~[~"a", ~"b"];
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split4() {
|
||||
let actual = split("a" + ps() + "b" + aps() + "c");
|
||||
let expected = ~["a", "b", "c"];
|
||||
let actual = split(~"a" + ps() + ~"b" + aps() + ~"c");
|
||||
let expected = ~[~"a", ~"b", ~"c"];
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize1() {
|
||||
let actual = normalize("a/b/..");
|
||||
let expected = "a";
|
||||
let actual = normalize(~"a/b/..");
|
||||
let expected = ~"a";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize2() {
|
||||
let actual = normalize("/a/b/..");
|
||||
let expected = "/a";
|
||||
let actual = normalize(~"/a/b/..");
|
||||
let expected = ~"/a";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize3() {
|
||||
let actual = normalize("a/../b");
|
||||
let expected = "b";
|
||||
let actual = normalize(~"a/../b");
|
||||
let expected = ~"b";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize4() {
|
||||
let actual = normalize("/a/../b");
|
||||
let expected = "/b";
|
||||
let actual = normalize(~"/a/../b");
|
||||
let expected = ~"/b";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize5() {
|
||||
let actual = normalize("a/.");
|
||||
let expected = "a";
|
||||
let actual = normalize(~"a/.");
|
||||
let expected = ~"a";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize6() {
|
||||
let actual = normalize("a/./b/");
|
||||
let expected = "a/b/";
|
||||
let actual = normalize(~"a/./b/");
|
||||
let expected = ~"a/b/";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize7() {
|
||||
let actual = normalize("a/..");
|
||||
let expected = ".";
|
||||
let actual = normalize(~"a/..");
|
||||
let expected = ~".";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize8() {
|
||||
let actual = normalize("../../..");
|
||||
let expected = "../../..";
|
||||
let actual = normalize(~"../../..");
|
||||
let expected = ~"../../..";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize9() {
|
||||
let actual = normalize("a/b/../../..");
|
||||
let expected = "..";
|
||||
let actual = normalize(~"a/b/../../..");
|
||||
let expected = ~"..";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize10() {
|
||||
let actual = normalize("/a/b/c/../d/./../../e/");
|
||||
let expected = "/a/e/";
|
||||
let actual = normalize(~"/a/b/c/../d/./../../e/");
|
||||
let expected = ~"/a/e/";
|
||||
log(error, actual);
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize11() {
|
||||
let actual = normalize("/a/..");
|
||||
let expected = "/";
|
||||
let actual = normalize(~"/a/..");
|
||||
let expected = ~"/";
|
||||
assert actual == expected;
|
||||
}
|
||||
|
||||
@ -440,58 +440,58 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn splitext_empty() {
|
||||
let (base, ext) = splitext("");
|
||||
assert base == "";
|
||||
assert ext == "";
|
||||
let (base, ext) = splitext(~"");
|
||||
assert base == ~"";
|
||||
assert ext == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_ext() {
|
||||
let (base, ext) = splitext("grum.exe");
|
||||
assert base == "grum";
|
||||
assert ext == ".exe";
|
||||
let (base, ext) = splitext(~"grum.exe");
|
||||
assert base == ~"grum";
|
||||
assert ext == ~".exe";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_noext() {
|
||||
let (base, ext) = splitext("grum");
|
||||
assert base == "grum";
|
||||
assert ext == "";
|
||||
let (base, ext) = splitext(~"grum");
|
||||
assert base == ~"grum";
|
||||
assert ext == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_dotfile() {
|
||||
let (base, ext) = splitext(".grum");
|
||||
assert base == ".grum";
|
||||
assert ext == "";
|
||||
let (base, ext) = splitext(~".grum");
|
||||
assert base == ~".grum";
|
||||
assert ext == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_path_ext() {
|
||||
let (base, ext) = splitext("oh/grum.exe");
|
||||
assert base == "oh/grum";
|
||||
assert ext == ".exe";
|
||||
let (base, ext) = splitext(~"oh/grum.exe");
|
||||
assert base == ~"oh/grum";
|
||||
assert ext == ~".exe";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_path_noext() {
|
||||
let (base, ext) = splitext("oh/grum");
|
||||
assert base == "oh/grum";
|
||||
assert ext == "";
|
||||
let (base, ext) = splitext(~"oh/grum");
|
||||
assert base == ~"oh/grum";
|
||||
assert ext == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_dot_in_path() {
|
||||
let (base, ext) = splitext("oh.my/grum");
|
||||
assert base == "oh.my/grum";
|
||||
assert ext == "";
|
||||
let (base, ext) = splitext(~"oh.my/grum");
|
||||
assert base == ~"oh.my/grum";
|
||||
assert ext == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn splitext_nobasename() {
|
||||
let (base, ext) = splitext("oh.my/");
|
||||
assert base == "oh.my/";
|
||||
assert ext == "";
|
||||
let (base, ext) = splitext(~"oh.my/");
|
||||
assert base == ~"oh.my/";
|
||||
assert ext == ~"";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ fn wait_event(this: *rust_task) -> *libc::c_void {
|
||||
|
||||
let res = rustrt::task_wait_event(this, &mut killed);
|
||||
if killed && !task::failing() {
|
||||
fail "killed"
|
||||
fail ~"killed"
|
||||
}
|
||||
res
|
||||
}
|
||||
@ -118,7 +118,7 @@ fn send<T: send>(-p: send_packet<T>, -payload: T) {
|
||||
// The receiver will eventually clean this up.
|
||||
unsafe { forget(p); }
|
||||
}
|
||||
full { fail "duplicate send" }
|
||||
full { fail ~"duplicate send" }
|
||||
blocked {
|
||||
#debug("waking up task for %?", p_);
|
||||
alt p.header.blocked_task {
|
||||
@ -126,7 +126,7 @@ fn send<T: send>(-p: send_packet<T>, -payload: T) {
|
||||
rustrt::task_signal_event(
|
||||
task, ptr::addr_of(p.header) as *libc::c_void);
|
||||
}
|
||||
none { fail "blocked packet has no task" }
|
||||
none { fail ~"blocked packet has no task" }
|
||||
}
|
||||
|
||||
// The receiver will eventually clean this up.
|
||||
@ -162,7 +162,7 @@ fn try_recv<T: send>(-p: recv_packet<T>) -> option<T> {
|
||||
}
|
||||
blocked {
|
||||
if first {
|
||||
fail "blocking on already blocked packet"
|
||||
fail ~"blocking on already blocked packet"
|
||||
}
|
||||
}
|
||||
full {
|
||||
@ -184,7 +184,7 @@ fn try_recv<T: send>(-p: recv_packet<T>) -> option<T> {
|
||||
pure fn peek<T: send>(p: recv_packet<T>) -> bool {
|
||||
alt unsafe {(*p.header()).state} {
|
||||
empty { false }
|
||||
blocked { fail "peeking on blocked packet" }
|
||||
blocked { fail ~"peeking on blocked packet" }
|
||||
full | terminated { true }
|
||||
}
|
||||
}
|
||||
@ -207,7 +207,7 @@ fn sender_terminate<T: send>(p: *packet<T>) {
|
||||
}
|
||||
full {
|
||||
// This is impossible
|
||||
fail "you dun goofed"
|
||||
fail ~"you dun goofed"
|
||||
}
|
||||
terminated {
|
||||
// I have to clean up, use drop_glue
|
||||
@ -224,7 +224,7 @@ fn receiver_terminate<T: send>(p: *packet<T>) {
|
||||
}
|
||||
blocked {
|
||||
// this shouldn't happen.
|
||||
fail "terminating a blocked packet"
|
||||
fail ~"terminating a blocked packet"
|
||||
}
|
||||
terminated | full {
|
||||
// I have to clean up, use drop_glue
|
||||
@ -267,7 +267,7 @@ fn wait_many(pkts: &[*packet_header]) -> uint {
|
||||
(*p).state = old;
|
||||
break;
|
||||
}
|
||||
blocked { fail "blocking on blocked packet" }
|
||||
blocked { fail ~"blocking on blocked packet" }
|
||||
empty { }
|
||||
}
|
||||
}
|
||||
@ -313,7 +313,7 @@ fn select2<A: send, B: send>(
|
||||
alt i {
|
||||
0 { left((try_recv(a), b)) }
|
||||
1 { right((a, try_recv(b))) }
|
||||
_ { fail "select2 return an invalid packet" }
|
||||
_ { fail ~"select2 return an invalid packet" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -397,7 +397,7 @@ class recv_packet<T: send> {
|
||||
header
|
||||
}
|
||||
}
|
||||
none { fail "packet already consumed" }
|
||||
none { fail ~"packet already consumed" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -508,7 +508,7 @@ impl port<T: send> for port<T> {
|
||||
some(endp) {
|
||||
pipes::peek(endp)
|
||||
}
|
||||
none { fail "peeking empty stream" }
|
||||
none { fail ~"peeking empty stream" }
|
||||
};
|
||||
self.endp <-> endp;
|
||||
peek
|
||||
@ -558,7 +558,7 @@ impl private_methods/&<T: send> for pipes::port<T> {
|
||||
some(endp) {
|
||||
endp.header()
|
||||
}
|
||||
none { fail "peeking empty stream" }
|
||||
none { fail ~"peeking empty stream" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,11 @@ unsafe fn chan_from_global_ptr<T: send>(
|
||||
abort
|
||||
}
|
||||
|
||||
log(debug,"ENTERING chan_from_global_ptr, before is_prob_zero check");
|
||||
log(debug,~"ENTERING chan_from_global_ptr, before is_prob_zero check");
|
||||
let is_probably_zero = *global == 0u;
|
||||
log(debug,"after is_prob_zero check");
|
||||
log(debug,~"after is_prob_zero check");
|
||||
if is_probably_zero {
|
||||
log(debug,"is probably zero...");
|
||||
log(debug,~"is probably zero...");
|
||||
// There's no global channel. We must make it
|
||||
|
||||
let setup_po = comm::port();
|
||||
@ -54,14 +54,14 @@ unsafe fn chan_from_global_ptr<T: send>(
|
||||
}
|
||||
};
|
||||
|
||||
log(debug,"before setup recv..");
|
||||
log(debug,~"before setup recv..");
|
||||
// This is the proposed global channel
|
||||
let ch = comm::recv(setup_po);
|
||||
// 0 is our sentinal value. It is not a valid channel
|
||||
assert unsafe::reinterpret_cast(ch) != 0u;
|
||||
|
||||
// Install the channel
|
||||
log(debug,"BEFORE COMPARE AND SWAP");
|
||||
log(debug,~"BEFORE COMPARE AND SWAP");
|
||||
let swapped = compare_and_swap(
|
||||
global, 0u, unsafe::reinterpret_cast(ch));
|
||||
log(debug,#fmt("AFTER .. swapped? %?", swapped));
|
||||
@ -76,7 +76,7 @@ unsafe fn chan_from_global_ptr<T: send>(
|
||||
unsafe::reinterpret_cast(*global)
|
||||
}
|
||||
} else {
|
||||
log(debug, "global != 0");
|
||||
log(debug, ~"global != 0");
|
||||
unsafe::reinterpret_cast(*global)
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ fn test_position() {
|
||||
import str::as_c_str;
|
||||
import libc::c_char;
|
||||
|
||||
let s = "hello";
|
||||
let s = ~"hello";
|
||||
unsafe {
|
||||
assert 2u == as_c_str(s, |p| position(p, |c| c == 'l' as c_char));
|
||||
assert 4u == as_c_str(s, |p| position(p, |c| c == 'o' as c_char));
|
||||
@ -184,9 +184,9 @@ fn test_position() {
|
||||
|
||||
#[test]
|
||||
fn test_buf_len() {
|
||||
let s0 = "hello";
|
||||
let s1 = "there";
|
||||
let s2 = "thing";
|
||||
let s0 = ~"hello";
|
||||
let s1 = ~"there";
|
||||
let s2 = ~"thing";
|
||||
do str::as_c_str(s0) |p0| {
|
||||
do str::as_c_str(s1) |p1| {
|
||||
do str::as_c_str(s2) |p2| {
|
||||
|
@ -121,7 +121,7 @@ impl extensions for rng {
|
||||
/**
|
||||
* Return a char randomly chosen from chars, failing if chars is empty
|
||||
*/
|
||||
fn gen_char_from(chars: str) -> char {
|
||||
fn gen_char_from(chars: ~str) -> char {
|
||||
assert !chars.is_empty();
|
||||
self.choose(str::chars(chars))
|
||||
}
|
||||
@ -143,11 +143,11 @@ impl extensions for rng {
|
||||
/**
|
||||
* Return a random string of the specified length composed of A-Z,a-z,0-9
|
||||
*/
|
||||
fn gen_str(len: uint) -> str {
|
||||
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||
fn gen_str(len: uint) -> ~str {
|
||||
let charset = ~"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||
abcdefghijklmnopqrstuvwxyz\
|
||||
0123456789";
|
||||
let mut s = "";
|
||||
let mut s = ~"";
|
||||
let mut i = 0u;
|
||||
while (i < len) {
|
||||
s = s + str::from_char(self.gen_char_from(charset));
|
||||
|
@ -37,7 +37,7 @@ pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
|
||||
alt res {
|
||||
err(u) { u }
|
||||
ok(_) {
|
||||
fail "get_error called on ok result";
|
||||
fail ~"get_error called on ok result";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -333,7 +333,7 @@ fn unwrap<T, U>(-res: result<T, U>) -> T {
|
||||
unsafe {
|
||||
let addr = alt res {
|
||||
ok(x) { ptr::addr_of(x) }
|
||||
err(_) { fail "error result" }
|
||||
err(_) { fail ~"error result" }
|
||||
};
|
||||
let liberated_value = unsafe::reinterpret_cast(*addr);
|
||||
unsafe::forget(res);
|
||||
@ -343,13 +343,13 @@ fn unwrap<T, U>(-res: result<T, U>) -> T {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
fn op1() -> result::result<int, str> { result::ok(666) }
|
||||
fn op1() -> result::result<int, ~str> { result::ok(666) }
|
||||
|
||||
fn op2(&&i: int) -> result::result<uint, str> {
|
||||
fn op2(&&i: int) -> result::result<uint, ~str> {
|
||||
result::ok(i as uint + 1u)
|
||||
}
|
||||
|
||||
fn op3() -> result::result<int, str> { result::err("sadface") }
|
||||
fn op3() -> result::result<int, ~str> { result::err(~"sadface") }
|
||||
|
||||
#[test]
|
||||
fn chain_success() {
|
||||
@ -358,39 +358,39 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn chain_failure() {
|
||||
assert get_err(chain(op3(), op2)) == "sadface";
|
||||
assert get_err(chain(op3(), op2)) == ~"sadface";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_impl_iter() {
|
||||
let mut valid = false;
|
||||
ok::<str, str>("a").iter(|_x| valid = true);
|
||||
ok::<~str, ~str>(~"a").iter(|_x| valid = true);
|
||||
assert valid;
|
||||
|
||||
err::<str, str>("b").iter(|_x| valid = false);
|
||||
err::<~str, ~str>(~"b").iter(|_x| valid = false);
|
||||
assert valid;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_impl_iter_err() {
|
||||
let mut valid = true;
|
||||
ok::<str, str>("a").iter_err(|_x| valid = false);
|
||||
ok::<~str, ~str>(~"a").iter_err(|_x| valid = false);
|
||||
assert valid;
|
||||
|
||||
valid = false;
|
||||
err::<str, str>("b").iter_err(|_x| valid = true);
|
||||
err::<~str, ~str>(~"b").iter_err(|_x| valid = true);
|
||||
assert valid;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_impl_map() {
|
||||
assert ok::<str, str>("a").map(|_x| "b") == ok("b");
|
||||
assert err::<str, str>("a").map(|_x| "b") == err("a");
|
||||
assert ok::<~str, ~str>(~"a").map(|_x| ~"b") == ok(~"b");
|
||||
assert err::<~str, ~str>(~"a").map(|_x| ~"b") == err(~"a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_impl_map_err() {
|
||||
assert ok::<str, str>("a").map_err(|_x| "b") == ok("a");
|
||||
assert err::<str, str>("a").map_err(|_x| "b") == err("b");
|
||||
assert ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == ok(~"a");
|
||||
assert err::<~str, ~str>(~"a").map_err(|_x| ~"b") == err(~"b");
|
||||
}
|
||||
}
|
||||
|
@ -62,9 +62,9 @@ iface program {
|
||||
*
|
||||
* The process id of the spawned process
|
||||
*/
|
||||
fn spawn_process(prog: str, args: ~[str],
|
||||
env: option<~[(str,str)]>,
|
||||
dir: option<str>,
|
||||
fn spawn_process(prog: ~str, args: ~[~str],
|
||||
env: option<~[(~str,~str)]>,
|
||||
dir: option<~str>,
|
||||
in_fd: c_int, out_fd: c_int, err_fd: c_int)
|
||||
-> pid_t {
|
||||
do with_argv(prog, args) |argv| {
|
||||
@ -77,7 +77,7 @@ fn spawn_process(prog: str, args: ~[str],
|
||||
}
|
||||
}
|
||||
|
||||
fn with_argv<T>(prog: str, args: ~[str],
|
||||
fn with_argv<T>(prog: ~str, args: ~[~str],
|
||||
cb: fn(**libc::c_char) -> T) -> T {
|
||||
let mut argptrs = str::as_c_str(prog, |b| ~[b]);
|
||||
let mut tmps = ~[];
|
||||
@ -91,7 +91,7 @@ fn with_argv<T>(prog: str, args: ~[str],
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn with_envp<T>(env: option<~[(str,str)]>,
|
||||
fn with_envp<T>(env: option<~[(~str,~str)]>,
|
||||
cb: fn(*c_void) -> T) -> T {
|
||||
// On posixy systems we can pass a char** for envp, which is
|
||||
// a null-terminated array of "k=v\n" strings.
|
||||
@ -144,7 +144,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 {
|
||||
alt d {
|
||||
some(dir) { str::as_c_str(dir, cb) }
|
||||
@ -164,7 +164,7 @@ fn with_dirp<T>(d: option<str>,
|
||||
*
|
||||
* The process id
|
||||
*/
|
||||
fn run_program(prog: str, args: ~[str]) -> int {
|
||||
fn run_program(prog: ~str, args: ~[~str]) -> int {
|
||||
let pid = spawn_process(prog, args, none, none,
|
||||
0i32, 0i32, 0i32);
|
||||
if pid == -1 as pid_t { fail; }
|
||||
@ -187,7 +187,7 @@ fn run_program(prog: str, args: ~[str]) -> int {
|
||||
*
|
||||
* A class with a <program> field
|
||||
*/
|
||||
fn start_program(prog: str, args: ~[str]) -> program {
|
||||
fn start_program(prog: ~str, args: ~[~str]) -> program {
|
||||
let pipe_input = os::pipe();
|
||||
let pipe_output = os::pipe();
|
||||
let pipe_err = os::pipe();
|
||||
@ -248,8 +248,8 @@ fn start_program(prog: str, args: ~[str]) -> program {
|
||||
ret prog_res(repr) as program;
|
||||
}
|
||||
|
||||
fn read_all(rd: io::reader) -> str {
|
||||
let mut buf = "";
|
||||
fn read_all(rd: io::reader) -> ~str {
|
||||
let mut buf = ~"";
|
||||
while !rd.eof() {
|
||||
let bytes = rd.read_bytes(4096u);
|
||||
buf += str::from_bytes(bytes);
|
||||
@ -271,8 +271,8 @@ fn read_all(rd: io::reader) -> str {
|
||||
* A record, {status: int, out: str, err: str} containing the exit code,
|
||||
* the contents of stdout and the contents of stderr.
|
||||
*/
|
||||
fn program_output(prog: str, args: ~[str]) ->
|
||||
{status: int, out: str, err: str} {
|
||||
fn program_output(prog: ~str, args: ~[~str]) ->
|
||||
{status: int, out: ~str, err: ~str} {
|
||||
|
||||
let pipe_in = os::pipe();
|
||||
let pipe_out = os::pipe();
|
||||
@ -307,8 +307,8 @@ fn program_output(prog: str, args: ~[str]) ->
|
||||
comm::send(ch, (1, output));
|
||||
};
|
||||
let status = run::waitpid(pid);
|
||||
let mut errs = "";
|
||||
let mut outs = "";
|
||||
let mut errs = ~"";
|
||||
let mut outs = ~"";
|
||||
let mut count = 2;
|
||||
while count > 0 {
|
||||
let stream = comm::recv(p);
|
||||
@ -325,7 +325,7 @@ fn program_output(prog: str, args: ~[str]) ->
|
||||
ret {status: status, out: outs, err: errs};
|
||||
}
|
||||
|
||||
fn writeclose(fd: c_int, s: str) {
|
||||
fn writeclose(fd: c_int, s: ~str) {
|
||||
import io::writer_util;
|
||||
|
||||
#error("writeclose %d, %s", fd as int, s);
|
||||
@ -335,10 +335,10 @@ fn writeclose(fd: c_int, s: str) {
|
||||
os::close(fd);
|
||||
}
|
||||
|
||||
fn readclose(fd: c_int) -> str {
|
||||
fn readclose(fd: c_int) -> ~str {
|
||||
let file = os::fdopen(fd);
|
||||
let reader = io::FILE_reader(file, false);
|
||||
let mut buf = "";
|
||||
let mut buf = ~"";
|
||||
while !reader.eof() {
|
||||
let bytes = reader.read_bytes(4096u);
|
||||
buf += str::from_bytes(bytes);
|
||||
@ -397,9 +397,9 @@ mod tests {
|
||||
// Regression test for memory leaks
|
||||
#[ignore(cfg(windows))] // FIXME (#2626)
|
||||
fn test_leaks() {
|
||||
run::run_program("echo", ~[]);
|
||||
run::start_program("echo", ~[]);
|
||||
run::program_output("echo", ~[]);
|
||||
run::run_program(~"echo", ~[]);
|
||||
run::start_program(~"echo", ~[]);
|
||||
run::program_output(~"echo", ~[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -410,14 +410,14 @@ mod tests {
|
||||
|
||||
let pid =
|
||||
run::spawn_process(
|
||||
"cat", ~[], none, none,
|
||||
~"cat", ~[], none, none,
|
||||
pipe_in.in, pipe_out.out, pipe_err.out);
|
||||
os::close(pipe_in.in);
|
||||
os::close(pipe_out.out);
|
||||
os::close(pipe_err.out);
|
||||
|
||||
if pid == -1i32 { fail; }
|
||||
let expected = "test";
|
||||
let expected = ~"test";
|
||||
writeclose(pipe_in.out, expected);
|
||||
let actual = readclose(pipe_out.in);
|
||||
readclose(pipe_err.in);
|
||||
@ -430,7 +430,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn waitpid() {
|
||||
let pid = run::spawn_process("false", ~[],
|
||||
let pid = run::spawn_process(~"false", ~[],
|
||||
none, none,
|
||||
0i32, 0i32, 0i32);
|
||||
let status = run::waitpid(pid);
|
||||
|
1024
src/libcore/str.rs
1024
src/libcore/str.rs
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,7 @@ type rust_cond_lock = *libc::c_void;
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
fn unsupervise();
|
||||
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> str;
|
||||
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> ~str;
|
||||
|
||||
fn rust_create_cond_lock() -> rust_cond_lock;
|
||||
fn rust_destroy_cond_lock(lock: rust_cond_lock);
|
||||
@ -77,7 +77,7 @@ pure fn refcount<T>(+t: @T) -> uint {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn log_str<T>(t: T) -> str {
|
||||
pure fn log_str<T>(t: T) -> ~str {
|
||||
unsafe {
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(ptr::addr_of(t));
|
||||
rustrt::shape_log_str(get_type_desc::<T>(), data_ptr)
|
||||
|
@ -519,7 +519,7 @@ fn yield() {
|
||||
let mut killed = false;
|
||||
rustrt::rust_task_yield(task_, killed);
|
||||
if killed && !failing() {
|
||||
fail "killed";
|
||||
fail ~"killed";
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,20 +613,20 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
|
||||
|
||||
fn new_task_in_new_sched(opts: sched_opts) -> *rust_task {
|
||||
if opts.foreign_stack_size != none {
|
||||
fail "foreign_stack_size scheduler option unimplemented";
|
||||
fail ~"foreign_stack_size scheduler option unimplemented";
|
||||
}
|
||||
|
||||
let num_threads = alt opts.mode {
|
||||
single_threaded { 1u }
|
||||
thread_per_core {
|
||||
fail "thread_per_core scheduling mode unimplemented"
|
||||
fail ~"thread_per_core scheduling mode unimplemented"
|
||||
}
|
||||
thread_per_task {
|
||||
fail "thread_per_task scheduling mode unimplemented"
|
||||
fail ~"thread_per_task scheduling mode unimplemented"
|
||||
}
|
||||
manual_threads(threads) {
|
||||
if threads == 0u {
|
||||
fail "can not create a scheduler with no threads";
|
||||
fail ~"can not create a scheduler with no threads";
|
||||
}
|
||||
threads
|
||||
}
|
||||
@ -980,21 +980,21 @@ fn test_spawn_listiner_bidi() {
|
||||
// Now the child has a port called 'po' to read from and
|
||||
// an environment-captured channel called 'ch'.
|
||||
let res = comm::recv(po);
|
||||
assert res == "ping";
|
||||
comm::send(ch, "pong");
|
||||
assert res == ~"ping";
|
||||
comm::send(ch, ~"pong");
|
||||
};
|
||||
// Likewise, the parent has both a 'po' and 'ch'
|
||||
comm::send(ch, "ping");
|
||||
comm::send(ch, ~"ping");
|
||||
let res = comm::recv(po);
|
||||
assert res == "pong";
|
||||
assert res == ~"pong";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_success() {
|
||||
alt do try {
|
||||
"Success!"
|
||||
~"Success!"
|
||||
} {
|
||||
result::ok("Success!") { }
|
||||
result::ok(~"Success!") { }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
@ -1300,54 +1300,54 @@ fn test_unkillable_nested() {
|
||||
|
||||
#[test]
|
||||
fn test_tls_multitask() unsafe {
|
||||
fn my_key(+_x: @str/~) { }
|
||||
local_data_set(my_key, @"parent data"/~);
|
||||
fn my_key(+_x: @~str) { }
|
||||
local_data_set(my_key, @~"parent data");
|
||||
do task::spawn {
|
||||
assert local_data_get(my_key) == none; // TLS shouldn't carry over.
|
||||
local_data_set(my_key, @"child data"/~);
|
||||
assert *(local_data_get(my_key).get()) == "child data";
|
||||
local_data_set(my_key, @~"child data");
|
||||
assert *(local_data_get(my_key).get()) == ~"child data";
|
||||
// should be cleaned up for us
|
||||
}
|
||||
// Must work multiple times
|
||||
assert *(local_data_get(my_key).get()) == "parent data";
|
||||
assert *(local_data_get(my_key).get()) == "parent data";
|
||||
assert *(local_data_get(my_key).get()) == "parent data";
|
||||
assert *(local_data_get(my_key).get()) == ~"parent data";
|
||||
assert *(local_data_get(my_key).get()) == ~"parent data";
|
||||
assert *(local_data_get(my_key).get()) == ~"parent data";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tls_overwrite() unsafe {
|
||||
fn my_key(+_x: @str/~) { }
|
||||
local_data_set(my_key, @"first data"/~);
|
||||
local_data_set(my_key, @"next data"/~); // Shouldn't leak.
|
||||
assert *(local_data_get(my_key).get()) == "next data";
|
||||
fn my_key(+_x: @~str) { }
|
||||
local_data_set(my_key, @~"first data");
|
||||
local_data_set(my_key, @~"next data"); // Shouldn't leak.
|
||||
assert *(local_data_get(my_key).get()) == ~"next data";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tls_pop() unsafe {
|
||||
fn my_key(+_x: @str/~) { }
|
||||
local_data_set(my_key, @"weasel"/~);
|
||||
assert *(local_data_pop(my_key).get()) == "weasel";
|
||||
fn my_key(+_x: @~str) { }
|
||||
local_data_set(my_key, @~"weasel");
|
||||
assert *(local_data_pop(my_key).get()) == ~"weasel";
|
||||
// Pop must remove the data from the map.
|
||||
assert local_data_pop(my_key) == none;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tls_modify() unsafe {
|
||||
fn my_key(+_x: @str/~) { }
|
||||
fn my_key(+_x: @~str) { }
|
||||
local_data_modify(my_key, |data| {
|
||||
alt data {
|
||||
some(@val) { fail "unwelcome value: " + val }
|
||||
none { some(@"first data"/~) }
|
||||
some(@val) { fail ~"unwelcome value: " + val }
|
||||
none { some(@~"first data") }
|
||||
}
|
||||
});
|
||||
local_data_modify(my_key, |data| {
|
||||
alt data {
|
||||
some(@"first data"/~) { some(@"next data"/~) }
|
||||
some(@val) { fail "wrong value: " + val }
|
||||
none { fail "missing value" }
|
||||
some(@~"first data") { some(@~"next data") }
|
||||
some(@val) { fail ~"wrong value: " + val }
|
||||
none { fail ~"missing value" }
|
||||
}
|
||||
});
|
||||
assert *(local_data_pop(my_key).get()) == "next data";
|
||||
assert *(local_data_pop(my_key).get()) == ~"next data";
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1357,19 +1357,19 @@ fn test_tls_crust_automorestack_memorial_bug() unsafe {
|
||||
// jump over to the rust stack, which causes next_c_sp to get recorded as
|
||||
// something within a rust stack segment. Then a subsequent upcall (esp.
|
||||
// for logging, think vsnprintf) would run on a stack smaller than 1 MB.
|
||||
fn my_key(+_x: @str/~) { }
|
||||
fn my_key(+_x: @~str) { }
|
||||
do task::spawn {
|
||||
unsafe { local_data_set(my_key, @"hax"/~); }
|
||||
unsafe { local_data_set(my_key, @~"hax"); }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tls_multiple_types() unsafe {
|
||||
fn str_key(+_x: @str/~) { }
|
||||
fn str_key(+_x: @~str) { }
|
||||
fn box_key(+_x: @@()) { }
|
||||
fn int_key(+_x: @int) { }
|
||||
do task::spawn {
|
||||
local_data_set(str_key, @"string data"/~);
|
||||
local_data_set(str_key, @~"string data");
|
||||
local_data_set(box_key, @@());
|
||||
local_data_set(int_key, @42);
|
||||
}
|
||||
@ -1377,11 +1377,11 @@ fn test_tls_multiple_types() unsafe {
|
||||
|
||||
#[test]
|
||||
fn test_tls_overwrite_multiple_types() unsafe {
|
||||
fn str_key(+_x: @str/~) { }
|
||||
fn str_key(+_x: @~str) { }
|
||||
fn box_key(+_x: @@()) { }
|
||||
fn int_key(+_x: @int) { }
|
||||
do task::spawn {
|
||||
local_data_set(str_key, @"string data"/~);
|
||||
local_data_set(str_key, @~"string data");
|
||||
local_data_set(int_key, @42);
|
||||
// This could cause a segfault if overwriting-destruction is done with
|
||||
// the crazy polymorphic transmute rather than the provided finaliser.
|
||||
@ -1393,13 +1393,13 @@ fn test_tls_overwrite_multiple_types() unsafe {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_tls_cleanup_on_failure() unsafe {
|
||||
fn str_key(+_x: @str/~) { }
|
||||
fn str_key(+_x: @~str) { }
|
||||
fn box_key(+_x: @@()) { }
|
||||
fn int_key(+_x: @int) { }
|
||||
local_data_set(str_key, @"parent data"/~);
|
||||
local_data_set(str_key, @~"parent data");
|
||||
local_data_set(box_key, @@());
|
||||
do task::spawn { // spawn_linked
|
||||
local_data_set(str_key, @"string data"/~);
|
||||
local_data_set(str_key, @~"string data");
|
||||
local_data_set(box_key, @@());
|
||||
local_data_set(int_key, @42);
|
||||
fail;
|
||||
|
@ -10,10 +10,10 @@ impl of to_bytes for @~[u8] {
|
||||
fn to_bytes() -> ~[u8] { copy *self }
|
||||
}
|
||||
|
||||
impl of to_bytes for str {
|
||||
impl of to_bytes for ~str {
|
||||
fn to_bytes() -> ~[u8] { str::bytes(self) }
|
||||
}
|
||||
|
||||
impl of to_bytes for @(str/~) {
|
||||
impl of to_bytes for @(~str) {
|
||||
fn to_bytes() -> ~[u8] { str::bytes(*self) }
|
||||
}
|
||||
|
@ -1,67 +1,67 @@
|
||||
iface to_str { fn to_str() -> str; }
|
||||
iface to_str { fn to_str() -> ~str; }
|
||||
|
||||
impl of to_str for int {
|
||||
fn to_str() -> str { int::str(self) }
|
||||
fn to_str() -> ~str { int::str(self) }
|
||||
}
|
||||
impl of to_str for i8 {
|
||||
fn to_str() -> str { i8::str(self) }
|
||||
fn to_str() -> ~str { i8::str(self) }
|
||||
}
|
||||
impl of to_str for i16 {
|
||||
fn to_str() -> str { i16::str(self) }
|
||||
fn to_str() -> ~str { i16::str(self) }
|
||||
}
|
||||
impl of to_str for i32 {
|
||||
fn to_str() -> str { i32::str(self) }
|
||||
fn to_str() -> ~str { i32::str(self) }
|
||||
}
|
||||
impl of to_str for i64 {
|
||||
fn to_str() -> str { i64::str(self) }
|
||||
fn to_str() -> ~str { i64::str(self) }
|
||||
}
|
||||
impl of to_str for uint {
|
||||
fn to_str() -> str { uint::str(self) }
|
||||
fn to_str() -> ~str { uint::str(self) }
|
||||
}
|
||||
impl of to_str for u8 {
|
||||
fn to_str() -> str { u8::str(self) }
|
||||
fn to_str() -> ~str { u8::str(self) }
|
||||
}
|
||||
impl of to_str for u16 {
|
||||
fn to_str() -> str { u16::str(self) }
|
||||
fn to_str() -> ~str { u16::str(self) }
|
||||
}
|
||||
impl of to_str for u32 {
|
||||
fn to_str() -> str { u32::str(self) }
|
||||
fn to_str() -> ~str { u32::str(self) }
|
||||
}
|
||||
impl of to_str for u64 {
|
||||
fn to_str() -> str { u64::str(self) }
|
||||
fn to_str() -> ~str { u64::str(self) }
|
||||
}
|
||||
impl of to_str for float {
|
||||
fn to_str() -> str { float::to_str(self, 4u) }
|
||||
fn to_str() -> ~str { float::to_str(self, 4u) }
|
||||
}
|
||||
impl of to_str for bool {
|
||||
fn to_str() -> str { bool::to_str(self) }
|
||||
fn to_str() -> ~str { bool::to_str(self) }
|
||||
}
|
||||
impl of to_str for () {
|
||||
fn to_str() -> str { "()" }
|
||||
fn to_str() -> ~str { ~"()" }
|
||||
}
|
||||
impl of to_str for str {
|
||||
fn to_str() -> str { self }
|
||||
impl of to_str for ~str {
|
||||
fn to_str() -> ~str { self }
|
||||
}
|
||||
|
||||
impl <A: to_str copy, B: to_str copy> of to_str for (A, B) {
|
||||
fn to_str() -> str {
|
||||
fn to_str() -> ~str {
|
||||
let (a, b) = self;
|
||||
"(" + a.to_str() + ", " + b.to_str() + ")"
|
||||
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
|
||||
}
|
||||
}
|
||||
impl <A: to_str copy, B: to_str copy, C: to_str copy> of to_str for (A, B, C){
|
||||
fn to_str() -> str {
|
||||
fn to_str() -> ~str {
|
||||
let (a, b, c) = self;
|
||||
"(" + a.to_str() + ", " + b.to_str() + ", " + c.to_str() + ")"
|
||||
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
|
||||
}
|
||||
}
|
||||
|
||||
impl <A: to_str> of to_str for ~[A] {
|
||||
fn to_str() -> str {
|
||||
let mut acc = "[", first = true;
|
||||
fn to_str() -> ~str {
|
||||
let mut acc = ~"[", first = true;
|
||||
for vec::each(self) |elt| {
|
||||
if first { first = false; }
|
||||
else { str::push_str(acc, ", "); }
|
||||
else { str::push_str(acc, ~", "); }
|
||||
str::push_str(acc, elt.to_str());
|
||||
}
|
||||
str::push_char(acc, ']');
|
||||
@ -70,47 +70,47 @@ impl <A: to_str> of to_str for ~[A] {
|
||||
}
|
||||
|
||||
impl <A: to_str> of to_str for @A {
|
||||
fn to_str() -> str { "@" + (*self).to_str() }
|
||||
fn to_str() -> ~str { ~"@" + (*self).to_str() }
|
||||
}
|
||||
impl <A: to_str> of to_str for ~A {
|
||||
fn to_str() -> str { "~" + (*self).to_str() }
|
||||
fn to_str() -> ~str { ~"~" + (*self).to_str() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_simple_types() {
|
||||
assert 1.to_str() == "1";
|
||||
assert (-1).to_str() == "-1";
|
||||
assert 200u.to_str() == "200";
|
||||
assert 2u8.to_str() == "2";
|
||||
assert true.to_str() == "true";
|
||||
assert false.to_str() == "false";
|
||||
assert ().to_str() == "()";
|
||||
assert "hi".to_str() == "hi";
|
||||
assert 1.to_str() == ~"1";
|
||||
assert (-1).to_str() == ~"-1";
|
||||
assert 200u.to_str() == ~"200";
|
||||
assert 2u8.to_str() == ~"2";
|
||||
assert true.to_str() == ~"true";
|
||||
assert false.to_str() == ~"false";
|
||||
assert ().to_str() == ~"()";
|
||||
assert (~"hi").to_str() == ~"hi";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_types() {
|
||||
assert (1, 2).to_str() == "(1, 2)";
|
||||
assert ("a", "b", false).to_str() == "(a, b, false)";
|
||||
assert ((), ((), 100)).to_str() == "((), ((), 100))";
|
||||
assert (1, 2).to_str() == ~"(1, 2)";
|
||||
assert (~"a", ~"b", false).to_str() == ~"(a, b, false)";
|
||||
assert ((), ((), 100)).to_str() == ~"((), ((), 100))";
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_vectors() {
|
||||
let x: ~[int] = ~[];
|
||||
assert x.to_str() == "~[]";
|
||||
assert (~[1]).to_str() == "~[1]";
|
||||
assert (~[1, 2, 3]).to_str() == "~[1, 2, 3]";
|
||||
assert x.to_str() == ~"~[]";
|
||||
assert (~[1]).to_str() == ~"~[1]";
|
||||
assert (~[1, 2, 3]).to_str() == ~"~[1, 2, 3]";
|
||||
assert (~[~[], ~[1], ~[1, 1]]).to_str() ==
|
||||
"~[~[], ~[1], ~[1, 1]]";
|
||||
~"~[~[], ~[1], ~[1, 1]]";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pointer_types() {
|
||||
assert (@1).to_str() == "@1";
|
||||
assert (~(true, false)).to_str() == "~(true, false)";
|
||||
assert (@1).to_str() == ~"@1";
|
||||
assert (~(true, false)).to_str() == ~"~(true, false)";
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ pure fn swap<T:copy, U:copy>(pair: (T, U)) -> (U, T) {
|
||||
#[test]
|
||||
fn test_tuple() {
|
||||
assert first((948, 4039.48)) == 948;
|
||||
assert second((34.5, "foo")) == "foo";
|
||||
assert second((34.5, ~"foo")) == ~"foo";
|
||||
assert swap(('a', 2)) == (2, 'a');
|
||||
}
|
||||
|
||||
|
@ -121,10 +121,10 @@ impl times of iter::times for T {
|
||||
}
|
||||
|
||||
/// Parse a string to an int
|
||||
fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) }
|
||||
fn from_str(s: ~str) -> option<T> { parse_buf(str::bytes(s), 10u) }
|
||||
|
||||
/// Parse a string as an unsigned integer.
|
||||
fn from_str_radix(buf: str, radix: u64) -> option<u64> {
|
||||
fn from_str_radix(buf: ~str, radix: u64) -> option<u64> {
|
||||
if str::len(buf) == 0u { ret none; }
|
||||
let mut i = str::len(buf) - 1u;
|
||||
let mut power = 1u64, n = 0u64;
|
||||
@ -146,7 +146,7 @@ fn from_str_radix(buf: str, radix: u64) -> option<u64> {
|
||||
*
|
||||
* Fails if `radix` < 2 or `radix` > 16
|
||||
*/
|
||||
fn to_str(num: T, radix: uint) -> str {
|
||||
fn to_str(num: T, radix: uint) -> ~str {
|
||||
do to_str_bytes(false, num, radix) |slice| {
|
||||
do vec::unpack_slice(slice) |p, len| {
|
||||
unsafe { str::unsafe::from_buf_len(p, len) }
|
||||
@ -220,46 +220,46 @@ fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
|
||||
}
|
||||
|
||||
/// Convert to a string
|
||||
fn str(i: T) -> str { ret to_str(i, 10u); }
|
||||
fn str(i: T) -> ~str { ret to_str(i, 10u); }
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
assert to_str(0 as T, 10u) == "0";
|
||||
assert to_str(1 as T, 10u) == "1";
|
||||
assert to_str(2 as T, 10u) == "2";
|
||||
assert to_str(11 as T, 10u) == "11";
|
||||
assert to_str(11 as T, 16u) == "b";
|
||||
assert to_str(255 as T, 16u) == "ff";
|
||||
assert to_str(0xff as T, 10u) == "255";
|
||||
assert to_str(0 as T, 10u) == ~"0";
|
||||
assert to_str(1 as T, 10u) == ~"1";
|
||||
assert to_str(2 as T, 10u) == ~"2";
|
||||
assert to_str(11 as T, 10u) == ~"11";
|
||||
assert to_str(11 as T, 16u) == ~"b";
|
||||
assert to_str(255 as T, 16u) == ~"ff";
|
||||
assert to_str(0xff as T, 10u) == ~"255";
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_from_str() {
|
||||
assert from_str("0") == some(0u as T);
|
||||
assert from_str("3") == some(3u as T);
|
||||
assert from_str("10") == some(10u as T);
|
||||
assert from_str("123456789") == some(123456789u as T);
|
||||
assert from_str("00100") == some(100u as T);
|
||||
assert from_str(~"0") == some(0u as T);
|
||||
assert from_str(~"3") == some(3u as T);
|
||||
assert from_str(~"10") == some(10u as T);
|
||||
assert from_str(~"123456789") == some(123456789u as T);
|
||||
assert from_str(~"00100") == some(100u as T);
|
||||
|
||||
assert from_str("") == none;
|
||||
assert from_str(" ") == none;
|
||||
assert from_str("x") == none;
|
||||
assert from_str(~"") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~"x") == none;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_parse_buf() {
|
||||
import str::bytes;
|
||||
assert parse_buf(bytes("123"), 10u) == some(123u as T);
|
||||
assert parse_buf(bytes("1001"), 2u) == some(9u as T);
|
||||
assert parse_buf(bytes("123"), 8u) == some(83u as T);
|
||||
assert parse_buf(bytes("123"), 16u) == some(291u as T);
|
||||
assert parse_buf(bytes("ffff"), 16u) == some(65535u as T);
|
||||
assert parse_buf(bytes("z"), 36u) == some(35u as T);
|
||||
assert parse_buf(bytes(~"123"), 10u) == some(123u as T);
|
||||
assert parse_buf(bytes(~"1001"), 2u) == some(9u as T);
|
||||
assert parse_buf(bytes(~"123"), 8u) == some(83u as T);
|
||||
assert parse_buf(bytes(~"123"), 16u) == some(291u as T);
|
||||
assert parse_buf(bytes(~"ffff"), 16u) == some(65535u as T);
|
||||
assert parse_buf(bytes(~"z"), 36u) == some(35u as T);
|
||||
|
||||
assert parse_buf(str::bytes("Z"), 10u) == none;
|
||||
assert parse_buf(str::bytes("_"), 2u) == none;
|
||||
assert parse_buf(str::bytes(~"Z"), 10u) == none;
|
||||
assert parse_buf(str::bytes(~"_"), 2u) == none;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -58,13 +58,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_bump_box_refcount() {
|
||||
unsafe {
|
||||
let box = @"box box box"/~; // refcount 1
|
||||
let box = @~"box box box"; // refcount 1
|
||||
bump_box_refcount(box); // refcount 2
|
||||
let ptr: *int = transmute(box); // refcount 2
|
||||
let _box1: @str/~ = reinterpret_cast(ptr);
|
||||
let _box2: @str/~ = reinterpret_cast(ptr);
|
||||
assert *_box1 == "box box box";
|
||||
assert *_box2 == "box box box";
|
||||
let _box1: @~str = reinterpret_cast(ptr);
|
||||
let _box2: @~str = reinterpret_cast(ptr);
|
||||
assert *_box1 == ~"box box box";
|
||||
assert *_box2 == ~"box box box";
|
||||
// Will destroy _box1 and _box2. Without the bump, this would
|
||||
// use-after-free. With too many bumps, it would leak.
|
||||
}
|
||||
@ -83,7 +83,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_transmute2() {
|
||||
unsafe {
|
||||
assert transmute("L") == ~[76u8, 0u8];
|
||||
assert transmute(~"L") == ~[76u8, 0u8];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ pure fn init<T: copy>(v: &[const T]) -> ~[T] {
|
||||
|
||||
/// Returns the last element of the slice `v`, failing if the slice is empty.
|
||||
pure fn last<T: copy>(v: &[const T]) -> T {
|
||||
if len(v) == 0u { fail "last_unsafe: empty vector" }
|
||||
if len(v) == 0u { fail ~"last_unsafe: empty vector" }
|
||||
v[len(v) - 1u]
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
import io::{reader, reader_util};
|
||||
|
||||
iface to_base64 {
|
||||
fn to_base64() -> str;
|
||||
fn to_base64() -> ~str;
|
||||
}
|
||||
|
||||
impl of to_base64 for ~[u8] {
|
||||
fn to_base64() -> str {
|
||||
fn to_base64() -> ~str {
|
||||
let chars = str::chars(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
);
|
||||
|
||||
let len = self.len();
|
||||
let mut s = "";
|
||||
let mut s = ~"";
|
||||
str::reserve(s, ((len + 3u) / 4u) * 3u);
|
||||
|
||||
let mut i = 0u;
|
||||
@ -52,8 +52,8 @@ impl of to_base64 for ~[u8] {
|
||||
}
|
||||
}
|
||||
|
||||
impl of to_base64 for str {
|
||||
fn to_base64() -> str {
|
||||
impl of to_base64 for ~str {
|
||||
fn to_base64() -> ~str {
|
||||
str::bytes(self).to_base64()
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,7 @@ iface from_base64 {
|
||||
|
||||
impl of from_base64 for ~[u8] {
|
||||
fn from_base64() -> ~[u8] {
|
||||
if self.len() % 4u != 0u { fail "invalid base64 length"; }
|
||||
if self.len() % 4u != 0u { fail ~"invalid base64 length"; }
|
||||
|
||||
let len = self.len();
|
||||
let mut padding = 0u;
|
||||
@ -107,11 +107,11 @@ impl of from_base64 for ~[u8] {
|
||||
ret copy r;
|
||||
}
|
||||
_ {
|
||||
fail "invalid base64 padding";
|
||||
fail ~"invalid base64 padding";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fail "invalid base64 character";
|
||||
fail ~"invalid base64 character";
|
||||
}
|
||||
|
||||
i += 1u;
|
||||
@ -126,7 +126,7 @@ impl of from_base64 for ~[u8] {
|
||||
}
|
||||
}
|
||||
|
||||
impl of from_base64 for str {
|
||||
impl of from_base64 for ~str {
|
||||
fn from_base64() -> ~[u8] {
|
||||
str::bytes(self).from_base64()
|
||||
}
|
||||
@ -136,23 +136,23 @@ impl of from_base64 for str {
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_to_base64() {
|
||||
assert "".to_base64() == "";
|
||||
assert "f".to_base64() == "Zg==";
|
||||
assert "fo".to_base64() == "Zm8=";
|
||||
assert "foo".to_base64() == "Zm9v";
|
||||
assert "foob".to_base64() == "Zm9vYg==";
|
||||
assert "fooba".to_base64() == "Zm9vYmE=";
|
||||
assert "foobar".to_base64() == "Zm9vYmFy";
|
||||
assert (~"").to_base64() == ~"";
|
||||
assert (~"f").to_base64() == ~"Zg==";
|
||||
assert (~"fo").to_base64() == ~"Zm8=";
|
||||
assert (~"foo").to_base64() == ~"Zm9v";
|
||||
assert (~"foob").to_base64() == ~"Zm9vYg==";
|
||||
assert (~"fooba").to_base64() == ~"Zm9vYmE=";
|
||||
assert (~"foobar").to_base64() == ~"Zm9vYmFy";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_base64() {
|
||||
assert "".from_base64() == str::bytes("");
|
||||
assert "Zg==".from_base64() == str::bytes("f");
|
||||
assert "Zm8=".from_base64() == str::bytes("fo");
|
||||
assert "Zm9v".from_base64() == str::bytes("foo");
|
||||
assert "Zm9vYg==".from_base64() == str::bytes("foob");
|
||||
assert "Zm9vYmE=".from_base64() == str::bytes("fooba");
|
||||
assert "Zm9vYmFy".from_base64() == str::bytes("foobar");
|
||||
assert (~"").from_base64() == str::bytes(~"");
|
||||
assert (~"Zg==").from_base64() == str::bytes(~"f");
|
||||
assert (~"Zm8=").from_base64() == str::bytes(~"fo");
|
||||
assert (~"Zm9v").from_base64() == str::bytes(~"foo");
|
||||
assert (~"Zm9vYg==").from_base64() == str::bytes(~"foob");
|
||||
assert (~"Zm9vYmE=").from_base64() == str::bytes(~"fooba");
|
||||
assert (~"Zm9vYmFy").from_base64() == str::bytes(~"foobar");
|
||||
}
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ fn each_storage(v: bitv, op: fn(&uint) -> bool) {
|
||||
* The resulting string has the same length as the bitvector, and each
|
||||
* character is either '0' or '1'.
|
||||
*/
|
||||
fn to_str(v: bitv) -> str {
|
||||
let mut rs = "";
|
||||
for each(v) |i| { if i { rs += "1"; } else { rs += "0"; } }
|
||||
fn to_str(v: bitv) -> ~str {
|
||||
let mut rs = ~"";
|
||||
for each(v) |i| { if i { rs += ~"1"; } else { rs += ~"0"; } }
|
||||
ret rs;
|
||||
}
|
||||
|
||||
@ -243,10 +243,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
let zerolen = bitv(0u, false);
|
||||
assert to_str(zerolen) == "";
|
||||
assert to_str(zerolen) == ~"";
|
||||
|
||||
let eightbits = bitv(8u, false);
|
||||
assert to_str(eightbits) == "00000000";
|
||||
assert to_str(eightbits) == ~"00000000";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -127,7 +127,7 @@ fn with_doc_data<T>(d: doc, f: fn(x: &[u8]) -> T) -> T {
|
||||
ret f(vec::slice::<u8>(*d.data, d.start, d.end));
|
||||
}
|
||||
|
||||
fn doc_as_str(d: doc) -> str { ret str::from_bytes(doc_data(d)); }
|
||||
fn doc_as_str(d: doc) -> ~str { ret str::from_bytes(doc_data(d)); }
|
||||
|
||||
fn doc_as_u8(d: doc) -> u8 {
|
||||
assert d.end == d.start + 1u;
|
||||
@ -271,7 +271,7 @@ impl writer for writer {
|
||||
self.wr_tagged_bytes(tag_id, &[v as u8]);
|
||||
}
|
||||
|
||||
fn wr_tagged_str(tag_id: uint, v: str) {
|
||||
fn wr_tagged_str(tag_id: uint, v: ~str) {
|
||||
// Lame: can't use str::as_bytes() here because the resulting
|
||||
// vector is NULL-terminated. Annoyingly, the underlying
|
||||
// writer interface doesn't permit us to write a slice of a
|
||||
@ -286,7 +286,7 @@ impl writer for writer {
|
||||
self.writer.write(b);
|
||||
}
|
||||
|
||||
fn wr_str(s: str) {
|
||||
fn wr_str(s: ~str) {
|
||||
#debug["Write str: %?", s];
|
||||
self.writer.write(str::bytes(s));
|
||||
}
|
||||
@ -320,7 +320,7 @@ impl serializer of serialization::serializer for ebml::writer {
|
||||
self.wr_tagged_u32(t as uint, v as u32);
|
||||
}
|
||||
|
||||
fn _emit_label(label: str) {
|
||||
fn _emit_label(label: ~str) {
|
||||
// There are various strings that we have access to, such as
|
||||
// the name of a record field, which do not actually appear in
|
||||
// the serialized EBML (normally). This is just for
|
||||
@ -345,17 +345,17 @@ impl serializer of serialization::serializer for ebml::writer {
|
||||
fn emit_bool(v: bool) { self.wr_tagged_u8(es_bool as uint, v as u8) }
|
||||
|
||||
// FIXME (#2742): implement these
|
||||
fn emit_f64(_v: f64) { fail "Unimplemented: serializing an f64"; }
|
||||
fn emit_f32(_v: f32) { fail "Unimplemented: serializing an f32"; }
|
||||
fn emit_float(_v: float) { fail "Unimplemented: serializing a float"; }
|
||||
fn emit_f64(_v: f64) { fail ~"Unimplemented: serializing an f64"; }
|
||||
fn emit_f32(_v: f32) { fail ~"Unimplemented: serializing an f32"; }
|
||||
fn emit_float(_v: float) { fail ~"Unimplemented: serializing a float"; }
|
||||
|
||||
fn emit_str(v: str) { self.wr_tagged_str(es_str as uint, v) }
|
||||
fn emit_str(v: ~str) { self.wr_tagged_str(es_str as uint, v) }
|
||||
|
||||
fn emit_enum(name: str, f: fn()) {
|
||||
fn emit_enum(name: ~str, f: fn()) {
|
||||
self._emit_label(name);
|
||||
self.wr_tag(es_enum as uint, f)
|
||||
}
|
||||
fn emit_enum_variant(_v_name: str, v_id: uint, _cnt: uint, f: fn()) {
|
||||
fn emit_enum_variant(_v_name: ~str, v_id: uint, _cnt: uint, f: fn()) {
|
||||
self._emit_tagged_uint(es_enum_vid, v_id);
|
||||
self.wr_tag(es_enum_body as uint, f)
|
||||
}
|
||||
@ -375,7 +375,7 @@ impl serializer of serialization::serializer for ebml::writer {
|
||||
fn emit_box(f: fn()) { f() }
|
||||
fn emit_uniq(f: fn()) { f() }
|
||||
fn emit_rec(f: fn()) { f() }
|
||||
fn emit_rec_field(f_name: str, _f_idx: uint, f: fn()) {
|
||||
fn emit_rec_field(f_name: ~str, _f_idx: uint, f: fn()) {
|
||||
self._emit_label(f_name);
|
||||
f()
|
||||
}
|
||||
@ -391,7 +391,7 @@ fn ebml_deserializer(d: ebml::doc) -> ebml_deserializer {
|
||||
}
|
||||
|
||||
impl deserializer of serialization::deserializer for ebml_deserializer {
|
||||
fn _check_label(lbl: str) {
|
||||
fn _check_label(lbl: ~str) {
|
||||
if self.pos < self.parent.end {
|
||||
let {tag: r_tag, doc: r_doc} =
|
||||
ebml::doc_at(self.parent.data, self.pos);
|
||||
@ -408,7 +408,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
|
||||
fn next_doc(exp_tag: ebml_serializer_tag) -> ebml::doc {
|
||||
#debug[". next_doc(exp_tag=%?)", exp_tag];
|
||||
if self.pos >= self.parent.end {
|
||||
fail "no more documents in current node!";
|
||||
fail ~"no more documents in current node!";
|
||||
}
|
||||
let {tag: r_tag, doc: r_doc} =
|
||||
ebml::doc_at(self.parent.data, self.pos);
|
||||
@ -472,14 +472,14 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
|
||||
|
||||
fn read_bool() -> bool { ebml::doc_as_u8(self.next_doc(es_bool)) as bool }
|
||||
|
||||
fn read_f64() -> f64 { fail "read_f64()"; }
|
||||
fn read_f32() -> f32 { fail "read_f32()"; }
|
||||
fn read_float() -> float { fail "read_float()"; }
|
||||
fn read_f64() -> f64 { fail ~"read_f64()"; }
|
||||
fn read_f32() -> f32 { fail ~"read_f32()"; }
|
||||
fn read_float() -> float { fail ~"read_float()"; }
|
||||
|
||||
fn read_str() -> str { ebml::doc_as_str(self.next_doc(es_str)) }
|
||||
fn read_str() -> ~str { ebml::doc_as_str(self.next_doc(es_str)) }
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T:copy>(name: str, f: fn() -> T) -> T {
|
||||
fn read_enum<T:copy>(name: ~str, f: fn() -> T) -> T {
|
||||
#debug["read_enum(%s)", name];
|
||||
self._check_label(name);
|
||||
self.push_doc(self.next_doc(es_enum), f)
|
||||
@ -528,7 +528,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_rec_field<T:copy>(f_name: str, f_idx: uint, f: fn() -> T) -> T {
|
||||
fn read_rec_field<T:copy>(f_name: ~str, f_idx: uint, f: fn() -> T) -> T {
|
||||
#debug["read_rec_field(%s, idx=%u)", f_name, f_idx];
|
||||
self._check_label(f_name);
|
||||
f()
|
||||
@ -556,13 +556,13 @@ fn test_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 {
|
||||
none {
|
||||
s.emit_enum_variant("core::option::none", 0u, 0u, || { } );
|
||||
s.emit_enum_variant(~"core::option::none", 0u, 0u, || { } );
|
||||
}
|
||||
some(v0) {
|
||||
do s.emit_enum_variant("core::option::some", 1u, 1u) {
|
||||
do s.emit_enum_variant(~"core::option::some", 1u, 1u) {
|
||||
s.emit_enum_variant_arg(0u, || serialize_1(s, v0));
|
||||
}
|
||||
}
|
||||
@ -575,7 +575,7 @@ fn test_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| {
|
||||
alt check i {
|
||||
0u { none }
|
||||
|
@ -84,7 +84,7 @@ export opt_maybe_str;
|
||||
export opt_default;
|
||||
export result; //NDM
|
||||
|
||||
enum name { long(str), short(char), }
|
||||
enum name { long(~str), short(char), }
|
||||
|
||||
enum hasarg { yes, no, maybe, }
|
||||
|
||||
@ -93,29 +93,29 @@ enum occur { req, optional, multi, }
|
||||
/// A description of a possible option
|
||||
type opt = {name: name, hasarg: hasarg, occur: occur};
|
||||
|
||||
fn mkname(nm: str) -> name {
|
||||
fn mkname(nm: ~str) -> name {
|
||||
ret if str::len(nm) == 1u {
|
||||
short(str::char_at(nm, 0u))
|
||||
} else { long(nm) };
|
||||
}
|
||||
|
||||
/// Create an option that is required and takes an argument
|
||||
fn reqopt(name: str) -> opt {
|
||||
fn reqopt(name: ~str) -> opt {
|
||||
ret {name: mkname(name), hasarg: yes, occur: req};
|
||||
}
|
||||
|
||||
/// Create an option that is optional and takes an argument
|
||||
fn optopt(name: str) -> opt {
|
||||
fn optopt(name: ~str) -> opt {
|
||||
ret {name: mkname(name), hasarg: yes, occur: optional};
|
||||
}
|
||||
|
||||
/// Create an option that is optional and does not take an argument
|
||||
fn optflag(name: str) -> opt {
|
||||
fn optflag(name: ~str) -> opt {
|
||||
ret {name: mkname(name), hasarg: no, occur: optional};
|
||||
}
|
||||
|
||||
/// Create an option that is optional and takes an optional argument
|
||||
fn optflagopt(name: str) -> opt {
|
||||
fn optflagopt(name: ~str) -> opt {
|
||||
ret {name: mkname(name), hasarg: maybe, occur: optional};
|
||||
}
|
||||
|
||||
@ -123,23 +123,23 @@ fn optflagopt(name: str) -> opt {
|
||||
* Create an option that is optional, takes an argument, and may occur
|
||||
* multiple times
|
||||
*/
|
||||
fn optmulti(name: str) -> opt {
|
||||
fn optmulti(name: ~str) -> opt {
|
||||
ret {name: mkname(name), hasarg: yes, occur: multi};
|
||||
}
|
||||
|
||||
enum optval { val(str), given, }
|
||||
enum optval { val(~str), given, }
|
||||
|
||||
/**
|
||||
* The result of checking command line arguments. Contains a vector
|
||||
* of matches and a vector of free strings.
|
||||
*/
|
||||
type match = {opts: ~[opt], vals: ~[~[optval]], free: ~[str]};
|
||||
type match = {opts: ~[opt], vals: ~[~[optval]], free: ~[~str]};
|
||||
|
||||
fn is_arg(arg: str) -> bool {
|
||||
fn is_arg(arg: ~str) -> bool {
|
||||
ret str::len(arg) > 1u && arg[0] == '-' as u8;
|
||||
}
|
||||
|
||||
fn name_str(nm: name) -> str {
|
||||
fn name_str(nm: name) -> ~str {
|
||||
ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
|
||||
}
|
||||
|
||||
@ -152,24 +152,26 @@ fn find_opt(opts: ~[opt], nm: name) -> option<uint> {
|
||||
* expected format. Pass this value to <fail_str> to get an error message.
|
||||
*/
|
||||
enum fail_ {
|
||||
argument_missing(str),
|
||||
unrecognized_option(str),
|
||||
option_missing(str),
|
||||
option_duplicated(str),
|
||||
unexpected_argument(str),
|
||||
argument_missing(~str),
|
||||
unrecognized_option(~str),
|
||||
option_missing(~str),
|
||||
option_duplicated(~str),
|
||||
unexpected_argument(~str),
|
||||
}
|
||||
|
||||
/// Convert a `fail_` enum into an error string
|
||||
fn fail_str(f: fail_) -> str {
|
||||
fn fail_str(f: fail_) -> ~str {
|
||||
ret alt f {
|
||||
argument_missing(nm) { "Argument to option '" + nm + "' missing." }
|
||||
unrecognized_option(nm) { "Unrecognized option: '" + nm + "'." }
|
||||
option_missing(nm) { "Required option '" + nm + "' missing." }
|
||||
argument_missing(nm) {
|
||||
~"Argument to option '" + nm + ~"' missing."
|
||||
}
|
||||
unrecognized_option(nm) { ~"Unrecognized option: '" + nm + ~"'." }
|
||||
option_missing(nm) { ~"Required option '" + nm + ~"' missing." }
|
||||
option_duplicated(nm) {
|
||||
"Option '" + nm + "' given more than once."
|
||||
~"Option '" + nm + ~"' given more than once."
|
||||
}
|
||||
unexpected_argument(nm) {
|
||||
"Option " + nm + " does not take an argument."
|
||||
~"Option " + nm + ~" does not take an argument."
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -187,11 +189,11 @@ type result = result::result<match, fail_>;
|
||||
* `opt_str`, etc. to interrogate results. Returns `err(fail_)` on failure.
|
||||
* Use <fail_str> to get an error message.
|
||||
*/
|
||||
fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
|
||||
fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
||||
let n_opts = vec::len::<opt>(opts);
|
||||
fn f(_x: uint) -> ~[optval] { ret ~[]; }
|
||||
let vals = vec::to_mut(vec::from_fn(n_opts, f));
|
||||
let mut free: ~[str] = ~[];
|
||||
let mut free: ~[~str] = ~[];
|
||||
let l = vec::len(args);
|
||||
let mut i = 0u;
|
||||
while i < l {
|
||||
@ -199,13 +201,13 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
|
||||
let curlen = str::len(cur);
|
||||
if !is_arg(cur) {
|
||||
vec::push(free, cur);
|
||||
} else if str::eq(cur, "--") {
|
||||
} else if str::eq(cur, ~"--") {
|
||||
let mut j = i + 1u;
|
||||
while j < l { vec::push(free, args[j]); j += 1u; }
|
||||
break;
|
||||
} else {
|
||||
let mut names;
|
||||
let mut i_arg = option::none::<str>;
|
||||
let mut i_arg = option::none::<~str>;
|
||||
if cur[1] == '-' as u8 {
|
||||
let tail = str::slice(cur, 2u, curlen);
|
||||
let tail_eq = str::splitn_char(tail, '=', 1u);
|
||||
@ -215,7 +217,7 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
|
||||
names =
|
||||
~[long(tail_eq[0])];
|
||||
i_arg =
|
||||
option::some::<str>(tail_eq[1]);
|
||||
option::some::<~str>(tail_eq[1]);
|
||||
}
|
||||
} else {
|
||||
let mut j = 1u;
|
||||
@ -264,13 +266,13 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
|
||||
};
|
||||
alt opts[optid].hasarg {
|
||||
no {
|
||||
if !option::is_none::<str>(i_arg) {
|
||||
if !option::is_none::<~str>(i_arg) {
|
||||
ret err(unexpected_argument(name_str(nm)));
|
||||
}
|
||||
vec::push(vals[optid], given);
|
||||
}
|
||||
maybe {
|
||||
if !option::is_none::<str>(i_arg) {
|
||||
if !option::is_none::<~str>(i_arg) {
|
||||
vec::push(vals[optid], val(option::get(i_arg)));
|
||||
} else if name_pos < vec::len::<name>(names) ||
|
||||
i + 1u == l || is_arg(args[i + 1u]) {
|
||||
@ -278,9 +280,9 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
|
||||
} else { i += 1u; vec::push(vals[optid], val(args[i])); }
|
||||
}
|
||||
yes {
|
||||
if !option::is_none::<str>(i_arg) {
|
||||
if !option::is_none::<~str>(i_arg) {
|
||||
vec::push(vals[optid],
|
||||
val(option::get::<str>(i_arg)));
|
||||
val(option::get::<~str>(i_arg)));
|
||||
} else if i + 1u == l {
|
||||
ret err(argument_missing(name_str(nm)));
|
||||
} else { i += 1u; vec::push(vals[optid], val(args[i])); }
|
||||
@ -309,22 +311,22 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
|
||||
ret ok({opts: opts, vals: vec::from_mut(vals), free: free});
|
||||
}
|
||||
|
||||
fn opt_vals(m: match, nm: str) -> ~[optval] {
|
||||
fn opt_vals(m: match, nm: ~str) -> ~[optval] {
|
||||
ret alt find_opt(m.opts, mkname(nm)) {
|
||||
some(id) { m.vals[id] }
|
||||
none { #error("No option '%s' defined", nm); fail }
|
||||
};
|
||||
}
|
||||
|
||||
fn opt_val(m: match, nm: str) -> optval { ret opt_vals(m, nm)[0]; }
|
||||
fn opt_val(m: match, nm: ~str) -> optval { ret opt_vals(m, nm)[0]; }
|
||||
|
||||
/// Returns true if an option was matched
|
||||
fn opt_present(m: match, nm: str) -> bool {
|
||||
fn opt_present(m: match, nm: ~str) -> bool {
|
||||
ret vec::len::<optval>(opt_vals(m, nm)) > 0u;
|
||||
}
|
||||
|
||||
/// Returns true if any of several options were matched
|
||||
fn opts_present(m: match, names: ~[str]) -> bool {
|
||||
fn opts_present(m: match, names: ~[~str]) -> bool {
|
||||
for vec::each(names) |nm| {
|
||||
alt find_opt(m.opts, mkname(nm)) {
|
||||
some(_) { ret true; }
|
||||
@ -341,7 +343,7 @@ fn opts_present(m: match, names: ~[str]) -> bool {
|
||||
* Fails if the option was not matched or if the match did not take an
|
||||
* argument
|
||||
*/
|
||||
fn opt_str(m: match, nm: str) -> str {
|
||||
fn opt_str(m: match, nm: ~str) -> ~str {
|
||||
ret alt opt_val(m, nm) { val(s) { s } _ { fail } };
|
||||
}
|
||||
|
||||
@ -351,7 +353,7 @@ fn opt_str(m: match, nm: str) -> str {
|
||||
* Fails if the no option was provided from the given list, or if the no such
|
||||
* option took an argument
|
||||
*/
|
||||
fn opts_str(m: match, names: ~[str]) -> str {
|
||||
fn opts_str(m: match, names: ~[~str]) -> ~str {
|
||||
for vec::each(names) |nm| {
|
||||
alt opt_val(m, nm) {
|
||||
val(s) { ret s }
|
||||
@ -368,8 +370,8 @@ fn opts_str(m: match, names: ~[str]) -> str {
|
||||
*
|
||||
* Used when an option accepts multiple values.
|
||||
*/
|
||||
fn opt_strs(m: match, nm: str) -> ~[str] {
|
||||
let mut acc: ~[str] = ~[];
|
||||
fn opt_strs(m: match, nm: ~str) -> ~[~str] {
|
||||
let mut acc: ~[~str] = ~[];
|
||||
for vec::each(opt_vals(m, nm)) |v| {
|
||||
alt v { val(s) { vec::push(acc, s); } _ { } }
|
||||
}
|
||||
@ -377,10 +379,10 @@ fn opt_strs(m: match, nm: str) -> ~[str] {
|
||||
}
|
||||
|
||||
/// Returns the string argument supplied to a matching option or none
|
||||
fn opt_maybe_str(m: match, nm: str) -> option<str> {
|
||||
fn opt_maybe_str(m: match, nm: ~str) -> option<~str> {
|
||||
let vals = opt_vals(m, nm);
|
||||
if vec::len::<optval>(vals) == 0u { ret none::<str>; }
|
||||
ret alt vals[0] { val(s) { some::<str>(s) } _ { none::<str> } };
|
||||
if vec::len::<optval>(vals) == 0u { ret none::<~str>; }
|
||||
ret alt vals[0] { val(s) { some::<~str>(s) } _ { none::<~str> } };
|
||||
}
|
||||
|
||||
|
||||
@ -391,10 +393,10 @@ fn opt_maybe_str(m: match, nm: str) -> option<str> {
|
||||
* present but no argument was provided, and the argument if the option was
|
||||
* present and an argument was provided.
|
||||
*/
|
||||
fn opt_default(m: match, nm: str, def: str) -> option<str> {
|
||||
fn opt_default(m: match, nm: ~str, def: ~str) -> option<~str> {
|
||||
let vals = opt_vals(m, nm);
|
||||
if vec::len::<optval>(vals) == 0u { ret none::<str>; }
|
||||
ret alt vals[0] { val(s) { some::<str>(s) } _ { some::<str>(def) } }
|
||||
if vec::len::<optval>(vals) == 0u { ret none::<~str>; }
|
||||
ret alt vals[0] { val(s) { some::<~str>(s) } _ { some::<~str>(def) } }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -424,21 +426,21 @@ mod tests {
|
||||
// Tests for reqopt
|
||||
#[test]
|
||||
fn test_reqopt_long() {
|
||||
let args = ~["--test=20"];
|
||||
let opts = ~[reqopt("test")];
|
||||
let args = ~[~"--test=20"];
|
||||
let opts = ~[reqopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt check rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "test"));
|
||||
assert (opt_str(m, "test") == "20");
|
||||
assert (opt_present(m, ~"test"));
|
||||
assert (opt_str(m, ~"test") == ~"20");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_long_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[reqopt("test")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[reqopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_missing_); }
|
||||
@ -448,8 +450,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_long_no_arg() {
|
||||
let args = ~["--test"];
|
||||
let opts = ~[reqopt("test")];
|
||||
let args = ~[~"--test"];
|
||||
let opts = ~[reqopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, argument_missing_); }
|
||||
@ -459,8 +461,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_long_multi() {
|
||||
let args = ~["--test=20", "--test=30"];
|
||||
let opts = ~[reqopt("test")];
|
||||
let args = ~[~"--test=20", ~"--test=30"];
|
||||
let opts = ~[reqopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_duplicated_); }
|
||||
@ -470,13 +472,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_short() {
|
||||
let args = ~["-t", "20"];
|
||||
let opts = ~[reqopt("t")];
|
||||
let args = ~[~"-t", ~"20"];
|
||||
let opts = ~[reqopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "t"));
|
||||
assert (opt_str(m, "t") == "20");
|
||||
assert (opt_present(m, ~"t"));
|
||||
assert (opt_str(m, ~"t") == ~"20");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -484,8 +486,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_short_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[reqopt("t")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[reqopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_missing_); }
|
||||
@ -495,8 +497,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_short_no_arg() {
|
||||
let args = ~["-t"];
|
||||
let opts = ~[reqopt("t")];
|
||||
let args = ~[~"-t"];
|
||||
let opts = ~[reqopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, argument_missing_); }
|
||||
@ -506,8 +508,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_reqopt_short_multi() {
|
||||
let args = ~["-t", "20", "-t", "30"];
|
||||
let opts = ~[reqopt("t")];
|
||||
let args = ~[~"-t", ~"20", ~"-t", ~"30"];
|
||||
let opts = ~[reqopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_duplicated_); }
|
||||
@ -519,13 +521,13 @@ mod tests {
|
||||
// Tests for optopt
|
||||
#[test]
|
||||
fn test_optopt_long() {
|
||||
let args = ~["--test=20"];
|
||||
let opts = ~[optopt("test")];
|
||||
let args = ~[~"--test=20"];
|
||||
let opts = ~[optopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "test"));
|
||||
assert (opt_str(m, "test") == "20");
|
||||
assert (opt_present(m, ~"test"));
|
||||
assert (opt_str(m, ~"test") == ~"20");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -533,19 +535,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optopt_long_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[optopt("test")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[optopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (!opt_present(m, "test")); }
|
||||
ok(m) { assert (!opt_present(m, ~"test")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optopt_long_no_arg() {
|
||||
let args = ~["--test"];
|
||||
let opts = ~[optopt("test")];
|
||||
let args = ~[~"--test"];
|
||||
let opts = ~[optopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, argument_missing_); }
|
||||
@ -555,8 +557,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optopt_long_multi() {
|
||||
let args = ~["--test=20", "--test=30"];
|
||||
let opts = ~[optopt("test")];
|
||||
let args = ~[~"--test=20", ~"--test=30"];
|
||||
let opts = ~[optopt(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_duplicated_); }
|
||||
@ -566,13 +568,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optopt_short() {
|
||||
let args = ~["-t", "20"];
|
||||
let opts = ~[optopt("t")];
|
||||
let args = ~[~"-t", ~"20"];
|
||||
let opts = ~[optopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "t"));
|
||||
assert (opt_str(m, "t") == "20");
|
||||
assert (opt_present(m, ~"t"));
|
||||
assert (opt_str(m, ~"t") == ~"20");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -580,19 +582,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optopt_short_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[optopt("t")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[optopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (!opt_present(m, "t")); }
|
||||
ok(m) { assert (!opt_present(m, ~"t")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optopt_short_no_arg() {
|
||||
let args = ~["-t"];
|
||||
let opts = ~[optopt("t")];
|
||||
let args = ~[~"-t"];
|
||||
let opts = ~[optopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, argument_missing_); }
|
||||
@ -602,8 +604,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optopt_short_multi() {
|
||||
let args = ~["-t", "20", "-t", "30"];
|
||||
let opts = ~[optopt("t")];
|
||||
let args = ~[~"-t", ~"20", ~"-t", ~"30"];
|
||||
let opts = ~[optopt(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_duplicated_); }
|
||||
@ -615,30 +617,30 @@ mod tests {
|
||||
// Tests for optflag
|
||||
#[test]
|
||||
fn test_optflag_long() {
|
||||
let args = ~["--test"];
|
||||
let opts = ~[optflag("test")];
|
||||
let args = ~[~"--test"];
|
||||
let opts = ~[optflag(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (opt_present(m, "test")); }
|
||||
ok(m) { assert (opt_present(m, ~"test")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optflag_long_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[optflag("test")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[optflag(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (!opt_present(m, "test")); }
|
||||
ok(m) { assert (!opt_present(m, ~"test")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optflag_long_arg() {
|
||||
let args = ~["--test=20"];
|
||||
let opts = ~[optflag("test")];
|
||||
let args = ~[~"--test=20"];
|
||||
let opts = ~[optflag(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) {
|
||||
@ -651,8 +653,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optflag_long_multi() {
|
||||
let args = ~["--test", "--test"];
|
||||
let opts = ~[optflag("test")];
|
||||
let args = ~[~"--test", ~"--test"];
|
||||
let opts = ~[optflag(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_duplicated_); }
|
||||
@ -662,36 +664,36 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optflag_short() {
|
||||
let args = ~["-t"];
|
||||
let opts = ~[optflag("t")];
|
||||
let args = ~[~"-t"];
|
||||
let opts = ~[optflag(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (opt_present(m, "t")); }
|
||||
ok(m) { assert (opt_present(m, ~"t")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optflag_short_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[optflag("t")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[optflag(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (!opt_present(m, "t")); }
|
||||
ok(m) { assert (!opt_present(m, ~"t")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optflag_short_arg() {
|
||||
let args = ~["-t", "20"];
|
||||
let opts = ~[optflag("t")];
|
||||
let args = ~[~"-t", ~"20"];
|
||||
let opts = ~[optflag(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
// The next variable after the flag is just a free argument
|
||||
|
||||
assert (m.free[0] == "20");
|
||||
assert (m.free[0] == ~"20");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -699,8 +701,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optflag_short_multi() {
|
||||
let args = ~["-t", "-t"];
|
||||
let opts = ~[optflag("t")];
|
||||
let args = ~[~"-t", ~"-t"];
|
||||
let opts = ~[optflag(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, option_duplicated_); }
|
||||
@ -712,13 +714,13 @@ mod tests {
|
||||
// Tests for optmulti
|
||||
#[test]
|
||||
fn test_optmulti_long() {
|
||||
let args = ~["--test=20"];
|
||||
let opts = ~[optmulti("test")];
|
||||
let args = ~[~"--test=20"];
|
||||
let opts = ~[optmulti(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "test"));
|
||||
assert (opt_str(m, "test") == "20");
|
||||
assert (opt_present(m, ~"test"));
|
||||
assert (opt_str(m, ~"test") == ~"20");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -726,19 +728,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_long_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[optmulti("test")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[optmulti(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (!opt_present(m, "test")); }
|
||||
ok(m) { assert (!opt_present(m, ~"test")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_long_no_arg() {
|
||||
let args = ~["--test"];
|
||||
let opts = ~[optmulti("test")];
|
||||
let args = ~[~"--test"];
|
||||
let opts = ~[optmulti(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, argument_missing_); }
|
||||
@ -748,15 +750,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_long_multi() {
|
||||
let args = ~["--test=20", "--test=30"];
|
||||
let opts = ~[optmulti("test")];
|
||||
let args = ~[~"--test=20", ~"--test=30"];
|
||||
let opts = ~[optmulti(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "test"));
|
||||
assert (opt_str(m, "test") == "20");
|
||||
assert (opt_strs(m, "test")[0] == "20");
|
||||
assert (opt_strs(m, "test")[1] == "30");
|
||||
assert (opt_present(m, ~"test"));
|
||||
assert (opt_str(m, ~"test") == ~"20");
|
||||
assert (opt_strs(m, ~"test")[0] == ~"20");
|
||||
assert (opt_strs(m, ~"test")[1] == ~"30");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -764,13 +766,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_short() {
|
||||
let args = ~["-t", "20"];
|
||||
let opts = ~[optmulti("t")];
|
||||
let args = ~[~"-t", ~"20"];
|
||||
let opts = ~[optmulti(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "t"));
|
||||
assert (opt_str(m, "t") == "20");
|
||||
assert (opt_present(m, ~"t"));
|
||||
assert (opt_str(m, ~"t") == ~"20");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -778,19 +780,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_short_missing() {
|
||||
let args = ~["blah"];
|
||||
let opts = ~[optmulti("t")];
|
||||
let args = ~[~"blah"];
|
||||
let opts = ~[optmulti(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) { assert (!opt_present(m, "t")); }
|
||||
ok(m) { assert (!opt_present(m, ~"t")); }
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_short_no_arg() {
|
||||
let args = ~["-t"];
|
||||
let opts = ~[optmulti("t")];
|
||||
let args = ~[~"-t"];
|
||||
let opts = ~[optmulti(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, argument_missing_); }
|
||||
@ -800,15 +802,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_optmulti_short_multi() {
|
||||
let args = ~["-t", "20", "-t", "30"];
|
||||
let opts = ~[optmulti("t")];
|
||||
let args = ~[~"-t", ~"20", ~"-t", ~"30"];
|
||||
let opts = ~[optmulti(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (opt_present(m, "t"));
|
||||
assert (opt_str(m, "t") == "20");
|
||||
assert (opt_strs(m, "t")[0] == "20");
|
||||
assert (opt_strs(m, "t")[1] == "30");
|
||||
assert (opt_present(m, ~"t"));
|
||||
assert (opt_str(m, ~"t") == ~"20");
|
||||
assert (opt_strs(m, ~"t")[0] == ~"20");
|
||||
assert (opt_strs(m, ~"t")[1] == ~"30");
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -816,8 +818,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_unrecognized_option_long() {
|
||||
let args = ~["--untest"];
|
||||
let opts = ~[optmulti("t")];
|
||||
let args = ~[~"--untest"];
|
||||
let opts = ~[optmulti(~"t")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, unrecognized_option_); }
|
||||
@ -827,8 +829,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_unrecognized_option_short() {
|
||||
let args = ~["-t"];
|
||||
let opts = ~[optmulti("test")];
|
||||
let args = ~[~"-t"];
|
||||
let opts = ~[optmulti(~"test")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
err(f) { check_fail_type(f, unrecognized_option_); }
|
||||
@ -839,27 +841,28 @@ mod tests {
|
||||
#[test]
|
||||
fn test_combined() {
|
||||
let args =
|
||||
~["prog", "free1", "-s", "20", "free2", "--flag", "--long=30",
|
||||
"-f", "-m", "40", "-m", "50", "-n", "-A B", "-n", "-60 70"];
|
||||
~[~"prog", ~"free1", ~"-s", ~"20", ~"free2",
|
||||
~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40",
|
||||
~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70"];
|
||||
let opts =
|
||||
~[optopt("s"), optflag("flag"), reqopt("long"),
|
||||
optflag("f"), optmulti("m"), optmulti("n"),
|
||||
optopt("notpresent")];
|
||||
~[optopt(~"s"), optflag(~"flag"), reqopt(~"long"),
|
||||
optflag(~"f"), optmulti(~"m"), optmulti(~"n"),
|
||||
optopt(~"notpresent")];
|
||||
let rs = getopts(args, opts);
|
||||
alt rs {
|
||||
ok(m) {
|
||||
assert (m.free[0] == "prog");
|
||||
assert (m.free[1] == "free1");
|
||||
assert (opt_str(m, "s") == "20");
|
||||
assert (m.free[2] == "free2");
|
||||
assert (opt_present(m, "flag"));
|
||||
assert (opt_str(m, "long") == "30");
|
||||
assert (opt_present(m, "f"));
|
||||
assert (opt_strs(m, "m")[0] == "40");
|
||||
assert (opt_strs(m, "m")[1] == "50");
|
||||
assert (opt_strs(m, "n")[0] == "-A B");
|
||||
assert (opt_strs(m, "n")[1] == "-60 70");
|
||||
assert (!opt_present(m, "notpresent"));
|
||||
assert (m.free[0] == ~"prog");
|
||||
assert (m.free[1] == ~"free1");
|
||||
assert (opt_str(m, ~"s") == ~"20");
|
||||
assert (m.free[2] == ~"free2");
|
||||
assert (opt_present(m, ~"flag"));
|
||||
assert (opt_str(m, ~"long") == ~"30");
|
||||
assert (opt_present(m, ~"f"));
|
||||
assert (opt_strs(m, ~"m")[0] == ~"40");
|
||||
assert (opt_strs(m, ~"m")[1] == ~"50");
|
||||
assert (opt_strs(m, ~"n")[0] == ~"-A B");
|
||||
assert (opt_strs(m, ~"n")[1] == ~"-60 70");
|
||||
assert (!opt_present(m, ~"notpresent"));
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
@ -867,35 +870,35 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_multi() {
|
||||
let args = ~["-e", "foo", "--encrypt", "foo"];
|
||||
let opts = ~[optopt("e"), optopt("encrypt")];
|
||||
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
|
||||
let opts = ~[optopt(~"e"), optopt(~"encrypt")];
|
||||
let match = alt getopts(args, opts) {
|
||||
result::ok(m) { m }
|
||||
result::err(f) { fail; }
|
||||
};
|
||||
assert opts_present(match, ~["e"]);
|
||||
assert opts_present(match, ~["encrypt"]);
|
||||
assert opts_present(match, ~["encrypt", "e"]);
|
||||
assert opts_present(match, ~["e", "encrypt"]);
|
||||
assert !opts_present(match, ~["thing"]);
|
||||
assert opts_present(match, ~[~"e"]);
|
||||
assert opts_present(match, ~[~"encrypt"]);
|
||||
assert opts_present(match, ~[~"encrypt", ~"e"]);
|
||||
assert opts_present(match, ~[~"e", ~"encrypt"]);
|
||||
assert !opts_present(match, ~[~"thing"]);
|
||||
assert !opts_present(match, ~[]);
|
||||
|
||||
assert opts_str(match, ~["e"]) == "foo";
|
||||
assert opts_str(match, ~["encrypt"]) == "foo";
|
||||
assert opts_str(match, ~["e", "encrypt"]) == "foo";
|
||||
assert opts_str(match, ~["encrypt", "e"]) == "foo";
|
||||
assert opts_str(match, ~[~"e"]) == ~"foo";
|
||||
assert opts_str(match, ~[~"encrypt"]) == ~"foo";
|
||||
assert opts_str(match, ~[~"e", ~"encrypt"]) == ~"foo";
|
||||
assert opts_str(match, ~[~"encrypt", ~"e"]) == ~"foo";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nospace() {
|
||||
let args = ~["-Lfoo"];
|
||||
let opts = ~[optmulti("L")];
|
||||
let args = ~[~"-Lfoo"];
|
||||
let opts = ~[optmulti(~"L")];
|
||||
let match = alt getopts(args, opts) {
|
||||
result::ok(m) { m }
|
||||
result::err(f) { fail; }
|
||||
};
|
||||
assert opts_present(match, ~["L"]);
|
||||
assert opts_str(match, ~["L"]) == "foo";
|
||||
assert opts_present(match, ~[~"L"]);
|
||||
assert opts_str(match, ~[~"L"]) == ~"foo";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,17 +29,17 @@ export null;
|
||||
/// Represents a json value
|
||||
enum json {
|
||||
num(float),
|
||||
string(@str/~),
|
||||
string(@~str),
|
||||
boolean(bool),
|
||||
list(@~[json]),
|
||||
dict(map::hashmap<str, json>),
|
||||
dict(map::hashmap<~str, json>),
|
||||
null,
|
||||
}
|
||||
|
||||
type error = {
|
||||
line: uint,
|
||||
col: uint,
|
||||
msg: @str/~,
|
||||
msg: @~str,
|
||||
};
|
||||
|
||||
/// Serializes a json value into a io::writer
|
||||
@ -50,14 +50,14 @@ fn to_writer(wr: io::writer, j: json) {
|
||||
wr.write_str(escape_str(*s));
|
||||
}
|
||||
boolean(b) {
|
||||
wr.write_str(if b { "true" } else { "false" });
|
||||
wr.write_str(if b { ~"true" } else { ~"false" });
|
||||
}
|
||||
list(v) {
|
||||
wr.write_char('[');
|
||||
let mut first = true;
|
||||
for (*v).each |item| {
|
||||
if !first {
|
||||
wr.write_str(", ");
|
||||
wr.write_str(~", ");
|
||||
}
|
||||
first = false;
|
||||
to_writer(wr, item);
|
||||
@ -66,51 +66,51 @@ fn to_writer(wr: io::writer, j: json) {
|
||||
}
|
||||
dict(d) {
|
||||
if d.size() == 0u {
|
||||
wr.write_str("{}");
|
||||
wr.write_str(~"{}");
|
||||
ret;
|
||||
}
|
||||
|
||||
wr.write_str("{ ");
|
||||
wr.write_str(~"{ ");
|
||||
let mut first = true;
|
||||
for d.each |key, value| {
|
||||
if !first {
|
||||
wr.write_str(", ");
|
||||
wr.write_str(~", ");
|
||||
}
|
||||
first = false;
|
||||
wr.write_str(escape_str(key));
|
||||
wr.write_str(": ");
|
||||
wr.write_str(~": ");
|
||||
to_writer(wr, value);
|
||||
};
|
||||
wr.write_str(" }");
|
||||
wr.write_str(~" }");
|
||||
}
|
||||
null {
|
||||
wr.write_str("null");
|
||||
wr.write_str(~"null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn escape_str(s: str) -> str {
|
||||
let mut escaped = "\"";
|
||||
fn escape_str(s: ~str) -> ~str {
|
||||
let mut escaped = ~"\"";
|
||||
do str::chars_iter(s) |c| {
|
||||
alt c {
|
||||
'"' { escaped += "\\\""; }
|
||||
'\\' { escaped += "\\\\"; }
|
||||
'\x08' { escaped += "\\b"; }
|
||||
'\x0c' { escaped += "\\f"; }
|
||||
'\n' { escaped += "\\n"; }
|
||||
'\r' { escaped += "\\r"; }
|
||||
'\t' { escaped += "\\t"; }
|
||||
'"' { escaped += ~"\\\""; }
|
||||
'\\' { escaped += ~"\\\\"; }
|
||||
'\x08' { escaped += ~"\\b"; }
|
||||
'\x0c' { escaped += ~"\\f"; }
|
||||
'\n' { escaped += ~"\\n"; }
|
||||
'\r' { escaped += ~"\\r"; }
|
||||
'\t' { escaped += ~"\\t"; }
|
||||
_ { escaped += str::from_char(c); }
|
||||
}
|
||||
};
|
||||
|
||||
escaped += "\"";
|
||||
escaped += ~"\"";
|
||||
|
||||
escaped
|
||||
}
|
||||
|
||||
/// Serializes a json value into a string
|
||||
fn to_str(j: json) -> str {
|
||||
fn to_str(j: json) -> ~str {
|
||||
io::with_str_writer(|wr| to_writer(wr, j))
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ impl parser for parser {
|
||||
self.ch
|
||||
}
|
||||
|
||||
fn error<T>(+msg: str) -> result<T, error> {
|
||||
fn error<T>(+msg: ~str) -> result<T, error> {
|
||||
err({ line: self.line, col: self.col, msg: @msg })
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ impl parser for parser {
|
||||
if self.eof() {
|
||||
ok(value)
|
||||
} else {
|
||||
self.error("trailing characters")
|
||||
self.error(~"trailing characters")
|
||||
}
|
||||
}
|
||||
e { e }
|
||||
@ -163,12 +163,12 @@ impl parser for parser {
|
||||
fn parse_value() -> result<json, error> {
|
||||
self.parse_whitespace();
|
||||
|
||||
if self.eof() { ret self.error("EOF while parsing value"); }
|
||||
if self.eof() { ret self.error(~"EOF while parsing value"); }
|
||||
|
||||
alt self.ch {
|
||||
'n' { self.parse_ident("ull", null) }
|
||||
't' { self.parse_ident("rue", boolean(true)) }
|
||||
'f' { self.parse_ident("alse", boolean(false)) }
|
||||
'n' { self.parse_ident(~"ull", null) }
|
||||
't' { self.parse_ident(~"rue", boolean(true)) }
|
||||
'f' { self.parse_ident(~"alse", boolean(false)) }
|
||||
'0' to '9' | '-' { self.parse_number() }
|
||||
'"' {
|
||||
alt self.parse_str() {
|
||||
@ -178,7 +178,7 @@ impl parser for parser {
|
||||
}
|
||||
'[' { self.parse_list() }
|
||||
'{' { self.parse_object() }
|
||||
_ { self.error("invalid syntax") }
|
||||
_ { self.error(~"invalid syntax") }
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,12 +186,12 @@ impl parser for parser {
|
||||
while char::is_whitespace(self.ch) { self.bump(); }
|
||||
}
|
||||
|
||||
fn parse_ident(ident: str, value: json) -> result<json, error> {
|
||||
fn parse_ident(ident: ~str, value: json) -> result<json, error> {
|
||||
if str::all(ident, |c| c == self.next_char()) {
|
||||
self.bump();
|
||||
ok(value)
|
||||
} else {
|
||||
self.error("invalid syntax")
|
||||
self.error(~"invalid syntax")
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ impl parser for parser {
|
||||
|
||||
// There can be only one leading '0'.
|
||||
alt self.ch {
|
||||
'0' to '9' { ret self.error("invalid number"); }
|
||||
'0' to '9' { ret self.error(~"invalid number"); }
|
||||
_ {}
|
||||
}
|
||||
}
|
||||
@ -251,7 +251,7 @@ impl parser for parser {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ { ret self.error("invalid number"); }
|
||||
_ { ret self.error(~"invalid number"); }
|
||||
}
|
||||
|
||||
ok(res)
|
||||
@ -263,7 +263,7 @@ impl parser for parser {
|
||||
// Make sure a digit follows the decimal place.
|
||||
alt self.ch {
|
||||
'0' to '9' {}
|
||||
_ { ret self.error("invalid number"); }
|
||||
_ { ret self.error(~"invalid number"); }
|
||||
}
|
||||
|
||||
let mut res = res;
|
||||
@ -299,7 +299,7 @@ impl parser for parser {
|
||||
// Make sure a digit follows the exponent place.
|
||||
alt self.ch {
|
||||
'0' to '9' {}
|
||||
_ { ret self.error("invalid number"); }
|
||||
_ { ret self.error(~"invalid number"); }
|
||||
}
|
||||
|
||||
while !self.eof() {
|
||||
@ -324,9 +324,9 @@ impl parser for parser {
|
||||
ok(res)
|
||||
}
|
||||
|
||||
fn parse_str() -> result<@str/~, error> {
|
||||
fn parse_str() -> result<@~str, error> {
|
||||
let mut escape = false;
|
||||
let mut res = "";
|
||||
let mut res = ~"";
|
||||
|
||||
while !self.eof() {
|
||||
self.bump();
|
||||
@ -351,19 +351,19 @@ impl parser for parser {
|
||||
n = n * 10u +
|
||||
(self.ch as uint) - ('0' as uint);
|
||||
}
|
||||
_ { ret self.error("invalid \\u escape"); }
|
||||
_ { ret self.error(~"invalid \\u escape"); }
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
// Error out if we didn't parse 4 digits.
|
||||
if i != 4u {
|
||||
ret self.error("invalid \\u escape");
|
||||
ret self.error(~"invalid \\u escape");
|
||||
}
|
||||
|
||||
str::push_char(res, n as char);
|
||||
}
|
||||
_ { ret self.error("invalid escape"); }
|
||||
_ { ret self.error(~"invalid escape"); }
|
||||
}
|
||||
escape = false;
|
||||
} else if self.ch == '\\' {
|
||||
@ -377,7 +377,7 @@ impl parser for parser {
|
||||
}
|
||||
}
|
||||
|
||||
self.error("EOF while parsing string")
|
||||
self.error(~"EOF while parsing string")
|
||||
}
|
||||
|
||||
fn parse_list() -> result<json, error> {
|
||||
@ -399,13 +399,13 @@ impl parser for parser {
|
||||
|
||||
self.parse_whitespace();
|
||||
if self.eof() {
|
||||
ret self.error("EOF while parsing list");
|
||||
ret self.error(~"EOF while parsing list");
|
||||
}
|
||||
|
||||
alt self.ch {
|
||||
',' { self.bump(); }
|
||||
']' { self.bump(); ret ok(list(@values)); }
|
||||
_ { ret self.error("expected `,` or `]`"); }
|
||||
_ { ret self.error(~"expected `,` or `]`"); }
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -425,7 +425,7 @@ impl parser for parser {
|
||||
self.parse_whitespace();
|
||||
|
||||
if self.ch != '"' {
|
||||
ret self.error("key must be a string");
|
||||
ret self.error(~"key must be a string");
|
||||
}
|
||||
|
||||
let key = alt self.parse_str() {
|
||||
@ -437,7 +437,7 @@ impl parser for parser {
|
||||
|
||||
if self.ch != ':' {
|
||||
if self.eof() { break; }
|
||||
ret self.error("expected `:`");
|
||||
ret self.error(~"expected `:`");
|
||||
}
|
||||
self.bump();
|
||||
|
||||
@ -452,12 +452,12 @@ impl parser for parser {
|
||||
'}' { self.bump(); ret ok(dict(values)); }
|
||||
_ {
|
||||
if self.eof() { break; }
|
||||
ret self.error("expected `,` or `}`");
|
||||
ret self.error(~"expected `,` or `}`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret self.error("EOF while parsing object");
|
||||
ret self.error(~"EOF while parsing object");
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,7 +474,7 @@ fn from_reader(rdr: io::reader) -> result<json, error> {
|
||||
}
|
||||
|
||||
/// Deserializes a json value from a string
|
||||
fn from_str(s: str) -> result<json, error> {
|
||||
fn from_str(s: ~str) -> result<json, error> {
|
||||
io::with_str_reader(s, from_reader)
|
||||
}
|
||||
|
||||
@ -575,11 +575,11 @@ impl of to_json for bool {
|
||||
fn to_json() -> json { boolean(self) }
|
||||
}
|
||||
|
||||
impl of to_json for str {
|
||||
impl of to_json for ~str {
|
||||
fn to_json() -> json { string(@copy self) }
|
||||
}
|
||||
|
||||
impl of to_json for @str/~ {
|
||||
impl of to_json for @~str {
|
||||
fn to_json() -> json { string(self) }
|
||||
}
|
||||
|
||||
@ -602,7 +602,7 @@ impl <A: to_json> of to_json for ~[A] {
|
||||
fn to_json() -> json { list(@self.map(|elt| elt.to_json())) }
|
||||
}
|
||||
|
||||
impl <A: to_json copy> of to_json for hashmap<str, A> {
|
||||
impl <A: to_json copy> of to_json for hashmap<~str, A> {
|
||||
fn to_json() -> json {
|
||||
let d = map::str_hash();
|
||||
for self.each() |key, value| {
|
||||
@ -622,18 +622,18 @@ impl <A: to_json> of to_json for option<A> {
|
||||
}
|
||||
|
||||
impl of to_str::to_str for json {
|
||||
fn to_str() -> str { to_str(self) }
|
||||
fn to_str() -> ~str { to_str(self) }
|
||||
}
|
||||
|
||||
impl of to_str::to_str for error {
|
||||
fn to_str() -> str {
|
||||
fn to_str() -> ~str {
|
||||
#fmt("%u:%u: %s", self.line, self.col, *self.msg)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
fn mk_dict(items: ~[(str, json)]) -> json {
|
||||
fn mk_dict(items: ~[(~str, json)]) -> json {
|
||||
let d = map::str_hash();
|
||||
|
||||
do vec::iter(items) |item| {
|
||||
@ -646,229 +646,230 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_write_null() {
|
||||
assert to_str(null) == "null";
|
||||
assert to_str(null) == ~"null";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_num() {
|
||||
assert to_str(num(3f)) == "3";
|
||||
assert to_str(num(3.1f)) == "3.1";
|
||||
assert to_str(num(-1.5f)) == "-1.5";
|
||||
assert to_str(num(0.5f)) == "0.5";
|
||||
assert to_str(num(3f)) == ~"3";
|
||||
assert to_str(num(3.1f)) == ~"3.1";
|
||||
assert to_str(num(-1.5f)) == ~"-1.5";
|
||||
assert to_str(num(0.5f)) == ~"0.5";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_str() {
|
||||
assert to_str(string(@""/~)) == "\"\""/~;
|
||||
assert to_str(string(@"foo"/~)) == "\"foo\""/~;
|
||||
assert to_str(string(@~"")) == ~"\"\"";
|
||||
assert to_str(string(@~"foo")) == ~"\"foo\"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_bool() {
|
||||
assert to_str(boolean(true)) == "true";
|
||||
assert to_str(boolean(false)) == "false";
|
||||
assert to_str(boolean(true)) == ~"true";
|
||||
assert to_str(boolean(false)) == ~"false";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_list() {
|
||||
assert to_str(list(@~[])) == "[]";
|
||||
assert to_str(list(@~[boolean(true)])) == "[true]";
|
||||
assert to_str(list(@~[])) == ~"[]";
|
||||
assert to_str(list(@~[boolean(true)])) == ~"[true]";
|
||||
assert to_str(list(@~[
|
||||
boolean(false),
|
||||
null,
|
||||
list(@~[string(@"foo\nbar"/~), num(3.5f)])
|
||||
])) == "[false, null, [\"foo\\nbar\", 3.5]]";
|
||||
list(@~[string(@~"foo\nbar"), num(3.5f)])
|
||||
])) == ~"[false, null, [\"foo\\nbar\", 3.5]]";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_dict() {
|
||||
assert to_str(mk_dict(~[])) == "{}";
|
||||
assert to_str(mk_dict(~[("a", boolean(true))])) == "{ \"a\": true }";
|
||||
assert to_str(mk_dict(~[])) == ~"{}";
|
||||
assert to_str(mk_dict(~[(~"a", boolean(true))]))
|
||||
== ~"{ \"a\": true }";
|
||||
assert to_str(mk_dict(~[
|
||||
("a", boolean(true)),
|
||||
("b", list(@~[
|
||||
mk_dict(~[("c", string(@"\x0c\r"/~))]),
|
||||
mk_dict(~[("d", string(@""/~))])
|
||||
(~"a", boolean(true)),
|
||||
(~"b", list(@~[
|
||||
mk_dict(~[(~"c", string(@~"\x0c\r"))]),
|
||||
mk_dict(~[(~"d", string(@~""))])
|
||||
]))
|
||||
])) ==
|
||||
"{ " +
|
||||
"\"a\": true, " +
|
||||
"\"b\": [" +
|
||||
"{ \"c\": \"\\f\\r\" }, " +
|
||||
"{ \"d\": \"\" }" +
|
||||
"]" +
|
||||
" }";
|
||||
~"{ " +
|
||||
~"\"a\": true, " +
|
||||
~"\"b\": [" +
|
||||
~"{ \"c\": \"\\f\\r\" }, " +
|
||||
~"{ \"d\": \"\" }" +
|
||||
~"]" +
|
||||
~" }";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_characters() {
|
||||
assert from_str("nulla") ==
|
||||
err({line: 1u, col: 5u, msg: @"trailing characters"/~});
|
||||
assert from_str("truea") ==
|
||||
err({line: 1u, col: 5u, msg: @"trailing characters"/~});
|
||||
assert from_str("falsea") ==
|
||||
err({line: 1u, col: 6u, msg: @"trailing characters"/~});
|
||||
assert from_str("1a") ==
|
||||
err({line: 1u, col: 2u, msg: @"trailing characters"/~});
|
||||
assert from_str("[]a") ==
|
||||
err({line: 1u, col: 3u, msg: @"trailing characters"/~});
|
||||
assert from_str("{}a") ==
|
||||
err({line: 1u, col: 3u, msg: @"trailing characters"/~});
|
||||
assert from_str(~"nulla") ==
|
||||
err({line: 1u, col: 5u, msg: @~"trailing characters"});
|
||||
assert from_str(~"truea") ==
|
||||
err({line: 1u, col: 5u, msg: @~"trailing characters"});
|
||||
assert from_str(~"falsea") ==
|
||||
err({line: 1u, col: 6u, msg: @~"trailing characters"});
|
||||
assert from_str(~"1a") ==
|
||||
err({line: 1u, col: 2u, msg: @~"trailing characters"});
|
||||
assert from_str(~"[]a") ==
|
||||
err({line: 1u, col: 3u, msg: @~"trailing characters"});
|
||||
assert from_str(~"{}a") ==
|
||||
err({line: 1u, col: 3u, msg: @~"trailing characters"});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_identifiers() {
|
||||
assert from_str("n") ==
|
||||
err({line: 1u, col: 2u, msg: @"invalid syntax"/~});
|
||||
assert from_str("nul") ==
|
||||
err({line: 1u, col: 4u, msg: @"invalid syntax"/~});
|
||||
assert from_str(~"n") ==
|
||||
err({line: 1u, col: 2u, msg: @~"invalid syntax"});
|
||||
assert from_str(~"nul") ==
|
||||
err({line: 1u, col: 4u, msg: @~"invalid syntax"});
|
||||
|
||||
assert from_str("t") ==
|
||||
err({line: 1u, col: 2u, msg: @"invalid syntax"/~});
|
||||
assert from_str("truz") ==
|
||||
err({line: 1u, col: 4u, msg: @"invalid syntax"/~});
|
||||
assert from_str(~"t") ==
|
||||
err({line: 1u, col: 2u, msg: @~"invalid syntax"});
|
||||
assert from_str(~"truz") ==
|
||||
err({line: 1u, col: 4u, msg: @~"invalid syntax"});
|
||||
|
||||
assert from_str("f") ==
|
||||
err({line: 1u, col: 2u, msg: @"invalid syntax"/~});
|
||||
assert from_str("faz") ==
|
||||
err({line: 1u, col: 3u, msg: @"invalid syntax"/~});
|
||||
assert from_str(~"f") ==
|
||||
err({line: 1u, col: 2u, msg: @~"invalid syntax"});
|
||||
assert from_str(~"faz") ==
|
||||
err({line: 1u, col: 3u, msg: @~"invalid syntax"});
|
||||
|
||||
assert from_str("null") == ok(null);
|
||||
assert from_str("true") == ok(boolean(true));
|
||||
assert from_str("false") == ok(boolean(false));
|
||||
assert from_str(" null ") == ok(null);
|
||||
assert from_str(" true ") == ok(boolean(true));
|
||||
assert from_str(" false ") == ok(boolean(false));
|
||||
assert from_str(~"null") == ok(null);
|
||||
assert from_str(~"true") == ok(boolean(true));
|
||||
assert from_str(~"false") == ok(boolean(false));
|
||||
assert from_str(~" null ") == ok(null);
|
||||
assert from_str(~" true ") == ok(boolean(true));
|
||||
assert from_str(~" false ") == ok(boolean(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_num() {
|
||||
assert from_str("+") ==
|
||||
err({line: 1u, col: 1u, msg: @"invalid syntax"/~});
|
||||
assert from_str(".") ==
|
||||
err({line: 1u, col: 1u, msg: @"invalid syntax"/~});
|
||||
assert from_str(~"+") ==
|
||||
err({line: 1u, col: 1u, msg: @~"invalid syntax"});
|
||||
assert from_str(~".") ==
|
||||
err({line: 1u, col: 1u, msg: @~"invalid syntax"});
|
||||
|
||||
assert from_str("-") ==
|
||||
err({line: 1u, col: 2u, msg: @"invalid number"/~});
|
||||
assert from_str("00") ==
|
||||
err({line: 1u, col: 2u, msg: @"invalid number"/~});
|
||||
assert from_str("1.") ==
|
||||
err({line: 1u, col: 3u, msg: @"invalid number"/~});
|
||||
assert from_str("1e") ==
|
||||
err({line: 1u, col: 3u, msg: @"invalid number"/~});
|
||||
assert from_str("1e+") ==
|
||||
err({line: 1u, col: 4u, msg: @"invalid number"/~});
|
||||
assert from_str(~"-") ==
|
||||
err({line: 1u, col: 2u, msg: @~"invalid number"});
|
||||
assert from_str(~"00") ==
|
||||
err({line: 1u, col: 2u, msg: @~"invalid number"});
|
||||
assert from_str(~"1.") ==
|
||||
err({line: 1u, col: 3u, msg: @~"invalid number"});
|
||||
assert from_str(~"1e") ==
|
||||
err({line: 1u, col: 3u, msg: @~"invalid number"});
|
||||
assert from_str(~"1e+") ==
|
||||
err({line: 1u, col: 4u, msg: @~"invalid number"});
|
||||
|
||||
assert from_str("3") == ok(num(3f));
|
||||
assert from_str("3.1") == ok(num(3.1f));
|
||||
assert from_str("-1.2") == ok(num(-1.2f));
|
||||
assert from_str("0.4") == ok(num(0.4f));
|
||||
assert from_str("0.4e5") == ok(num(0.4e5f));
|
||||
assert from_str("0.4e+15") == ok(num(0.4e15f));
|
||||
assert from_str("0.4e-01") == ok(num(0.4e-01f));
|
||||
assert from_str(" 3 ") == ok(num(3f));
|
||||
assert from_str(~"3") == ok(num(3f));
|
||||
assert from_str(~"3.1") == ok(num(3.1f));
|
||||
assert from_str(~"-1.2") == ok(num(-1.2f));
|
||||
assert from_str(~"0.4") == ok(num(0.4f));
|
||||
assert from_str(~"0.4e5") == ok(num(0.4e5f));
|
||||
assert from_str(~"0.4e+15") == ok(num(0.4e15f));
|
||||
assert from_str(~"0.4e-01") == ok(num(0.4e-01f));
|
||||
assert from_str(~" 3 ") == ok(num(3f));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_str() {
|
||||
assert from_str("\"") ==
|
||||
err({line: 1u, col: 2u, msg: @"EOF while parsing string"/~});
|
||||
assert from_str("\"lol") ==
|
||||
err({line: 1u, col: 5u, msg: @"EOF while parsing string"/~});
|
||||
assert from_str(~"\"") ==
|
||||
err({line: 1u, col: 2u, msg: @~"EOF while parsing string"});
|
||||
assert from_str(~"\"lol") ==
|
||||
err({line: 1u, col: 5u, msg: @~"EOF while parsing string"});
|
||||
|
||||
assert from_str("\"\"") == ok(string(@""/~));
|
||||
assert from_str("\"foo\"") == ok(string(@"foo"/~));
|
||||
assert from_str("\"\\\"\"") == ok(string(@"\""/~));
|
||||
assert from_str("\"\\b\"") == ok(string(@"\x08"/~));
|
||||
assert from_str("\"\\n\"") == ok(string(@"\n"/~));
|
||||
assert from_str("\"\\r\"") == ok(string(@"\r"/~));
|
||||
assert from_str("\"\\t\"") == ok(string(@"\t"/~));
|
||||
assert from_str(" \"foo\" ") == ok(string(@"foo"/~));
|
||||
assert from_str(~"\"\"") == ok(string(@~""));
|
||||
assert from_str(~"\"foo\"") == ok(string(@~"foo"));
|
||||
assert from_str(~"\"\\\"\"") == ok(string(@~"\""));
|
||||
assert from_str(~"\"\\b\"") == ok(string(@~"\x08"));
|
||||
assert from_str(~"\"\\n\"") == ok(string(@~"\n"));
|
||||
assert from_str(~"\"\\r\"") == ok(string(@~"\r"));
|
||||
assert from_str(~"\"\\t\"") == ok(string(@~"\t"));
|
||||
assert from_str(~" \"foo\" ") == ok(string(@~"foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_list() {
|
||||
assert from_str("[") ==
|
||||
err({line: 1u, col: 2u, msg: @"EOF while parsing value"/~});
|
||||
assert from_str("[1") ==
|
||||
err({line: 1u, col: 3u, msg: @"EOF while parsing list"/~});
|
||||
assert from_str("[1,") ==
|
||||
err({line: 1u, col: 4u, msg: @"EOF while parsing value"/~});
|
||||
assert from_str("[1,]") ==
|
||||
err({line: 1u, col: 4u, msg: @"invalid syntax"/~});
|
||||
assert from_str("[6 7]") ==
|
||||
err({line: 1u, col: 4u, msg: @"expected `,` or `]`"/~});
|
||||
assert from_str(~"[") ==
|
||||
err({line: 1u, col: 2u, msg: @~"EOF while parsing value"});
|
||||
assert from_str(~"[1") ==
|
||||
err({line: 1u, col: 3u, msg: @~"EOF while parsing list"});
|
||||
assert from_str(~"[1,") ==
|
||||
err({line: 1u, col: 4u, msg: @~"EOF while parsing value"});
|
||||
assert from_str(~"[1,]") ==
|
||||
err({line: 1u, col: 4u, msg: @~"invalid syntax"});
|
||||
assert from_str(~"[6 7]") ==
|
||||
err({line: 1u, col: 4u, msg: @~"expected `,` or `]`"});
|
||||
|
||||
assert from_str("[]") == ok(list(@~[]));
|
||||
assert from_str("[ ]") == ok(list(@~[]));
|
||||
assert from_str("[true]") == ok(list(@~[boolean(true)]));
|
||||
assert from_str("[ false ]") == ok(list(@~[boolean(false)]));
|
||||
assert from_str("[null]") == ok(list(@~[null]));
|
||||
assert from_str("[3, 1]") == ok(list(@~[num(3f), num(1f)]));
|
||||
assert from_str("\n[3, 2]\n") == ok(list(@~[num(3f), num(2f)]));
|
||||
assert from_str("[2, [4, 1]]") ==
|
||||
assert from_str(~"[]") == ok(list(@~[]));
|
||||
assert from_str(~"[ ]") == ok(list(@~[]));
|
||||
assert from_str(~"[true]") == ok(list(@~[boolean(true)]));
|
||||
assert from_str(~"[ false ]") == ok(list(@~[boolean(false)]));
|
||||
assert from_str(~"[null]") == ok(list(@~[null]));
|
||||
assert from_str(~"[3, 1]") == ok(list(@~[num(3f), num(1f)]));
|
||||
assert from_str(~"\n[3, 2]\n") == ok(list(@~[num(3f), num(2f)]));
|
||||
assert from_str(~"[2, [4, 1]]") ==
|
||||
ok(list(@~[num(2f), list(@~[num(4f), num(1f)])]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_dict() {
|
||||
assert from_str("{") ==
|
||||
err({line: 1u, col: 2u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str("{ ") ==
|
||||
err({line: 1u, col: 3u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str("{1") ==
|
||||
err({line: 1u, col: 2u, msg: @"key must be a string"/~});
|
||||
assert from_str("{ \"a\"") ==
|
||||
err({line: 1u, col: 6u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str("{\"a\"") ==
|
||||
err({line: 1u, col: 5u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str("{\"a\" ") ==
|
||||
err({line: 1u, col: 6u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str(~"{") ==
|
||||
err({line: 1u, col: 2u, msg: @~"EOF while parsing object"});
|
||||
assert from_str(~"{ ") ==
|
||||
err({line: 1u, col: 3u, msg: @~"EOF while parsing object"});
|
||||
assert from_str(~"{1") ==
|
||||
err({line: 1u, col: 2u, msg: @~"key must be a string"});
|
||||
assert from_str(~"{ \"a\"") ==
|
||||
err({line: 1u, col: 6u, msg: @~"EOF while parsing object"});
|
||||
assert from_str(~"{\"a\"") ==
|
||||
err({line: 1u, col: 5u, msg: @~"EOF while parsing object"});
|
||||
assert from_str(~"{\"a\" ") ==
|
||||
err({line: 1u, col: 6u, msg: @~"EOF while parsing object"});
|
||||
|
||||
assert from_str("{\"a\" 1") ==
|
||||
err({line: 1u, col: 6u, msg: @"expected `:`"/~});
|
||||
assert from_str("{\"a\":") ==
|
||||
err({line: 1u, col: 6u, msg: @"EOF while parsing value"/~});
|
||||
assert from_str("{\"a\":1") ==
|
||||
err({line: 1u, col: 7u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str("{\"a\":1 1") ==
|
||||
err({line: 1u, col: 8u, msg: @"expected `,` or `}`"/~});
|
||||
assert from_str("{\"a\":1,") ==
|
||||
err({line: 1u, col: 8u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str(~"{\"a\" 1") ==
|
||||
err({line: 1u, col: 6u, msg: @~"expected `:`"});
|
||||
assert from_str(~"{\"a\":") ==
|
||||
err({line: 1u, col: 6u, msg: @~"EOF while parsing value"});
|
||||
assert from_str(~"{\"a\":1") ==
|
||||
err({line: 1u, col: 7u, msg: @~"EOF while parsing object"});
|
||||
assert from_str(~"{\"a\":1 1") ==
|
||||
err({line: 1u, col: 8u, msg: @~"expected `,` or `}`"});
|
||||
assert from_str(~"{\"a\":1,") ==
|
||||
err({line: 1u, col: 8u, msg: @~"EOF while parsing object"});
|
||||
|
||||
assert eq(result::get(from_str("{}")), mk_dict(~[]));
|
||||
assert eq(result::get(from_str("{\"a\": 3}")),
|
||||
mk_dict(~[("a", num(3.0f))]));
|
||||
assert eq(result::get(from_str(~"{}")), mk_dict(~[]));
|
||||
assert eq(result::get(from_str(~"{\"a\": 3}")),
|
||||
mk_dict(~[(~"a", num(3.0f))]));
|
||||
|
||||
assert eq(result::get(from_str("{ \"a\": null, \"b\" : true }")),
|
||||
assert eq(result::get(from_str(~"{ \"a\": null, \"b\" : true }")),
|
||||
mk_dict(~[
|
||||
("a", null),
|
||||
("b", boolean(true))]));
|
||||
assert eq(result::get(from_str("\n{ \"a\": null, \"b\" : true }\n")),
|
||||
(~"a", null),
|
||||
(~"b", boolean(true))]));
|
||||
assert eq(result::get(from_str(~"\n{ \"a\": null, \"b\" : true }\n")),
|
||||
mk_dict(~[
|
||||
("a", null),
|
||||
("b", boolean(true))]));
|
||||
assert eq(result::get(from_str("{\"a\" : 1.0 ,\"b\": [ true ]}")),
|
||||
(~"a", null),
|
||||
(~"b", boolean(true))]));
|
||||
assert eq(result::get(from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")),
|
||||
mk_dict(~[
|
||||
("a", num(1.0)),
|
||||
("b", list(@~[boolean(true)]))
|
||||
(~"a", num(1.0)),
|
||||
(~"b", list(@~[boolean(true)]))
|
||||
]));
|
||||
assert eq(result::get(from_str(
|
||||
"{" +
|
||||
"\"a\": 1.0, " +
|
||||
"\"b\": [" +
|
||||
"true," +
|
||||
"\"foo\\nbar\", " +
|
||||
"{ \"c\": {\"d\": null} } " +
|
||||
"]" +
|
||||
"}")),
|
||||
~"{" +
|
||||
~"\"a\": 1.0, " +
|
||||
~"\"b\": [" +
|
||||
~"true," +
|
||||
~"\"foo\\nbar\", " +
|
||||
~"{ \"c\": {\"d\": null} } " +
|
||||
~"]" +
|
||||
~"}")),
|
||||
mk_dict(~[
|
||||
("a", num(1.0f)),
|
||||
("b", list(@~[
|
||||
(~"a", num(1.0f)),
|
||||
(~"b", list(@~[
|
||||
boolean(true),
|
||||
string(@"foo\nbar"/~),
|
||||
string(@~"foo\nbar"),
|
||||
mk_dict(~[
|
||||
("c", mk_dict(~[("d", null)]))
|
||||
(~"c", mk_dict(~[(~"d", null)]))
|
||||
])
|
||||
]))
|
||||
]));
|
||||
@ -876,7 +877,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_multiline_errors() {
|
||||
assert from_str("{\n \"foo\":\n \"bar\"") ==
|
||||
err({line: 3u, col: 8u, msg: @"EOF while parsing object"/~});
|
||||
assert from_str(~"{\n \"foo\":\n \"bar\"") ==
|
||||
err({line: 3u, col: 8u, msg: @~"EOF while parsing object"});
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ fn len<T>(ls: @list<T>) -> uint {
|
||||
pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
|
||||
alt *ls {
|
||||
cons(_, tl) { ret tl; }
|
||||
nil { fail "list empty" }
|
||||
nil { fail ~"list empty" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ mod chained {
|
||||
}
|
||||
|
||||
fn get(k: K) -> V {
|
||||
self.find(k).expect("Key not found in table")
|
||||
self.find(k).expect(~"Key not found in table")
|
||||
}
|
||||
|
||||
fn [](k: K) -> V {
|
||||
@ -305,13 +305,13 @@ fn hashmap<K: const, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>)
|
||||
}
|
||||
|
||||
/// Construct a hashmap for string keys
|
||||
fn str_hash<V: copy>() -> hashmap<str, V> {
|
||||
fn str_hash<V: copy>() -> hashmap<~str, V> {
|
||||
ret hashmap(str::hash, str::eq);
|
||||
}
|
||||
|
||||
/// Construct a hashmap for boxed string keys
|
||||
fn box_str_hash<V: copy>() -> hashmap<@str/~, V> {
|
||||
ret hashmap(|x: @str/~| str::hash(*x), |x,y| str::eq(*x,*y));
|
||||
fn box_str_hash<V: copy>() -> hashmap<@~str, V> {
|
||||
ret hashmap(|x: @~str| str::hash(*x), |x,y| str::eq(*x,*y));
|
||||
}
|
||||
|
||||
/// Construct a hashmap for byte string keys
|
||||
@ -356,7 +356,7 @@ fn hash_from_vec<K: const copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>,
|
||||
}
|
||||
|
||||
/// Construct a hashmap from a vector with string keys
|
||||
fn hash_from_strs<V: copy>(items: ~[(str, V)]) -> hashmap<str, V> {
|
||||
fn hash_from_strs<V: copy>(items: ~[(~str, V)]) -> hashmap<~str, V> {
|
||||
hash_from_vec(str::hash, str::eq, items)
|
||||
}
|
||||
|
||||
@ -385,8 +385,8 @@ mod tests {
|
||||
fn uint_id(&&x: uint) -> uint { x }
|
||||
let hasher_uint: map::hashfn<uint> = uint_id;
|
||||
let eqer_uint: map::eqfn<uint> = eq_uint;
|
||||
let hasher_str: map::hashfn<str> = str::hash;
|
||||
let eqer_str: map::eqfn<str> = str::eq;
|
||||
let hasher_str: map::hashfn<~str> = str::hash;
|
||||
let eqer_str: map::eqfn<~str> = str::eq;
|
||||
#debug("uint -> uint");
|
||||
let hm_uu: map::hashmap<uint, uint> =
|
||||
map::hashmap::<uint, uint>(hasher_uint, eqer_uint);
|
||||
@ -400,49 +400,49 @@ mod tests {
|
||||
assert (hm_uu.get(12u) == 14u);
|
||||
assert (!hm_uu.insert(12u, 12u));
|
||||
assert (hm_uu.get(12u) == 12u);
|
||||
let ten: str = "ten";
|
||||
let eleven: str = "eleven";
|
||||
let twelve: str = "twelve";
|
||||
let ten: ~str = ~"ten";
|
||||
let eleven: ~str = ~"eleven";
|
||||
let twelve: ~str = ~"twelve";
|
||||
#debug("str -> uint");
|
||||
let hm_su: map::hashmap<str, uint> =
|
||||
map::hashmap::<str, uint>(hasher_str, eqer_str);
|
||||
assert (hm_su.insert("ten", 12u));
|
||||
let hm_su: map::hashmap<~str, uint> =
|
||||
map::hashmap::<~str, uint>(hasher_str, eqer_str);
|
||||
assert (hm_su.insert(~"ten", 12u));
|
||||
assert (hm_su.insert(eleven, 13u));
|
||||
assert (hm_su.insert("twelve", 14u));
|
||||
assert (hm_su.insert(~"twelve", 14u));
|
||||
assert (hm_su.get(eleven) == 13u);
|
||||
assert (hm_su.get("eleven") == 13u);
|
||||
assert (hm_su.get("twelve") == 14u);
|
||||
assert (hm_su.get("ten") == 12u);
|
||||
assert (!hm_su.insert("twelve", 14u));
|
||||
assert (hm_su.get("twelve") == 14u);
|
||||
assert (!hm_su.insert("twelve", 12u));
|
||||
assert (hm_su.get("twelve") == 12u);
|
||||
assert (hm_su.get(~"eleven") == 13u);
|
||||
assert (hm_su.get(~"twelve") == 14u);
|
||||
assert (hm_su.get(~"ten") == 12u);
|
||||
assert (!hm_su.insert(~"twelve", 14u));
|
||||
assert (hm_su.get(~"twelve") == 14u);
|
||||
assert (!hm_su.insert(~"twelve", 12u));
|
||||
assert (hm_su.get(~"twelve") == 12u);
|
||||
#debug("uint -> str");
|
||||
let hm_us: map::hashmap<uint, str> =
|
||||
map::hashmap::<uint, str>(hasher_uint, eqer_uint);
|
||||
assert (hm_us.insert(10u, "twelve"));
|
||||
assert (hm_us.insert(11u, "thirteen"));
|
||||
assert (hm_us.insert(12u, "fourteen"));
|
||||
assert (str::eq(hm_us.get(11u), "thirteen"));
|
||||
assert (str::eq(hm_us.get(12u), "fourteen"));
|
||||
assert (str::eq(hm_us.get(10u), "twelve"));
|
||||
assert (!hm_us.insert(12u, "fourteen"));
|
||||
assert (str::eq(hm_us.get(12u), "fourteen"));
|
||||
assert (!hm_us.insert(12u, "twelve"));
|
||||
assert (str::eq(hm_us.get(12u), "twelve"));
|
||||
let hm_us: map::hashmap<uint, ~str> =
|
||||
map::hashmap::<uint, ~str>(hasher_uint, eqer_uint);
|
||||
assert (hm_us.insert(10u, ~"twelve"));
|
||||
assert (hm_us.insert(11u, ~"thirteen"));
|
||||
assert (hm_us.insert(12u, ~"fourteen"));
|
||||
assert (str::eq(hm_us.get(11u), ~"thirteen"));
|
||||
assert (str::eq(hm_us.get(12u), ~"fourteen"));
|
||||
assert (str::eq(hm_us.get(10u), ~"twelve"));
|
||||
assert (!hm_us.insert(12u, ~"fourteen"));
|
||||
assert (str::eq(hm_us.get(12u), ~"fourteen"));
|
||||
assert (!hm_us.insert(12u, ~"twelve"));
|
||||
assert (str::eq(hm_us.get(12u), ~"twelve"));
|
||||
#debug("str -> str");
|
||||
let hm_ss: map::hashmap<str, str> =
|
||||
map::hashmap::<str, str>(hasher_str, eqer_str);
|
||||
assert (hm_ss.insert(ten, "twelve"));
|
||||
assert (hm_ss.insert(eleven, "thirteen"));
|
||||
assert (hm_ss.insert(twelve, "fourteen"));
|
||||
assert (str::eq(hm_ss.get("eleven"), "thirteen"));
|
||||
assert (str::eq(hm_ss.get("twelve"), "fourteen"));
|
||||
assert (str::eq(hm_ss.get("ten"), "twelve"));
|
||||
assert (!hm_ss.insert("twelve", "fourteen"));
|
||||
assert (str::eq(hm_ss.get("twelve"), "fourteen"));
|
||||
assert (!hm_ss.insert("twelve", "twelve"));
|
||||
assert (str::eq(hm_ss.get("twelve"), "twelve"));
|
||||
let hm_ss: map::hashmap<~str, ~str> =
|
||||
map::hashmap::<~str, ~str>(hasher_str, eqer_str);
|
||||
assert (hm_ss.insert(ten, ~"twelve"));
|
||||
assert (hm_ss.insert(eleven, ~"thirteen"));
|
||||
assert (hm_ss.insert(twelve, ~"fourteen"));
|
||||
assert (str::eq(hm_ss.get(~"eleven"), ~"thirteen"));
|
||||
assert (str::eq(hm_ss.get(~"twelve"), ~"fourteen"));
|
||||
assert (str::eq(hm_ss.get(~"ten"), ~"twelve"));
|
||||
assert (!hm_ss.insert(~"twelve", ~"fourteen"));
|
||||
assert (str::eq(hm_ss.get(~"twelve"), ~"fourteen"));
|
||||
assert (!hm_ss.insert(~"twelve", ~"twelve"));
|
||||
assert (str::eq(hm_ss.get(~"twelve"), ~"twelve"));
|
||||
#debug("*** finished test_simple");
|
||||
}
|
||||
|
||||
@ -484,10 +484,10 @@ mod tests {
|
||||
i += 1u;
|
||||
}
|
||||
#debug("str -> str");
|
||||
let hasher_str: map::hashfn<str> = str::hash;
|
||||
let eqer_str: map::eqfn<str> = str::eq;
|
||||
let hm_ss: map::hashmap<str, str> =
|
||||
map::hashmap::<str, str>(hasher_str, eqer_str);
|
||||
let hasher_str: map::hashfn<~str> = str::hash;
|
||||
let eqer_str: map::eqfn<~str> = str::eq;
|
||||
let hm_ss: map::hashmap<~str, ~str> =
|
||||
map::hashmap::<~str, ~str>(hasher_str, eqer_str);
|
||||
i = 0u;
|
||||
while i < num_to_insert {
|
||||
assert hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u));
|
||||
@ -602,27 +602,27 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_contains_key() {
|
||||
let key = "k";
|
||||
let map = map::hashmap::<str, str>(str::hash, str::eq);
|
||||
let key = ~"k";
|
||||
let map = map::hashmap::<~str, ~str>(str::hash, str::eq);
|
||||
assert (!map.contains_key(key));
|
||||
map.insert(key, "val");
|
||||
map.insert(key, ~"val");
|
||||
assert (map.contains_key(key));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find() {
|
||||
let key = "k";
|
||||
let map = map::hashmap::<str, str>(str::hash, str::eq);
|
||||
let key = ~"k";
|
||||
let map = map::hashmap::<~str, ~str>(str::hash, str::eq);
|
||||
assert (option::is_none(map.find(key)));
|
||||
map.insert(key, "val");
|
||||
assert (option::get(map.find(key)) == "val");
|
||||
map.insert(key, ~"val");
|
||||
assert (option::get(map.find(key)) == ~"val");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear() {
|
||||
let key = "k";
|
||||
let map = map::hashmap::<str, str>(str::hash, str::eq);
|
||||
map.insert(key, "val");
|
||||
let key = ~"k";
|
||||
let map = map::hashmap::<~str, ~str>(str::hash, str::eq);
|
||||
map.insert(key, ~"val");
|
||||
assert (map.size() == 1);
|
||||
assert (map.contains_key(key));
|
||||
map.clear();
|
||||
@ -633,13 +633,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_hash_from_vec() {
|
||||
let map = map::hash_from_strs(~[
|
||||
("a", 1),
|
||||
("b", 2),
|
||||
("c", 3)
|
||||
(~"a", 1),
|
||||
(~"b", 2),
|
||||
(~"c", 3)
|
||||
]);
|
||||
assert map.size() == 3u;
|
||||
assert map.get("a") == 1;
|
||||
assert map.get("b") == 2;
|
||||
assert map.get("c") == 3;
|
||||
assert map.get(~"a") == 1;
|
||||
assert map.get(~"b") == 2;
|
||||
assert map.get(~"c") == 3;
|
||||
}
|
||||
}
|
||||
|
@ -82,17 +82,17 @@ fn md4(msg: ~[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
|
||||
ret {a: a, b: b, c: c, d: d};
|
||||
}
|
||||
|
||||
fn md4_str(msg: ~[u8]) -> str {
|
||||
fn md4_str(msg: ~[u8]) -> ~str {
|
||||
let {a, b, c, d} = md4(msg);
|
||||
fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
|
||||
f(a); f(b); f(c); f(d);
|
||||
}
|
||||
let mut result = "";
|
||||
let mut result = ~"";
|
||||
do app(a, b, c, d) |u| {
|
||||
let mut i = 0u32;
|
||||
while i < 4u32 {
|
||||
let byte = (u >> (i * 8u32)) as u8;
|
||||
if byte <= 16u8 { result += "0"; }
|
||||
if byte <= 16u8 { result += ~"0"; }
|
||||
result += uint::to_str(byte as uint, 16u);
|
||||
i += 1u32;
|
||||
}
|
||||
@ -100,19 +100,19 @@ fn md4_str(msg: ~[u8]) -> str {
|
||||
result
|
||||
}
|
||||
|
||||
fn md4_text(msg: str) -> str { md4_str(str::bytes(msg)) }
|
||||
fn md4_text(msg: ~str) -> ~str { md4_str(str::bytes(msg)) }
|
||||
|
||||
#[test]
|
||||
fn test_md4() {
|
||||
assert md4_text("") == "31d6cfe0d16ae931b73c59d7e0c089c0";
|
||||
assert md4_text("a") == "bde52cb31de33e46245e05fbdbd6fb24";
|
||||
assert md4_text("abc") == "a448017aaf21d8525fc10ae87aa6729d";
|
||||
assert md4_text("message digest") == "d9130a8164549fe818874806e1c7014b";
|
||||
assert md4_text("abcdefghijklmnopqrstuvwxyz") ==
|
||||
"d79e1c308aa5bbcdeea8ed63df412da9";
|
||||
assert md4_text("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123\
|
||||
456789") == "043f8582f241db351ce627e153e7f0e4";
|
||||
assert md4_text("12345678901234567890123456789012345678901234567890123456\
|
||||
789012345678901234567890") ==
|
||||
"e33b4ddc9c38f2199c3e7b164fcc0536";
|
||||
assert md4_text(~"") == ~"31d6cfe0d16ae931b73c59d7e0c089c0";
|
||||
assert md4_text(~"a") == ~"bde52cb31de33e46245e05fbdbd6fb24";
|
||||
assert md4_text(~"abc") == ~"a448017aaf21d8525fc10ae87aa6729d";
|
||||
assert md4_text(~"message digest") == ~"d9130a8164549fe818874806e1c7014b";
|
||||
assert md4_text(~"abcdefghijklmnopqrstuvwxyz") ==
|
||||
~"d79e1c308aa5bbcdeea8ed63df412da9";
|
||||
assert md4_text(~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
|
||||
0123456789") == ~"043f8582f241db351ce627e153e7f0e4";
|
||||
assert md4_text(~"1234567890123456789012345678901234567890123456789\
|
||||
0123456789012345678901234567890") ==
|
||||
~"e33b4ddc9c38f2199c3e7b164fcc0536";
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ enum ip_addr {
|
||||
|
||||
/// Human-friendly feedback on why a parse_addr attempt failed
|
||||
type parse_addr_err = {
|
||||
err_msg: str
|
||||
err_msg: ~str
|
||||
};
|
||||
|
||||
/**
|
||||
@ -46,13 +46,13 @@ type parse_addr_err = {
|
||||
*
|
||||
* * ip - a `std::net::ip::ip_addr`
|
||||
*/
|
||||
fn format_addr(ip: ip_addr) -> str {
|
||||
fn format_addr(ip: ip_addr) -> ~str {
|
||||
alt ip {
|
||||
ipv4(addr) {
|
||||
unsafe {
|
||||
let result = uv_ip4_name(&addr);
|
||||
if result == "" {
|
||||
fail "failed to convert inner sockaddr_in address to str"
|
||||
if result == ~"" {
|
||||
fail ~"failed to convert inner sockaddr_in address to str"
|
||||
}
|
||||
result
|
||||
}
|
||||
@ -60,8 +60,8 @@ fn format_addr(ip: ip_addr) -> str {
|
||||
ipv6(addr) {
|
||||
unsafe {
|
||||
let result = uv_ip6_name(&addr);
|
||||
if result == "" {
|
||||
fail "failed to convert inner sockaddr_in address to str"
|
||||
if result == ~"" {
|
||||
fail ~"failed to convert inner sockaddr_in address to str"
|
||||
}
|
||||
result
|
||||
}
|
||||
@ -88,7 +88,7 @@ enum ip_get_addr_err {
|
||||
* a vector of `ip_addr` results, in the case of success, or an error
|
||||
* object in the case of failure
|
||||
*/
|
||||
fn get_addr(++node: str, iotask: iotask)
|
||||
fn get_addr(++node: ~str, iotask: iotask)
|
||||
-> result::result<~[ip_addr], ip_get_addr_err> unsafe {
|
||||
do comm::listen |output_ch| {
|
||||
do str::unpack_slice(node) |node_ptr, len| {
|
||||
@ -137,7 +137,7 @@ mod v4 {
|
||||
*
|
||||
* * 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) {
|
||||
result::ok(addr) { copy(addr) }
|
||||
result::err(err_data) {
|
||||
@ -154,7 +154,7 @@ mod v4 {
|
||||
*((ptr::addr_of(self)) as *u32)
|
||||
}
|
||||
}
|
||||
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| {
|
||||
alt uint::from_str(s) {
|
||||
some(n) if n <= 255u { n }
|
||||
@ -172,7 +172,7 @@ mod v4 {
|
||||
c: parts[2] as u8, d: parts[3] as u8})
|
||||
}
|
||||
}
|
||||
fn try_parse_addr(ip: str) -> result::result<ip_addr,parse_addr_err> {
|
||||
fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> {
|
||||
unsafe {
|
||||
let INADDR_NONE = ll::get_INADDR_NONE();
|
||||
let ip_rep_result = parse_to_ipv4_rep(ip);
|
||||
@ -196,7 +196,7 @@ mod v4 {
|
||||
if result::get(ref_ip_rep_result).as_u32() == INADDR_NONE &&
|
||||
!input_is_inaddr_none {
|
||||
ret result::err(
|
||||
{err_msg: "uv_ip4_name produced invalid result."})
|
||||
{err_msg: ~"uv_ip4_name produced invalid result."})
|
||||
}
|
||||
else {
|
||||
result::ok(ipv4(copy(new_addr)))
|
||||
@ -220,7 +220,7 @@ mod v6 {
|
||||
*
|
||||
* * 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) {
|
||||
result::ok(addr) { copy(addr) }
|
||||
result::err(err_data) {
|
||||
@ -228,7 +228,7 @@ mod v6 {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn try_parse_addr(ip: str) -> result::result<ip_addr,parse_addr_err> {
|
||||
fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> {
|
||||
unsafe {
|
||||
// need to figure out how to establish a parse failure..
|
||||
let new_addr = uv_ip6_addr(ip, 22);
|
||||
@ -237,7 +237,7 @@ mod v6 {
|
||||
ip, reparsed_name));
|
||||
// '::' appears to be uv_ip6_name() returns for bogus
|
||||
// parses..
|
||||
if ip != "::" && reparsed_name == "::" {
|
||||
if ip != ~"::" && reparsed_name == ~"::" {
|
||||
result::err({err_msg:#fmt("failed to parse '%s'",
|
||||
ip)})
|
||||
}
|
||||
@ -254,7 +254,7 @@ type get_addr_data = {
|
||||
|
||||
extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||
res: *addrinfo) unsafe {
|
||||
log(debug, "in get_addr_cb");
|
||||
log(debug, ~"in get_addr_cb");
|
||||
let handle_data = get_data_for_req(handle) as
|
||||
*get_addr_data;
|
||||
if status == 0i32 {
|
||||
@ -272,8 +272,8 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||
*ll::addrinfo_as_sockaddr_in6(curr_addr))))
|
||||
}
|
||||
else {
|
||||
log(debug, "curr_addr is not of family AF_INET or "+
|
||||
"AF_INET6. Error.");
|
||||
log(debug, ~"curr_addr is not of family AF_INET or "+
|
||||
~"AF_INET6. Error.");
|
||||
(*handle_data).output_ch.send(
|
||||
result::err(get_addr_unknown_error));
|
||||
break;
|
||||
@ -282,7 +282,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||
|
||||
let next_addr = ll::get_next_addrinfo(curr_addr);
|
||||
if next_addr == ptr::null::<addrinfo>() as *addrinfo {
|
||||
log(debug, "null next_addr encountered. no mas");
|
||||
log(debug, ~"null next_addr encountered. no mas");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
@ -295,33 +295,33 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||
(*handle_data).output_ch.send(result::ok(out_vec));
|
||||
}
|
||||
else {
|
||||
log(debug, "addrinfo pointer is NULL");
|
||||
log(debug, ~"addrinfo pointer is NULL");
|
||||
(*handle_data).output_ch.send(
|
||||
result::err(get_addr_unknown_error));
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(debug, "status != 0 error in get_addr_cb");
|
||||
log(debug, ~"status != 0 error in get_addr_cb");
|
||||
(*handle_data).output_ch.send(
|
||||
result::err(get_addr_unknown_error));
|
||||
}
|
||||
if res != (ptr::null::<addrinfo>()) {
|
||||
uv_freeaddrinfo(res);
|
||||
}
|
||||
log(debug, "leaving get_addr_cb");
|
||||
log(debug, ~"leaving get_addr_cb");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_ip_ipv4_parse_and_format_ip() {
|
||||
let localhost_str = "127.0.0.1";
|
||||
let localhost_str = ~"127.0.0.1";
|
||||
assert (format_addr(v4::parse_addr(localhost_str))
|
||||
== localhost_str)
|
||||
}
|
||||
#[test]
|
||||
fn test_ip_ipv6_parse_and_format_ip() {
|
||||
let localhost_str = "::1";
|
||||
let localhost_str = ~"::1";
|
||||
let format_result = format_addr(v6::parse_addr(localhost_str));
|
||||
log(debug, #fmt("results: expected: '%s' actual: '%s'",
|
||||
localhost_str, format_result));
|
||||
@ -329,7 +329,7 @@ mod test {
|
||||
}
|
||||
#[test]
|
||||
fn test_ip_ipv4_bad_parse() {
|
||||
alt v4::try_parse_addr("b4df00d") {
|
||||
alt v4::try_parse_addr(~"b4df00d") {
|
||||
result::err(err_info) {
|
||||
log(debug, #fmt("got error as expected %?", err_info));
|
||||
assert true;
|
||||
@ -342,7 +342,7 @@ mod test {
|
||||
#[test]
|
||||
#[ignore(target_os="win32")]
|
||||
fn test_ip_ipv6_bad_parse() {
|
||||
alt v6::try_parse_addr("::,~2234k;") {
|
||||
alt v6::try_parse_addr(~"::,~2234k;") {
|
||||
result::err(err_info) {
|
||||
log(debug, #fmt("got error as expected %?", err_info));
|
||||
assert true;
|
||||
@ -355,11 +355,11 @@ mod test {
|
||||
#[test]
|
||||
#[ignore(reason = "valgrind says it's leaky")]
|
||||
fn test_ip_get_addr() {
|
||||
let localhost_name = "localhost";
|
||||
let localhost_name = ~"localhost";
|
||||
let iotask = uv::global_loop::get();
|
||||
let ga_result = get_addr(localhost_name, iotask);
|
||||
if result::is_err(ga_result) {
|
||||
fail "got err result from net::ip::get_addr();"
|
||||
fail ~"got err result from net::ip::get_addr();"
|
||||
}
|
||||
// note really sure how to realiably test/assert
|
||||
// this.. mostly just wanting to see it work, atm.
|
||||
@ -369,10 +369,10 @@ mod test {
|
||||
for vec::each(results) |r| {
|
||||
let ipv_prefix = alt r {
|
||||
ipv4(_) {
|
||||
"IPv4"
|
||||
~"IPv4"
|
||||
}
|
||||
ipv6(_) {
|
||||
"IPv6"
|
||||
~"IPv6"
|
||||
}
|
||||
};
|
||||
log(debug, #fmt("test_get_addr: result %s: '%s'",
|
||||
@ -385,7 +385,7 @@ mod test {
|
||||
#[test]
|
||||
#[ignore(reason = "valgrind says it's leaky")]
|
||||
fn test_ip_get_addr_bad_input() {
|
||||
let localhost_name = "sjkl234m,./sdf";
|
||||
let localhost_name = ~"sjkl234m,./sdf";
|
||||
let iotask = uv::global_loop::get();
|
||||
let ga_result = get_addr(localhost_name, iotask);
|
||||
assert result::is_err(ga_result);
|
||||
|
@ -62,8 +62,8 @@ class tcp_socket_buf {
|
||||
|
||||
/// Contains raw, string-based, error information returned from libuv
|
||||
type tcp_err_data = {
|
||||
err_name: str,
|
||||
err_msg: str
|
||||
err_name: ~str,
|
||||
err_msg: ~str
|
||||
};
|
||||
/// Details returned as part of a `result::err` result from `tcp::listen`
|
||||
enum tcp_listen_err_data {
|
||||
@ -71,7 +71,7 @@ enum tcp_listen_err_data {
|
||||
* Some unplanned-for error. The first and second fields correspond
|
||||
* to libuv's `err_name` and `err_msg` fields, respectively.
|
||||
*/
|
||||
generic_listen_err(str, str),
|
||||
generic_listen_err(~str, ~str),
|
||||
/**
|
||||
* Failed to bind to the requested IP/Port, because it is already in use.
|
||||
*
|
||||
@ -98,7 +98,7 @@ enum tcp_connect_err_data {
|
||||
* Some unplanned-for error. The first and second fields correspond
|
||||
* to libuv's `err_name` and `err_msg` fields, respectively.
|
||||
*/
|
||||
generic_connect_err(str, str),
|
||||
generic_connect_err(~str, ~str),
|
||||
/// Invalid IP or invalid port
|
||||
connection_refused
|
||||
}
|
||||
@ -147,15 +147,15 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
|
||||
log(debug, #fmt("stream_handle_ptr outside interact %?",
|
||||
stream_handle_ptr));
|
||||
do iotask::interact(iotask) |loop_ptr| {
|
||||
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 %?",
|
||||
stream_handle_ptr));
|
||||
alt uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
|
||||
0i32 {
|
||||
log(debug, "tcp_init successful");
|
||||
log(debug, ~"tcp_init successful");
|
||||
alt input_ip {
|
||||
ipv4 {
|
||||
log(debug, "dealing w/ ipv4 connection..");
|
||||
log(debug, ~"dealing w/ ipv4 connection..");
|
||||
let connect_req_ptr =
|
||||
ptr::addr_of((*socket_data_ptr).connect_req);
|
||||
let addr_str = ip::format_addr(input_ip);
|
||||
@ -186,7 +186,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
|
||||
};
|
||||
alt connect_result {
|
||||
0i32 {
|
||||
log(debug, "tcp_connect successful");
|
||||
log(debug, ~"tcp_connect successful");
|
||||
// reusable data that we'll have for the
|
||||
// duration..
|
||||
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
|
||||
@ -196,7 +196,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
|
||||
// outcome..
|
||||
uv::ll::set_data_for_req(connect_req_ptr,
|
||||
conn_data_ptr);
|
||||
log(debug, "leaving tcp_connect interact cb...");
|
||||
log(debug, ~"leaving tcp_connect interact cb...");
|
||||
// let tcp_connect_on_connect_cb send on
|
||||
// the result_ch, now..
|
||||
}
|
||||
@ -224,17 +224,17 @@ fn connect(-input_ip: ip::ip_addr, port: uint,
|
||||
};
|
||||
alt comm::recv(result_po) {
|
||||
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))
|
||||
}
|
||||
conn_failure(err_data) {
|
||||
comm::recv(closed_signal_po);
|
||||
log(debug, "tcp::connect - received failure on result_po");
|
||||
log(debug, ~"tcp::connect - received failure on result_po");
|
||||
// still have to free the malloc'd stream handle..
|
||||
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
|
||||
as *libc::c_void);
|
||||
let tcp_conn_err = alt err_data.err_name {
|
||||
"ECONNREFUSED" { connection_refused }
|
||||
~"ECONNREFUSED" { connection_refused }
|
||||
_ { generic_connect_err(err_data.err_name, err_data.err_msg) }
|
||||
};
|
||||
result::err(tcp_conn_err)
|
||||
@ -497,31 +497,31 @@ fn accept(new_conn: tcp_new_connection)
|
||||
// the rules here because this always has to be
|
||||
// called within the context of a listen() new_connect_cb
|
||||
// callback (or it will likely fail and drown your cat)
|
||||
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(
|
||||
server_handle_ptr);
|
||||
alt uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) {
|
||||
0i32 {
|
||||
log(debug, "uv_tcp_init successful for client stream");
|
||||
log(debug, ~"uv_tcp_init successful for client stream");
|
||||
alt uv::ll::accept(
|
||||
server_handle_ptr as *libc::c_void,
|
||||
client_stream_handle_ptr as *libc::c_void) {
|
||||
0i32 {
|
||||
log(debug, "successfully accepted client connection");
|
||||
log(debug, ~"successfully accepted client connection");
|
||||
uv::ll::set_data_for_uv_handle(client_stream_handle_ptr,
|
||||
client_socket_data_ptr
|
||||
as *libc::c_void);
|
||||
comm::send(result_ch, none);
|
||||
}
|
||||
_ {
|
||||
log(debug, "failed to accept client conn");
|
||||
log(debug, ~"failed to accept client conn");
|
||||
comm::send(result_ch, some(
|
||||
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ {
|
||||
log(debug, "failed to init client stream");
|
||||
log(debug, ~"failed to init client stream");
|
||||
comm::send(result_ch, some(
|
||||
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
|
||||
}
|
||||
@ -642,21 +642,21 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
||||
comm::send(setup_ch, none);
|
||||
}
|
||||
_ {
|
||||
log(debug, "failure to uv_listen()");
|
||||
log(debug, ~"failure to uv_listen()");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
comm::send(setup_ch, some(err_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ {
|
||||
log(debug, "failure to uv_tcp_bind");
|
||||
log(debug, ~"failure to uv_tcp_bind");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
comm::send(setup_ch, some(err_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ {
|
||||
log(debug, "failure to uv_tcp_init");
|
||||
log(debug, ~"failure to uv_tcp_init");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
comm::send(setup_ch, some(err_data));
|
||||
}
|
||||
@ -674,12 +674,12 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
||||
};
|
||||
stream_closed_po.recv();
|
||||
alt err_data.err_name {
|
||||
"EACCES" {
|
||||
log(debug, "Got EACCES error");
|
||||
~"EACCES" {
|
||||
log(debug, ~"Got EACCES error");
|
||||
result::err(access_denied)
|
||||
}
|
||||
"EADDRINUSE" {
|
||||
log(debug, "Got EADDRINUSE error");
|
||||
~"EADDRINUSE" {
|
||||
log(debug, ~"Got EADDRINUSE error");
|
||||
result::err(address_in_use)
|
||||
}
|
||||
_ {
|
||||
@ -855,13 +855,13 @@ fn tear_down_socket_data(socket_data: @tcp_socket_data) unsafe {
|
||||
log(debug, #fmt("about to free socket_data at %?", socket_data));
|
||||
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
|
||||
as *libc::c_void);
|
||||
log(debug, "exiting dtor for tcp_socket");
|
||||
log(debug, ~"exiting dtor for tcp_socket");
|
||||
}
|
||||
|
||||
// shared implementation for tcp::read
|
||||
fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
|
||||
-> result::result<~[u8],tcp_err_data> unsafe {
|
||||
log(debug, "starting tcp::read");
|
||||
log(debug, ~"starting tcp::read");
|
||||
let iotask = (*socket_data).iotask;
|
||||
let rs_result = read_start_common_impl(socket_data);
|
||||
if result::is_err(rs_result) {
|
||||
@ -869,26 +869,26 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
|
||||
result::err(err_data)
|
||||
}
|
||||
else {
|
||||
log(debug, "tcp::read before recv_timeout");
|
||||
log(debug, ~"tcp::read before recv_timeout");
|
||||
let read_result = if timeout_msecs > 0u {
|
||||
timer::recv_timeout(
|
||||
iotask, timeout_msecs, result::get(rs_result))
|
||||
} else {
|
||||
some(comm::recv(result::get(rs_result)))
|
||||
};
|
||||
log(debug, "tcp::read after recv_timeout");
|
||||
log(debug, ~"tcp::read after recv_timeout");
|
||||
alt read_result {
|
||||
none {
|
||||
log(debug, "tcp::read: timed out..");
|
||||
log(debug, ~"tcp::read: timed out..");
|
||||
let err_data = {
|
||||
err_name: "TIMEOUT",
|
||||
err_msg: "req timed out"
|
||||
err_name: ~"TIMEOUT",
|
||||
err_msg: ~"req timed out"
|
||||
};
|
||||
read_stop_common_impl(socket_data);
|
||||
result::err(err_data)
|
||||
}
|
||||
some(data_result) {
|
||||
log(debug, "tcp::read got data");
|
||||
log(debug, ~"tcp::read got data");
|
||||
read_stop_common_impl(socket_data);
|
||||
data_result
|
||||
}
|
||||
@ -903,14 +903,14 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
|
||||
let stop_po = comm::port::<option<tcp_err_data>>();
|
||||
let stop_ch = comm::chan(stop_po);
|
||||
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) {
|
||||
0i32 {
|
||||
log(debug, "successfully called uv_read_stop");
|
||||
log(debug, ~"successfully called uv_read_stop");
|
||||
comm::send(stop_ch, none);
|
||||
}
|
||||
_ {
|
||||
log(debug, "failure in calling uv_read_stop");
|
||||
log(debug, ~"failure in calling uv_read_stop");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
comm::send(stop_ch, some(err_data.to_tcp_err()));
|
||||
}
|
||||
@ -933,18 +933,18 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
|
||||
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
|
||||
let start_po = comm::port::<option<uv::ll::uv_err_data>>();
|
||||
let start_ch = comm::chan(start_po);
|
||||
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| {
|
||||
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,
|
||||
on_alloc_cb,
|
||||
on_tcp_read_cb) {
|
||||
0i32 {
|
||||
log(debug, "success doing uv_read_start");
|
||||
log(debug, ~"success doing uv_read_start");
|
||||
comm::send(start_ch, none);
|
||||
}
|
||||
_ {
|
||||
log(debug, "error attempting uv_read_start");
|
||||
log(debug, ~"error attempting uv_read_start");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
comm::send(start_ch, some(err_data));
|
||||
}
|
||||
@ -985,11 +985,11 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data,
|
||||
write_buf_vec_ptr,
|
||||
tcp_write_complete_cb) {
|
||||
0i32 {
|
||||
log(debug, "uv_write() invoked successfully");
|
||||
log(debug, ~"uv_write() invoked successfully");
|
||||
uv::ll::set_data_for_req(write_req_ptr, write_data_ptr);
|
||||
}
|
||||
_ {
|
||||
log(debug, "error invoking uv_write()");
|
||||
log(debug, ~"error invoking uv_write()");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
comm::send((*write_data_ptr).result_ch,
|
||||
tcp_write_error(err_data.to_tcp_err()));
|
||||
@ -1113,13 +1113,13 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
|
||||
}
|
||||
}
|
||||
uv::ll::free_base_of_buf(buf);
|
||||
log(debug, "exiting on_tcp_read_cb");
|
||||
log(debug, ~"exiting on_tcp_read_cb");
|
||||
}
|
||||
|
||||
extern fn on_alloc_cb(handle: *libc::c_void,
|
||||
++suggested_size: size_t)
|
||||
-> uv::ll::uv_buf_t unsafe {
|
||||
log(debug, "tcp read on_alloc_cb!");
|
||||
log(debug, ~"tcp read on_alloc_cb!");
|
||||
let char_ptr = uv::ll::malloc_buf_base_of(suggested_size);
|
||||
log(debug, #fmt("tcp read on_alloc_cb h: %? char_ptr: %u sugsize: %u",
|
||||
handle,
|
||||
@ -1137,7 +1137,7 @@ extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
|
||||
as *tcp_socket_close_data;
|
||||
let closed_ch = (*data).closed_ch;
|
||||
comm::send(closed_ch, ());
|
||||
log(debug, "tcp_socket_dtor_close_cb exiting..");
|
||||
log(debug, ~"tcp_socket_dtor_close_cb exiting..");
|
||||
}
|
||||
|
||||
extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t,
|
||||
@ -1145,14 +1145,14 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t,
|
||||
let write_data_ptr = uv::ll::get_data_for_req(write_req)
|
||||
as *write_req_data;
|
||||
if status == 0i32 {
|
||||
log(debug, "successful write complete");
|
||||
log(debug, ~"successful write complete");
|
||||
comm::send((*write_data_ptr).result_ch, tcp_write_success);
|
||||
} else {
|
||||
let stream_handle_ptr = uv::ll::get_stream_handle_from_write_req(
|
||||
write_req);
|
||||
let loop_ptr = uv::ll::get_loop_for_uv_handle(stream_handle_ptr);
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
log(debug, "failure to write");
|
||||
log(debug, ~"failure to write");
|
||||
comm::send((*write_data_ptr).result_ch, tcp_write_error(err_data));
|
||||
}
|
||||
}
|
||||
@ -1187,11 +1187,11 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t,
|
||||
uv::ll::get_stream_handle_from_connect_req(connect_req_ptr);
|
||||
alt status {
|
||||
0i32 {
|
||||
log(debug, "successful tcp connection!");
|
||||
log(debug, ~"successful tcp connection!");
|
||||
comm::send(result_ch, conn_success);
|
||||
}
|
||||
_ {
|
||||
log(debug, "error in tcp_connect_on_connect_cb");
|
||||
log(debug, ~"error in tcp_connect_on_connect_cb");
|
||||
let loop_ptr = uv::ll::get_loop_for_uv_handle(tcp_stream_ptr);
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
log(debug, #fmt("err_data %? %?", err_data.err_name,
|
||||
@ -1202,7 +1202,7 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t,
|
||||
uv::ll::close(tcp_stream_ptr, stream_error_close_cb);
|
||||
}
|
||||
}
|
||||
log(debug, "leaving tcp_connect_on_connect_cb");
|
||||
log(debug, ~"leaving tcp_connect_on_connect_cb");
|
||||
}
|
||||
|
||||
enum conn_attempt {
|
||||
@ -1287,12 +1287,12 @@ mod test {
|
||||
}
|
||||
fn impl_gl_tcp_ipv4_server_and_client() {
|
||||
let hl_loop = uv::global_loop::get();
|
||||
let server_ip = "127.0.0.1";
|
||||
let server_ip = ~"127.0.0.1";
|
||||
let server_port = 8888u;
|
||||
let expected_req = "ping";
|
||||
let expected_resp = "pong";
|
||||
let expected_req = ~"ping";
|
||||
let expected_resp = ~"pong";
|
||||
|
||||
let server_result_po = comm::port::<str>();
|
||||
let server_result_po = comm::port::<~str>();
|
||||
let server_result_ch = comm::chan(server_result_po);
|
||||
|
||||
let cont_po = comm::port::<()>();
|
||||
@ -1312,7 +1312,7 @@ mod test {
|
||||
};
|
||||
comm::recv(cont_po);
|
||||
// client
|
||||
log(debug, "server started, firing up client..");
|
||||
log(debug, ~"server started, firing up client..");
|
||||
let actual_resp_result = do comm::listen |client_ch| {
|
||||
run_tcp_test_client(
|
||||
server_ip,
|
||||
@ -1333,11 +1333,11 @@ mod test {
|
||||
}
|
||||
fn impl_gl_tcp_ipv4_client_error_connection_refused() {
|
||||
let hl_loop = uv::global_loop::get();
|
||||
let server_ip = "127.0.0.1";
|
||||
let server_ip = ~"127.0.0.1";
|
||||
let server_port = 8889u;
|
||||
let expected_req = "ping";
|
||||
let expected_req = ~"ping";
|
||||
// client
|
||||
log(debug, "firing up client..");
|
||||
log(debug, ~"firing up client..");
|
||||
let actual_resp_result = do comm::listen |client_ch| {
|
||||
run_tcp_test_client(
|
||||
server_ip,
|
||||
@ -1350,18 +1350,18 @@ mod test {
|
||||
connection_refused {
|
||||
}
|
||||
_ {
|
||||
fail "unknown error.. expected connection_refused"
|
||||
fail ~"unknown error.. expected connection_refused"
|
||||
}
|
||||
}
|
||||
}
|
||||
fn impl_gl_tcp_ipv4_server_address_in_use() {
|
||||
let hl_loop = uv::global_loop::get();
|
||||
let server_ip = "127.0.0.1";
|
||||
let server_ip = ~"127.0.0.1";
|
||||
let server_port = 8890u;
|
||||
let expected_req = "ping";
|
||||
let expected_resp = "pong";
|
||||
let expected_req = ~"ping";
|
||||
let expected_resp = ~"pong";
|
||||
|
||||
let server_result_po = comm::port::<str>();
|
||||
let server_result_po = comm::port::<~str>();
|
||||
let server_result_ch = comm::chan(server_result_po);
|
||||
|
||||
let cont_po = comm::port::<()>();
|
||||
@ -1386,7 +1386,7 @@ mod test {
|
||||
server_port,
|
||||
hl_loop);
|
||||
// client.. just doing this so that the first server tears down
|
||||
log(debug, "server started, firing up client..");
|
||||
log(debug, ~"server started, firing up client..");
|
||||
do comm::listen |client_ch| {
|
||||
run_tcp_test_client(
|
||||
server_ip,
|
||||
@ -1400,14 +1400,14 @@ mod test {
|
||||
assert true;
|
||||
}
|
||||
_ {
|
||||
fail "expected address_in_use listen error,"+
|
||||
"but got a different error varient. check logs.";
|
||||
fail ~"expected address_in_use listen error,"+
|
||||
~"but got a different error varient. check logs.";
|
||||
}
|
||||
}
|
||||
}
|
||||
fn impl_gl_tcp_ipv4_server_access_denied() {
|
||||
let hl_loop = uv::global_loop::get();
|
||||
let server_ip = "127.0.0.1";
|
||||
let server_ip = ~"127.0.0.1";
|
||||
let server_port = 80u;
|
||||
// this one should fail..
|
||||
let listen_err = run_tcp_test_server_fail(
|
||||
@ -1419,19 +1419,19 @@ mod test {
|
||||
assert true;
|
||||
}
|
||||
_ {
|
||||
fail "expected address_in_use listen error,"+
|
||||
"but got a different error varient. check logs.";
|
||||
fail ~"expected address_in_use listen error,"+
|
||||
~"but got a different error varient. check logs.";
|
||||
}
|
||||
}
|
||||
}
|
||||
fn impl_gl_tcp_ipv4_server_client_reader_writer() {
|
||||
let iotask = uv::global_loop::get();
|
||||
let server_ip = "127.0.0.1";
|
||||
let server_ip = ~"127.0.0.1";
|
||||
let server_port = 8891u;
|
||||
let expected_req = "ping";
|
||||
let expected_resp = "pong";
|
||||
let expected_req = ~"ping";
|
||||
let expected_resp = ~"pong";
|
||||
|
||||
let server_result_po = comm::port::<str>();
|
||||
let server_result_po = comm::port::<~str>();
|
||||
let server_result_ch = comm::chan(server_result_po);
|
||||
|
||||
let cont_po = comm::port::<()>();
|
||||
@ -1474,7 +1474,7 @@ mod test {
|
||||
assert str::contains(actual_resp, expected_resp);
|
||||
}
|
||||
|
||||
fn buf_write(+w: io::writer, val: str) {
|
||||
fn buf_write(+w: io::writer, val: ~str) {
|
||||
log(debug, #fmt("BUF_WRITE: val len %?", str::len(val)));
|
||||
do str::byte_slice(val) |b_slice| {
|
||||
log(debug, #fmt("BUF_WRITE: b_slice len %?",
|
||||
@ -1483,17 +1483,17 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
fn buf_read(+r: io::reader, len: uint) -> str {
|
||||
fn buf_read(+r: io::reader, len: uint) -> ~str {
|
||||
let new_bytes = r.read_bytes(len);
|
||||
log(debug, #fmt("in buf_read.. new_bytes len: %?",
|
||||
vec::len(new_bytes)));
|
||||
str::from_bytes(new_bytes)
|
||||
}
|
||||
|
||||
fn run_tcp_test_server(server_ip: str, server_port: uint, resp: str,
|
||||
server_ch: comm::chan<str>,
|
||||
fn run_tcp_test_server(server_ip: ~str, server_port: uint, resp: ~str,
|
||||
server_ch: comm::chan<~str>,
|
||||
cont_ch: comm::chan<()>,
|
||||
iotask: iotask) -> str {
|
||||
iotask: iotask) -> ~str {
|
||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||
let listen_result = listen(server_ip_addr, server_port, 128u, iotask,
|
||||
// on_establish_cb -- called when listener is set up
|
||||
@ -1505,55 +1505,55 @@ mod test {
|
||||
// risky to run this on the loop, but some users
|
||||
// will want the POWER
|
||||
|new_conn, kill_ch| {
|
||||
log(debug, "SERVER: new connection!");
|
||||
log(debug, ~"SERVER: new connection!");
|
||||
do comm::listen |cont_ch| {
|
||||
do task::spawn_sched(task::manual_threads(1u)) {
|
||||
log(debug, "SERVER: starting worker for new req");
|
||||
log(debug, ~"SERVER: starting worker for new req");
|
||||
|
||||
let accept_result = accept(new_conn);
|
||||
log(debug, "SERVER: after accept()");
|
||||
log(debug, ~"SERVER: after accept()");
|
||||
if result::is_err(accept_result) {
|
||||
log(debug, "SERVER: error accept connection");
|
||||
log(debug, ~"SERVER: error accept connection");
|
||||
let err_data = result::get_err(accept_result);
|
||||
comm::send(kill_ch, some(err_data));
|
||||
log(debug,
|
||||
"SERVER/WORKER: send on err cont ch");
|
||||
~"SERVER/WORKER: send on err cont ch");
|
||||
cont_ch.send(());
|
||||
}
|
||||
else {
|
||||
log(debug,
|
||||
"SERVER/WORKER: send on cont ch");
|
||||
~"SERVER/WORKER: send on cont ch");
|
||||
cont_ch.send(());
|
||||
let sock = result::unwrap(accept_result);
|
||||
log(debug, "SERVER: successfully accepted"+
|
||||
"connection!");
|
||||
log(debug, ~"SERVER: successfully accepted"+
|
||||
~"connection!");
|
||||
let received_req_bytes = read(sock, 0u);
|
||||
alt received_req_bytes {
|
||||
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: %?",
|
||||
vec::len(data)));
|
||||
server_ch.send(
|
||||
str::from_bytes(data));
|
||||
log(debug, "SERVER: before write");
|
||||
log(debug, ~"SERVER: before write");
|
||||
tcp_write_single(sock, str::bytes(resp));
|
||||
log(debug, "SERVER: after write.. die");
|
||||
log(debug, ~"SERVER: after write.. die");
|
||||
comm::send(kill_ch, none);
|
||||
}
|
||||
result::err(err_data) {
|
||||
log(debug, #fmt("SERVER: error recvd: %s %s",
|
||||
err_data.err_name, err_data.err_msg));
|
||||
comm::send(kill_ch, some(err_data));
|
||||
server_ch.send("");
|
||||
server_ch.send(~"");
|
||||
}
|
||||
}
|
||||
log(debug, "SERVER: worker spinning down");
|
||||
log(debug, ~"SERVER: worker spinning down");
|
||||
}
|
||||
}
|
||||
log(debug, "SERVER: waiting to recv on cont_ch");
|
||||
log(debug, ~"SERVER: waiting to recv on cont_ch");
|
||||
cont_ch.recv()
|
||||
};
|
||||
log(debug, "SERVER: recv'd on cont_ch..leaving listen cb");
|
||||
log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb");
|
||||
});
|
||||
// err check on listen_result
|
||||
if result::is_err(listen_result) {
|
||||
@ -1563,10 +1563,10 @@ mod test {
|
||||
name, msg);
|
||||
}
|
||||
access_denied {
|
||||
fail "SERVER: exited abnormally, got access denied..";
|
||||
fail ~"SERVER: exited abnormally, got access denied..";
|
||||
}
|
||||
address_in_use {
|
||||
fail "SERVER: exited abnormally, got address in use...";
|
||||
fail ~"SERVER: exited abnormally, got address in use...";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1575,7 +1575,7 @@ mod test {
|
||||
ret_val
|
||||
}
|
||||
|
||||
fn run_tcp_test_server_fail(server_ip: str, server_port: uint,
|
||||
fn run_tcp_test_server_fail(server_ip: ~str, server_port: uint,
|
||||
iotask: iotask) -> tcp_listen_err_data {
|
||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||
let listen_result = listen(server_ip_addr, server_port, 128u, iotask,
|
||||
@ -1593,20 +1593,20 @@ mod test {
|
||||
result::get_err(listen_result)
|
||||
}
|
||||
else {
|
||||
fail "SERVER: did not fail as expected"
|
||||
fail ~"SERVER: did not fail as expected"
|
||||
}
|
||||
}
|
||||
|
||||
fn run_tcp_test_client(server_ip: str, server_port: uint, resp: str,
|
||||
client_ch: comm::chan<str>,
|
||||
iotask: iotask) -> result::result<str,
|
||||
fn run_tcp_test_client(server_ip: ~str, server_port: uint, resp: ~str,
|
||||
client_ch: comm::chan<~str>,
|
||||
iotask: iotask) -> result::result<~str,
|
||||
tcp_connect_err_data> {
|
||||
let server_ip_addr = ip::v4::parse_addr(server_ip);
|
||||
|
||||
log(debug, "CLIENT: starting..");
|
||||
log(debug, ~"CLIENT: starting..");
|
||||
let connect_result = connect(server_ip_addr, server_port, iotask);
|
||||
if result::is_err(connect_result) {
|
||||
log(debug, "CLIENT: failed to connect");
|
||||
log(debug, ~"CLIENT: failed to connect");
|
||||
let err_data = result::get_err(connect_result);
|
||||
err(err_data)
|
||||
}
|
||||
@ -1616,8 +1616,8 @@ mod test {
|
||||
tcp_write_single(sock, resp_bytes);
|
||||
let read_result = sock.read(0u);
|
||||
if read_result.is_err() {
|
||||
log(debug, "CLIENT: failure to read");
|
||||
ok("")
|
||||
log(debug, ~"CLIENT: failure to read");
|
||||
ok(~"")
|
||||
}
|
||||
else {
|
||||
client_ch.send(str::from_bytes(read_result.get()));
|
||||
@ -1633,12 +1633,12 @@ mod test {
|
||||
let write_result_future = sock.write_future(val);
|
||||
let write_result = write_result_future.get();
|
||||
if result::is_err(write_result) {
|
||||
log(debug, "tcp_write_single: write failed!");
|
||||
log(debug, ~"tcp_write_single: write failed!");
|
||||
let err_data = result::get_err(write_result);
|
||||
log(debug, #fmt("tcp_write_single err name: %s msg: %s",
|
||||
err_data.err_name, err_data.err_msg));
|
||||
// meh. torn on what to do here.
|
||||
fail "tcp_write_single failed";
|
||||
fail ~"tcp_write_single failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ fn map_slices<A: copy send, B: copy send>(
|
||||
|
||||
let len = xs.len();
|
||||
if len < min_granularity {
|
||||
log(info, "small slice");
|
||||
log(info, ~"small slice");
|
||||
// This is a small vector, fall back on the normal map.
|
||||
~[f()(0u, xs)]
|
||||
}
|
||||
@ -42,7 +42,7 @@ fn map_slices<A: copy send, B: copy send>(
|
||||
|
||||
let mut futures = ~[];
|
||||
let mut base = 0u;
|
||||
log(info, "spawning tasks");
|
||||
log(info, ~"spawning tasks");
|
||||
while base < len {
|
||||
let end = uint::min(len, base + items_per_task);
|
||||
// FIXME: why is the ::<A, ()> annotation required here? (#2617)
|
||||
@ -66,7 +66,7 @@ fn map_slices<A: copy send, B: copy send>(
|
||||
};
|
||||
base += items_per_task;
|
||||
}
|
||||
log(info, "tasks spawned");
|
||||
log(info, ~"tasks spawned");
|
||||
|
||||
log(info, #fmt("num_tasks: %?", (num_tasks, futures.len())));
|
||||
assert(num_tasks == futures.len());
|
||||
|
@ -4,7 +4,7 @@ import serialization::serializer;
|
||||
|
||||
impl of serializer for writer {
|
||||
fn emit_nil() {
|
||||
self.write_str("()")
|
||||
self.write_str(~"()")
|
||||
}
|
||||
|
||||
fn emit_uint(v: uint) {
|
||||
@ -63,68 +63,68 @@ impl of serializer for writer {
|
||||
self.write_str(#fmt["%?_f32", v]);
|
||||
}
|
||||
|
||||
fn emit_str(v: str) {
|
||||
fn emit_str(v: ~str) {
|
||||
self.write_str(#fmt["%?", v]);
|
||||
}
|
||||
|
||||
fn emit_enum(_name: str, f: fn()) {
|
||||
fn emit_enum(_name: ~str, f: fn()) {
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_enum_variant(v_name: str, _v_id: uint, sz: uint, f: fn()) {
|
||||
fn emit_enum_variant(v_name: ~str, _v_id: uint, sz: uint, f: fn()) {
|
||||
self.write_str(v_name);
|
||||
if sz > 0u { self.write_str("("); }
|
||||
if sz > 0u { self.write_str(~"("); }
|
||||
f();
|
||||
if sz > 0u { self.write_str(")"); }
|
||||
if sz > 0u { self.write_str(~")"); }
|
||||
}
|
||||
|
||||
fn emit_enum_variant_arg(idx: uint, f: fn()) {
|
||||
if idx > 0u { self.write_str(", "); }
|
||||
if idx > 0u { self.write_str(~", "); }
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_vec(_len: uint, f: fn()) {
|
||||
self.write_str("[");
|
||||
self.write_str(~"[");
|
||||
f();
|
||||
self.write_str("]");
|
||||
self.write_str(~"]");
|
||||
}
|
||||
|
||||
fn emit_vec_elt(idx: uint, f: fn()) {
|
||||
if idx > 0u { self.write_str(", "); }
|
||||
if idx > 0u { self.write_str(~", "); }
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_box(f: fn()) {
|
||||
self.write_str("@");
|
||||
self.write_str(~"@");
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_uniq(f: fn()) {
|
||||
self.write_str("~");
|
||||
self.write_str(~"~");
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_rec(f: fn()) {
|
||||
self.write_str("{");
|
||||
self.write_str(~"{");
|
||||
f();
|
||||
self.write_str("}");
|
||||
self.write_str(~"}");
|
||||
}
|
||||
|
||||
fn emit_rec_field(f_name: str, f_idx: uint, f: fn()) {
|
||||
if f_idx > 0u { self.write_str(", "); }
|
||||
fn emit_rec_field(f_name: ~str, f_idx: uint, f: fn()) {
|
||||
if f_idx > 0u { self.write_str(~", "); }
|
||||
self.write_str(f_name);
|
||||
self.write_str(": ");
|
||||
self.write_str(~": ");
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_tup(_sz: uint, f: fn()) {
|
||||
self.write_str("(");
|
||||
self.write_str(~"(");
|
||||
f();
|
||||
self.write_str(")");
|
||||
self.write_str(~")");
|
||||
}
|
||||
|
||||
fn emit_tup_elt(idx: uint, f: fn()) {
|
||||
if idx > 0u { self.write_str(", "); }
|
||||
if idx > 0u { self.write_str(~", "); }
|
||||
f();
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ fn empty() -> rope {
|
||||
* * this operation does not copy the string;
|
||||
* * the function runs in linear time.
|
||||
*/
|
||||
fn of_str(str: @str/~) -> rope {
|
||||
fn of_str(str: @~str) -> rope {
|
||||
ret of_substr(str, 0u, str::len(*str));
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ fn of_str(str: @str/~) -> rope {
|
||||
* * this function does _not_ check the validity of the substring;
|
||||
* * this function fails if `byte_offset` or `byte_len` do not match `str`.
|
||||
*/
|
||||
fn of_substr(str: @str/~, byte_offset: uint, byte_len: uint) -> rope {
|
||||
fn of_substr(str: @~str, byte_offset: uint, byte_len: uint) -> rope {
|
||||
if byte_len == 0u { ret node::empty; }
|
||||
if byte_offset + byte_len > str::len(*str) { fail; }
|
||||
ret node::content(node::of_substr(str, byte_offset, byte_len));
|
||||
@ -107,7 +107,7 @@ fn append_char(rope: rope, char: char) -> rope {
|
||||
*
|
||||
* * this function executes in near-linear time
|
||||
*/
|
||||
fn append_str(rope: rope, str: @str/~) -> rope {
|
||||
fn append_str(rope: rope, str: @~str) -> rope {
|
||||
ret append_rope(rope, of_str(str))
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ fn prepend_char(rope: rope, char: char) -> rope {
|
||||
* # Performance note
|
||||
* * this function executes in near-linear time
|
||||
*/
|
||||
fn prepend_str(rope: rope, str: @str/~) -> rope {
|
||||
fn prepend_str(rope: rope, str: @~str) -> rope {
|
||||
ret append_rope(of_str(str), rope)
|
||||
}
|
||||
|
||||
@ -567,7 +567,7 @@ mod node {
|
||||
byte_offset: uint,
|
||||
byte_len: uint,
|
||||
char_len: uint,
|
||||
content: @str/~
|
||||
content: @~str
|
||||
};
|
||||
|
||||
/**
|
||||
@ -627,7 +627,7 @@ mod node {
|
||||
* Performance note: The complexity of this function is linear in
|
||||
* the length of `str`.
|
||||
*/
|
||||
fn of_str(str: @str/~) -> @node {
|
||||
fn of_str(str: @~str) -> @node {
|
||||
ret of_substr(str, 0u, str::len(*str));
|
||||
}
|
||||
|
||||
@ -648,7 +648,7 @@ mod node {
|
||||
* Behavior is undefined if `byte_start` or `byte_len` do not represent
|
||||
* valid positions in `str`
|
||||
*/
|
||||
fn of_substr(str: @str/~, byte_start: uint, byte_len: uint) -> @node {
|
||||
fn of_substr(str: @~str, byte_start: uint, byte_len: uint) -> @node {
|
||||
ret of_substr_unsafer(str, byte_start, byte_len,
|
||||
str::count_chars(*str, byte_start, byte_len));
|
||||
}
|
||||
@ -674,7 +674,7 @@ mod node {
|
||||
* * Behavior is undefined if `char_len` does not accurately represent the
|
||||
* number of chars between byte_start and byte_start+byte_len
|
||||
*/
|
||||
fn of_substr_unsafer(str: @str/~, byte_start: uint, byte_len: uint,
|
||||
fn of_substr_unsafer(str: @~str, byte_start: uint, byte_len: uint,
|
||||
char_len: uint) -> @node {
|
||||
assert(byte_start + byte_len <= str::len(*str));
|
||||
let candidate = @leaf({
|
||||
@ -799,7 +799,7 @@ mod node {
|
||||
ret forest[0];
|
||||
}
|
||||
|
||||
fn serialize_node(node: @node) -> str unsafe {
|
||||
fn serialize_node(node: @node) -> ~str unsafe {
|
||||
let mut buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8));
|
||||
let mut offset = 0u;//Current position in the buffer
|
||||
let it = leaf_iterator::start(node);
|
||||
@ -1237,11 +1237,11 @@ mod node {
|
||||
mod tests {
|
||||
|
||||
//Utility function, used for sanity check
|
||||
fn rope_to_string(r: rope) -> str {
|
||||
fn rope_to_string(r: rope) -> ~str {
|
||||
alt(r) {
|
||||
node::empty { ret "" }
|
||||
node::empty { ret ~"" }
|
||||
node::content(x) {
|
||||
let str = @mut "";
|
||||
let str = @mut ~"";
|
||||
fn aux(str: @mut str, node: @node::node) unsafe {
|
||||
alt(*node) {
|
||||
node::leaf(x) {
|
||||
@ -1270,7 +1270,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn of_string1() {
|
||||
let sample = @"0123456789ABCDE"/~;
|
||||
let sample = @~"0123456789ABCDE";
|
||||
let r = of_str(sample);
|
||||
|
||||
assert char_len(r) == str::char_len(*sample);
|
||||
@ -1279,7 +1279,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn of_string2() {
|
||||
let buf = @ mut "1234567890";
|
||||
let buf = @ mut ~"1234567890";
|
||||
let mut i = 0;
|
||||
while i < 10 { *buf = *buf + *buf; i+=1;}
|
||||
let sample = @*buf;
|
||||
@ -1310,7 +1310,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn iter1() {
|
||||
let buf = @ mut "1234567890";
|
||||
let buf = @ mut ~"1234567890";
|
||||
let mut i = 0;
|
||||
while i < 10 { *buf = *buf + *buf; i+=1;}
|
||||
let sample = @*buf;
|
||||
@ -1330,7 +1330,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bal1() {
|
||||
let init = @"1234567890"/~;
|
||||
let init = @~"1234567890";
|
||||
let buf = @mut * init;
|
||||
let mut i = 0;
|
||||
while i < 8 { *buf = *buf + *buf; i+=1;}
|
||||
@ -1352,7 +1352,7 @@ mod tests {
|
||||
#[ignore]
|
||||
fn char_at1() {
|
||||
//Generate a large rope
|
||||
let mut r = of_str(@"123456789"/~);
|
||||
let mut r = of_str(@~"123456789");
|
||||
for uint::range(0u, 10u) |_i| {
|
||||
r = append_rope(r, r);
|
||||
}
|
||||
@ -1384,7 +1384,7 @@ mod tests {
|
||||
#[test]
|
||||
fn concat1() {
|
||||
//Generate a reasonable rope
|
||||
let chunk = of_str(@"123456789"/~);
|
||||
let chunk = of_str(@~"123456789");
|
||||
let mut r = empty();
|
||||
for uint::range(0u, 10u) |_i| {
|
||||
r = append_rope(r, chunk);
|
||||
|
@ -23,18 +23,18 @@ iface serializer {
|
||||
fn emit_float(v: float);
|
||||
fn emit_f64(v: f64);
|
||||
fn emit_f32(v: f32);
|
||||
fn emit_str(v: str);
|
||||
fn emit_str(v: ~str);
|
||||
|
||||
// Compound types:
|
||||
fn emit_enum(name: str, f: fn());
|
||||
fn emit_enum_variant(v_name: str, v_id: uint, sz: uint, f: fn());
|
||||
fn emit_enum(name: ~str, f: fn());
|
||||
fn emit_enum_variant(v_name: ~str, v_id: uint, sz: uint, f: fn());
|
||||
fn emit_enum_variant_arg(idx: uint, f: fn());
|
||||
fn emit_vec(len: uint, f: fn());
|
||||
fn emit_vec_elt(idx: uint, f: fn());
|
||||
fn emit_box(f: fn());
|
||||
fn emit_uniq(f: fn());
|
||||
fn emit_rec(f: fn());
|
||||
fn emit_rec_field(f_name: str, f_idx: uint, f: fn());
|
||||
fn emit_rec_field(f_name: ~str, f_idx: uint, f: fn());
|
||||
fn emit_tup(sz: uint, f: fn());
|
||||
fn emit_tup_elt(idx: uint, f: fn());
|
||||
}
|
||||
@ -58,14 +58,14 @@ iface deserializer {
|
||||
|
||||
fn read_bool() -> bool;
|
||||
|
||||
fn read_str() -> str;
|
||||
fn read_str() -> ~str;
|
||||
|
||||
fn read_f64() -> f64;
|
||||
fn read_f32() -> f32;
|
||||
fn read_float() -> float;
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T:copy>(name: str, f: fn() -> T) -> T;
|
||||
fn read_enum<T:copy>(name: ~str, f: fn() -> T) -> T;
|
||||
fn read_enum_variant<T:copy>(f: fn(uint) -> T) -> T;
|
||||
fn read_enum_variant_arg<T:copy>(idx: uint, f: fn() -> T) -> T;
|
||||
fn read_vec<T:copy>(f: fn(uint) -> T) -> T;
|
||||
@ -73,7 +73,7 @@ iface deserializer {
|
||||
fn read_box<T:copy>(f: fn() -> T) -> T;
|
||||
fn read_uniq<T:copy>(f: fn() -> T) -> T;
|
||||
fn read_rec<T:copy>(f: fn() -> T) -> T;
|
||||
fn read_rec_field<T:copy>(f_name: str, f_idx: uint, f: fn() -> T) -> T;
|
||||
fn read_rec_field<T:copy>(f_name: ~str, f_idx: uint, f: fn() -> T) -> T;
|
||||
fn read_tup<T:copy>(sz: uint, f: fn() -> T) -> T;
|
||||
fn read_tup_elt<T:copy>(idx: uint, f: fn() -> T) -> T;
|
||||
}
|
||||
@ -193,11 +193,11 @@ fn deserialize_i64<D: deserializer>(d: D) -> i64 {
|
||||
d.read_i64()
|
||||
}
|
||||
|
||||
fn serialize_str<S: serializer>(s: S, v: str) {
|
||||
fn serialize_str<S: serializer>(s: S, v: ~str) {
|
||||
s.emit_str(v);
|
||||
}
|
||||
|
||||
fn deserialize_str<D: deserializer>(d: D) -> str {
|
||||
fn deserialize_str<D: deserializer>(d: D) -> ~str {
|
||||
d.read_str()
|
||||
}
|
||||
|
||||
@ -234,15 +234,15 @@ fn deserialize_bool<D: deserializer>(d: D) -> bool {
|
||||
}
|
||||
|
||||
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 {
|
||||
none {
|
||||
do s.emit_enum_variant("none", 0u, 0u) {
|
||||
do s.emit_enum_variant(~"none", 0u, 0u) {
|
||||
}
|
||||
}
|
||||
|
||||
some(v) {
|
||||
do s.emit_enum_variant("some", 1u, 1u) {
|
||||
do s.emit_enum_variant(~"some", 1u, 1u) {
|
||||
do s.emit_enum_variant_arg(0u) {
|
||||
st(v)
|
||||
}
|
||||
@ -254,7 +254,7 @@ fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
|
||||
|
||||
fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T)
|
||||
-> option<T> {
|
||||
do d.read_enum("option") {
|
||||
do d.read_enum(~"option") {
|
||||
do d.read_enum_variant |i| {
|
||||
alt check i {
|
||||
0u { // none
|
||||
|
@ -24,7 +24,7 @@ iface sha1 {
|
||||
/// Provide message input as bytes
|
||||
fn input(~[u8]);
|
||||
/// Provide message input as string
|
||||
fn input_str(str);
|
||||
fn input_str(~str);
|
||||
/**
|
||||
* Read the digest as a vector of 20 bytes. After calling this no further
|
||||
* input may be provided until reset is called.
|
||||
@ -34,7 +34,7 @@ iface sha1 {
|
||||
* Read the digest as a hex string. After calling this no further
|
||||
* input may be provided until reset is called.
|
||||
*/
|
||||
fn result_str() -> str;
|
||||
fn result_str() -> ~str;
|
||||
/// Reset the SHA-1 state for reuse
|
||||
fn reset();
|
||||
}
|
||||
@ -232,11 +232,11 @@ fn sha1() -> sha1 {
|
||||
self.computed = false;
|
||||
}
|
||||
fn input(msg: ~[u8]) { add_input(self, msg); }
|
||||
fn input_str(msg: str) { add_input(self, str::bytes(msg)); }
|
||||
fn input_str(msg: ~str) { add_input(self, str::bytes(msg)); }
|
||||
fn result() -> ~[u8] { ret mk_result(self); }
|
||||
fn result_str() -> str {
|
||||
fn result_str() -> ~str {
|
||||
let r = mk_result(self);
|
||||
let mut s = "";
|
||||
let mut s = ~"";
|
||||
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
|
||||
ret s;
|
||||
}
|
||||
@ -260,18 +260,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test() unsafe {
|
||||
type test = {input: str, output: ~[u8]};
|
||||
type test = {input: ~str, output: ~[u8]};
|
||||
|
||||
fn a_million_letter_a() -> str {
|
||||
fn a_million_letter_a() -> ~str {
|
||||
let mut i = 0;
|
||||
let mut rs = "";
|
||||
while i < 100000 { str::push_str(rs, "aaaaaaaaaa"); i += 1; }
|
||||
let mut rs = ~"";
|
||||
while i < 100000 { str::push_str(rs, ~"aaaaaaaaaa"); i += 1; }
|
||||
ret rs;
|
||||
}
|
||||
// Test messages from FIPS 180-1
|
||||
|
||||
let fips_180_1_tests: ~[test] =
|
||||
~[{input: "abc",
|
||||
~[{input: ~"abc",
|
||||
output:
|
||||
~[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8,
|
||||
0x47u8, 0x06u8, 0x81u8, 0x6Au8,
|
||||
@ -279,8 +279,8 @@ mod tests {
|
||||
0x78u8, 0x50u8, 0xC2u8, 0x6Cu8,
|
||||
0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]},
|
||||
{input:
|
||||
"abcdbcdecdefdefgefghfghighij" +
|
||||
"hijkijkljklmklmnlmnomnopnopq",
|
||||
~"abcdbcdecdefdefgefghfghighij" +
|
||||
~"hijkijkljklmklmnlmnomnopnopq",
|
||||
output:
|
||||
~[0x84u8, 0x98u8, 0x3Eu8, 0x44u8,
|
||||
0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8,
|
||||
@ -297,14 +297,14 @@ mod tests {
|
||||
// Examples from wikipedia
|
||||
|
||||
let wikipedia_tests: ~[test] =
|
||||
~[{input: "The quick brown fox jumps over the lazy dog",
|
||||
~[{input: ~"The quick brown fox jumps over the lazy dog",
|
||||
output:
|
||||
~[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8,
|
||||
0x7au8, 0x2du8, 0x28u8, 0xfcu8,
|
||||
0xedu8, 0x84u8, 0x9eu8, 0xe1u8,
|
||||
0xbbu8, 0x76u8, 0xe7u8, 0x39u8,
|
||||
0x1bu8, 0x93u8, 0xebu8, 0x12u8]},
|
||||
{input: "The quick brown fox jumps over the lazy cog",
|
||||
{input: ~"The quick brown fox jumps over the lazy cog",
|
||||
output:
|
||||
~[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8,
|
||||
0xd2u8, 0x5eu8, 0x1bu8, 0x3au8,
|
||||
|
@ -5,7 +5,7 @@ import option::{none, some};
|
||||
import rand;
|
||||
import core::rand::extensions;
|
||||
|
||||
fn mkdtemp(prefix: str, suffix: str) -> option<str> {
|
||||
fn mkdtemp(prefix: ~str, suffix: ~str) -> option<~str> {
|
||||
let r = rand::rng();
|
||||
let mut i = 0u;
|
||||
while (i < 1000u) {
|
||||
@ -20,11 +20,11 @@ fn mkdtemp(prefix: str, suffix: str) -> option<str> {
|
||||
|
||||
#[test]
|
||||
fn test_mkdtemp() {
|
||||
let r = mkdtemp("./", "foobar");
|
||||
let r = mkdtemp(~"./", ~"foobar");
|
||||
alt r {
|
||||
some(p) {
|
||||
os::remove_dir(p);
|
||||
assert(str::ends_with(p, "foobar"));
|
||||
assert(str::ends_with(p, ~"foobar"));
|
||||
}
|
||||
_ { assert(false); }
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ fn reset(writer: io::writer) {
|
||||
|
||||
/// Returns true if the terminal supports color
|
||||
fn color_supported() -> bool {
|
||||
let supported_terms = ~["xterm-color", "xterm",
|
||||
"screen-bce", "xterm-256color"];
|
||||
ret alt os::getenv("TERM") {
|
||||
let supported_terms = ~[~"xterm-color", ~"xterm",
|
||||
~"screen-bce", ~"xterm-256color"];
|
||||
ret alt os::getenv(~"TERM") {
|
||||
option::some(env) {
|
||||
for vec::each(supported_terms) |term| {
|
||||
if str::eq(term, env) { ret true; }
|
||||
|
@ -30,7 +30,7 @@ extern mod rustrt {
|
||||
// paths; i.e. it should be a series of identifiers seperated by double
|
||||
// colons. This way if some test runner wants to arrange the tests
|
||||
// hierarchically it may.
|
||||
type test_name = str;
|
||||
type test_name = ~str;
|
||||
|
||||
// A function that runs a test. If the function returns successfully,
|
||||
// the test succeeds; if the function fails then the test fails. We
|
||||
@ -49,24 +49,24 @@ type test_desc = {
|
||||
|
||||
// The default console test runner. It accepts the command line
|
||||
// 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 =
|
||||
alt parse_opts(args) {
|
||||
either::left(o) { o }
|
||||
either::right(m) { fail m }
|
||||
};
|
||||
if !run_tests_console(opts, tests) { fail "Some tests failed"; }
|
||||
if !run_tests_console(opts, tests) { fail ~"Some tests failed"; }
|
||||
}
|
||||
|
||||
type test_opts = {filter: option<str>, run_ignored: bool,
|
||||
logfile: option<str>};
|
||||
type test_opts = {filter: option<~str>, run_ignored: bool,
|
||||
logfile: option<~str>};
|
||||
|
||||
type opt_res = either<test_opts, str>;
|
||||
type opt_res = either<test_opts, ~str>;
|
||||
|
||||
// Parses command line arguments into test options
|
||||
fn parse_opts(args: ~[str]) -> opt_res {
|
||||
fn parse_opts(args: ~[~str]) -> opt_res {
|
||||
let args_ = vec::tail(args);
|
||||
let opts = ~[getopts::optflag("ignored"), getopts::optopt("logfile")];
|
||||
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
|
||||
let match =
|
||||
alt getopts::getopts(args_, opts) {
|
||||
ok(m) { m }
|
||||
@ -78,8 +78,8 @@ fn parse_opts(args: ~[str]) -> opt_res {
|
||||
option::some(match.free[0])
|
||||
} else { option::none };
|
||||
|
||||
let run_ignored = getopts::opt_present(match, "ignored");
|
||||
let logfile = getopts::opt_maybe_str(match, "logfile");
|
||||
let run_ignored = getopts::opt_present(match, ~"ignored");
|
||||
let logfile = getopts::opt_maybe_str(match, ~"logfile");
|
||||
|
||||
let test_opts = {filter: filter, run_ignored: run_ignored,
|
||||
logfile: logfile};
|
||||
@ -107,7 +107,7 @@ fn run_tests_console(opts: test_opts,
|
||||
alt event {
|
||||
te_filtered(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" };
|
||||
st.out.write_line(#fmt["\nrunning %u %s", st.total, noun]);
|
||||
}
|
||||
te_wait(test) { st.out.write_str(#fmt["test %s ... ", test.name]); }
|
||||
@ -122,18 +122,18 @@ fn run_tests_console(opts: test_opts,
|
||||
tr_ok {
|
||||
st.passed += 1u;
|
||||
write_ok(st.out, st.use_color);
|
||||
st.out.write_line("");
|
||||
st.out.write_line(~"");
|
||||
}
|
||||
tr_failed {
|
||||
st.failed += 1u;
|
||||
write_failed(st.out, st.use_color);
|
||||
st.out.write_line("");
|
||||
st.out.write_line(~"");
|
||||
vec::push(st.failures, copy test);
|
||||
}
|
||||
tr_ignored {
|
||||
st.ignored += 1u;
|
||||
write_ignored(st.out, st.use_color);
|
||||
st.out.write_line("");
|
||||
st.out.write_line(~"");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,25 +184,25 @@ fn run_tests_console(opts: test_opts,
|
||||
fn write_log(out: io::writer, result: test_result, test: test_desc) {
|
||||
out.write_line(#fmt("%s %s",
|
||||
alt result {
|
||||
tr_ok { "ok" }
|
||||
tr_failed { "failed" }
|
||||
tr_ignored { "ignored" }
|
||||
tr_ok { ~"ok" }
|
||||
tr_failed { ~"failed" }
|
||||
tr_ignored { ~"ignored" }
|
||||
}, test.name));
|
||||
}
|
||||
|
||||
fn write_ok(out: io::writer, use_color: bool) {
|
||||
write_pretty(out, "ok", term::color_green, use_color);
|
||||
write_pretty(out, ~"ok", term::color_green, use_color);
|
||||
}
|
||||
|
||||
fn write_failed(out: io::writer, use_color: bool) {
|
||||
write_pretty(out, "FAILED", term::color_red, use_color);
|
||||
write_pretty(out, ~"FAILED", term::color_red, use_color);
|
||||
}
|
||||
|
||||
fn write_ignored(out: io::writer, use_color: bool) {
|
||||
write_pretty(out, "ignored", term::color_yellow, use_color);
|
||||
write_pretty(out, ~"ignored", term::color_yellow, use_color);
|
||||
}
|
||||
|
||||
fn write_pretty(out: io::writer, word: str, color: u8, use_color: bool) {
|
||||
fn write_pretty(out: io::writer, word: ~str, color: u8, use_color: bool) {
|
||||
if use_color && term::color_supported() {
|
||||
term::fg(out, color);
|
||||
}
|
||||
@ -214,7 +214,7 @@ fn run_tests_console(opts: test_opts,
|
||||
}
|
||||
|
||||
fn print_failures(st: console_test_state) {
|
||||
st.out.write_line("\nfailures:");
|
||||
st.out.write_line(~"\nfailures:");
|
||||
let failures = copy st.failures;
|
||||
let failures = vec::map(failures, |test| test.name);
|
||||
let failures = sort::merge_sort(str::le, failures);
|
||||
@ -229,14 +229,14 @@ fn should_sort_failures_before_printing_them() {
|
||||
let writer = io::mem_buffer_writer(buffer);
|
||||
|
||||
let test_a = {
|
||||
name: "a",
|
||||
name: ~"a",
|
||||
fn: fn~() { },
|
||||
ignore: false,
|
||||
should_fail: false
|
||||
};
|
||||
|
||||
let test_b = {
|
||||
name: "b",
|
||||
name: ~"b",
|
||||
fn: fn~() { },
|
||||
ignore: false,
|
||||
should_fail: false
|
||||
@ -256,8 +256,8 @@ fn should_sort_failures_before_printing_them() {
|
||||
|
||||
let s = io::mem_buffer_str(buffer);
|
||||
|
||||
let apos = option::get(str::find_str(s, "a"));
|
||||
let bpos = option::get(str::find_str(s, "b"));
|
||||
let apos = option::get(str::find_str(s, ~"a"));
|
||||
let bpos = option::get(str::find_str(s, ~"b"));
|
||||
assert apos < bpos;
|
||||
}
|
||||
|
||||
@ -339,10 +339,10 @@ fn filter_tests(opts: test_opts,
|
||||
let filter_str =
|
||||
alt opts.filter {
|
||||
option::some(f) { f }
|
||||
option::none { "" }
|
||||
option::none { ~"" }
|
||||
};
|
||||
|
||||
fn filter_fn(test: test_desc, filter_str: str) ->
|
||||
fn filter_fn(test: test_desc, filter_str: ~str) ->
|
||||
option<test_desc> {
|
||||
if str::contains(test.name, filter_str) {
|
||||
ret option::some(copy test);
|
||||
@ -419,7 +419,7 @@ mod tests {
|
||||
fn do_not_run_ignored_tests() {
|
||||
fn f() { fail; }
|
||||
let desc = {
|
||||
name: "whatever",
|
||||
name: ~"whatever",
|
||||
fn: f,
|
||||
ignore: true,
|
||||
should_fail: false
|
||||
@ -435,7 +435,7 @@ mod tests {
|
||||
fn ignored_tests_result_in_ignored() {
|
||||
fn f() { }
|
||||
let desc = {
|
||||
name: "whatever",
|
||||
name: ~"whatever",
|
||||
fn: f,
|
||||
ignore: true,
|
||||
should_fail: false
|
||||
@ -452,7 +452,7 @@ mod tests {
|
||||
fn test_should_fail() {
|
||||
fn f() { fail; }
|
||||
let desc = {
|
||||
name: "whatever",
|
||||
name: ~"whatever",
|
||||
fn: f,
|
||||
ignore: false,
|
||||
should_fail: true
|
||||
@ -468,7 +468,7 @@ mod tests {
|
||||
fn test_should_fail_but_succeeds() {
|
||||
fn f() { }
|
||||
let desc = {
|
||||
name: "whatever",
|
||||
name: ~"whatever",
|
||||
fn: f,
|
||||
ignore: false,
|
||||
should_fail: true
|
||||
@ -482,17 +482,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn first_free_arg_should_be_a_filter() {
|
||||
let args = ~["progname", "filter"];
|
||||
let args = ~[~"progname", ~"filter"];
|
||||
let opts = alt parse_opts(args) { either::left(o) { o }
|
||||
_ { fail "Malformed arg in first_free_arg_should_be_a_filter"; } };
|
||||
assert (str::eq("filter", option::get(opts.filter)));
|
||||
_ { fail ~"Malformed arg in first_free_arg_should_be_a_filter"; } };
|
||||
assert (str::eq(~"filter", option::get(opts.filter)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_ignored_flag() {
|
||||
let args = ~["progname", "filter", "--ignored"];
|
||||
let args = ~[~"progname", ~"filter", ~"--ignored"];
|
||||
let opts = alt parse_opts(args) { either::left(o) { o }
|
||||
_ { fail "Malformed arg in parse_ignored_flag"; } };
|
||||
_ { fail ~"Malformed arg in parse_ignored_flag"; } };
|
||||
assert (opts.run_ignored);
|
||||
}
|
||||
|
||||
@ -504,12 +504,12 @@ mod tests {
|
||||
let opts = {filter: option::none, run_ignored: true,
|
||||
logfile: option::none};
|
||||
let tests =
|
||||
~[{name: "1", fn: fn~() { }, ignore: true, should_fail: false},
|
||||
{name: "2", fn: fn~() { }, ignore: false, should_fail: false}];
|
||||
~[{name: ~"1", fn: fn~() { }, ignore: true, should_fail: false},
|
||||
{name: ~"2", fn: fn~() { }, ignore: false, should_fail: false}];
|
||||
let filtered = filter_tests(opts, tests);
|
||||
|
||||
assert (vec::len(filtered) == 1u);
|
||||
assert (filtered[0].name == "1");
|
||||
assert (filtered[0].name == ~"1");
|
||||
assert (filtered[0].ignore == false);
|
||||
}
|
||||
|
||||
@ -519,12 +519,12 @@ mod tests {
|
||||
logfile: option::none};
|
||||
|
||||
let names =
|
||||
~["sha1::test", "int::test_to_str", "int::test_pow",
|
||||
"test::do_not_run_ignored_tests",
|
||||
"test::ignored_tests_result_in_ignored",
|
||||
"test::first_free_arg_should_be_a_filter",
|
||||
"test::parse_ignored_flag", "test::filter_for_ignored_option",
|
||||
"test::sort_tests"];
|
||||
~[~"sha1::test", ~"int::test_to_str", ~"int::test_pow",
|
||||
~"test::do_not_run_ignored_tests",
|
||||
~"test::ignored_tests_result_in_ignored",
|
||||
~"test::first_free_arg_should_be_a_filter",
|
||||
~"test::parse_ignored_flag", ~"test::filter_for_ignored_option",
|
||||
~"test::sort_tests"];
|
||||
let tests =
|
||||
{
|
||||
let testfn = fn~() { };
|
||||
@ -539,11 +539,13 @@ mod tests {
|
||||
let filtered = filter_tests(opts, tests);
|
||||
|
||||
let expected =
|
||||
~["int::test_pow", "int::test_to_str", "sha1::test",
|
||||
"test::do_not_run_ignored_tests", "test::filter_for_ignored_option",
|
||||
"test::first_free_arg_should_be_a_filter",
|
||||
"test::ignored_tests_result_in_ignored", "test::parse_ignored_flag",
|
||||
"test::sort_tests"];
|
||||
~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",
|
||||
~"test::do_not_run_ignored_tests",
|
||||
~"test::filter_for_ignored_option",
|
||||
~"test::first_free_arg_should_be_a_filter",
|
||||
~"test::ignored_tests_result_in_ignored",
|
||||
~"test::parse_ignored_flag",
|
||||
~"test::sort_tests"];
|
||||
|
||||
let pairs = vec::zip(expected, filtered);
|
||||
|
||||
|
@ -76,7 +76,7 @@ type tm = {
|
||||
tm_yday: i32, // days since January 1 ~[0-365]
|
||||
tm_isdst: i32, // Daylight Savings Time flag
|
||||
tm_gmtoff: i32, // offset from UTC in seconds
|
||||
tm_zone: str, // timezone abbreviation
|
||||
tm_zone: ~str, // timezone abbreviation
|
||||
tm_nsec: i32, // nanoseconds
|
||||
};
|
||||
|
||||
@ -92,7 +92,7 @@ fn empty_tm() -> tm {
|
||||
tm_yday: 0_i32,
|
||||
tm_isdst: 0_i32,
|
||||
tm_gmtoff: 0_i32,
|
||||
tm_zone: "",
|
||||
tm_zone: ~"",
|
||||
tm_nsec: 0_i32,
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ fn now() -> tm {
|
||||
}
|
||||
|
||||
/// Parses the time from the string according to the format string.
|
||||
fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
|
||||
type tm_mut = {
|
||||
mut tm_sec: i32,
|
||||
mut tm_min: i32,
|
||||
@ -136,11 +136,11 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
mut tm_yday: i32,
|
||||
mut tm_isdst: i32,
|
||||
mut tm_gmtoff: i32,
|
||||
mut tm_zone: str,
|
||||
mut tm_zone: ~str,
|
||||
mut tm_nsec: i32,
|
||||
};
|
||||
|
||||
fn match_str(s: str, pos: uint, needle: str) -> bool {
|
||||
fn match_str(s: ~str, pos: uint, needle: ~str) -> bool {
|
||||
let mut i = pos;
|
||||
for str::each(needle) |ch| {
|
||||
if s[i] != ch {
|
||||
@ -151,7 +151,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn match_strs(s: str, pos: uint, strs: ~[(str, i32)])
|
||||
fn match_strs(s: ~str, pos: uint, strs: ~[(~str, i32)])
|
||||
-> option<(i32, uint)> {
|
||||
let mut i = 0u;
|
||||
let len = vec::len(strs);
|
||||
@ -167,7 +167,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
none
|
||||
}
|
||||
|
||||
fn match_digits(s: str, pos: uint, digits: uint, ws: bool)
|
||||
fn match_digits(s: ~str, pos: uint, digits: uint, ws: bool)
|
||||
-> option<(i32, uint)> {
|
||||
let mut pos = pos;
|
||||
let mut value = 0_i32;
|
||||
@ -190,7 +190,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
some((value, pos))
|
||||
}
|
||||
|
||||
fn parse_char(s: str, pos: uint, c: char) -> result<uint, str> {
|
||||
fn parse_char(s: ~str, pos: uint, c: char) -> result<uint, ~str> {
|
||||
let {ch, next} = str::char_range_at(s, pos);
|
||||
|
||||
if c == ch {
|
||||
@ -202,73 +202,73 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_type(s: str, pos: uint, ch: char, tm: tm_mut)
|
||||
-> result<uint, str> {
|
||||
fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut)
|
||||
-> result<uint, ~str> {
|
||||
alt ch {
|
||||
'A' {
|
||||
alt match_strs(s, pos, ~[
|
||||
("Sunday", 0_i32),
|
||||
("Monday", 1_i32),
|
||||
("Tuesday", 2_i32),
|
||||
("Wednesday", 3_i32),
|
||||
("Thursday", 4_i32),
|
||||
("Friday", 5_i32),
|
||||
("Saturday", 6_i32)
|
||||
(~"Sunday", 0_i32),
|
||||
(~"Monday", 1_i32),
|
||||
(~"Tuesday", 2_i32),
|
||||
(~"Wednesday", 3_i32),
|
||||
(~"Thursday", 4_i32),
|
||||
(~"Friday", 5_i32),
|
||||
(~"Saturday", 6_i32)
|
||||
]) {
|
||||
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, ~[
|
||||
("Sun", 0_i32),
|
||||
("Mon", 1_i32),
|
||||
("Tue", 2_i32),
|
||||
("Wed", 3_i32),
|
||||
("Thu", 4_i32),
|
||||
("Fri", 5_i32),
|
||||
("Sat", 6_i32)
|
||||
(~"Sun", 0_i32),
|
||||
(~"Mon", 1_i32),
|
||||
(~"Tue", 2_i32),
|
||||
(~"Wed", 3_i32),
|
||||
(~"Thu", 4_i32),
|
||||
(~"Fri", 5_i32),
|
||||
(~"Sat", 6_i32)
|
||||
]) {
|
||||
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, ~[
|
||||
("January", 0_i32),
|
||||
("February", 1_i32),
|
||||
("March", 2_i32),
|
||||
("April", 3_i32),
|
||||
("May", 4_i32),
|
||||
("June", 5_i32),
|
||||
("July", 6_i32),
|
||||
("August", 7_i32),
|
||||
("September", 8_i32),
|
||||
("October", 9_i32),
|
||||
("November", 10_i32),
|
||||
("December", 11_i32)
|
||||
(~"January", 0_i32),
|
||||
(~"February", 1_i32),
|
||||
(~"March", 2_i32),
|
||||
(~"April", 3_i32),
|
||||
(~"May", 4_i32),
|
||||
(~"June", 5_i32),
|
||||
(~"July", 6_i32),
|
||||
(~"August", 7_i32),
|
||||
(~"September", 8_i32),
|
||||
(~"October", 9_i32),
|
||||
(~"November", 10_i32),
|
||||
(~"December", 11_i32)
|
||||
]) {
|
||||
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, ~[
|
||||
("Jan", 0_i32),
|
||||
("Feb", 1_i32),
|
||||
("Mar", 2_i32),
|
||||
("Apr", 3_i32),
|
||||
("May", 4_i32),
|
||||
("Jun", 5_i32),
|
||||
("Jul", 6_i32),
|
||||
("Aug", 7_i32),
|
||||
("Sep", 8_i32),
|
||||
("Oct", 9_i32),
|
||||
("Nov", 10_i32),
|
||||
("Dec", 11_i32)
|
||||
(~"Jan", 0_i32),
|
||||
(~"Feb", 1_i32),
|
||||
(~"Mar", 2_i32),
|
||||
(~"Apr", 3_i32),
|
||||
(~"May", 4_i32),
|
||||
(~"Jun", 5_i32),
|
||||
(~"Jul", 6_i32),
|
||||
(~"Aug", 7_i32),
|
||||
(~"Sep", 8_i32),
|
||||
(~"Oct", 9_i32),
|
||||
(~"Nov", 10_i32),
|
||||
(~"Dec", 11_i32)
|
||||
]) {
|
||||
some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
|
||||
none { err("Invalid month") }
|
||||
none { err(~"Invalid month") }
|
||||
}
|
||||
}
|
||||
'C' {
|
||||
@ -278,7 +278,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_year += (v * 100_i32) - 1900_i32;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid year") }
|
||||
none { err(~"Invalid year") }
|
||||
}
|
||||
}
|
||||
'c' {
|
||||
@ -302,13 +302,13 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
'd' {
|
||||
alt match_digits(s, pos, 2u, false) {
|
||||
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) {
|
||||
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") }
|
||||
}
|
||||
}
|
||||
'F' {
|
||||
@ -322,7 +322,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
// FIXME (#2350): range check.
|
||||
alt match_digits(s, pos, 2u, false) {
|
||||
some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
|
||||
none { err("Invalid hour") }
|
||||
none { err(~"Invalid hour") }
|
||||
}
|
||||
}
|
||||
'I' {
|
||||
@ -333,7 +333,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid hour") }
|
||||
none { err(~"Invalid hour") }
|
||||
}
|
||||
}
|
||||
'j' {
|
||||
@ -344,14 +344,14 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_yday = v - 1_i32;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid year") }
|
||||
none { err(~"Invalid year") }
|
||||
}
|
||||
}
|
||||
'k' {
|
||||
// FIXME (#2350): range check.
|
||||
alt match_digits(s, pos, 2u, true) {
|
||||
some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
|
||||
none { err("Invalid hour") }
|
||||
none { err(~"Invalid hour") }
|
||||
}
|
||||
}
|
||||
'l' {
|
||||
@ -362,14 +362,14 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid hour") }
|
||||
none { err(~"Invalid hour") }
|
||||
}
|
||||
}
|
||||
'M' {
|
||||
// FIXME (#2350): range check.
|
||||
alt match_digits(s, pos, 2u, false) {
|
||||
some(item) { let (v, pos) = item; tm.tm_min = v; ok(pos) }
|
||||
none { err("Invalid minute") }
|
||||
none { err(~"Invalid minute") }
|
||||
}
|
||||
}
|
||||
'm' {
|
||||
@ -380,20 +380,20 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_mon = v - 1_i32;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid month") }
|
||||
none { err(~"Invalid month") }
|
||||
}
|
||||
}
|
||||
'n' { parse_char(s, pos, '\n') }
|
||||
'P' {
|
||||
alt match_strs(s, pos, ~[("am", 0_i32), ("pm", 12_i32)]) {
|
||||
alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) {
|
||||
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)]) {
|
||||
alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) {
|
||||
some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
|
||||
none { err("Invalid hour") }
|
||||
none { err(~"Invalid hour") }
|
||||
}
|
||||
}
|
||||
'R' {
|
||||
@ -418,7 +418,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_sec = v;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid second") }
|
||||
none { err(~"Invalid second") }
|
||||
}
|
||||
}
|
||||
//'s' {}
|
||||
@ -438,7 +438,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_wday = v;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid weekday") }
|
||||
none { err(~"Invalid weekday") }
|
||||
}
|
||||
}
|
||||
'v' {
|
||||
@ -453,7 +453,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
// FIXME (#2350): range check.
|
||||
alt match_digits(s, pos, 1u, false) {
|
||||
some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
|
||||
none { err("Invalid weekday") }
|
||||
none { err(~"Invalid weekday") }
|
||||
}
|
||||
}
|
||||
//'X' {}
|
||||
@ -466,7 +466,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_year = v - 1900_i32;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid weekday") }
|
||||
none { err(~"Invalid weekday") }
|
||||
}
|
||||
}
|
||||
'y' {
|
||||
@ -477,13 +477,13 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
tm.tm_year = v - 1900_i32;
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid weekday") }
|
||||
none { err(~"Invalid weekday") }
|
||||
}
|
||||
}
|
||||
'Z' {
|
||||
if match_str(s, pos, "UTC") || match_str(s, pos, "GMT") {
|
||||
if match_str(s, pos, ~"UTC") || match_str(s, pos, ~"GMT") {
|
||||
tm.tm_gmtoff = 0_i32;
|
||||
tm.tm_zone = "UTC";
|
||||
tm.tm_zone = ~"UTC";
|
||||
ok(pos + 3u)
|
||||
} else {
|
||||
// It's odd, but to maintain compatibility with c's
|
||||
@ -508,15 +508,15 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
let (v, pos) = item;
|
||||
if v == 0_i32 {
|
||||
tm.tm_gmtoff = 0_i32;
|
||||
tm.tm_zone = "UTC";
|
||||
tm.tm_zone = ~"UTC";
|
||||
}
|
||||
|
||||
ok(pos)
|
||||
}
|
||||
none { err("Invalid zone offset") }
|
||||
none { err(~"Invalid zone offset") }
|
||||
}
|
||||
} else {
|
||||
err("Invalid zone offset")
|
||||
err(~"Invalid zone offset")
|
||||
}
|
||||
}
|
||||
'%' { parse_char(s, pos, '%') }
|
||||
@ -538,12 +538,12 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
mut tm_yday: 0_i32,
|
||||
mut tm_isdst: 0_i32,
|
||||
mut tm_gmtoff: 0_i32,
|
||||
mut tm_zone: "",
|
||||
mut tm_zone: ~"",
|
||||
mut tm_nsec: 0_i32,
|
||||
};
|
||||
let mut pos = 0u;
|
||||
let len = str::len(s);
|
||||
let mut result = err("Invalid time");
|
||||
let mut result = err(~"Invalid time");
|
||||
|
||||
while !rdr.eof() && pos < len {
|
||||
let {ch, next} = str::char_range_at(s, pos);
|
||||
@ -581,62 +581,62 @@ fn strptime(s: str, format: str) -> result<tm, str> {
|
||||
}
|
||||
}
|
||||
|
||||
fn strftime(format: str, tm: tm) -> str {
|
||||
fn parse_type(ch: char, tm: tm) -> str {
|
||||
fn strftime(format: ~str, tm: tm) -> ~str {
|
||||
fn parse_type(ch: char, tm: tm) -> ~str {
|
||||
//FIXME (#2350): Implement missing types.
|
||||
alt check ch {
|
||||
'A' {
|
||||
alt check tm.tm_wday as int {
|
||||
0 { "Sunday" }
|
||||
1 { "Monday" }
|
||||
2 { "Tuesday" }
|
||||
3 { "Wednesday" }
|
||||
4 { "Thursday" }
|
||||
5 { "Friday" }
|
||||
6 { "Saturday" }
|
||||
0 { ~"Sunday" }
|
||||
1 { ~"Monday" }
|
||||
2 { ~"Tuesday" }
|
||||
3 { ~"Wednesday" }
|
||||
4 { ~"Thursday" }
|
||||
5 { ~"Friday" }
|
||||
6 { ~"Saturday" }
|
||||
}
|
||||
}
|
||||
'a' {
|
||||
alt check tm.tm_wday as int {
|
||||
0 { "Sun" }
|
||||
1 { "Mon" }
|
||||
2 { "Tue" }
|
||||
3 { "Wed" }
|
||||
4 { "Thu" }
|
||||
5 { "Fri" }
|
||||
6 { "Sat" }
|
||||
0 { ~"Sun" }
|
||||
1 { ~"Mon" }
|
||||
2 { ~"Tue" }
|
||||
3 { ~"Wed" }
|
||||
4 { ~"Thu" }
|
||||
5 { ~"Fri" }
|
||||
6 { ~"Sat" }
|
||||
}
|
||||
}
|
||||
'B' {
|
||||
alt check tm.tm_mon as int {
|
||||
0 { "January" }
|
||||
1 { "February" }
|
||||
2 { "March" }
|
||||
3 { "April" }
|
||||
4 { "May" }
|
||||
5 { "June" }
|
||||
6 { "July" }
|
||||
7 { "August" }
|
||||
8 { "September" }
|
||||
9 { "October" }
|
||||
10 { "November" }
|
||||
11 { "December" }
|
||||
0 { ~"January" }
|
||||
1 { ~"February" }
|
||||
2 { ~"March" }
|
||||
3 { ~"April" }
|
||||
4 { ~"May" }
|
||||
5 { ~"June" }
|
||||
6 { ~"July" }
|
||||
7 { ~"August" }
|
||||
8 { ~"September" }
|
||||
9 { ~"October" }
|
||||
10 { ~"November" }
|
||||
11 { ~"December" }
|
||||
}
|
||||
}
|
||||
'b' | 'h' {
|
||||
alt check tm.tm_mon as int {
|
||||
0 { "Jan" }
|
||||
1 { "Feb" }
|
||||
2 { "Mar" }
|
||||
3 { "Apr" }
|
||||
4 { "May" }
|
||||
5 { "Jun" }
|
||||
6 { "Jul" }
|
||||
7 { "Aug" }
|
||||
8 { "Sep" }
|
||||
9 { "Oct" }
|
||||
10 { "Nov" }
|
||||
11 { "Dec" }
|
||||
0 { ~"Jan" }
|
||||
1 { ~"Feb" }
|
||||
2 { ~"Mar" }
|
||||
3 { ~"Apr" }
|
||||
4 { ~"May" }
|
||||
5 { ~"Jun" }
|
||||
6 { ~"Jul" }
|
||||
7 { ~"Aug" }
|
||||
8 { ~"Sep" }
|
||||
9 { ~"Oct" }
|
||||
10 { ~"Nov" }
|
||||
11 { ~"Dec" }
|
||||
}
|
||||
}
|
||||
'C' { #fmt("%02d", (tm.tm_year as int + 1900) / 100) }
|
||||
@ -681,9 +681,9 @@ fn strftime(format: str, tm: tm) -> str {
|
||||
}
|
||||
'M' { #fmt("%02d", tm.tm_min as int) }
|
||||
'm' { #fmt("%02d", tm.tm_mon as int + 1) }
|
||||
'n' { "\n" }
|
||||
'P' { if tm.tm_hour as int < 12 { "am" } else { "pm" } }
|
||||
'p' { if tm.tm_hour as int < 12 { "AM" } else { "PM" } }
|
||||
'n' { ~"\n" }
|
||||
'P' { if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" } }
|
||||
'p' { if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" } }
|
||||
'R' {
|
||||
#fmt("%s:%s",
|
||||
parse_type('H', tm),
|
||||
@ -704,7 +704,7 @@ fn strftime(format: str, tm: tm) -> str {
|
||||
parse_type('M', tm),
|
||||
parse_type('S', tm))
|
||||
}
|
||||
't' { "\t" }
|
||||
't' { ~"\t" }
|
||||
//'U' {}
|
||||
'u' {
|
||||
let i = tm.tm_wday as int;
|
||||
@ -732,11 +732,11 @@ fn strftime(format: str, tm: tm) -> str {
|
||||
#fmt("%c%02d%02d", sign, h as int, m as int)
|
||||
}
|
||||
//'+' {}
|
||||
'%' { "%" }
|
||||
'%' { ~"%" }
|
||||
}
|
||||
}
|
||||
|
||||
let mut buf = "";
|
||||
let mut buf = ~"";
|
||||
|
||||
do io::with_str_reader(format) |rdr| {
|
||||
while !rdr.eof() {
|
||||
@ -776,10 +776,10 @@ impl tm for tm {
|
||||
* Return a string of the current time in the form
|
||||
* "Thu Jan 1 00:00:00 1970".
|
||||
*/
|
||||
fn ctime() -> str { self.strftime("%c") }
|
||||
fn ctime() -> ~str { self.strftime(~"%c") }
|
||||
|
||||
/// Formats the time according to the format string.
|
||||
fn strftime(format: str) -> str { strftime(format, self) }
|
||||
fn strftime(format: ~str) -> ~str { strftime(format, self) }
|
||||
|
||||
/**
|
||||
* Returns a time string formatted according to RFC 822.
|
||||
@ -787,11 +787,11 @@ impl tm for tm {
|
||||
* local: "Thu, 22 Mar 2012 07:53:18 PST"
|
||||
* utc: "Thu, 22 Mar 2012 14:53:18 UTC"
|
||||
*/
|
||||
fn rfc822() -> str {
|
||||
fn rfc822() -> ~str {
|
||||
if self.tm_gmtoff == 0_i32 {
|
||||
self.strftime("%a, %d %b %Y %T GMT")
|
||||
self.strftime(~"%a, %d %b %Y %T GMT")
|
||||
} else {
|
||||
self.strftime("%a, %d %b %Y %T %Z")
|
||||
self.strftime(~"%a, %d %b %Y %T %Z")
|
||||
}
|
||||
}
|
||||
|
||||
@ -801,8 +801,8 @@ impl tm for tm {
|
||||
* local: "Thu, 22 Mar 2012 07:53:18 -0700"
|
||||
* utc: "Thu, 22 Mar 2012 14:53:18 -0000"
|
||||
*/
|
||||
fn rfc822z() -> str {
|
||||
self.strftime("%a, %d %b %Y %T %z")
|
||||
fn rfc822z() -> ~str {
|
||||
self.strftime(~"%a, %d %b %Y %T %z")
|
||||
}
|
||||
|
||||
/**
|
||||
@ -811,11 +811,11 @@ impl tm for tm {
|
||||
* local: "2012-02-22T07:53:18-07:00"
|
||||
* utc: "2012-02-22T14:53:18Z"
|
||||
*/
|
||||
fn rfc3339() -> str {
|
||||
fn rfc3339() -> ~str {
|
||||
if self.tm_gmtoff == 0_i32 {
|
||||
self.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
self.strftime(~"%Y-%m-%dT%H:%M:%SZ")
|
||||
} else {
|
||||
let s = self.strftime("%Y-%m-%dT%H:%M:%S");
|
||||
let s = self.strftime(~"%Y-%m-%dT%H:%M:%S");
|
||||
let sign = if self.tm_gmtoff > 0_i32 { '+' } else { '-' };
|
||||
let mut m = i32::abs(self.tm_gmtoff) / 60_i32;
|
||||
let h = m / 60_i32;
|
||||
@ -835,15 +835,15 @@ mod tests {
|
||||
const some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
|
||||
|
||||
let tv1 = get_time();
|
||||
log(debug, "tv1=" + uint::str(tv1.sec as uint) + " sec + "
|
||||
+ uint::str(tv1.nsec as uint) + " nsec");
|
||||
log(debug, ~"tv1=" + uint::str(tv1.sec as uint) + ~" sec + "
|
||||
+ uint::str(tv1.nsec as uint) + ~" nsec");
|
||||
|
||||
assert tv1.sec > some_recent_date;
|
||||
assert tv1.nsec < 1000000000i32;
|
||||
|
||||
let tv2 = get_time();
|
||||
log(debug, "tv2=" + uint::str(tv2.sec as uint) + " sec + "
|
||||
+ uint::str(tv2.nsec as uint) + " nsec");
|
||||
log(debug, ~"tv2=" + uint::str(tv2.sec as uint) + ~" sec + "
|
||||
+ uint::str(tv2.nsec as uint) + ~" nsec");
|
||||
|
||||
assert tv2.sec >= tv1.sec;
|
||||
assert tv2.sec < some_future_date;
|
||||
@ -858,22 +858,22 @@ mod tests {
|
||||
let s0 = precise_time_s();
|
||||
let ns1 = precise_time_ns();
|
||||
|
||||
log(debug, "s0=" + float::to_str(s0, 9u) + " sec");
|
||||
log(debug, ~"s0=" + float::to_str(s0, 9u) + ~" sec");
|
||||
assert s0 > 0.;
|
||||
let ns0 = (s0 * 1000000000.) as u64;
|
||||
log(debug, "ns0=" + u64::str(ns0) + " ns");
|
||||
log(debug, ~"ns0=" + u64::str(ns0) + ~" ns");
|
||||
|
||||
log(debug, "ns1=" + u64::str(ns1) + " ns");
|
||||
log(debug, ~"ns1=" + u64::str(ns1) + ~" ns");
|
||||
assert ns1 >= ns0;
|
||||
|
||||
let ns2 = precise_time_ns();
|
||||
log(debug, "ns2=" + u64::str(ns2) + " ns");
|
||||
log(debug, ~"ns2=" + u64::str(ns2) + ~" ns");
|
||||
assert ns2 >= ns1;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_at_utc() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
|
||||
@ -889,13 +889,13 @@ mod tests {
|
||||
assert utc.tm_yday == 43_i32;
|
||||
assert utc.tm_isdst == 0_i32;
|
||||
assert utc.tm_gmtoff == 0_i32;
|
||||
assert utc.tm_zone == "UTC";
|
||||
assert utc.tm_zone == ~"UTC";
|
||||
assert utc.tm_nsec == 54321_i32;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_at() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
|
||||
@ -917,14 +917,14 @@ mod tests {
|
||||
// FIXME (#2350): We should probably standardize on the timezone
|
||||
// abbreviation.
|
||||
let zone = local.tm_zone;
|
||||
assert zone == "PST" || zone == "Pacific Standard Time";
|
||||
assert zone == ~"PST" || zone == ~"Pacific Standard Time";
|
||||
|
||||
assert local.tm_nsec == 54321_i32;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_timespec() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
|
||||
@ -936,7 +936,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_conversions() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
|
||||
@ -953,10 +953,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_strptime() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
alt strptime("", "") {
|
||||
alt strptime(~"", ~"") {
|
||||
ok(tm) {
|
||||
assert tm.tm_sec == 0_i32;
|
||||
assert tm.tm_min == 0_i32;
|
||||
@ -967,17 +967,18 @@ mod tests {
|
||||
assert tm.tm_wday == 0_i32;
|
||||
assert tm.tm_isdst== 0_i32;
|
||||
assert tm.tm_gmtoff == 0_i32;
|
||||
assert tm.tm_zone == "";
|
||||
assert tm.tm_zone == ~"";
|
||||
assert tm.tm_nsec == 0_i32;
|
||||
}
|
||||
err(_) {}
|
||||
}
|
||||
|
||||
let format = "%a %b %e %T %Y";
|
||||
assert strptime("", format) == err("Invalid time");
|
||||
assert strptime("Fri Feb 13 15:31:30", format) == err("Invalid time");
|
||||
let format = ~"%a %b %e %T %Y";
|
||||
assert strptime(~"", format) == err(~"Invalid time");
|
||||
assert strptime(~"Fri Feb 13 15:31:30", format)
|
||||
== err(~"Invalid time");
|
||||
|
||||
alt strptime("Fri Feb 13 15:31:30 2009", format) {
|
||||
alt strptime(~"Fri Feb 13 15:31:30 2009", format) {
|
||||
err(e) { fail e }
|
||||
ok(tm) {
|
||||
assert tm.tm_sec == 30_i32;
|
||||
@ -990,12 +991,12 @@ mod tests {
|
||||
assert tm.tm_yday == 0_i32;
|
||||
assert tm.tm_isdst == 0_i32;
|
||||
assert tm.tm_gmtoff == 0_i32;
|
||||
assert tm.tm_zone == "";
|
||||
assert tm.tm_zone == ~"";
|
||||
assert tm.tm_nsec == 0_i32;
|
||||
}
|
||||
}
|
||||
|
||||
fn test(s: str, format: str) -> bool {
|
||||
fn test(s: ~str, format: ~str) -> bool {
|
||||
alt strptime(s, format) {
|
||||
ok(tm) { tm.strftime(format) == s }
|
||||
err(e) { fail e }
|
||||
@ -1003,103 +1004,103 @@ mod tests {
|
||||
}
|
||||
|
||||
[
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
]/_.iter(|day| assert test(day, "%A"));
|
||||
~"Sunday",
|
||||
~"Monday",
|
||||
~"Tuesday",
|
||||
~"Wednesday",
|
||||
~"Thursday",
|
||||
~"Friday",
|
||||
~"Saturday"
|
||||
]/_.iter(|day| assert test(day, ~"%A"));
|
||||
|
||||
[
|
||||
"Sun",
|
||||
"Mon",
|
||||
"Tue",
|
||||
"Wed",
|
||||
"Thu",
|
||||
"Fri",
|
||||
"Sat"
|
||||
]/_.iter(|day| assert test(day, "%a"));
|
||||
~"Sun",
|
||||
~"Mon",
|
||||
~"Tue",
|
||||
~"Wed",
|
||||
~"Thu",
|
||||
~"Fri",
|
||||
~"Sat"
|
||||
]/_.iter(|day| assert test(day, ~"%a"));
|
||||
|
||||
[
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
]/_.iter(|day| assert test(day, "%B"));
|
||||
~"January",
|
||||
~"February",
|
||||
~"March",
|
||||
~"April",
|
||||
~"May",
|
||||
~"June",
|
||||
~"July",
|
||||
~"August",
|
||||
~"September",
|
||||
~"October",
|
||||
~"November",
|
||||
~"December"
|
||||
]/_.iter(|day| assert test(day, ~"%B"));
|
||||
|
||||
[
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec"
|
||||
]/_.iter(|day| assert test(day, "%b"));
|
||||
~"Jan",
|
||||
~"Feb",
|
||||
~"Mar",
|
||||
~"Apr",
|
||||
~"May",
|
||||
~"Jun",
|
||||
~"Jul",
|
||||
~"Aug",
|
||||
~"Sep",
|
||||
~"Oct",
|
||||
~"Nov",
|
||||
~"Dec"
|
||||
]/_.iter(|day| assert test(day, ~"%b"));
|
||||
|
||||
assert test("19", "%C");
|
||||
assert test("Fri Feb 13 23:31:30 2009", "%c");
|
||||
assert test("02/13/09", "%D");
|
||||
assert test("03", "%d");
|
||||
assert test("13", "%d");
|
||||
assert test(" 3", "%e");
|
||||
assert test("13", "%e");
|
||||
assert test("2009-02-13", "%F");
|
||||
assert test("03", "%H");
|
||||
assert test("13", "%H");
|
||||
assert test("03", "%I"); // FIXME (#2350): flesh out
|
||||
assert test("11", "%I"); // FIXME (#2350): flesh out
|
||||
assert test("044", "%j");
|
||||
assert test(" 3", "%k");
|
||||
assert test("13", "%k");
|
||||
assert test(" 1", "%l");
|
||||
assert test("11", "%l");
|
||||
assert test("03", "%M");
|
||||
assert test("13", "%M");
|
||||
assert test("\n", "%n");
|
||||
assert test("am", "%P");
|
||||
assert test("pm", "%P");
|
||||
assert test("AM", "%p");
|
||||
assert test("PM", "%p");
|
||||
assert test("23:31", "%R");
|
||||
assert test("11:31:30 AM", "%r");
|
||||
assert test("11:31:30 PM", "%r");
|
||||
assert test("03", "%S");
|
||||
assert test("13", "%S");
|
||||
assert test("15:31:30", "%T");
|
||||
assert test("\t", "%t");
|
||||
assert test("1", "%u");
|
||||
assert test("7", "%u");
|
||||
assert test("13-Feb-2009", "%v");
|
||||
assert test("0", "%w");
|
||||
assert test("6", "%w");
|
||||
assert test("2009", "%Y");
|
||||
assert test("09", "%y");
|
||||
assert strptime("UTC", "%Z").get().tm_zone == "UTC";
|
||||
assert strptime("PST", "%Z").get().tm_zone == "";
|
||||
assert strptime("-0000", "%z").get().tm_gmtoff == 0_i32;
|
||||
assert strptime("-0800", "%z").get().tm_gmtoff == 0_i32;
|
||||
assert test("%", "%%");
|
||||
assert test(~"19", ~"%C");
|
||||
assert test(~"Fri Feb 13 23:31:30 2009", ~"%c");
|
||||
assert test(~"02/13/09", ~"%D");
|
||||
assert test(~"03", ~"%d");
|
||||
assert test(~"13", ~"%d");
|
||||
assert test(~" 3", ~"%e");
|
||||
assert test(~"13", ~"%e");
|
||||
assert test(~"2009-02-13", ~"%F");
|
||||
assert test(~"03", ~"%H");
|
||||
assert test(~"13", ~"%H");
|
||||
assert test(~"03", ~"%I"); // FIXME (#2350): flesh out
|
||||
assert test(~"11", ~"%I"); // FIXME (#2350): flesh out
|
||||
assert test(~"044", ~"%j");
|
||||
assert test(~" 3", ~"%k");
|
||||
assert test(~"13", ~"%k");
|
||||
assert test(~" 1", ~"%l");
|
||||
assert test(~"11", ~"%l");
|
||||
assert test(~"03", ~"%M");
|
||||
assert test(~"13", ~"%M");
|
||||
assert test(~"\n", ~"%n");
|
||||
assert test(~"am", ~"%P");
|
||||
assert test(~"pm", ~"%P");
|
||||
assert test(~"AM", ~"%p");
|
||||
assert test(~"PM", ~"%p");
|
||||
assert test(~"23:31", ~"%R");
|
||||
assert test(~"11:31:30 AM", ~"%r");
|
||||
assert test(~"11:31:30 PM", ~"%r");
|
||||
assert test(~"03", ~"%S");
|
||||
assert test(~"13", ~"%S");
|
||||
assert test(~"15:31:30", ~"%T");
|
||||
assert test(~"\t", ~"%t");
|
||||
assert test(~"1", ~"%u");
|
||||
assert test(~"7", ~"%u");
|
||||
assert test(~"13-Feb-2009", ~"%v");
|
||||
assert test(~"0", ~"%w");
|
||||
assert test(~"6", ~"%w");
|
||||
assert test(~"2009", ~"%Y");
|
||||
assert test(~"09", ~"%y");
|
||||
assert strptime(~"UTC", ~"%Z").get().tm_zone == ~"UTC";
|
||||
assert strptime(~"PST", ~"%Z").get().tm_zone == ~"";
|
||||
assert strptime(~"-0000", ~"%z").get().tm_gmtoff == 0_i32;
|
||||
assert strptime(~"-0800", ~"%z").get().tm_gmtoff == 0_i32;
|
||||
assert test(~"%", ~"%%");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ctime() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
|
||||
@ -1108,81 +1109,81 @@ mod tests {
|
||||
|
||||
#error("test_ctime: %? %?", utc.ctime(), local.ctime());
|
||||
|
||||
assert utc.ctime() == "Fri Feb 13 23:31:30 2009";
|
||||
assert local.ctime() == "Fri Feb 13 15:31:30 2009";
|
||||
assert utc.ctime() == ~"Fri Feb 13 23:31:30 2009";
|
||||
assert local.ctime() == ~"Fri Feb 13 15:31:30 2009";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strftime() {
|
||||
os::setenv("TZ", "America/Los_Angeles");
|
||||
os::setenv(~"TZ", ~"America/Los_Angeles");
|
||||
tzset();
|
||||
|
||||
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
|
||||
let utc = at_utc(time);
|
||||
let local = at(time);
|
||||
|
||||
assert local.strftime("") == "";
|
||||
assert local.strftime("%A") == "Friday";
|
||||
assert local.strftime("%a") == "Fri";
|
||||
assert local.strftime("%B") == "February";
|
||||
assert local.strftime("%b") == "Feb";
|
||||
assert local.strftime("%C") == "20";
|
||||
assert local.strftime("%c") == "Fri Feb 13 15:31:30 2009";
|
||||
assert local.strftime("%D") == "02/13/09";
|
||||
assert local.strftime("%d") == "13";
|
||||
assert local.strftime("%e") == "13";
|
||||
assert local.strftime("%F") == "2009-02-13";
|
||||
assert local.strftime(~"") == ~"";
|
||||
assert local.strftime(~"%A") == ~"Friday";
|
||||
assert local.strftime(~"%a") == ~"Fri";
|
||||
assert local.strftime(~"%B") == ~"February";
|
||||
assert local.strftime(~"%b") == ~"Feb";
|
||||
assert local.strftime(~"%C") == ~"20";
|
||||
assert local.strftime(~"%c") == ~"Fri Feb 13 15:31:30 2009";
|
||||
assert local.strftime(~"%D") == ~"02/13/09";
|
||||
assert local.strftime(~"%d") == ~"13";
|
||||
assert local.strftime(~"%e") == ~"13";
|
||||
assert local.strftime(~"%F") == ~"2009-02-13";
|
||||
// assert local.strftime("%G") == "2009";
|
||||
// assert local.strftime("%g") == "09";
|
||||
assert local.strftime("%H") == "15";
|
||||
assert local.strftime("%I") == "03";
|
||||
assert local.strftime("%j") == "044";
|
||||
assert local.strftime("%k") == "15";
|
||||
assert local.strftime("%l") == " 3";
|
||||
assert local.strftime("%M") == "31";
|
||||
assert local.strftime("%m") == "02";
|
||||
assert local.strftime("%n") == "\n";
|
||||
assert local.strftime("%P") == "pm";
|
||||
assert local.strftime("%p") == "PM";
|
||||
assert local.strftime("%R") == "15:31";
|
||||
assert local.strftime("%r") == "03:31:30 PM";
|
||||
assert local.strftime("%S") == "30";
|
||||
assert local.strftime("%s") == "1234567890";
|
||||
assert local.strftime("%T") == "15:31:30";
|
||||
assert local.strftime("%t") == "\t";
|
||||
assert local.strftime(~"%H") == ~"15";
|
||||
assert local.strftime(~"%I") == ~"03";
|
||||
assert local.strftime(~"%j") == ~"044";
|
||||
assert local.strftime(~"%k") == ~"15";
|
||||
assert local.strftime(~"%l") == ~" 3";
|
||||
assert local.strftime(~"%M") == ~"31";
|
||||
assert local.strftime(~"%m") == ~"02";
|
||||
assert local.strftime(~"%n") == ~"\n";
|
||||
assert local.strftime(~"%P") == ~"pm";
|
||||
assert local.strftime(~"%p") == ~"PM";
|
||||
assert local.strftime(~"%R") == ~"15:31";
|
||||
assert local.strftime(~"%r") == ~"03:31:30 PM";
|
||||
assert local.strftime(~"%S") == ~"30";
|
||||
assert local.strftime(~"%s") == ~"1234567890";
|
||||
assert local.strftime(~"%T") == ~"15:31:30";
|
||||
assert local.strftime(~"%t") == ~"\t";
|
||||
// assert local.strftime("%U") == "06";
|
||||
assert local.strftime("%u") == "5";
|
||||
assert local.strftime(~"%u") == ~"5";
|
||||
// assert local.strftime("%V") == "07";
|
||||
assert local.strftime("%v") == "13-Feb-2009";
|
||||
assert local.strftime(~"%v") == ~"13-Feb-2009";
|
||||
// assert local.strftime("%W") == "06";
|
||||
assert local.strftime("%w") == "5";
|
||||
assert local.strftime(~"%w") == ~"5";
|
||||
// handle "%X"
|
||||
// handle "%x"
|
||||
assert local.strftime("%Y") == "2009";
|
||||
assert local.strftime("%y") == "09";
|
||||
assert local.strftime(~"%Y") == ~"2009";
|
||||
assert local.strftime(~"%y") == ~"09";
|
||||
|
||||
// FIXME (#2350): We should probably standardize on the timezone
|
||||
// abbreviation.
|
||||
let zone = local.strftime("%Z");
|
||||
assert zone == "PST" || zone == "Pacific Standard Time";
|
||||
let zone = local.strftime(~"%Z");
|
||||
assert zone == ~"PST" || zone == ~"Pacific Standard Time";
|
||||
|
||||
assert local.strftime("%z") == "-0800";
|
||||
assert local.strftime("%%") == "%";
|
||||
assert local.strftime(~"%z") == ~"-0800";
|
||||
assert local.strftime(~"%%") == ~"%";
|
||||
|
||||
// FIXME (#2350): We should probably standardize on the timezone
|
||||
// abbreviation.
|
||||
let rfc822 = local.rfc822();
|
||||
let prefix = "Fri, 13 Feb 2009 15:31:30 ";
|
||||
assert rfc822 == prefix + "PST" ||
|
||||
rfc822 == prefix + "Pacific Standard Time";
|
||||
let prefix = ~"Fri, 13 Feb 2009 15:31:30 ";
|
||||
assert rfc822 == prefix + ~"PST" ||
|
||||
rfc822 == prefix + ~"Pacific Standard Time";
|
||||
|
||||
assert local.ctime() == "Fri Feb 13 15:31:30 2009";
|
||||
assert local.rfc822z() == "Fri, 13 Feb 2009 15:31:30 -0800";
|
||||
assert local.rfc3339() == "2009-02-13T15:31:30-08:00";
|
||||
assert local.ctime() == ~"Fri Feb 13 15:31:30 2009";
|
||||
assert local.rfc822z() == ~"Fri, 13 Feb 2009 15:31:30 -0800";
|
||||
assert local.rfc3339() == ~"2009-02-13T15:31:30-08:00";
|
||||
|
||||
assert utc.ctime() == "Fri Feb 13 23:31:30 2009";
|
||||
assert utc.rfc822() == "Fri, 13 Feb 2009 23:31:30 GMT";
|
||||
assert utc.rfc822z() == "Fri, 13 Feb 2009 23:31:30 -0000";
|
||||
assert utc.rfc3339() == "2009-02-13T23:31:30Z";
|
||||
assert utc.ctime() == ~"Fri Feb 13 23:31:30 2009";
|
||||
assert utc.rfc822() == ~"Fri, 13 Feb 2009 23:31:30 GMT";
|
||||
assert utc.rfc822z() == ~"Fri, 13 Feb 2009 23:31:30 -0000";
|
||||
assert utc.rfc3339() == ~"2009-02-13T23:31:30Z";
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,13 @@ fn delayed_send<T: copy send>(iotask: iotask,
|
||||
}
|
||||
else {
|
||||
let error_msg = uv::ll::get_last_err_info(loop_ptr);
|
||||
fail "timer::delayed_send() start failed: "+error_msg;
|
||||
fail ~"timer::delayed_send() start failed: " +
|
||||
error_msg;
|
||||
}
|
||||
}
|
||||
else {
|
||||
let error_msg = uv::ll::get_last_err_info(loop_ptr);
|
||||
fail "timer::delayed_send() init failed: "+error_msg;
|
||||
fail ~"timer::delayed_send() init failed: "+error_msg;
|
||||
}
|
||||
};
|
||||
// delayed_send_cb has been processed by libuv
|
||||
@ -128,7 +129,7 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t,
|
||||
else {
|
||||
let loop_ptr = uv::ll::get_loop_for_uv_handle(handle);
|
||||
let error_msg = uv::ll::get_last_err_info(loop_ptr);
|
||||
fail "timer::sleep() init failed: "+error_msg;
|
||||
fail ~"timer::sleep() init failed: "+error_msg;
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,7 +233,7 @@ mod test {
|
||||
|
||||
for iter::repeat(times as uint) {
|
||||
let expected = rand::rng().gen_str(16u);
|
||||
let test_po = comm::port::<str>();
|
||||
let test_po = comm::port::<~str>();
|
||||
let test_ch = comm::chan(test_po);
|
||||
|
||||
do task::spawn() {
|
||||
|
@ -132,13 +132,13 @@ mod tests {
|
||||
fn u8_map() {
|
||||
let m = treemap();
|
||||
|
||||
let k1 = str::bytes("foo");
|
||||
let k2 = str::bytes("bar");
|
||||
let k1 = str::bytes(~"foo");
|
||||
let k2 = str::bytes(~"bar");
|
||||
|
||||
insert(m, k1, "foo");
|
||||
insert(m, k2, "bar");
|
||||
insert(m, k1, ~"foo");
|
||||
insert(m, k2, ~"bar");
|
||||
|
||||
assert (find(m, k2) == some("bar"));
|
||||
assert (find(m, k1) == some("foo"));
|
||||
assert (find(m, k2) == some(~"bar"));
|
||||
assert (find(m, k1) == some(~"foo"));
|
||||
}
|
||||
}
|
||||
|
@ -118,16 +118,16 @@ mod test {
|
||||
}
|
||||
extern fn simple_timer_cb(timer_ptr: *ll::uv_timer_t,
|
||||
_status: libc::c_int) unsafe {
|
||||
log(debug, "in simple timer cb");
|
||||
log(debug, ~"in simple timer cb");
|
||||
ll::timer_stop(timer_ptr);
|
||||
let hl_loop = get_gl();
|
||||
do iotask::interact(hl_loop) |_loop_ptr| {
|
||||
log(debug, "closing timer");
|
||||
log(debug, ~"closing timer");
|
||||
ll::close(timer_ptr, simple_timer_close_cb);
|
||||
log(debug, "about to deref exit_ch_ptr");
|
||||
log(debug, "after msg sent on deref'd exit_ch");
|
||||
log(debug, ~"about to deref exit_ch_ptr");
|
||||
log(debug, ~"after msg sent on deref'd exit_ch");
|
||||
};
|
||||
log(debug, "exiting simple timer cb");
|
||||
log(debug, ~"exiting simple timer cb");
|
||||
}
|
||||
|
||||
fn impl_uv_hl_simple_timer(iotask: iotask) unsafe {
|
||||
@ -139,7 +139,7 @@ mod test {
|
||||
let timer_handle = ll::timer_t();
|
||||
let timer_ptr = ptr::addr_of(timer_handle);
|
||||
do iotask::interact(iotask) |loop_ptr| {
|
||||
log(debug, "user code inside interact loop!!!");
|
||||
log(debug, ~"user code inside interact loop!!!");
|
||||
let init_status = ll::timer_init(loop_ptr, timer_ptr);
|
||||
if(init_status == 0i32) {
|
||||
ll::set_data_for_uv_handle(
|
||||
@ -150,15 +150,15 @@ mod test {
|
||||
if(start_status == 0i32) {
|
||||
}
|
||||
else {
|
||||
fail "failure on ll::timer_start()";
|
||||
fail ~"failure on ll::timer_start()";
|
||||
}
|
||||
}
|
||||
else {
|
||||
fail "failure on ll::timer_init()";
|
||||
fail ~"failure on ll::timer_init()";
|
||||
}
|
||||
};
|
||||
comm::recv(exit_po);
|
||||
log(debug, "global_loop timer test: msg recv on exit_po, done..");
|
||||
log(debug, ~"global_loop timer test: msg recv on exit_po, done..");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -192,7 +192,7 @@ mod test {
|
||||
for iter::repeat(cycles) {
|
||||
comm::recv(exit_po);
|
||||
};
|
||||
log(debug, "test_stress_gl_uv_global_loop_high_level_global_timer"+
|
||||
" exiting sucessfully!");
|
||||
log(debug, ~"test_stress_gl_uv_global_loop_high_level_global_timer"+
|
||||
~" exiting sucessfully!");
|
||||
}
|
||||
}
|
||||
|
@ -114,10 +114,10 @@ fn run_loop(iotask_ch: chan<iotask>) unsafe {
|
||||
});
|
||||
iotask_ch.send(iotask);
|
||||
|
||||
log(debug, "about to run uv loop");
|
||||
log(debug, ~"about to run uv loop");
|
||||
// enter the loop... this blocks until the loop is done..
|
||||
ll::run(loop_ptr);
|
||||
log(debug, "uv loop ended");
|
||||
log(debug, ~"uv loop ended");
|
||||
ll::loop_delete(loop_ptr);
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ extern fn wake_up_cb(async_handle: *ll::uv_async_t,
|
||||
}
|
||||
|
||||
fn begin_teardown(data: *iotask_loop_data) unsafe {
|
||||
log(debug, "iotask begin_teardown() called, close async_handle");
|
||||
log(debug, ~"iotask begin_teardown() called, close async_handle");
|
||||
let async_handle = (*data).async_handle;
|
||||
ll::close(async_handle as *c_void, tear_down_close_cb);
|
||||
}
|
||||
@ -250,9 +250,9 @@ mod test {
|
||||
for iter::repeat(7u) {
|
||||
comm::recv(work_exit_po);
|
||||
};
|
||||
log(debug, "sending teardown_loop msg..");
|
||||
log(debug, ~"sending teardown_loop msg..");
|
||||
exit(iotask);
|
||||
comm::recv(exit_po);
|
||||
log(debug, "after recv on exit_po.. exiting..");
|
||||
log(debug, ~"after recv on exit_po.. exiting..");
|
||||
}
|
||||
}
|
||||
|
@ -793,7 +793,7 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
|
||||
// yuck :/
|
||||
rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t);
|
||||
//let result = rustrt::rust_uv_buf_init_2(input, len as size_t);
|
||||
log(debug, "after rust_uv_buf_init");
|
||||
log(debug, ~"after rust_uv_buf_init");
|
||||
let res_base = get_base_from_buf(out_buf);
|
||||
let res_len = get_len_from_buf(out_buf);
|
||||
//let res_base = get_base_from_buf(result);
|
||||
@ -803,21 +803,21 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
|
||||
ret out_buf;
|
||||
//ret result;
|
||||
}
|
||||
unsafe fn ip4_addr(ip: str, port: int)
|
||||
unsafe fn ip4_addr(ip: ~str, port: int)
|
||||
-> sockaddr_in {
|
||||
do str::as_c_str(ip) |ip_buf| {
|
||||
rustrt::rust_uv_ip4_addr(ip_buf as *u8,
|
||||
port as libc::c_int)
|
||||
}
|
||||
}
|
||||
unsafe fn ip6_addr(ip: str, port: int)
|
||||
unsafe fn ip6_addr(ip: ~str, port: int)
|
||||
-> sockaddr_in6 {
|
||||
do str::as_c_str(ip) |ip_buf| {
|
||||
rustrt::rust_uv_ip6_addr(ip_buf as *u8,
|
||||
port as libc::c_int)
|
||||
}
|
||||
}
|
||||
unsafe fn ip4_name(src: &sockaddr_in) -> str {
|
||||
unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
|
||||
// ipv4 addr max size: 15 + 1 trailing null byte
|
||||
let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
|
||||
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8];
|
||||
@ -834,7 +834,7 @@ unsafe fn ip4_name(src: &sockaddr_in) -> str {
|
||||
str::unsafe::from_buf(dst_buf)
|
||||
}
|
||||
}
|
||||
unsafe fn ip6_name(src: &sockaddr_in6) -> str {
|
||||
unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
|
||||
// ipv6 addr max size: 45 + 1 trailing null byte
|
||||
let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
|
||||
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
|
||||
@ -854,7 +854,7 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> str {
|
||||
str::unsafe::from_buf(dst_buf)
|
||||
}
|
||||
_ {
|
||||
""
|
||||
~""
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -961,7 +961,7 @@ unsafe fn free_base_of_buf(buf: uv_buf_t) {
|
||||
rustrt::rust_uv_free_base_of_buf(buf);
|
||||
}
|
||||
|
||||
unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> str {
|
||||
unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
|
||||
let err = last_error(uv_loop);
|
||||
let err_ptr = ptr::addr_of(err);
|
||||
let err_name = str::unsafe::from_c_str(err_name(err_ptr));
|
||||
@ -979,8 +979,8 @@ unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data {
|
||||
}
|
||||
|
||||
type uv_err_data = {
|
||||
err_name: str,
|
||||
err_msg: str
|
||||
err_name: ~str,
|
||||
err_msg: ~str
|
||||
};
|
||||
|
||||
unsafe fn is_ipv4_addrinfo(input: *addrinfo) -> bool {
|
||||
@ -1013,7 +1013,7 @@ mod test {
|
||||
type request_wrapper = {
|
||||
write_req: *uv_write_t,
|
||||
req_buf: *~[uv_buf_t],
|
||||
read_chan: *comm::chan<str>
|
||||
read_chan: *comm::chan<~str>
|
||||
};
|
||||
|
||||
extern fn after_close_cb(handle: *libc::c_void) {
|
||||
@ -1024,7 +1024,7 @@ mod test {
|
||||
extern fn on_alloc_cb(handle: *libc::c_void,
|
||||
++suggested_size: libc::size_t)
|
||||
-> uv_buf_t unsafe {
|
||||
log(debug, "on_alloc_cb!");
|
||||
log(debug, ~"on_alloc_cb!");
|
||||
let char_ptr = malloc_buf_base_of(suggested_size);
|
||||
log(debug, #fmt("on_alloc_cb h: %? char_ptr: %u sugsize: %u",
|
||||
handle,
|
||||
@ -1056,15 +1056,15 @@ mod test {
|
||||
}
|
||||
else if (nread == -1) {
|
||||
// err .. possibly EOF
|
||||
log(debug, "read: eof!");
|
||||
log(debug, ~"read: eof!");
|
||||
}
|
||||
else {
|
||||
// nread == 0 .. do nothing, just free buf as below
|
||||
log(debug, "read: do nothing!");
|
||||
log(debug, ~"read: do nothing!");
|
||||
}
|
||||
// when we're done
|
||||
free_base_of_buf(buf);
|
||||
log(debug, "CLIENT exiting on_read_cb");
|
||||
log(debug, ~"CLIENT exiting on_read_cb");
|
||||
}
|
||||
|
||||
extern fn on_write_complete_cb(write_req: *uv_write_t,
|
||||
@ -1086,7 +1086,7 @@ mod test {
|
||||
let stream =
|
||||
get_stream_handle_from_connect_req(connect_req_ptr);
|
||||
if (status == 0i32) {
|
||||
log(debug, "on_connect_cb: in status=0 if..");
|
||||
log(debug, ~"on_connect_cb: in status=0 if..");
|
||||
let client_data = get_data_for_req(
|
||||
connect_req_ptr as *libc::c_void)
|
||||
as *request_wrapper;
|
||||
@ -1107,11 +1107,11 @@ mod test {
|
||||
log(debug, err_msg);
|
||||
assert false;
|
||||
}
|
||||
log(debug, "finishing on_connect_cb");
|
||||
log(debug, ~"finishing on_connect_cb");
|
||||
}
|
||||
|
||||
fn impl_uv_tcp_request(ip: str, port: int, req_str: str,
|
||||
client_chan: *comm::chan<str>) unsafe {
|
||||
fn impl_uv_tcp_request(ip: ~str, port: int, req_str: ~str,
|
||||
client_chan: *comm::chan<~str>) unsafe {
|
||||
let test_loop = loop_new();
|
||||
let tcp_handle = tcp_t();
|
||||
let tcp_handle_ptr = ptr::addr_of(tcp_handle);
|
||||
@ -1143,9 +1143,9 @@ mod test {
|
||||
let tcp_init_result = tcp_init(
|
||||
test_loop as *libc::c_void, tcp_handle_ptr);
|
||||
if (tcp_init_result == 0i32) {
|
||||
log(debug, "sucessful tcp_init_result");
|
||||
log(debug, ~"sucessful tcp_init_result");
|
||||
|
||||
log(debug, "building addr...");
|
||||
log(debug, ~"building addr...");
|
||||
let addr = ip4_addr(ip, port);
|
||||
// FIXME ref #2064
|
||||
let addr_ptr = ptr::addr_of(addr);
|
||||
@ -1167,17 +1167,17 @@ mod test {
|
||||
set_data_for_uv_handle(
|
||||
tcp_handle_ptr as *libc::c_void,
|
||||
ptr::addr_of(client_data) as *libc::c_void);
|
||||
log(debug, "before run tcp req loop");
|
||||
log(debug, ~"before run tcp req loop");
|
||||
run(test_loop);
|
||||
log(debug, "after run tcp req loop");
|
||||
log(debug, ~"after run tcp req loop");
|
||||
}
|
||||
else {
|
||||
log(debug, "tcp_connect() failure");
|
||||
log(debug, ~"tcp_connect() failure");
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(debug, "tcp_init() failure");
|
||||
log(debug, ~"tcp_init() failure");
|
||||
assert false;
|
||||
}
|
||||
loop_delete(test_loop);
|
||||
@ -1191,7 +1191,8 @@ mod test {
|
||||
|
||||
extern fn client_stream_after_close_cb(handle: *libc::c_void)
|
||||
unsafe {
|
||||
log(debug, "SERVER: closed client stream, now closing server stream");
|
||||
log(debug,
|
||||
~"SERVER: closed client stream, now closing server stream");
|
||||
let client_data = get_data_for_uv_handle(
|
||||
handle) as
|
||||
*tcp_server_data;
|
||||
@ -1202,7 +1203,7 @@ mod test {
|
||||
extern fn after_server_resp_write(req: *uv_write_t) unsafe {
|
||||
let client_stream_ptr =
|
||||
get_stream_handle_from_write_req(req);
|
||||
log(debug, "SERVER: resp sent... closing client stream");
|
||||
log(debug, ~"SERVER: resp sent... closing client stream");
|
||||
close(client_stream_ptr as *libc::c_void,
|
||||
client_stream_after_close_cb)
|
||||
}
|
||||
@ -1231,8 +1232,8 @@ mod test {
|
||||
let server_kill_msg = (*client_data).server_kill_msg;
|
||||
let write_req = (*client_data).server_write_req;
|
||||
if (str::contains(request_str, server_kill_msg)) {
|
||||
log(debug, "SERVER: client req contains kill_msg!");
|
||||
log(debug, "SERVER: sending response to client");
|
||||
log(debug, ~"SERVER: client req contains kill_msg!");
|
||||
log(debug, ~"SERVER: sending response to client");
|
||||
read_stop(client_stream_ptr);
|
||||
let server_chan = *((*client_data).server_chan);
|
||||
comm::send(server_chan, request_str);
|
||||
@ -1244,7 +1245,7 @@ mod test {
|
||||
log(debug, #fmt("SERVER: resp write result: %d",
|
||||
write_result as int));
|
||||
if (write_result != 0i32) {
|
||||
log(debug, "bad result for server resp write()");
|
||||
log(debug, ~"bad result for server resp write()");
|
||||
log(debug, get_last_err_info(
|
||||
get_loop_for_uv_handle(client_stream_ptr
|
||||
as *libc::c_void)));
|
||||
@ -1252,26 +1253,26 @@ mod test {
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(debug, "SERVER: client req !contain kill_msg!");
|
||||
log(debug, ~"SERVER: client req !contain kill_msg!");
|
||||
}
|
||||
}
|
||||
else if (nread == -1) {
|
||||
// err .. possibly EOF
|
||||
log(debug, "read: eof!");
|
||||
log(debug, ~"read: eof!");
|
||||
}
|
||||
else {
|
||||
// nread == 0 .. do nothing, just free buf as below
|
||||
log(debug, "read: do nothing!");
|
||||
log(debug, ~"read: do nothing!");
|
||||
}
|
||||
// when we're done
|
||||
free_base_of_buf(buf);
|
||||
log(debug, "SERVER exiting on_read_cb");
|
||||
log(debug, ~"SERVER exiting on_read_cb");
|
||||
}
|
||||
|
||||
extern fn server_connection_cb(server_stream_ptr:
|
||||
*uv_stream_t,
|
||||
status: libc::c_int) unsafe {
|
||||
log(debug, "client connecting!");
|
||||
log(debug, ~"client connecting!");
|
||||
let test_loop = get_loop_for_uv_handle(
|
||||
server_stream_ptr as *libc::c_void);
|
||||
if status != 0i32 {
|
||||
@ -1289,7 +1290,7 @@ mod test {
|
||||
client_stream_ptr as *libc::c_void,
|
||||
server_data as *libc::c_void);
|
||||
if (client_init_result == 0i32) {
|
||||
log(debug, "successfully initialized client stream");
|
||||
log(debug, ~"successfully initialized client stream");
|
||||
let accept_result = accept(server_stream_ptr as
|
||||
*libc::c_void,
|
||||
client_stream_ptr as
|
||||
@ -1301,7 +1302,7 @@ mod test {
|
||||
on_alloc_cb,
|
||||
on_server_read_cb);
|
||||
if (read_result == 0i32) {
|
||||
log(debug, "successful server read start");
|
||||
log(debug, ~"successful server read start");
|
||||
}
|
||||
else {
|
||||
log(debug, #fmt("server_connection_cb: bad read:%d",
|
||||
@ -1325,9 +1326,9 @@ mod test {
|
||||
type tcp_server_data = {
|
||||
client: *uv_tcp_t,
|
||||
server: *uv_tcp_t,
|
||||
server_kill_msg: str,
|
||||
server_kill_msg: ~str,
|
||||
server_resp_buf: *~[uv_buf_t],
|
||||
server_chan: *comm::chan<str>,
|
||||
server_chan: *comm::chan<~str>,
|
||||
server_write_req: *uv_write_t
|
||||
};
|
||||
|
||||
@ -1354,11 +1355,11 @@ mod test {
|
||||
close(async_handle as *libc::c_void, async_close_cb);
|
||||
}
|
||||
|
||||
fn impl_uv_tcp_server(server_ip: str,
|
||||
fn impl_uv_tcp_server(server_ip: ~str,
|
||||
server_port: int,
|
||||
kill_server_msg: str,
|
||||
server_resp_msg: str,
|
||||
server_chan: *comm::chan<str>,
|
||||
kill_server_msg: ~str,
|
||||
server_resp_msg: ~str,
|
||||
server_chan: *comm::chan<~str>,
|
||||
continue_chan: *comm::chan<bool>) unsafe {
|
||||
let test_loop = loop_new();
|
||||
let tcp_server = tcp_t();
|
||||
@ -1408,7 +1409,7 @@ mod test {
|
||||
let bind_result = tcp_bind(tcp_server_ptr,
|
||||
server_addr_ptr);
|
||||
if (bind_result == 0i32) {
|
||||
log(debug, "successful uv_tcp_bind, listening");
|
||||
log(debug, ~"successful uv_tcp_bind, listening");
|
||||
|
||||
// uv_listen()
|
||||
let listen_result = listen(tcp_server_ptr as
|
||||
@ -1428,7 +1429,7 @@ mod test {
|
||||
async_send(continue_async_handle_ptr);
|
||||
// uv_run()
|
||||
run(test_loop);
|
||||
log(debug, "server uv::run() has returned");
|
||||
log(debug, ~"server uv::run() has returned");
|
||||
}
|
||||
else {
|
||||
log(debug, #fmt("uv_async_init failure: %d",
|
||||
@ -1459,15 +1460,15 @@ mod test {
|
||||
// this is the impl for a test that is (maybe) ran on a
|
||||
// per-platform/arch basis below
|
||||
fn impl_uv_tcp_server_and_request() unsafe {
|
||||
let bind_ip = "0.0.0.0";
|
||||
let request_ip = "127.0.0.1";
|
||||
let bind_ip = ~"0.0.0.0";
|
||||
let request_ip = ~"127.0.0.1";
|
||||
let port = 8887;
|
||||
let kill_server_msg = "does a dog have buddha nature?";
|
||||
let server_resp_msg = "mu!";
|
||||
let client_port = comm::port::<str>();
|
||||
let client_chan = comm::chan::<str>(client_port);
|
||||
let server_port = comm::port::<str>();
|
||||
let server_chan = comm::chan::<str>(server_port);
|
||||
let kill_server_msg = ~"does a dog have buddha nature?";
|
||||
let server_resp_msg = ~"mu!";
|
||||
let client_port = comm::port::<~str>();
|
||||
let client_chan = comm::chan::<~str>(client_port);
|
||||
let server_port = comm::port::<~str>();
|
||||
let server_chan = comm::chan::<~str>(server_port);
|
||||
|
||||
let continue_port = comm::port::<bool>();
|
||||
let continue_chan = comm::chan::<bool>(continue_port);
|
||||
@ -1482,9 +1483,9 @@ mod test {
|
||||
};
|
||||
|
||||
// block until the server up is.. possibly a race?
|
||||
log(debug, "before receiving on server continue_port");
|
||||
log(debug, ~"before receiving on server continue_port");
|
||||
comm::recv(continue_port);
|
||||
log(debug, "received on continue port, set up tcp client");
|
||||
log(debug, ~"received on continue port, set up tcp client");
|
||||
|
||||
do task::spawn_sched(task::manual_threads(1u)) {
|
||||
impl_uv_tcp_request(request_ip, port,
|
||||
|
@ -32,7 +32,7 @@ fn deserialize_span<D>(_d: D) -> span {
|
||||
type spanned<T> = {node: T, span: span};
|
||||
|
||||
#[auto_serialize]
|
||||
type ident = @str/~;
|
||||
type ident = @~str;
|
||||
|
||||
// Functions may or may not have names.
|
||||
#[auto_serialize]
|
||||
@ -428,11 +428,11 @@ type lit = spanned<lit_>;
|
||||
|
||||
#[auto_serialize]
|
||||
enum lit_ {
|
||||
lit_str(@str/~),
|
||||
lit_str(@~str),
|
||||
lit_int(i64, int_ty),
|
||||
lit_uint(u64, uint_ty),
|
||||
lit_int_unsuffixed(i64),
|
||||
lit_float(@str/~, float_ty),
|
||||
lit_float(@~str, float_ty),
|
||||
lit_nil,
|
||||
lit_bool(bool),
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ enum path_elt { path_mod(ident), path_name(ident) }
|
||||
type path = ~[path_elt];
|
||||
|
||||
/* 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| {
|
||||
alt e {
|
||||
path_mod(s) { /* FIXME (#2543) */ copy *s }
|
||||
@ -20,7 +20,7 @@ fn path_to_str_with_sep(p: path, sep: str) -> str {
|
||||
str::connect(strs, sep)
|
||||
}
|
||||
|
||||
fn path_ident_to_str(p: path, i: ident) -> str {
|
||||
fn path_ident_to_str(p: path, i: ident) -> ~str {
|
||||
if vec::is_empty(p) {
|
||||
/* FIXME (#2543) */ copy *i
|
||||
} else {
|
||||
@ -28,8 +28,8 @@ fn path_ident_to_str(p: path, i: ident) -> str {
|
||||
}
|
||||
}
|
||||
|
||||
fn path_to_str(p: path) -> str {
|
||||
path_to_str_with_sep(p, "::")
|
||||
fn path_to_str(p: path) -> ~str {
|
||||
path_to_str_with_sep(p, ~"::")
|
||||
}
|
||||
|
||||
enum ast_node {
|
||||
@ -267,7 +267,7 @@ fn map_expr(ex: @expr, cx: ctx, v: vt) {
|
||||
visit::visit_expr(ex, cx, v);
|
||||
}
|
||||
|
||||
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) {
|
||||
none {
|
||||
#fmt["unknown node (id=%d)", id]
|
||||
|
@ -21,11 +21,11 @@ pure fn mk_sp(lo: uint, hi: uint) -> span {
|
||||
// make this a const, once the compiler supports it
|
||||
pure fn dummy_sp() -> span { ret mk_sp(0u, 0u); }
|
||||
|
||||
pure fn path_name(p: @path) -> str { path_name_i(p.idents) }
|
||||
pure fn path_name(p: @path) -> ~str { path_name_i(p.idents) }
|
||||
|
||||
pure fn path_name_i(idents: ~[ident]) -> str {
|
||||
pure fn path_name_i(idents: ~[ident]) -> ~str {
|
||||
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
|
||||
str::connect(idents.map(|i|*i), "::")
|
||||
str::connect(idents.map(|i|*i), ~"::")
|
||||
}
|
||||
|
||||
pure fn path_to_ident(p: @path) -> ident { vec::last(p.idents) }
|
||||
@ -45,7 +45,7 @@ pure fn stmt_id(s: stmt) -> node_id {
|
||||
fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
|
||||
alt d { def_variant(enum_id, var_id) {
|
||||
ret {enm: enum_id, var: var_id}; }
|
||||
_ { fail "non-variant in variant_def_ids"; } }
|
||||
_ { fail ~"non-variant in variant_def_ids"; } }
|
||||
}
|
||||
|
||||
pure fn def_id_of_def(d: def) -> def_id {
|
||||
@ -63,26 +63,26 @@ 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 {
|
||||
add { ret "+"; }
|
||||
subtract { ret "-"; }
|
||||
mul { ret "*"; }
|
||||
div { ret "/"; }
|
||||
rem { ret "%"; }
|
||||
and { ret "&&"; }
|
||||
or { ret "||"; }
|
||||
bitxor { ret "^"; }
|
||||
bitand { ret "&"; }
|
||||
bitor { ret "|"; }
|
||||
shl { ret "<<"; }
|
||||
shr { ret ">>"; }
|
||||
eq { ret "=="; }
|
||||
lt { ret "<"; }
|
||||
le { ret "<="; }
|
||||
ne { ret "!="; }
|
||||
ge { ret ">="; }
|
||||
gt { ret ">"; }
|
||||
add { ret ~"+"; }
|
||||
subtract { ret ~"-"; }
|
||||
mul { ret ~"*"; }
|
||||
div { ret ~"/"; }
|
||||
rem { ret ~"%"; }
|
||||
and { ret ~"&&"; }
|
||||
or { ret ~"||"; }
|
||||
bitxor { ret ~"^"; }
|
||||
bitand { ret ~"&"; }
|
||||
bitor { ret ~"|"; }
|
||||
shl { ret ~"<<"; }
|
||||
shr { ret ~">>"; }
|
||||
eq { ret ~"=="; }
|
||||
lt { ret ~"<"; }
|
||||
le { ret ~"<="; }
|
||||
ne { ret ~"!="; }
|
||||
ge { ret ~">="; }
|
||||
gt { ret ~">"; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,13 +98,13 @@ 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 {
|
||||
box(mt) { if mt == m_mutbl { ret "@mut "; } ret "@"; }
|
||||
uniq(mt) { if mt == m_mutbl { ret "~mut "; } ret "~"; }
|
||||
deref { ret "*"; }
|
||||
not { ret "!"; }
|
||||
neg { ret "-"; }
|
||||
box(mt) { if mt == m_mutbl { ret ~"@mut "; } ret ~"@"; }
|
||||
uniq(mt) { if mt == m_mutbl { ret ~"~mut "; } ret ~"~"; }
|
||||
deref { ret ~"*"; }
|
||||
not { ret ~"!"; }
|
||||
neg { ret ~"-"; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,11 +112,11 @@ pure fn is_path(e: @expr) -> bool {
|
||||
ret alt 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 {
|
||||
ty_char { "u8" } // ???
|
||||
ty_i { "" } ty_i8 { "i8" } ty_i16 { "i16" }
|
||||
ty_i32 { "i32" } ty_i64 { "i64" }
|
||||
ty_char { ~"u8" } // ???
|
||||
ty_i { ~"" } ty_i8 { ~"i8" } ty_i16 { ~"i16" }
|
||||
ty_i32 { ~"i32" } ty_i64 { ~"i64" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,10 +129,10 @@ 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 {
|
||||
ty_u { "u" } ty_u8 { "u8" } ty_u16 { "u16" }
|
||||
ty_u32 { "u32" } ty_u64 { "u64" }
|
||||
ty_u { ~"u" } ty_u8 { ~"u8" } ty_u16 { ~"u16" }
|
||||
ty_u32 { ~"u32" } ty_u64 { ~"u64" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,8 +145,8 @@ pure fn uint_ty_max(t: uint_ty) -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn float_ty_to_str(t: float_ty) -> str {
|
||||
alt t { ty_f { "" } ty_f32 { "f32" } ty_f64 { "f64" } }
|
||||
pure fn float_ty_to_str(t: float_ty) -> ~str {
|
||||
alt t { ty_f { ~"" } ty_f32 { ~"f32" } ty_f64 { ~"f64" } }
|
||||
}
|
||||
|
||||
fn is_exported(i: ident, m: _mod) -> bool {
|
||||
@ -191,7 +191,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
|
||||
if id.node.name == i { ret true; }
|
||||
}
|
||||
} else {
|
||||
fail "export of path-qualified list";
|
||||
fail ~"export of path-qualified list";
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,7 +381,7 @@ fn dtor_dec() -> fn_decl {
|
||||
let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()};
|
||||
// dtor has one argument, of type ()
|
||||
{inputs: ~[{mode: ast::expl(ast::by_ref),
|
||||
ty: nil_t, ident: @"_"/~, id: 0}],
|
||||
ty: nil_t, ident: @~"_", id: 0}],
|
||||
output: nil_t, purity: impure_fn, cf: return_val, constraints: ~[]}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,8 @@ export require_unique_names;
|
||||
|
||||
/* Constructors */
|
||||
|
||||
fn mk_name_value_item_str(+name: ast::ident, +value: str) -> @ast::meta_item {
|
||||
fn mk_name_value_item_str(+name: ast::ident, +value: ~str) ->
|
||||
@ast::meta_item {
|
||||
let value_lit = dummy_spanned(ast::lit_str(@value));
|
||||
ret mk_name_value_item(name, value_lit);
|
||||
}
|
||||
@ -73,11 +74,11 @@ fn mk_attr(item: @ast::meta_item) -> ast::attribute {
|
||||
is_sugared_doc: false});
|
||||
}
|
||||
|
||||
fn mk_sugared_doc_attr(text: str, lo: uint, hi: uint) -> ast::attribute {
|
||||
fn mk_sugared_doc_attr(text: ~str, lo: uint, hi: uint) -> ast::attribute {
|
||||
let lit = spanned(lo, hi, ast::lit_str(@text));
|
||||
let attr = {
|
||||
style: doc_comment_style(text),
|
||||
value: spanned(lo, hi, ast::meta_name_value(@"doc"/~, lit)),
|
||||
value: spanned(lo, hi, ast::meta_name_value(@~"doc", lit)),
|
||||
is_sugared_doc: true
|
||||
};
|
||||
ret spanned(lo, hi, attr);
|
||||
@ -97,7 +98,7 @@ fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
|
||||
fn desugar_doc_attr(attr: ast::attribute) -> ast::attribute {
|
||||
if attr.node.is_sugared_doc {
|
||||
let comment = get_meta_item_value_str(@attr.node.value).get();
|
||||
let meta = mk_name_value_item_str(@"doc"/~,
|
||||
let meta = mk_name_value_item_str(@~"doc",
|
||||
strip_doc_comment_decoration(*comment));
|
||||
ret mk_attr(meta);
|
||||
} else {
|
||||
@ -124,7 +125,7 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
|
||||
* Gets the string value if the meta_item is a meta_name_value variant
|
||||
* 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 {
|
||||
ast::meta_name_value(_, v) {
|
||||
alt v.node {
|
||||
@ -154,7 +155,7 @@ fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
|
||||
*/
|
||||
fn get_name_value_str_pair(
|
||||
item: @ast::meta_item
|
||||
) -> option<(ast::ident, @str/~)> {
|
||||
) -> option<(ast::ident, @~str)> {
|
||||
alt attr::get_meta_item_value_str(item) {
|
||||
some(value) {
|
||||
let name = attr::get_meta_item_name(item);
|
||||
@ -168,7 +169,7 @@ fn get_name_value_str_pair(
|
||||
/* Searching */
|
||||
|
||||
/// Search a list of attributes and return only those with a specific name
|
||||
fn find_attrs_by_name(attrs: ~[ast::attribute], +name: str) ->
|
||||
fn find_attrs_by_name(attrs: ~[ast::attribute], +name: ~str) ->
|
||||
~[ast::attribute] {
|
||||
let filter = (
|
||||
fn@(a: ast::attribute) -> option<ast::attribute> {
|
||||
@ -181,7 +182,7 @@ fn find_attrs_by_name(attrs: ~[ast::attribute], +name: str) ->
|
||||
}
|
||||
|
||||
/// Searcha list of meta items and return only those with a specific name
|
||||
fn find_meta_items_by_name(metas: ~[@ast::meta_item], +name: str) ->
|
||||
fn find_meta_items_by_name(metas: ~[@ast::meta_item], +name: ~str) ->
|
||||
~[@ast::meta_item] {
|
||||
let filter = fn@(&&m: @ast::meta_item) -> option<@ast::meta_item> {
|
||||
if *get_meta_item_name(m) == name {
|
||||
@ -224,22 +225,22 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
|
||||
// FIXME (#607): Needs implementing
|
||||
// This involves probably sorting the list by name and
|
||||
// meta_item variant
|
||||
fail "unimplemented meta_item variant"
|
||||
fail ~"unimplemented meta_item variant"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn contains_name(metas: ~[@ast::meta_item], +name: str) -> bool {
|
||||
fn contains_name(metas: ~[@ast::meta_item], +name: ~str) -> bool {
|
||||
let matches = find_meta_items_by_name(metas, name);
|
||||
ret vec::len(matches) > 0u;
|
||||
}
|
||||
|
||||
fn attrs_contains_name(attrs: ~[ast::attribute], +name: str) -> bool {
|
||||
fn attrs_contains_name(attrs: ~[ast::attribute], +name: ~str) -> bool {
|
||||
vec::is_not_empty(find_attrs_by_name(attrs, name))
|
||||
}
|
||||
|
||||
fn first_attr_value_str_by_name(attrs: ~[ast::attribute], +name: str)
|
||||
-> option<@str/~> {
|
||||
fn first_attr_value_str_by_name(attrs: ~[ast::attribute], +name: ~str)
|
||||
-> option<@~str> {
|
||||
let mattrs = find_attrs_by_name(attrs, name);
|
||||
if vec::len(mattrs) > 0u {
|
||||
ret get_meta_item_value_str(attr_meta(mattrs[0]));
|
||||
@ -249,7 +250,7 @@ fn first_attr_value_str_by_name(attrs: ~[ast::attribute], +name: str)
|
||||
|
||||
fn last_meta_item_by_name(
|
||||
items: ~[@ast::meta_item],
|
||||
+name: str
|
||||
+name: ~str
|
||||
) -> option<@ast::meta_item> {
|
||||
let items = attr::find_meta_items_by_name(items, name);
|
||||
vec::last_opt(items)
|
||||
@ -257,8 +258,8 @@ fn last_meta_item_by_name(
|
||||
|
||||
fn last_meta_item_value_str_by_name(
|
||||
items: ~[@ast::meta_item],
|
||||
+name: str
|
||||
) -> option<@str/~> {
|
||||
+name: ~str
|
||||
) -> option<@~str> {
|
||||
alt last_meta_item_by_name(items, name) {
|
||||
some(item) {
|
||||
alt attr::get_meta_item_value_str(item) {
|
||||
@ -272,7 +273,7 @@ fn last_meta_item_value_str_by_name(
|
||||
|
||||
fn last_meta_item_list_by_name(
|
||||
items: ~[@ast::meta_item],
|
||||
+name: str
|
||||
+name: ~str
|
||||
) -> option<~[@ast::meta_item]> {
|
||||
alt last_meta_item_by_name(items, name) {
|
||||
some(item) {
|
||||
@ -319,7 +320,7 @@ fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ast::ident) ->
|
||||
|
||||
fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] {
|
||||
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 {
|
||||
ast::meta_list(_, _) { vec::push(found, attr) }
|
||||
_ { #debug("ignoring link attribute that has incorrect type"); }
|
||||
@ -340,22 +341,22 @@ fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
|
||||
}
|
||||
}
|
||||
|
||||
fn foreign_abi(attrs: ~[ast::attribute]) -> either<str, ast::foreign_abi> {
|
||||
ret alt attr::first_attr_value_str_by_name(attrs, "abi") {
|
||||
fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
|
||||
ret alt attr::first_attr_value_str_by_name(attrs, ~"abi") {
|
||||
option::none {
|
||||
either::right(ast::foreign_abi_cdecl)
|
||||
}
|
||||
option::some(@"rust-intrinsic"/~) {
|
||||
option::some(@~"rust-intrinsic") {
|
||||
either::right(ast::foreign_abi_rust_intrinsic)
|
||||
}
|
||||
option::some(@"cdecl"/~) {
|
||||
option::some(@~"cdecl") {
|
||||
either::right(ast::foreign_abi_cdecl)
|
||||
}
|
||||
option::some(@"stdcall"/~) {
|
||||
option::some(@~"stdcall") {
|
||||
either::right(ast::foreign_abi_stdcall)
|
||||
}
|
||||
option::some(t) {
|
||||
either::left("unsupported abi: " + *t)
|
||||
either::left(~"unsupported abi: " + *t)
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -371,9 +372,9 @@ fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr {
|
||||
// FIXME (#2809)---validate the usage of #[inline] and #[inline(always)]
|
||||
do vec::foldl(ia_none, attrs) |ia,attr| {
|
||||
alt attr.node.value.node {
|
||||
ast::meta_word(@"inline"/~) { ia_hint }
|
||||
ast::meta_list(@"inline"/~, items) {
|
||||
if !vec::is_empty(find_meta_items_by_name(items, "always")) {
|
||||
ast::meta_word(@~"inline") { ia_hint }
|
||||
ast::meta_list(@~"inline", items) {
|
||||
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {
|
||||
ia_always
|
||||
} else {
|
||||
ia_hint
|
||||
|
@ -28,7 +28,7 @@ export loc;
|
||||
export get_filemap;
|
||||
export new_codemap;
|
||||
|
||||
type filename = str;
|
||||
type filename = ~str;
|
||||
|
||||
type file_pos = {ch: uint, byte: uint};
|
||||
|
||||
@ -41,11 +41,11 @@ type file_pos = {ch: uint, byte: uint};
|
||||
enum file_substr {
|
||||
fss_none,
|
||||
fss_internal(span),
|
||||
fss_external({filename: str, line: uint, col: uint})
|
||||
fss_external({filename: ~str, line: uint, col: uint})
|
||||
}
|
||||
|
||||
type filemap =
|
||||
@{name: filename, substr: file_substr, src: @str/~,
|
||||
@{name: filename, substr: file_substr, src: @~str,
|
||||
start_pos: file_pos, mut lines: ~[file_pos]};
|
||||
|
||||
type codemap = @{files: dvec<filemap>};
|
||||
@ -55,7 +55,7 @@ type loc = {file: filemap, line: uint, col: uint};
|
||||
fn new_codemap() -> codemap { @{files: dvec()} }
|
||||
|
||||
fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
|
||||
src: @str/~,
|
||||
src: @~str,
|
||||
start_pos_ch: uint, start_pos_byte: uint)
|
||||
-> filemap {
|
||||
ret @{name: filename, substr: substr, src: src,
|
||||
@ -63,14 +63,14 @@ fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
|
||||
mut lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]};
|
||||
}
|
||||
|
||||
fn new_filemap(+filename: filename, src: @str/~,
|
||||
fn new_filemap(+filename: filename, src: @~str,
|
||||
start_pos_ch: uint, start_pos_byte: uint)
|
||||
-> filemap {
|
||||
ret new_filemap_w_substr(filename, fss_none, src,
|
||||
start_pos_ch, start_pos_byte);
|
||||
}
|
||||
|
||||
fn mk_substr_filename(cm: codemap, sp: span) -> str
|
||||
fn mk_substr_filename(cm: codemap, sp: span) -> ~str
|
||||
{
|
||||
let pos = lookup_char_pos(cm, sp.lo);
|
||||
ret #fmt("<%s:%u:%u>", pos.file.name, pos.line, pos.col);
|
||||
@ -121,7 +121,7 @@ fn lookup_byte_pos(map: codemap, pos: uint) -> loc {
|
||||
}
|
||||
|
||||
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);
|
||||
alt (loc.file.substr) {
|
||||
@ -158,19 +158,19 @@ fn adjust_span(map: codemap, sp: span) -> span {
|
||||
|
||||
enum expn_info_ {
|
||||
expanded_from({call_site: span,
|
||||
callie: {name: str, span: option<span>}})
|
||||
callie: {name: ~str, span: option<span>}})
|
||||
}
|
||||
type expn_info = option<@expn_info_>;
|
||||
type span = {lo: uint, hi: uint, expn_info: expn_info};
|
||||
|
||||
fn span_to_str_no_adj(sp: span, cm: codemap) -> str {
|
||||
fn span_to_str_no_adj(sp: span, cm: codemap) -> ~str {
|
||||
let lo = lookup_char_pos(cm, sp.lo);
|
||||
let hi = lookup_char_pos(cm, sp.hi);
|
||||
ret #fmt("%s:%u:%u: %u:%u", lo.file.name,
|
||||
lo.line, lo.col, hi.line, hi.col)
|
||||
}
|
||||
|
||||
fn span_to_str(sp: span, cm: codemap) -> str {
|
||||
fn span_to_str(sp: span, cm: codemap) -> ~str {
|
||||
let lo = lookup_char_pos_adj(cm, sp.lo);
|
||||
let hi = lookup_char_pos_adj(cm, sp.hi);
|
||||
ret #fmt("%s:%u:%u: %u:%u", lo.filename,
|
||||
@ -194,7 +194,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
||||
ret @{file: lo.file, lines: 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 end = alt str::find_char_from(*fm.src, '\n', begin) {
|
||||
some(e) { e }
|
||||
@ -213,20 +213,20 @@ fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
|
||||
{fm: fm, pos: line_offset + col_offset}
|
||||
}
|
||||
|
||||
fn span_to_snippet(sp: span, cm: codemap::codemap) -> str {
|
||||
fn span_to_snippet(sp: span, cm: codemap::codemap) -> ~str {
|
||||
let begin = lookup_byte_offset(cm, sp.lo);
|
||||
let end = lookup_byte_offset(cm, sp.hi);
|
||||
assert begin.fm == end.fm;
|
||||
ret str::slice(*begin.fm.src, begin.pos, end.pos);
|
||||
}
|
||||
|
||||
fn get_snippet(cm: codemap::codemap, fidx: uint, lo: uint, hi: uint) -> str
|
||||
fn get_snippet(cm: codemap::codemap, fidx: uint, lo: uint, hi: uint) -> ~str
|
||||
{
|
||||
let fm = cm.files[fidx];
|
||||
ret str::slice(*fm.src, lo, hi)
|
||||
}
|
||||
|
||||
fn get_filemap(cm: codemap, filename: str) -> filemap {
|
||||
fn get_filemap(cm: codemap, filename: ~str) -> filemap {
|
||||
for cm.files.each |fm| { if fm.name == filename { ret fm; } }
|
||||
//XXjdm the following triggers a mismatched type bug
|
||||
// (or expected function, found _|_)
|
||||
|
@ -10,30 +10,30 @@ export ice_msg;
|
||||
export expect;
|
||||
|
||||
type emitter = fn@(cmsp: option<(codemap::codemap, span)>,
|
||||
msg: str, lvl: level);
|
||||
msg: ~str, lvl: level);
|
||||
|
||||
|
||||
iface span_handler {
|
||||
fn span_fatal(sp: span, msg: str) -> !;
|
||||
fn span_err(sp: span, msg: str);
|
||||
fn span_warn(sp: span, msg: str);
|
||||
fn span_note(sp: span, msg: str);
|
||||
fn span_bug(sp: span, msg: str) -> !;
|
||||
fn span_unimpl(sp: span, msg: str) -> !;
|
||||
fn span_fatal(sp: span, msg: ~str) -> !;
|
||||
fn span_err(sp: span, msg: ~str);
|
||||
fn span_warn(sp: span, msg: ~str);
|
||||
fn span_note(sp: span, msg: ~str);
|
||||
fn span_bug(sp: span, msg: ~str) -> !;
|
||||
fn span_unimpl(sp: span, msg: ~str) -> !;
|
||||
fn handler() -> handler;
|
||||
}
|
||||
|
||||
iface handler {
|
||||
fn fatal(msg: str) -> !;
|
||||
fn err(msg: str);
|
||||
fn fatal(msg: ~str) -> !;
|
||||
fn err(msg: ~str);
|
||||
fn bump_err_count();
|
||||
fn has_errors() -> bool;
|
||||
fn abort_if_errors();
|
||||
fn warn(msg: str);
|
||||
fn note(msg: str);
|
||||
fn bug(msg: str) -> !;
|
||||
fn unimpl(msg: str) -> !;
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>, msg: str, lvl: level);
|
||||
fn warn(msg: ~str);
|
||||
fn note(msg: ~str);
|
||||
fn bug(msg: ~str) -> !;
|
||||
fn unimpl(msg: ~str) -> !;
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>, msg: ~str, lvl: level);
|
||||
}
|
||||
|
||||
type handler_t = @{
|
||||
@ -47,25 +47,25 @@ type codemap_t = @{
|
||||
};
|
||||
|
||||
impl codemap_span_handler of span_handler for codemap_t {
|
||||
fn span_fatal(sp: span, msg: str) -> ! {
|
||||
fn span_fatal(sp: span, msg: ~str) -> ! {
|
||||
self.handler.emit(some((self.cm, sp)), msg, fatal);
|
||||
fail;
|
||||
}
|
||||
fn span_err(sp: span, msg: str) {
|
||||
fn span_err(sp: span, msg: ~str) {
|
||||
self.handler.emit(some((self.cm, sp)), msg, error);
|
||||
self.handler.bump_err_count();
|
||||
}
|
||||
fn span_warn(sp: span, msg: str) {
|
||||
fn span_warn(sp: span, msg: ~str) {
|
||||
self.handler.emit(some((self.cm, sp)), msg, warning);
|
||||
}
|
||||
fn span_note(sp: span, msg: str) {
|
||||
fn span_note(sp: span, msg: ~str) {
|
||||
self.handler.emit(some((self.cm, sp)), msg, note);
|
||||
}
|
||||
fn span_bug(sp: span, msg: str) -> ! {
|
||||
fn span_bug(sp: span, msg: ~str) -> ! {
|
||||
self.span_fatal(sp, ice_msg(msg));
|
||||
}
|
||||
fn span_unimpl(sp: span, msg: str) -> ! {
|
||||
self.span_bug(sp, "unimplemented " + msg);
|
||||
fn span_unimpl(sp: span, msg: ~str) -> ! {
|
||||
self.span_bug(sp, ~"unimplemented " + msg);
|
||||
}
|
||||
fn handler() -> handler {
|
||||
self.handler
|
||||
@ -73,11 +73,11 @@ impl codemap_span_handler of span_handler for codemap_t {
|
||||
}
|
||||
|
||||
impl codemap_handler of handler for handler_t {
|
||||
fn fatal(msg: str) -> ! {
|
||||
fn fatal(msg: ~str) -> ! {
|
||||
self.emit(none, msg, fatal);
|
||||
fail;
|
||||
}
|
||||
fn err(msg: str) {
|
||||
fn err(msg: ~str) {
|
||||
self.emit(none, msg, error);
|
||||
self.bump_err_count();
|
||||
}
|
||||
@ -89,28 +89,28 @@ impl codemap_handler of handler for handler_t {
|
||||
let s;
|
||||
alt self.err_count {
|
||||
0u { ret; }
|
||||
1u { s = "aborting due to previous error"; }
|
||||
1u { s = ~"aborting due to previous error"; }
|
||||
_ { s = #fmt["aborting due to %u previous errors",
|
||||
self.err_count]; }
|
||||
}
|
||||
self.fatal(s);
|
||||
}
|
||||
fn warn(msg: str) {
|
||||
fn warn(msg: ~str) {
|
||||
self.emit(none, msg, warning);
|
||||
}
|
||||
fn note(msg: str) {
|
||||
fn note(msg: ~str) {
|
||||
self.emit(none, msg, note);
|
||||
}
|
||||
fn bug(msg: str) -> ! {
|
||||
fn bug(msg: ~str) -> ! {
|
||||
self.fatal(ice_msg(msg));
|
||||
}
|
||||
fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); }
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>, msg: str, lvl: level) {
|
||||
fn unimpl(msg: ~str) -> ! { self.bug(~"unimplemented " + msg); }
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>, msg: ~str, lvl: level) {
|
||||
self.emit(cmsp, msg, lvl);
|
||||
}
|
||||
}
|
||||
|
||||
fn ice_msg(msg: str) -> str {
|
||||
fn ice_msg(msg: ~str) -> ~str {
|
||||
#fmt["internal compiler error: %s", msg]
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ fn mk_handler(emitter: option<emitter>) -> handler {
|
||||
some(e) { e }
|
||||
none {
|
||||
let f = fn@(cmsp: option<(codemap::codemap, span)>,
|
||||
msg: str, t: level) {
|
||||
msg: ~str, t: level) {
|
||||
emit(cmsp, msg, t);
|
||||
};
|
||||
f
|
||||
@ -144,12 +144,12 @@ enum level {
|
||||
note,
|
||||
}
|
||||
|
||||
fn diagnosticstr(lvl: level) -> str {
|
||||
fn diagnosticstr(lvl: level) -> ~str {
|
||||
alt lvl {
|
||||
fatal { "error" }
|
||||
error { "error" }
|
||||
warning { "warning" }
|
||||
note { "note" }
|
||||
fatal { ~"error" }
|
||||
error { ~"error" }
|
||||
warning { ~"warning" }
|
||||
note { ~"note" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ fn diagnosticcolor(lvl: level) -> u8 {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_diagnostic(topic: str, lvl: level, msg: str) {
|
||||
fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) {
|
||||
if str::is_not_empty(topic) {
|
||||
io::stderr().write_str(#fmt["%s ", topic]);
|
||||
}
|
||||
@ -177,7 +177,7 @@ fn print_diagnostic(topic: str, lvl: level, msg: str) {
|
||||
}
|
||||
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>,
|
||||
msg: str, lvl: level) {
|
||||
msg: ~str, lvl: level) {
|
||||
alt cmsp {
|
||||
some((cm, sp)) {
|
||||
let sp = codemap::adjust_span(cm,sp);
|
||||
@ -188,7 +188,7 @@ fn emit(cmsp: option<(codemap::codemap, span)>,
|
||||
print_macro_backtrace(cm, sp);
|
||||
}
|
||||
none {
|
||||
print_diagnostic("", lvl, msg);
|
||||
print_diagnostic(~"", lvl, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -209,16 +209,16 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
|
||||
// Print the offending lines
|
||||
for display_lines.each |line| {
|
||||
io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]);
|
||||
let s = codemap::get_line(fm, line as int) + "\n";
|
||||
let s = codemap::get_line(fm, line as int) + ~"\n";
|
||||
io::stderr().write_str(s);
|
||||
}
|
||||
if elided {
|
||||
let last_line = display_lines[vec::len(display_lines) - 1u];
|
||||
let s = #fmt["%s:%u ", fm.name, last_line + 1u];
|
||||
let mut indent = str::len(s);
|
||||
let mut out = "";
|
||||
while indent > 0u { out += " "; indent -= 1u; }
|
||||
out += "...\n";
|
||||
let mut out = ~"";
|
||||
while indent > 0u { out += ~" "; indent -= 1u; }
|
||||
out += ~"...\n";
|
||||
io::stderr().write_str(out);
|
||||
}
|
||||
|
||||
@ -234,34 +234,34 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
|
||||
|
||||
// indent past |name:## | and the 0-offset column location
|
||||
let mut left = str::len(fm.name) + digits + lo.col + 3u;
|
||||
let mut s = "";
|
||||
let mut s = ~"";
|
||||
while left > 0u { str::push_char(s, ' '); left -= 1u; }
|
||||
|
||||
s += "^";
|
||||
s += ~"^";
|
||||
let hi = codemap::lookup_char_pos(cm, sp.hi);
|
||||
if hi.col != lo.col {
|
||||
// the ^ already takes up one space
|
||||
let mut width = hi.col - lo.col - 1u;
|
||||
while width > 0u { str::push_char(s, '~'); width -= 1u; }
|
||||
}
|
||||
io::stderr().write_str(s + "\n");
|
||||
io::stderr().write_str(s + ~"\n");
|
||||
}
|
||||
}
|
||||
|
||||
fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
|
||||
do option::iter (sp.expn_info) |ei| {
|
||||
let ss = option::map_default(ei.callie.span, @""/~,
|
||||
let ss = option::map_default(ei.callie.span, @~"",
|
||||
|span| @codemap::span_to_str(span, cm));
|
||||
print_diagnostic(*ss, note,
|
||||
#fmt("in expansion of #%s", ei.callie.name));
|
||||
let ss = codemap::span_to_str(ei.call_site, cm);
|
||||
print_diagnostic(ss, note, "expansion site");
|
||||
print_diagnostic(ss, note, ~"expansion site");
|
||||
print_macro_backtrace(cm, ei.call_site);
|
||||
}
|
||||
}
|
||||
|
||||
fn expect<T: copy>(diag: span_handler,
|
||||
opt: option<T>, msg: fn() -> str) -> T {
|
||||
opt: option<T>, msg: fn() -> ~str) -> T {
|
||||
alt opt {
|
||||
some(t) { t }
|
||||
none { diag.handler().bug(msg()); }
|
||||
|
@ -84,15 +84,15 @@ mod syntax {
|
||||
export parse;
|
||||
}
|
||||
|
||||
type ser_tps_map = map::hashmap<str, fn@(@ast::expr) -> ~[@ast::stmt]>;
|
||||
type deser_tps_map = map::hashmap<str, fn@() -> @ast::expr>;
|
||||
type ser_tps_map = map::hashmap<~str, fn@(@ast::expr) -> ~[@ast::stmt]>;
|
||||
type deser_tps_map = map::hashmap<~str, fn@() -> @ast::expr>;
|
||||
|
||||
fn expand(cx: ext_ctxt,
|
||||
span: span,
|
||||
_mitem: ast::meta_item,
|
||||
in_items: ~[@ast::item]) -> ~[@ast::item] {
|
||||
fn not_auto_serialize(a: ast::attribute) -> bool {
|
||||
attr::get_attr_name(a) != @"auto_serialize"/~
|
||||
attr::get_attr_name(a) != @~"auto_serialize"
|
||||
}
|
||||
|
||||
fn filter_attrs(item: @ast::item) -> @ast::item {
|
||||
@ -114,7 +114,7 @@ fn expand(cx: ext_ctxt,
|
||||
}
|
||||
|
||||
_ {
|
||||
cx.span_err(span, "#[auto_serialize] can only be \
|
||||
cx.span_err(span, ~"#[auto_serialize] can only be \
|
||||
applied to type and enum \
|
||||
definitions");
|
||||
~[in_item]
|
||||
@ -125,11 +125,11 @@ fn expand(cx: ext_ctxt,
|
||||
|
||||
impl helpers for ext_ctxt {
|
||||
fn helper_path(base_path: @ast::path,
|
||||
helper_name: str) -> @ast::path {
|
||||
helper_name: ~str) -> @ast::path {
|
||||
let head = vec::init(base_path.idents);
|
||||
let tail = vec::last(base_path.idents);
|
||||
self.path(base_path.span,
|
||||
vec::append(head, ~[@(helper_name + "_" + *tail)]))
|
||||
vec::append(head, ~[@(helper_name + ~"_" + *tail)]))
|
||||
}
|
||||
|
||||
fn path(span: span, strs: ~[ast::ident]) -> @ast::path {
|
||||
@ -154,7 +154,7 @@ impl helpers for ext_ctxt {
|
||||
let args = do vec::map(input_tys) |ty| {
|
||||
{mode: ast::expl(ast::by_ref),
|
||||
ty: ty,
|
||||
ident: @""/~,
|
||||
ident: @~"",
|
||||
id: self.next_id()}
|
||||
};
|
||||
|
||||
@ -219,7 +219,7 @@ impl helpers for ext_ctxt {
|
||||
ast::expr_alt(v, arms, ast::alt_exhaustive)))
|
||||
}
|
||||
|
||||
fn lit_str(span: span, s: @str/~) -> @ast::expr {
|
||||
fn lit_str(span: span, s: @~str) -> @ast::expr {
|
||||
self.expr(
|
||||
span,
|
||||
ast::expr_vstore(
|
||||
@ -297,7 +297,7 @@ fn ser_path(cx: ext_ctxt, tps: ser_tps_map, path: @ast::path,
|
||||
cx.expr(
|
||||
path.span,
|
||||
ast::expr_path(
|
||||
cx.helper_path(path, "serialize")));
|
||||
cx.helper_path(path, ~"serialize")));
|
||||
|
||||
let ty_args = do vec::map(path.types) |ty| {
|
||||
let sv_stmts = ser_ty(cx, tps, ty, cx.clone(s), #ast{ __v });
|
||||
@ -354,7 +354,7 @@ fn is_vec_or_str(ty: @ast::ty) -> bool {
|
||||
// This may be wrong if the user has shadowed (!) str
|
||||
ast::ty_path(@{span: _, global: _, idents: ids,
|
||||
rp: none, types: _}, _)
|
||||
if ids == ~[@"str"/~] { true }
|
||||
if ids == ~[@~"str"] { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
@ -392,7 +392,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
|
||||
}
|
||||
|
||||
ast::ty_ptr(_) | ast::ty_rptr(_, _) {
|
||||
cx.span_err(ty.span, "cannot serialize pointer types");
|
||||
cx.span_err(ty.span, ~"cannot serialize pointer types");
|
||||
~[]
|
||||
}
|
||||
|
||||
@ -414,7 +414,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
|
||||
}
|
||||
|
||||
ast::ty_fn(_, _) {
|
||||
cx.span_err(ty.span, "cannot serialize function types");
|
||||
cx.span_err(ty.span, ~"cannot serialize function types");
|
||||
~[]
|
||||
}
|
||||
|
||||
@ -471,12 +471,12 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
|
||||
}
|
||||
|
||||
ast::ty_mac(_) {
|
||||
cx.span_err(ty.span, "cannot serialize macro types");
|
||||
cx.span_err(ty.span, ~"cannot serialize macro types");
|
||||
~[]
|
||||
}
|
||||
|
||||
ast::ty_infer {
|
||||
cx.span_err(ty.span, "cannot serialize inferred types");
|
||||
cx.span_err(ty.span, ~"cannot serialize inferred types");
|
||||
~[]
|
||||
}
|
||||
|
||||
@ -503,7 +503,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
|
||||
}
|
||||
|
||||
ast::ty_vstore(_, _) {
|
||||
cx.span_unimpl(ty.span, "serialization for vstore types");
|
||||
cx.span_unimpl(ty.span, ~"serialization for vstore types");
|
||||
}
|
||||
|
||||
}
|
||||
@ -525,7 +525,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
|
||||
ty: cx.ty_fn(span,
|
||||
~[cx.ty_path(span, ~[tp.ident], ~[])],
|
||||
cx.ty_nil(span)),
|
||||
ident: @("__s" + *tp.ident),
|
||||
ident: @(~"__s" + *tp.ident),
|
||||
id: cx.next_id()});
|
||||
|
||||
#debug["tp_inputs = %?", tp_inputs];
|
||||
@ -533,12 +533,12 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
|
||||
|
||||
let ser_inputs: ~[ast::arg] =
|
||||
vec::append(~[{mode: ast::expl(ast::by_ref),
|
||||
ty: cx.ty_path(span, ~[@"__S"/~], ~[]),
|
||||
ident: @"__s"/~,
|
||||
ty: cx.ty_path(span, ~[@~"__S"], ~[]),
|
||||
ident: @~"__s",
|
||||
id: cx.next_id()},
|
||||
{mode: ast::expl(ast::by_ref),
|
||||
ty: v_ty,
|
||||
ident: @"__v"/~,
|
||||
ident: @~"__v",
|
||||
id: cx.next_id()}],
|
||||
tp_inputs);
|
||||
|
||||
@ -556,12 +556,12 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
|
||||
|
||||
let ser_bnds = @~[
|
||||
ast::bound_trait(cx.ty_path(span,
|
||||
~[@"std"/~, @"serialization"/~,
|
||||
@"serializer"/~],
|
||||
~[@~"std", @~"serialization",
|
||||
@~"serializer"],
|
||||
~[]))];
|
||||
|
||||
let ser_tps: ~[ast::ty_param] =
|
||||
vec::append(~[{ident: @"__S"/~,
|
||||
vec::append(~[{ident: @~"__S",
|
||||
id: cx.next_id(),
|
||||
bounds: ser_bnds}],
|
||||
vec::map(tps, |tp| cx.clone_ty_param(tp)));
|
||||
@ -573,7 +573,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
|
||||
let ser_blk = cx.blk(span,
|
||||
f(cx, tps_map, #ast{ __s }, #ast{ __v }));
|
||||
|
||||
@{ident: @("serialize_" + *name),
|
||||
@{ident: @(~"serialize_" + *name),
|
||||
attrs: ~[],
|
||||
id: cx.next_id(),
|
||||
node: ast::item_fn({inputs: ser_inputs,
|
||||
@ -598,7 +598,7 @@ fn deser_path(cx: ext_ctxt, tps: deser_tps_map, path: @ast::path,
|
||||
cx.expr(
|
||||
path.span,
|
||||
ast::expr_path(
|
||||
cx.helper_path(path, "deserialize")));
|
||||
cx.helper_path(path, ~"deserialize")));
|
||||
|
||||
let ty_args = do vec::map(path.types) |ty| {
|
||||
let dv_expr = deser_ty(cx, tps, ty, cx.clone(d));
|
||||
@ -726,7 +726,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
|
||||
}
|
||||
|
||||
ast::ty_vstore(_, _) {
|
||||
cx.span_unimpl(ty.span, "deserialization for vstore types");
|
||||
cx.span_unimpl(ty.span, ~"deserialization for vstore types");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -746,15 +746,15 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
|
||||
ty: cx.ty_fn(span,
|
||||
~[],
|
||||
cx.ty_path(span, ~[tp.ident], ~[])),
|
||||
ident: @("__d" + *tp.ident),
|
||||
ident: @(~"__d" + *tp.ident),
|
||||
id: cx.next_id()});
|
||||
|
||||
#debug["tp_inputs = %?", tp_inputs];
|
||||
|
||||
let deser_inputs: ~[ast::arg] =
|
||||
vec::append(~[{mode: ast::expl(ast::by_ref),
|
||||
ty: cx.ty_path(span, ~[@"__D"/~], ~[]),
|
||||
ident: @"__d"/~,
|
||||
ty: cx.ty_path(span, ~[@~"__D"], ~[]),
|
||||
ident: @~"__d",
|
||||
id: cx.next_id()}],
|
||||
tp_inputs);
|
||||
|
||||
@ -772,11 +772,11 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
|
||||
let deser_bnds = @~[
|
||||
ast::bound_trait(cx.ty_path(
|
||||
span,
|
||||
~[@"std"/~, @"serialization"/~, @"deserializer"/~],
|
||||
~[@~"std", @~"serialization", @~"deserializer"],
|
||||
~[]))];
|
||||
|
||||
let deser_tps: ~[ast::ty_param] =
|
||||
vec::append(~[{ident: @"__D"/~,
|
||||
vec::append(~[{ident: @~"__D",
|
||||
id: cx.next_id(),
|
||||
bounds: deser_bnds}],
|
||||
vec::map(tps, |tp| {
|
||||
@ -788,7 +788,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
|
||||
|
||||
let deser_blk = cx.expr_blk(f(cx, tps_map, #ast(expr){__d}));
|
||||
|
||||
@{ident: @("deserialize_" + *name),
|
||||
@{ident: @(~"deserialize_" + *name),
|
||||
attrs: ~[],
|
||||
id: cx.next_id(),
|
||||
node: ast::item_fn({inputs: deser_inputs,
|
||||
|
@ -42,47 +42,47 @@ enum syntax_extension {
|
||||
|
||||
// A temporary hard-coded map of methods for expanding syntax extension
|
||||
// AST nodes into full ASTs
|
||||
fn syntax_expander_table() -> hashmap<str, syntax_extension> {
|
||||
fn syntax_expander_table() -> hashmap<~str, syntax_extension> {
|
||||
fn builtin(f: syntax_expander_) -> syntax_extension
|
||||
{normal({expander: f, span: none})}
|
||||
fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
|
||||
item_tt({expander: f, span: none})
|
||||
}
|
||||
let syntax_expanders = str_hash::<syntax_extension>();
|
||||
syntax_expanders.insert("macro",
|
||||
syntax_expanders.insert(~"macro",
|
||||
macro_defining(ext::simplext::add_new_extension));
|
||||
syntax_expanders.insert("macro_rules",
|
||||
syntax_expanders.insert(~"macro_rules",
|
||||
builtin_item_tt(
|
||||
ext::tt::macro_rules::add_new_extension));
|
||||
syntax_expanders.insert("fmt", builtin(ext::fmt::expand_syntax_ext));
|
||||
syntax_expanders.insert("auto_serialize",
|
||||
syntax_expanders.insert(~"fmt", builtin(ext::fmt::expand_syntax_ext));
|
||||
syntax_expanders.insert(~"auto_serialize",
|
||||
item_decorator(ext::auto_serialize::expand));
|
||||
syntax_expanders.insert("env", builtin(ext::env::expand_syntax_ext));
|
||||
syntax_expanders.insert("concat_idents",
|
||||
syntax_expanders.insert(~"env", builtin(ext::env::expand_syntax_ext));
|
||||
syntax_expanders.insert(~"concat_idents",
|
||||
builtin(ext::concat_idents::expand_syntax_ext));
|
||||
syntax_expanders.insert("ident_to_str",
|
||||
syntax_expanders.insert(~"ident_to_str",
|
||||
builtin(ext::ident_to_str::expand_syntax_ext));
|
||||
syntax_expanders.insert("log_syntax",
|
||||
syntax_expanders.insert(~"log_syntax",
|
||||
builtin(ext::log_syntax::expand_syntax_ext));
|
||||
syntax_expanders.insert("ast",
|
||||
syntax_expanders.insert(~"ast",
|
||||
builtin(ext::qquote::expand_ast));
|
||||
syntax_expanders.insert("line",
|
||||
syntax_expanders.insert(~"line",
|
||||
builtin(ext::source_util::expand_line));
|
||||
syntax_expanders.insert("col",
|
||||
syntax_expanders.insert(~"col",
|
||||
builtin(ext::source_util::expand_col));
|
||||
syntax_expanders.insert("file",
|
||||
syntax_expanders.insert(~"file",
|
||||
builtin(ext::source_util::expand_file));
|
||||
syntax_expanders.insert("stringify",
|
||||
syntax_expanders.insert(~"stringify",
|
||||
builtin(ext::source_util::expand_stringify));
|
||||
syntax_expanders.insert("include",
|
||||
syntax_expanders.insert(~"include",
|
||||
builtin(ext::source_util::expand_include));
|
||||
syntax_expanders.insert("include_str",
|
||||
syntax_expanders.insert(~"include_str",
|
||||
builtin(ext::source_util::expand_include_str));
|
||||
syntax_expanders.insert("include_bin",
|
||||
syntax_expanders.insert(~"include_bin",
|
||||
builtin(ext::source_util::expand_include_bin));
|
||||
syntax_expanders.insert("mod",
|
||||
syntax_expanders.insert(~"mod",
|
||||
builtin(ext::source_util::expand_mod));
|
||||
syntax_expanders.insert("proto",
|
||||
syntax_expanders.insert(~"proto",
|
||||
builtin_item_tt(ext::pipes::expand_proto));
|
||||
ret syntax_expanders;
|
||||
}
|
||||
@ -98,11 +98,11 @@ iface ext_ctxt {
|
||||
fn mod_path() -> ~[ast::ident];
|
||||
fn bt_push(ei: codemap::expn_info_);
|
||||
fn bt_pop();
|
||||
fn span_fatal(sp: span, msg: str) -> !;
|
||||
fn span_err(sp: span, msg: str);
|
||||
fn span_unimpl(sp: span, msg: str) -> !;
|
||||
fn span_bug(sp: span, msg: str) -> !;
|
||||
fn bug(msg: str) -> !;
|
||||
fn span_fatal(sp: span, msg: ~str) -> !;
|
||||
fn span_err(sp: span, msg: ~str);
|
||||
fn span_unimpl(sp: span, msg: ~str) -> !;
|
||||
fn span_bug(sp: span, msg: ~str) -> !;
|
||||
fn bug(msg: ~str) -> !;
|
||||
fn next_id() -> ast::node_id;
|
||||
}
|
||||
|
||||
@ -137,26 +137,26 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
|
||||
some(@expanded_from({call_site: {expn_info: prev, _}, _})) {
|
||||
self.backtrace = prev
|
||||
}
|
||||
_ { self.bug("tried to pop without a push"); }
|
||||
_ { self.bug(~"tried to pop without a push"); }
|
||||
}
|
||||
}
|
||||
fn span_fatal(sp: span, msg: str) -> ! {
|
||||
fn span_fatal(sp: span, msg: ~str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
|
||||
}
|
||||
fn span_err(sp: span, msg: str) {
|
||||
fn span_err(sp: span, msg: ~str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_err(sp, msg);
|
||||
}
|
||||
fn span_unimpl(sp: span, msg: str) -> ! {
|
||||
fn span_unimpl(sp: span, msg: ~str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
|
||||
}
|
||||
fn span_bug(sp: span, msg: str) -> ! {
|
||||
fn span_bug(sp: span, msg: ~str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
||||
}
|
||||
fn bug(msg: str) -> ! {
|
||||
fn bug(msg: ~str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||
}
|
||||
@ -173,7 +173,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
|
||||
ret imp as ext_ctxt
|
||||
}
|
||||
|
||||
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 {
|
||||
ast::expr_lit(l) {
|
||||
alt l.node {
|
||||
@ -185,7 +185,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 {
|
||||
ast::expr_path(p) {
|
||||
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
|
||||
@ -197,12 +197,12 @@ fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: str) -> ast::ident {
|
||||
}
|
||||
|
||||
fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
min: uint, name: str) -> ~[@ast::expr] {
|
||||
min: uint, name: ~str) -> ~[@ast::expr] {
|
||||
ret get_mac_args(cx, sp, arg, min, none, name);
|
||||
}
|
||||
|
||||
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 {
|
||||
some(expr) {
|
||||
alt expr.node {
|
||||
@ -235,7 +235,7 @@ fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body)
|
||||
{
|
||||
alt (args) {
|
||||
some(body) {body}
|
||||
none {cx.span_fatal(sp, "missing macro body")}
|
||||
none {cx.span_fatal(sp, ~"missing macro body")}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,11 +77,11 @@ fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
||||
@ast::expr {
|
||||
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(none))
|
||||
}
|
||||
fn mk_base_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
|
||||
fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
|
||||
let lit = ast::lit_str(@s);
|
||||
ret mk_lit(cx, sp, lit);
|
||||
}
|
||||
fn mk_uniq_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
|
||||
fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
|
||||
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::vstore_uniq)
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@ import base::*;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args_no_max(cx,sp,arg,1u,"concat_idents");
|
||||
let mut res = "";
|
||||
let args = get_mac_args_no_max(cx,sp,arg,1u,~"concat_idents");
|
||||
let mut res = ~"";
|
||||
for args.each |e| {
|
||||
res += *expr_to_ident(cx, e, "expected an ident");
|
||||
res += *expr_to_ident(cx, e, ~"expected an ident");
|
||||
}
|
||||
|
||||
ret @{id: cx.next_id(),
|
||||
|
@ -10,14 +10,14 @@ export expand_syntax_ext;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), "env");
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"env");
|
||||
|
||||
// FIXME (#2248): if this was more thorough it would manufacture an
|
||||
// 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) {
|
||||
option::none { ret mk_uniq_str(cx, sp, ""); }
|
||||
option::none { ret mk_uniq_str(cx, sp, ~""); }
|
||||
option::some(s) { ret mk_uniq_str(cx, sp, s); }
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import parse::{parser, parse_expr_from_source_str, new_parser_from_tt};
|
||||
|
||||
import codemap::{span, expanded_from};
|
||||
|
||||
fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
|
||||
fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
e: expr_, s: span, fld: ast_fold,
|
||||
orig: fn@(expr_, span, ast_fold) -> (expr_, span))
|
||||
-> (expr_, span)
|
||||
@ -54,7 +54,7 @@ fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
|
||||
}
|
||||
some(item_tt(*)) {
|
||||
cx.span_fatal(pth.span,
|
||||
"cannot use item macros in this context");
|
||||
~"cannot use item macros in this context");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,14 +91,14 @@ fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
|
||||
|
||||
}
|
||||
}
|
||||
_ { cx.span_bug(mac.span, "naked syntactic bit") }
|
||||
_ { cx.span_bug(mac.span, ~"naked syntactic bit") }
|
||||
}
|
||||
}
|
||||
_ { orig(e, s, fld) }
|
||||
};
|
||||
}
|
||||
|
||||
fn expand_mod_items(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
|
||||
fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
||||
module: ast::_mod, fld: ast_fold,
|
||||
orig: fn@(ast::_mod, ast_fold) -> ast::_mod)
|
||||
-> ast::_mod
|
||||
@ -133,7 +133,7 @@ fn expand_mod_items(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
|
||||
}
|
||||
|
||||
/* record module we enter for `#mod` */
|
||||
fn expand_item(exts: hashmap<str, syntax_extension>,
|
||||
fn expand_item(exts: hashmap<~str, syntax_extension>,
|
||||
cx: ext_ctxt, &&it: @ast::item, fld: ast_fold,
|
||||
orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>)
|
||||
-> option<@ast::item>
|
||||
@ -160,7 +160,7 @@ 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,
|
||||
fld: ast_fold) -> option<@ast::item> {
|
||||
alt it.node {
|
||||
@ -179,7 +179,7 @@ fn expand_item_mac(exts: hashmap<str, syntax_extension>,
|
||||
let maybe_it = alt expanded {
|
||||
mr_item(it) { fld.fold_item(it) }
|
||||
mr_expr(e) { cx.span_fatal(pth.span,
|
||||
"expr macro in item position: " +
|
||||
~"expr macro in item position: " +
|
||||
*extname) }
|
||||
mr_def(mdef) {
|
||||
exts.insert(*mdef.ident, mdef.ext);
|
||||
@ -194,7 +194,7 @@ fn expand_item_mac(exts: hashmap<str, syntax_extension>,
|
||||
}
|
||||
}
|
||||
_ {
|
||||
cx.span_bug(it.span, "invalid item macro invocation");
|
||||
cx.span_bug(it.span, ~"invalid item macro invocation");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -209,9 +209,9 @@ fn new_span(cx: ext_ctxt, sp: span) -> span {
|
||||
// is substantially more mature, these should move from here, into a
|
||||
// compiled part of libcore at very least.
|
||||
|
||||
fn core_macros() -> str {
|
||||
fn core_macros() -> ~str {
|
||||
ret
|
||||
"{
|
||||
~"{
|
||||
#macro([#error[f, ...], log(core::error, #fmt[f, ...])]);
|
||||
#macro([#warn[f, ...], log(core::warn, #fmt[f, ...])]);
|
||||
#macro([#info[f, ...], log(core::info, #fmt[f, ...])]);
|
||||
@ -231,7 +231,7 @@ fn expand_crate(parse_sess: parse::parse_sess,
|
||||
new_span: |a|new_span(cx, a)
|
||||
with *afp};
|
||||
let f = make_fold(f_pre);
|
||||
let cm = parse_expr_from_source_str("<core-macros>",
|
||||
let cm = parse_expr_from_source_str(~"<core-macros>",
|
||||
@core_macros(),
|
||||
cfg,
|
||||
parse_sess);
|
||||
|
@ -13,17 +13,17 @@ export expand_syntax_ext;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args_no_max(cx, sp, arg, 1u, "fmt");
|
||||
let args = get_mac_args_no_max(cx, sp, arg, 1u, ~"fmt");
|
||||
let fmt =
|
||||
expr_to_str(cx, args[0],
|
||||
"first argument to #fmt must be a string literal.");
|
||||
~"first argument to #fmt must be a string literal.");
|
||||
let fmtspan = args[0].span;
|
||||
#debug("Format string:");
|
||||
log(debug, fmt);
|
||||
fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: str) -> ! {
|
||||
fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: ~str) -> ! {
|
||||
cx.span_fatal(sp, msg);
|
||||
}
|
||||
let parse_fmt_err = fn@(s: str) -> ! {
|
||||
let parse_fmt_err = fn@(s: ~str) -> ! {
|
||||
parse_fmt_err_(cx, fmtspan, s)
|
||||
};
|
||||
let pieces = parse_fmt_string(fmt, parse_fmt_err);
|
||||
@ -38,7 +38,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
pieces: ~[piece], args: ~[@ast::expr])
|
||||
-> @ast::expr {
|
||||
fn make_path_vec(_cx: ext_ctxt, ident: ast::ident) -> ~[ast::ident] {
|
||||
ret ~[@"extfmt"/~, @"rt"/~, ident];
|
||||
ret ~[@~"extfmt", @~"rt", ident];
|
||||
}
|
||||
fn make_rt_path_expr(cx: ext_ctxt, sp: span,
|
||||
ident: ast::ident) -> @ast::expr {
|
||||
@ -50,14 +50,14 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
|
||||
fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @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| {
|
||||
let fstr = alt f {
|
||||
flag_left_justify { "flag_left_justify" }
|
||||
flag_left_zero_pad { "flag_left_zero_pad" }
|
||||
flag_space_for_sign { "flag_space_for_sign" }
|
||||
flag_sign_always { "flag_sign_always" }
|
||||
flag_alternate { "flag_alternate" }
|
||||
flag_left_justify { ~"flag_left_justify" }
|
||||
flag_left_zero_pad { ~"flag_left_zero_pad" }
|
||||
flag_space_for_sign { ~"flag_space_for_sign" }
|
||||
flag_sign_always { ~"flag_sign_always" }
|
||||
flag_alternate { ~"flag_alternate" }
|
||||
};
|
||||
tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr,
|
||||
make_rt_path_expr(cx, sp, @fstr));
|
||||
@ -67,15 +67,15 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
|
||||
alt cnt {
|
||||
count_implied {
|
||||
ret make_rt_path_expr(cx, sp, @"count_implied"/~);
|
||||
ret make_rt_path_expr(cx, sp, @~"count_implied");
|
||||
}
|
||||
count_is(c) {
|
||||
let count_lit = mk_int(cx, sp, c);
|
||||
let count_is_path = make_path_vec(cx, @"count_is"/~);
|
||||
let count_is_path = make_path_vec(cx, @~"count_is");
|
||||
let count_is_args = ~[count_lit];
|
||||
ret mk_call(cx, sp, count_is_path, count_is_args);
|
||||
}
|
||||
_ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); }
|
||||
_ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); }
|
||||
}
|
||||
}
|
||||
fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr {
|
||||
@ -83,13 +83,13 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
alt t {
|
||||
ty_hex(c) {
|
||||
alt c {
|
||||
case_upper { rt_type = "ty_hex_upper"; }
|
||||
case_lower { rt_type = "ty_hex_lower"; }
|
||||
case_upper { rt_type = ~"ty_hex_upper"; }
|
||||
case_lower { rt_type = ~"ty_hex_lower"; }
|
||||
}
|
||||
}
|
||||
ty_bits { rt_type = "ty_bits"; }
|
||||
ty_octal { rt_type = "ty_octal"; }
|
||||
_ { rt_type = "ty_default"; }
|
||||
ty_bits { rt_type = ~"ty_bits"; }
|
||||
ty_octal { rt_type = ~"ty_octal"; }
|
||||
_ { rt_type = ~"ty_default"; }
|
||||
}
|
||||
ret make_rt_path_expr(cx, sp, @rt_type);
|
||||
}
|
||||
@ -97,10 +97,10 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
width_expr: @ast::expr, precision_expr: @ast::expr,
|
||||
ty_expr: @ast::expr) -> @ast::expr {
|
||||
ret mk_rec_e(cx, sp,
|
||||
~[{ident: @"flags"/~, ex: flags_expr},
|
||||
{ident: @"width"/~, ex: width_expr},
|
||||
{ident: @"precision"/~, ex: precision_expr},
|
||||
{ident: @"ty"/~, ex: ty_expr}]);
|
||||
~[{ident: @~"flags", ex: flags_expr},
|
||||
{ident: @~"width", ex: width_expr},
|
||||
{ident: @~"precision", ex: precision_expr},
|
||||
{ident: @~"ty", ex: ty_expr}]);
|
||||
}
|
||||
let rt_conv_flags = make_flags(cx, sp, cnv.flags);
|
||||
let rt_conv_width = make_count(cx, sp, cnv.width);
|
||||
@ -109,9 +109,9 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width,
|
||||
rt_conv_precision, rt_conv_ty);
|
||||
}
|
||||
fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: str, cnv: conv,
|
||||
fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: ~str, cnv: conv,
|
||||
arg: @ast::expr) -> @ast::expr {
|
||||
let fname = "conv_" + conv_type;
|
||||
let fname = ~"conv_" + conv_type;
|
||||
let path = make_path_vec(cx, @fname);
|
||||
let cnv_expr = make_rt_conv_expr(cx, sp, cnv);
|
||||
let args = ~[cnv_expr, arg];
|
||||
@ -131,7 +131,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
_ { ret false; }
|
||||
}
|
||||
}
|
||||
let unsupported = "conversion not supported in #fmt string";
|
||||
let unsupported = ~"conversion not supported in #fmt string";
|
||||
alt cnv.param {
|
||||
option::none { }
|
||||
_ { cx.span_unimpl(sp, unsupported); }
|
||||
@ -142,15 +142,15 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
flag_sign_always {
|
||||
if !is_signed_type(cnv) {
|
||||
cx.span_fatal(sp,
|
||||
"+ flag only valid in " +
|
||||
"signed #fmt conversion");
|
||||
~"+ flag only valid in " +
|
||||
~"signed #fmt conversion");
|
||||
}
|
||||
}
|
||||
flag_space_for_sign {
|
||||
if !is_signed_type(cnv) {
|
||||
cx.span_fatal(sp,
|
||||
"space flag only valid in " +
|
||||
"signed #fmt conversions");
|
||||
~"space flag only valid in " +
|
||||
~"signed #fmt conversions");
|
||||
}
|
||||
}
|
||||
flag_left_zero_pad { }
|
||||
@ -168,27 +168,27 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
_ { cx.span_unimpl(sp, unsupported); }
|
||||
}
|
||||
alt cnv.ty {
|
||||
ty_str { ret make_conv_call(cx, arg.span, "str", cnv, arg); }
|
||||
ty_str { ret make_conv_call(cx, arg.span, ~"str", cnv, arg); }
|
||||
ty_int(sign) {
|
||||
alt sign {
|
||||
signed { ret make_conv_call(cx, arg.span, "int", cnv, arg); }
|
||||
signed { ret make_conv_call(cx, arg.span, ~"int", cnv, arg); }
|
||||
unsigned {
|
||||
ret make_conv_call(cx, arg.span, "uint", cnv, arg);
|
||||
ret make_conv_call(cx, arg.span, ~"uint", cnv, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
ty_bool { ret make_conv_call(cx, arg.span, "bool", cnv, arg); }
|
||||
ty_char { ret make_conv_call(cx, arg.span, "char", cnv, arg); }
|
||||
ty_hex(_) { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
|
||||
ty_bits { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
|
||||
ty_octal { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
|
||||
ty_float { ret make_conv_call(cx, arg.span, "float", cnv, arg); }
|
||||
ty_poly { ret make_conv_call(cx, arg.span, "poly", cnv, arg); }
|
||||
ty_bool { ret make_conv_call(cx, arg.span, ~"bool", cnv, arg); }
|
||||
ty_char { ret make_conv_call(cx, arg.span, ~"char", cnv, arg); }
|
||||
ty_hex(_) { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
|
||||
ty_bits { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
|
||||
ty_octal { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
|
||||
ty_float { ret make_conv_call(cx, arg.span, ~"float", cnv, arg); }
|
||||
ty_poly { ret make_conv_call(cx, arg.span, ~"poly", cnv, arg); }
|
||||
}
|
||||
}
|
||||
fn log_conv(c: conv) {
|
||||
alt 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"); }
|
||||
}
|
||||
for c.flags.each |f| {
|
||||
@ -202,20 +202,20 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
}
|
||||
alt c.width {
|
||||
count_is(i) { log(debug,
|
||||
"width: count is " + int::to_str(i, 10u)); }
|
||||
~"width: count is " + int::to_str(i, 10u)); }
|
||||
count_is_param(i) {
|
||||
log(debug,
|
||||
"width: count is param " + int::to_str(i, 10u));
|
||||
~"width: count is param " + int::to_str(i, 10u));
|
||||
}
|
||||
count_is_next_param { #debug("width: count is next param"); }
|
||||
count_implied { #debug("width: count is implied"); }
|
||||
}
|
||||
alt c.precision {
|
||||
count_is(i) { log(debug,
|
||||
"prec: count is " + int::to_str(i, 10u)); }
|
||||
~"prec: count is " + int::to_str(i, 10u)); }
|
||||
count_is_param(i) {
|
||||
log(debug,
|
||||
"prec: count is param " + int::to_str(i, 10u));
|
||||
~"prec: count is param " + int::to_str(i, 10u));
|
||||
}
|
||||
count_is_next_param { #debug("prec: count is next param"); }
|
||||
count_implied { #debug("prec: count is implied"); }
|
||||
@ -255,8 +255,8 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
n += 1u;
|
||||
if n >= nargs {
|
||||
cx.span_fatal(sp,
|
||||
"not enough arguments to #fmt " +
|
||||
"for the given format string");
|
||||
~"not enough arguments to #fmt " +
|
||||
~"for the given format string");
|
||||
}
|
||||
#debug("Building conversion:");
|
||||
log_conv(conv);
|
||||
@ -275,7 +275,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
}
|
||||
|
||||
let arg_vec = mk_fixed_vec_e(cx, fmt_sp, piece_exprs);
|
||||
ret mk_call(cx, fmt_sp, ~[@"str"/~, @"concat"/~], ~[arg_vec]);
|
||||
ret mk_call(cx, fmt_sp, ~[@~"str", @~"concat"], ~[arg_vec]);
|
||||
}
|
||||
//
|
||||
// Local Variables:
|
||||
|
@ -4,8 +4,8 @@ import option;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),"ident_to_str");
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"ident_to_str");
|
||||
|
||||
ret mk_uniq_str(cx, sp, *expr_to_ident(cx, args[0u],
|
||||
"expected an ident"));
|
||||
~"expected an ident"));
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ import io::writer_util;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args_no_max(cx,sp,arg,0u,"log_syntax");
|
||||
let args = get_mac_args_no_max(cx,sp,arg,0u,~"log_syntax");
|
||||
cx.print_backtrace();
|
||||
io::stdout().write_line(
|
||||
str::connect(vec::map(args,
|
||||
|&&ex| print::pprust::expr_to_str(ex)), ", ")
|
||||
|&&ex| print::pprust::expr_to_str(ex)), ~", ")
|
||||
);
|
||||
|
||||
//trivial expression
|
||||
|
@ -7,7 +7,7 @@ import ast::{ident, node_id};
|
||||
import codemap::span;
|
||||
import ext::base::mk_ctxt;
|
||||
|
||||
fn ident(s: str) -> ast::ident {
|
||||
fn ident(s: ~str) -> ast::ident {
|
||||
@(copy s)
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@ impl proto_parser for parser {
|
||||
};
|
||||
self.bump();
|
||||
let dir = alt dir {
|
||||
@"send"/~ { send }
|
||||
@"recv"/~ { recv }
|
||||
@~"send" { send }
|
||||
@~"recv" { recv }
|
||||
_ { fail }
|
||||
};
|
||||
|
||||
|
@ -23,10 +23,10 @@ enum direction {
|
||||
}
|
||||
|
||||
impl of to_str for direction {
|
||||
fn to_str() -> str {
|
||||
fn to_str() -> ~str {
|
||||
alt self {
|
||||
send { "send" }
|
||||
recv { "recv" }
|
||||
send { ~"send" }
|
||||
recv { ~"recv" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,35 +68,35 @@ impl methods for message {
|
||||
message(id, tys, this, next, next_tys) {
|
||||
let next = this.proto.get_state(next);
|
||||
assert next_tys.len() == next.ty_params.len();
|
||||
let arg_names = tys.mapi(|i, _ty| @("x_" + i.to_str()));
|
||||
let arg_names = tys.mapi(|i, _ty| @(~"x_" + i.to_str()));
|
||||
|
||||
let args_ast = (arg_names, tys).map(
|
||||
|n, t| cx.arg_mode(n, t, ast::by_copy)
|
||||
);
|
||||
|
||||
let args_ast = vec::append(
|
||||
~[cx.arg_mode(@"pipe"/~,
|
||||
~[cx.arg_mode(@~"pipe",
|
||||
cx.ty_path(path(this.data_name())
|
||||
.add_tys(cx.ty_vars(this.ty_params))),
|
||||
ast::by_copy)],
|
||||
args_ast);
|
||||
|
||||
let pat = alt (this.dir, next.dir) {
|
||||
(send, send) { "(c, s)" }
|
||||
(send, recv) { "(s, c)" }
|
||||
(recv, send) { "(s, c)" }
|
||||
(recv, recv) { "(c, s)" }
|
||||
(send, send) { ~"(c, s)" }
|
||||
(send, recv) { ~"(s, c)" }
|
||||
(recv, send) { ~"(s, c)" }
|
||||
(recv, recv) { ~"(c, s)" }
|
||||
};
|
||||
|
||||
let mut body = #fmt("{ let %s = pipes::entangle();\n", pat);
|
||||
body += #fmt("let message = %s::%s(%s);\n",
|
||||
*this.proto.name,
|
||||
*self.name(),
|
||||
str::connect(vec::append_one(arg_names, @"s"/~)
|
||||
str::connect(vec::append_one(arg_names, @~"s")
|
||||
.map(|x| *x),
|
||||
", "));
|
||||
~", "));
|
||||
body += #fmt("pipes::send(pipe, message);\n");
|
||||
body += "c }";
|
||||
body += ~"c }";
|
||||
|
||||
let body = cx.parse_expr(body);
|
||||
|
||||
@ -127,7 +127,7 @@ impl methods for state {
|
||||
self.messages.push(message(name, data, self, next, next_tys));
|
||||
}
|
||||
|
||||
fn filename() -> str {
|
||||
fn filename() -> ~str {
|
||||
(*self).proto.filename()
|
||||
}
|
||||
|
||||
@ -158,8 +158,8 @@ impl methods for state {
|
||||
let next_name = next.data_name();
|
||||
|
||||
let dir = alt this.dir {
|
||||
send { @"server"/~ }
|
||||
recv { @"client"/~ }
|
||||
send { @~"server" }
|
||||
recv { @~"client" }
|
||||
};
|
||||
|
||||
let v = cx.variant(name,
|
||||
@ -190,7 +190,7 @@ impl methods for state {
|
||||
cx.item_ty_poly(
|
||||
self.data_name(),
|
||||
cx.ty_path(
|
||||
(@"pipes"/~ + @(dir.to_str() + "_packet"/~))
|
||||
(@~"pipes" + @(dir.to_str() + ~"_packet"))
|
||||
.add_ty(cx.ty_path(
|
||||
(self.proto.name + self.data_name())
|
||||
.add_tys(cx.ty_vars(self.ty_params))))),
|
||||
@ -236,17 +236,17 @@ impl methods for protocol {
|
||||
state
|
||||
}
|
||||
|
||||
fn filename() -> str {
|
||||
"proto://" + *self.name
|
||||
fn filename() -> ~str {
|
||||
~"proto://" + *self.name
|
||||
}
|
||||
|
||||
fn gen_init(cx: ext_ctxt) -> @ast::item {
|
||||
let start_state = self.states[0];
|
||||
|
||||
let body = alt start_state.dir {
|
||||
send { cx.parse_expr("pipes::entangle()") }
|
||||
send { cx.parse_expr(~"pipes::entangle()") }
|
||||
recv {
|
||||
cx.parse_expr("{ \
|
||||
cx.parse_expr(~"{ \
|
||||
let (s, c) = pipes::entangle(); \
|
||||
(c, s) \
|
||||
}")
|
||||
@ -281,10 +281,10 @@ impl methods for protocol {
|
||||
}
|
||||
|
||||
vec::push(items,
|
||||
cx.item_mod(@"client"/~,
|
||||
cx.item_mod(@~"client",
|
||||
client_states));
|
||||
vec::push(items,
|
||||
cx.item_mod(@"server"/~,
|
||||
cx.item_mod(@~"server",
|
||||
server_states));
|
||||
|
||||
cx.item_mod(self.name, items)
|
||||
@ -293,49 +293,49 @@ impl methods for protocol {
|
||||
|
||||
iface to_source {
|
||||
// Takes a thing and generates a string containing rust code for it.
|
||||
fn to_source() -> str;
|
||||
fn to_source() -> ~str;
|
||||
}
|
||||
|
||||
impl of to_source for @ast::item {
|
||||
fn to_source() -> str {
|
||||
fn to_source() -> ~str {
|
||||
item_to_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl of to_source for ~[@ast::item] {
|
||||
fn to_source() -> str {
|
||||
str::connect(self.map(|i| i.to_source()), "\n\n")
|
||||
fn to_source() -> ~str {
|
||||
str::connect(self.map(|i| i.to_source()), ~"\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
impl of to_source for @ast::ty {
|
||||
fn to_source() -> str {
|
||||
fn to_source() -> ~str {
|
||||
ty_to_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl of to_source for ~[@ast::ty] {
|
||||
fn to_source() -> str {
|
||||
str::connect(self.map(|i| i.to_source()), ", ")
|
||||
fn to_source() -> ~str {
|
||||
str::connect(self.map(|i| i.to_source()), ~", ")
|
||||
}
|
||||
}
|
||||
|
||||
impl of to_source for ~[ast::ty_param] {
|
||||
fn to_source() -> str {
|
||||
fn to_source() -> ~str {
|
||||
pprust::typarams_to_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl of to_source for @ast::expr {
|
||||
fn to_source() -> str {
|
||||
fn to_source() -> ~str {
|
||||
pprust::expr_to_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl parse_utils for ext_ctxt {
|
||||
fn parse_item(s: str) -> @ast::item {
|
||||
fn parse_item(s: ~str) -> @ast::item {
|
||||
let res = parse::parse_item_from_source_str(
|
||||
"***protocol expansion***",
|
||||
~"***protocol expansion***",
|
||||
@(copy s),
|
||||
self.cfg(),
|
||||
~[],
|
||||
@ -350,9 +350,9 @@ impl parse_utils for ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_expr(s: str) -> @ast::expr {
|
||||
fn parse_expr(s: ~str) -> @ast::expr {
|
||||
parse::parse_expr_from_source_str(
|
||||
"***protocol expansion***",
|
||||
~"***protocol expansion***",
|
||||
@(copy s),
|
||||
self.cfg(),
|
||||
self.parse_sess())
|
||||
|
@ -16,7 +16,7 @@ import codemap::span;
|
||||
type aq_ctxt = @{lo: uint,
|
||||
gather: dvec<{lo: uint, hi: uint,
|
||||
e: @ast::expr,
|
||||
constr: str}>};
|
||||
constr: ~str}>};
|
||||
enum fragment {
|
||||
from_expr(@ast::expr),
|
||||
from_ty(@ast::ty)
|
||||
@ -27,7 +27,7 @@ iface qq_helper {
|
||||
fn visit(aq_ctxt, vt<aq_ctxt>);
|
||||
fn extract_mac() -> option<ast::mac_>;
|
||||
fn mk_parse_fn(ext_ctxt,span) -> @ast::expr;
|
||||
fn get_fold_fn() -> str;
|
||||
fn get_fold_fn() -> ~str;
|
||||
}
|
||||
|
||||
impl of qq_helper for @ast::crate {
|
||||
@ -36,9 +36,9 @@ impl of qq_helper for @ast::crate {
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"parse_crate"/~])
|
||||
~[@~"syntax", @~"ext", @~"qquote", @~"parse_crate"])
|
||||
}
|
||||
fn get_fold_fn() -> str {"fold_crate"}
|
||||
fn get_fold_fn() -> ~str {~"fold_crate"}
|
||||
}
|
||||
impl of qq_helper for @ast::expr {
|
||||
fn span() -> span {self.span}
|
||||
@ -51,9 +51,9 @@ impl of qq_helper for @ast::expr {
|
||||
}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"parse_expr"/~])
|
||||
~[@~"syntax", @~"ext", @~"qquote", @~"parse_expr"])
|
||||
}
|
||||
fn get_fold_fn() -> str {"fold_expr"}
|
||||
fn get_fold_fn() -> ~str {~"fold_expr"}
|
||||
}
|
||||
impl of qq_helper for @ast::ty {
|
||||
fn span() -> span {self.span}
|
||||
@ -66,9 +66,9 @@ impl of qq_helper for @ast::ty {
|
||||
}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"parse_ty"/~])
|
||||
~[@~"syntax", @~"ext", @~"qquote", @~"parse_ty"])
|
||||
}
|
||||
fn get_fold_fn() -> str {"fold_ty"}
|
||||
fn get_fold_fn() -> ~str {~"fold_ty"}
|
||||
}
|
||||
impl of qq_helper for @ast::item {
|
||||
fn span() -> span {self.span}
|
||||
@ -76,9 +76,9 @@ impl of qq_helper for @ast::item {
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"parse_item"/~])
|
||||
~[@~"syntax", @~"ext", @~"qquote", @~"parse_item"])
|
||||
}
|
||||
fn get_fold_fn() -> str {"fold_item"}
|
||||
fn get_fold_fn() -> ~str {~"fold_item"}
|
||||
}
|
||||
impl of qq_helper for @ast::stmt {
|
||||
fn span() -> span {self.span}
|
||||
@ -86,24 +86,24 @@ impl of qq_helper for @ast::stmt {
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"parse_stmt"/~])
|
||||
~[@~"syntax", @~"ext", @~"qquote", @~"parse_stmt"])
|
||||
}
|
||||
fn get_fold_fn() -> str {"fold_stmt"}
|
||||
fn get_fold_fn() -> ~str {~"fold_stmt"}
|
||||
}
|
||||
impl of qq_helper for @ast::pat {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_pat(self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp, ~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"parse_pat"/~])
|
||||
mk_path(cx, sp, ~[@~"syntax", @~"ext", @~"qquote", @~"parse_pat"])
|
||||
}
|
||||
fn get_fold_fn() -> str {"fold_pat"}
|
||||
fn get_fold_fn() -> ~str {~"fold_pat"}
|
||||
}
|
||||
|
||||
fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
|
||||
{
|
||||
let v = @{visit_expr: |node, &&cx, v| visit_aq(node, "from_expr", cx, v),
|
||||
visit_ty: |node, &&cx, v| visit_aq(node, "from_ty", cx, v)
|
||||
let v = @{visit_expr: |node, &&cx, v| visit_aq(node, ~"from_expr", cx, v),
|
||||
visit_ty: |node, &&cx, v| visit_aq(node, ~"from_ty", cx, v)
|
||||
with *default_visitor()};
|
||||
let cx = @{lo:lo, gather: dvec()};
|
||||
node.visit(cx, mk_vt(v));
|
||||
@ -115,7 +115,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
|
||||
ret cx;
|
||||
}
|
||||
|
||||
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()) {
|
||||
some(mac_aq(sp, e)) {
|
||||
@ -134,35 +134,35 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
|
||||
arg: ast::mac_arg, body: ast::mac_body)
|
||||
-> @ast::expr
|
||||
{
|
||||
let mut what = "expr";
|
||||
let mut what = ~"expr";
|
||||
do option::iter(arg) |arg| {
|
||||
let args: ~[@ast::expr] =
|
||||
alt arg.node {
|
||||
ast::expr_vec(elts, _) { elts }
|
||||
_ {
|
||||
ecx.span_fatal
|
||||
(_sp, "#ast requires arguments of the form `~[...]`.")
|
||||
(_sp, ~"#ast requires arguments of the form `~[...]`.")
|
||||
}
|
||||
};
|
||||
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) {
|
||||
ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u
|
||||
{what = *id[0]}
|
||||
_ {ecx.span_fatal(args[0].span, "expected an identifier");}
|
||||
_ {ecx.span_fatal(args[0].span, ~"expected an identifier");}
|
||||
}
|
||||
}
|
||||
let body = get_mac_body(ecx,_sp,body);
|
||||
|
||||
ret alt what {
|
||||
"crate" {finish(ecx, body, parse_crate)}
|
||||
"expr" {finish(ecx, body, parse_expr)}
|
||||
"ty" {finish(ecx, body, parse_ty)}
|
||||
"item" {finish(ecx, body, parse_item)}
|
||||
"stmt" {finish(ecx, body, parse_stmt)}
|
||||
"pat" {finish(ecx, body, parse_pat)}
|
||||
_ {ecx.span_fatal(_sp, "unsupported ast type")}
|
||||
~"crate" {finish(ecx, body, parse_crate)}
|
||||
~"expr" {finish(ecx, body, parse_expr)}
|
||||
~"ty" {finish(ecx, body, parse_ty)}
|
||||
~"item" {finish(ecx, body, parse_item)}
|
||||
~"stmt" {finish(ecx, body, parse_stmt)}
|
||||
~"pat" {finish(ecx, body, parse_pat)}
|
||||
_ {ecx.span_fatal(_sp, ~"unsupported ast type")}
|
||||
};
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ fn parse_pat(p: parser) -> @ast::pat { p.parse_pat() }
|
||||
fn parse_item(p: parser) -> @ast::item {
|
||||
alt p.parse_item(~[], ast::public) {
|
||||
some(item) { item }
|
||||
none { fail "parse_item: parsing an item failed"; }
|
||||
none { fail ~"parse_item: parsing an item failed"; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ fn finish<T: qq_helper>
|
||||
// ^^ check that the spans are non-overlapping
|
||||
}
|
||||
|
||||
let mut str2 = "";
|
||||
let mut str2 = ~"";
|
||||
enum state {active, skip(uint), blank};
|
||||
let mut state = active;
|
||||
let mut i = 0u, j = 0u;
|
||||
@ -233,19 +233,19 @@ fn finish<T: qq_helper>
|
||||
let cx = ecx;
|
||||
|
||||
let cfg_call = || mk_call_(
|
||||
cx, sp, mk_access(cx, sp, ~[@"ext_cx"/~], @"cfg"/~), ~[]);
|
||||
cx, sp, mk_access(cx, sp, ~[@~"ext_cx"], @~"cfg"), ~[]);
|
||||
|
||||
let parse_sess_call = || mk_call_(
|
||||
cx, sp, mk_access(cx, sp, ~[@"ext_cx"/~], @"parse_sess"/~), ~[]);
|
||||
cx, sp, mk_access(cx, sp, ~[@~"ext_cx"], @~"parse_sess"), ~[]);
|
||||
|
||||
let pcall = mk_call(cx,sp,
|
||||
~[@"syntax"/~, @"parse"/~, @"parser"/~,
|
||||
@"parse_from_source_str"/~],
|
||||
~[@~"syntax", @~"parse", @~"parser",
|
||||
@~"parse_from_source_str"],
|
||||
~[node.mk_parse_fn(cx,sp),
|
||||
mk_uniq_str(cx,sp, fname),
|
||||
mk_call(cx,sp,
|
||||
~[@"syntax"/~,@"ext"/~,
|
||||
@"qquote"/~, @"mk_file_substr"/~],
|
||||
~[@~"syntax",@~"ext",
|
||||
@~"qquote", @~"mk_file_substr"],
|
||||
~[mk_uniq_str(cx,sp, loc.file.name),
|
||||
mk_uint(cx,sp, loc.line),
|
||||
mk_uint(cx,sp, loc.col)]),
|
||||
@ -257,15 +257,15 @@ fn finish<T: qq_helper>
|
||||
let mut rcall = pcall;
|
||||
if (g_len > 0u) {
|
||||
rcall = mk_call(cx,sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~, @"replace"/~],
|
||||
~[@~"syntax", @~"ext", @~"qquote", @~"replace"],
|
||||
~[pcall,
|
||||
mk_uniq_vec_e(cx,sp, qcx.gather.map_to_vec(|g| {
|
||||
mk_call(cx,sp,
|
||||
~[@"syntax"/~, @"ext"/~,
|
||||
@"qquote"/~, @g.constr],
|
||||
~[@~"syntax", @~"ext",
|
||||
@~"qquote", @g.constr],
|
||||
~[g.e])})),
|
||||
mk_path(cx,sp,
|
||||
~[@"syntax"/~, @"ext"/~, @"qquote"/~,
|
||||
~[@~"syntax", @~"ext", @~"qquote",
|
||||
@node.get_fold_fn()])]);
|
||||
}
|
||||
ret rcall;
|
||||
@ -326,10 +326,11 @@ fn print_expr(expr: @ast::expr) {
|
||||
let pp = pprust::rust_printer(stdout);
|
||||
pprust::print_expr(pp, expr);
|
||||
pp::eof(pp.s);
|
||||
stdout.write_str("\n");
|
||||
stdout.write_str(~"\n");
|
||||
}
|
||||
|
||||
fn mk_file_substr(fname: str, line: uint, col: uint) -> codemap::file_substr {
|
||||
fn mk_file_substr(fname: ~str, line: uint, col: uint) ->
|
||||
codemap::file_substr {
|
||||
codemap::fss_external({filename: fname, line: line, col: col})
|
||||
}
|
||||
|
||||
|
@ -35,29 +35,29 @@ enum matchable {
|
||||
}
|
||||
|
||||
/* 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_expr(x) {
|
||||
cx.span_fatal(x.span,
|
||||
"this argument is an expr, expected " + expected);
|
||||
~"this argument is an expr, expected " + expected);
|
||||
}
|
||||
match_path(x) {
|
||||
cx.span_fatal(x.span,
|
||||
"this argument is a path, expected " + expected);
|
||||
~"this argument is a path, expected " + expected);
|
||||
}
|
||||
match_ident(x) {
|
||||
cx.span_fatal(x.span,
|
||||
"this argument is an ident, expected " + expected);
|
||||
~"this argument is an ident, expected " + expected);
|
||||
}
|
||||
match_ty(x) {
|
||||
cx.span_fatal(x.span,
|
||||
"this argument is a type, expected " + expected);
|
||||
~"this argument is a type, expected " + expected);
|
||||
}
|
||||
match_block(x) {
|
||||
cx.span_fatal(x.span,
|
||||
"this argument is a block, expected " + expected);
|
||||
~"this argument is a block, expected " + expected);
|
||||
}
|
||||
match_exact { cx.bug("what is a match_exact doing in a bindings?"); }
|
||||
match_exact { cx.bug(~"what is a match_exact doing in a bindings?"); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
|
||||
alt m.node {
|
||||
ast::mac_ellipsis {
|
||||
if res != none {
|
||||
cx.span_fatal(m.span, "only one ellipsis allowed");
|
||||
cx.span_fatal(m.span, ~"only one ellipsis allowed");
|
||||
}
|
||||
res =
|
||||
some({pre: vec::slice(elts, 0u, idx - 1u),
|
||||
@ -234,8 +234,8 @@ fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>,
|
||||
ret alt follow(m, idx_path) {
|
||||
seq(_, sp) {
|
||||
cx.span_fatal(sp,
|
||||
"syntax matched under ... but not " +
|
||||
"used that way.")
|
||||
~"syntax matched under ... but not " +
|
||||
~"used that way.")
|
||||
}
|
||||
leaf(m) { ret some(m) }
|
||||
}
|
||||
@ -302,8 +302,8 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
alt repeat {
|
||||
none {
|
||||
cx.span_fatal(repeat_me.span,
|
||||
"'...' surrounds an expression without any" +
|
||||
" repeating syntax variables");
|
||||
~"'...' surrounds an expression without any" +
|
||||
~" repeating syntax variables");
|
||||
}
|
||||
some({rep_count: rc, _}) {
|
||||
/* Whew, we now know how how many times to repeat */
|
||||
@ -331,7 +331,7 @@ fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
&&i: ident, _fld: ast_fold) -> ident {
|
||||
ret alt follow_for_trans(cx, b.find(i), idx_path) {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,7 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
rp: none, types: ~[]}
|
||||
}
|
||||
some(match_path(a_pth)) { *a_pth }
|
||||
some(m) { match_error(cx, m, "a path") }
|
||||
some(m) { match_error(cx, m, ~"a path") }
|
||||
none { p }
|
||||
}
|
||||
}
|
||||
@ -374,7 +374,7 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
}
|
||||
some(match_path(a_pth)) { (expr_path(a_pth), s) }
|
||||
some(match_expr(a_exp)) { (a_exp.node, a_exp.span) }
|
||||
some(m) { match_error(cx, m, "an expression") }
|
||||
some(m) { match_error(cx, m, ~"an expression") }
|
||||
none { orig(e, s, fld) }
|
||||
}
|
||||
}
|
||||
@ -393,7 +393,7 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
some(id) {
|
||||
alt follow_for_trans(cx, b.find(id), idx_path) {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
@ -424,7 +424,7 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
|
||||
// possibly allow promotion of ident/path/expr to blocks?
|
||||
some(m) {
|
||||
match_error(cx, m, "a block")
|
||||
match_error(cx, m, ~"a block")
|
||||
}
|
||||
none { orig(blk, s, fld) }
|
||||
}
|
||||
@ -455,12 +455,12 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
||||
|
||||
if vec::len(post) > 0u {
|
||||
cx.span_unimpl(e.span,
|
||||
"matching after `...` not yet supported");
|
||||
~"matching after `...` not yet supported");
|
||||
}
|
||||
}
|
||||
{pre: pre, rep: none, post: post} {
|
||||
if post != ~[] {
|
||||
cx.bug("elts_to_ell provided an invalid result");
|
||||
cx.bug(~"elts_to_ell provided an invalid result");
|
||||
}
|
||||
p_t_s_r_length(cx, vec::len(pre), false, s, b);
|
||||
p_t_s_r_actual_vector(cx, pre, false, s, b);
|
||||
@ -478,7 +478,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
||||
match_expr(e) {
|
||||
if e == pat { some(leaf(match_exact)) } else { none }
|
||||
}
|
||||
_ { cx.bug("broken traversal in p_t_s_r") }
|
||||
_ { cx.bug(~"broken traversal in p_t_s_r") }
|
||||
}
|
||||
}
|
||||
b.literal_ast_matchers.push(|x| select(cx, x, e));
|
||||
@ -486,7 +486,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
||||
}
|
||||
}
|
||||
_ {
|
||||
cx.bug("undocumented invariant in p_t_s_rec");
|
||||
cx.bug(~"undocumented invariant in p_t_s_rec");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -517,11 +517,11 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
|
||||
fn select(cx: ext_ctxt, m: matchable) -> match_result {
|
||||
ret alt 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") }
|
||||
}
|
||||
}
|
||||
if b.real_binders.contains_key(p_id) {
|
||||
cx.span_fatal(p.span, "duplicate binding identifier");
|
||||
cx.span_fatal(p.span, ~"duplicate binding identifier");
|
||||
}
|
||||
b.real_binders.insert(p_id, compose_sels(s, |x| select(cx, x)));
|
||||
}
|
||||
@ -546,16 +546,16 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
|
||||
match_expr(e) {
|
||||
alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }
|
||||
}
|
||||
_ { cx.bug("broken traversal in p_t_s_r") }
|
||||
_ { cx.bug(~"broken traversal in p_t_s_r") }
|
||||
}
|
||||
}
|
||||
fn no_des(cx: ext_ctxt, sp: span, syn: str) -> ! {
|
||||
cx.span_fatal(sp, "destructuring " + syn + " is not yet supported");
|
||||
fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! {
|
||||
cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported");
|
||||
}
|
||||
alt mac.node {
|
||||
ast::mac_ellipsis { cx.span_fatal(mac.span, "misused `...`"); }
|
||||
ast::mac_invoc(_, _, _) { no_des(cx, mac.span, "macro calls"); }
|
||||
ast::mac_invoc_tt(_, _) { no_des(cx, mac.span, "macro calls"); }
|
||||
ast::mac_ellipsis { cx.span_fatal(mac.span, ~"misused `...`"); }
|
||||
ast::mac_invoc(_, _, _) { no_des(cx, mac.span, ~"macro calls"); }
|
||||
ast::mac_invoc_tt(_, _) { no_des(cx, mac.span, ~"macro calls"); }
|
||||
ast::mac_embed_type(ty) {
|
||||
alt ty.node {
|
||||
ast::ty_path(pth, _) {
|
||||
@ -571,10 +571,10 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
|
||||
let final_step = |x| select_pt_1(cx, x, select_pt_2);
|
||||
b.real_binders.insert(id, compose_sels(s, final_step));
|
||||
}
|
||||
none { no_des(cx, pth.span, "under `#<>`"); }
|
||||
none { no_des(cx, pth.span, ~"under `#<>`"); }
|
||||
}
|
||||
}
|
||||
_ { no_des(cx, ty.span, "under `#<>`"); }
|
||||
_ { no_des(cx, ty.span, ~"under `#<>`"); }
|
||||
}
|
||||
}
|
||||
ast::mac_embed_block(blk) {
|
||||
@ -591,11 +591,11 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
|
||||
let final_step = |x| select_pt_1(cx, x, select_pt_2);
|
||||
b.real_binders.insert(id, compose_sels(s, final_step));
|
||||
}
|
||||
none { no_des(cx, blk.span, "under `#{}`"); }
|
||||
none { no_des(cx, blk.span, ~"under `#{}`"); }
|
||||
}
|
||||
}
|
||||
ast::mac_aq(_,_) { no_des(cx, mac.span, "antiquotes"); }
|
||||
ast::mac_var(_) { no_des(cx, mac.span, "antiquote variables"); }
|
||||
ast::mac_aq(_,_) { no_des(cx, mac.span, ~"antiquotes"); }
|
||||
ast::mac_var(_) { no_des(cx, mac.span, ~"antiquote variables"); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,7 +621,7 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector,
|
||||
_ { none }
|
||||
}
|
||||
}
|
||||
_ { cx.bug("broken traversal in p_t_s_r") }
|
||||
_ { cx.bug(~"broken traversal in p_t_s_r") }
|
||||
}
|
||||
}
|
||||
p_t_s_rec(cx, match_expr(repeat_me),
|
||||
@ -666,7 +666,7 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
|
||||
_ { none }
|
||||
}
|
||||
}
|
||||
_ { cx.bug("broken traversal in p_t_s_r") }
|
||||
_ { cx.bug(~"broken traversal in p_t_s_r") }
|
||||
}
|
||||
}
|
||||
p_t_s_rec(cx, match_expr(elts[idx]),
|
||||
@ -677,17 +677,17 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
|
||||
|
||||
fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> base::macro_def {
|
||||
let args = get_mac_args_no_max(cx, sp, arg, 0u, "macro");
|
||||
let args = get_mac_args_no_max(cx, sp, arg, 0u, ~"macro");
|
||||
|
||||
let mut macro_name: option<@str/~> = none;
|
||||
let mut macro_name: option<@~str> = none;
|
||||
let mut clauses: ~[@clause] = ~[];
|
||||
for args.each |arg| {
|
||||
alt arg.node {
|
||||
expr_vec(elts, mutbl) {
|
||||
if vec::len(elts) != 2u {
|
||||
cx.span_fatal((*arg).span,
|
||||
"extension clause must consist of ~[" +
|
||||
"macro invocation, expansion body]");
|
||||
~"extension clause must consist of ~[" +
|
||||
~"macro invocation, expansion body]");
|
||||
}
|
||||
|
||||
|
||||
@ -702,21 +702,21 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
some(other_id) {
|
||||
if id != other_id {
|
||||
cx.span_fatal(pth.span,
|
||||
"macro name must be " +
|
||||
"consistent");
|
||||
~"macro name must be " +
|
||||
~"consistent");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
some(arg) { arg }
|
||||
none { cx.span_fatal(mac.span,
|
||||
"macro must have arguments")}
|
||||
~"macro must have arguments")}
|
||||
};
|
||||
vec::push(clauses,
|
||||
@{params: pattern_to_selectors(cx, arg),
|
||||
@ -726,21 +726,21 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
// the macro arg situation)
|
||||
}
|
||||
_ {
|
||||
cx.span_bug(mac.span, "undocumented invariant in \
|
||||
cx.span_bug(mac.span, ~"undocumented invariant in \
|
||||
add_extension");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ {
|
||||
cx.span_fatal(elts[0u].span,
|
||||
"extension clause must" +
|
||||
" start with a macro invocation.");
|
||||
~"extension clause must" +
|
||||
~" start with a macro invocation.");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ {
|
||||
cx.span_fatal((*arg).span,
|
||||
"extension must be ~[clause, " + " ...]");
|
||||
~"extension must be ~[clause, " + ~" ...]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -751,8 +751,8 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
alt macro_name {
|
||||
some(id) { id }
|
||||
none {
|
||||
cx.span_fatal(sp, "macro definition must have " +
|
||||
"at least one clause")
|
||||
cx.span_fatal(sp, ~"macro definition must have " +
|
||||
~"at least one clause")
|
||||
}
|
||||
},
|
||||
ext: normal({expander: ext, span: some(option::get(arg).span)})};
|
||||
@ -762,7 +762,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
clauses: ~[@clause]) -> @expr {
|
||||
let arg = alt 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| {
|
||||
alt use_selectors_to_bind(c.params, arg) {
|
||||
@ -770,7 +770,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
none { again; }
|
||||
}
|
||||
}
|
||||
cx.span_fatal(sp, "no clauses match macro invocation");
|
||||
cx.span_fatal(sp, ~"no clauses match macro invocation");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ export expand_include_bin;
|
||||
/* #line(): expands to the current line number */
|
||||
fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "line");
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"line");
|
||||
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
ret mk_uint(cx, sp, loc.line);
|
||||
}
|
||||
@ -24,7 +24,7 @@ fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
/* #col(): expands to the current column number */
|
||||
fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "col");
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"col");
|
||||
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
ret mk_uint(cx, sp, loc.col);
|
||||
}
|
||||
@ -34,7 +34,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
* out if we wanted. */
|
||||
fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "file");
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"file");
|
||||
let { file: @{ name: filename, _ }, _ } =
|
||||
codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
ret mk_uniq_str(cx, sp, filename);
|
||||
@ -42,21 +42,21 @@ fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
|
||||
fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), "stringify");
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"stringify");
|
||||
ret mk_uniq_str(cx, sp, pprust::expr_to_str(args[0]));
|
||||
}
|
||||
|
||||
fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body)
|
||||
-> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "file");
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"file");
|
||||
ret mk_uniq_str(cx, sp,
|
||||
str::connect(cx.mod_path().map(|x|*x), "::"));
|
||||
str::connect(cx.mod_path().map(|x|*x), ~"::"));
|
||||
}
|
||||
|
||||
fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), "include");
|
||||
let file = expr_to_str(cx, args[0], "#include_str requires a string");
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"include");
|
||||
let file = expr_to_str(cx, args[0], ~"#include_str requires a string");
|
||||
let p = parse::new_parser_from_file(cx.parse_sess(), cx.cfg(),
|
||||
res_rel_file(cx, sp, file),
|
||||
parse::parser::SOURCE_FILE);
|
||||
@ -65,9 +65,9 @@ fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
|
||||
fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),"include_str");
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"include_str");
|
||||
|
||||
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));
|
||||
alt res {
|
||||
@ -82,9 +82,9 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
|
||||
fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),"include_bin");
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"include_bin");
|
||||
|
||||
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)) {
|
||||
result::ok(src) {
|
||||
|
@ -83,7 +83,7 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@arb_depth])
|
||||
}
|
||||
{node: mtc_bb(bind_name, _, idx), span: sp} {
|
||||
if ret_val.contains_key(bind_name) {
|
||||
p_s.span_diagnostic.span_fatal(sp, "Duplicated bind name: "
|
||||
p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "
|
||||
+ *bind_name)
|
||||
}
|
||||
ret_val.insert(bind_name, res[idx]);
|
||||
@ -97,7 +97,7 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@arb_depth])
|
||||
|
||||
enum parse_result {
|
||||
success(hashmap<ident, @arb_depth>),
|
||||
failure(codemap::span, str)
|
||||
failure(codemap::span, ~str)
|
||||
}
|
||||
|
||||
fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
||||
@ -207,9 +207,9 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
||||
nameize(sess, ms,
|
||||
vec::map(eof_eis[0u].matches, |dv| dv.pop())));
|
||||
} else if eof_eis.len() > 1u {
|
||||
ret failure(sp, "Ambiguity: multiple successful parses");
|
||||
ret failure(sp, ~"Ambiguity: multiple successful parses");
|
||||
} else {
|
||||
ret failure(sp, "Unexpected end of macro invocation");
|
||||
ret failure(sp, ~"Unexpected end of macro invocation");
|
||||
}
|
||||
} else {
|
||||
if (bb_eis.len() > 0u && next_eis.len() > 0u)
|
||||
@ -217,13 +217,13 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
||||
let nts = str::connect(vec::map(bb_eis, |ei| {
|
||||
alt ei.elts[ei.idx].node
|
||||
{ mtc_bb(_,name,_) { *name } _ { fail; } }
|
||||
}), " or ");
|
||||
}), ~" or ");
|
||||
ret failure(sp, #fmt[
|
||||
"Local ambiguity: multiple parsing options: \
|
||||
built-in NTs %s or %u other options.",
|
||||
nts, next_eis.len()]);
|
||||
} else if (bb_eis.len() == 0u && next_eis.len() == 0u) {
|
||||
ret failure(sp, "No rules expected the token "
|
||||
ret failure(sp, ~"No rules expected the token "
|
||||
+ to_str(*rdr.interner(), tok));
|
||||
} else if (next_eis.len() > 0u) {
|
||||
/* Now process the next token */
|
||||
@ -259,32 +259,32 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_nt(p: parser, name: str) -> whole_nt {
|
||||
fn parse_nt(p: parser, name: ~str) -> whole_nt {
|
||||
alt name {
|
||||
"item" { alt p.parse_item(~[], ast::public) {
|
||||
~"item" { alt p.parse_item(~[], ast::public) {
|
||||
some(i) { token::w_item(i) }
|
||||
none { p.fatal("expected an item keyword") }
|
||||
none { p.fatal(~"expected an item keyword") }
|
||||
}}
|
||||
"block" { token::w_block(p.parse_block()) }
|
||||
"stmt" { token::w_stmt(p.parse_stmt(~[])) }
|
||||
"pat" { token::w_pat(p.parse_pat()) }
|
||||
"expr" { token::w_expr(p.parse_expr()) }
|
||||
"ty" { token::w_ty(p.parse_ty(false /* no need to disambiguate*/)) }
|
||||
~"block" { token::w_block(p.parse_block()) }
|
||||
~"stmt" { token::w_stmt(p.parse_stmt(~[])) }
|
||||
~"pat" { token::w_pat(p.parse_pat()) }
|
||||
~"expr" { token::w_expr(p.parse_expr()) }
|
||||
~"ty" { token::w_ty(p.parse_ty(false /* no need to disambiguate*/)) }
|
||||
// this could be handled like a token, since it is one
|
||||
"ident" { alt copy p.token {
|
||||
~"ident" { alt copy p.token {
|
||||
token::IDENT(sn,b) { p.bump(); token::w_ident(sn,b) }
|
||||
_ { p.fatal("expected ident, found "
|
||||
_ { p.fatal(~"expected ident, found "
|
||||
+ token::to_str(*p.reader.interner(), copy p.token)) }
|
||||
} }
|
||||
"path" { token::w_path(p.parse_path_with_tps(false)) }
|
||||
"tt" {
|
||||
~"path" { token::w_path(p.parse_path_with_tps(false)) }
|
||||
~"tt" {
|
||||
p.quote_depth += 1u; //but in theory, non-quoted tts might be useful
|
||||
let res = token::w_tt(@p.parse_token_tree());
|
||||
p.quote_depth -= 1u;
|
||||
res
|
||||
}
|
||||
"mtcs" { token::w_mtcs(p.parse_matchers()) }
|
||||
_ { p.fatal("Unsupported builtin nonterminal parser: " + name)}
|
||||
~"mtcs" { token::w_mtcs(p.parse_matchers()) }
|
||||
_ { p.fatal(~"Unsupported builtin nonterminal parser: " + name)}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
|
||||
let argument_gram = ~[
|
||||
ms(mtc_rep(~[
|
||||
ms(mtc_bb(@"lhs"/~,@"mtcs"/~, 0u)),
|
||||
ms(mtc_bb(@~"lhs",@~"mtcs", 0u)),
|
||||
ms(mtc_tok(FAT_ARROW)),
|
||||
ms(mtc_bb(@"rhs"/~,@"tt"/~, 1u)),
|
||||
ms(mtc_bb(@~"rhs",@~"tt", 1u)),
|
||||
], some(SEMI), false))];
|
||||
|
||||
let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
|
||||
@ -31,20 +31,20 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
failure(sp, msg) { cx.span_fatal(sp, msg); }
|
||||
};
|
||||
|
||||
let lhses = alt arguments.get(@"lhs"/~) {
|
||||
let lhses = alt arguments.get(@~"lhs") {
|
||||
@seq(s, sp) { s }
|
||||
_ { cx.span_bug(sp, "wrong-structured lhs") }
|
||||
_ { cx.span_bug(sp, ~"wrong-structured lhs") }
|
||||
};
|
||||
let rhses = alt arguments.get(@"rhs"/~) {
|
||||
let rhses = alt arguments.get(@~"rhs") {
|
||||
@seq(s, sp) { s }
|
||||
_ { cx.span_bug(sp, "wrong-structured rhs") }
|
||||
_ { cx.span_bug(sp, ~"wrong-structured rhs") }
|
||||
};
|
||||
|
||||
fn generic_extension(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree],
|
||||
lhses: ~[@arb_depth], rhses: ~[@arb_depth])
|
||||
-> mac_result {
|
||||
let mut best_fail_spot = {lo: 0u, hi: 0u, expn_info: none};
|
||||
let mut best_fail_msg = "internal error: ran no matchers";
|
||||
let mut best_fail_msg = ~"internal error: ran no matchers";
|
||||
|
||||
let s_d = cx.parse_sess().span_diagnostic;
|
||||
let itr = cx.parse_sess().interner;
|
||||
@ -57,7 +57,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
success(m) {
|
||||
let rhs = alt rhses[i] {
|
||||
@leaf(w_tt(@tt)) { tt }
|
||||
_ { cx.span_bug(sp, "bad thing in rhs") }
|
||||
_ { cx.span_bug(sp, ~"bad thing in rhs") }
|
||||
};
|
||||
let trncbr = new_tt_reader(s_d, itr, some(m), ~[rhs]);
|
||||
let p = parser(cx.parse_sess(), cx.cfg(),
|
||||
@ -71,7 +71,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
||||
}
|
||||
}
|
||||
}
|
||||
_ { cx.bug("non-matcher found in parsed lhses"); }
|
||||
_ { cx.bug(~"non-matcher found in parsed lhses"); }
|
||||
}
|
||||
}
|
||||
cx.span_fatal(best_fail_spot, best_fail_msg);
|
||||
|
@ -25,7 +25,7 @@ type tt_frame = @{
|
||||
|
||||
type tt_reader = @{
|
||||
sp_diag: span_handler,
|
||||
interner: @interner<@str/~>,
|
||||
interner: @interner<@~str>,
|
||||
mut cur: tt_frame,
|
||||
/* for MBE-style macro transcription */
|
||||
interpolations: std::map::hashmap<ident, @arb_depth>,
|
||||
@ -39,7 +39,7 @@ type tt_reader = @{
|
||||
/** This can do Macro-By-Example transcription. On the other hand, if
|
||||
* `src` contains no `tt_dotdotdot`s and `tt_interpolate`s, `interp` can (and
|
||||
* should) be none. */
|
||||
fn new_tt_reader(sp_diag: span_handler, itr: @interner<@str/~>,
|
||||
fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>,
|
||||
interp: option<std::map::hashmap<ident,@arb_depth>>,
|
||||
src: ~[ast::token_tree])
|
||||
-> tt_reader {
|
||||
@ -93,7 +93,7 @@ fn lookup_cur_ad(r: tt_reader, name: ident) -> @arb_depth {
|
||||
lookup_cur_ad_by_ad(r, r.interpolations.get(name))
|
||||
}
|
||||
enum lis {
|
||||
lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(str)
|
||||
lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str)
|
||||
}
|
||||
|
||||
fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis {
|
||||
@ -183,7 +183,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
|
||||
lis_unconstrained {
|
||||
r.sp_diag.span_fatal(
|
||||
sp, /* blame macro writer */
|
||||
"attempted to repeat an expression containing no syntax \
|
||||
~"attempted to repeat an expression containing no syntax \
|
||||
variables matched as repeating at this depth");
|
||||
}
|
||||
lis_contradiction(msg) { /* FIXME #2887 blame macro invoker
|
||||
@ -200,7 +200,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
|
||||
if !zerok {
|
||||
r.sp_diag.span_fatal(sp, /* FIXME #2887 blame invoker
|
||||
*/
|
||||
"this must repeat at least \
|
||||
~"this must repeat at least \
|
||||
once");
|
||||
}
|
||||
/* we need to pop before we proceed, so recur */
|
||||
|
@ -25,7 +25,7 @@ type parse_sess = @{
|
||||
cm: codemap::codemap,
|
||||
mut next_id: node_id,
|
||||
span_diagnostic: span_handler,
|
||||
interner: @interner::interner<@str/~>,
|
||||
interner: @interner::interner<@~str>,
|
||||
// these two must be kept up to date
|
||||
mut chpos: uint,
|
||||
mut byte_pos: uint
|
||||
@ -36,7 +36,7 @@ fn new_parse_sess(demitter: option<emitter>) -> parse_sess {
|
||||
ret @{cm: cm,
|
||||
mut next_id: 1,
|
||||
span_diagnostic: mk_span_handler(mk_handler(demitter), cm),
|
||||
interner: @interner::mk::<@str/~>(|x| str::hash(*x),
|
||||
interner: @interner::mk::<@~str>(|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y)),
|
||||
mut chpos: 0u, mut byte_pos: 0u};
|
||||
}
|
||||
@ -46,24 +46,24 @@ fn new_parse_sess_special_handler(sh: span_handler, cm: codemap::codemap)
|
||||
ret @{cm: cm,
|
||||
mut next_id: 1,
|
||||
span_diagnostic: sh,
|
||||
interner: @interner::mk::<@str/~>(|x| str::hash(*x),
|
||||
interner: @interner::mk::<@~str>(|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y)),
|
||||
mut chpos: 0u, mut byte_pos: 0u};
|
||||
}
|
||||
|
||||
fn parse_crate_from_file(input: str, cfg: ast::crate_cfg, sess: parse_sess) ->
|
||||
@ast::crate {
|
||||
if str::ends_with(input, ".rc") {
|
||||
fn parse_crate_from_file(input: ~str, cfg: ast::crate_cfg,
|
||||
sess: parse_sess) -> @ast::crate {
|
||||
if str::ends_with(input, ~".rc") {
|
||||
parse_crate_from_crate_file(input, cfg, sess)
|
||||
} else if str::ends_with(input, ".rs") {
|
||||
} else if str::ends_with(input, ~".rs") {
|
||||
parse_crate_from_source_file(input, cfg, sess)
|
||||
} else {
|
||||
sess.span_diagnostic.handler().fatal("unknown input file type: " +
|
||||
sess.span_diagnostic.handler().fatal(~"unknown input file type: " +
|
||||
input)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_crate_from_crate_file(input: str, cfg: ast::crate_cfg,
|
||||
fn parse_crate_from_crate_file(input: ~str, cfg: ast::crate_cfg,
|
||||
sess: parse_sess) -> @ast::crate {
|
||||
let (p, rdr) = new_parser_etc_from_file(sess, cfg, input,
|
||||
parser::CRATE_FILE);
|
||||
@ -87,7 +87,7 @@ fn parse_crate_from_crate_file(input: str, cfg: ast::crate_cfg,
|
||||
config: /* FIXME (#2543) */ copy p.cfg});
|
||||
}
|
||||
|
||||
fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,
|
||||
fn parse_crate_from_source_file(input: ~str, cfg: ast::crate_cfg,
|
||||
sess: parse_sess) -> @ast::crate {
|
||||
let (p, rdr) = new_parser_etc_from_file(sess, cfg, input,
|
||||
parser::SOURCE_FILE);
|
||||
@ -97,7 +97,7 @@ fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,
|
||||
ret r;
|
||||
}
|
||||
|
||||
fn parse_crate_from_source_str(name: str, source: @str/~, cfg: ast::crate_cfg,
|
||||
fn parse_crate_from_source_str(name: ~str, source: @~str, cfg: ast::crate_cfg,
|
||||
sess: parse_sess) -> @ast::crate {
|
||||
let (p, rdr) = new_parser_etc_from_source_str(sess, cfg, name,
|
||||
codemap::fss_none, source);
|
||||
@ -107,7 +107,7 @@ fn parse_crate_from_source_str(name: str, source: @str/~, cfg: ast::crate_cfg,
|
||||
ret r;
|
||||
}
|
||||
|
||||
fn parse_expr_from_source_str(name: str, source: @str/~, cfg: ast::crate_cfg,
|
||||
fn parse_expr_from_source_str(name: ~str, source: @~str, cfg: ast::crate_cfg,
|
||||
sess: parse_sess) -> @ast::expr {
|
||||
let (p, rdr) = new_parser_etc_from_source_str(sess, cfg, name,
|
||||
codemap::fss_none, source);
|
||||
@ -117,7 +117,7 @@ fn parse_expr_from_source_str(name: str, source: @str/~, cfg: ast::crate_cfg,
|
||||
ret r;
|
||||
}
|
||||
|
||||
fn parse_item_from_source_str(name: str, source: @str/~, cfg: ast::crate_cfg,
|
||||
fn parse_item_from_source_str(name: ~str, source: @~str, cfg: ast::crate_cfg,
|
||||
+attrs: ~[ast::attribute],
|
||||
vis: ast::visibility,
|
||||
sess: parse_sess) -> option<@ast::item> {
|
||||
@ -130,8 +130,8 @@ fn parse_item_from_source_str(name: str, source: @str/~, cfg: ast::crate_cfg,
|
||||
}
|
||||
|
||||
fn parse_from_source_str<T>(f: fn (p: parser) -> T,
|
||||
name: str, ss: codemap::file_substr,
|
||||
source: @str/~, cfg: ast::crate_cfg,
|
||||
name: ~str, ss: codemap::file_substr,
|
||||
source: @~str, cfg: ast::crate_cfg,
|
||||
sess: parse_sess)
|
||||
-> T
|
||||
{
|
||||
@ -139,7 +139,7 @@ fn parse_from_source_str<T>(f: fn (p: parser) -> T,
|
||||
source);
|
||||
let r = f(p);
|
||||
if !p.reader.is_eof() {
|
||||
p.reader.fatal("expected end-of-string");
|
||||
p.reader.fatal(~"expected end-of-string");
|
||||
}
|
||||
sess.chpos = rdr.chpos;
|
||||
sess.byte_pos = sess.byte_pos + rdr.pos;
|
||||
@ -155,8 +155,8 @@ fn next_node_id(sess: parse_sess) -> node_id {
|
||||
}
|
||||
|
||||
fn new_parser_etc_from_source_str(sess: parse_sess, cfg: ast::crate_cfg,
|
||||
+name: str, +ss: codemap::file_substr,
|
||||
source: @str/~) -> (parser, string_reader) {
|
||||
+name: ~str, +ss: codemap::file_substr,
|
||||
source: @~str) -> (parser, string_reader) {
|
||||
let ftype = parser::SOURCE_FILE;
|
||||
let filemap = codemap::new_filemap_w_substr
|
||||
(name, ss, source, sess.chpos, sess.byte_pos);
|
||||
@ -167,15 +167,15 @@ fn new_parser_etc_from_source_str(sess: parse_sess, cfg: ast::crate_cfg,
|
||||
}
|
||||
|
||||
fn new_parser_from_source_str(sess: parse_sess, cfg: ast::crate_cfg,
|
||||
+name: str, +ss: codemap::file_substr,
|
||||
source: @str/~) -> parser {
|
||||
+name: ~str, +ss: codemap::file_substr,
|
||||
source: @~str) -> parser {
|
||||
let (p, _) = new_parser_etc_from_source_str(sess, cfg, name, ss, source);
|
||||
ret p;
|
||||
}
|
||||
|
||||
|
||||
fn new_parser_etc_from_file(sess: parse_sess, cfg: ast::crate_cfg, +path: str,
|
||||
ftype: parser::file_type) ->
|
||||
fn new_parser_etc_from_file(sess: parse_sess, cfg: ast::crate_cfg,
|
||||
+path: ~str, ftype: parser::file_type) ->
|
||||
(parser, string_reader) {
|
||||
let res = io::read_whole_file_str(path);
|
||||
alt res {
|
||||
@ -190,7 +190,7 @@ fn new_parser_etc_from_file(sess: parse_sess, cfg: ast::crate_cfg, +path: str,
|
||||
ret (parser(sess, cfg, srdr as reader, ftype), srdr);
|
||||
}
|
||||
|
||||
fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, +path: str,
|
||||
fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, +path: ~str,
|
||||
ftype: parser::file_type) -> parser {
|
||||
let (p, _) = new_parser_etc_from_file(sess, cfg, path, ftype);
|
||||
ret p;
|
||||
|
@ -56,7 +56,7 @@ impl parser_attr for parser {
|
||||
let attr = ::attr::mk_sugared_doc_attr(
|
||||
*self.get_str(s), self.span.lo, self.span.hi);
|
||||
if attr.node.style != ast::attr_outer {
|
||||
self.fatal("expected outer comment");
|
||||
self.fatal(~"expected outer comment");
|
||||
}
|
||||
attrs += ~[attr];
|
||||
self.bump();
|
||||
|
@ -18,28 +18,28 @@ enum cmnt_style {
|
||||
blank_line, // Just a manual blank line "\n\n", for layout
|
||||
}
|
||||
|
||||
type cmnt = {style: cmnt_style, lines: ~[str], pos: uint};
|
||||
type cmnt = {style: cmnt_style, lines: ~[~str], pos: uint};
|
||||
|
||||
fn is_doc_comment(s: str) -> bool {
|
||||
s.starts_with("///") ||
|
||||
s.starts_with("//!") ||
|
||||
s.starts_with("/**") ||
|
||||
s.starts_with("/*!")
|
||||
fn is_doc_comment(s: ~str) -> bool {
|
||||
s.starts_with(~"///") ||
|
||||
s.starts_with(~"//!") ||
|
||||
s.starts_with(~"/**") ||
|
||||
s.starts_with(~"/*!")
|
||||
}
|
||||
|
||||
fn doc_comment_style(comment: str) -> ast::attr_style {
|
||||
fn doc_comment_style(comment: ~str) -> ast::attr_style {
|
||||
assert is_doc_comment(comment);
|
||||
if comment.starts_with("//!") || comment.starts_with("/*!") {
|
||||
if comment.starts_with(~"//!") || comment.starts_with(~"/*!") {
|
||||
ast::attr_inner
|
||||
} else {
|
||||
ast::attr_outer
|
||||
}
|
||||
}
|
||||
|
||||
fn strip_doc_comment_decoration(comment: str) -> str {
|
||||
fn strip_doc_comment_decoration(comment: ~str) -> ~str {
|
||||
|
||||
/// remove whitespace-only lines from the start/end of lines
|
||||
fn vertical_trim(lines: ~[str]) -> ~[str] {
|
||||
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
|
||||
let mut i = 0u, j = lines.len();
|
||||
while i < j && lines[i].trim().is_empty() {
|
||||
i += 1u;
|
||||
@ -51,7 +51,7 @@ fn strip_doc_comment_decoration(comment: str) -> str {
|
||||
}
|
||||
|
||||
// drop leftmost columns that contain only values in chars
|
||||
fn block_trim(lines: ~[str], chars: str, max: option<uint>) -> ~[str] {
|
||||
fn block_trim(lines: ~[~str], chars: ~str, max: option<uint>) -> ~[~str] {
|
||||
|
||||
let mut i = max.get_default(uint::max_value);
|
||||
for lines.each |line| {
|
||||
@ -72,31 +72,31 @@ fn strip_doc_comment_decoration(comment: str) -> str {
|
||||
ret do lines.map |line| {
|
||||
let chars = str::chars(line);
|
||||
if i > chars.len() {
|
||||
""
|
||||
~""
|
||||
} else {
|
||||
str::from_chars(chars.slice(i, chars.len()))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if comment.starts_with("//") {
|
||||
if comment.starts_with(~"//") {
|
||||
ret comment.slice(3u, comment.len()).trim();
|
||||
}
|
||||
|
||||
if comment.starts_with("/*") {
|
||||
if comment.starts_with(~"/*") {
|
||||
let lines = str::lines_any(comment.slice(3u, comment.len() - 2u));
|
||||
let lines = vertical_trim(lines);
|
||||
let lines = block_trim(lines, "\t ", none);
|
||||
let lines = block_trim(lines, "*", some(1u));
|
||||
let lines = block_trim(lines, "\t ", none);
|
||||
ret str::connect(lines, "\n");
|
||||
let lines = block_trim(lines, ~"\t ", none);
|
||||
let lines = block_trim(lines, ~"*", some(1u));
|
||||
let lines = block_trim(lines, ~"\t ", none);
|
||||
ret str::connect(lines, ~"\n");
|
||||
}
|
||||
|
||||
fail "not a doc-comment: " + comment;
|
||||
fail ~"not a doc-comment: " + comment;
|
||||
}
|
||||
|
||||
fn read_to_eol(rdr: string_reader) -> str {
|
||||
let mut val = "";
|
||||
fn read_to_eol(rdr: string_reader) -> ~str {
|
||||
let mut val = ~"";
|
||||
while rdr.curr != '\n' && !is_eof(rdr) {
|
||||
str::push_char(val, rdr.curr);
|
||||
bump(rdr);
|
||||
@ -105,7 +105,7 @@ fn read_to_eol(rdr: string_reader) -> str {
|
||||
ret val;
|
||||
}
|
||||
|
||||
fn read_one_line_comment(rdr: string_reader) -> str {
|
||||
fn read_one_line_comment(rdr: string_reader) -> ~str {
|
||||
let val = read_to_eol(rdr);
|
||||
assert ((val[0] == '/' as u8 && val[1] == '/' as u8) ||
|
||||
(val[0] == '#' as u8 && val[1] == '!' as u8));
|
||||
@ -120,7 +120,7 @@ fn consume_non_eol_whitespace(rdr: string_reader) {
|
||||
|
||||
fn push_blank_line_comment(rdr: string_reader, &comments: ~[cmnt]) {
|
||||
#debug(">>> blank-line comment");
|
||||
let v: ~[str] = ~[];
|
||||
let v: ~[~str] = ~[];
|
||||
vec::push(comments, {style: blank_line, lines: v, pos: rdr.chpos});
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ fn read_line_comments(rdr: string_reader, code_to_the_left: bool,
|
||||
&comments: ~[cmnt]) {
|
||||
#debug(">>> line comments");
|
||||
let p = rdr.chpos;
|
||||
let mut lines: ~[str] = ~[];
|
||||
let mut lines: ~[~str] = ~[];
|
||||
while rdr.curr == '/' && nextch(rdr) == '/' {
|
||||
let line = read_one_line_comment(rdr);
|
||||
log(debug, line);
|
||||
@ -171,22 +171,22 @@ fn read_line_comments(rdr: string_reader, code_to_the_left: bool,
|
||||
}
|
||||
}
|
||||
|
||||
fn all_whitespace(s: str, begin: uint, end: uint) -> bool {
|
||||
fn all_whitespace(s: ~str, begin: uint, end: uint) -> bool {
|
||||
let mut i: uint = begin;
|
||||
while i != end { if !is_whitespace(s[i] as char) { ret false; } i += 1u; }
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn trim_whitespace_prefix_and_push_line(&lines: ~[str],
|
||||
s: str, col: uint) unsafe {
|
||||
fn trim_whitespace_prefix_and_push_line(&lines: ~[~str],
|
||||
s: ~str, col: uint) unsafe {
|
||||
let mut s1;
|
||||
let len = str::len(s);
|
||||
if all_whitespace(s, 0u, uint::min(len, col)) {
|
||||
if col < len {
|
||||
s1 = str::slice(s, col, len);
|
||||
} else { s1 = ""; }
|
||||
} else { s1 = ~""; }
|
||||
} else { s1 = s; }
|
||||
log(debug, "pushing line: " + s1);
|
||||
log(debug, ~"pushing line: " + s1);
|
||||
vec::push(lines, s1);
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ fn read_block_comment(rdr: string_reader, code_to_the_left: bool,
|
||||
&comments: ~[cmnt]) {
|
||||
#debug(">>> block comment");
|
||||
let p = rdr.chpos;
|
||||
let mut lines: ~[str] = ~[];
|
||||
let mut lines: ~[~str] = ~[];
|
||||
let mut col: uint = rdr.col;
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
@ -211,27 +211,27 @@ fn read_block_comment(rdr: string_reader, code_to_the_left: bool,
|
||||
ret;
|
||||
}
|
||||
|
||||
let mut curr_line = "/*";
|
||||
let mut curr_line = ~"/*";
|
||||
let mut level: int = 1;
|
||||
while level > 0 {
|
||||
#debug("=== block comment level %d", level);
|
||||
if is_eof(rdr) {(rdr as reader).fatal("unterminated block comment");}
|
||||
if is_eof(rdr) {(rdr as reader).fatal(~"unterminated block comment");}
|
||||
if rdr.curr == '\n' {
|
||||
trim_whitespace_prefix_and_push_line(lines, curr_line, col);
|
||||
curr_line = "";
|
||||
curr_line = ~"";
|
||||
bump(rdr);
|
||||
} else {
|
||||
str::push_char(curr_line, rdr.curr);
|
||||
if rdr.curr == '/' && nextch(rdr) == '*' {
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
curr_line += "*";
|
||||
curr_line += ~"*";
|
||||
level += 1;
|
||||
} else {
|
||||
if rdr.curr == '*' && nextch(rdr) == '/' {
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
curr_line += "/";
|
||||
curr_line += ~"/";
|
||||
level -= 1;
|
||||
} else { bump(rdr); }
|
||||
}
|
||||
@ -268,14 +268,14 @@ fn consume_comment(rdr: string_reader, code_to_the_left: bool,
|
||||
#debug("<<< consume comment");
|
||||
}
|
||||
|
||||
type lit = {lit: str, pos: uint};
|
||||
type lit = {lit: ~str, pos: uint};
|
||||
|
||||
fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
|
||||
path: str,
|
||||
path: ~str,
|
||||
srdr: io::reader) ->
|
||||
{cmnts: ~[cmnt], lits: ~[lit]} {
|
||||
let src = @str::from_bytes(srdr.read_whole_stream());
|
||||
let itr = @interner::mk::<@str/~>(
|
||||
let itr = @interner::mk::<@~str>(
|
||||
|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y)
|
||||
);
|
||||
@ -308,9 +308,9 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
|
||||
if token::is_lit(tok) {
|
||||
let s = get_str_from(rdr, bstart);
|
||||
vec::push(literals, {lit: s, pos: sp.lo});
|
||||
log(debug, "tok lit: " + s);
|
||||
log(debug, ~"tok lit: " + s);
|
||||
} else {
|
||||
log(debug, "tok: " + token::to_str(*rdr.interner, tok));
|
||||
log(debug, ~"tok: " + token::to_str(*rdr.interner, tok));
|
||||
}
|
||||
first_read = false;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn seq_sep_none() -> seq_sep {
|
||||
ret {sep: option::none, trailing_sep_allowed: false};
|
||||
}
|
||||
|
||||
fn token_to_str(reader: reader, ++token: token::token) -> str {
|
||||
fn token_to_str(reader: reader, ++token: token::token) -> ~str {
|
||||
token::to_str(*reader.interner(), token)
|
||||
}
|
||||
|
||||
@ -28,23 +28,23 @@ impl parser_common for parser {
|
||||
fn unexpected_last(t: token::token) -> ! {
|
||||
self.span_fatal(
|
||||
copy self.last_span,
|
||||
"unexpected token: `" + token_to_str(self.reader, t) + "`");
|
||||
~"unexpected token: `" + token_to_str(self.reader, t) + ~"`");
|
||||
}
|
||||
|
||||
fn unexpected() -> ! {
|
||||
self.fatal("unexpected token: `"
|
||||
+ token_to_str(self.reader, self.token) + "`");
|
||||
self.fatal(~"unexpected token: `"
|
||||
+ token_to_str(self.reader, self.token) + ~"`");
|
||||
}
|
||||
|
||||
fn expect(t: token::token) {
|
||||
if self.token == t {
|
||||
self.bump();
|
||||
} else {
|
||||
let mut s: str = "expected `";
|
||||
let mut s: ~str = ~"expected `";
|
||||
s += token_to_str(self.reader, t);
|
||||
s += "` but found `";
|
||||
s += ~"` but found `";
|
||||
s += token_to_str(self.reader, self.token);
|
||||
self.fatal(s + "`");
|
||||
self.fatal(s + ~"`");
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,10 +52,10 @@ impl parser_common for parser {
|
||||
alt copy self.token {
|
||||
token::IDENT(i, _) { self.bump(); ret self.get_str(i); }
|
||||
token::ACTUALLY(token::w_ident(*)) { self.bug(
|
||||
"ident interpolation not converted to real token"); }
|
||||
_ { self.fatal("expected ident, found `"
|
||||
~"ident interpolation not converted to real token"); }
|
||||
_ { self.fatal(~"expected ident, found `"
|
||||
+ token_to_str(self.reader, self.token)
|
||||
+ "`"); }
|
||||
+ ~"`"); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,13 +76,13 @@ impl parser_common for parser {
|
||||
}
|
||||
|
||||
// A sanity check that the word we are asking for is a known keyword
|
||||
fn require_keyword(word: str) {
|
||||
fn require_keyword(word: ~str) {
|
||||
if !self.keywords.contains_key(word) {
|
||||
self.bug(#fmt("unknown keyword: %s", word));
|
||||
}
|
||||
}
|
||||
|
||||
fn token_is_keyword(word: str, ++tok: token::token) -> bool {
|
||||
fn token_is_keyword(word: ~str, ++tok: token::token) -> bool {
|
||||
self.require_keyword(word);
|
||||
alt tok {
|
||||
token::IDENT(sid, false) { str::eq(word, *self.get_str(sid)) }
|
||||
@ -90,7 +90,7 @@ impl parser_common for parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_keyword(word: str) -> bool {
|
||||
fn is_keyword(word: ~str) -> bool {
|
||||
self.token_is_keyword(word, self.token)
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ impl parser_common for parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn eat_keyword(word: str) -> bool {
|
||||
fn eat_keyword(word: ~str) -> bool {
|
||||
self.require_keyword(word);
|
||||
|
||||
// FIXME (#13042): this gratuitous use of @ is to
|
||||
@ -119,16 +119,16 @@ impl parser_common for parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn expect_keyword(word: str) {
|
||||
fn expect_keyword(word: ~str) {
|
||||
self.require_keyword(word);
|
||||
if !self.eat_keyword(word) {
|
||||
self.fatal("expected `" + word + "`, found `" +
|
||||
self.fatal(~"expected `" + word + ~"`, found `" +
|
||||
token_to_str(self.reader, self.token) +
|
||||
"`");
|
||||
~"`");
|
||||
}
|
||||
}
|
||||
|
||||
fn is_restricted_keyword(word: str) -> bool {
|
||||
fn is_restricted_keyword(word: ~str) -> bool {
|
||||
self.restricted_keywords.contains_key(word)
|
||||
}
|
||||
|
||||
@ -142,9 +142,9 @@ impl parser_common for parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_restricted_keywords_(w: str) {
|
||||
fn check_restricted_keywords_(w: ~str) {
|
||||
if self.is_restricted_keyword(w) {
|
||||
self.fatal("found `" + w + "` in restricted position");
|
||||
self.fatal(~"found `" + w + ~"` in restricted position");
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,11 +154,11 @@ impl parser_common for parser {
|
||||
} else if self.token == token::BINOP(token::SHR) {
|
||||
self.swap(token::GT, self.span.lo + 1u, self.span.hi);
|
||||
} else {
|
||||
let mut s: str = "expected `";
|
||||
let mut s: ~str = ~"expected `";
|
||||
s += token_to_str(self.reader, token::GT);
|
||||
s += "`, found `";
|
||||
s += ~"`, found `";
|
||||
s += token_to_str(self.reader, self.token);
|
||||
s += "`";
|
||||
s += ~"`";
|
||||
self.fatal(s);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ type ctx =
|
||||
|
||||
fn eval_crate_directives(cx: ctx,
|
||||
cdirs: ~[@ast::crate_directive],
|
||||
prefix: str,
|
||||
prefix: ~str,
|
||||
&view_items: ~[@ast::view_item],
|
||||
&items: ~[@ast::item]) {
|
||||
for cdirs.each |sub_cdir| {
|
||||
@ -18,11 +18,11 @@ fn eval_crate_directives(cx: ctx,
|
||||
}
|
||||
|
||||
fn eval_crate_directives_to_mod(cx: ctx, cdirs: ~[@ast::crate_directive],
|
||||
prefix: str, suffix: option<str>)
|
||||
prefix: ~str, suffix: option<~str>)
|
||||
-> (ast::_mod, ~[ast::attribute]) {
|
||||
#debug("eval crate prefix: %s", prefix);
|
||||
#debug("eval crate suffix: %s",
|
||||
option::get_default(suffix, "none"));
|
||||
option::get_default(suffix, ~"none"));
|
||||
let (cview_items, citems, cattrs)
|
||||
= parse_companion_mod(cx, prefix, suffix);
|
||||
let mut view_items: ~[@ast::view_item] = ~[];
|
||||
@ -43,17 +43,17 @@ companion mod is a .rs file with the same name as the directory.
|
||||
We build the path to the companion mod by combining the prefix and the
|
||||
optional suffix then adding the .rs extension.
|
||||
*/
|
||||
fn parse_companion_mod(cx: ctx, prefix: str, suffix: option<str>)
|
||||
fn parse_companion_mod(cx: ctx, prefix: ~str, suffix: option<~str>)
|
||||
-> (~[@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 {
|
||||
ret alt suffix {
|
||||
option::some(s) { path::connect(prefix, s) }
|
||||
option::none { prefix }
|
||||
} + ".rs";
|
||||
} + ~".rs";
|
||||
}
|
||||
|
||||
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
|
||||
// up to writing it just now
|
||||
alt io::file_reader(path) {
|
||||
@ -78,8 +78,8 @@ fn parse_companion_mod(cx: ctx, prefix: str, suffix: option<str>)
|
||||
}
|
||||
}
|
||||
|
||||
fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @str/~ {
|
||||
alt ::attr::first_attr_value_str_by_name(attrs, "path") {
|
||||
fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str {
|
||||
alt ::attr::first_attr_value_str_by_name(attrs, ~"path") {
|
||||
some(d) {
|
||||
ret d;
|
||||
}
|
||||
@ -87,12 +87,12 @@ 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],
|
||||
&items: ~[@ast::item]) {
|
||||
alt cdir.node {
|
||||
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 =
|
||||
if path::path_is_absolute(*file_path) {
|
||||
*file_path
|
||||
|
@ -12,22 +12,22 @@ export string_reader_as_reader, tt_reader_as_reader;
|
||||
iface reader {
|
||||
fn is_eof() -> bool;
|
||||
fn next_token() -> {tok: token::token, sp: span};
|
||||
fn fatal(str) -> !;
|
||||
fn fatal(~str) -> !;
|
||||
fn span_diag() -> span_handler;
|
||||
fn interner() -> @interner<@str/~>;
|
||||
fn interner() -> @interner<@~str>;
|
||||
fn peek() -> {tok: token::token, sp: span};
|
||||
fn dup() -> reader;
|
||||
}
|
||||
|
||||
type string_reader = @{
|
||||
span_diagnostic: span_handler,
|
||||
src: @str/~,
|
||||
src: @~str,
|
||||
mut col: uint,
|
||||
mut pos: uint,
|
||||
mut curr: char,
|
||||
mut chpos: uint,
|
||||
filemap: codemap::filemap,
|
||||
interner: @interner<@str/~>,
|
||||
interner: @interner<@~str>,
|
||||
/* cached: */
|
||||
mut peek_tok: token::token,
|
||||
mut peek_span: span
|
||||
@ -35,7 +35,7 @@ type string_reader = @{
|
||||
|
||||
fn new_string_reader(span_diagnostic: span_handler,
|
||||
filemap: codemap::filemap,
|
||||
itr: @interner<@str/~>) -> string_reader {
|
||||
itr: @interner<@~str>) -> string_reader {
|
||||
let r = new_low_level_string_reader(span_diagnostic, filemap, itr);
|
||||
string_advance_token(r); /* fill in peek_* */
|
||||
ret r;
|
||||
@ -44,7 +44,7 @@ fn new_string_reader(span_diagnostic: span_handler,
|
||||
/* For comments.rs, which hackily pokes into 'pos' and 'curr' */
|
||||
fn new_low_level_string_reader(span_diagnostic: span_handler,
|
||||
filemap: codemap::filemap,
|
||||
itr: @interner<@str/~>)
|
||||
itr: @interner<@~str>)
|
||||
-> string_reader {
|
||||
let r = @{span_diagnostic: span_diagnostic, src: filemap.src,
|
||||
mut col: 0u, mut pos: 0u, mut curr: -1 as char,
|
||||
@ -75,11 +75,11 @@ impl string_reader_as_reader of reader for string_reader {
|
||||
string_advance_token(self);
|
||||
ret ret_val;
|
||||
}
|
||||
fn fatal(m: str) -> ! {
|
||||
fn fatal(m: ~str) -> ! {
|
||||
self.span_diagnostic.span_fatal(copy self.peek_span, m)
|
||||
}
|
||||
fn span_diag() -> span_handler { self.span_diagnostic }
|
||||
fn interner() -> @interner<@str/~> { self.interner }
|
||||
fn interner() -> @interner<@~str> { self.interner }
|
||||
fn peek() -> {tok: token::token, sp: span} {
|
||||
{tok: self.peek_tok, sp: self.peek_span}
|
||||
}
|
||||
@ -97,11 +97,11 @@ impl tt_reader_as_reader of reader for tt_reader {
|
||||
}
|
||||
tt_next_token(self)
|
||||
}
|
||||
fn fatal(m: str) -> ! {
|
||||
fn fatal(m: ~str) -> ! {
|
||||
self.sp_diag.span_fatal(copy self.cur_span, m);
|
||||
}
|
||||
fn span_diag() -> span_handler { self.sp_diag }
|
||||
fn interner() -> @interner<@str/~> { self.interner }
|
||||
fn interner() -> @interner<@~str> { self.interner }
|
||||
fn peek() -> {tok: token::token, sp: span} {
|
||||
{ tok: self.cur_tok, sp: self.cur_span }
|
||||
}
|
||||
@ -125,7 +125,7 @@ fn string_advance_token(&&r: string_reader) {
|
||||
|
||||
}
|
||||
|
||||
fn get_str_from(rdr: string_reader, start: uint) -> str unsafe {
|
||||
fn get_str_from(rdr: string_reader, start: uint) -> ~str unsafe {
|
||||
// I'm pretty skeptical about this subtraction. What if there's a
|
||||
// multi-byte character before the mark?
|
||||
ret str::slice(*rdr.src, start - 1u, rdr.pos - 1u);
|
||||
@ -211,7 +211,7 @@ fn consume_any_line_comment(rdr: string_reader)
|
||||
// line comments starting with "///" or "//!" are doc-comments
|
||||
if rdr.curr == '/' || rdr.curr == '!' {
|
||||
let start_chpos = rdr.chpos - 2u;
|
||||
let mut acc = "//";
|
||||
let mut acc = ~"//";
|
||||
while rdr.curr != '\n' && !is_eof(rdr) {
|
||||
str::push_char(acc, rdr.curr);
|
||||
bump(rdr);
|
||||
@ -250,15 +250,15 @@ fn consume_block_comment(rdr: string_reader)
|
||||
// block comments starting with "/**" or "/*!" are doc-comments
|
||||
if rdr.curr == '*' || rdr.curr == '!' {
|
||||
let start_chpos = rdr.chpos - 2u;
|
||||
let mut acc = "/*";
|
||||
let mut acc = ~"/*";
|
||||
while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
|
||||
str::push_char(acc, rdr.curr);
|
||||
bump(rdr);
|
||||
}
|
||||
if is_eof(rdr) {
|
||||
rdr.fatal("unterminated block doc-comment");
|
||||
rdr.fatal(~"unterminated block doc-comment");
|
||||
} else {
|
||||
acc += "*/";
|
||||
acc += ~"*/";
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
ret some({
|
||||
@ -270,7 +270,7 @@ fn consume_block_comment(rdr: string_reader)
|
||||
|
||||
let mut level: int = 1;
|
||||
while level > 0 {
|
||||
if is_eof(rdr) { rdr.fatal("unterminated block comment"); }
|
||||
if is_eof(rdr) { rdr.fatal(~"unterminated block comment"); }
|
||||
if rdr.curr == '/' && nextch(rdr) == '*' {
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
@ -288,9 +288,9 @@ fn consume_block_comment(rdr: string_reader)
|
||||
ret consume_whitespace_and_comments(rdr);
|
||||
}
|
||||
|
||||
fn scan_exponent(rdr: string_reader) -> option<str> {
|
||||
fn scan_exponent(rdr: string_reader) -> option<~str> {
|
||||
let mut c = rdr.curr;
|
||||
let mut rslt = "";
|
||||
let mut rslt = ~"";
|
||||
if c == 'e' || c == 'E' {
|
||||
str::push_char(rslt, c);
|
||||
bump(rdr);
|
||||
@ -302,12 +302,12 @@ fn scan_exponent(rdr: string_reader) -> option<str> {
|
||||
let exponent = scan_digits(rdr, 10u);
|
||||
if str::len(exponent) > 0u {
|
||||
ret some(rslt + exponent);
|
||||
} else { rdr.fatal("scan_exponent: bad fp literal"); }
|
||||
} else { ret none::<str>; }
|
||||
} else { rdr.fatal(~"scan_exponent: bad fp literal"); }
|
||||
} else { ret none::<~str>; }
|
||||
}
|
||||
|
||||
fn scan_digits(rdr: string_reader, radix: uint) -> str {
|
||||
let mut rslt = "";
|
||||
fn scan_digits(rdr: string_reader, radix: uint) -> ~str {
|
||||
let mut rslt = ~"";
|
||||
loop {
|
||||
let c = rdr.curr;
|
||||
if c == '_' { bump(rdr); again; }
|
||||
@ -366,7 +366,7 @@ fn scan_number(c: char, rdr: string_reader) -> token::token {
|
||||
else { either::right(ast::ty_u64) };
|
||||
}
|
||||
if str::len(num_str) == 0u {
|
||||
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));
|
||||
alt tp {
|
||||
@ -379,7 +379,7 @@ fn scan_number(c: char, rdr: string_reader) -> token::token {
|
||||
is_float = true;
|
||||
bump(rdr);
|
||||
let dec_part = scan_digits(rdr, 10u);
|
||||
num_str += "." + dec_part;
|
||||
num_str += ~"." + dec_part;
|
||||
}
|
||||
alt scan_exponent(rdr) {
|
||||
some(s) {
|
||||
@ -414,7 +414,7 @@ fn scan_number(c: char, rdr: string_reader) -> token::token {
|
||||
ast::ty_f);
|
||||
} else {
|
||||
if str::len(num_str) == 0u {
|
||||
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));
|
||||
|
||||
@ -440,7 +440,7 @@ fn scan_numeric_escape(rdr: string_reader, n_hex_digits: uint) -> char {
|
||||
}
|
||||
|
||||
fn next_token_inner(rdr: string_reader) -> token::token {
|
||||
let mut accum_str = "";
|
||||
let mut accum_str = ~"";
|
||||
let mut c = rdr.curr;
|
||||
if (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
@ -455,7 +455,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
|
||||
bump(rdr);
|
||||
c = rdr.curr;
|
||||
}
|
||||
if str::eq(accum_str, "_") { ret token::UNDERSCORE; }
|
||||
if str::eq(accum_str, ~"_") { ret token::UNDERSCORE; }
|
||||
let is_mod_name = c == ':' && nextch(rdr) == ':';
|
||||
|
||||
// FIXME: perform NFKC normalization here. (Issue #2253)
|
||||
@ -578,7 +578,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
|
||||
}
|
||||
}
|
||||
if rdr.curr != '\'' {
|
||||
rdr.fatal("unterminated character constant");
|
||||
rdr.fatal(~"unterminated character constant");
|
||||
}
|
||||
bump(rdr); // advance curr past token
|
||||
ret token::LIT_INT(c2 as i64, ast::ty_char);
|
||||
|
@ -160,8 +160,8 @@ class parser {
|
||||
let mut restriction: restriction;
|
||||
let mut quote_depth: uint; // not (yet) related to the quasiquoter
|
||||
let reader: reader;
|
||||
let keywords: hashmap<str, ()>;
|
||||
let restricted_keywords: hashmap<str, ()>;
|
||||
let keywords: hashmap<~str, ()>;
|
||||
let restricted_keywords: hashmap<~str, ()>;
|
||||
|
||||
new(sess: parse_sess, cfg: ast::crate_cfg, +rdr: reader, ftype: file_type)
|
||||
{
|
||||
@ -220,29 +220,29 @@ class parser {
|
||||
}
|
||||
ret copy self.buffer[(self.buffer_start + dist - 1) & 3].tok;
|
||||
}
|
||||
fn fatal(m: str) -> ! {
|
||||
fn fatal(m: ~str) -> ! {
|
||||
self.sess.span_diagnostic.span_fatal(copy self.span, m)
|
||||
}
|
||||
fn span_fatal(sp: span, m: str) -> ! {
|
||||
fn span_fatal(sp: span, m: ~str) -> ! {
|
||||
self.sess.span_diagnostic.span_fatal(sp, m)
|
||||
}
|
||||
fn bug(m: str) -> ! {
|
||||
fn bug(m: ~str) -> ! {
|
||||
self.sess.span_diagnostic.span_bug(copy self.span, m)
|
||||
}
|
||||
fn warn(m: str) {
|
||||
fn warn(m: ~str) {
|
||||
self.sess.span_diagnostic.span_warn(copy self.span, m)
|
||||
}
|
||||
fn get_str(i: token::str_num) -> @str/~ {
|
||||
fn get_str(i: token::str_num) -> @~str {
|
||||
interner::get(*self.reader.interner(), i)
|
||||
}
|
||||
fn get_id() -> node_id { next_node_id(self.sess) }
|
||||
|
||||
fn parse_ty_fn(purity: ast::purity) -> ty_ {
|
||||
let proto = if self.eat_keyword("extern") {
|
||||
self.expect_keyword("fn");
|
||||
let proto = if self.eat_keyword(~"extern") {
|
||||
self.expect_keyword(~"fn");
|
||||
ast::proto_bare
|
||||
} else {
|
||||
self.expect_keyword("fn");
|
||||
self.expect_keyword(~"fn");
|
||||
self.parse_fn_ty_proto()
|
||||
};
|
||||
ty_fn(proto, self.parse_ty_fn_decl(purity))
|
||||
@ -259,7 +259,7 @@ class parser {
|
||||
let name = self.parse_value_ident();
|
||||
p.bump();
|
||||
name
|
||||
} else { @""/~ };
|
||||
} else { @~"" };
|
||||
|
||||
{mode: mode, ty: p.parse_ty(false), ident: name,
|
||||
id: p.get_id()}
|
||||
@ -317,8 +317,8 @@ class parser {
|
||||
vis: vis})
|
||||
}
|
||||
|
||||
_ { p.fatal("expected `;` or `}` but found `" +
|
||||
token_to_str(p.reader, p.token) + "`");
|
||||
_ { p.fatal(~"expected `;` or `}` but found `" +
|
||||
token_to_str(p.reader, p.token) + ~"`");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -345,7 +345,7 @@ class parser {
|
||||
fn ident_index(args: ~[arg], i: ident) -> uint {
|
||||
let mut j = 0u;
|
||||
for args.each |a| { if a.ident == i { ret j; } j += 1u; }
|
||||
self.fatal("unbound variable `" + *i + "` in constraint arg");
|
||||
self.fatal(~"unbound variable `" + *i + ~"` in constraint arg");
|
||||
}
|
||||
|
||||
fn parse_type_constr_arg() -> @ty_constr_arg {
|
||||
@ -431,7 +431,7 @@ class parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn region_from_name(s: option<@str/~>) -> @region {
|
||||
fn region_from_name(s: option<@~str>) -> @region {
|
||||
let r = alt s {
|
||||
some (string) { re_named(string) }
|
||||
none { re_anon }
|
||||
@ -538,19 +538,19 @@ class parser {
|
||||
let region = self.parse_region_with_sep();
|
||||
let mt = self.parse_mt();
|
||||
ty_rptr(region, mt)
|
||||
} else if self.eat_keyword("pure") {
|
||||
} else if self.eat_keyword(~"pure") {
|
||||
self.parse_ty_fn(ast::pure_fn)
|
||||
} else if self.eat_keyword("unsafe") {
|
||||
} else if self.eat_keyword(~"unsafe") {
|
||||
self.parse_ty_fn(ast::unsafe_fn)
|
||||
} else if self.is_keyword("fn") {
|
||||
} else if self.is_keyword(~"fn") {
|
||||
self.parse_ty_fn(ast::impure_fn)
|
||||
} else if self.eat_keyword("extern") {
|
||||
self.expect_keyword("fn");
|
||||
} else if self.eat_keyword(~"extern") {
|
||||
self.expect_keyword(~"fn");
|
||||
ty_fn(proto_bare, self.parse_ty_fn_decl(ast::impure_fn))
|
||||
} else if self.token == token::MOD_SEP || is_ident(self.token) {
|
||||
let path = self.parse_path_with_tps(colons_before_params);
|
||||
ty_path(path, self.get_id())
|
||||
} else { self.fatal("expected type"); };
|
||||
} else { self.fatal(~"expected type"); };
|
||||
|
||||
let sp = mk_sp(lo, self.last_span.hi);
|
||||
ret @{id: self.get_id(),
|
||||
@ -588,9 +588,9 @@ class parser {
|
||||
@{id: p.get_id(), is_move: is_move, name: ident, span: sp}
|
||||
}
|
||||
|
||||
if self.eat_keyword("move") {
|
||||
if self.eat_keyword(~"move") {
|
||||
either::right(parse_capture_item(self, true))
|
||||
} else if self.eat_keyword("copy") {
|
||||
} else if self.eat_keyword(~"copy") {
|
||||
either::right(parse_capture_item(self, false))
|
||||
} else {
|
||||
parse_arg_fn(self)
|
||||
@ -642,7 +642,7 @@ class parser {
|
||||
some(mac_aq(mk_sp(lo,hi), e))
|
||||
}
|
||||
_ {
|
||||
self.fatal("expected `(` or unsuffixed integer literal");
|
||||
self.fatal(~"expected `(` or unsuffixed integer literal");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -692,9 +692,9 @@ class parser {
|
||||
|
||||
fn parse_lit() -> lit {
|
||||
let lo = self.span.lo;
|
||||
let lit = if self.eat_keyword("true") {
|
||||
let lit = if self.eat_keyword(~"true") {
|
||||
lit_bool(true)
|
||||
} else if self.eat_keyword("false") {
|
||||
} else if self.eat_keyword(~"false") {
|
||||
lit_bool(false)
|
||||
} else {
|
||||
let tok = self.token;
|
||||
@ -753,7 +753,7 @@ class parser {
|
||||
// Hack: avoid parsing vstores like /@ and /~. This is painful
|
||||
// because the notation for region bounds and the notation for
|
||||
// vstores is... um... the same. I guess that's my fault. This
|
||||
// is still not ideal as for str/& we end up parsing more than we
|
||||
// is still not ideal as for &str we end up parsing more than we
|
||||
// ought to and have to sort it out later.
|
||||
if self.token == token::BINOP(token::SLASH)
|
||||
&& self.look_ahead(1u) == token::BINOP(token::AND) {
|
||||
@ -781,9 +781,9 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_mutability() -> mutability {
|
||||
if self.eat_keyword("mut") {
|
||||
if self.eat_keyword(~"mut") {
|
||||
m_mutbl
|
||||
} else if self.eat_keyword("const") {
|
||||
} else if self.eat_keyword(~"const") {
|
||||
m_const
|
||||
} else {
|
||||
m_imm
|
||||
@ -866,7 +866,7 @@ class parser {
|
||||
ret self.mk_pexpr(lo, hi, expr_tup(es));
|
||||
} else if self.token == token::LBRACE {
|
||||
self.bump();
|
||||
if self.is_keyword("mut") ||
|
||||
if self.is_keyword(~"mut") ||
|
||||
is_plain_ident(self.token)
|
||||
&& self.look_ahead(1u) == token::COLON {
|
||||
let mut fields = ~[self.parse_field(token::COLON)];
|
||||
@ -874,11 +874,11 @@ class parser {
|
||||
while self.token != token::RBRACE {
|
||||
// optional comma before "with"
|
||||
if self.token == token::COMMA
|
||||
&& self.token_is_keyword("with",
|
||||
&& self.token_is_keyword(~"with",
|
||||
self.look_ahead(1u)) {
|
||||
self.bump();
|
||||
}
|
||||
if self.eat_keyword("with") {
|
||||
if self.eat_keyword(~"with") {
|
||||
base = some(self.parse_expr()); break;
|
||||
}
|
||||
self.expect(token::COMMA);
|
||||
@ -897,36 +897,38 @@ class parser {
|
||||
}
|
||||
} else if token::is_bar(self.token) {
|
||||
ret pexpr(self.parse_lambda_expr());
|
||||
} else if self.eat_keyword("new") {
|
||||
} else if self.eat_keyword(~"new") {
|
||||
self.expect(token::LPAREN);
|
||||
let r = self.parse_expr();
|
||||
self.expect(token::RPAREN);
|
||||
let v = self.parse_expr();
|
||||
ret self.mk_pexpr(lo, self.span.hi,
|
||||
expr_new(r, self.get_id(), v));
|
||||
} else if self.eat_keyword("if") {
|
||||
} else if self.eat_keyword(~"if") {
|
||||
ret pexpr(self.parse_if_expr());
|
||||
} else if self.eat_keyword("for") {
|
||||
ret pexpr(self.parse_sugary_call_expr("for", expr_loop_body));
|
||||
} else if self.eat_keyword("do") {
|
||||
ret pexpr(self.parse_sugary_call_expr("do", expr_do_body));
|
||||
} else if self.eat_keyword("while") {
|
||||
} else if self.eat_keyword(~"for") {
|
||||
ret pexpr(self.parse_sugary_call_expr(~"for", expr_loop_body));
|
||||
} else if self.eat_keyword(~"do") {
|
||||
ret pexpr(self.parse_sugary_call_expr(~"do", expr_do_body));
|
||||
} else if self.eat_keyword(~"while") {
|
||||
ret pexpr(self.parse_while_expr());
|
||||
} else if self.eat_keyword("loop") {
|
||||
} else if self.eat_keyword(~"loop") {
|
||||
ret pexpr(self.parse_loop_expr());
|
||||
} else if self.eat_keyword("alt") {
|
||||
} else if self.eat_keyword(~"alt") {
|
||||
ret pexpr(self.parse_alt_expr());
|
||||
} else if self.eat_keyword("fn") {
|
||||
} else if self.eat_keyword(~"fn") {
|
||||
let proto = self.parse_fn_ty_proto();
|
||||
alt proto {
|
||||
proto_bare { self.fatal("fn expr are deprecated, use fn@"); }
|
||||
proto_any { self.fatal("fn* cannot be used in an expression"); }
|
||||
proto_bare { self.fatal(~"fn expr are deprecated, use fn@"); }
|
||||
proto_any {
|
||||
self.fatal(~"fn* cannot be used in an expression");
|
||||
}
|
||||
_ { /* fallthrough */ }
|
||||
}
|
||||
ret pexpr(self.parse_fn_expr(proto));
|
||||
} else if self.eat_keyword("unchecked") {
|
||||
} else if self.eat_keyword(~"unchecked") {
|
||||
ret pexpr(self.parse_block_expr(lo, unchecked_blk));
|
||||
} else if self.eat_keyword("unsafe") {
|
||||
} else if self.eat_keyword(~"unsafe") {
|
||||
ret pexpr(self.parse_block_expr(lo, unsafe_blk));
|
||||
} else if self.token == token::LBRACKET {
|
||||
self.bump();
|
||||
@ -958,13 +960,13 @@ class parser {
|
||||
let ex_ext = self.parse_syntax_ext();
|
||||
hi = ex_ext.span.hi;
|
||||
ex = ex_ext.node;
|
||||
} else if self.eat_keyword("fail") {
|
||||
} else if self.eat_keyword(~"fail") {
|
||||
if can_begin_expr(self.token) {
|
||||
let e = self.parse_expr();
|
||||
hi = e.span.hi;
|
||||
ex = expr_fail(some(e));
|
||||
} else { ex = expr_fail(none); }
|
||||
} else if self.eat_keyword("log") {
|
||||
} else if self.eat_keyword(~"log") {
|
||||
self.expect(token::LPAREN);
|
||||
let lvl = self.parse_expr();
|
||||
self.expect(token::COMMA);
|
||||
@ -972,18 +974,18 @@ class parser {
|
||||
ex = expr_log(2, lvl, e);
|
||||
hi = self.span.hi;
|
||||
self.expect(token::RPAREN);
|
||||
} else if self.eat_keyword("assert") {
|
||||
} else if self.eat_keyword(~"assert") {
|
||||
let e = self.parse_expr();
|
||||
ex = expr_assert(e);
|
||||
hi = e.span.hi;
|
||||
} else if self.eat_keyword("check") {
|
||||
} else if self.eat_keyword(~"check") {
|
||||
/* Should be a predicate (pure boolean function) applied to
|
||||
arguments that are all either slot variables or literals.
|
||||
but the typechecker enforces that. */
|
||||
let e = self.parse_expr();
|
||||
hi = e.span.hi;
|
||||
ex = expr_check(checked_expr, e);
|
||||
} else if self.eat_keyword("claim") {
|
||||
} else if self.eat_keyword(~"claim") {
|
||||
/* Same rules as check, except that if check-claims
|
||||
is enabled (a command-line flag), then the parser turns
|
||||
claims into check */
|
||||
@ -991,25 +993,25 @@ class parser {
|
||||
let e = self.parse_expr();
|
||||
hi = e.span.hi;
|
||||
ex = expr_check(claimed_expr, e);
|
||||
} else if self.eat_keyword("ret") {
|
||||
} else if self.eat_keyword(~"ret") {
|
||||
if can_begin_expr(self.token) {
|
||||
let e = self.parse_expr();
|
||||
hi = e.span.hi;
|
||||
ex = expr_ret(some(e));
|
||||
} else { ex = expr_ret(none); }
|
||||
} else if self.eat_keyword("break") {
|
||||
} else if self.eat_keyword(~"break") {
|
||||
ex = expr_break;
|
||||
hi = self.span.hi;
|
||||
} else if self.eat_keyword("again") {
|
||||
} else if self.eat_keyword(~"again") {
|
||||
ex = expr_again;
|
||||
hi = self.span.hi;
|
||||
} else if self.eat_keyword("copy") {
|
||||
} else if self.eat_keyword(~"copy") {
|
||||
let e = self.parse_expr();
|
||||
ex = expr_copy(e);
|
||||
hi = e.span.hi;
|
||||
} else if self.token == token::MOD_SEP ||
|
||||
is_ident(self.token) && !self.is_keyword("true") &&
|
||||
!self.is_keyword("false") {
|
||||
is_ident(self.token) && !self.is_keyword(~"true") &&
|
||||
!self.is_keyword(~"false") {
|
||||
let pth = self.parse_path_with_tps(true);
|
||||
|
||||
/* `!`, as an operator, is prefix, so we know this isn't that */
|
||||
@ -1065,7 +1067,7 @@ class parser {
|
||||
fn parse_syntax_ext_naked(lo: uint) -> @expr {
|
||||
alt self.token {
|
||||
token::IDENT(_, _) {}
|
||||
_ { self.fatal("expected a syntax expander name"); }
|
||||
_ { self.fatal(~"expected a syntax expander name"); }
|
||||
}
|
||||
let pth = self.parse_path_without_tps();
|
||||
//temporary for a backwards-compatible cycle:
|
||||
@ -1093,7 +1095,7 @@ class parser {
|
||||
alt (self.token) {
|
||||
token::LBRACE {depth += 1u;}
|
||||
token::RBRACE {depth -= 1u;}
|
||||
token::EOF {self.fatal("unexpected EOF in macro body");}
|
||||
token::EOF {self.fatal(~"unexpected EOF in macro body");}
|
||||
_ {}
|
||||
}
|
||||
self.bump();
|
||||
@ -1181,7 +1183,7 @@ class parser {
|
||||
self.bump();
|
||||
ret (some(sep), zerok);
|
||||
} else {
|
||||
self.fatal("expected `*` or `+`");
|
||||
self.fatal(~"expected `*` or `+`");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1201,11 +1203,11 @@ class parser {
|
||||
alt p.token {
|
||||
token::RPAREN | token::RBRACE | token::RBRACKET
|
||||
if !delim_ok {
|
||||
p.fatal("incorrect close delimiter: `"
|
||||
+ token_to_str(p.reader, p.token) + "`");
|
||||
p.fatal(~"incorrect close delimiter: `"
|
||||
+ token_to_str(p.reader, p.token) + ~"`");
|
||||
}
|
||||
token::EOF {
|
||||
p.fatal("file ended in the middle of a macro invocation");
|
||||
p.fatal(~"file ended in the middle of a macro invocation");
|
||||
}
|
||||
/* we ought to allow different depths of unquotation */
|
||||
token::DOLLAR if p.quote_depth > 0u {
|
||||
@ -1280,7 +1282,7 @@ class parser {
|
||||
let ms = self.parse_matcher_subseq(name_idx, token::LPAREN,
|
||||
token::RPAREN);
|
||||
if ms.len() == 0u {
|
||||
self.fatal("repetition body must be nonempty");
|
||||
self.fatal(~"repetition body must be nonempty");
|
||||
}
|
||||
let (sep, zerok) = self.parse_sep_and_zerok();
|
||||
mtc_rep(ms, sep, zerok)
|
||||
@ -1411,7 +1413,7 @@ class parser {
|
||||
}
|
||||
_ {}
|
||||
}
|
||||
if as_prec > min_prec && self.eat_keyword("as") {
|
||||
if as_prec > min_prec && self.eat_keyword(~"as") {
|
||||
let rhs = self.parse_ty(true);
|
||||
let _as =
|
||||
self.mk_pexpr(lhs.span.lo, rhs.span.hi, expr_cast(lhs, rhs));
|
||||
@ -1474,7 +1476,7 @@ class parser {
|
||||
let thn = self.parse_block();
|
||||
let mut els: option<@expr> = none;
|
||||
let mut hi = thn.span.hi;
|
||||
if self.eat_keyword("else") {
|
||||
if self.eat_keyword(~"else") {
|
||||
let elexpr = self.parse_else_expr();
|
||||
els = some(elexpr);
|
||||
hi = elexpr.span.hi;
|
||||
@ -1483,7 +1485,7 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_if_expr() -> @expr {
|
||||
if self.eat_keyword("check") {
|
||||
if self.eat_keyword(~"check") {
|
||||
let q = self.parse_if_expr_1();
|
||||
ret self.mk_expr(q.lo, q.hi,
|
||||
expr_if_check(q.cond, q.then, q.els));
|
||||
@ -1560,7 +1562,7 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_else_expr() -> @expr {
|
||||
if self.eat_keyword("if") {
|
||||
if self.eat_keyword(~"if") {
|
||||
ret self.parse_if_expr();
|
||||
} else {
|
||||
let blk = self.parse_block();
|
||||
@ -1568,7 +1570,7 @@ class parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_sugary_call_expr(keyword: str,
|
||||
fn parse_sugary_call_expr(keyword: ~str,
|
||||
ctor: fn(+@expr) -> expr_) -> @expr {
|
||||
let lo = self.last_span;
|
||||
// Parse the callee `foo` in
|
||||
@ -1625,7 +1627,7 @@ class parser {
|
||||
|
||||
fn parse_alt_expr() -> @expr {
|
||||
let lo = self.last_span.lo;
|
||||
let mode = if self.eat_keyword("check") { alt_check }
|
||||
let mode = if self.eat_keyword(~"check") { alt_check }
|
||||
else { alt_exhaustive };
|
||||
let discriminant = self.parse_expr();
|
||||
self.expect(token::LBRACE);
|
||||
@ -1633,7 +1635,7 @@ class parser {
|
||||
while self.token != token::RBRACE {
|
||||
let pats = self.parse_pats();
|
||||
let mut guard = none;
|
||||
if self.eat_keyword("if") { guard = some(self.parse_expr()); }
|
||||
if self.eat_keyword(~"if") { guard = some(self.parse_expr()); }
|
||||
if self.token == token::FAT_ARROW { self.bump(); }
|
||||
let blk = self.parse_block();
|
||||
vec::push(arms, {pats: pats, guard: guard, body: blk});
|
||||
@ -1736,9 +1738,9 @@ class parser {
|
||||
if self.token == token::UNDERSCORE {
|
||||
self.bump();
|
||||
if self.token != token::RBRACE {
|
||||
self.fatal("expected `}`, found `" +
|
||||
self.fatal(~"expected `}`, found `" +
|
||||
token_to_str(self.reader, self.token) +
|
||||
"`");
|
||||
~"`");
|
||||
}
|
||||
etc = true;
|
||||
break;
|
||||
@ -1789,10 +1791,10 @@ class parser {
|
||||
}
|
||||
}
|
||||
tok {
|
||||
if !is_ident(tok) || self.is_keyword("true")
|
||||
|| self.is_keyword("false") {
|
||||
if !is_ident(tok) || self.is_keyword(~"true")
|
||||
|| self.is_keyword(~"false") {
|
||||
let val = self.parse_expr_res(RESTRICT_NO_BAR_OP);
|
||||
if self.eat_keyword("to") {
|
||||
if self.eat_keyword(~"to") {
|
||||
let end = self.parse_expr_res(RESTRICT_NO_BAR_OP);
|
||||
hi = end.span.hi;
|
||||
pat = pat_range(val, end);
|
||||
@ -1866,7 +1868,7 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_let() -> @decl {
|
||||
let is_mutbl = self.eat_keyword("mut");
|
||||
let is_mutbl = self.eat_keyword(~"mut");
|
||||
let lo = self.span.lo;
|
||||
let mut locals = ~[self.parse_local(is_mutbl, true)];
|
||||
while self.eat(token::COMMA) {
|
||||
@ -1879,11 +1881,11 @@ class parser {
|
||||
fn parse_instance_var(pr: visibility) -> @class_member {
|
||||
let mut is_mutbl = class_immutable;
|
||||
let lo = self.span.lo;
|
||||
if self.eat_keyword("mut") {
|
||||
if self.eat_keyword(~"mut") {
|
||||
is_mutbl = class_mutable;
|
||||
}
|
||||
if !is_plain_ident(self.token) {
|
||||
self.fatal("expected ident");
|
||||
self.fatal(~"expected ident");
|
||||
}
|
||||
let name = self.parse_ident();
|
||||
self.expect(token::COLON);
|
||||
@ -1896,14 +1898,14 @@ class parser {
|
||||
fn check_expected_item(p: parser, current_attrs: ~[attribute]) {
|
||||
// If we have attributes then we should have an item
|
||||
if vec::is_not_empty(current_attrs) {
|
||||
p.fatal("expected item");
|
||||
p.fatal(~"expected item");
|
||||
}
|
||||
}
|
||||
|
||||
let lo = self.span.lo;
|
||||
if self.is_keyword("let") {
|
||||
if self.is_keyword(~"let") {
|
||||
check_expected_item(self, first_item_attrs);
|
||||
self.expect_keyword("let");
|
||||
self.expect_keyword(~"let");
|
||||
let decl = self.parse_let();
|
||||
ret @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id()));
|
||||
} else {
|
||||
@ -1936,7 +1938,7 @@ class parser {
|
||||
}
|
||||
|
||||
fn expr_is_complete(e: pexpr) -> bool {
|
||||
log(debug, ("expr_is_complete", self.restriction,
|
||||
log(debug, (~"expr_is_complete", self.restriction,
|
||||
print::pprust::expr_to_str(*e),
|
||||
classify::expr_requires_semi_to_be_stmt(*e)));
|
||||
ret self.restriction == RESTRICT_STMT_EXPR &&
|
||||
@ -1962,12 +1964,12 @@ class parser {
|
||||
}
|
||||
|
||||
let lo = self.span.lo;
|
||||
if self.eat_keyword("unchecked") {
|
||||
if self.eat_keyword(~"unchecked") {
|
||||
self.expect(token::LBRACE);
|
||||
let {inner, next} = maybe_parse_inner_attrs_and_next(self,
|
||||
parse_attrs);
|
||||
ret (inner, self.parse_block_tail_(lo, unchecked_blk, next));
|
||||
} else if self.eat_keyword("unsafe") {
|
||||
} else if self.eat_keyword(~"unsafe") {
|
||||
self.expect(token::LBRACE);
|
||||
let {inner, next} = maybe_parse_inner_attrs_and_next(self,
|
||||
parse_attrs);
|
||||
@ -2004,7 +2006,7 @@ class parser {
|
||||
let mut initial_attrs = attrs_remaining;
|
||||
|
||||
if self.token == token::RBRACE && !vec::is_empty(initial_attrs) {
|
||||
self.fatal("expected item");
|
||||
self.fatal(~"expected item");
|
||||
}
|
||||
|
||||
while self.token != token::RBRACE {
|
||||
@ -2028,9 +2030,9 @@ class parser {
|
||||
}
|
||||
t {
|
||||
if classify::stmt_ends_with_semi(*stmt) {
|
||||
self.fatal("expected `;` or `}` after expression \
|
||||
but found `"
|
||||
+ token_to_str(self.reader, t) + "`");
|
||||
self.fatal(~"expected `;` or `}` after \
|
||||
expression but found `"
|
||||
+ token_to_str(self.reader, t) + ~"`");
|
||||
}
|
||||
vec::push(stmts, stmt);
|
||||
}
|
||||
@ -2060,9 +2062,9 @@ class parser {
|
||||
let ident = self.parse_ident();
|
||||
if self.eat(token::COLON) {
|
||||
while self.token != token::COMMA && self.token != token::GT {
|
||||
if self.eat_keyword("send") { push(bounds, bound_send); }
|
||||
else if self.eat_keyword("copy") { push(bounds, bound_copy) }
|
||||
else if self.eat_keyword("const") {
|
||||
if self.eat_keyword(~"send") { push(bounds, bound_send); }
|
||||
else if self.eat_keyword(~"copy") { push(bounds, bound_copy) }
|
||||
else if self.eat_keyword(~"const") {
|
||||
push(bounds, bound_const)
|
||||
}
|
||||
else { push(bounds, bound_trait(self.parse_ty(false))); }
|
||||
@ -2156,16 +2158,16 @@ class parser {
|
||||
fn parse_method_name() -> ident {
|
||||
alt copy self.token {
|
||||
token::BINOP(op) { self.bump(); @token::binop_to_str(op) }
|
||||
token::NOT { self.bump(); @"!"/~ }
|
||||
token::NOT { self.bump(); @~"!" }
|
||||
token::LBRACKET {
|
||||
self.bump();
|
||||
self.expect(token::RBRACKET);
|
||||
@"[]"/~
|
||||
@~"[]"
|
||||
}
|
||||
_ {
|
||||
let id = self.parse_value_ident();
|
||||
if id == @"unary"/~ && self.eat(token::BINOP(token::MINUS)) {
|
||||
@"unary-"/~
|
||||
if id == @~"unary" && self.eat(token::BINOP(token::MINUS)) {
|
||||
@~"unary-"
|
||||
}
|
||||
else { id }
|
||||
}
|
||||
@ -2208,7 +2210,7 @@ class parser {
|
||||
self.parse_region_param();
|
||||
(none, self.parse_ty_params())
|
||||
}
|
||||
else if self.is_keyword("of") {
|
||||
else if self.is_keyword(~"of") {
|
||||
(none, ~[])
|
||||
} else {
|
||||
let id = self.parse_ident();
|
||||
@ -2216,7 +2218,7 @@ class parser {
|
||||
(some(id), self.parse_ty_params())
|
||||
}
|
||||
};
|
||||
let ifce = if self.eat_keyword("of") {
|
||||
let ifce = if self.eat_keyword(~"of") {
|
||||
let path = self.parse_path_with_tps(false);
|
||||
if option::is_none(ident) {
|
||||
ident = some(vec::last(path.idents));
|
||||
@ -2225,9 +2227,9 @@ class parser {
|
||||
} else { none };
|
||||
let ident = alt ident {
|
||||
some(name) { name }
|
||||
none { self.expect_keyword("of"); fail; }
|
||||
none { self.expect_keyword(~"of"); fail; }
|
||||
};
|
||||
self.expect_keyword("for");
|
||||
self.expect_keyword(~"for");
|
||||
let ty = self.parse_ty(false);
|
||||
let mut meths = ~[];
|
||||
self.expect(token::LBRACE);
|
||||
@ -2310,14 +2312,14 @@ class parser {
|
||||
Is it strange for the parser to check this?
|
||||
*/
|
||||
none {
|
||||
self.fatal("class with no constructor");
|
||||
self.fatal(~"class with no constructor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_single_class_item(vis: visibility)
|
||||
-> @class_member {
|
||||
if self.eat_keyword("let") {
|
||||
if self.eat_keyword(~"let") {
|
||||
let a_var = self.parse_instance_var(vis);
|
||||
self.expect(token::SEMI);
|
||||
ret a_var;
|
||||
@ -2348,15 +2350,15 @@ class parser {
|
||||
|
||||
fn parse_class_item(class_name_with_tps: @path)
|
||||
-> class_contents {
|
||||
if self.eat_keyword("new") {
|
||||
if self.eat_keyword(~"new") {
|
||||
// result type is always the type of the class
|
||||
ret self.parse_ctor(ty_path(class_name_with_tps,
|
||||
self.get_id()));
|
||||
}
|
||||
else if self.eat_keyword("drop") {
|
||||
else if self.eat_keyword(~"drop") {
|
||||
ret self.parse_dtor();
|
||||
}
|
||||
else if self.eat_keyword("priv") {
|
||||
else if self.eat_keyword(~"priv") {
|
||||
self.expect(token::LBRACE);
|
||||
let mut results = ~[];
|
||||
while self.token != token::RBRACE {
|
||||
@ -2372,8 +2374,8 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_visibility(def: visibility) -> visibility {
|
||||
if self.eat_keyword("pub") { public }
|
||||
else if self.eat_keyword("priv") { private }
|
||||
if self.eat_keyword(~"pub") { public }
|
||||
else if self.eat_keyword(~"priv") { private }
|
||||
else { def }
|
||||
}
|
||||
|
||||
@ -2395,8 +2397,8 @@ class parser {
|
||||
alt self.parse_item(attrs, vis) {
|
||||
some(i) { vec::push(items, i); }
|
||||
_ {
|
||||
self.fatal("expected item but found `" +
|
||||
token_to_str(self.reader, self.token) + "`");
|
||||
self.fatal(~"expected item but found `" +
|
||||
token_to_str(self.reader, self.token) + ~"`");
|
||||
}
|
||||
}
|
||||
#debug["parse_mod_items: attrs=%?", attrs];
|
||||
@ -2404,7 +2406,7 @@ class parser {
|
||||
|
||||
if first && attrs_remaining.len() > 0u {
|
||||
// We parsed attributes for the first item but didn't find it
|
||||
self.fatal("expected item");
|
||||
self.fatal(~"expected item");
|
||||
}
|
||||
|
||||
ret {view_items: view_items, items: items};
|
||||
@ -2444,12 +2446,12 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_fn_purity() -> purity {
|
||||
if self.eat_keyword("fn") { impure_fn }
|
||||
else if self.eat_keyword("pure") {
|
||||
self.expect_keyword("fn");
|
||||
if self.eat_keyword(~"fn") { impure_fn }
|
||||
else if self.eat_keyword(~"pure") {
|
||||
self.expect_keyword(~"fn");
|
||||
pure_fn
|
||||
} else if self.eat_keyword("unsafe") {
|
||||
self.expect_keyword("fn");
|
||||
} else if self.eat_keyword(~"unsafe") {
|
||||
self.expect_keyword(~"fn");
|
||||
unsafe_fn
|
||||
}
|
||||
else { self.unexpected(); }
|
||||
@ -2478,7 +2480,7 @@ class parser {
|
||||
}
|
||||
|
||||
fn parse_item_foreign_mod() -> item_info {
|
||||
self.expect_keyword("mod");
|
||||
self.expect_keyword(~"mod");
|
||||
let id = self.parse_ident();
|
||||
self.expect(token::LBRACE);
|
||||
let more_attrs = self.parse_inner_attrs_and_next();
|
||||
@ -2563,7 +2565,7 @@ class parser {
|
||||
}
|
||||
self.expect(token::RBRACE);
|
||||
if (have_disr && !all_nullary) {
|
||||
self.fatal("discriminator values can only be used with a c-like \
|
||||
self.fatal(~"discriminator values can only be used with a c-like \
|
||||
enum");
|
||||
}
|
||||
(id, item_enum(variants, ty_params), none)
|
||||
@ -2603,39 +2605,39 @@ class parser {
|
||||
fn parse_item(+attrs: ~[attribute], vis: visibility)
|
||||
-> option<@item> {
|
||||
let lo = self.span.lo;
|
||||
let (ident, item_, extra_attrs) = if self.eat_keyword("const") {
|
||||
let (ident, item_, extra_attrs) = if self.eat_keyword(~"const") {
|
||||
self.parse_item_const()
|
||||
} else if self.is_keyword("fn") &&
|
||||
} else if self.is_keyword(~"fn") &&
|
||||
!self.fn_expr_lookahead(self.look_ahead(1u)) {
|
||||
self.bump();
|
||||
self.parse_item_fn(impure_fn)
|
||||
} else if self.eat_keyword("pure") {
|
||||
self.expect_keyword("fn");
|
||||
} else if self.eat_keyword(~"pure") {
|
||||
self.expect_keyword(~"fn");
|
||||
self.parse_item_fn(pure_fn)
|
||||
} else if self.is_keyword("unsafe")
|
||||
} else if self.is_keyword(~"unsafe")
|
||||
&& self.look_ahead(1u) != token::LBRACE {
|
||||
self.bump();
|
||||
self.expect_keyword("fn");
|
||||
self.expect_keyword(~"fn");
|
||||
self.parse_item_fn(unsafe_fn)
|
||||
} else if self.eat_keyword("extern") {
|
||||
if self.eat_keyword("fn") {
|
||||
} else if self.eat_keyword(~"extern") {
|
||||
if self.eat_keyword(~"fn") {
|
||||
self.parse_item_fn(extern_fn)
|
||||
} else {
|
||||
self.parse_item_foreign_mod()
|
||||
}
|
||||
} else if self.eat_keyword("mod") {
|
||||
} else if self.eat_keyword(~"mod") {
|
||||
self.parse_item_mod()
|
||||
} else if self.eat_keyword("type") {
|
||||
} else if self.eat_keyword(~"type") {
|
||||
self.parse_item_type()
|
||||
} else if self.eat_keyword("enum") {
|
||||
} else if self.eat_keyword(~"enum") {
|
||||
self.parse_item_enum(vis)
|
||||
} else if self.eat_keyword("iface") {
|
||||
} else if self.eat_keyword(~"iface") {
|
||||
self.parse_item_trait()
|
||||
} else if self.eat_keyword("trait") {
|
||||
} else if self.eat_keyword(~"trait") {
|
||||
self.parse_item_trait()
|
||||
} else if self.eat_keyword("impl") {
|
||||
} else if self.eat_keyword(~"impl") {
|
||||
self.parse_item_impl()
|
||||
} else if self.eat_keyword("class") {
|
||||
} else if self.eat_keyword(~"class") {
|
||||
self.parse_item_class()
|
||||
} else if !self.is_any_keyword(copy self.token)
|
||||
&& self.look_ahead(1) == token::NOT
|
||||
@ -2747,21 +2749,21 @@ class parser {
|
||||
}
|
||||
|
||||
fn is_view_item() -> bool {
|
||||
let tok = if !self.is_keyword("pub") && !self.is_keyword("priv") {
|
||||
let tok = if !self.is_keyword(~"pub") && !self.is_keyword(~"priv") {
|
||||
self.token
|
||||
} else { self.look_ahead(1u) };
|
||||
self.token_is_keyword("use", tok)
|
||||
|| self.token_is_keyword("import", tok)
|
||||
|| self.token_is_keyword("export", tok)
|
||||
self.token_is_keyword(~"use", tok)
|
||||
|| self.token_is_keyword(~"import", tok)
|
||||
|| self.token_is_keyword(~"export", tok)
|
||||
}
|
||||
|
||||
fn parse_view_item(+attrs: ~[attribute]) -> @view_item {
|
||||
let lo = self.span.lo, vis = self.parse_visibility(private);
|
||||
let node = if self.eat_keyword("use") {
|
||||
let node = if self.eat_keyword(~"use") {
|
||||
self.parse_use()
|
||||
} else if self.eat_keyword("import") {
|
||||
} else if self.eat_keyword(~"import") {
|
||||
view_item_import(self.parse_view_paths())
|
||||
} else if self.eat_keyword("export") {
|
||||
} else if self.eat_keyword(~"export") {
|
||||
view_item_export(self.parse_view_paths())
|
||||
} else { fail; };
|
||||
self.expect(token::SEMI);
|
||||
@ -2775,7 +2777,7 @@ class parser {
|
||||
let mut attrs = vec::append(first_item_attrs,
|
||||
self.parse_outer_attributes());
|
||||
let mut items = ~[];
|
||||
while if only_imports { self.is_keyword("import") }
|
||||
while if only_imports { self.is_keyword(~"import") }
|
||||
else { self.is_view_item() } {
|
||||
vec::push(items, self.parse_view_item(attrs));
|
||||
attrs = self.parse_outer_attributes();
|
||||
@ -2796,11 +2798,11 @@ class parser {
|
||||
config: self.cfg});
|
||||
}
|
||||
|
||||
fn parse_str() -> @str/~ {
|
||||
fn parse_str() -> @~str {
|
||||
alt copy self.token {
|
||||
token::LIT_STR(s) { self.bump(); self.get_str(s) }
|
||||
_ {
|
||||
self.fatal("expected string literal")
|
||||
self.fatal(~"expected string literal")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2821,8 +2823,8 @@ class parser {
|
||||
let expect_mod = vec::len(outer_attrs) > 0u;
|
||||
|
||||
let lo = self.span.lo;
|
||||
if expect_mod || self.is_keyword("mod") {
|
||||
self.expect_keyword("mod");
|
||||
if expect_mod || self.is_keyword(~"mod") {
|
||||
self.expect_keyword(~"mod");
|
||||
let id = self.parse_ident();
|
||||
alt self.token {
|
||||
// mod x = "foo.rs";
|
||||
@ -2849,7 +2851,7 @@ class parser {
|
||||
} else if self.is_view_item() {
|
||||
let vi = self.parse_view_item(outer_attrs);
|
||||
ret spanned(lo, vi.span.hi, cdir_view_item(vi));
|
||||
} else { ret self.fatal("expected crate directive"); }
|
||||
} else { ret self.fatal(~"expected crate directive"); }
|
||||
}
|
||||
|
||||
fn parse_crate_directives(term: token::token,
|
||||
@ -2860,7 +2862,7 @@ class parser {
|
||||
// accept seeing the terminator next, so if we do see it then fail the
|
||||
// same way parse_crate_directive would
|
||||
if vec::len(first_outer_attr) > 0u && self.token == term {
|
||||
self.expect_keyword("mod");
|
||||
self.expect_keyword(~"mod");
|
||||
}
|
||||
|
||||
let mut cdirs: ~[@crate_directive] = ~[];
|
||||
|
@ -100,61 +100,61 @@ enum whole_nt {
|
||||
w_mtcs(~[ast::matcher])
|
||||
}
|
||||
|
||||
fn binop_to_str(o: binop) -> str {
|
||||
fn binop_to_str(o: binop) -> ~str {
|
||||
alt o {
|
||||
PLUS { "+" }
|
||||
MINUS { "-" }
|
||||
STAR { "*" }
|
||||
SLASH { "/" }
|
||||
PERCENT { "%" }
|
||||
CARET { "^" }
|
||||
AND { "&" }
|
||||
OR { "|" }
|
||||
SHL { "<<" }
|
||||
SHR { ">>" }
|
||||
PLUS { ~"+" }
|
||||
MINUS { ~"-" }
|
||||
STAR { ~"*" }
|
||||
SLASH { ~"/" }
|
||||
PERCENT { ~"%" }
|
||||
CARET { ~"^" }
|
||||
AND { ~"&" }
|
||||
OR { ~"|" }
|
||||
SHL { ~"<<" }
|
||||
SHR { ~">>" }
|
||||
}
|
||||
}
|
||||
|
||||
fn to_str(in: interner<@str/~>, t: token) -> str {
|
||||
fn to_str(in: interner<@~str>, t: token) -> ~str {
|
||||
alt t {
|
||||
EQ { "=" }
|
||||
LT { "<" }
|
||||
LE { "<=" }
|
||||
EQEQ { "==" }
|
||||
NE { "!=" }
|
||||
GE { ">=" }
|
||||
GT { ">" }
|
||||
NOT { "!" }
|
||||
TILDE { "~" }
|
||||
OROR { "||" }
|
||||
ANDAND { "&&" }
|
||||
EQ { ~"=" }
|
||||
LT { ~"<" }
|
||||
LE { ~"<=" }
|
||||
EQEQ { ~"==" }
|
||||
NE { ~"!=" }
|
||||
GE { ~">=" }
|
||||
GT { ~">" }
|
||||
NOT { ~"!" }
|
||||
TILDE { ~"~" }
|
||||
OROR { ~"||" }
|
||||
ANDAND { ~"&&" }
|
||||
BINOP(op) { binop_to_str(op) }
|
||||
BINOPEQ(op) { binop_to_str(op) + "=" }
|
||||
BINOPEQ(op) { binop_to_str(op) + ~"=" }
|
||||
|
||||
/* Structural symbols */
|
||||
AT { "@" }
|
||||
DOT { "." }
|
||||
ELLIPSIS { "..." }
|
||||
COMMA { "," }
|
||||
SEMI { "" }
|
||||
COLON { ":" }
|
||||
MOD_SEP { "::" }
|
||||
RARROW { "->" }
|
||||
LARROW { "<-" }
|
||||
DARROW { "<->" }
|
||||
FAT_ARROW { "=>" }
|
||||
LPAREN { "(" }
|
||||
RPAREN { ")" }
|
||||
LBRACKET { "[" }
|
||||
RBRACKET { "]" }
|
||||
LBRACE { "{" }
|
||||
RBRACE { "}" }
|
||||
POUND { "#" }
|
||||
DOLLAR { "$" }
|
||||
AT { ~"@" }
|
||||
DOT { ~"." }
|
||||
ELLIPSIS { ~"..." }
|
||||
COMMA { ~"," }
|
||||
SEMI { ~"" }
|
||||
COLON { ~":" }
|
||||
MOD_SEP { ~"::" }
|
||||
RARROW { ~"->" }
|
||||
LARROW { ~"<-" }
|
||||
DARROW { ~"<->" }
|
||||
FAT_ARROW { ~"=>" }
|
||||
LPAREN { ~"(" }
|
||||
RPAREN { ~")" }
|
||||
LBRACKET { ~"[" }
|
||||
RBRACKET { ~"]" }
|
||||
LBRACE { ~"{" }
|
||||
RBRACE { ~"}" }
|
||||
POUND { ~"#" }
|
||||
DOLLAR { ~"$" }
|
||||
|
||||
/* Literals */
|
||||
LIT_INT(c, ast::ty_char) {
|
||||
"'" + char::escape_default(c as char) + "'"
|
||||
~"'" + char::escape_default(c as char) + ~"'"
|
||||
}
|
||||
LIT_INT(i, t) {
|
||||
int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t)
|
||||
@ -170,28 +170,28 @@ fn to_str(in: interner<@str/~>, t: token) -> str {
|
||||
ast_util::float_ty_to_str(t)
|
||||
}
|
||||
LIT_STR(s) {
|
||||
"\""
|
||||
~"\""
|
||||
+ str::escape_default(*interner::get(in, s))
|
||||
+ "\""
|
||||
+ ~"\""
|
||||
}
|
||||
|
||||
/* Name components */
|
||||
IDENT(s, _) {
|
||||
*interner::get(in, s)
|
||||
}
|
||||
UNDERSCORE { "_" }
|
||||
UNDERSCORE { ~"_" }
|
||||
|
||||
/* Other */
|
||||
DOC_COMMENT(s) { *interner::get(in, s) }
|
||||
EOF { "<eof>" }
|
||||
EOF { ~"<eof>" }
|
||||
ACTUALLY(w_nt) {
|
||||
"an interpolated " +
|
||||
~"an interpolated " +
|
||||
alt w_nt {
|
||||
w_item(*) { "item" } w_block(*) { "block" }
|
||||
w_stmt(*) { "statement" } w_pat(*) { "pattern" }
|
||||
w_expr(*) { "expression" } w_ty(*) { "type" }
|
||||
w_ident(*) { "identifier" } w_path(*) { "path" }
|
||||
w_tt(*) { "tt" } w_mtcs(*) { "matcher sequence" }
|
||||
w_item(*) { ~"item" } w_block(*) { ~"block" }
|
||||
w_stmt(*) { ~"statement" } w_pat(*) { ~"pattern" }
|
||||
w_expr(*) { ~"expression" } w_ty(*) { ~"type" }
|
||||
w_ident(*) { ~"identifier" } w_path(*) { ~"path" }
|
||||
w_tt(*) { ~"tt" } w_mtcs(*) { ~"matcher sequence" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,7 +256,7 @@ pure fn is_bar(t: token) -> bool {
|
||||
* the grammar is unambiguous. Restricted keywords may not appear
|
||||
* in positions that might otherwise contain _value identifiers_.
|
||||
*/
|
||||
fn keyword_table() -> hashmap<str, ()> {
|
||||
fn keyword_table() -> hashmap<~str, ()> {
|
||||
let keywords = str_hash();
|
||||
for contextual_keyword_table().each_key |word| {
|
||||
keywords.insert(word, ());
|
||||
@ -268,18 +268,18 @@ fn keyword_table() -> hashmap<str, ()> {
|
||||
}
|
||||
|
||||
/// Keywords that may be used as identifiers
|
||||
fn contextual_keyword_table() -> hashmap<str, ()> {
|
||||
fn contextual_keyword_table() -> hashmap<~str, ()> {
|
||||
let words = str_hash();
|
||||
let keys = ~[
|
||||
"as",
|
||||
"else",
|
||||
"move",
|
||||
"of",
|
||||
"priv", "pub",
|
||||
"self", "send", "static",
|
||||
"to",
|
||||
"use",
|
||||
"with"
|
||||
~"as",
|
||||
~"else",
|
||||
~"move",
|
||||
~"of",
|
||||
~"priv", ~"pub",
|
||||
~"self", ~"send", ~"static",
|
||||
~"to",
|
||||
~"use",
|
||||
~"with"
|
||||
];
|
||||
for keys.each |word| {
|
||||
words.insert(word, ());
|
||||
@ -301,23 +301,23 @@ fn contextual_keyword_table() -> hashmap<str, ()> {
|
||||
* * `true` or `false` as identifiers would always be shadowed by
|
||||
* the boolean constants
|
||||
*/
|
||||
fn restricted_keyword_table() -> hashmap<str, ()> {
|
||||
fn restricted_keyword_table() -> hashmap<~str, ()> {
|
||||
let words = str_hash();
|
||||
let keys = ~[
|
||||
"alt", "again", "assert",
|
||||
"break",
|
||||
"check", "claim", "class", "const", "copy",
|
||||
"do", "drop",
|
||||
"else", "enum", "export", "extern",
|
||||
"fail", "false", "fn", "for",
|
||||
"if", "iface", "impl", "import",
|
||||
"let", "log", "loop",
|
||||
"mod", "mut",
|
||||
"new",
|
||||
"pure", "ret",
|
||||
"true", "trait", "type",
|
||||
"unchecked", "unsafe",
|
||||
"while"
|
||||
~"alt", ~"again", ~"assert",
|
||||
~"break",
|
||||
~"check", ~"claim", ~"class", ~"const", ~"copy",
|
||||
~"do", ~"drop",
|
||||
~"else", ~"enum", ~"export", ~"extern",
|
||||
~"fail", ~"false", ~"fn", ~"for",
|
||||
~"if", ~"iface", ~"impl", ~"import",
|
||||
~"let", ~"log", ~"loop",
|
||||
~"mod", ~"mut",
|
||||
~"new",
|
||||
~"pure", ~"ret",
|
||||
~"true", ~"trait", ~"type",
|
||||
~"unchecked", ~"unsafe",
|
||||
~"while"
|
||||
];
|
||||
for keys.each |word| {
|
||||
words.insert(word, ());
|
||||
|
@ -59,33 +59,33 @@ type break_t = {offset: int, blank_space: int};
|
||||
|
||||
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 {
|
||||
STRING(s, len) { ret #fmt["STR(%s,%d)", *s, len]; }
|
||||
BREAK(_) { ret "BREAK"; }
|
||||
BEGIN(_) { ret "BEGIN"; }
|
||||
END { ret "END"; }
|
||||
EOF { ret "EOF"; }
|
||||
BREAK(_) { ret ~"BREAK"; }
|
||||
BEGIN(_) { ret ~"BEGIN"; }
|
||||
END { ret ~"END"; }
|
||||
EOF { ret ~"EOF"; }
|
||||
}
|
||||
}
|
||||
|
||||
fn buf_str(toks: ~[mut token], szs: ~[mut int], left: uint, right: uint,
|
||||
lim: uint) -> str {
|
||||
lim: uint) -> ~str {
|
||||
let n = vec::len(toks);
|
||||
assert (n == vec::len(szs));
|
||||
let mut i = left;
|
||||
let mut L = lim;
|
||||
let mut s = "[";
|
||||
let mut s = ~"[";
|
||||
while i != right && L != 0u {
|
||||
L -= 1u;
|
||||
if i != left { s += ", "; }
|
||||
if i != left { s += ~", "; }
|
||||
s += #fmt["%d=%s", szs[i], tok_str(toks[i])];
|
||||
i += 1u;
|
||||
i %= n;
|
||||
}
|
||||
s += "]";
|
||||
s += ~"]";
|
||||
ret s;
|
||||
}
|
||||
|
||||
@ -389,7 +389,7 @@ impl printer for printer {
|
||||
}
|
||||
fn print_newline(amount: int) {
|
||||
#debug("NEWLINE %d", amount);
|
||||
self.out.write_str("\n");
|
||||
self.out.write_str(~"\n");
|
||||
self.pending_indentation = 0;
|
||||
self.indent(amount);
|
||||
}
|
||||
@ -405,9 +405,9 @@ impl printer for printer {
|
||||
{offset: 0, pbreak: broken(inconsistent)}
|
||||
}
|
||||
}
|
||||
fn write_str(s: str) {
|
||||
fn write_str(s: ~str) {
|
||||
while self.pending_indentation > 0 {
|
||||
self.out.write_str(" ");
|
||||
self.out.write_str(~" ");
|
||||
self.pending_indentation -= 1;
|
||||
}
|
||||
self.out.write_str(s);
|
||||
@ -492,15 +492,15 @@ fn end(p: printer) { p.pretty_print(END); }
|
||||
|
||||
fn eof(p: printer) { p.pretty_print(EOF); }
|
||||
|
||||
fn word(p: printer, wrd: str) {
|
||||
fn word(p: printer, wrd: ~str) {
|
||||
p.pretty_print(STRING(@wrd, str::len(wrd) as int));
|
||||
}
|
||||
|
||||
fn huge_word(p: printer, wrd: str) {
|
||||
fn huge_word(p: printer, wrd: ~str) {
|
||||
p.pretty_print(STRING(@wrd, size_infinity));
|
||||
}
|
||||
|
||||
fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(@wrd, 0)); }
|
||||
fn zero_word(p: printer, wrd: ~str) { p.pretty_print(STRING(@wrd, 0)); }
|
||||
|
||||
fn spaces(p: printer, n: uint) { break_offset(p, n, 0); }
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user