rustdoc: Move parse_compound_fndoc into mod attr_parser
This commit is contained in:
parent
46a662ecb2
commit
f3c4263635
3 changed files with 70 additions and 67 deletions
67
src/rustdoc/attr_parser.rs
Normal file
67
src/rustdoc/attr_parser.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
export parse_compound_fndoc;
|
||||
|
||||
#[doc(
|
||||
brief = "Parses function docs from a complex #[doc] attribute.",
|
||||
desc = "Supported attributes:
|
||||
|
||||
* `brief`: Brief description
|
||||
* `desc`: Long description
|
||||
* `return`: Description of return value
|
||||
* `args`: List of argname = argdesc pairs
|
||||
",
|
||||
args(items = "Doc attribute contents"),
|
||||
return = "Parsed function docs."
|
||||
)]
|
||||
fn parse_compound_fndoc(items: [@ast::meta_item]) -> doc::fndoc {
|
||||
let brief = none;
|
||||
let desc = none;
|
||||
let return = none;
|
||||
let argdocs = map::new_str_hash::<str>();
|
||||
let argdocsfound = none;
|
||||
for item: @ast::meta_item in items {
|
||||
alt item.node {
|
||||
ast::meta_name_value("brief", {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
brief = some(value);
|
||||
}
|
||||
ast::meta_name_value("desc", {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
desc = some(value);
|
||||
}
|
||||
ast::meta_name_value("return", {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
return = some(value);
|
||||
}
|
||||
ast::meta_list("args", args) {
|
||||
argdocsfound = some(args);
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
|
||||
alt argdocsfound {
|
||||
none. { }
|
||||
some(ds) {
|
||||
for d: @ast::meta_item in ds {
|
||||
alt d.node {
|
||||
ast::meta_name_value(key, {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
argdocs.insert(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _brief = alt brief {
|
||||
some(_b) { _b }
|
||||
none. { "_undocumented_" }
|
||||
};
|
||||
|
||||
~{
|
||||
name: "todo",
|
||||
brief: _brief,
|
||||
desc: desc,
|
||||
return: return,
|
||||
args: argdocs }
|
||||
}
|
|
@ -9,5 +9,6 @@
|
|||
|
||||
mod parse;
|
||||
mod extract;
|
||||
mod attr_parser;
|
||||
mod doc;
|
||||
mod gen;
|
|
@ -22,72 +22,6 @@ type rustdoc = {
|
|||
w: io::writer
|
||||
};
|
||||
|
||||
#[doc(
|
||||
brief = "Parses function docs from a complex #[doc] attribute.",
|
||||
desc = "Supported attributes:
|
||||
|
||||
* `brief`: Brief description
|
||||
* `desc`: Long description
|
||||
* `return`: Description of return value
|
||||
* `args`: List of argname = argdesc pairs
|
||||
",
|
||||
args(items = "Doc attribute contents"),
|
||||
return = "Parsed function docs."
|
||||
)]
|
||||
fn parse_compound_fndoc(items: [@ast::meta_item]) -> doc::fndoc {
|
||||
let brief = none;
|
||||
let desc = none;
|
||||
let return = none;
|
||||
let argdocs = map::new_str_hash::<str>();
|
||||
let argdocsfound = none;
|
||||
for item: @ast::meta_item in items {
|
||||
alt item.node {
|
||||
ast::meta_name_value("brief", {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
brief = some(value);
|
||||
}
|
||||
ast::meta_name_value("desc", {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
desc = some(value);
|
||||
}
|
||||
ast::meta_name_value("return", {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
return = some(value);
|
||||
}
|
||||
ast::meta_list("args", args) {
|
||||
argdocsfound = some(args);
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
|
||||
alt argdocsfound {
|
||||
none. { }
|
||||
some(ds) {
|
||||
for d: @ast::meta_item in ds {
|
||||
alt d.node {
|
||||
ast::meta_name_value(key, {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
argdocs.insert(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _brief = alt brief {
|
||||
some(_b) { _b }
|
||||
none. { "_undocumented_" }
|
||||
};
|
||||
|
||||
~{
|
||||
name: "todo",
|
||||
brief: _brief,
|
||||
desc: desc,
|
||||
return: return,
|
||||
args: argdocs }
|
||||
}
|
||||
|
||||
#[doc(
|
||||
brief = "Documents a single crate item.",
|
||||
args(rd = "Rustdoc context",
|
||||
|
@ -109,7 +43,8 @@ fn doc_item(rd: rustdoc, item: @ast::item) {
|
|||
});
|
||||
}
|
||||
ast::meta_list("doc", docs) {
|
||||
_fndoc = some(parse_compound_fndoc(docs));
|
||||
_fndoc = some(
|
||||
attr_parser::parse_compound_fndoc(docs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue