1
Fork 0

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 = { type nmoddoc = {
item: itemdoc, item: itemdoc,
fns: ~[fndoc] fns: [fndoc]
}; };
type constdoc = { 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] { fn fns() -> [fndoc] {
vec::filter_map(*self.items) {|itemtag| vec::filter_map(*self.items) {|itemtag|
alt itemtag { alt itemtag {

View file

@ -57,6 +57,11 @@ fn moddoc_from_mod(
moddoc_from_mod(itemdoc, m) moddoc_from_mod(itemdoc, m)
)) ))
} }
ast::item_native_mod(nm) {
some(doc::nmodtag(
nmoddoc_from_mod(itemdoc, nm)
))
}
ast::item_fn(decl, _, _) { ast::item_fn(decl, _, _) {
some(doc::fntag( some(doc::fntag(
fndoc_from_fn(itemdoc, decl) 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( fn fndoc_from_fn(
itemdoc: doc::itemdoc, itemdoc: doc::itemdoc,
decl: ast::fn_decl decl: ast::fn_decl
@ -341,6 +363,18 @@ mod test {
assert doc.topmod.mods()[0].mods()[1].name() == "c"; 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] #[test]
fn extract_mods_deep() { fn extract_mods_deep() {
let doc = mk_doc("mod a { mod b { mod c { } } }"); let doc = mk_doc("mod a { mod b { mod c { } } }");

View file

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