Skip to content

Commit c93c635

Browse files
committed
rustdoc: Add parsing of const attribute docs
1 parent e6ed88d commit c93c635

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/rustdoc/attr_parser.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import rustc::syntax::ast;
99
import rustc::front::attr;
1010
import core::tuple;
1111

12-
export crate_attrs, mod_attrs, fn_attrs, arg_attrs;
13-
export parse_crate, parse_mod, parse_fn;
12+
export crate_attrs, mod_attrs, fn_attrs, arg_attrs, const_attrs;
13+
export parse_crate, parse_mod, parse_fn, parse_const;
1414

1515
type crate_attrs = {
1616
name: option<str>
@@ -33,6 +33,11 @@ type arg_attrs = {
3333
desc: str
3434
};
3535

36+
type const_attrs = {
37+
brief: option<str>,
38+
desc: option<str>
39+
};
40+
3641
fn doc_meta(
3742
attrs: [ast::attribute]
3843
) -> option<@ast::meta_item> {
@@ -276,6 +281,47 @@ fn parse_fn_should_parse_the_argument_descriptions() {
276281
assert attrs.args[1] == {name: "b", desc: "arg b"};
277282
}
278283
284+
fn parse_const(attrs: [ast::attribute]) -> const_attrs {
285+
parse_short_doc_or(
286+
attrs,
287+
{|desc|
288+
{
289+
brief: none,
290+
desc: desc
291+
}
292+
},
293+
parse_const_long_doc
294+
)
295+
}
296+
297+
fn parse_const_long_doc(
298+
_items: [@ast::meta_item],
299+
brief: option<str>,
300+
desc: option<str>
301+
) -> const_attrs {
302+
{
303+
brief: brief,
304+
desc: desc
305+
}
306+
}
307+
308+
#[test]
309+
fn should_parse_const_short_doc() {
310+
let source = "#[doc = \"description\"]";
311+
let attrs = test::parse_attributes(source);
312+
let attrs = parse_fn(attrs);
313+
assert attrs.desc == some("description");
314+
}
315+
316+
#[test]
317+
fn should_parse_const_long_doc() {
318+
let source = "#[doc(brief = \"a\", desc = \"b\")]";
319+
let attrs = test::parse_attributes(source);
320+
let attrs = parse_fn(attrs);
321+
assert attrs.brief == some("a");
322+
assert attrs.desc == some("b");
323+
}
324+
279325
#[cfg(test)]
280326
mod test {
281327

0 commit comments

Comments
 (0)