提交 23e9f7a1 编写于 作者: B Brian Anderson

rustdoc: Extract resources from the AST

上级 7cf72535
......@@ -16,7 +16,7 @@
fns: fnlist,
consts: constlist,
enums: enumlist,
resources: resourcelist
resources: reslist
};
type constdoc = ~{
......@@ -63,7 +63,7 @@
sig: option<str>
};
type resourcedoc = ~{
type resdoc = ~{
id: ast_id,
name: str,
brief: option<str>,
......@@ -77,4 +77,4 @@
enum constlist = [constdoc];
enum fnlist = [fndoc];
enum enumlist = [enumdoc];
enum resourcelist = [resourcedoc];
enum reslist = [resdoc];
......@@ -88,7 +88,17 @@ fn moddoc_from_mod(
}
}
}),
resources: doc::resourcelist([])
resources: doc::reslist(
vec::filter_map(module.items) {|item|
alt item.node {
ast::item_res(_, _, _, _, _) {
some(resdoc_from_resource(item.ident, item.id))
}
_ {
none
}
}
})
}
}
......@@ -201,6 +211,29 @@ fn should_extract_enum_variants() {
assert doc.topmod.enums[0].variants[0].name == "v";
}
fn resdoc_from_resource(
name: str,
id: ast::node_id
) -> doc::resdoc {
~{
id: id,
name: name,
brief: none,
desc: none,
args: [],
sig: none
}
}
#[test]
fn should_extract_resources() {
let source = "resource r(b: bool) { }";
let ast = parse::from_str(source);
let doc = extract(ast, "");
assert doc.topmod.resources[0].id != 0;
assert doc.topmod.resources[0].name == "r";
}
#[cfg(test)]
mod tests {
......
......@@ -53,7 +53,7 @@ fn pass1(
fns: doc::fnlist([]),
consts: doc::constlist([]),
enums: doc::enumlist([]),
resources: doc::resourcelist([])
resources: doc::reslist([])
}
}
}
......@@ -72,7 +72,7 @@ fn pass2(
fns: doc::fnlist([]),
consts: doc::constlist([]),
enums: doc::enumlist([]),
resources: doc::resourcelist([])
resources: doc::reslist([])
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册