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
|
|
|
*/
|
|
|
|
|
2012-01-28 16:36:35 -06:00
|
|
|
import doc::util;
|
|
|
|
|
2012-01-17 19:44:32 -06:00
|
|
|
#[doc = "A single operation on the document model"]
|
2012-01-17 18:12:31 -06:00
|
|
|
type pass = fn~(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc;
|
2012-01-16 20:08:17 -06:00
|
|
|
|
|
|
|
fn run_passes(
|
2012-01-17 18:12:31 -06:00
|
|
|
srv: astsrv::srv,
|
2012-01-16 20:08:17 -06:00
|
|
|
doc: doc::cratedoc,
|
|
|
|
passes: [pass]
|
|
|
|
) -> doc::cratedoc {
|
2012-01-18 16:06:22 -06:00
|
|
|
|
2012-01-19 01:11:20 -06:00
|
|
|
#[doc(
|
|
|
|
brief =
|
|
|
|
"Run a series of passes over the document",
|
|
|
|
args(
|
|
|
|
srv =
|
|
|
|
"The AST service to provide to the passes",
|
|
|
|
doc =
|
|
|
|
"The document to transform",
|
|
|
|
passes =
|
|
|
|
"The list of passes used to transform the document"
|
|
|
|
),
|
|
|
|
return =
|
|
|
|
"The transformed document that results from folding the \
|
|
|
|
original through each pass"
|
|
|
|
)];
|
2012-01-18 16:06:22 -06:00
|
|
|
|
2012-01-25 22:55:55 -06:00
|
|
|
let passno = 0;
|
2012-01-16 20:08:17 -06:00
|
|
|
vec::foldl(doc, passes) {|doc, pass|
|
2012-01-25 22:55:55 -06:00
|
|
|
log(debug, #fmt("pass #%d", passno));
|
|
|
|
passno += 1;
|
|
|
|
log(debug, doc);
|
2012-01-16 20:08:17 -06:00
|
|
|
pass(srv, doc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_run_passes() {
|
|
|
|
fn pass1(
|
2012-01-17 18:12:31 -06:00
|
|
|
_srv: astsrv::srv,
|
2012-01-16 20:08:17 -06:00
|
|
|
doc: doc::cratedoc
|
|
|
|
) -> doc::cratedoc {
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
|
|
|
topmod: {
|
2012-01-18 20:35:55 -06:00
|
|
|
id: 0,
|
2012-01-16 20:08:17 -06:00
|
|
|
name: doc.topmod.name + "two",
|
2012-01-19 01:23:10 -06:00
|
|
|
path: [],
|
2012-01-18 20:11:26 -06:00
|
|
|
brief: none,
|
|
|
|
desc: none,
|
2012-01-30 15:05:25 -06:00
|
|
|
items: ~[]
|
2012-01-16 20:08:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn pass2(
|
2012-01-17 18:12:31 -06:00
|
|
|
_srv: astsrv::srv,
|
2012-01-16 20:08:17 -06:00
|
|
|
doc: doc::cratedoc
|
|
|
|
) -> doc::cratedoc {
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
|
|
|
topmod: {
|
2012-01-18 20:35:55 -06:00
|
|
|
id: 0,
|
2012-01-16 20:08:17 -06:00
|
|
|
name: doc.topmod.name + "three",
|
2012-01-19 01:23:10 -06:00
|
|
|
path: [],
|
2012-01-18 20:11:26 -06:00
|
|
|
brief: none,
|
|
|
|
desc: none,
|
2012-01-30 15:05:25 -06:00
|
|
|
items: ~[]
|
2012-01-16 20:08:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let source = "";
|
2012-01-17 18:12:31 -06:00
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
2012-01-16 20:08:17 -06:00
|
|
|
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
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:22:03 -06:00
|
|
|
#[doc = "Runs rustdoc over the given file"]
|
2012-01-16 20:21:34 -06:00
|
|
|
fn run(source_file: str) {
|
|
|
|
|
2012-01-16 03:03:41 -06:00
|
|
|
let default_name = source_file;
|
2012-01-17 18:12:31 -06:00
|
|
|
let srv = astsrv::mk_srv_from_file(source_file);
|
2012-01-16 20:21:34 -06:00
|
|
|
let doc = extract::from_srv(srv, default_name);
|
2012-01-17 18:12:50 -06:00
|
|
|
run_passes(srv, doc, [
|
2012-01-23 21:23:02 -06:00
|
|
|
prune_unexported_pass::mk_pass(),
|
2012-01-19 16:12:40 -06:00
|
|
|
tystr_pass::mk_pass(),
|
2012-01-19 01:48:25 -06:00
|
|
|
path_pass::mk_pass(),
|
2012-01-19 16:12:40 -06:00
|
|
|
attr_pass::mk_pass(),
|
2012-01-31 23:52:30 -06:00
|
|
|
prune_undoc_details_pass::mk_pass(),
|
2012-01-17 00:50:00 -06:00
|
|
|
// FIXME: This pass should be optional
|
2012-01-31 23:52:30 -06:00
|
|
|
// prune_undoc_items_pass::mk_pass(),
|
2012-01-24 19:19:27 -06:00
|
|
|
desc_to_brief_pass::mk_pass(),
|
2012-01-24 19:40:22 -06:00
|
|
|
trim_pass::mk_pass(),
|
2012-01-25 00:02:36 -06:00
|
|
|
unindent_pass::mk_pass(),
|
2012-02-03 14:00:49 -06:00
|
|
|
sort_item_name_pass::mk_pass(),
|
|
|
|
sort_item_type_pass::mk_pass(),
|
2012-01-29 16:51:09 -06:00
|
|
|
markdown_pass::mk_pass {|f| f(std::io:: stdout()) }
|
2012-01-16 20:21:34 -06:00
|
|
|
]);
|
|
|
|
}
|