Hi all. I've been interested in Rust, and thought I'd try making an XML
parser -- seems like a fairly simple task, and is the sort of thing Rust
should do.
I've only gotten as far as assembling a bunch of questions (admittedly I
have not even tried to compile the code). I'm sure at least one of the
questions will reveal a deep lack of understanding on my part... but though
I've read through most of the docs, I've started forgetting things that I've
read, so if I'm going to retain anything I need to try to write something.
So if you'll indulge me...
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.
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?
3. Is the difference between `for` and `for each` just iterating over a
vector/string or an iterator?
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.
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.
6. Is _str.eq() really the right way to do string equality?
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev