2012-02-17 16:46:30 -06:00
|
|
|
// Some utility interfaces
|
2012-07-11 17:00:40 -05:00
|
|
|
import doc::item_utils;
|
2012-02-17 16:46:30 -06:00
|
|
|
import doc::item;
|
2012-01-28 16:36:35 -06:00
|
|
|
import doc::util;
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// A single operation on the document model
|
2012-02-27 20:07:16 -06:00
|
|
|
type pass = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~str,
|
2012-03-02 20:33:25 -06:00
|
|
|
f: fn~(srv: astsrv::srv, doc: doc::doc) -> doc::doc
|
2012-02-27 20:07:16 -06:00
|
|
|
};
|
2012-01-16 20:08:17 -06:00
|
|
|
|
|
|
|
fn run_passes(
|
2012-01-17 18:12:31 -06:00
|
|
|
srv: astsrv::srv,
|
2012-03-02 20:33:25 -06:00
|
|
|
doc: doc::doc,
|
2012-06-29 18:26:56 -05:00
|
|
|
passes: ~[pass]
|
2012-03-02 20:33:25 -06:00
|
|
|
) -> doc::doc {
|
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-03-22 10:39:41 -05:00
|
|
|
let mut passno = 0;
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::foldl(doc, passes) |doc, pass| {
|
2012-07-30 18:01:07 -05:00
|
|
|
log(debug, fmt!{"pass #%d", passno});
|
2012-01-25 22:55:55 -06:00
|
|
|
passno += 1;
|
|
|
|
log(debug, doc);
|
2012-07-04 14:04:28 -05:00
|
|
|
do time(pass.name) {
|
2012-02-27 20:07:16 -06:00
|
|
|
pass.f(srv, doc)
|
|
|
|
}
|
2012-01-16 20:08:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_run_passes() {
|
|
|
|
fn pass1(
|
2012-01-17 18:12:31 -06:00
|
|
|
_srv: astsrv::srv,
|
2012-03-02 20:33:25 -06:00
|
|
|
doc: doc::doc
|
|
|
|
) -> doc::doc {
|
2012-07-11 17:00:40 -05:00
|
|
|
doc::doc_({
|
2012-06-29 18:26:56 -05:00
|
|
|
pages: ~[
|
2012-03-02 20:33:25 -06:00
|
|
|
doc::cratepage({
|
2012-07-11 17:00:40 -05:00
|
|
|
topmod: doc::moddoc_({
|
2012-03-02 20:33:25 -06:00
|
|
|
item: {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: doc.cratemod().name() + ~"two"
|
2012-03-02 20:33:25 -06:00
|
|
|
with doc.cratemod().item
|
|
|
|
},
|
2012-06-29 18:26:56 -05:00
|
|
|
items: ~[],
|
2012-03-02 20:33:25 -06:00
|
|
|
index: none
|
2012-07-11 17:00:40 -05:00
|
|
|
})
|
2012-03-02 20:33:25 -06:00
|
|
|
})
|
2012-06-29 18:26:56 -05:00
|
|
|
]
|
2012-07-11 17:00:40 -05:00
|
|
|
})
|
2012-01-16 20:08:17 -06:00
|
|
|
}
|
|
|
|
fn pass2(
|
2012-01-17 18:12:31 -06:00
|
|
|
_srv: astsrv::srv,
|
2012-03-02 20:33:25 -06:00
|
|
|
doc: doc::doc
|
|
|
|
) -> doc::doc {
|
2012-07-11 17:00:40 -05:00
|
|
|
doc::doc_({
|
2012-06-29 18:26:56 -05:00
|
|
|
pages: ~[
|
2012-03-02 20:33:25 -06:00
|
|
|
doc::cratepage({
|
2012-07-11 17:00:40 -05:00
|
|
|
topmod: doc::moddoc_({
|
2012-03-02 20:33:25 -06:00
|
|
|
item: {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: doc.cratemod().name() + ~"three"
|
2012-03-02 20:33:25 -06:00
|
|
|
with doc.cratemod().item
|
|
|
|
},
|
2012-06-29 18:26:56 -05:00
|
|
|
items: ~[],
|
2012-03-02 20:33:25 -06:00
|
|
|
index: none
|
2012-07-11 17:00:40 -05:00
|
|
|
})
|
2012-03-02 20:33:25 -06:00
|
|
|
})
|
2012-06-29 18:26:56 -05:00
|
|
|
]
|
2012-07-11 17:00:40 -05:00
|
|
|
})
|
2012-01-16 20:08:17 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
let source = ~"";
|
2012-06-30 18:19:07 -05:00
|
|
|
do astsrv::from_str(source) |srv| {
|
2012-06-29 18:26:56 -05:00
|
|
|
let passes = ~[
|
2012-02-27 20:07:16 -06:00
|
|
|
{
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"",
|
2012-02-27 20:07:16 -06:00
|
|
|
f: pass1
|
|
|
|
},
|
|
|
|
{
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~"",
|
2012-02-27 20:07:16 -06:00
|
|
|
f: pass2
|
|
|
|
}
|
2012-06-29 18:26:56 -05:00
|
|
|
];
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = extract::from_srv(srv, ~"one");
|
2012-02-20 23:08:19 -06:00
|
|
|
let doc = run_passes(srv, doc, passes);
|
2012-07-14 00:57:48 -05:00
|
|
|
assert doc.cratemod().name() == ~"onetwothree";
|
2012-02-20 23:08:19 -06:00
|
|
|
}
|
2012-01-16 20:08:17 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn main(args: ~[~str]) {
|
2011-12-30 17:26:49 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if vec::contains(args, ~"-h") {
|
2012-02-28 23:27:38 -06:00
|
|
|
config::usage();
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2012-02-28 23:31:55 -06:00
|
|
|
let config = alt config::parse_config(args) {
|
|
|
|
result::ok(config) { config }
|
|
|
|
result::err(err) {
|
2012-07-30 18:01:07 -05:00
|
|
|
io::println(fmt!{"error: %s", err});
|
2011-12-30 17:26:49 -06:00
|
|
|
ret;
|
2012-02-28 23:31:55 -06:00
|
|
|
}
|
|
|
|
};
|
2011-12-30 17:26:49 -06:00
|
|
|
|
2012-02-29 20:10:40 -06:00
|
|
|
run(config);
|
2012-01-16 20:21:34 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn time<T>(what: ~str, f: fn() -> T) -> T {
|
2012-02-27 20:07:16 -06:00
|
|
|
let start = std::time::precise_time_s();
|
|
|
|
let rv = f();
|
|
|
|
let end = std::time::precise_time_s();
|
2012-07-30 18:01:07 -05:00
|
|
|
info!{"time: %3.3f s %s", end - start, what};
|
2012-02-27 20:07:16 -06:00
|
|
|
ret rv;
|
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Runs rustdoc over the given file
|
2012-02-29 20:10:40 -06:00
|
|
|
fn run(config: config::config) {
|
2012-01-16 20:21:34 -06:00
|
|
|
|
2012-02-29 20:10:40 -06:00
|
|
|
let source_file = config.input_crate;
|
2012-06-30 18:19:07 -05:00
|
|
|
do astsrv::from_file(source_file) |srv| {
|
2012-07-14 00:57:48 -05:00
|
|
|
do time(~"wait_ast") {
|
2012-06-30 18:19:07 -05:00
|
|
|
do astsrv::exec(srv) |_ctxt| { }
|
2012-02-27 20:07:16 -06:00
|
|
|
};
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = time(~"extract", || {
|
2012-02-29 20:10:40 -06:00
|
|
|
let default_name = source_file;
|
2012-02-27 20:07:16 -06:00
|
|
|
extract::from_srv(srv, default_name)
|
2012-06-26 15:55:56 -05:00
|
|
|
});
|
2012-06-29 18:26:56 -05:00
|
|
|
run_passes(srv, doc, ~[
|
2012-02-20 23:08:19 -06:00
|
|
|
tystr_pass::mk_pass(),
|
|
|
|
path_pass::mk_pass(),
|
|
|
|
attr_pass::mk_pass(),
|
2012-03-16 14:20:29 -05:00
|
|
|
escape_pass::mk_pass(),
|
2012-03-07 16:49:52 -06:00
|
|
|
prune_hidden_pass::mk_pass(),
|
2012-02-20 23:08:19 -06:00
|
|
|
desc_to_brief_pass::mk_pass(),
|
|
|
|
unindent_pass::mk_pass(),
|
2012-03-09 13:47:31 -06:00
|
|
|
sectionalize_pass::mk_pass(),
|
|
|
|
trim_pass::mk_pass(),
|
2012-02-20 23:08:19 -06:00
|
|
|
sort_item_name_pass::mk_pass(),
|
|
|
|
sort_item_type_pass::mk_pass(),
|
2012-03-06 17:57:36 -06:00
|
|
|
markdown_index_pass::mk_pass(config),
|
2012-03-06 16:07:34 -06:00
|
|
|
page_pass::mk_pass(config.output_style),
|
2012-03-04 01:20:40 -06:00
|
|
|
markdown_pass::mk_pass(
|
2012-03-04 01:56:38 -06:00
|
|
|
markdown_writer::make_writer_factory(config)
|
2012-03-04 01:20:40 -06:00
|
|
|
)
|
2012-06-29 18:26:56 -05:00
|
|
|
]);
|
2012-02-20 23:08:19 -06:00
|
|
|
}
|
2012-06-25 22:00:46 -05:00
|
|
|
}
|