1
1
export parse_fn;
2
2
3
- fn parse_fn ( name : str , attrs : [ ast:: attribute ] ) -> doc:: fndoc {
3
+ fn parse_fn (
4
+ name : str ,
5
+ id : ast:: node_id ,
6
+ attrs : [ ast:: attribute ]
7
+ ) -> doc:: fndoc {
4
8
let noargdocs = map:: new_str_hash :: < str > ( ) ;
5
9
let _fndoc = none;
6
10
for attr: ast:: attribute in attrs {
7
11
alt attr. node . value . node {
8
12
ast:: meta_name_value (
9
13
"doc" , { node: ast:: lit_str ( value) , span: _} ) {
10
14
_fndoc = some ( ~{
15
+ id: id,
11
16
name: name,
12
17
brief: value,
13
18
desc: none,
@@ -17,7 +22,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
17
22
}
18
23
ast:: meta_list ( "doc" , docs) {
19
24
_fndoc = some (
20
- parse_fn_ ( name, docs) ) ;
25
+ parse_fn_ ( name, id , docs) ) ;
21
26
}
22
27
}
23
28
}
@@ -26,6 +31,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
26
31
some( _d) { _d }
27
32
none. {
28
33
~{
34
+ id: id,
29
35
name: name,
30
36
brief: "_undocumented_" ,
31
37
desc: none,
@@ -50,7 +56,11 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
50
56
args( items = "Doc attribute contents" ) ,
51
57
return = "Parsed function docs."
52
58
) ]
53
- fn parse_fn_ ( name : str , items : [ @ast:: meta_item ] ) -> doc:: fndoc {
59
+ fn parse_fn_ (
60
+ name : str ,
61
+ id : ast:: node_id ,
62
+ items : [ @ast:: meta_item ]
63
+ ) -> doc:: fndoc {
54
64
let brief = none;
55
65
let desc = none;
56
66
let return = none;
@@ -97,6 +107,7 @@ fn parse_fn_(name: str, items: [@ast::meta_item]) -> doc::fndoc {
97
107
} ;
98
108
99
109
~{
110
+ id: id,
100
111
name: name,
101
112
brief: _brief,
102
113
desc: desc,
@@ -128,7 +139,7 @@ mod tests {
128
139
fn parse_fn_should_handle_undocumented_functions ( ) {
129
140
let source = "" ;
130
141
let attrs = parse_attributes ( source) ;
131
- let doc = parse_fn ( "f" , attrs) ;
142
+ let doc = parse_fn ( "f" , 0 , attrs) ;
132
143
assert doc. brief == "_undocumented_" ;
133
144
assert doc. desc == none;
134
145
assert doc. return == none;
@@ -139,39 +150,39 @@ mod tests {
139
150
fn parse_fn_should_parse_simple_doc_attributes ( ) {
140
151
let source = "#[doc = \" basic\" ]" ;
141
152
let attrs = parse_attributes ( source) ;
142
- let doc = parse_fn ( "f" , attrs) ;
153
+ let doc = parse_fn ( "f" , 0 , attrs) ;
143
154
assert doc. brief == "basic" ;
144
155
}
145
156
146
157
#[ test]
147
158
fn parse_fn_should_parse_the_brief_description ( ) {
148
159
let source = "#[doc(brief = \" short\" )]" ;
149
160
let attrs = parse_attributes ( source) ;
150
- let doc = parse_fn ( "f" , attrs) ;
161
+ let doc = parse_fn ( "f" , 0 , attrs) ;
151
162
assert doc. brief == "short" ;
152
163
}
153
164
154
165
#[ test]
155
166
fn parse_fn_should_parse_the_long_description ( ) {
156
167
let source = "#[doc(desc = \" description\" )]" ;
157
168
let attrs = parse_attributes ( source) ;
158
- let doc = parse_fn ( "f" , attrs) ;
169
+ let doc = parse_fn ( "f" , 0 , attrs) ;
159
170
assert doc. desc == some ( "description" ) ;
160
171
}
161
172
162
173
#[ test]
163
174
fn parse_fn_should_parse_the_return_value_description ( ) {
164
175
let source = "#[doc(return = \" return value\" )]" ;
165
176
let attrs = parse_attributes ( source) ;
166
- let doc = parse_fn ( "f" , attrs) ;
177
+ let doc = parse_fn ( "f" , 0 , attrs) ;
167
178
assert doc. return == some ( "return value" ) ;
168
179
}
169
180
170
181
#[ test]
171
182
fn parse_fn_should_parse_the_argument_descriptions ( ) {
172
183
let source = "#[doc(args(a = \" arg a\" , b = \" arg b\" ))]" ;
173
184
let attrs = parse_attributes ( source) ;
174
- let doc = parse_fn ( "f" , attrs) ;
185
+ let doc = parse_fn ( "f" , 0 , attrs) ;
175
186
assert doc. args . get ( "a" ) == "arg a" ;
176
187
assert doc. args . get ( "b" ) == "arg b" ;
177
188
}
@@ -180,7 +191,7 @@ mod tests {
180
191
fn parse_fn_should_set_brief_desc_to_undocumented_if_not_exists ( ) {
181
192
let source = "#[doc(desc = \" long desc\" )]" ;
182
193
let attrs = parse_attributes ( source) ;
183
- let doc = parse_fn ( "f" , attrs) ;
194
+ let doc = parse_fn ( "f" , 0 , attrs) ;
184
195
assert doc. brief == "_undocumented_" ;
185
196
}
186
197
}
0 commit comments