On 11/15/10 12:12 PM, Ian Bicking wrote:
1. Is the best way to handle expected errors (like a parse error) to use
a tag return type? I'm thinking like:
type xml = rec(...);
type xml_error = rec(str message, int position);
tag xmlerr {
xml;
xml_error;
}
fn parse_xml(str input) -> xmlerr {
}
? I'm confused about something with tags, but I can't quite figure out
what... looking through uses of tag in docs and source I can't figure
out what it should be.
I'd recommend just failing on parse errors. If someone wants to catch
the error they can always spawn a task to do the XML parsing (when that
works). Given the draconian error handling mandated by the XML spec, I'd
think that, most of the time, an XML parse error is something that can't
be sensibly handled except at a coarse-grained level.
2. Is there a way to return a record without declaring it? I only see
how to do:
xml_error err = rec(message="< expected", pos=0);
ret err;
But it seems like I need that `err` variable?
You shouldn't. If you do, that's a bug!
4. I see references to _vec.len[T](), which seems... complex. So would
I really do _vec.len[xml](children) to get a length? What about string
length? I'm only finding references to the byte length of strings, not
the character length.
Yeah, it's a bummer. Maybe we should have a length operator a la Lua.
5. There's lots of cases in parsing where an error or a success can be
returned by a routine; I almost always just want to pass the error up
when I encounter it, but the only way I can see to do that is to do a
complete `alt type` condition on success or error. For instance:
let attrs = parse_attrs(input, pos);
alt type (attrs) {
case (xml_error err) {
ret err;
}
}
... now I know it wasn't an error and can continue...?
Anyway, just wondering if there's a quicker way.
Failure is the quicker way. If a caller of your library wants to be able
to catch errors sensibly, they can always spawn a task to do the XML
parsing. Tasks are cheap, use 'em :)
6. Is _str.eq() really the right way to do string equality?
No (we intend == to work), but it's the only way that works right now :)
Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev