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;
|
|
|
|
|
2012-01-16 20:08:17 -06:00
|
|
|
type pass = fn~(srv: astsrv::seq_srv, doc: doc::cratedoc) -> doc::cratedoc;
|
|
|
|
|
|
|
|
fn run_passes(
|
|
|
|
srv: astsrv::seq_srv,
|
|
|
|
doc: doc::cratedoc,
|
|
|
|
passes: [pass]
|
|
|
|
) -> doc::cratedoc {
|
|
|
|
vec::foldl(doc, passes) {|doc, pass|
|
|
|
|
pass(srv, doc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_run_passes() {
|
|
|
|
import astsrv::seq_srv;
|
|
|
|
fn pass1(
|
|
|
|
_srv: astsrv::seq_srv,
|
|
|
|
doc: doc::cratedoc
|
|
|
|
) -> doc::cratedoc {
|
|
|
|
~{
|
|
|
|
topmod: ~{
|
|
|
|
name: doc.topmod.name + "two",
|
|
|
|
mods: doc::modlist([]),
|
|
|
|
fns: doc::fnlist([])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn pass2(
|
|
|
|
_srv: astsrv::seq_srv,
|
|
|
|
doc: doc::cratedoc
|
|
|
|
) -> doc::cratedoc {
|
|
|
|
~{
|
|
|
|
topmod: ~{
|
|
|
|
name: doc.topmod.name + "three",
|
|
|
|
mods: doc::modlist([]),
|
|
|
|
fns: doc::fnlist([])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let source = "";
|
|
|
|
let srv = astsrv::mk_seq_srv_from_str(source);
|
|
|
|
let passes = [pass1, pass2];
|
|
|
|
let doc = extract::from_srv(srv, "one");
|
|
|
|
let doc = run_passes(srv, doc, passes);
|
|
|
|
assert doc.topmod.name == "onetwothree";
|
|
|
|
}
|
|
|
|
|
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-16 15:22:25 -06:00
|
|
|
std::io::println(#fmt("usage: %s <input>", argv[0]));
|
2011-12-30 17:26:49 -06:00
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2012-01-16 03:03:41 -06:00
|
|
|
let source_file = argv[1];
|
2012-01-16 20:21:34 -06:00
|
|
|
run(source_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(source_file: str) {
|
|
|
|
|
2012-01-16 03:03:41 -06:00
|
|
|
let default_name = source_file;
|
2012-01-16 20:21:34 -06:00
|
|
|
let srv = astsrv::mk_seq_srv_from_file(source_file);
|
|
|
|
let doc = extract::from_srv(srv, default_name);
|
|
|
|
let doc = run_passes(srv, doc, [
|
2012-01-16 21:39:53 -06:00
|
|
|
attr_pass::run,
|
2012-01-17 00:50:00 -06:00
|
|
|
// FIXME: This pass should be optional
|
|
|
|
prune_undoc_pass::run,
|
2012-01-16 20:21:34 -06:00
|
|
|
tystr_pass::run
|
|
|
|
]);
|
2012-01-16 17:38:40 -06:00
|
|
|
gen::write_markdown(doc, std::io::stdout());
|
2012-01-16 20:21:34 -06:00
|
|
|
}
|