| 1 |
use crate::argument::ArgumentList; |
| 2 |
use crate::attribute::ExtendedAttributeList; |
| 3 |
use crate::common::{Docstring, Identifier, Parenthesized}; |
| 4 |
use crate::types::{AttributedType, ReturnType}; |
| 5 |
|
| 6 |
/// Parses namespace members declaration |
| 7 |
pub type NamespaceMembers<'a> = Vec<NamespaceMember<'a>>; |
| 8 |
|
| 9 |
ast_types! { |
| 10 |
/// Parses namespace member declaration |
| 11 |
enum NamespaceMember<'a> { |
| 12 |
/// Parses `[attributes]? returntype identifier? (( args ));` |
| 13 |
/// |
| 14 |
/// (( )) means ( ) chars |
| 15 |
Operation(struct OperationNamespaceMember<'a> { |
| 16 |
docstring: Option<Docstring>, |
| 17 |
attributes: Option<ExtendedAttributeList<'a>>, |
| 18 |
return_type: ReturnType<'a>, |
| 19 |
identifier: Option<Identifier<'a>>, |
| 20 |
args: Parenthesized<ArgumentList<'a>>, |
| 21 |
semi_colon: term!(;), |
| 22 |
}), |
| 23 |
/// Parses `[attribute]? readonly attributetype type identifier;` |
| 24 |
Attribute(struct AttributeNamespaceMember<'a> { |
| 25 |
docstring: Option<Docstring>, |
| 26 |
attributes: Option<ExtendedAttributeList<'a>>, |
| 27 |
readonly: term!(readonly), |
| 28 |
attribute: term!(attribute), |
| 29 |
type_: AttributedType<'a>, |
| 30 |
identifier: Identifier<'a>, |
| 31 |
semi_colon: term!(;), |
| 32 |
}), |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
#[cfg(test)] |
| 37 |
mod test { |
| 38 |
use super::*; |
| 39 |
use crate::Parse; |
| 40 |
|
| 41 |
test!(should_parse_attribute_namespace_member { "readonly attribute short name;" => |
| 42 |
""; |
| 43 |
AttributeNamespaceMember; |
| 44 |
attributes.is_none(); |
| 45 |
identifier.0 == "name"; |
| 46 |
}); |
| 47 |
|
| 48 |
test!(should_parse_operation_namespace_member { "short (long a, long b);" => |
| 49 |
""; |
| 50 |
OperationNamespaceMember; |
| 51 |
attributes.is_none(); |
| 52 |
identifier.is_none(); |
| 53 |
}); |
| 54 |
} |