Accept prefix notation for writing the types of str/~ and friends.

This commit is contained in:
Michael Sullivan 2012-07-11 23:42:26 -07:00
parent acb86921a6
commit 2ea9c8df0f
37 changed files with 198 additions and 147 deletions

View file

@ -29,7 +29,7 @@ export null;
/// Represents a json value
enum json {
num(float),
string(@str),
string(@str/~),
boolean(bool),
list(@~[json]),
dict(map::hashmap<str, json>),
@ -39,7 +39,7 @@ enum json {
type error = {
line: uint,
col: uint,
msg: @str,
msg: @str/~,
};
/// Serializes a json value into a io::writer
@ -324,7 +324,7 @@ 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 = "";
@ -579,7 +579,7 @@ 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) }
}

View file

@ -310,8 +310,8 @@ fn str_hash<V: copy>() -> hashmap<str, V> {
}
/// 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

View file

@ -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({