2011-12-20 16:15:49 -06:00
|
|
|
/* rustdoc: rust -> markdown translator
|
2011-12-20 16:19:46 -06:00
|
|
|
* Copyright 2011 Google Inc.
|
2011-12-20 15:52:04 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
use std;
|
|
|
|
use rustc;
|
|
|
|
|
|
|
|
import option;
|
|
|
|
import option::{some, none};
|
2012-01-13 19:33:16 -06:00
|
|
|
import rustc::driver::diagnostic;
|
2011-12-20 15:52:04 -06:00
|
|
|
import rustc::syntax::ast;
|
|
|
|
import rustc::syntax::codemap;
|
|
|
|
import rustc::syntax::parse::parser;
|
|
|
|
import rustc::syntax::print::pprust;
|
|
|
|
import rustc::syntax::visit;
|
|
|
|
import std::io;
|
2012-01-11 08:15:54 -06:00
|
|
|
import io::writer_util;
|
2011-12-20 15:52:04 -06:00
|
|
|
import std::map;
|
|
|
|
|
|
|
|
#[doc(
|
|
|
|
brief = "Documents a single crate item.",
|
|
|
|
args(rd = "Rustdoc context",
|
|
|
|
item = "AST item to document")
|
|
|
|
)]
|
2012-01-16 01:01:05 -06:00
|
|
|
fn doc_item(ctxt: gen::ctxt, item: @ast::item) {
|
2012-01-16 02:15:03 -06:00
|
|
|
let _fndoc0 = attr_parser::parse_fn(item.ident, item.id, item.attrs);
|
2011-12-20 15:52:04 -06:00
|
|
|
|
|
|
|
alt item.node {
|
|
|
|
ast::item_const(ty, expr) { }
|
2011-12-22 15:16:02 -06:00
|
|
|
ast::item_fn(decl, _, _) {
|
2012-01-16 01:01:05 -06:00
|
|
|
gen::write_fndoc(ctxt, item.ident, _fndoc0, decl);
|
2011-12-20 15:52:04 -06:00
|
|
|
}
|
|
|
|
ast::item_mod(_mod) { }
|
|
|
|
ast::item_ty(ty, typarams) { }
|
|
|
|
ast::item_tag(variant, typarams) { }
|
2011-12-22 15:16:02 -06:00
|
|
|
ast::item_res(_, _, _, _, _) { }
|
2011-12-20 15:52:04 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(
|
|
|
|
brief = "Main function.",
|
|
|
|
desc = "Command-line arguments:
|
|
|
|
|
|
|
|
* argv[1]: crate file name",
|
|
|
|
args(argv = "Command-line arguments.")
|
|
|
|
)]
|
|
|
|
fn main(argv: [str]) {
|
2011-12-30 17:26:49 -06:00
|
|
|
|
|
|
|
if vec::len(argv) != 2u {
|
2012-01-15 16:16:55 -06:00
|
|
|
io::println(#fmt("usage: %s <input>", argv[0]));
|
2011-12-30 17:26:49 -06:00
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2012-01-15 16:16:55 -06:00
|
|
|
let crate = parse::from_file(argv[1]);
|
|
|
|
|
|
|
|
let w = io::stdout();
|
2012-01-16 01:01:05 -06:00
|
|
|
let ctxt = { ps: pprust::rust_printer(w), w: w };
|
|
|
|
gen::write_header(ctxt, argv[1]);
|
2012-01-15 16:16:55 -06:00
|
|
|
|
2011-12-20 15:52:04 -06:00
|
|
|
let v = visit::mk_simple_visitor(@{
|
2012-01-16 01:01:05 -06:00
|
|
|
visit_item: bind doc_item(ctxt, _)
|
2011-12-20 15:52:04 -06:00
|
|
|
with *visit::default_simple_visitor()});
|
2012-01-15 16:16:55 -06:00
|
|
|
visit::visit_crate(*crate, (), v);
|
2011-12-20 15:52:04 -06:00
|
|
|
}
|