rustdoc: Extract doc nodes for native mods

This commit is contained in:
Brian Anderson 2012-02-24 13:50:40 -08:00
parent ba173d8409
commit fdea1c414c
3 changed files with 45 additions and 2 deletions

View file

@ -37,7 +37,7 @@ type moddoc = {
type nmoddoc = {
item: itemdoc,
fns: ~[fndoc]
fns: [fndoc]
};
type constdoc = {
@ -120,6 +120,15 @@ impl util for moddoc {
}
}
fn nmods() -> [nmoddoc] {
vec::filter_map(*self.items) {|itemtag|
alt itemtag {
nmodtag(nmoddoc) { some(nmoddoc) }
_ { none }
}
}
}
fn fns() -> [fndoc] {
vec::filter_map(*self.items) {|itemtag|
alt itemtag {

View file

@ -57,6 +57,11 @@ fn moddoc_from_mod(
moddoc_from_mod(itemdoc, m)
))
}
ast::item_native_mod(nm) {
some(doc::nmodtag(
nmoddoc_from_mod(itemdoc, nm)
))
}
ast::item_fn(decl, _, _) {
some(doc::fntag(
fndoc_from_fn(itemdoc, decl)
@ -100,6 +105,23 @@ fn moddoc_from_mod(
}
}
fn nmoddoc_from_mod(
itemdoc: doc::itemdoc,
module: ast::native_mod
) -> doc::nmoddoc {
{
item: itemdoc,
fns: vec::map(module.items) {|item|
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
ast::native_item_fn(decl, _) {
fndoc_from_fn(itemdoc, decl)
}
}
}
}
}
fn fndoc_from_fn(
itemdoc: doc::itemdoc,
decl: ast::fn_decl
@ -341,6 +363,18 @@ mod test {
assert doc.topmod.mods()[0].mods()[1].name() == "c";
}
#[test]
fn extract_native_mods() {
let doc = mk_doc("native mod a { }");
assert doc.topmod.nmods()[0].name() == "a";
}
#[test]
fn extract_fns_from_native_mods() {
let doc = mk_doc("native mod a { fn a(); }");
assert doc.topmod.nmods()[0].fns[0].name() == "a";
}
#[test]
fn extract_mods_deep() {
let doc = mk_doc("mod a { mod b { mod c { } } }");

View file

@ -154,7 +154,7 @@ fn default_seq_fold_nmod<T>(
) -> doc::nmoddoc {
{
item: fold.fold_item(fold, doc.item),
fns: ~vec::map(*doc.fns) {|fndoc|
fns: vec::map(doc.fns) {|fndoc|
fold.fold_fn(fold, fndoc)
}
with doc