about summary refs log tree commit diff
path: root/src/rustdoc/attr_parser.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-26 21:20:17 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-26 21:20:17 -0800
commit2efc6004b5e155174f2e66ff694b11ed42f8bcce (patch)
treea0baa7514eb1ba897c234e16073f99bbf4133c6d /src/rustdoc/attr_parser.rs
parent97a1110c5f66e4cc6a3ebf280066860d2efec397 (diff)
downloadrust-2efc6004b5e155174f2e66ff694b11ed42f8bcce.tar.gz
rust-2efc6004b5e155174f2e66ff694b11ed42f8bcce.zip
rustdoc: Parse resource doc attributes
Diffstat (limited to 'src/rustdoc/attr_parser.rs')
-rw-r--r--src/rustdoc/attr_parser.rs87
1 files changed, 76 insertions, 11 deletions
diff --git a/src/rustdoc/attr_parser.rs b/src/rustdoc/attr_parser.rs
index bcdc093aed6..97c0f31ea5c 100644
--- a/src/rustdoc/attr_parser.rs
+++ b/src/rustdoc/attr_parser.rs
@@ -10,9 +10,9 @@ import rustc::front::attr;
 import core::tuple;
 
 export crate_attrs, mod_attrs, fn_attrs, arg_attrs,
-       const_attrs, enum_attrs, variant_attrs;
+       const_attrs, enum_attrs, variant_attrs, res_attrs;
 export parse_crate, parse_mod, parse_fn, parse_const,
-       parse_enum, parse_variant;
+       parse_enum, parse_variant, parse_res;
 
 type crate_attrs = {
     name: option<str>
@@ -50,6 +50,12 @@ type variant_attrs = {
     desc: option<str>
 };
 
+type res_attrs = {
+    brief: option<str>,
+    desc: option<str>,
+    args: [arg_attrs]
+};
+
 #[cfg(test)]
 mod test {
 
@@ -248,7 +254,19 @@ fn parse_fn_long_doc(
 ) -> fn_attrs {
     let return = attr::meta_item_value_from_list(items, "return");
     let failure = attr::meta_item_value_from_list(items, "failure");
-    let args = alt attr::meta_item_list_from_list(items, "args") {
+    let args = parse_args(items);
+
+    {
+        brief: brief,
+        desc: desc,
+        args: args,
+        return: return,
+        failure: failure
+    }
+}
+
+fn parse_args(items: [@ast::meta_item]) -> [arg_attrs] {
+    alt attr::meta_item_list_from_list(items, "args") {
       some(items) {
         vec::filter_map(items) {|item|
             option::map(attr::name_value_str_pair(item)) { |pair|
@@ -260,14 +278,6 @@ fn parse_fn_long_doc(
         }
       }
       none { [] }
-    };
-
-    {
-        brief: brief,
-        desc: desc,
-        args: args,
-        return: return,
-        failure: failure
     }
 }
 
@@ -417,3 +427,58 @@ fn should_parse_variant_long_doc() {
     let attrs = parse_variant(attrs);
     assert attrs.desc == some("a");
 }
+
+fn parse_res(
+    attrs: [ast::attribute]
+) -> res_attrs {
+
+    parse_short_doc_or(
+        attrs,
+        {|desc|
+            {
+                brief: none,
+                desc: desc,
+                args: []
+            }
+        },
+        parse_res_long_doc
+    )
+}
+
+fn parse_res_long_doc(
+    items: [@ast::meta_item],
+    brief: option<str>,
+    desc: option<str>
+) -> res_attrs {
+    {
+        brief: brief,
+        desc: desc,
+        args: parse_args(items)
+    }
+}
+
+#[test]
+fn should_parse_resource_short_desc() {
+    let source = "#[doc = \"a\"]";
+    let attrs = test::parse_attributes(source);
+    let attrs = parse_res(attrs);
+    assert attrs.desc == some("a");
+}
+
+#[test]
+fn should_parse_resource_long_desc() {
+    let source = "#[doc(brief = \"a\", desc = \"b\")]";
+    let attrs = test::parse_attributes(source);
+    let attrs = parse_res(attrs);
+    assert attrs.brief == some("a");
+    assert attrs.desc == some("b");
+}
+
+#[test]
+fn shoulde_parse_resource_arg() {
+    let source = "#[doc(args(a = \"b\"))]";
+    let attrs = test::parse_attributes(source);
+    let attrs = parse_res(attrs);
+    assert attrs.args[0].name == "a";
+    assert attrs.args[0].desc == "b";
+}
\ No newline at end of file