From 0e65ddfaea1c25c0fb2f20a2d28ed782c1dff369 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 15 Jan 2012 14:16:55 -0800 Subject: [PATCH] rustdoc: Move AST parsing into the parse module --- src/rustdoc/rustdoc.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index 1635d1062fd..abcc5cb6358 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -177,6 +177,18 @@ fn doc_header(rd: rustdoc, name: str) { rd.w.write_line("# Crate " + name); } +mod parse { + fn from_file(file: str) -> @ast::crate { + let cm = codemap::new_codemap(); + let sess = @{ + cm: cm, + mutable next_id: 0, + diagnostic: diagnostic::mk_handler(cm, none) + }; + parser::parse_crate_from_source_file(file, [], sess) + } +} + #[doc( brief = "Main function.", desc = "Command-line arguments: @@ -184,27 +196,21 @@ fn doc_header(rd: rustdoc, name: str) { * argv[1]: crate file name", args(argv = "Command-line arguments.") )] - fn main(argv: [str]) { - let w = io::stdout(); - if vec::len(argv) != 2u { - w.write_str(#fmt("usage: %s \n", argv[0])); + io::println(#fmt("usage: %s ", argv[0])); ret; } - let cm = codemap::new_codemap(); - let sess = @{ - cm: cm, - mutable next_id: 0, - diagnostic: diagnostic::mk_handler(cm, none) - }; + let crate = parse::from_file(argv[1]); + + let w = io::stdout(); let rd = { ps: pprust::rust_printer(w), w: w }; doc_header(rd, argv[1]); - let p = parser::parse_crate_from_source_file(argv[1], [], sess); + let v = visit::mk_simple_visitor(@{ visit_item: bind doc_item(rd, _) with *visit::default_simple_visitor()}); - visit::visit_crate(*p, (), v); + visit::visit_crate(*crate, (), v); }