weedle/
mixin.rs

1use crate::argument::ArgumentList;
2use crate::attribute::ExtendedAttributeList;
3use crate::common::{Identifier, Parenthesized};
4use crate::interface::{ConstMember, StringifierMember};
5use crate::types::{AttributedType, ReturnType};
6
7/// Parses the members declarations of a mixin
8pub type MixinMembers<'a> = Vec<MixinMember<'a>>;
9
10ast_types! {
11    /// Parses one of the variants of a mixin member
12    enum MixinMember<'a> {
13        Const(ConstMember<'a>),
14        /// Parses `[attributes]? stringifier? returntype identifier? (( args ));`
15        ///
16        /// (( )) means ( ) chars
17        Operation(struct OperationMixinMember<'a> {
18            attributes: Option<ExtendedAttributeList<'a>>,
19            stringifier: Option<term!(stringifier)>,
20            return_type: ReturnType<'a>,
21            identifier: Option<Identifier<'a>>,
22            args: Parenthesized<ArgumentList<'a>>,
23            semi_colon: term!(;),
24        }),
25        /// Parses `[attributes]? stringifier? readonly? attribute attributedtype identifier;`
26        Attribute(struct AttributeMixinMember<'a> {
27            attributes: Option<ExtendedAttributeList<'a>>,
28            stringifier: Option<term!(stringifier)>,
29            readonly: Option<term!(readonly)>,
30            attribute: term!(attribute),
31            type_: AttributedType<'a>,
32            identifier: Identifier<'a>,
33            semi_colon: term!(;),
34        }),
35        Stringifier(StringifierMember<'a>),
36    }
37}
38
39#[cfg(test)]
40mod test {
41    use super::*;
42    use crate::Parse;
43
44    test!(should_parse_attribute_mixin_member { "stringifier readonly attribute short name;" =>
45        "";
46        AttributeMixinMember;
47        attributes.is_none();
48        stringifier.is_some();
49        readonly.is_some();
50        identifier.0 == "name";
51    });
52
53    test!(should_parse_operation_mixin_member { "short fnName(long a);" =>
54        "";
55        OperationMixinMember;
56        attributes.is_none();
57        stringifier.is_none();
58        identifier.is_some();
59    });
60}