diff --git a/src/rustdoc/gen.rs b/src/rustdoc/gen.rs new file mode 100644 index 00000000000..e53bb15a9c7 --- /dev/null +++ b/src/rustdoc/gen.rs @@ -0,0 +1,43 @@ +#[doc( + brief = "Generate a crate document header.", + args(rd = "Rustdoc context", + name = "Crate name") +)] +fn write_header(rd: rustdoc, name: str) { + rd.w.write_line("# Crate " + name); +} + +#[doc( + brief = "Documents a single function.", + args(rd = "Rustdoc context", + ident = "Identifier for this function", + doc = "Function docs extracted from attributes", + _fn = "AST object representing this function") +)] +fn write_fndoc(rd: rustdoc, ident: str, doc: doc::fndoc, decl: ast::fn_decl) { + rd.w.write_line("## Function `" + ident + "`"); + rd.w.write_line(doc.brief); + alt doc.desc { + some(_d) { + rd.w.write_line(""); + rd.w.write_line(_d); + rd.w.write_line(""); + } + none. { } + } + for arg: ast::arg in decl.inputs { + rd.w.write_str("### Argument `" + arg.ident + "`: "); + rd.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`"); + alt doc.args.find(arg.ident) { + some(_d) { + rd.w.write_line(_d); + } + none. { } + }; + } + rd.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`"); + alt doc.return { + some(_r) { rd.w.write_line(_r); } + none. { } + } +} diff --git a/src/rustdoc/rustdoc.rc b/src/rustdoc/rustdoc.rc index 390ba33a55e..3f482740852 100644 --- a/src/rustdoc/rustdoc.rc +++ b/src/rustdoc/rustdoc.rc @@ -8,4 +8,5 @@ #[crate_type = "bin"]; mod parse; -mod doc; \ No newline at end of file +mod doc; +mod gen; \ No newline at end of file diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index 1f30fb4302e..2e53155f06c 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -22,41 +22,6 @@ type rustdoc = { w: io::writer }; -#[doc( - brief = "Documents a single function.", - args(rd = "Rustdoc context", - ident = "Identifier for this function", - doc = "Function docs extracted from attributes", - _fn = "AST object representing this function") -)] -fn doc_fn(rd: rustdoc, ident: str, doc: doc::fndoc, decl: ast::fn_decl) { - rd.w.write_line("## Function `" + ident + "`"); - rd.w.write_line(doc.brief); - alt doc.desc { - some(_d) { - rd.w.write_line(""); - rd.w.write_line(_d); - rd.w.write_line(""); - } - none. { } - } - for arg: ast::arg in decl.inputs { - rd.w.write_str("### Argument `" + arg.ident + "`: "); - rd.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`"); - alt doc.args.find(arg.ident) { - some(_d) { - rd.w.write_line(_d); - } - none. { } - }; - } - rd.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`"); - alt doc.return { - some(_r) { rd.w.write_line(_r); } - none. { } - } -} - #[doc( brief = "Parses function docs from a complex #[doc] attribute.", desc = "Supported attributes: @@ -152,7 +117,7 @@ fn doc_item(rd: rustdoc, item: @ast::item) { alt item.node { ast::item_const(ty, expr) { } ast::item_fn(decl, _, _) { - doc_fn(rd, item.ident, _fndoc0, decl); + gen::write_fndoc(rd, item.ident, _fndoc0, decl); } ast::item_mod(_mod) { } ast::item_ty(ty, typarams) { } @@ -161,15 +126,6 @@ fn doc_item(rd: rustdoc, item: @ast::item) { }; } -#[doc( - brief = "Generate a crate document header.", - args(rd = "Rustdoc context", - name = "Crate name") -)] -fn doc_header(rd: rustdoc, name: str) { - rd.w.write_line("# Crate " + name); -} - #[doc( brief = "Main function.", desc = "Command-line arguments: @@ -188,7 +144,7 @@ fn main(argv: [str]) { let w = io::stdout(); let rd = { ps: pprust::rust_printer(w), w: w }; - doc_header(rd, argv[1]); + gen::write_header(rd, argv[1]); let v = visit::mk_simple_visitor(@{ visit_item: bind doc_item(rd, _)