rustdoc: Rename type rustdoc to gen::ctxt

This commit is contained in:
Brian Anderson 2012-01-15 23:01:05 -08:00
parent 906a7c2174
commit 7a9ba240a0
2 changed files with 19 additions and 24 deletions

View File

@ -1,4 +1,4 @@
type rustdoc = { type ctxt = {
ps: pprust::ps, ps: pprust::ps,
w: io::writer w: io::writer
}; };
@ -8,8 +8,8 @@ type rustdoc = {
args(rd = "Rustdoc context", args(rd = "Rustdoc context",
name = "Crate name") name = "Crate name")
)] )]
fn write_header(rd: rustdoc, name: str) { fn write_header(ctxt: ctxt, name: str) {
rd.w.write_line("# Crate " + name); ctxt.w.write_line("# Crate " + name);
} }
#[doc( #[doc(
@ -19,30 +19,30 @@ fn write_header(rd: rustdoc, name: str) {
doc = "Function docs extracted from attributes", doc = "Function docs extracted from attributes",
_fn = "AST object representing this function") _fn = "AST object representing this function")
)] )]
fn write_fndoc(rd: rustdoc, ident: str, doc: doc::fndoc, decl: ast::fn_decl) { fn write_fndoc(ctxt: ctxt, ident: str, doc: doc::fndoc, decl: ast::fn_decl) {
rd.w.write_line("## Function `" + ident + "`"); ctxt.w.write_line("## Function `" + ident + "`");
rd.w.write_line(doc.brief); ctxt.w.write_line(doc.brief);
alt doc.desc { alt doc.desc {
some(_d) { some(_d) {
rd.w.write_line(""); ctxt.w.write_line("");
rd.w.write_line(_d); ctxt.w.write_line(_d);
rd.w.write_line(""); ctxt.w.write_line("");
} }
none. { } none. { }
} }
for arg: ast::arg in decl.inputs { for arg: ast::arg in decl.inputs {
rd.w.write_str("### Argument `" + arg.ident + "`: "); ctxt.w.write_str("### Argument `" + arg.ident + "`: ");
rd.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`"); ctxt.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`");
alt doc.args.find(arg.ident) { alt doc.args.find(arg.ident) {
some(_d) { some(_d) {
rd.w.write_line(_d); ctxt.w.write_line(_d);
} }
none. { } none. { }
}; };
} }
rd.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`"); ctxt.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`");
alt doc.return { alt doc.return {
some(_r) { rd.w.write_line(_r); } some(_r) { ctxt.w.write_line(_r); }
none. { } none. { }
} }
} }

View File

@ -17,23 +17,18 @@ import std::io;
import io::writer_util; import io::writer_util;
import std::map; import std::map;
type rustdoc = {
ps: pprust::ps,
w: io::writer
};
#[doc( #[doc(
brief = "Documents a single crate item.", brief = "Documents a single crate item.",
args(rd = "Rustdoc context", args(rd = "Rustdoc context",
item = "AST item to document") item = "AST item to document")
)] )]
fn doc_item(rd: rustdoc, item: @ast::item) { fn doc_item(ctxt: gen::ctxt, item: @ast::item) {
let _fndoc0 = attr_parser::parse_fn(item.ident, item.attrs); let _fndoc0 = attr_parser::parse_fn(item.ident, item.attrs);
alt item.node { alt item.node {
ast::item_const(ty, expr) { } ast::item_const(ty, expr) { }
ast::item_fn(decl, _, _) { ast::item_fn(decl, _, _) {
gen::write_fndoc(rd, item.ident, _fndoc0, decl); gen::write_fndoc(ctxt, item.ident, _fndoc0, decl);
} }
ast::item_mod(_mod) { } ast::item_mod(_mod) { }
ast::item_ty(ty, typarams) { } ast::item_ty(ty, typarams) { }
@ -59,11 +54,11 @@ fn main(argv: [str]) {
let crate = parse::from_file(argv[1]); let crate = parse::from_file(argv[1]);
let w = io::stdout(); let w = io::stdout();
let rd = { ps: pprust::rust_printer(w), w: w }; let ctxt = { ps: pprust::rust_printer(w), w: w };
gen::write_header(rd, argv[1]); gen::write_header(ctxt, argv[1]);
let v = visit::mk_simple_visitor(@{ let v = visit::mk_simple_visitor(@{
visit_item: bind doc_item(rd, _) visit_item: bind doc_item(ctxt, _)
with *visit::default_simple_visitor()}); with *visit::default_simple_visitor()});
visit::visit_crate(*crate, (), v); visit::visit_crate(*crate, (), v);
} }