yang_rs/
compound.rs

1//
2// YANG - YANG compound statement
3//  Copyright (C) 2021 Toshiaki Takada
4//
5
6use derive_getters::Getters;
7
8use super::core::*;
9use super::error::*;
10use super::parser::*;
11use super::stmt::*;
12use super::substmt::*;
13
14use crate::collect_a_stmt;
15use crate::collect_opt_stmt;
16use crate::collect_vec_stmt;
17
18///
19/// Trait for compound YANG statements.
20///
21pub trait Compound {
22    /// Return list fo statement keyword.
23    fn keywords() -> Vec<Keyword> {
24        panic!("undefined");
25    }
26
27    /// Return substatements definition.
28    fn substmts_def() -> Vec<SubStmtDef>;
29}
30
31///
32/// "module-header" statements.
33///
34#[derive(Debug, Clone, PartialEq, Getters)]
35pub struct ModuleHeaderStmts {
36    /// "yang-version" statement.
37    yang_version: Option<YangVersionStmt>,
38
39    /// "namespace" statement.
40    namespace: NamespaceStmt,
41
42    /// "prefix" statement.
43    prefix: PrefixStmt,
44}
45
46impl Compound for ModuleHeaderStmts {
47    /// Return substatements definition.
48    fn substmts_def() -> Vec<SubStmtDef> {
49        vec![
50            SubStmtDef::Optional(SubStmtWith::Stmt(YangVersionStmt::keyword)),
51            SubStmtDef::HasOne(SubStmtWith::Stmt(NamespaceStmt::keyword)),
52            SubStmtDef::HasOne(SubStmtWith::Stmt(PrefixStmt::keyword)),
53        ]
54    }
55}
56
57impl ModuleHeaderStmts {
58    /// Parse sub statements.
59    pub fn parse(parser: &mut Parser) -> Result<ModuleHeaderStmts, YangError> {
60        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
61
62        Ok(ModuleHeaderStmts {
63            yang_version: collect_opt_stmt!(stmts, YangVersionStmt)?,
64            namespace: collect_a_stmt!(stmts, NamespaceStmt)?,
65            prefix: collect_a_stmt!(stmts, PrefixStmt)?,
66        })
67    }
68}
69
70///
71/// "submodule-header" statements.
72///
73#[derive(Debug, Clone, PartialEq, Getters)]
74pub struct SubmoduleHeaderStmts {
75    /// "yang-version" statement.
76    yang_version: Option<YangVersionStmt>,
77
78    /// "belongs-to" statement.
79    belongs_to: BelongsToStmt,
80}
81
82impl Compound for SubmoduleHeaderStmts {
83    /// Return substatements definition.
84    fn substmts_def() -> Vec<SubStmtDef> {
85        vec![
86            SubStmtDef::Optional(SubStmtWith::Stmt(YangVersionStmt::keyword)),
87            SubStmtDef::HasOne(SubStmtWith::Stmt(BelongsToStmt::keyword)),
88        ]
89    }
90}
91
92impl SubmoduleHeaderStmts {
93    /// Parse sub statements.
94    pub fn parse(parser: &mut Parser) -> Result<SubmoduleHeaderStmts, YangError> {
95        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
96
97        Ok(SubmoduleHeaderStmts {
98            yang_version: collect_opt_stmt!(stmts, YangVersionStmt)?,
99            belongs_to: collect_a_stmt!(stmts, BelongsToStmt)?,
100        })
101    }
102}
103
104///
105/// "body" Statements.
106///
107#[derive(Debug, Clone, PartialEq, Getters)]
108pub struct BodyStmts {
109    /// "extension" statment.
110    extension: Vec<ExtensionStmt>,
111
112    /// "feature" statement.
113    feature: Vec<FeatureStmt>,
114
115    /// "identity" statement.
116    identity: Vec<IdentityStmt>,
117
118    /// "typedef" statement.
119    typedef: Vec<TypedefStmt>,
120
121    /// "grouping" statement.
122    grouping: Vec<GroupingStmt>,
123
124    /// "data-def" statement.
125    data_def: DataDefStmt,
126
127    /// "augment" statement.
128    augment: Vec<AugmentStmt>,
129
130    /// "rpc" statement.
131    rpc: Vec<RpcStmt>,
132
133    /// "notification" statement.
134    notification: Vec<NotificationStmt>,
135
136    /// "deviation" statement.
137    deviation: Vec<DeviationStmt>,
138}
139
140impl Compound for BodyStmts {
141    /// Return substatements definition.
142    fn substmts_def() -> Vec<SubStmtDef> {
143        vec![
144            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ExtensionStmt::keyword)),
145            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(FeatureStmt::keyword)),
146            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IdentityStmt::keyword)),
147            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(TypedefStmt::keyword)),
148            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(GroupingStmt::keyword)),
149            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
150            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(AugmentStmt::keyword)),
151            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(RpcStmt::keyword)),
152            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
153            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DeviationStmt::keyword)),
154        ]
155    }
156}
157
158impl BodyStmts {
159    pub fn parse(parser: &mut Parser) -> Result<BodyStmts, YangError> {
160        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
161
162        Ok(BodyStmts {
163            extension: collect_vec_stmt!(stmts, ExtensionStmt)?,
164            feature: collect_vec_stmt!(stmts, FeatureStmt)?,
165            identity: collect_vec_stmt!(stmts, IdentityStmt)?,
166            typedef: collect_vec_stmt!(stmts, TypedefStmt)?,
167            grouping: collect_vec_stmt!(stmts, GroupingStmt)?,
168            data_def: DataDefStmt::new_with_substmts((
169                collect_vec_stmt!(stmts, ContainerStmt)?,
170                collect_vec_stmt!(stmts, LeafStmt)?,
171                collect_vec_stmt!(stmts, LeafListStmt)?,
172                collect_vec_stmt!(stmts, ListStmt)?,
173                collect_vec_stmt!(stmts, ChoiceStmt)?,
174                collect_vec_stmt!(stmts, AnydataStmt)?,
175                collect_vec_stmt!(stmts, AnyxmlStmt)?,
176                collect_vec_stmt!(stmts, UsesStmt)?,
177            )),
178            augment: collect_vec_stmt!(stmts, AugmentStmt)?,
179            rpc: collect_vec_stmt!(stmts, RpcStmt)?,
180            notification: collect_vec_stmt!(stmts, NotificationStmt)?,
181            deviation: collect_vec_stmt!(stmts, DeviationStmt)?,
182        })
183    }
184}
185
186///
187/// "meta" statements.
188///
189#[derive(Debug, Clone, PartialEq, Getters)]
190pub struct MetaStmts {
191    /// "organization" statement.
192    organization: Option<OrganizationStmt>,
193
194    /// "contact" statement.
195    contact: Option<ContactStmt>,
196
197    /// "description" statement.
198    description: Option<DescriptionStmt>,
199
200    /// "refrence statement.
201    reference: Option<ReferenceStmt>,
202}
203
204impl Compound for MetaStmts {
205    /// Return substatements definition.
206    fn substmts_def() -> Vec<SubStmtDef> {
207        vec![
208            SubStmtDef::Optional(SubStmtWith::Stmt(OrganizationStmt::keyword)),
209            SubStmtDef::Optional(SubStmtWith::Stmt(ContactStmt::keyword)),
210            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
211            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
212        ]
213    }
214}
215
216impl MetaStmts {
217    pub fn parse(parser: &mut Parser) -> Result<MetaStmts, YangError> {
218        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
219
220        Ok(MetaStmts {
221            organization: collect_opt_stmt!(stmts, OrganizationStmt)?,
222            contact: collect_opt_stmt!(stmts, ContactStmt)?,
223            description: collect_opt_stmt!(stmts, DescriptionStmt)?,
224            reference: collect_opt_stmt!(stmts, ReferenceStmt)?,
225        })
226    }
227}
228
229///
230/// "linkage" statements.
231///
232#[derive(Debug, Clone, PartialEq, Getters)]
233pub struct LinkageStmts {
234    /// "import" statement.
235    import: Vec<ImportStmt>,
236
237    /// "include" statement.
238    include: Vec<IncludeStmt>,
239}
240
241impl Compound for LinkageStmts {
242    /// Return substatements definition.
243    fn substmts_def() -> Vec<SubStmtDef> {
244        vec![
245            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ImportStmt::keyword)),
246            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IncludeStmt::keyword)),
247        ]
248    }
249}
250
251impl LinkageStmts {
252    pub fn parse(parser: &mut Parser) -> Result<LinkageStmts, YangError> {
253        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
254
255        Ok(LinkageStmts {
256            import: collect_vec_stmt!(stmts, ImportStmt)?,
257            include: collect_vec_stmt!(stmts, IncludeStmt)?,
258        })
259    }
260}
261
262///
263/// "revision" statements.
264///
265#[derive(Debug, Clone, PartialEq, Getters)]
266pub struct RevisionStmts {
267    /// "revision" statement.
268    revision: Vec<RevisionStmt>,
269}
270
271impl Compound for RevisionStmts {
272    /// Return substatements definition.
273    fn substmts_def() -> Vec<SubStmtDef> {
274        vec![SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(
275            RevisionStmt::keyword,
276        ))]
277    }
278}
279
280impl RevisionStmts {
281    pub fn parse(parser: &mut Parser) -> Result<RevisionStmts, YangError> {
282        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
283
284        Ok(RevisionStmts {
285            revision: collect_vec_stmt!(stmts, RevisionStmt)?,
286        })
287    }
288}
289
290///
291/// "numerical-restrictions".
292///
293#[derive(Debug, Clone, PartialEq, Getters)]
294pub struct NumericalRestrictions {
295    /// "reange" statement.
296    range: Option<RangeStmt>,
297}
298
299impl Compound for NumericalRestrictions {
300    /// Return substatements definition.
301    fn substmts_def() -> Vec<SubStmtDef> {
302        vec![SubStmtDef::Optional(SubStmtWith::Stmt(RangeStmt::keyword))]
303    }
304}
305
306impl NumericalRestrictions {
307    pub fn parse(parser: &mut Parser) -> Result<NumericalRestrictions, YangError> {
308        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
309
310        Ok(NumericalRestrictions {
311            range: collect_opt_stmt!(stmts, RangeStmt)?,
312        })
313    }
314}
315
316///
317/// "decimal64-specification".
318///
319#[derive(Debug, Clone, PartialEq, Getters)]
320pub struct Decimal64Specification {
321    /// "fraction-digits" statement.
322    fraction_digits: FractionDigitsStmt,
323
324    /// "range" statement.
325    range: Option<RangeStmt>,
326}
327
328impl Compound for Decimal64Specification {
329    /// Return substatements definition.
330    fn substmts_def() -> Vec<SubStmtDef> {
331        vec![
332            SubStmtDef::HasOne(SubStmtWith::Stmt(FractionDigitsStmt::keyword)),
333            SubStmtDef::Optional(SubStmtWith::Stmt(RangeStmt::keyword)),
334        ]
335    }
336}
337
338impl Decimal64Specification {
339    pub fn parse(parser: &mut Parser) -> Result<Decimal64Specification, YangError> {
340        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
341
342        Ok(Decimal64Specification {
343            fraction_digits: collect_a_stmt!(stmts, FractionDigitsStmt)?,
344            range: collect_opt_stmt!(stmts, RangeStmt)?,
345        })
346    }
347}
348
349///
350/// "string-restrictions".
351///
352#[derive(Debug, Clone, PartialEq, Getters)]
353pub struct StringRestrictions {
354    /// "length" statement.
355    length: Option<LengthStmt>,
356
357    /// "pattern" statement.
358    pattern: Vec<PatternStmt>,
359}
360
361///
362/// "enum-specification".
363///
364#[derive(Debug, Clone, PartialEq, Getters)]
365pub struct EnumSpecification {
366    /// "enum" statement.
367    enum_: Vec<EnumStmt>,
368}
369
370///
371/// "leafref-specification".
372///
373#[derive(Debug, Clone, PartialEq, Getters)]
374pub struct LeafrefSpecification {
375    /// "path" statement.
376    path: PathStmt,
377
378    /// "require-instance" statement.
379    require_instance: Option<RequireInstanceStmt>,
380}
381
382///
383/// "identityref-specification".
384///
385#[derive(Debug, Clone, PartialEq, Getters)]
386pub struct IdentityrefSpecification {
387    /// "base" statement.
388    base: Vec<BaseStmt>,
389}
390
391///
392/// "instance-identifier-specification".
393///
394#[derive(Debug, Clone, PartialEq, Getters)]
395pub struct InstanceIdentifierSpecification {
396    /// "require-instance" statement.
397    require_instance: Option<RequireInstanceStmt>,
398}
399
400///
401/// "bits-specification".
402///
403#[derive(Debug, Clone, PartialEq, Getters)]
404pub struct BitsSpecification {
405    /// "bit" statement.
406    bit: Vec<BitStmt>,
407}
408
409///
410/// "union-specification".
411///
412#[derive(Debug, Clone, PartialEq, Getters)]
413pub struct UnionSpecification {
414    /// "type" statement.
415    type_: Vec<TypeStmt>,
416}
417
418///
419/// "binary-specification".
420///
421#[derive(Debug, Clone, PartialEq, Getters)]
422pub struct BinarySpecification {
423    /// "length" statement.
424    length: Option<LengthStmt>,
425}
426
427///
428/// "type-body" Statements.
429///
430#[derive(Debug, Clone, PartialEq)]
431pub enum TypeBodyStmts {
432    NumericalRestrictions(NumericalRestrictions),
433    Decimal64Specification(Decimal64Specification),
434    StringRestrictions(StringRestrictions),
435    EnumSpecification(EnumSpecification),
436    LeafrefSpecification(LeafrefSpecification),
437    IdentityrefSpecification(IdentityrefSpecification),
438    InstanceIdentifierSpecification(InstanceIdentifierSpecification),
439    BitsSpecification(BitsSpecification),
440    UnionSpecification(UnionSpecification),
441    BinarySpecification(BinarySpecification),
442}
443
444impl TypeBodyStmts {
445    /// Return substatements definition.
446    pub fn substmts_def() -> Vec<SubStmtDef> {
447        vec![
448            SubStmtDef::Optional(SubStmtWith::Stmt(FractionDigitsStmt::keyword)),
449            SubStmtDef::Optional(SubStmtWith::Stmt(RangeStmt::keyword)),
450            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(PatternStmt::keyword)),
451            SubStmtDef::Optional(SubStmtWith::Stmt(LengthStmt::keyword)),
452            SubStmtDef::Optional(SubStmtWith::Stmt(PathStmt::keyword)),
453            SubStmtDef::Optional(SubStmtWith::Stmt(RequireInstanceStmt::keyword)),
454            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(EnumStmt::keyword)),
455            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(BaseStmt::keyword)),
456            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(BitStmt::keyword)),
457            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(TypeStmt::keyword)),
458        ]
459        // TBD: This check is very loose at this moment.
460    }
461
462    // decimal64 specification		fraction-digits-stmt [range-stmt]	(any order)
463    // numerical restrictions		[range-stmt]
464    // string restrictions			[length-stmt] *pattern-stmt		(any order)
465    // binary-specification			[length-stmt]
466    // leafref-specification		path-stmt [require-instance-stmt]	(any order)
467    // instance-identifier-specpfication	[require-instance-stmt]
468    // enum specification			1*enum-stmt
469    // identityref-specification		1*base-stmt
470    // bits-specification			1*bit-stmt
471    // union-specification			1*type-stmt
472    pub fn parse(parser: &mut Parser) -> Result<TypeBodyStmts, YangError> {
473        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
474
475        let type_body = if let Ok(fraction_digits) = collect_a_stmt!(stmts, FractionDigitsStmt) {
476            let range = if let Ok(range) = collect_a_stmt!(stmts, RangeStmt) {
477                Some(range)
478            } else {
479                None
480            };
481
482            TypeBodyStmts::Decimal64Specification(Decimal64Specification {
483                fraction_digits,
484                range,
485            })
486        } else if let Ok(range) = collect_a_stmt!(stmts, RangeStmt) {
487            TypeBodyStmts::NumericalRestrictions(NumericalRestrictions { range: Some(range) })
488        } else if let Ok(pattern) = collect_vec_stmt!(stmts, PatternStmt) {
489            // TBD: need check pattern.len()
490            let length = if let Ok(length) = collect_a_stmt!(stmts, LengthStmt) {
491                Some(length)
492            } else {
493                None
494            };
495
496            TypeBodyStmts::StringRestrictions(StringRestrictions { pattern, length })
497        } else if let Ok(length) = collect_a_stmt!(stmts, LengthStmt) {
498            TypeBodyStmts::BinarySpecification(BinarySpecification {
499                length: Some(length),
500            })
501        } else if let Ok(path) = collect_a_stmt!(stmts, PathStmt) {
502            let require_instance =
503                if let Ok(require_instance) = collect_a_stmt!(stmts, RequireInstanceStmt) {
504                    Some(require_instance)
505                } else {
506                    None
507                };
508
509            TypeBodyStmts::LeafrefSpecification(LeafrefSpecification {
510                path,
511                require_instance,
512            })
513        } else if let Ok(require_instance) = collect_a_stmt!(stmts, RequireInstanceStmt) {
514            TypeBodyStmts::InstanceIdentifierSpecification(InstanceIdentifierSpecification {
515                require_instance: Some(require_instance),
516            })
517        } else if let Ok(enum_) = collect_vec_stmt!(stmts, EnumStmt) {
518            TypeBodyStmts::EnumSpecification(EnumSpecification { enum_ })
519        } else if let Ok(base) = collect_vec_stmt!(stmts, BaseStmt) {
520            TypeBodyStmts::IdentityrefSpecification(IdentityrefSpecification { base })
521        } else if let Ok(bit) = collect_vec_stmt!(stmts, BitStmt) {
522            TypeBodyStmts::BitsSpecification(BitsSpecification { bit })
523        } else if let Ok(type_) = collect_vec_stmt!(stmts, TypeStmt) {
524            TypeBodyStmts::UnionSpecification(UnionSpecification { type_ })
525        } else {
526            return Err(YangError::MissingStatement(""));
527        };
528
529        Ok(type_body)
530    }
531}
532
533//
534// Trait for selection of YANG statements.
535//
536pub trait Selection {
537    /// Sub Statements.
538    type SubStmts;
539
540    /// Return list fo statement keyword.
541    fn keywords() -> Vec<Keyword> {
542        panic!("undefined");
543    }
544
545    /// Constructor with empty substatements.
546    fn new() -> Self
547    where
548        Self: Sized,
549    {
550        panic!("{:?}", Self::keywords());
551    }
552
553    /// Constructor with tuple of substatements. Panic if it is not defined.
554    fn new_with_substmts(_substmts: Self::SubStmts) -> Self
555    where
556        Self: Sized,
557    {
558        panic!("{:?}", Self::keywords());
559    }
560}
561
562///
563/// "typedef" stmt / "grouping" stmt
564///
565#[derive(Debug, Clone, PartialEq, Getters)]
566pub struct TypedefOrGrouping {
567    /// "typedef" statement.
568    typedef: Vec<TypedefStmt>,
569
570    /// "grouping" statement.
571    grouping: Vec<GroupingStmt>,
572}
573
574impl Selection for TypedefOrGrouping {
575    /// Sub Statements.
576    type SubStmts = (Vec<TypedefStmt>, Vec<GroupingStmt>);
577
578    /// Return list fo statement keyword.
579    fn keywords() -> Vec<Keyword> {
580        vec![TypedefStmt::keyword(), GroupingStmt::keyword()]
581    }
582
583    /// Constructor with empty substatements.
584    fn new() -> Self
585    where
586        Self: Sized,
587    {
588        Self {
589            typedef: Vec::new(),
590            grouping: Vec::new(),
591        }
592    }
593
594    /// Constructor with tuple of substatements. Panic if it is not defined.
595    fn new_with_substmts(substmts: Self::SubStmts) -> Self
596    where
597        Self: Sized,
598    {
599        Self {
600            typedef: substmts.0,
601            grouping: substmts.1,
602        }
603    }
604}
605
606///
607/// "data-def-stmt".
608///
609#[derive(Debug, Clone, PartialEq, Getters)]
610pub struct DataDefStmt {
611    /// "container" statement.
612    container: Vec<ContainerStmt>,
613
614    /// "leaf" statement.
615    leaf: Vec<LeafStmt>,
616
617    /// "leaf-list" statement.
618    leaf_list: Vec<LeafListStmt>,
619
620    /// "list" statement.
621    list: Vec<ListStmt>,
622
623    /// "choice" statement.
624    choice: Vec<ChoiceStmt>,
625
626    /// "anydata" statement.
627    anydata: Vec<AnydataStmt>,
628
629    /// "anyxml" statement.
630    anyxml: Vec<AnyxmlStmt>,
631
632    /// "uses" statement.
633    uses: Vec<UsesStmt>,
634}
635
636impl Selection for DataDefStmt {
637    /// Sub Statements.
638    type SubStmts = (
639        Vec<ContainerStmt>,
640        Vec<LeafStmt>,
641        Vec<LeafListStmt>,
642        Vec<ListStmt>,
643        Vec<ChoiceStmt>,
644        Vec<AnydataStmt>,
645        Vec<AnyxmlStmt>,
646        Vec<UsesStmt>,
647    );
648
649    /// Return list fo statement keyword.
650    fn keywords() -> Vec<Keyword> {
651        vec![
652            ContainerStmt::keyword(),
653            LeafStmt::keyword(),
654            LeafListStmt::keyword(),
655            ListStmt::keyword(),
656            ChoiceStmt::keyword(),
657            AnydataStmt::keyword(),
658            AnyxmlStmt::keyword(),
659            UsesStmt::keyword(),
660        ]
661    }
662
663    /// Constructor with empty substatements.
664    fn new() -> Self
665    where
666        Self: Sized,
667    {
668        Self {
669            container: Vec::new(),
670            leaf: Vec::new(),
671            leaf_list: Vec::new(),
672            list: Vec::new(),
673            choice: Vec::new(),
674            anydata: Vec::new(),
675            anyxml: Vec::new(),
676            uses: Vec::new(),
677        }
678    }
679
680    /// Constructor with tuple of substatements. Panic if it is not defined.
681    fn new_with_substmts(substmts: Self::SubStmts) -> Self
682    where
683        Self: Sized,
684    {
685        Self {
686            container: substmts.0,
687            leaf: substmts.1,
688            leaf_list: substmts.2,
689            list: substmts.3,
690            choice: substmts.4,
691            anydata: substmts.5,
692            anyxml: substmts.6,
693            uses: substmts.7,
694        }
695    }
696}
697
698///
699/// "data-def-stmt" / "case-stmt" / "action-stmt" / "notification-stmt".
700///
701#[derive(Debug, Clone, PartialEq, Getters)]
702pub struct DataDefOrElse {
703    /// "container" statement.
704    container: Vec<ContainerStmt>,
705
706    /// "leaf" statement.
707    leaf: Vec<LeafStmt>,
708
709    /// "leaf-list" statement.
710    leaf_list: Vec<LeafListStmt>,
711
712    /// "list" statement.
713    list: Vec<ListStmt>,
714
715    /// "choice" statement.
716    choice: Vec<ChoiceStmt>,
717
718    /// "anydata" statement.
719    anydata: Vec<AnydataStmt>,
720
721    /// "anyxml" statement.
722    anyxml: Vec<AnyxmlStmt>,
723
724    /// "uses" statement.
725    uses: Vec<UsesStmt>,
726
727    /// "case" statement.
728    case: Vec<CaseStmt>,
729
730    /// "action" statement.
731    action: Vec<ActionStmt>,
732
733    /// "notification" statement.
734    notification: Vec<NotificationStmt>,
735}
736
737impl Selection for DataDefOrElse {
738    /// Sub Statements.
739    type SubStmts = (
740        Vec<ContainerStmt>,
741        Vec<LeafStmt>,
742        Vec<LeafListStmt>,
743        Vec<ListStmt>,
744        Vec<ChoiceStmt>,
745        Vec<AnydataStmt>,
746        Vec<AnyxmlStmt>,
747        Vec<UsesStmt>,
748        Vec<CaseStmt>,
749        Vec<ActionStmt>,
750        Vec<NotificationStmt>,
751    );
752
753    /// Return list fo statement keyword.
754    fn keywords() -> Vec<Keyword> {
755        vec![
756            ContainerStmt::keyword(),
757            LeafStmt::keyword(),
758            LeafListStmt::keyword(),
759            ListStmt::keyword(),
760            ChoiceStmt::keyword(),
761            AnydataStmt::keyword(),
762            AnyxmlStmt::keyword(),
763            UsesStmt::keyword(),
764            CaseStmt::keyword(),
765            ActionStmt::keyword(),
766            NotificationStmt::keyword(),
767        ]
768    }
769
770    /// Constructor with empty substatements.
771    fn new() -> Self
772    where
773        Self: Sized,
774    {
775        Self {
776            container: Vec::new(),
777            leaf: Vec::new(),
778            leaf_list: Vec::new(),
779            list: Vec::new(),
780            choice: Vec::new(),
781            anydata: Vec::new(),
782            anyxml: Vec::new(),
783            uses: Vec::new(),
784            case: Vec::new(),
785            action: Vec::new(),
786            notification: Vec::new(),
787        }
788    }
789
790    /// Constructor with tuple of substatements. Panic if it is not defined.
791    fn new_with_substmts(substmts: Self::SubStmts) -> Self
792    where
793        Self: Sized,
794    {
795        Self {
796            container: substmts.0,
797            leaf: substmts.1,
798            leaf_list: substmts.2,
799            list: substmts.3,
800            choice: substmts.4,
801            anydata: substmts.5,
802            anyxml: substmts.6,
803            uses: substmts.7,
804            case: substmts.8,
805            action: substmts.9,
806            notification: substmts.10,
807        }
808    }
809}
810
811///
812/// "short-case-stmt" / "case-stmt".
813///
814#[derive(Debug, Clone, PartialEq, Getters)]
815pub struct ShortCaseOrCaseStmt {
816    /// "choice" statement.
817    choice: Vec<ChoiceStmt>,
818
819    /// "container" statement.
820    container: Vec<ContainerStmt>,
821
822    /// "leaf" statement.
823    leaf: Vec<LeafStmt>,
824
825    /// "leaf-list" statement.
826    leaf_list: Vec<LeafListStmt>,
827
828    /// "list" statement.
829    list: Vec<ListStmt>,
830
831    /// "anydata" statement.
832    anydata: Vec<AnydataStmt>,
833
834    /// "anyxml" statement.
835    anyxml: Vec<AnyxmlStmt>,
836
837    /// "case" statement.
838    case: Vec<CaseStmt>,
839}
840
841impl Selection for ShortCaseOrCaseStmt {
842    /// Sub Statements.
843    type SubStmts = (
844        Vec<ChoiceStmt>,
845        Vec<ContainerStmt>,
846        Vec<LeafStmt>,
847        Vec<LeafListStmt>,
848        Vec<ListStmt>,
849        Vec<AnydataStmt>,
850        Vec<AnyxmlStmt>,
851        Vec<CaseStmt>,
852    );
853
854    /// Return list fo statement keyword.
855    fn keywords() -> Vec<Keyword> {
856        vec![
857            ChoiceStmt::keyword(),
858            ContainerStmt::keyword(),
859            LeafStmt::keyword(),
860            LeafListStmt::keyword(),
861            ListStmt::keyword(),
862            AnydataStmt::keyword(),
863            AnyxmlStmt::keyword(),
864            CaseStmt::keyword(),
865        ]
866    }
867
868    /// Constructor with empty substatements.
869    fn new() -> Self
870    where
871        Self: Sized,
872    {
873        Self {
874            choice: Vec::new(),
875            container: Vec::new(),
876            leaf: Vec::new(),
877            leaf_list: Vec::new(),
878            list: Vec::new(),
879            anydata: Vec::new(),
880            anyxml: Vec::new(),
881            case: Vec::new(),
882        }
883    }
884
885    /// Constructor with tuple of substatements. Panic if it is not defined.
886    fn new_with_substmts(substmts: Self::SubStmts) -> Self
887    where
888        Self: Sized,
889    {
890        Self {
891            choice: substmts.0,
892            container: substmts.1,
893            leaf: substmts.2,
894            leaf_list: substmts.3,
895            list: substmts.4,
896            anydata: substmts.5,
897            anyxml: substmts.6,
898            case: substmts.7,
899        }
900    }
901}