diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-01-18 23:48:25 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-01-19 00:04:59 -0800 |
| commit | a5e0f037be17204c640e2941e576a9dca09efc90 (patch) | |
| tree | 7680033969abfcdac62464c75104ce823aaca6e4 /src/rustdoc/path_pass.rs | |
| parent | c54f53b9d9f67dd4596aac36e59fa6e5d725aaf5 (diff) | |
| download | rust-a5e0f037be17204c640e2941e576a9dca09efc90.tar.gz rust-a5e0f037be17204c640e2941e576a9dca09efc90.zip | |
rustdoc: Add path_pass for recording full paths to mods
Diffstat (limited to 'src/rustdoc/path_pass.rs')
| -rw-r--r-- | src/rustdoc/path_pass.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/rustdoc/path_pass.rs b/src/rustdoc/path_pass.rs new file mode 100644 index 00000000000..9bcdde561c4 --- /dev/null +++ b/src/rustdoc/path_pass.rs @@ -0,0 +1,49 @@ +#[doc = "Records the full path to items"]; + +export mk_pass; + +fn mk_pass() -> pass { run } + +type ctxt = { + srv: astsrv::srv, + mutable path: [str] +}; + +fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { + let ctxt = { + srv: srv, + mutable path: [] + }; + let fold = fold::fold({ + fold_mod: fn~( + f: fold::fold<ctxt>, + d: doc::moddoc + ) -> doc::moddoc { + fold_mod(f, d) + } + with *fold::default_seq_fold(ctxt) + }); + fold.fold_crate(fold, doc) +} + +fn fold_mod(fold: fold::fold<ctxt>, doc: doc::moddoc) -> doc::moddoc { + let is_topmod = doc.id == rustc::syntax::ast::crate_node_id; + + if !is_topmod { vec::push(fold.ctxt.path, doc.name); } + let doc = fold::default_seq_fold_mod(fold, doc); + if !is_topmod { vec::pop(fold.ctxt.path); } + ~{ + path: fold.ctxt.path + with *doc + } +} + +#[test] +fn should_record_mod_paths() { + let source = "mod a { mod b { mod c { } } mod d { mod e { } } }"; + let srv = astsrv::mk_srv_from_str(source); + let doc = extract::from_srv(srv, ""); + let doc = run(srv, doc); + assert doc.topmod.mods[0].mods[0].mods[0].path == ["a", "b"]; + assert doc.topmod.mods[0].mods[1].mods[0].path == ["a", "d"]; +} \ No newline at end of file |
