yang_rs/
stmt.rs

1//
2// YANG - YANG statement
3//  Copyright (C) 2021 Toshiaki Takada
4//
5
6use std::str::FromStr;
7use url::Url;
8
9use derive_getters::Getters;
10
11use super::arg::*;
12use super::compound::Compound;
13use super::compound::*;
14use super::core::*;
15use super::error::*;
16use super::parser::*;
17use super::substmt::*;
18
19use crate::collect_a_stmt;
20use crate::collect_opt_stmt;
21use crate::collect_vec_stmt;
22
23///
24/// Trait for a single YANG statement.
25///
26pub trait Stmt {
27    /// Arg type.
28    type Arg;
29
30    /// Sub Statements.
31    type SubStmts;
32
33    /// Return statement keyword.
34    fn keyword() -> Keyword;
35
36    /// Return true if this statement has sub-statements.
37    fn has_substmts() -> bool {
38        false
39    }
40
41    /// Return true if this statement has sub-statements optionally.
42    fn opt_substmts() -> bool {
43        false
44    }
45
46    /// Return substatements definition.
47    fn substmts_def() -> Vec<SubStmtDef> {
48        panic!("{:?}", Self::keyword());
49    }
50
51    /// Constructor with a single arg. Panic if it is not defined.
52    fn new_with_arg(_arg: Self::Arg) -> YangStmt
53    where
54        Self: Sized,
55    {
56        panic!("{:?}", Self::keyword());
57    }
58
59    /// Constructor with tuple of substatements. Panic if it is not defined.
60    fn new_with_substmts(_arg: Self::Arg, _substmts: Self::SubStmts) -> YangStmt
61    where
62        Self: Sized,
63    {
64        panic!("{:?}", Self::keyword());
65    }
66
67    /// Parse substatements.
68    fn parse_substmts(_parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
69        panic!("{:?}", Self::keyword());
70    }
71
72    /// Parse a statement and return the object wrapped in enum.
73    fn parse(parser: &mut Parser) -> Result<YangStmt, YangError>
74    where
75        Self::Arg: StmtArg,
76        Self: Sized,
77    {
78        let arg = Self::Arg::parse_arg(parser)?;
79
80        if Self::has_substmts() {
81            let token = parser.get_token()?;
82            match token {
83                Token::BlockBegin => {
84                    let substmts = Self::parse_substmts(parser)?;
85                    let token = parser.get_token()?;
86
87                    match token {
88                        Token::BlockEnd => Ok(Self::new_with_substmts(arg, substmts)),
89                        _ => Err(YangError::UnexpectedToken(token.to_string())),
90                    }
91                }
92                _ => Err(YangError::UnexpectedToken(token.to_string())),
93            }
94        } else if Self::opt_substmts() {
95            let token = parser.get_token()?;
96            match token {
97                Token::StatementEnd => Ok(Self::new_with_arg(arg)),
98                Token::BlockBegin => {
99                    let substmts = Self::parse_substmts(parser)?;
100                    let token = parser.get_token()?;
101                    match token {
102                        Token::BlockEnd => Ok(Self::new_with_substmts(arg, substmts)),
103                        _ => Err(YangError::UnexpectedToken(token.to_string())),
104                    }
105                }
106                _ => Err(YangError::UnexpectedToken(token.to_string())),
107            }
108        } else {
109            let token = parser.get_token()?;
110            match token {
111                Token::StatementEnd => Ok(Self::new_with_arg(arg)),
112                _ => Err(YangError::UnexpectedToken(token.to_string())),
113            }
114        }
115    }
116}
117
118///
119/// The "module" Statement.
120///
121#[derive(Debug, Clone, PartialEq, Getters)]
122pub struct ModuleStmt {
123    /// "identifier-arg".
124    arg: Identifier,
125
126    /// "module-header" statements.
127    module_header: ModuleHeaderStmts,
128
129    /// "linkage" statements.
130    linkage: LinkageStmts,
131
132    /// "meta" statements.
133    meta: MetaStmts,
134
135    /// "revision" statements.
136    revision: RevisionStmts,
137
138    /// "body" statements.
139    body: BodyStmts,
140}
141
142impl Stmt for ModuleStmt {
143    /// Arg type.
144    type Arg = Identifier;
145
146    /// Sub Statements.
147    type SubStmts = (
148        ModuleHeaderStmts,
149        LinkageStmts,
150        MetaStmts,
151        RevisionStmts,
152        BodyStmts,
153    );
154
155    /// Return statement keyword.
156    fn keyword() -> Keyword {
157        "module"
158    }
159
160    /// Return true if this statement has substatements.
161    fn has_substmts() -> bool {
162        true
163    }
164
165    /// Constructor with tuple of substatements. Panic if it is not defined.
166    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
167    where
168        Self: Sized,
169    {
170        YangStmt::ModuleStmt(ModuleStmt {
171            arg,
172            module_header: substmts.0,
173            linkage: substmts.1,
174            meta: substmts.2,
175            revision: substmts.3,
176            body: substmts.4,
177        })
178    }
179
180    /// Parse substatements.
181    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
182        let module_header = ModuleHeaderStmts::parse(parser)?;
183        let linkage = LinkageStmts::parse(parser)?;
184        let meta = MetaStmts::parse(parser)?;
185        let revision = RevisionStmts::parse(parser)?;
186        let body = BodyStmts::parse(parser)?;
187
188        Ok((module_header, linkage, meta, revision, body))
189    }
190}
191
192///
193/// The "submodule" Statement.
194///
195#[derive(Debug, Clone, PartialEq, Getters)]
196pub struct SubmoduleStmt {
197    /// "identifier-arg".
198    arg: Identifier,
199
200    /// "submodule-header" statements.
201    submodule_header: SubmoduleHeaderStmts,
202
203    /// "linkage" statements.
204    linkage: LinkageStmts,
205
206    /// "meta" statements.
207    meta: MetaStmts,
208
209    /// "revision" statements.
210    revision: RevisionStmts,
211
212    /// "body" statements.
213    body: BodyStmts,
214}
215
216impl Stmt for SubmoduleStmt {
217    /// Arg type.
218    type Arg = Identifier;
219
220    /// Sub Statements.
221    type SubStmts = (
222        SubmoduleHeaderStmts,
223        LinkageStmts,
224        MetaStmts,
225        RevisionStmts,
226        BodyStmts,
227    );
228
229    /// Return statement keyword.
230    fn keyword() -> Keyword {
231        "submodule"
232    }
233
234    /// Return true if this statement has substatements.
235    fn has_substmts() -> bool {
236        true
237    }
238
239    /// Constructor with tuple of substatements. Panic if it is not defined.
240    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
241    where
242        Self: Sized,
243    {
244        YangStmt::SubmoduleStmt(SubmoduleStmt {
245            arg,
246            submodule_header: substmts.0,
247            linkage: substmts.1,
248            meta: substmts.2,
249            revision: substmts.3,
250            body: substmts.4,
251        })
252    }
253
254    /// Parse substatements.
255    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
256        let submodule_header = SubmoduleHeaderStmts::parse(parser)?;
257        let linkage = LinkageStmts::parse(parser)?;
258        let meta = MetaStmts::parse(parser)?;
259        let revision = RevisionStmts::parse(parser)?;
260        let body = BodyStmts::parse(parser)?;
261
262        Ok((submodule_header, linkage, meta, revision, body))
263    }
264}
265
266///
267/// The "yang-version" Statement.
268///
269#[derive(Debug, Clone, PartialEq, Getters)]
270pub struct YangVersionStmt {
271    /// Yang version arg.
272    arg: YangVersionArg,
273}
274
275impl Stmt for YangVersionStmt {
276    /// Arg type.
277    type Arg = YangVersionArg;
278
279    /// Sub Statements.
280    type SubStmts = ();
281
282    /// Return statement keyword.
283    fn keyword() -> Keyword {
284        "yang-version"
285    }
286
287    /// Constructor with a single arg. Panic if it is not defined.
288    fn new_with_arg(arg: Self::Arg) -> YangStmt
289    where
290        Self: Sized,
291    {
292        YangStmt::YangVersionStmt(YangVersionStmt { arg })
293    }
294}
295
296///
297/// The "import" Statement.
298///
299#[derive(Debug, Clone, PartialEq, Getters)]
300pub struct ImportStmt {
301    /// "identifier-arg".
302    arg: Identifier,
303
304    /// "prefix" statement.
305    prefix: PrefixStmt,
306
307    /// "revision-date" statement.
308    revision_date: Option<RevisionDateStmt>,
309
310    /// "description" statement.
311    description: Option<DescriptionStmt>,
312
313    /// "reference" statement.
314    reference: Option<ReferenceStmt>,
315}
316
317impl Stmt for ImportStmt {
318    /// Arg type.
319    type Arg = Identifier;
320
321    /// Sub Statements.
322    type SubStmts = (
323        PrefixStmt,
324        Option<RevisionDateStmt>,
325        Option<DescriptionStmt>,
326        Option<ReferenceStmt>,
327    );
328
329    /// Return statement keyword.
330    fn keyword() -> Keyword {
331        "import"
332    }
333
334    /// Return true if this statement has substatements.
335    fn has_substmts() -> bool {
336        true
337    }
338
339    /// Return substatements definition.
340    fn substmts_def() -> Vec<SubStmtDef> {
341        vec![
342            SubStmtDef::HasOne(SubStmtWith::Stmt(PrefixStmt::keyword)),
343            SubStmtDef::Optional(SubStmtWith::Stmt(RevisionDateStmt::keyword)),
344            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
345            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
346        ]
347    }
348
349    /// Constructor with tuple of substatements. Panic if it is not defined.
350    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
351    where
352        Self: Sized,
353    {
354        YangStmt::ImportStmt(ImportStmt {
355            arg,
356            prefix: substmts.0,
357            revision_date: substmts.1,
358            description: substmts.2,
359            reference: substmts.3,
360        })
361    }
362
363    /// Parse substatements.
364    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
365        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
366
367        Ok((
368            collect_a_stmt!(stmts, PrefixStmt)?,
369            collect_opt_stmt!(stmts, RevisionDateStmt)?,
370            collect_opt_stmt!(stmts, DescriptionStmt)?,
371            collect_opt_stmt!(stmts, ReferenceStmt)?,
372        ))
373    }
374}
375
376///
377/// The "include" Statement.
378///
379#[derive(Debug, Clone, PartialEq, Getters)]
380pub struct IncludeStmt {
381    /// "identifier-arg".
382    arg: Identifier,
383
384    /// "revision-date" statement.
385    revision_date: Option<RevisionDateStmt>,
386
387    /// "description" statement.
388    description: Option<DescriptionStmt>,
389
390    /// "reference" statement.
391    reference: Option<ReferenceStmt>,
392}
393
394impl Stmt for IncludeStmt {
395    /// Arg type.
396    type Arg = Identifier;
397
398    /// Sub Statements.
399    type SubStmts = (
400        Option<RevisionDateStmt>,
401        Option<DescriptionStmt>,
402        Option<ReferenceStmt>,
403    );
404
405    /// Return statement keyword.
406    fn keyword() -> Keyword {
407        "include"
408    }
409
410    /// Return true if this statement has sub-statements optionally.
411    fn opt_substmts() -> bool {
412        true
413    }
414
415    /// Return substatements definition.
416    fn substmts_def() -> Vec<SubStmtDef> {
417        vec![
418            SubStmtDef::Optional(SubStmtWith::Stmt(RevisionDateStmt::keyword)),
419            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
420            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
421        ]
422    }
423
424    /// Constructor with a single arg. Panic if it is not defined.
425    fn new_with_arg(arg: Self::Arg) -> YangStmt
426    where
427        Self: Sized,
428    {
429        YangStmt::IncludeStmt(IncludeStmt {
430            arg,
431            revision_date: None,
432            description: None,
433            reference: None,
434        })
435    }
436
437    /// Constructor with tuple of substatements. Panic if it is not defined.
438    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
439    where
440        Self: Sized,
441    {
442        YangStmt::IncludeStmt(IncludeStmt {
443            arg,
444            revision_date: substmts.0,
445            description: substmts.1,
446            reference: substmts.2,
447        })
448    }
449
450    /// Parse substatements.
451    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
452        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
453
454        Ok((
455            collect_opt_stmt!(stmts, RevisionDateStmt)?,
456            collect_opt_stmt!(stmts, DescriptionStmt)?,
457            collect_opt_stmt!(stmts, ReferenceStmt)?,
458        ))
459    }
460}
461
462///
463/// The "namespace" Statement.
464///
465#[derive(Debug, Clone, PartialEq, Getters)]
466pub struct NamespaceStmt {
467    /// URI.
468    arg: Url,
469}
470
471impl Stmt for NamespaceStmt {
472    /// Arg type.
473    type Arg = Url;
474
475    /// Sub Statements.
476    type SubStmts = ();
477
478    /// Return statement keyword.
479    fn keyword() -> Keyword {
480        "namespace"
481    }
482
483    /// Constructor with a single arg. Panic if it is not defined.
484    fn new_with_arg(arg: Self::Arg) -> YangStmt
485    where
486        Self: Sized,
487    {
488        YangStmt::NamespaceStmt(NamespaceStmt { arg })
489    }
490}
491
492///
493/// The "prefix" Statement.
494///
495#[derive(Debug, Clone, PartialEq, Getters)]
496pub struct PrefixStmt {
497    /// "dentifier-arg".
498    arg: Identifier,
499}
500
501impl Stmt for PrefixStmt {
502    /// Arg type.
503    type Arg = Identifier;
504
505    /// Sub Statements.
506    type SubStmts = ();
507
508    /// Return statement keyword.
509    fn keyword() -> Keyword {
510        "prefix"
511    }
512
513    /// Constructor with a single arg. Panic if it is not defined.
514    fn new_with_arg(arg: Self::Arg) -> YangStmt
515    where
516        Self: Sized,
517    {
518        YangStmt::PrefixStmt(PrefixStmt { arg })
519    }
520}
521
522///
523/// The "belongs-to" Statement.
524///
525#[derive(Debug, Clone, PartialEq, Getters)]
526pub struct BelongsToStmt {
527    /// "identifier-arg".
528    arg: Identifier,
529
530    /// "prefix" statement.
531    prefix: PrefixStmt,
532}
533
534impl Stmt for BelongsToStmt {
535    /// Arg type.
536    type Arg = Identifier;
537
538    /// Sub Statements.
539    type SubStmts = (PrefixStmt,);
540
541    /// Return statement keyword.
542    fn keyword() -> Keyword {
543        "belongs-to"
544    }
545
546    /// Return true if this statement has substatements.
547    fn has_substmts() -> bool {
548        true
549    }
550
551    /// Return substatements definition.
552    fn substmts_def() -> Vec<SubStmtDef> {
553        vec![SubStmtDef::HasOne(SubStmtWith::Stmt(PrefixStmt::keyword))]
554    }
555
556    /// Constructor with tuple of substatements. Panic if it is not defined.
557    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
558    where
559        Self: Sized,
560    {
561        YangStmt::BelongsToStmt(BelongsToStmt {
562            arg,
563            prefix: substmts.0,
564        })
565    }
566
567    /// Parse substatements.
568    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
569        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
570
571        Ok((collect_a_stmt!(stmts, PrefixStmt)?,))
572    }
573}
574
575///
576/// The "organization" Statement.
577///
578#[derive(Debug, Clone, PartialEq, Getters)]
579pub struct OrganizationStmt {
580    /// String.
581    arg: String,
582}
583
584impl Stmt for OrganizationStmt {
585    /// Arg type.
586    type Arg = String;
587
588    /// Sub Statements.
589    type SubStmts = ();
590
591    /// Return statement keyword.
592    fn keyword() -> Keyword {
593        "organization"
594    }
595
596    /// Constructor with a single arg. Panic if it is not defined.
597    fn new_with_arg(arg: Self::Arg) -> YangStmt
598    where
599        Self: Sized,
600    {
601        YangStmt::OrganizationStmt(OrganizationStmt { arg })
602    }
603}
604
605///
606/// The "contact" Statement.
607///
608#[derive(Debug, Clone, PartialEq, Getters)]
609pub struct ContactStmt {
610    /// String.
611    arg: String,
612}
613
614impl Stmt for ContactStmt {
615    /// Arg type.
616    type Arg = String;
617
618    /// Sub Statements.
619    type SubStmts = ();
620
621    /// Return statement keyword.
622    fn keyword() -> Keyword {
623        "contact"
624    }
625
626    /// Constructor with a single arg. Panic if it is not defined.
627    fn new_with_arg(arg: Self::Arg) -> YangStmt
628    where
629        Self: Sized,
630    {
631        YangStmt::ContactStmt(ContactStmt { arg })
632    }
633}
634
635///
636/// The "description" Statement.
637///
638#[derive(Debug, Clone, PartialEq, Getters)]
639pub struct DescriptionStmt {
640    /// String.
641    arg: String,
642}
643
644impl Stmt for DescriptionStmt {
645    /// Arg type.
646    type Arg = String;
647
648    /// Sub Statements.
649    type SubStmts = ();
650
651    /// Return statement keyword.
652    fn keyword() -> Keyword {
653        "description"
654    }
655
656    /// Constructor with a single arg. Panic if it is not defined.
657    fn new_with_arg(arg: Self::Arg) -> YangStmt
658    where
659        Self: Sized,
660    {
661        YangStmt::DescriptionStmt(DescriptionStmt { arg })
662    }
663}
664
665///
666/// The "reference" Statement.
667///
668#[derive(Debug, Clone, PartialEq, Getters)]
669pub struct ReferenceStmt {
670    /// String.
671    arg: String,
672}
673
674impl Stmt for ReferenceStmt {
675    /// Arg type.
676    type Arg = String;
677
678    /// Sub Statements.
679    type SubStmts = ();
680
681    /// Return statement keyword.
682    fn keyword() -> Keyword {
683        "reference"
684    }
685
686    /// Constructor with a single arg. Panic if it is not defined.
687    fn new_with_arg(arg: Self::Arg) -> YangStmt
688    where
689        Self: Sized,
690    {
691        YangStmt::ReferenceStmt(ReferenceStmt { arg })
692    }
693}
694
695///
696/// The "units" Statement.
697///
698#[derive(Debug, Clone, PartialEq, Getters)]
699pub struct UnitsStmt {
700    /// String.
701    arg: String,
702}
703
704impl Stmt for UnitsStmt {
705    /// Arg type.
706    type Arg = String;
707
708    /// Sub Statements.
709    type SubStmts = ();
710
711    /// Return statement keyword.
712    fn keyword() -> Keyword {
713        "units"
714    }
715
716    /// Constructor with a single arg. Panic if it is not defined.
717    fn new_with_arg(arg: Self::Arg) -> YangStmt
718    where
719        Self: Sized,
720    {
721        YangStmt::UnitsStmt(UnitsStmt { arg })
722    }
723}
724
725///
726/// The "revision" Statement.
727///
728#[derive(Debug, Clone, PartialEq, Getters)]
729pub struct RevisionStmt {
730    /// "revision-date".
731    arg: DateArg,
732
733    /// "description" statement..
734    description: Option<DescriptionStmt>,
735
736    /// "reference" statement.
737    reference: Option<ReferenceStmt>,
738}
739
740impl Stmt for RevisionStmt {
741    /// Arg type.
742    type Arg = DateArg;
743
744    /// Sub Statements.
745    type SubStmts = (Option<DescriptionStmt>, Option<ReferenceStmt>);
746
747    /// Return statement keyword.
748    fn keyword() -> Keyword {
749        "revision"
750    }
751
752    /// Return true if this statement has sub-statements optionally.
753    fn opt_substmts() -> bool {
754        true
755    }
756
757    /// Return substatements definition.
758    fn substmts_def() -> Vec<SubStmtDef> {
759        vec![
760            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
761            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
762        ]
763    }
764
765    /// Constructor with a single arg. Panic if it is not defined.
766    fn new_with_arg(arg: Self::Arg) -> YangStmt
767    where
768        Self: Sized,
769    {
770        YangStmt::RevisionStmt(RevisionStmt {
771            arg,
772            description: None,
773            reference: None,
774        })
775    }
776
777    /// Constructor with tuple of substatements. Panic if it is not defined.
778    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
779    where
780        Self: Sized,
781    {
782        YangStmt::RevisionStmt(RevisionStmt {
783            arg,
784            description: substmts.0,
785            reference: substmts.1,
786        })
787    }
788
789    /// Parse substatements.
790    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
791        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
792
793        Ok((
794            collect_opt_stmt!(stmts, DescriptionStmt)?,
795            collect_opt_stmt!(stmts, ReferenceStmt)?,
796        ))
797    }
798}
799
800///
801/// The "revision-date" Statement.
802///
803#[derive(Debug, Clone, PartialEq, Getters)]
804pub struct RevisionDateStmt {
805    /// "revision-date".
806    arg: DateArg,
807}
808
809impl Stmt for RevisionDateStmt {
810    /// Arg type.
811    type Arg = DateArg;
812
813    /// Sub Statements.
814    type SubStmts = ();
815
816    /// Return statement keyword.
817    fn keyword() -> Keyword {
818        "revision-date"
819    }
820
821    /// Constructor with a single arg. Panic if it is not defined.
822    fn new_with_arg(arg: Self::Arg) -> YangStmt
823    where
824        Self: Sized,
825    {
826        YangStmt::RevisionDateStmt(RevisionDateStmt { arg })
827    }
828}
829
830///
831/// The "extension" Statement.
832///
833#[derive(Debug, Clone, PartialEq, Getters)]
834pub struct ExtensionStmt {
835    /// "identifier-arg".
836    arg: Identifier,
837
838    /// "argument" statement.
839    argument: Option<ArgumentStmt>,
840
841    /// "status" statement.
842    status: Option<StatusStmt>,
843
844    /// "description" statement.
845    description: Option<DescriptionStmt>,
846
847    /// "reference" statement.
848    reference: Option<ReferenceStmt>,
849}
850
851impl Stmt for ExtensionStmt {
852    /// Arg type.
853    type Arg = Identifier;
854
855    /// Sub Statements.
856    type SubStmts = (
857        Option<ArgumentStmt>,
858        Option<StatusStmt>,
859        Option<DescriptionStmt>,
860        Option<ReferenceStmt>,
861    );
862
863    /// Return statement keyword.
864    fn keyword() -> Keyword {
865        "extension"
866    }
867
868    /// Return true if this statement has sub-statements optionally.
869    fn opt_substmts() -> bool {
870        true
871    }
872
873    /// Return substatements definition.
874    fn substmts_def() -> Vec<SubStmtDef> {
875        vec![
876            SubStmtDef::Optional(SubStmtWith::Stmt(ArgumentStmt::keyword)),
877            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
878            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
879            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
880        ]
881    }
882
883    /// Constructor with a single arg. Panic if it is not defined.
884    fn new_with_arg(arg: Self::Arg) -> YangStmt
885    where
886        Self: Sized,
887    {
888        YangStmt::ExtensionStmt(ExtensionStmt {
889            arg,
890            argument: None,
891            status: None,
892            description: None,
893            reference: None,
894        })
895    }
896
897    /// Constructor with tuple of substatements. Panic if it is not defined.
898    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
899    where
900        Self: Sized,
901    {
902        YangStmt::ExtensionStmt(ExtensionStmt {
903            arg,
904            argument: substmts.0,
905            status: substmts.1,
906            description: substmts.2,
907            reference: substmts.3,
908        })
909    }
910
911    /// Parse substatements.
912    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
913        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
914
915        Ok((
916            collect_opt_stmt!(stmts, ArgumentStmt)?,
917            collect_opt_stmt!(stmts, StatusStmt)?,
918            collect_opt_stmt!(stmts, DescriptionStmt)?,
919            collect_opt_stmt!(stmts, ReferenceStmt)?,
920        ))
921    }
922}
923
924///
925/// The "argument" Statement.
926///
927#[derive(Debug, Clone, PartialEq, Getters)]
928pub struct ArgumentStmt {
929    /// "identifier-arg".
930    arg: Identifier,
931
932    /// "yin-element" statement.
933    yin_element: Option<YinElementStmt>,
934}
935
936impl Stmt for ArgumentStmt {
937    /// Arg type.
938    type Arg = Identifier;
939
940    /// Sub Statements.
941    type SubStmts = (Option<YinElementStmt>,);
942
943    /// Return statement keyword.
944    fn keyword() -> Keyword {
945        "argument"
946    }
947
948    /// Return true if this statement has sub-statements optionally.
949    fn opt_substmts() -> bool {
950        true
951    }
952
953    /// Return substatements definition.
954    fn substmts_def() -> Vec<SubStmtDef> {
955        vec![SubStmtDef::Optional(SubStmtWith::Stmt(
956            YinElementStmt::keyword,
957        ))]
958    }
959
960    /// Constructor with a single arg. Panic if it is not defined.
961    fn new_with_arg(arg: Self::Arg) -> YangStmt
962    where
963        Self: Sized,
964    {
965        YangStmt::ArgumentStmt(ArgumentStmt {
966            arg,
967            yin_element: None,
968        })
969    }
970
971    /// Constructor with tuple of substatements. Panic if it is not defined.
972    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
973    where
974        Self: Sized,
975    {
976        YangStmt::ArgumentStmt(ArgumentStmt {
977            arg,
978            yin_element: substmts.0,
979        })
980    }
981
982    /// Parse substatements.
983    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
984        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
985
986        Ok((collect_opt_stmt!(stmts, YinElementStmt)?,))
987    }
988}
989
990///
991/// The "yin-element" Statement.
992///
993#[derive(Debug, Clone, PartialEq, Getters)]
994pub struct YinElementStmt {
995    /// "yin-element-arg".
996    arg: YinElementArg,
997}
998
999impl Stmt for YinElementStmt {
1000    /// Arg type.
1001    type Arg = YinElementArg;
1002
1003    /// Sub Statements.
1004    type SubStmts = ();
1005
1006    /// Return statement keyword.
1007    fn keyword() -> Keyword {
1008        "yin-element"
1009    }
1010
1011    /// Constructor with a single arg. Panic if it is not defined.
1012    fn new_with_arg(arg: Self::Arg) -> YangStmt
1013    where
1014        Self: Sized,
1015    {
1016        YangStmt::YinElementStmt(YinElementStmt { arg })
1017    }
1018}
1019
1020///
1021/// The "identity" Statement.
1022///
1023#[derive(Debug, Clone, PartialEq, Getters)]
1024pub struct IdentityStmt {
1025    /// "identifier-arg".
1026    arg: Identifier,
1027
1028    /// "if-feature" statement.
1029    if_feature: Vec<IfFeatureStmt>,
1030
1031    /// "base" statement.
1032    base: Vec<BaseStmt>,
1033
1034    /// "status" statement.
1035    status: Option<StatusStmt>,
1036
1037    /// "description" statement.
1038    description: Option<DescriptionStmt>,
1039
1040    /// "reference" statement.
1041    reference: Option<ReferenceStmt>,
1042}
1043
1044impl Stmt for IdentityStmt {
1045    /// Arg type.
1046    type Arg = Identifier;
1047
1048    /// Sub Statements.
1049    type SubStmts = (
1050        Vec<IfFeatureStmt>,
1051        Vec<BaseStmt>,
1052        Option<StatusStmt>,
1053        Option<DescriptionStmt>,
1054        Option<ReferenceStmt>,
1055    );
1056
1057    /// Return statement keyword.
1058    fn keyword() -> Keyword {
1059        "identity"
1060    }
1061
1062    /// Return true if this statement has sub-statements optionally.
1063    fn opt_substmts() -> bool {
1064        true
1065    }
1066
1067    /// Return substatements definition.
1068    fn substmts_def() -> Vec<SubStmtDef> {
1069        vec![
1070            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
1071            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(BaseStmt::keyword)),
1072            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
1073            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1074            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1075        ]
1076    }
1077
1078    /// Constructor with a single arg. Panic if it is not defined.
1079    fn new_with_arg(arg: Self::Arg) -> YangStmt
1080    where
1081        Self: Sized,
1082    {
1083        YangStmt::IdentityStmt(IdentityStmt {
1084            arg,
1085            if_feature: Vec::new(),
1086            base: Vec::new(),
1087            status: None,
1088            description: None,
1089            reference: None,
1090        })
1091    }
1092
1093    /// Constructor with tuple of substatements. Panic if it is not defined.
1094    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1095    where
1096        Self: Sized,
1097    {
1098        YangStmt::IdentityStmt(IdentityStmt {
1099            arg,
1100            if_feature: substmts.0,
1101            base: substmts.1,
1102            status: substmts.2,
1103            description: substmts.3,
1104            reference: substmts.4,
1105        })
1106    }
1107
1108    /// Parse substatements.
1109    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1110        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1111
1112        Ok((
1113            collect_vec_stmt!(stmts, IfFeatureStmt)?,
1114            collect_vec_stmt!(stmts, BaseStmt)?,
1115            collect_opt_stmt!(stmts, StatusStmt)?,
1116            collect_opt_stmt!(stmts, DescriptionStmt)?,
1117            collect_opt_stmt!(stmts, ReferenceStmt)?,
1118        ))
1119    }
1120}
1121
1122///
1123/// The "base" Statement.
1124///
1125#[derive(Debug, Clone, PartialEq, Getters)]
1126pub struct BaseStmt {
1127    /// "dentifier-ref-arg".
1128    arg: IdentifierRef,
1129}
1130
1131impl Stmt for BaseStmt {
1132    /// Arg type.
1133    type Arg = IdentifierRef;
1134
1135    /// Sub Statements.
1136    type SubStmts = ();
1137
1138    /// Return statement keyword.
1139    fn keyword() -> Keyword {
1140        "base"
1141    }
1142
1143    /// Constructor with a single arg. Panic if it is not defined.
1144    fn new_with_arg(arg: Self::Arg) -> YangStmt
1145    where
1146        Self: Sized,
1147    {
1148        YangStmt::BaseStmt(BaseStmt { arg })
1149    }
1150}
1151
1152///
1153/// The "feature" Statement.
1154///
1155#[derive(Debug, Clone, PartialEq, Getters)]
1156pub struct FeatureStmt {
1157    /// "identifier-arg".
1158    arg: Identifier,
1159
1160    /// "if-feature" statement.
1161    if_feature: Vec<IfFeatureStmt>,
1162
1163    /// "status" statement.
1164    status: Option<StatusStmt>,
1165
1166    /// "description" statement.
1167    description: Option<DescriptionStmt>,
1168
1169    /// "reference" statement.
1170    reference: Option<ReferenceStmt>,
1171}
1172
1173impl Stmt for FeatureStmt {
1174    /// Arg type.
1175    type Arg = Identifier;
1176
1177    /// Sub Statements.
1178    type SubStmts = (
1179        Vec<IfFeatureStmt>,
1180        Option<StatusStmt>,
1181        Option<DescriptionStmt>,
1182        Option<ReferenceStmt>,
1183    );
1184
1185    /// Return statement keyword.
1186    fn keyword() -> Keyword {
1187        "feature"
1188    }
1189
1190    /// Return true if this statement has sub-statements optionally.
1191    fn opt_substmts() -> bool {
1192        true
1193    }
1194
1195    /// Return substatements definition.
1196    fn substmts_def() -> Vec<SubStmtDef> {
1197        vec![
1198            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
1199            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
1200            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1201            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1202        ]
1203    }
1204
1205    /// Constructor with a single arg. Panic if it is not defined.
1206    fn new_with_arg(arg: Self::Arg) -> YangStmt
1207    where
1208        Self: Sized,
1209    {
1210        YangStmt::FeatureStmt(FeatureStmt {
1211            arg,
1212            if_feature: Vec::new(),
1213            status: None,
1214            description: None,
1215            reference: None,
1216        })
1217    }
1218
1219    /// Constructor with tuple of substatements. Panic if it is not defined.
1220    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1221    where
1222        Self: Sized,
1223    {
1224        YangStmt::FeatureStmt(FeatureStmt {
1225            arg,
1226            if_feature: substmts.0,
1227            status: substmts.1,
1228            description: substmts.2,
1229            reference: substmts.3,
1230        })
1231    }
1232
1233    /// Parse substatements.
1234    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1235        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1236
1237        Ok((
1238            collect_vec_stmt!(stmts, IfFeatureStmt)?,
1239            collect_opt_stmt!(stmts, StatusStmt)?,
1240            collect_opt_stmt!(stmts, DescriptionStmt)?,
1241            collect_opt_stmt!(stmts, ReferenceStmt)?,
1242        ))
1243    }
1244}
1245
1246///
1247/// The "if-feature" Statement.
1248///
1249#[derive(Debug, Clone, PartialEq, Getters)]
1250pub struct IfFeatureStmt {
1251    /// "if-feature-expr-str".
1252    arg: IfFeatureExpr,
1253}
1254
1255impl Stmt for IfFeatureStmt {
1256    /// Arg type.
1257    type Arg = IfFeatureExpr;
1258
1259    /// Sub Statements.
1260    type SubStmts = ();
1261
1262    /// Return statement keyword.
1263    fn keyword() -> Keyword {
1264        "if-feature"
1265    }
1266
1267    /// Constructor with a single arg. Panic if it is not defined.
1268    fn new_with_arg(arg: Self::Arg) -> YangStmt
1269    where
1270        Self: Sized,
1271    {
1272        YangStmt::IfFeatureStmt(IfFeatureStmt { arg })
1273    }
1274}
1275
1276///
1277/// The "typedef" Statement.
1278///
1279#[derive(Debug, Clone, PartialEq, Getters)]
1280pub struct TypedefStmt {
1281    /// "identifier-arg".
1282    arg: Identifier,
1283
1284    /// "type" statement.
1285    type_: TypeStmt,
1286
1287    /// "units" statement.
1288    units: Option<UnitsStmt>,
1289
1290    /// "default" statement.
1291    default: Option<DefaultStmt>,
1292
1293    /// "status" statement.
1294    status: Option<StatusStmt>,
1295
1296    /// "description" statement.
1297    description: Option<DescriptionStmt>,
1298
1299    /// "reference" statement.
1300    reference: Option<ReferenceStmt>,
1301}
1302
1303impl Stmt for TypedefStmt {
1304    /// Arg type.
1305    type Arg = Identifier;
1306
1307    /// Sub Statements.
1308    type SubStmts = (
1309        TypeStmt,
1310        Option<UnitsStmt>,
1311        Option<DefaultStmt>,
1312        Option<StatusStmt>,
1313        Option<DescriptionStmt>,
1314        Option<ReferenceStmt>,
1315    );
1316
1317    /// Return statement keyword.
1318    fn keyword() -> Keyword {
1319        "typedef"
1320    }
1321
1322    /// Return true if this statement has substatements.
1323    fn has_substmts() -> bool {
1324        true
1325    }
1326
1327    /// Return substatements definition.
1328    fn substmts_def() -> Vec<SubStmtDef> {
1329        vec![
1330            SubStmtDef::HasOne(SubStmtWith::Stmt(TypeStmt::keyword)),
1331            SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
1332            SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
1333            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
1334            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1335            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1336        ]
1337    }
1338
1339    /// Constructor with tuple of substatements. Panic if it is not defined.
1340    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1341    where
1342        Self: Sized,
1343    {
1344        YangStmt::TypedefStmt(TypedefStmt {
1345            arg,
1346            type_: substmts.0,
1347            units: substmts.1,
1348            default: substmts.2,
1349            status: substmts.3,
1350            description: substmts.4,
1351            reference: substmts.5,
1352        })
1353    }
1354
1355    /// Parse substatements.
1356    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1357        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1358
1359        Ok((
1360            collect_a_stmt!(stmts, TypeStmt)?,
1361            collect_opt_stmt!(stmts, UnitsStmt)?,
1362            collect_opt_stmt!(stmts, DefaultStmt)?,
1363            collect_opt_stmt!(stmts, StatusStmt)?,
1364            collect_opt_stmt!(stmts, DescriptionStmt)?,
1365            collect_opt_stmt!(stmts, ReferenceStmt)?,
1366        ))
1367    }
1368}
1369
1370///
1371/// The "type" Statement.
1372///
1373#[derive(Debug, Clone, PartialEq, Getters)]
1374pub struct TypeStmt {
1375    /// "identifier-ref-arg".
1376    arg: IdentifierRef,
1377
1378    /// "type-body" statements.
1379    type_body: Option<TypeBodyStmts>,
1380}
1381
1382impl Stmt for TypeStmt {
1383    /// Arg type.
1384    type Arg = IdentifierRef;
1385
1386    /// Sub Statements.
1387    type SubStmts = Option<TypeBodyStmts>;
1388
1389    /// Return statement keyword.
1390    fn keyword() -> Keyword {
1391        "type"
1392    }
1393
1394    /// Return true if this statement has sub-statements optionally.
1395    fn opt_substmts() -> bool {
1396        true
1397    }
1398
1399    /// Constructor with a single arg. Panic if it is not defined.
1400    fn new_with_arg(arg: Self::Arg) -> YangStmt
1401    where
1402        Self: Sized,
1403    {
1404        YangStmt::TypeStmt(TypeStmt {
1405            arg,
1406            type_body: None,
1407        })
1408    }
1409
1410    /// Constructor with tuple of substatements. Panic if it is not defined.
1411    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1412    where
1413        Self: Sized,
1414    {
1415        YangStmt::TypeStmt(TypeStmt {
1416            arg,
1417            type_body: substmts,
1418        })
1419    }
1420
1421    /// Parse substatements.
1422    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1423        let type_body = TypeBodyStmts::parse(parser)?;
1424
1425        Ok(Some(type_body))
1426    }
1427}
1428
1429///
1430/// The "range" Statement.
1431///
1432#[derive(Debug, Clone, PartialEq, Getters)]
1433pub struct RangeStmt {
1434    /// "range-arg".
1435    arg: RangeArg,
1436
1437    /// "error-message" statement.
1438    error_message: Option<ErrorMessageStmt>,
1439
1440    /// "error-app-tag" statement.
1441    error_app_tag: Option<ErrorAppTagStmt>,
1442
1443    /// "description" statement.
1444    description: Option<DescriptionStmt>,
1445
1446    /// "reference" statement.
1447    reference: Option<ReferenceStmt>,
1448}
1449
1450impl Stmt for RangeStmt {
1451    /// Arg type.
1452    type Arg = RangeArg;
1453
1454    /// Sub Statements.
1455    type SubStmts = (
1456        Option<ErrorMessageStmt>,
1457        Option<ErrorAppTagStmt>,
1458        Option<DescriptionStmt>,
1459        Option<ReferenceStmt>,
1460    );
1461
1462    /// Return statement keyword.
1463    fn keyword() -> Keyword {
1464        "range"
1465    }
1466
1467    /// Return true if this statement has sub-statements optionally.
1468    fn opt_substmts() -> bool {
1469        true
1470    }
1471
1472    /// Return substatements definition.
1473    fn substmts_def() -> Vec<SubStmtDef> {
1474        vec![
1475            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
1476            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
1477            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1478            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1479        ]
1480    }
1481
1482    /// Constructor with a single arg. Panic if it is not defined.
1483    fn new_with_arg(arg: Self::Arg) -> YangStmt
1484    where
1485        Self: Sized,
1486    {
1487        YangStmt::RangeStmt(RangeStmt {
1488            arg,
1489            error_message: None,
1490            error_app_tag: None,
1491            description: None,
1492            reference: None,
1493        })
1494    }
1495
1496    /// Constructor with tuple of substatements. Panic if it is not defined.
1497    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1498    where
1499        Self: Sized,
1500    {
1501        YangStmt::RangeStmt(RangeStmt {
1502            arg,
1503            error_message: substmts.0,
1504            error_app_tag: substmts.1,
1505            description: substmts.2,
1506            reference: substmts.3,
1507        })
1508    }
1509
1510    /// Parse substatements.
1511    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1512        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1513
1514        Ok((
1515            collect_opt_stmt!(stmts, ErrorMessageStmt)?,
1516            collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
1517            collect_opt_stmt!(stmts, DescriptionStmt)?,
1518            collect_opt_stmt!(stmts, ReferenceStmt)?,
1519        ))
1520    }
1521}
1522
1523///
1524/// The "fraction-digits" Statement.
1525///
1526#[derive(Debug, Clone, PartialEq, Getters)]
1527pub struct FractionDigitsStmt {
1528    /// "fraction-digits-arg".
1529    arg: FractionDigitsArg,
1530}
1531
1532impl Stmt for FractionDigitsStmt {
1533    /// Arg type.
1534    type Arg = FractionDigitsArg;
1535
1536    /// Sub Statements.
1537    type SubStmts = ();
1538
1539    /// Return statement keyword.
1540    fn keyword() -> Keyword {
1541        "fraction-digits"
1542    }
1543
1544    /// Constructor with a single arg. Panic if it is not defined.
1545    fn new_with_arg(arg: Self::Arg) -> YangStmt
1546    where
1547        Self: Sized,
1548    {
1549        YangStmt::FractionDigitsStmt(FractionDigitsStmt { arg })
1550    }
1551}
1552
1553///
1554/// The "length" Statement.
1555///
1556#[derive(Debug, Clone, PartialEq, Getters)]
1557pub struct LengthStmt {
1558    /// "length-arg".
1559    arg: LengthArg,
1560
1561    /// "error-message" statement.
1562    error_message: Option<ErrorMessageStmt>,
1563
1564    /// "error-app-tag" statement.
1565    error_app_tag: Option<ErrorAppTagStmt>,
1566
1567    /// "description" statement.
1568    description: Option<DescriptionStmt>,
1569
1570    /// "reference" statement.
1571    reference: Option<ReferenceStmt>,
1572}
1573
1574impl Stmt for LengthStmt {
1575    /// Arg type.
1576    type Arg = LengthArg;
1577
1578    /// Sub Statements.
1579    type SubStmts = (
1580        Option<ErrorMessageStmt>,
1581        Option<ErrorAppTagStmt>,
1582        Option<DescriptionStmt>,
1583        Option<ReferenceStmt>,
1584    );
1585
1586    /// Return statement keyword.
1587    fn keyword() -> Keyword {
1588        "length"
1589    }
1590
1591    /// Return true if this statement has sub-statements optionally.
1592    fn opt_substmts() -> bool {
1593        true
1594    }
1595
1596    /// Return substatements definition.
1597    fn substmts_def() -> Vec<SubStmtDef> {
1598        vec![
1599            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
1600            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
1601            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1602            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1603        ]
1604    }
1605
1606    /// Constructor with a single arg. Panic if it is not defined.
1607    fn new_with_arg(arg: Self::Arg) -> YangStmt
1608    where
1609        Self: Sized,
1610    {
1611        YangStmt::LengthStmt(LengthStmt {
1612            arg,
1613            error_message: None,
1614            error_app_tag: None,
1615            description: None,
1616            reference: None,
1617        })
1618    }
1619
1620    /// Constructor with tuple of substatements. Panic if it is not defined.
1621    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1622    where
1623        Self: Sized,
1624    {
1625        YangStmt::LengthStmt(LengthStmt {
1626            arg,
1627            error_message: substmts.0,
1628            error_app_tag: substmts.1,
1629            description: substmts.2,
1630            reference: substmts.3,
1631        })
1632    }
1633
1634    /// Parse substatements.
1635    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1636        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1637
1638        Ok((
1639            collect_opt_stmt!(stmts, ErrorMessageStmt)?,
1640            collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
1641            collect_opt_stmt!(stmts, DescriptionStmt)?,
1642            collect_opt_stmt!(stmts, ReferenceStmt)?,
1643        ))
1644    }
1645}
1646
1647///
1648/// The "pattern" Statement.
1649///
1650#[derive(Debug, Clone, PartialEq, Getters)]
1651pub struct PatternStmt {
1652    /// String.
1653    arg: String,
1654
1655    /// "modifier" statement.
1656    modifier: Option<ModifierStmt>,
1657
1658    /// "error-message" statement.
1659    error_message: Option<ErrorMessageStmt>,
1660
1661    /// "error-app-tag" statement.
1662    error_app_tag: Option<ErrorAppTagStmt>,
1663
1664    /// "description" statement.
1665    description: Option<DescriptionStmt>,
1666
1667    /// "reference" statement.
1668    reference: Option<ReferenceStmt>,
1669}
1670
1671impl Stmt for PatternStmt {
1672    /// Arg type.
1673    type Arg = String;
1674
1675    /// Sub Statements.
1676    type SubStmts = (
1677        Option<ModifierStmt>,
1678        Option<ErrorMessageStmt>,
1679        Option<ErrorAppTagStmt>,
1680        Option<DescriptionStmt>,
1681        Option<ReferenceStmt>,
1682    );
1683
1684    /// Return statement keyword.
1685    fn keyword() -> Keyword {
1686        "pattern"
1687    }
1688
1689    /// Return true if this statement has sub-statements optionally.
1690    fn opt_substmts() -> bool {
1691        true
1692    }
1693
1694    /// Return substatements definition.
1695    fn substmts_def() -> Vec<SubStmtDef> {
1696        vec![
1697            SubStmtDef::Optional(SubStmtWith::Stmt(ModifierStmt::keyword)),
1698            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
1699            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
1700            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1701            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1702        ]
1703    }
1704
1705    /// Constructor with a single arg. Panic if it is not defined.
1706    fn new_with_arg(arg: Self::Arg) -> YangStmt
1707    where
1708        Self: Sized,
1709    {
1710        YangStmt::PatternStmt(PatternStmt {
1711            arg,
1712            modifier: None,
1713            error_message: None,
1714            error_app_tag: None,
1715            description: None,
1716            reference: None,
1717        })
1718    }
1719
1720    /// Constructor with tuple of substatements. Panic if it is not defined.
1721    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1722    where
1723        Self: Sized,
1724    {
1725        YangStmt::PatternStmt(PatternStmt {
1726            arg,
1727            modifier: substmts.0,
1728            error_message: substmts.1,
1729            error_app_tag: substmts.2,
1730            description: substmts.3,
1731            reference: substmts.4,
1732        })
1733    }
1734
1735    /// Parse substatements.
1736    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1737        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1738
1739        Ok((
1740            collect_opt_stmt!(stmts, ModifierStmt)?,
1741            collect_opt_stmt!(stmts, ErrorMessageStmt)?,
1742            collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
1743            collect_opt_stmt!(stmts, DescriptionStmt)?,
1744            collect_opt_stmt!(stmts, ReferenceStmt)?,
1745        ))
1746    }
1747}
1748
1749///
1750/// The "modifier" Statement.
1751///
1752#[derive(Debug, Clone, PartialEq, Getters)]
1753pub struct ModifierStmt {
1754    /// "modifier-arg".
1755    arg: ModifierArg,
1756}
1757
1758impl Stmt for ModifierStmt {
1759    /// Arg type.
1760    type Arg = ModifierArg;
1761
1762    /// Sub Statements.
1763    type SubStmts = ();
1764
1765    /// Return statement keyword.
1766    fn keyword() -> Keyword {
1767        "modifier"
1768    }
1769
1770    /// Constructor with a single arg. Panic if it is not defined.
1771    fn new_with_arg(arg: Self::Arg) -> YangStmt
1772    where
1773        Self: Sized,
1774    {
1775        YangStmt::ModifierStmt(ModifierStmt { arg })
1776    }
1777}
1778
1779///
1780/// The "default" Statement.
1781///
1782#[derive(Debug, Clone, PartialEq, Getters)]
1783pub struct DefaultStmt {
1784    /// String.
1785    arg: String,
1786}
1787
1788impl Stmt for DefaultStmt {
1789    /// Arg type.
1790    type Arg = String;
1791
1792    /// Sub Statements.
1793    type SubStmts = ();
1794
1795    /// Return statement keyword.
1796    fn keyword() -> Keyword {
1797        "default"
1798    }
1799
1800    /// Constructor with a single arg. Panic if it is not defined.
1801    fn new_with_arg(arg: Self::Arg) -> YangStmt
1802    where
1803        Self: Sized,
1804    {
1805        YangStmt::DefaultStmt(DefaultStmt { arg })
1806    }
1807}
1808
1809///
1810/// The "enum" Statement.
1811///
1812#[derive(Debug, Clone, PartialEq, Getters)]
1813pub struct EnumStmt {
1814    /// String.
1815    arg: String,
1816
1817    /// "if-feature" statement.
1818    if_feature: Vec<IfFeatureStmt>,
1819
1820    /// "value" statement.
1821    value: Option<ValueStmt>,
1822
1823    /// "status" statement.
1824    status: Option<StatusStmt>,
1825
1826    /// "description" statement.
1827    description: Option<DescriptionStmt>,
1828
1829    /// "reference" statement.
1830    reference: Option<ReferenceStmt>,
1831}
1832
1833impl Stmt for EnumStmt {
1834    /// Arg type.
1835    type Arg = String;
1836
1837    /// Sub Statements.
1838    type SubStmts = (
1839        Vec<IfFeatureStmt>,
1840        Option<ValueStmt>,
1841        Option<StatusStmt>,
1842        Option<DescriptionStmt>,
1843        Option<ReferenceStmt>,
1844    );
1845
1846    /// Return statement keyword.
1847    fn keyword() -> Keyword {
1848        "enum"
1849    }
1850
1851    /// Return true if this statement has sub-statements optionally.
1852    fn opt_substmts() -> bool {
1853        true
1854    }
1855
1856    /// Return substatements definition.
1857    fn substmts_def() -> Vec<SubStmtDef> {
1858        vec![
1859            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
1860            SubStmtDef::Optional(SubStmtWith::Stmt(ValueStmt::keyword)),
1861            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
1862            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
1863            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
1864        ]
1865    }
1866
1867    /// Constructor with a single arg. Panic if it is not defined.
1868    fn new_with_arg(arg: Self::Arg) -> YangStmt
1869    where
1870        Self: Sized,
1871    {
1872        YangStmt::EnumStmt(EnumStmt {
1873            arg,
1874            if_feature: Vec::new(),
1875            value: None,
1876            status: None,
1877            description: None,
1878            reference: None,
1879        })
1880    }
1881
1882    /// Constructor with tuple of substatements. Panic if it is not defined.
1883    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
1884    where
1885        Self: Sized,
1886    {
1887        YangStmt::EnumStmt(EnumStmt {
1888            arg,
1889            if_feature: substmts.0,
1890            value: substmts.1,
1891            status: substmts.2,
1892            description: substmts.3,
1893            reference: substmts.4,
1894        })
1895    }
1896
1897    /// Parse substatements.
1898    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
1899        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
1900
1901        Ok((
1902            collect_vec_stmt!(stmts, IfFeatureStmt)?,
1903            collect_opt_stmt!(stmts, ValueStmt)?,
1904            collect_opt_stmt!(stmts, StatusStmt)?,
1905            collect_opt_stmt!(stmts, DescriptionStmt)?,
1906            collect_opt_stmt!(stmts, ReferenceStmt)?,
1907        ))
1908    }
1909}
1910
1911///
1912/// The "path" Statement.
1913///
1914#[derive(Debug, Clone, PartialEq, Getters)]
1915pub struct PathStmt {
1916    /// "path" arg.
1917    arg: PathArg,
1918}
1919
1920impl Stmt for PathStmt {
1921    /// Arg type.
1922    type Arg = PathArg;
1923
1924    /// Sub Statements.
1925    type SubStmts = ();
1926
1927    /// Return statement keyword.
1928    fn keyword() -> Keyword {
1929        "path"
1930    }
1931
1932    /// Constructor with a single arg. Panic if it is not defined.
1933    fn new_with_arg(arg: Self::Arg) -> YangStmt
1934    where
1935        Self: Sized,
1936    {
1937        YangStmt::PathStmt(PathStmt { arg })
1938    }
1939}
1940
1941///
1942/// The "require-instance" Statement.
1943///
1944#[derive(Debug, Clone, PartialEq, Getters)]
1945pub struct RequireInstanceStmt {
1946    /// "require-instance" arg.
1947    arg: RequireInstanceArg,
1948}
1949
1950impl Stmt for RequireInstanceStmt {
1951    /// Arg type.
1952    type Arg = RequireInstanceArg;
1953
1954    /// Sub Statements.
1955    type SubStmts = ();
1956
1957    /// Return statement keyword.
1958    fn keyword() -> Keyword {
1959        "require-instance"
1960    }
1961
1962    /// Constructor with a single arg. Panic if it is not defined.
1963    fn new_with_arg(arg: Self::Arg) -> YangStmt
1964    where
1965        Self: Sized,
1966    {
1967        YangStmt::RequireInstanceStmt(RequireInstanceStmt { arg })
1968    }
1969}
1970
1971///
1972/// The "bit" Statement.
1973///
1974#[derive(Debug, Clone, PartialEq, Getters)]
1975pub struct BitStmt {
1976    /// "identifier" arg.
1977    arg: Identifier,
1978
1979    /// "if-feature" statement.
1980    if_feature: Vec<IfFeatureStmt>,
1981
1982    /// "position" statement.
1983    position: Option<PositionStmt>,
1984
1985    /// "status" statement.
1986    status: Option<StatusStmt>,
1987
1988    /// "description" statement.
1989    description: Option<DescriptionStmt>,
1990
1991    /// "reference" statement.
1992    reference: Option<ReferenceStmt>,
1993}
1994
1995impl Stmt for BitStmt {
1996    /// Arg type.
1997    type Arg = Identifier;
1998
1999    /// Sub Statements.
2000    type SubStmts = (
2001        Vec<IfFeatureStmt>,
2002        Option<PositionStmt>,
2003        Option<StatusStmt>,
2004        Option<DescriptionStmt>,
2005        Option<ReferenceStmt>,
2006    );
2007
2008    /// Return statement keyword.
2009    fn keyword() -> Keyword {
2010        "bit"
2011    }
2012
2013    /// Return true if this statement has sub-statements optionally.
2014    fn opt_substmts() -> bool {
2015        true
2016    }
2017
2018    /// Return substatements definition.
2019    fn substmts_def() -> Vec<SubStmtDef> {
2020        vec![
2021            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
2022            SubStmtDef::Optional(SubStmtWith::Stmt(PositionStmt::keyword)),
2023            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
2024            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
2025            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
2026        ]
2027    }
2028
2029    /// Constructor with a single arg. Panic if it is not defined.
2030    fn new_with_arg(arg: Self::Arg) -> YangStmt
2031    where
2032        Self: Sized,
2033    {
2034        YangStmt::BitStmt(BitStmt {
2035            arg,
2036            if_feature: Vec::new(),
2037            position: None,
2038            status: None,
2039            description: None,
2040            reference: None,
2041        })
2042    }
2043
2044    /// Constructor with tuple of substatements. Panic if it is not defined.
2045    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
2046    where
2047        Self: Sized,
2048    {
2049        YangStmt::BitStmt(BitStmt {
2050            arg,
2051            if_feature: substmts.0,
2052            position: substmts.1,
2053            status: substmts.2,
2054            description: substmts.3,
2055            reference: substmts.4,
2056        })
2057    }
2058
2059    /// Parse substatements.
2060    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
2061        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
2062
2063        Ok((
2064            collect_vec_stmt!(stmts, IfFeatureStmt)?,
2065            collect_opt_stmt!(stmts, PositionStmt)?,
2066            collect_opt_stmt!(stmts, StatusStmt)?,
2067            collect_opt_stmt!(stmts, DescriptionStmt)?,
2068            collect_opt_stmt!(stmts, ReferenceStmt)?,
2069        ))
2070    }
2071}
2072
2073///
2074/// The "position" Statement.
2075///
2076#[derive(Debug, Clone, PartialEq, Getters)]
2077pub struct PositionStmt {
2078    /// "position-value-arg".
2079    arg: PositionValueArg,
2080}
2081
2082impl Stmt for PositionStmt {
2083    /// Arg type.
2084    type Arg = PositionValueArg;
2085
2086    /// Sub Statements.
2087    type SubStmts = ();
2088
2089    /// Return statement keyword.
2090    fn keyword() -> Keyword {
2091        "position"
2092    }
2093
2094    /// Constructor with a single arg. Panic if it is not defined.
2095    fn new_with_arg(arg: Self::Arg) -> YangStmt
2096    where
2097        Self: Sized,
2098    {
2099        YangStmt::PositionStmt(PositionStmt { arg })
2100    }
2101}
2102
2103///
2104/// The "status" Statement.
2105///
2106#[derive(Debug, Clone, PartialEq, Getters)]
2107pub struct StatusStmt {
2108    /// "status-arg".
2109    arg: StatusArg,
2110}
2111
2112impl Stmt for StatusStmt {
2113    /// Arg type.
2114    type Arg = StatusArg;
2115
2116    /// Sub Statements.
2117    type SubStmts = ();
2118
2119    /// Return statement keyword.
2120    fn keyword() -> Keyword {
2121        "status"
2122    }
2123
2124    /// Constructor with a single arg. Panic if it is not defined.
2125    fn new_with_arg(arg: Self::Arg) -> YangStmt
2126    where
2127        Self: Sized,
2128    {
2129        YangStmt::StatusStmt(StatusStmt { arg })
2130    }
2131}
2132
2133///
2134/// The "config" Statement.
2135///
2136#[derive(Debug, Clone, PartialEq, Getters)]
2137pub struct ConfigStmt {
2138    /// "config-arg".
2139    arg: ConfigArg,
2140}
2141
2142impl Stmt for ConfigStmt {
2143    /// Arg type.
2144    type Arg = ConfigArg;
2145
2146    /// Sub Statements.
2147    type SubStmts = ();
2148
2149    /// Return statement keyword.
2150    fn keyword() -> Keyword {
2151        "config"
2152    }
2153
2154    /// Constructor with a single arg. Panic if it is not defined.
2155    fn new_with_arg(arg: Self::Arg) -> YangStmt
2156    where
2157        Self: Sized,
2158    {
2159        YangStmt::ConfigStmt(ConfigStmt { arg })
2160    }
2161}
2162
2163///
2164/// The "mandatory" Statement.
2165///
2166#[derive(Debug, Clone, PartialEq, Getters)]
2167pub struct MandatoryStmt {
2168    /// "mandatory-arg".
2169    arg: MandatoryArg,
2170}
2171
2172impl Stmt for MandatoryStmt {
2173    /// Arg type.
2174    type Arg = MandatoryArg;
2175
2176    /// Sub Statements.
2177    type SubStmts = ();
2178
2179    /// Return statement keyword.
2180    fn keyword() -> Keyword {
2181        "mandatory"
2182    }
2183
2184    /// Constructor with a single arg. Panic if it is not defined.
2185    fn new_with_arg(arg: Self::Arg) -> YangStmt
2186    where
2187        Self: Sized,
2188    {
2189        YangStmt::MandatoryStmt(MandatoryStmt { arg })
2190    }
2191}
2192
2193///
2194/// The "presence" Statement.
2195///
2196#[derive(Debug, Clone, PartialEq, Getters)]
2197pub struct PresenceStmt {
2198    /// String.
2199    arg: String,
2200}
2201
2202impl Stmt for PresenceStmt {
2203    /// Arg type.
2204    type Arg = String;
2205
2206    /// Sub Statements.
2207    type SubStmts = ();
2208
2209    /// Return statement keyword.
2210    fn keyword() -> Keyword {
2211        "presence"
2212    }
2213
2214    /// Constructor with a single arg. Panic if it is not defined.
2215    fn new_with_arg(arg: Self::Arg) -> YangStmt
2216    where
2217        Self: Sized,
2218    {
2219        YangStmt::PresenceStmt(PresenceStmt { arg })
2220    }
2221}
2222
2223///
2224/// The "ordered-by" Statement.
2225///
2226#[derive(Debug, Clone, PartialEq, Getters)]
2227pub struct OrderedByStmt {
2228    /// "ordered-by-arg".
2229    arg: OrderedByArg,
2230}
2231
2232impl Stmt for OrderedByStmt {
2233    /// Arg type.
2234    type Arg = OrderedByArg;
2235
2236    /// Sub Statements.
2237    type SubStmts = ();
2238
2239    /// Return statement keyword.
2240    fn keyword() -> Keyword {
2241        "ordered-by"
2242    }
2243
2244    /// Constructor with a single arg. Panic if it is not defined.
2245    fn new_with_arg(arg: Self::Arg) -> YangStmt
2246    where
2247        Self: Sized,
2248    {
2249        YangStmt::OrderedByStmt(OrderedByStmt { arg })
2250    }
2251}
2252
2253///
2254/// The "must" Statement.
2255///
2256#[derive(Debug, Clone, PartialEq, Getters)]
2257pub struct MustStmt {
2258    /// String.
2259    arg: String,
2260
2261    /// Error-message statement.
2262    error_message: Option<ErrorMessageStmt>,
2263
2264    /// Error-app-tag statement.
2265    error_app_tag: Option<ErrorAppTagStmt>,
2266
2267    /// "description" statement.
2268    description: Option<DescriptionStmt>,
2269
2270    /// "reference" statement.
2271    reference: Option<ReferenceStmt>,
2272}
2273
2274impl Stmt for MustStmt {
2275    /// Arg type.
2276    type Arg = String;
2277
2278    /// Sub Statements.
2279    type SubStmts = (
2280        Option<ErrorMessageStmt>,
2281        Option<ErrorAppTagStmt>,
2282        Option<DescriptionStmt>,
2283        Option<ReferenceStmt>,
2284    );
2285
2286    /// Return statement keyword.
2287    fn keyword() -> Keyword {
2288        "must"
2289    }
2290
2291    /// Return true if this statement has sub-statements optionally.
2292    fn opt_substmts() -> bool {
2293        true
2294    }
2295
2296    /// Return substatements definition.
2297    fn substmts_def() -> Vec<SubStmtDef> {
2298        vec![
2299            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
2300            SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
2301            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
2302            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
2303        ]
2304    }
2305
2306    /// Constructor with a single arg. Panic if it is not defined.
2307    fn new_with_arg(arg: Self::Arg) -> YangStmt
2308    where
2309        Self: Sized,
2310    {
2311        YangStmt::MustStmt(MustStmt {
2312            arg,
2313            error_message: None,
2314            error_app_tag: None,
2315            description: None,
2316            reference: None,
2317        })
2318    }
2319
2320    /// Constructor with tuple of substatements. Panic if it is not defined.
2321    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
2322    where
2323        Self: Sized,
2324    {
2325        YangStmt::MustStmt(MustStmt {
2326            arg,
2327            error_message: substmts.0,
2328            error_app_tag: substmts.1,
2329            description: substmts.2,
2330            reference: substmts.3,
2331        })
2332    }
2333
2334    /// Parse substatements.
2335    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
2336        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
2337
2338        Ok((
2339            collect_opt_stmt!(stmts, ErrorMessageStmt)?,
2340            collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
2341            collect_opt_stmt!(stmts, DescriptionStmt)?,
2342            collect_opt_stmt!(stmts, ReferenceStmt)?,
2343        ))
2344    }
2345}
2346
2347///
2348/// The "error-message" Statement.
2349///
2350#[derive(Debug, Clone, PartialEq, Getters)]
2351pub struct ErrorMessageStmt {
2352    /// String.
2353    arg: String,
2354}
2355
2356impl Stmt for ErrorMessageStmt {
2357    /// Arg type.
2358    type Arg = String;
2359
2360    /// Sub Statements.
2361    type SubStmts = ();
2362
2363    /// Return statement keyword.
2364    fn keyword() -> Keyword {
2365        "error-message"
2366    }
2367
2368    /// Constructor with a single arg. Panic if it is not defined.
2369    fn new_with_arg(arg: Self::Arg) -> YangStmt
2370    where
2371        Self: Sized,
2372    {
2373        YangStmt::ErrorMessageStmt(ErrorMessageStmt { arg })
2374    }
2375}
2376
2377///
2378/// The "error-app-tag" Statement.
2379///
2380#[derive(Debug, Clone, PartialEq, Getters)]
2381pub struct ErrorAppTagStmt {
2382    /// String.
2383    arg: String,
2384}
2385
2386impl Stmt for ErrorAppTagStmt {
2387    /// Arg type.
2388    type Arg = String;
2389
2390    /// Sub Statements.
2391    type SubStmts = ();
2392
2393    /// Return statement keyword.
2394    fn keyword() -> Keyword {
2395        "error-app-tag"
2396    }
2397
2398    /// Constructor with a single arg. Panic if it is not defined.
2399    fn new_with_arg(arg: Self::Arg) -> YangStmt
2400    where
2401        Self: Sized,
2402    {
2403        YangStmt::ErrorAppTagStmt(ErrorAppTagStmt { arg })
2404    }
2405}
2406
2407///
2408/// The "min-elements" Statement.
2409///
2410#[derive(Debug, Clone, PartialEq, Getters)]
2411pub struct MinElementsStmt {
2412    /// "min-value-arg".
2413    arg: MinValueArg,
2414}
2415
2416impl Stmt for MinElementsStmt {
2417    /// Arg type.
2418    type Arg = MinValueArg;
2419
2420    /// Sub Statements.
2421    type SubStmts = ();
2422
2423    /// Return statement keyword.
2424    fn keyword() -> Keyword {
2425        "min-elements"
2426    }
2427
2428    /// Constructor with a single arg. Panic if it is not defined.
2429    fn new_with_arg(arg: Self::Arg) -> YangStmt
2430    where
2431        Self: Sized,
2432    {
2433        YangStmt::MinElementsStmt(MinElementsStmt { arg })
2434    }
2435}
2436
2437///
2438/// The "max-elements" Statement.
2439///
2440#[derive(Debug, Clone, PartialEq, Getters)]
2441pub struct MaxElementsStmt {
2442    /// "max-value-arg".
2443    arg: MaxValueArg,
2444}
2445
2446impl Stmt for MaxElementsStmt {
2447    /// Arg type.
2448    type Arg = MaxValueArg;
2449
2450    /// Sub Statements.
2451    type SubStmts = ();
2452
2453    /// Return statement keyword.
2454    fn keyword() -> Keyword {
2455        "max-elements"
2456    }
2457
2458    /// Constructor with a single arg. Panic if it is not defined.
2459    fn new_with_arg(arg: Self::Arg) -> YangStmt
2460    where
2461        Self: Sized,
2462    {
2463        YangStmt::MaxElementsStmt(MaxElementsStmt { arg })
2464    }
2465}
2466
2467///
2468/// The "value" Statement.
2469///
2470#[derive(Debug, Clone, PartialEq, Getters)]
2471pub struct ValueStmt {
2472    /// "integer-value".
2473    arg: IntegerValue,
2474}
2475
2476impl Stmt for ValueStmt {
2477    /// Arg type.
2478    type Arg = IntegerValue;
2479
2480    /// Sub Statements.
2481    type SubStmts = ();
2482
2483    /// Return statement keyword.
2484    fn keyword() -> Keyword {
2485        "value"
2486    }
2487
2488    /// Constructor with a single arg. Panic if it is not defined.
2489    fn new_with_arg(arg: Self::Arg) -> YangStmt
2490    where
2491        Self: Sized,
2492    {
2493        YangStmt::ValueStmt(ValueStmt { arg })
2494    }
2495}
2496
2497///
2498/// The "grouping" Statement.
2499///
2500#[derive(Debug, Clone, PartialEq, Getters)]
2501pub struct GroupingStmt {
2502    /// "identifier-arg".
2503    arg: Identifier,
2504
2505    /// "status" statement.
2506    status: Option<StatusStmt>,
2507
2508    /// "description" statement.
2509    description: Option<DescriptionStmt>,
2510
2511    /// "reference" statement.
2512    reference: Option<ReferenceStmt>,
2513
2514    /// "typedef" / "grouping" statement.
2515    typedef_or_grouping: TypedefOrGrouping,
2516
2517    /// "data-def" statement.
2518    data_def: DataDefStmt,
2519
2520    /// "action" statement.
2521    action: Vec<ActionStmt>,
2522
2523    /// "notification" statement.
2524    notification: Vec<NotificationStmt>,
2525}
2526
2527impl GroupingStmt {
2528    pub fn typedef(&self) -> &Vec<TypedefStmt> {
2529        &self.typedef_or_grouping.typedef()
2530    }
2531
2532    pub fn grouping(&self) -> &Vec<GroupingStmt> {
2533        &self.typedef_or_grouping.grouping()
2534    }
2535
2536    pub fn container(&self) -> &Vec<ContainerStmt> {
2537        &self.data_def.container()
2538    }
2539
2540    pub fn leaf(&self) -> &Vec<LeafStmt> {
2541        &self.data_def.leaf()
2542    }
2543
2544    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
2545        &self.data_def.leaf_list()
2546    }
2547
2548    pub fn list(&self) -> &Vec<ListStmt> {
2549        &self.data_def.list()
2550    }
2551
2552    pub fn choice(&self) -> &Vec<ChoiceStmt> {
2553        &self.data_def.choice()
2554    }
2555
2556    pub fn anydata(&self) -> &Vec<AnydataStmt> {
2557        &self.data_def.anydata()
2558    }
2559
2560    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
2561        &self.data_def.anyxml()
2562    }
2563
2564    pub fn uses(&self) -> &Vec<UsesStmt> {
2565        &self.data_def.uses()
2566    }
2567}
2568
2569impl Stmt for GroupingStmt {
2570    /// Arg type.
2571    type Arg = Identifier;
2572
2573    /// Sub Statements.
2574    type SubStmts = (
2575        Option<StatusStmt>,
2576        Option<DescriptionStmt>,
2577        Option<ReferenceStmt>,
2578        TypedefOrGrouping,
2579        DataDefStmt,
2580        Vec<ActionStmt>,
2581        Vec<NotificationStmt>,
2582    );
2583
2584    /// Return statement keyword.
2585    fn keyword() -> Keyword {
2586        "grouping"
2587    }
2588
2589    /// Return true if this statement has sub-statements optionally.
2590    fn opt_substmts() -> bool {
2591        true
2592    }
2593
2594    /// Return substatements definition.
2595    fn substmts_def() -> Vec<SubStmtDef> {
2596        vec![
2597            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
2598            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
2599            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
2600            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
2601            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
2602            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ActionStmt::keyword)),
2603            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
2604        ]
2605    }
2606
2607    /// Constructor with a single arg. Panic if it is not defined.
2608    fn new_with_arg(arg: Self::Arg) -> YangStmt
2609    where
2610        Self: Sized,
2611    {
2612        YangStmt::GroupingStmt(GroupingStmt {
2613            arg,
2614            status: None,
2615            description: None,
2616            reference: None,
2617            typedef_or_grouping: TypedefOrGrouping::new(),
2618            data_def: DataDefStmt::new(),
2619            action: Vec::new(),
2620            notification: Vec::new(),
2621        })
2622    }
2623
2624    /// Constructor with tuple of substatements. Panic if it is not defined.
2625    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
2626    where
2627        Self: Sized,
2628    {
2629        YangStmt::GroupingStmt(GroupingStmt {
2630            arg,
2631            status: substmts.0,
2632            description: substmts.1,
2633            reference: substmts.2,
2634            typedef_or_grouping: substmts.3,
2635            data_def: substmts.4,
2636            action: substmts.5,
2637            notification: substmts.6,
2638        })
2639    }
2640
2641    /// Parse substatements.
2642    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
2643        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
2644
2645        Ok((
2646            collect_opt_stmt!(stmts, StatusStmt)?,
2647            collect_opt_stmt!(stmts, DescriptionStmt)?,
2648            collect_opt_stmt!(stmts, ReferenceStmt)?,
2649            TypedefOrGrouping::new_with_substmts((
2650                collect_vec_stmt!(stmts, TypedefStmt)?,
2651                collect_vec_stmt!(stmts, GroupingStmt)?,
2652            )),
2653            DataDefStmt::new_with_substmts((
2654                collect_vec_stmt!(stmts, ContainerStmt)?,
2655                collect_vec_stmt!(stmts, LeafStmt)?,
2656                collect_vec_stmt!(stmts, LeafListStmt)?,
2657                collect_vec_stmt!(stmts, ListStmt)?,
2658                collect_vec_stmt!(stmts, ChoiceStmt)?,
2659                collect_vec_stmt!(stmts, AnydataStmt)?,
2660                collect_vec_stmt!(stmts, AnyxmlStmt)?,
2661                collect_vec_stmt!(stmts, UsesStmt)?,
2662            )),
2663            collect_vec_stmt!(stmts, ActionStmt)?,
2664            collect_vec_stmt!(stmts, NotificationStmt)?,
2665        ))
2666    }
2667}
2668
2669///
2670/// The "container" Statement.
2671///
2672#[derive(Debug, Clone, PartialEq, Getters)]
2673pub struct ContainerStmt {
2674    /// "identifier-arg".
2675    arg: Identifier,
2676
2677    /// "when" statement.
2678    when: Option<WhenStmt>,
2679
2680    /// "if-feature" statement.
2681    if_feature: Vec<IfFeatureStmt>,
2682
2683    /// "must" statement.
2684    must: Vec<MustStmt>,
2685
2686    /// "presence" statement.
2687    presence: Option<PresenceStmt>,
2688
2689    /// "config" statement.
2690    config: Option<ConfigStmt>,
2691
2692    /// "status" statement.
2693    status: Option<StatusStmt>,
2694
2695    /// "description" statement.
2696    description: Option<DescriptionStmt>,
2697
2698    /// "reference" statement.
2699    reference: Option<ReferenceStmt>,
2700
2701    /// "typedef" / "grouping" statement.
2702    typedef_or_grouping: TypedefOrGrouping,
2703
2704    /// "data-def" statement.
2705    data_def: DataDefStmt,
2706
2707    /// "action" statement.
2708    action: Vec<ActionStmt>,
2709
2710    /// "notification" statement.
2711    notification: Vec<NotificationStmt>,
2712}
2713
2714impl ContainerStmt {
2715    pub fn typedef(&self) -> &Vec<TypedefStmt> {
2716        &self.typedef_or_grouping.typedef()
2717    }
2718
2719    pub fn grouping(&self) -> &Vec<GroupingStmt> {
2720        &self.typedef_or_grouping.grouping()
2721    }
2722
2723    pub fn container(&self) -> &Vec<ContainerStmt> {
2724        &self.data_def.container()
2725    }
2726
2727    pub fn leaf(&self) -> &Vec<LeafStmt> {
2728        &self.data_def.leaf()
2729    }
2730
2731    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
2732        &self.data_def.leaf_list()
2733    }
2734
2735    pub fn list(&self) -> &Vec<ListStmt> {
2736        &self.data_def.list()
2737    }
2738
2739    pub fn choice(&self) -> &Vec<ChoiceStmt> {
2740        &self.data_def.choice()
2741    }
2742
2743    pub fn anydata(&self) -> &Vec<AnydataStmt> {
2744        &self.data_def.anydata()
2745    }
2746
2747    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
2748        &self.data_def.anyxml()
2749    }
2750
2751    pub fn uses(&self) -> &Vec<UsesStmt> {
2752        &self.data_def.uses()
2753    }
2754}
2755
2756impl Stmt for ContainerStmt {
2757    /// Arg type.
2758    type Arg = Identifier;
2759
2760    /// Sub Statements.
2761    type SubStmts = (
2762        Option<WhenStmt>,
2763        Vec<IfFeatureStmt>,
2764        Vec<MustStmt>,
2765        Option<PresenceStmt>,
2766        Option<ConfigStmt>,
2767        Option<StatusStmt>,
2768        Option<DescriptionStmt>,
2769        Option<ReferenceStmt>,
2770        TypedefOrGrouping,
2771        DataDefStmt,
2772        Vec<ActionStmt>,
2773        Vec<NotificationStmt>,
2774    );
2775
2776    /// Return statement keyword.
2777    fn keyword() -> Keyword {
2778        "container"
2779    }
2780
2781    /// Return true if this statement has sub-statements optionally.
2782    fn opt_substmts() -> bool {
2783        true
2784    }
2785
2786    /// Return substatements definition.
2787    fn substmts_def() -> Vec<SubStmtDef> {
2788        vec![
2789            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
2790            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
2791            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
2792            SubStmtDef::Optional(SubStmtWith::Stmt(PresenceStmt::keyword)),
2793            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
2794            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
2795            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
2796            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
2797            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
2798            SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
2799            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ActionStmt::keyword)),
2800            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
2801        ]
2802    }
2803
2804    /// Constructor with a single arg. Panic if it is not defined.
2805    fn new_with_arg(arg: Self::Arg) -> YangStmt
2806    where
2807        Self: Sized,
2808    {
2809        YangStmt::ContainerStmt(ContainerStmt {
2810            arg,
2811            when: None,
2812            if_feature: Vec::new(),
2813            must: Vec::new(),
2814            presence: None,
2815            config: None,
2816            status: None,
2817            description: None,
2818            reference: None,
2819            typedef_or_grouping: TypedefOrGrouping::new(),
2820            data_def: DataDefStmt::new(),
2821            action: Vec::new(),
2822            notification: Vec::new(),
2823        })
2824    }
2825
2826    /// Constructor with tuple of substatements. Panic if it is not defined.
2827    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
2828    where
2829        Self: Sized,
2830    {
2831        YangStmt::ContainerStmt(ContainerStmt {
2832            arg,
2833            when: substmts.0,
2834            if_feature: substmts.1,
2835            must: substmts.2,
2836            presence: substmts.3,
2837            config: substmts.4,
2838            status: substmts.5,
2839            description: substmts.6,
2840            reference: substmts.7,
2841            typedef_or_grouping: substmts.8,
2842            data_def: substmts.9,
2843            action: substmts.10,
2844            notification: substmts.11,
2845        })
2846    }
2847
2848    /// Parse substatements.
2849    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
2850        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
2851
2852        Ok((
2853            collect_opt_stmt!(stmts, WhenStmt)?,
2854            collect_vec_stmt!(stmts, IfFeatureStmt)?,
2855            collect_vec_stmt!(stmts, MustStmt)?,
2856            collect_opt_stmt!(stmts, PresenceStmt)?,
2857            collect_opt_stmt!(stmts, ConfigStmt)?,
2858            collect_opt_stmt!(stmts, StatusStmt)?,
2859            collect_opt_stmt!(stmts, DescriptionStmt)?,
2860            collect_opt_stmt!(stmts, ReferenceStmt)?,
2861            TypedefOrGrouping::new_with_substmts((
2862                collect_vec_stmt!(stmts, TypedefStmt)?,
2863                collect_vec_stmt!(stmts, GroupingStmt)?,
2864            )),
2865            DataDefStmt::new_with_substmts((
2866                collect_vec_stmt!(stmts, ContainerStmt)?,
2867                collect_vec_stmt!(stmts, LeafStmt)?,
2868                collect_vec_stmt!(stmts, LeafListStmt)?,
2869                collect_vec_stmt!(stmts, ListStmt)?,
2870                collect_vec_stmt!(stmts, ChoiceStmt)?,
2871                collect_vec_stmt!(stmts, AnydataStmt)?,
2872                collect_vec_stmt!(stmts, AnyxmlStmt)?,
2873                collect_vec_stmt!(stmts, UsesStmt)?,
2874            )),
2875            collect_vec_stmt!(stmts, ActionStmt)?,
2876            collect_vec_stmt!(stmts, NotificationStmt)?,
2877        ))
2878    }
2879}
2880
2881///
2882/// The "leaf" Statement.
2883///
2884#[derive(Debug, Clone, PartialEq, Getters)]
2885pub struct LeafStmt {
2886    /// "identifier-arg".
2887    arg: Identifier,
2888
2889    /// "when" statement.
2890    when: Option<WhenStmt>,
2891
2892    /// "if-feature" statement.
2893    if_feature: Vec<IfFeatureStmt>,
2894
2895    /// "type" statement.
2896    type_: TypeStmt,
2897
2898    /// "units" statement.
2899    units: Option<UnitsStmt>,
2900
2901    /// "must" statement.
2902    must: Vec<MustStmt>,
2903
2904    /// "default" statement.
2905    default: Option<DefaultStmt>,
2906
2907    /// "config" statement.
2908    config: Option<ConfigStmt>,
2909
2910    /// "mandatory" statement.
2911    mandatory: Option<MandatoryStmt>,
2912
2913    /// "status" statement.
2914    status: Option<StatusStmt>,
2915
2916    /// "description" statement.
2917    description: Option<DescriptionStmt>,
2918
2919    /// "reference" statement.
2920    reference: Option<ReferenceStmt>,
2921}
2922
2923impl Stmt for LeafStmt {
2924    /// Arg type.
2925    type Arg = Identifier;
2926
2927    /// Sub Statements.
2928    type SubStmts = (
2929        Option<WhenStmt>,
2930        Vec<IfFeatureStmt>,
2931        TypeStmt,
2932        Option<UnitsStmt>,
2933        Vec<MustStmt>,
2934        Option<DefaultStmt>,
2935        Option<ConfigStmt>,
2936        Option<MandatoryStmt>,
2937        Option<StatusStmt>,
2938        Option<DescriptionStmt>,
2939        Option<ReferenceStmt>,
2940    );
2941
2942    /// Return statement keyword.
2943    fn keyword() -> Keyword {
2944        "leaf"
2945    }
2946
2947    /// Return true if this statement has substatements.
2948    fn has_substmts() -> bool {
2949        true
2950    }
2951
2952    /// Return substatements definition.
2953    fn substmts_def() -> Vec<SubStmtDef> {
2954        vec![
2955            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
2956            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
2957            SubStmtDef::HasOne(SubStmtWith::Stmt(TypeStmt::keyword)),
2958            SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
2959            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
2960            SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
2961            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
2962            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
2963            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
2964            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
2965            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
2966        ]
2967    }
2968
2969    /// Constructor with tuple of substatements. Panic if it is not defined.
2970    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
2971    where
2972        Self: Sized,
2973    {
2974        YangStmt::LeafStmt(LeafStmt {
2975            arg,
2976            when: substmts.0,
2977            if_feature: substmts.1,
2978            type_: substmts.2,
2979            units: substmts.3,
2980            must: substmts.4,
2981            default: substmts.5,
2982            config: substmts.6,
2983            mandatory: substmts.7,
2984            status: substmts.8,
2985            description: substmts.9,
2986            reference: substmts.10,
2987        })
2988    }
2989
2990    /// Parse substatements.
2991    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
2992        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
2993
2994        Ok((
2995            collect_opt_stmt!(stmts, WhenStmt)?,
2996            collect_vec_stmt!(stmts, IfFeatureStmt)?,
2997            collect_a_stmt!(stmts, TypeStmt)?,
2998            collect_opt_stmt!(stmts, UnitsStmt)?,
2999            collect_vec_stmt!(stmts, MustStmt)?,
3000            collect_opt_stmt!(stmts, DefaultStmt)?,
3001            collect_opt_stmt!(stmts, ConfigStmt)?,
3002            collect_opt_stmt!(stmts, MandatoryStmt)?,
3003            collect_opt_stmt!(stmts, StatusStmt)?,
3004            collect_opt_stmt!(stmts, DescriptionStmt)?,
3005            collect_opt_stmt!(stmts, ReferenceStmt)?,
3006        ))
3007    }
3008}
3009
3010///
3011/// The "leaf-list" Statement.
3012///
3013#[derive(Debug, Clone, PartialEq, Getters)]
3014pub struct LeafListStmt {
3015    /// "identifier-arg".
3016    arg: Identifier,
3017
3018    /// "when" statement.
3019    when: Option<WhenStmt>,
3020
3021    /// "if-feature" statement.
3022    if_feature: Vec<IfFeatureStmt>,
3023
3024    /// "type" statement.
3025    type_: TypeStmt,
3026
3027    /// "units" statement.
3028    units: Option<UnitsStmt>,
3029
3030    /// "must" statement.
3031    must: Vec<MustStmt>,
3032
3033    /// "default" statement.
3034    default: Vec<DefaultStmt>,
3035
3036    /// "config" statement.
3037    config: Option<ConfigStmt>,
3038
3039    /// "min-elements" statement.
3040    min_elements: Option<MinElementsStmt>,
3041
3042    /// "max-elements" statement.
3043    max_elements: Option<MaxElementsStmt>,
3044
3045    /// "ordered-by" statement.
3046    ordered_by: Option<OrderedByStmt>,
3047
3048    /// "status" statement.
3049    status: Option<StatusStmt>,
3050
3051    /// "description" statement.
3052    description: Option<DescriptionStmt>,
3053
3054    /// "reference" statement.
3055    reference: Option<ReferenceStmt>,
3056}
3057
3058impl Stmt for LeafListStmt {
3059    /// Arg type.
3060    type Arg = Identifier;
3061
3062    /// Sub Statements.
3063    type SubStmts = (
3064        Option<WhenStmt>,
3065        Vec<IfFeatureStmt>,
3066        TypeStmt,
3067        Option<UnitsStmt>,
3068        Vec<MustStmt>,
3069        Vec<DefaultStmt>,
3070        Option<ConfigStmt>,
3071        Option<MinElementsStmt>,
3072        Option<MaxElementsStmt>,
3073        Option<OrderedByStmt>,
3074        Option<StatusStmt>,
3075        Option<DescriptionStmt>,
3076        Option<ReferenceStmt>,
3077    );
3078
3079    /// Return statement keyword.
3080    fn keyword() -> Keyword {
3081        "leaf-list"
3082    }
3083
3084    /// Return true if this statement has substatements.
3085    fn has_substmts() -> bool {
3086        true
3087    }
3088
3089    /// Return substatements definition.
3090    fn substmts_def() -> Vec<SubStmtDef> {
3091        vec![
3092            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
3093            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
3094            SubStmtDef::HasOne(SubStmtWith::Stmt(TypeStmt::keyword)),
3095            SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
3096            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
3097            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
3098            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
3099            SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
3100            SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
3101            SubStmtDef::Optional(SubStmtWith::Stmt(OrderedByStmt::keyword)),
3102            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
3103            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
3104            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
3105        ]
3106    }
3107
3108    /// Constructor with tuple of substatements. Panic if it is not defined.
3109    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
3110    where
3111        Self: Sized,
3112    {
3113        YangStmt::LeafListStmt(LeafListStmt {
3114            arg,
3115            when: substmts.0,
3116            if_feature: substmts.1,
3117            type_: substmts.2,
3118            units: substmts.3,
3119            must: substmts.4,
3120            default: substmts.5,
3121            config: substmts.6,
3122            min_elements: substmts.7,
3123            max_elements: substmts.8,
3124            ordered_by: substmts.9,
3125            status: substmts.10,
3126            description: substmts.11,
3127            reference: substmts.12,
3128        })
3129    }
3130
3131    /// Parse substatements.
3132    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
3133        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
3134
3135        Ok((
3136            collect_opt_stmt!(stmts, WhenStmt)?,
3137            collect_vec_stmt!(stmts, IfFeatureStmt)?,
3138            collect_a_stmt!(stmts, TypeStmt)?,
3139            collect_opt_stmt!(stmts, UnitsStmt)?,
3140            collect_vec_stmt!(stmts, MustStmt)?,
3141            collect_vec_stmt!(stmts, DefaultStmt)?,
3142            collect_opt_stmt!(stmts, ConfigStmt)?,
3143            collect_opt_stmt!(stmts, MinElementsStmt)?,
3144            collect_opt_stmt!(stmts, MaxElementsStmt)?,
3145            collect_opt_stmt!(stmts, OrderedByStmt)?,
3146            collect_opt_stmt!(stmts, StatusStmt)?,
3147            collect_opt_stmt!(stmts, DescriptionStmt)?,
3148            collect_opt_stmt!(stmts, ReferenceStmt)?,
3149        ))
3150    }
3151}
3152
3153///
3154/// The "list" Statement.
3155///
3156#[derive(Debug, Clone, PartialEq, Getters)]
3157pub struct ListStmt {
3158    /// "Identifier-arg".
3159    arg: Identifier,
3160
3161    /// "when" statement.
3162    when: Option<WhenStmt>,
3163
3164    /// "if-feature" statement.
3165    if_feature: Vec<IfFeatureStmt>,
3166
3167    /// "must" statement.
3168    must: Vec<MustStmt>,
3169
3170    /// "key" statement.
3171    key: Option<KeyStmt>,
3172
3173    /// "unique" statement.
3174    unique: Vec<UniqueStmt>,
3175
3176    /// "config" statement.
3177    config: Option<ConfigStmt>,
3178
3179    /// "min-elements" statement.
3180    min_elements: Option<MinElementsStmt>,
3181
3182    /// "max-elements" statement.
3183    max_elements: Option<MaxElementsStmt>,
3184
3185    /// "ordered-by" statement.
3186    ordered_by: Option<OrderedByStmt>,
3187
3188    /// "status" statement.
3189    status: Option<StatusStmt>,
3190
3191    /// "description" statement.
3192    description: Option<DescriptionStmt>,
3193
3194    /// "reference" statement.
3195    reference: Option<ReferenceStmt>,
3196
3197    /// "typedef" / "grouping" statement.
3198    typedef_or_grouping: TypedefOrGrouping,
3199
3200    /// "data-def" statement.
3201    data_def: DataDefStmt,
3202
3203    /// "action" statement.
3204    action: Vec<ActionStmt>,
3205
3206    /// "notification" statement.
3207    notification: Vec<NotificationStmt>,
3208}
3209
3210impl ListStmt {
3211    pub fn typedef(&self) -> &Vec<TypedefStmt> {
3212        &self.typedef_or_grouping.typedef()
3213    }
3214
3215    pub fn grouping(&self) -> &Vec<GroupingStmt> {
3216        &self.typedef_or_grouping.grouping()
3217    }
3218
3219    pub fn container(&self) -> &Vec<ContainerStmt> {
3220        &self.data_def.container()
3221    }
3222
3223    pub fn leaf(&self) -> &Vec<LeafStmt> {
3224        &self.data_def.leaf()
3225    }
3226
3227    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
3228        &self.data_def.leaf_list()
3229    }
3230
3231    pub fn list(&self) -> &Vec<ListStmt> {
3232        &self.data_def.list()
3233    }
3234
3235    pub fn choice(&self) -> &Vec<ChoiceStmt> {
3236        &self.data_def.choice()
3237    }
3238
3239    pub fn anydata(&self) -> &Vec<AnydataStmt> {
3240        &self.data_def.anydata()
3241    }
3242
3243    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
3244        &self.data_def.anyxml()
3245    }
3246
3247    pub fn uses(&self) -> &Vec<UsesStmt> {
3248        &self.data_def.uses()
3249    }
3250}
3251
3252impl Stmt for ListStmt {
3253    /// Arg type.
3254    type Arg = Identifier;
3255
3256    /// Sub Statements.
3257    type SubStmts = (
3258        Option<WhenStmt>,
3259        Vec<IfFeatureStmt>,
3260        Vec<MustStmt>,
3261        Option<KeyStmt>,
3262        Vec<UniqueStmt>,
3263        Option<ConfigStmt>,
3264        Option<MinElementsStmt>,
3265        Option<MaxElementsStmt>,
3266        Option<OrderedByStmt>,
3267        Option<StatusStmt>,
3268        Option<DescriptionStmt>,
3269        Option<ReferenceStmt>,
3270        TypedefOrGrouping,
3271        DataDefStmt,
3272        Vec<ActionStmt>,
3273        Vec<NotificationStmt>,
3274    );
3275
3276    /// Return statement keyword.
3277    fn keyword() -> Keyword {
3278        "list"
3279    }
3280
3281    /// Return true if this statement has substatements.
3282    fn has_substmts() -> bool {
3283        true
3284    }
3285
3286    /// Return substatements definition.
3287    fn substmts_def() -> Vec<SubStmtDef> {
3288        vec![
3289            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
3290            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
3291            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
3292            SubStmtDef::Optional(SubStmtWith::Stmt(KeyStmt::keyword)),
3293            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(UniqueStmt::keyword)),
3294            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
3295            SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
3296            SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
3297            SubStmtDef::Optional(SubStmtWith::Stmt(OrderedByStmt::keyword)),
3298            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
3299            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
3300            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
3301            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
3302            SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
3303            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ActionStmt::keyword)),
3304            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
3305        ]
3306    }
3307
3308    /// Constructor with tuple of substatements. Panic if it is not defined.
3309    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
3310    where
3311        Self: Sized,
3312    {
3313        YangStmt::ListStmt(ListStmt {
3314            arg,
3315            when: substmts.0,
3316            if_feature: substmts.1,
3317            must: substmts.2,
3318            key: substmts.3,
3319            unique: substmts.4,
3320            config: substmts.5,
3321            min_elements: substmts.6,
3322            max_elements: substmts.7,
3323            ordered_by: substmts.8,
3324            status: substmts.9,
3325            description: substmts.10,
3326            reference: substmts.11,
3327            typedef_or_grouping: substmts.12,
3328            data_def: substmts.13,
3329            action: substmts.14,
3330            notification: substmts.15,
3331        })
3332    }
3333
3334    /// Parse substatements.
3335    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
3336        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
3337
3338        Ok((
3339            collect_opt_stmt!(stmts, WhenStmt)?,
3340            collect_vec_stmt!(stmts, IfFeatureStmt)?,
3341            collect_vec_stmt!(stmts, MustStmt)?,
3342            collect_opt_stmt!(stmts, KeyStmt)?,
3343            collect_vec_stmt!(stmts, UniqueStmt)?,
3344            collect_opt_stmt!(stmts, ConfigStmt)?,
3345            collect_opt_stmt!(stmts, MinElementsStmt)?,
3346            collect_opt_stmt!(stmts, MaxElementsStmt)?,
3347            collect_opt_stmt!(stmts, OrderedByStmt)?,
3348            collect_opt_stmt!(stmts, StatusStmt)?,
3349            collect_opt_stmt!(stmts, DescriptionStmt)?,
3350            collect_opt_stmt!(stmts, ReferenceStmt)?,
3351            TypedefOrGrouping::new_with_substmts((
3352                collect_vec_stmt!(stmts, TypedefStmt)?,
3353                collect_vec_stmt!(stmts, GroupingStmt)?,
3354            )),
3355            DataDefStmt::new_with_substmts((
3356                collect_vec_stmt!(stmts, ContainerStmt)?,
3357                collect_vec_stmt!(stmts, LeafStmt)?,
3358                collect_vec_stmt!(stmts, LeafListStmt)?,
3359                collect_vec_stmt!(stmts, ListStmt)?,
3360                collect_vec_stmt!(stmts, ChoiceStmt)?,
3361                collect_vec_stmt!(stmts, AnydataStmt)?,
3362                collect_vec_stmt!(stmts, AnyxmlStmt)?,
3363                collect_vec_stmt!(stmts, UsesStmt)?,
3364            )),
3365            collect_vec_stmt!(stmts, ActionStmt)?,
3366            collect_vec_stmt!(stmts, NotificationStmt)?,
3367        ))
3368    }
3369}
3370
3371///
3372/// The "key" Statement.
3373///
3374#[derive(Debug, Clone, PartialEq, Getters)]
3375pub struct KeyStmt {
3376    /// "key-arg".
3377    arg: KeyArg,
3378}
3379
3380impl Stmt for KeyStmt {
3381    /// Arg type.
3382    type Arg = KeyArg;
3383
3384    /// Sub Statements.
3385    type SubStmts = ();
3386
3387    /// Return statement keyword.
3388    fn keyword() -> Keyword {
3389        "key"
3390    }
3391
3392    /// Constructor with a single arg. Panic if it is not defined.
3393    fn new_with_arg(arg: Self::Arg) -> YangStmt
3394    where
3395        Self: Sized,
3396    {
3397        YangStmt::KeyStmt(KeyStmt { arg })
3398    }
3399}
3400
3401///
3402/// The list's "unique" Statement.
3403///
3404#[derive(Debug, Clone, PartialEq, Getters)]
3405pub struct UniqueStmt {
3406    /// "unique-arg".
3407    arg: UniqueArg,
3408}
3409
3410impl Stmt for UniqueStmt {
3411    /// Arg type.
3412    type Arg = UniqueArg;
3413
3414    /// Sub Statements.
3415    type SubStmts = ();
3416
3417    /// Return statement keyword.
3418    fn keyword() -> Keyword {
3419        "unique"
3420    }
3421
3422    /// Constructor with a single arg. Panic if it is not defined.
3423    fn new_with_arg(arg: Self::Arg) -> YangStmt
3424    where
3425        Self: Sized,
3426    {
3427        YangStmt::UniqueStmt(UniqueStmt { arg })
3428    }
3429}
3430
3431///
3432/// The "choice" Statement.
3433///
3434#[derive(Debug, Clone, PartialEq, Getters)]
3435pub struct ChoiceStmt {
3436    /// "identifier-arg".
3437    arg: Identifier,
3438
3439    /// "when" statement.
3440    when: Option<WhenStmt>,
3441
3442    /// "if-feature" statement.
3443    if_feature: Vec<IfFeatureStmt>,
3444
3445    /// "default" statement.
3446    default: Option<DefaultStmt>,
3447
3448    /// "config" statement.
3449    config: Option<ConfigStmt>,
3450
3451    /// "mandatory" statement.
3452    mandatory: Option<MandatoryStmt>,
3453
3454    /// "status" statement.
3455    status: Option<StatusStmt>,
3456
3457    /// "description" statement.
3458    description: Option<DescriptionStmt>,
3459
3460    /// "reference" statement.
3461    reference: Option<ReferenceStmt>,
3462
3463    /// "short-case" / "case" statement.
3464    short_case_or_case: ShortCaseOrCaseStmt,
3465}
3466
3467impl ChoiceStmt {
3468    pub fn choice(&self) -> &Vec<ChoiceStmt> {
3469        &self.short_case_or_case.choice()
3470    }
3471
3472    pub fn container(&self) -> &Vec<ContainerStmt> {
3473        &self.short_case_or_case.container()
3474    }
3475
3476    pub fn leaf(&self) -> &Vec<LeafStmt> {
3477        &self.short_case_or_case.leaf()
3478    }
3479
3480    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
3481        &self.short_case_or_case.leaf_list()
3482    }
3483
3484    pub fn list(&self) -> &Vec<ListStmt> {
3485        &self.short_case_or_case.list()
3486    }
3487
3488    pub fn anydata(&self) -> &Vec<AnydataStmt> {
3489        &self.short_case_or_case.anydata()
3490    }
3491
3492    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
3493        &self.short_case_or_case.anyxml()
3494    }
3495
3496    pub fn case(&self) -> &Vec<CaseStmt> {
3497        &self.short_case_or_case.case()
3498    }
3499}
3500
3501impl Stmt for ChoiceStmt {
3502    /// Arg type.
3503    type Arg = Identifier;
3504
3505    /// Return statement keyword.
3506    fn keyword() -> Keyword {
3507        "choice"
3508    }
3509
3510    /// Sub Statements.
3511    type SubStmts = (
3512        Option<WhenStmt>,
3513        Vec<IfFeatureStmt>,
3514        Option<DefaultStmt>,
3515        Option<ConfigStmt>,
3516        Option<MandatoryStmt>,
3517        Option<StatusStmt>,
3518        Option<DescriptionStmt>,
3519        Option<ReferenceStmt>,
3520        ShortCaseOrCaseStmt,
3521    );
3522
3523    /// Return true if this statement has sub-statements optionally.
3524    fn opt_substmts() -> bool {
3525        true
3526    }
3527
3528    /// Return substatements definition.
3529    fn substmts_def() -> Vec<SubStmtDef> {
3530        vec![
3531            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
3532            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
3533            SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
3534            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
3535            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
3536            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
3537            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
3538            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
3539            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(ShortCaseOrCaseStmt::keywords)),
3540        ]
3541    }
3542
3543    /// Constructor with a single arg. Panic if it is not defined.
3544    fn new_with_arg(arg: Self::Arg) -> YangStmt
3545    where
3546        Self: Sized,
3547    {
3548        YangStmt::ChoiceStmt(ChoiceStmt {
3549            arg,
3550            when: None,
3551            if_feature: Vec::new(),
3552            default: None,
3553            config: None,
3554            mandatory: None,
3555            status: None,
3556            description: None,
3557            reference: None,
3558            short_case_or_case: ShortCaseOrCaseStmt::new(),
3559        })
3560    }
3561
3562    /// Constructor with tuple of substatements. Panic if it is not defined.
3563    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
3564    where
3565        Self: Sized,
3566    {
3567        YangStmt::ChoiceStmt(ChoiceStmt {
3568            arg,
3569            when: substmts.0,
3570            if_feature: substmts.1,
3571            default: substmts.2,
3572            config: substmts.3,
3573            mandatory: substmts.4,
3574            status: substmts.5,
3575            description: substmts.6,
3576            reference: substmts.7,
3577            short_case_or_case: substmts.8,
3578        })
3579    }
3580
3581    /// Parse substatements.
3582    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
3583        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
3584
3585        Ok((
3586            collect_opt_stmt!(stmts, WhenStmt)?,
3587            collect_vec_stmt!(stmts, IfFeatureStmt)?,
3588            collect_opt_stmt!(stmts, DefaultStmt)?,
3589            collect_opt_stmt!(stmts, ConfigStmt)?,
3590            collect_opt_stmt!(stmts, MandatoryStmt)?,
3591            collect_opt_stmt!(stmts, StatusStmt)?,
3592            collect_opt_stmt!(stmts, DescriptionStmt)?,
3593            collect_opt_stmt!(stmts, ReferenceStmt)?,
3594            ShortCaseOrCaseStmt::new_with_substmts((
3595                collect_vec_stmt!(stmts, ChoiceStmt)?,
3596                collect_vec_stmt!(stmts, ContainerStmt)?,
3597                collect_vec_stmt!(stmts, LeafStmt)?,
3598                collect_vec_stmt!(stmts, LeafListStmt)?,
3599                collect_vec_stmt!(stmts, ListStmt)?,
3600                collect_vec_stmt!(stmts, AnydataStmt)?,
3601                collect_vec_stmt!(stmts, AnyxmlStmt)?,
3602                collect_vec_stmt!(stmts, CaseStmt)?,
3603            )),
3604        ))
3605    }
3606}
3607
3608///
3609/// The "case" Statement.
3610///
3611#[derive(Debug, Clone, PartialEq, Getters)]
3612pub struct CaseStmt {
3613    /// "identifier-arg".
3614    arg: Identifier,
3615
3616    /// "when" statement.
3617    when: Option<WhenStmt>,
3618
3619    /// "if-feature" statement.
3620    if_feature: Vec<IfFeatureStmt>,
3621
3622    /// "status" statement.
3623    status: Option<StatusStmt>,
3624
3625    /// "description" statement.
3626    description: Option<DescriptionStmt>,
3627
3628    /// "reference" statement.
3629    reference: Option<ReferenceStmt>,
3630
3631    /// "data-def" statement.
3632    data_def: DataDefStmt,
3633}
3634
3635impl CaseStmt {
3636    pub fn container(&self) -> &Vec<ContainerStmt> {
3637        &self.data_def.container()
3638    }
3639
3640    pub fn leaf(&self) -> &Vec<LeafStmt> {
3641        &self.data_def.leaf()
3642    }
3643
3644    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
3645        &self.data_def.leaf_list()
3646    }
3647
3648    pub fn list(&self) -> &Vec<ListStmt> {
3649        &self.data_def.list()
3650    }
3651
3652    pub fn choice(&self) -> &Vec<ChoiceStmt> {
3653        &self.data_def.choice()
3654    }
3655
3656    pub fn anydata(&self) -> &Vec<AnydataStmt> {
3657        &self.data_def.anydata()
3658    }
3659
3660    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
3661        &self.data_def.anyxml()
3662    }
3663
3664    pub fn uses(&self) -> &Vec<UsesStmt> {
3665        &self.data_def.uses()
3666    }
3667}
3668
3669impl Stmt for CaseStmt {
3670    /// Arg type.
3671    type Arg = Identifier;
3672
3673    /// Return statement keyword.
3674    fn keyword() -> Keyword {
3675        "case"
3676    }
3677
3678    /// Sub Statements.
3679    type SubStmts = (
3680        Option<WhenStmt>,
3681        Vec<IfFeatureStmt>,
3682        Option<StatusStmt>,
3683        Option<DescriptionStmt>,
3684        Option<ReferenceStmt>,
3685        DataDefStmt,
3686    );
3687
3688    /// Return true if this statement has sub-statements optionally.
3689    fn opt_substmts() -> bool {
3690        true
3691    }
3692
3693    /// Return substatements definition.
3694    fn substmts_def() -> Vec<SubStmtDef> {
3695        vec![
3696            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
3697            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
3698            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
3699            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
3700            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
3701            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
3702        ]
3703    }
3704
3705    /// Constructor with a single arg. Panic if it is not defined.
3706    fn new_with_arg(arg: Self::Arg) -> YangStmt
3707    where
3708        Self: Sized,
3709    {
3710        YangStmt::CaseStmt(CaseStmt {
3711            arg,
3712            when: None,
3713            if_feature: Vec::new(),
3714            status: None,
3715            description: None,
3716            reference: None,
3717            data_def: DataDefStmt::new(),
3718        })
3719    }
3720
3721    /// Constructor with tuple of substatements. Panic if it is not defined.
3722    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
3723    where
3724        Self: Sized,
3725    {
3726        YangStmt::CaseStmt(CaseStmt {
3727            arg,
3728            when: substmts.0,
3729            if_feature: substmts.1,
3730            status: substmts.2,
3731            description: substmts.3,
3732            reference: substmts.4,
3733            data_def: substmts.5,
3734        })
3735    }
3736
3737    /// Parse substatements.
3738    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
3739        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
3740
3741        Ok((
3742            collect_opt_stmt!(stmts, WhenStmt)?,
3743            collect_vec_stmt!(stmts, IfFeatureStmt)?,
3744            collect_opt_stmt!(stmts, StatusStmt)?,
3745            collect_opt_stmt!(stmts, DescriptionStmt)?,
3746            collect_opt_stmt!(stmts, ReferenceStmt)?,
3747            DataDefStmt::new_with_substmts((
3748                collect_vec_stmt!(stmts, ContainerStmt)?,
3749                collect_vec_stmt!(stmts, LeafStmt)?,
3750                collect_vec_stmt!(stmts, LeafListStmt)?,
3751                collect_vec_stmt!(stmts, ListStmt)?,
3752                collect_vec_stmt!(stmts, ChoiceStmt)?,
3753                collect_vec_stmt!(stmts, AnydataStmt)?,
3754                collect_vec_stmt!(stmts, AnyxmlStmt)?,
3755                collect_vec_stmt!(stmts, UsesStmt)?,
3756            )),
3757        ))
3758    }
3759}
3760
3761///
3762/// The "anydata" Statement.
3763///
3764#[derive(Debug, Clone, PartialEq, Getters)]
3765pub struct AnydataStmt {
3766    /// "identifier-arg".
3767    arg: Identifier,
3768
3769    /// "when" statement.
3770    when: Option<WhenStmt>,
3771
3772    /// "if-feature" statement.
3773    if_feature: Vec<IfFeatureStmt>,
3774
3775    /// "must" statement.
3776    must: Vec<MustStmt>,
3777
3778    /// "config" statement.
3779    config: Option<ConfigStmt>,
3780
3781    /// "mandatory" statement.
3782    mandatory: Option<MandatoryStmt>,
3783
3784    /// "status" statement.
3785    status: Option<StatusStmt>,
3786
3787    /// "description" statement.
3788    description: Option<DescriptionStmt>,
3789
3790    /// "reference" statement.
3791    reference: Option<ReferenceStmt>,
3792}
3793
3794impl Stmt for AnydataStmt {
3795    /// Arg type.
3796    type Arg = Identifier;
3797
3798    /// Sub Statements.
3799    type SubStmts = (
3800        Option<WhenStmt>,
3801        Vec<IfFeatureStmt>,
3802        Vec<MustStmt>,
3803        Option<ConfigStmt>,
3804        Option<MandatoryStmt>,
3805        Option<StatusStmt>,
3806        Option<DescriptionStmt>,
3807        Option<ReferenceStmt>,
3808    );
3809
3810    /// Return statement keyword.
3811    fn keyword() -> Keyword {
3812        "anydata"
3813    }
3814
3815    /// Return true if this statement has sub-statements optionally.
3816    fn opt_substmts() -> bool {
3817        true
3818    }
3819
3820    /// Return substatements definition.
3821    fn substmts_def() -> Vec<SubStmtDef> {
3822        vec![
3823            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
3824            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
3825            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
3826            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
3827            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
3828            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
3829            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
3830            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
3831        ]
3832    }
3833
3834    /// Constructor with a single arg. Panic if it is not defined.
3835    fn new_with_arg(arg: Self::Arg) -> YangStmt
3836    where
3837        Self: Sized,
3838    {
3839        YangStmt::AnydataStmt(AnydataStmt {
3840            arg,
3841            when: None,
3842            if_feature: Vec::new(),
3843            must: Vec::new(),
3844            config: None,
3845            mandatory: None,
3846            status: None,
3847            description: None,
3848            reference: None,
3849        })
3850    }
3851
3852    /// Constructor with tuple of substatements. Panic if it is not defined.
3853    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
3854    where
3855        Self: Sized,
3856    {
3857        YangStmt::AnydataStmt(AnydataStmt {
3858            arg,
3859            when: substmts.0,
3860            if_feature: substmts.1,
3861            must: substmts.2,
3862            config: substmts.3,
3863            mandatory: substmts.4,
3864            status: substmts.5,
3865            description: substmts.6,
3866            reference: substmts.7,
3867        })
3868    }
3869
3870    /// Parse substatements.
3871    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
3872        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
3873
3874        Ok((
3875            collect_opt_stmt!(stmts, WhenStmt)?,
3876            collect_vec_stmt!(stmts, IfFeatureStmt)?,
3877            collect_vec_stmt!(stmts, MustStmt)?,
3878            collect_opt_stmt!(stmts, ConfigStmt)?,
3879            collect_opt_stmt!(stmts, MandatoryStmt)?,
3880            collect_opt_stmt!(stmts, StatusStmt)?,
3881            collect_opt_stmt!(stmts, DescriptionStmt)?,
3882            collect_opt_stmt!(stmts, ReferenceStmt)?,
3883        ))
3884    }
3885}
3886
3887///
3888/// The "anyxml" Statement.
3889///
3890#[derive(Debug, Clone, PartialEq, Getters)]
3891pub struct AnyxmlStmt {
3892    /// "identifier-arg".
3893    arg: Identifier,
3894
3895    /// "when" statement.
3896    when: Option<WhenStmt>,
3897
3898    /// "if-feature" statement.
3899    if_feature: Vec<IfFeatureStmt>,
3900
3901    /// "must" statement.
3902    must: Vec<MustStmt>,
3903
3904    /// "config" statement.
3905    config: Option<ConfigStmt>,
3906
3907    /// "mandatory" statement.
3908    mandatory: Option<MandatoryStmt>,
3909
3910    /// "status" statement.
3911    status: Option<StatusStmt>,
3912
3913    /// "description" statement.
3914    description: Option<DescriptionStmt>,
3915
3916    /// "reference" statement.
3917    reference: Option<ReferenceStmt>,
3918}
3919
3920impl Stmt for AnyxmlStmt {
3921    /// Arg type.
3922    type Arg = Identifier;
3923
3924    /// Sub Statements.
3925    type SubStmts = (
3926        Option<WhenStmt>,
3927        Vec<IfFeatureStmt>,
3928        Vec<MustStmt>,
3929        Option<ConfigStmt>,
3930        Option<MandatoryStmt>,
3931        Option<StatusStmt>,
3932        Option<DescriptionStmt>,
3933        Option<ReferenceStmt>,
3934    );
3935
3936    /// Return statement keyword.
3937    fn keyword() -> Keyword {
3938        "anyxml"
3939    }
3940
3941    /// Return true if this statement has sub-statements optionally.
3942    fn opt_substmts() -> bool {
3943        true
3944    }
3945
3946    /// Return substatements definition.
3947    fn substmts_def() -> Vec<SubStmtDef> {
3948        vec![
3949            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
3950            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
3951            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
3952            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
3953            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
3954            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
3955            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
3956            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
3957        ]
3958    }
3959
3960    /// Constructor with a single arg. Panic if it is not defined.
3961    fn new_with_arg(arg: Self::Arg) -> YangStmt
3962    where
3963        Self: Sized,
3964    {
3965        YangStmt::AnyxmlStmt(AnyxmlStmt {
3966            arg,
3967            when: None,
3968            if_feature: Vec::new(),
3969            must: Vec::new(),
3970            config: None,
3971            mandatory: None,
3972            status: None,
3973            description: None,
3974            reference: None,
3975        })
3976    }
3977
3978    /// Constructor with tuple of substatements. Panic if it is not defined.
3979    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
3980    where
3981        Self: Sized,
3982    {
3983        YangStmt::AnyxmlStmt(AnyxmlStmt {
3984            arg,
3985            when: substmts.0,
3986            if_feature: substmts.1,
3987            must: substmts.2,
3988            config: substmts.3,
3989            mandatory: substmts.4,
3990            status: substmts.5,
3991            description: substmts.6,
3992            reference: substmts.7,
3993        })
3994    }
3995
3996    /// Parse substatements.
3997    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
3998        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
3999
4000        Ok((
4001            collect_opt_stmt!(stmts, WhenStmt)?,
4002            collect_vec_stmt!(stmts, IfFeatureStmt)?,
4003            collect_vec_stmt!(stmts, MustStmt)?,
4004            collect_opt_stmt!(stmts, ConfigStmt)?,
4005            collect_opt_stmt!(stmts, MandatoryStmt)?,
4006            collect_opt_stmt!(stmts, StatusStmt)?,
4007            collect_opt_stmt!(stmts, DescriptionStmt)?,
4008            collect_opt_stmt!(stmts, ReferenceStmt)?,
4009        ))
4010    }
4011}
4012
4013///
4014/// The "uses" Statement.
4015///
4016#[derive(Debug, Clone, PartialEq, Getters)]
4017pub struct UsesStmt {
4018    /// "identifier-ref-arg".
4019    arg: IdentifierRef,
4020
4021    /// "when" statement.
4022    when: Option<WhenStmt>,
4023
4024    /// "if-feature" statement.
4025    if_feature: Vec<IfFeatureStmt>,
4026
4027    /// "status" statement.
4028    status: Option<StatusStmt>,
4029
4030    /// "description" statement.
4031    description: Option<DescriptionStmt>,
4032
4033    /// "reference" statement.
4034    reference: Option<ReferenceStmt>,
4035
4036    /// "refine" statement.
4037    refine: Vec<RefineStmt>,
4038
4039    /// "uses" statement.
4040    uses_augment: Vec<AugmentStmt>,
4041}
4042
4043impl Stmt for UsesStmt {
4044    /// Arg type.
4045    type Arg = IdentifierRef;
4046
4047    /// Sub Statements.
4048    type SubStmts = (
4049        Option<WhenStmt>,
4050        Vec<IfFeatureStmt>,
4051        Option<StatusStmt>,
4052        Option<DescriptionStmt>,
4053        Option<ReferenceStmt>,
4054        Vec<RefineStmt>,
4055        Vec<AugmentStmt>,
4056    );
4057
4058    /// Return statement keyword.
4059    fn keyword() -> Keyword {
4060        "uses"
4061    }
4062
4063    /// Return true if this statement has sub-statements optionally.
4064    fn opt_substmts() -> bool {
4065        true
4066    }
4067
4068    /// Return substatements definition.
4069    fn substmts_def() -> Vec<SubStmtDef> {
4070        vec![
4071            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
4072            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
4073            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
4074            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
4075            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
4076            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(RefineStmt::keyword)),
4077            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(AugmentStmt::keyword)),
4078        ]
4079    }
4080
4081    /// Constructor with a single arg. Panic if it is not defined.
4082    fn new_with_arg(arg: Self::Arg) -> YangStmt
4083    where
4084        Self: Sized,
4085    {
4086        YangStmt::UsesStmt(UsesStmt {
4087            arg,
4088            when: None,
4089            if_feature: Vec::new(),
4090            status: None,
4091            description: None,
4092            reference: None,
4093            refine: Vec::new(),
4094            uses_augment: Vec::new(),
4095        })
4096    }
4097
4098    /// Constructor with tuple of substatements. Panic if it is not defined.
4099    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4100    where
4101        Self: Sized,
4102    {
4103        YangStmt::UsesStmt(UsesStmt {
4104            arg,
4105            when: substmts.0,
4106            if_feature: substmts.1,
4107            status: substmts.2,
4108            description: substmts.3,
4109            reference: substmts.4,
4110            refine: substmts.5,
4111            uses_augment: substmts.6,
4112        })
4113    }
4114
4115    /// Parse substatements.
4116    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4117        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4118
4119        Ok((
4120            collect_opt_stmt!(stmts, WhenStmt)?,
4121            collect_vec_stmt!(stmts, IfFeatureStmt)?,
4122            collect_opt_stmt!(stmts, StatusStmt)?,
4123            collect_opt_stmt!(stmts, DescriptionStmt)?,
4124            collect_opt_stmt!(stmts, ReferenceStmt)?,
4125            collect_vec_stmt!(stmts, RefineStmt)?,
4126            collect_vec_stmt!(stmts, AugmentStmt)?,
4127        ))
4128    }
4129}
4130
4131///
4132/// The "refine" Statement.
4133///
4134#[derive(Debug, Clone, PartialEq, Getters)]
4135pub struct RefineStmt {
4136    /// "refine-arg".
4137    arg: RefineArg,
4138
4139    /// "if-feature" statement.
4140    if_feature: Vec<IfFeatureStmt>,
4141
4142    /// "must" statement.
4143    must: Vec<MustStmt>,
4144
4145    /// "presence" statement.
4146    presence: Option<PresenceStmt>,
4147
4148    /// "default" statement.
4149    default: Vec<DefaultStmt>,
4150
4151    /// "config" statement.
4152    config: Option<ConfigStmt>,
4153
4154    /// "mandatory" statement.
4155    mandatory: Option<MandatoryStmt>,
4156
4157    /// "min-elements" statement.
4158    min_elements: Option<MinElementsStmt>,
4159
4160    /// "max-elements" statement.
4161    max_elements: Option<MaxElementsStmt>,
4162
4163    /// "description" statement.
4164    description: Option<DescriptionStmt>,
4165
4166    /// "reference" statement.
4167    reference: Option<ReferenceStmt>,
4168}
4169
4170impl Stmt for RefineStmt {
4171    /// Arg type.
4172    type Arg = RefineArg;
4173
4174    /// Sub Statements.
4175    type SubStmts = (
4176        Vec<IfFeatureStmt>,
4177        Vec<MustStmt>,
4178        Option<PresenceStmt>,
4179        Vec<DefaultStmt>,
4180        Option<ConfigStmt>,
4181        Option<MandatoryStmt>,
4182        Option<MinElementsStmt>,
4183        Option<MaxElementsStmt>,
4184        Option<DescriptionStmt>,
4185        Option<ReferenceStmt>,
4186    );
4187
4188    /// Return statement keyword.
4189    fn keyword() -> Keyword {
4190        "refine"
4191    }
4192
4193    /// Return true if this statement has sub-statements optionally.
4194    fn opt_substmts() -> bool {
4195        true
4196    }
4197
4198    /// Return substatements definition.
4199    fn substmts_def() -> Vec<SubStmtDef> {
4200        vec![
4201            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
4202            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
4203            SubStmtDef::Optional(SubStmtWith::Stmt(PresenceStmt::keyword)),
4204            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
4205            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
4206            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
4207            SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
4208            SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
4209            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
4210            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
4211        ]
4212    }
4213
4214    /// Constructor with a single arg. Panic if it is not defined.
4215    fn new_with_arg(arg: Self::Arg) -> YangStmt
4216    where
4217        Self: Sized,
4218    {
4219        YangStmt::RefineStmt(RefineStmt {
4220            arg,
4221            if_feature: Vec::new(),
4222            must: Vec::new(),
4223            presence: None,
4224            default: Vec::new(),
4225            config: None,
4226            mandatory: None,
4227            min_elements: None,
4228            max_elements: None,
4229            description: None,
4230            reference: None,
4231        })
4232    }
4233
4234    /// Constructor with tuple of substatements. Panic if it is not defined.
4235    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4236    where
4237        Self: Sized,
4238    {
4239        YangStmt::RefineStmt(RefineStmt {
4240            arg,
4241            if_feature: substmts.0,
4242            must: substmts.1,
4243            presence: substmts.2,
4244            default: substmts.3,
4245            config: substmts.4,
4246            mandatory: substmts.5,
4247            min_elements: substmts.6,
4248            max_elements: substmts.7,
4249            description: substmts.8,
4250            reference: substmts.9,
4251        })
4252    }
4253
4254    /// Parse substatements.
4255    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4256        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4257
4258        Ok((
4259            collect_vec_stmt!(stmts, IfFeatureStmt)?,
4260            collect_vec_stmt!(stmts, MustStmt)?,
4261            collect_opt_stmt!(stmts, PresenceStmt)?,
4262            collect_vec_stmt!(stmts, DefaultStmt)?,
4263            collect_opt_stmt!(stmts, ConfigStmt)?,
4264            collect_opt_stmt!(stmts, MandatoryStmt)?,
4265            collect_opt_stmt!(stmts, MinElementsStmt)?,
4266            collect_opt_stmt!(stmts, MaxElementsStmt)?,
4267            collect_opt_stmt!(stmts, DescriptionStmt)?,
4268            collect_opt_stmt!(stmts, ReferenceStmt)?,
4269        ))
4270    }
4271}
4272
4273///
4274/// The "augment" Statement.
4275///
4276#[derive(Debug, Clone, PartialEq, Getters)]
4277pub struct AugmentStmt {
4278    /// "augment-arg".
4279    arg: SchemaNodeid,
4280
4281    /// "when" statement.
4282    when: Option<WhenStmt>,
4283
4284    /// "if-feature" statement.
4285    if_feature: Vec<IfFeatureStmt>,
4286
4287    /// "status" statement.
4288    status: Option<StatusStmt>,
4289
4290    /// "description" statement.
4291    description: Option<DescriptionStmt>,
4292
4293    /// "reference" statement.
4294    reference: Option<ReferenceStmt>,
4295
4296    /// "data-def" / "case" / "action" / "notification" statement.
4297    data_def_or_else: DataDefOrElse,
4298}
4299
4300impl AugmentStmt {
4301    pub fn container(&self) -> &Vec<ContainerStmt> {
4302        &self.data_def_or_else.container()
4303    }
4304
4305    pub fn leaf(&self) -> &Vec<LeafStmt> {
4306        &self.data_def_or_else.leaf()
4307    }
4308
4309    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
4310        &self.data_def_or_else.leaf_list()
4311    }
4312
4313    pub fn list(&self) -> &Vec<ListStmt> {
4314        &self.data_def_or_else.list()
4315    }
4316
4317    pub fn choice(&self) -> &Vec<ChoiceStmt> {
4318        &self.data_def_or_else.choice()
4319    }
4320
4321    pub fn anydata(&self) -> &Vec<AnydataStmt> {
4322        &self.data_def_or_else.anydata()
4323    }
4324
4325    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
4326        &self.data_def_or_else.anyxml()
4327    }
4328
4329    pub fn uses(&self) -> &Vec<UsesStmt> {
4330        &self.data_def_or_else.uses()
4331    }
4332
4333    pub fn case(&self) -> &Vec<CaseStmt> {
4334        &self.data_def_or_else.case()
4335    }
4336    pub fn action(&self) -> &Vec<ActionStmt> {
4337        &self.data_def_or_else.action()
4338    }
4339    pub fn notification(&self) -> &Vec<NotificationStmt> {
4340        &self.data_def_or_else.notification()
4341    }
4342}
4343
4344impl Stmt for AugmentStmt {
4345    /// Arg type.
4346    type Arg = SchemaNodeid;
4347
4348    /// Sub Statements.
4349    type SubStmts = (
4350        Option<WhenStmt>,
4351        Vec<IfFeatureStmt>,
4352        Option<StatusStmt>,
4353        Option<DescriptionStmt>,
4354        Option<ReferenceStmt>,
4355        DataDefOrElse,
4356    );
4357
4358    /// Return statement keyword.
4359    fn keyword() -> Keyword {
4360        "augment"
4361    }
4362
4363    /// Return true if this statement has substatements.
4364    fn has_substmts() -> bool {
4365        true
4366    }
4367
4368    /// Return substatements definition.
4369    fn substmts_def() -> Vec<SubStmtDef> {
4370        vec![
4371            SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
4372            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
4373            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
4374            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
4375            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
4376            SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefOrElse::keywords)),
4377        ]
4378    }
4379
4380    /// Constructor with tuple of substatements. Panic if it is not defined.
4381    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4382    where
4383        Self: Sized,
4384    {
4385        YangStmt::AugmentStmt(AugmentStmt {
4386            arg,
4387            when: substmts.0,
4388            if_feature: substmts.1,
4389            status: substmts.2,
4390            description: substmts.3,
4391            reference: substmts.4,
4392            data_def_or_else: substmts.5,
4393        })
4394    }
4395
4396    /// Parse substatements.
4397    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4398        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4399
4400        Ok((
4401            collect_opt_stmt!(stmts, WhenStmt)?,
4402            collect_vec_stmt!(stmts, IfFeatureStmt)?,
4403            collect_opt_stmt!(stmts, StatusStmt)?,
4404            collect_opt_stmt!(stmts, DescriptionStmt)?,
4405            collect_opt_stmt!(stmts, ReferenceStmt)?,
4406            DataDefOrElse::new_with_substmts((
4407                collect_vec_stmt!(stmts, ContainerStmt)?,
4408                collect_vec_stmt!(stmts, LeafStmt)?,
4409                collect_vec_stmt!(stmts, LeafListStmt)?,
4410                collect_vec_stmt!(stmts, ListStmt)?,
4411                collect_vec_stmt!(stmts, ChoiceStmt)?,
4412                collect_vec_stmt!(stmts, AnydataStmt)?,
4413                collect_vec_stmt!(stmts, AnyxmlStmt)?,
4414                collect_vec_stmt!(stmts, UsesStmt)?,
4415                collect_vec_stmt!(stmts, CaseStmt)?,
4416                collect_vec_stmt!(stmts, ActionStmt)?,
4417                collect_vec_stmt!(stmts, NotificationStmt)?,
4418            )),
4419        ))
4420    }
4421}
4422
4423///
4424/// The "when" Statement.
4425///
4426#[derive(Debug, Clone, PartialEq, Getters)]
4427pub struct WhenStmt {
4428    /// String.
4429    arg: String,
4430
4431    /// "description" statement.
4432    description: Option<DescriptionStmt>,
4433
4434    /// "reference" statement.
4435    reference: Option<ReferenceStmt>,
4436}
4437
4438impl Stmt for WhenStmt {
4439    /// Arg type.
4440    type Arg = String;
4441
4442    /// Sub Statements.
4443    type SubStmts = (Option<DescriptionStmt>, Option<ReferenceStmt>);
4444
4445    /// Return statement keyword.
4446    fn keyword() -> Keyword {
4447        "when"
4448    }
4449
4450    /// Return true if this statement has sub-statements optionally.
4451    fn opt_substmts() -> bool {
4452        true
4453    }
4454
4455    /// Return substatements definition.
4456    fn substmts_def() -> Vec<SubStmtDef> {
4457        vec![
4458            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
4459            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
4460        ]
4461    }
4462
4463    /// Constructor with a single arg. Panic if it is not defined.
4464    fn new_with_arg(arg: Self::Arg) -> YangStmt
4465    where
4466        Self: Sized,
4467    {
4468        YangStmt::WhenStmt(WhenStmt {
4469            arg,
4470            description: None,
4471            reference: None,
4472        })
4473    }
4474
4475    /// Constructor with tuple of substatements. Panic if it is not defined.
4476    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4477    where
4478        Self: Sized,
4479    {
4480        YangStmt::WhenStmt(WhenStmt {
4481            arg,
4482            description: substmts.0,
4483            reference: substmts.1,
4484        })
4485    }
4486
4487    /// Parse substatements.
4488    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4489        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4490
4491        Ok((
4492            collect_opt_stmt!(stmts, DescriptionStmt)?,
4493            collect_opt_stmt!(stmts, ReferenceStmt)?,
4494        ))
4495    }
4496}
4497
4498///
4499/// The "rpc" Statement.
4500///
4501#[derive(Debug, Clone, PartialEq, Getters)]
4502pub struct RpcStmt {
4503    /// "identifier-arg".
4504    arg: Identifier,
4505
4506    /// "if-feature" statement.
4507    if_feature: Vec<IfFeatureStmt>,
4508
4509    /// "status" statement.
4510    status: Option<StatusStmt>,
4511
4512    /// "description" statement.
4513    description: Option<DescriptionStmt>,
4514
4515    /// "reference" statement.
4516    reference: Option<ReferenceStmt>,
4517
4518    /// "typedef" / "grouping" statement.
4519    typedef_or_grouping: TypedefOrGrouping,
4520
4521    /// "input" statement.
4522    input: Option<InputStmt>,
4523
4524    /// "output" statement.
4525    output: Option<OutputStmt>,
4526}
4527
4528impl RpcStmt {
4529    pub fn typedef(&self) -> &Vec<TypedefStmt> {
4530        &self.typedef_or_grouping.typedef()
4531    }
4532
4533    pub fn grouping(&self) -> &Vec<GroupingStmt> {
4534        &self.typedef_or_grouping.grouping()
4535    }
4536}
4537
4538impl Stmt for RpcStmt {
4539    /// Arg type.
4540    type Arg = Identifier;
4541
4542    /// Sub Statements.
4543    type SubStmts = (
4544        Vec<IfFeatureStmt>,
4545        Option<StatusStmt>,
4546        Option<DescriptionStmt>,
4547        Option<ReferenceStmt>,
4548        TypedefOrGrouping,
4549        Option<InputStmt>,
4550        Option<OutputStmt>,
4551    );
4552
4553    /// Return statement keyword.
4554    fn keyword() -> Keyword {
4555        "rpc"
4556    }
4557
4558    /// Return true if this statement has sub-statements optionally.
4559    fn opt_substmts() -> bool {
4560        true
4561    }
4562
4563    /// Return substatements definition.
4564    fn substmts_def() -> Vec<SubStmtDef> {
4565        vec![
4566            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
4567            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
4568            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
4569            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
4570            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
4571            SubStmtDef::Optional(SubStmtWith::Stmt(InputStmt::keyword)),
4572            SubStmtDef::Optional(SubStmtWith::Stmt(OutputStmt::keyword)),
4573        ]
4574    }
4575
4576    /// Constructor with a single arg. Panic if it is not defined.
4577    fn new_with_arg(arg: Self::Arg) -> YangStmt
4578    where
4579        Self: Sized,
4580    {
4581        YangStmt::RpcStmt(RpcStmt {
4582            arg,
4583            if_feature: Vec::new(),
4584            status: None,
4585            description: None,
4586            reference: None,
4587            typedef_or_grouping: TypedefOrGrouping::new(),
4588            input: None,
4589            output: None,
4590        })
4591    }
4592
4593    /// Constructor with tuple of substatements. Panic if it is not defined.
4594    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4595    where
4596        Self: Sized,
4597    {
4598        YangStmt::RpcStmt(RpcStmt {
4599            arg,
4600            if_feature: substmts.0,
4601            status: substmts.1,
4602            description: substmts.2,
4603            reference: substmts.3,
4604            typedef_or_grouping: substmts.4,
4605            input: substmts.5,
4606            output: substmts.6,
4607        })
4608    }
4609
4610    /// Parse substatements.
4611    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4612        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4613
4614        Ok((
4615            collect_vec_stmt!(stmts, IfFeatureStmt)?,
4616            collect_opt_stmt!(stmts, StatusStmt)?,
4617            collect_opt_stmt!(stmts, DescriptionStmt)?,
4618            collect_opt_stmt!(stmts, ReferenceStmt)?,
4619            TypedefOrGrouping::new_with_substmts((
4620                collect_vec_stmt!(stmts, TypedefStmt)?,
4621                collect_vec_stmt!(stmts, GroupingStmt)?,
4622            )),
4623            collect_opt_stmt!(stmts, InputStmt)?,
4624            collect_opt_stmt!(stmts, OutputStmt)?,
4625        ))
4626    }
4627}
4628
4629///
4630/// The "action" Statement.
4631///
4632#[derive(Debug, Clone, PartialEq, Getters)]
4633pub struct ActionStmt {
4634    /// "identifier" arg.
4635    arg: Identifier,
4636
4637    /// "if-feature" statement.
4638    if_feature: Vec<IfFeatureStmt>,
4639
4640    /// "status" statement.
4641    status: Option<StatusStmt>,
4642
4643    /// "description" statement.
4644    description: Option<DescriptionStmt>,
4645
4646    /// "reference" statement.
4647    reference: Option<ReferenceStmt>,
4648
4649    /// "typedef" / "grouping" statement.
4650    typedef_or_grouping: TypedefOrGrouping,
4651
4652    /// "input" statement.
4653    input: Option<InputStmt>,
4654
4655    /// "output" statement.
4656    output: Option<OutputStmt>,
4657}
4658
4659impl ActionStmt {
4660    pub fn typedef(&self) -> &Vec<TypedefStmt> {
4661        &self.typedef_or_grouping.typedef()
4662    }
4663
4664    pub fn grouping(&self) -> &Vec<GroupingStmt> {
4665        &self.typedef_or_grouping.grouping()
4666    }
4667}
4668
4669impl Stmt for ActionStmt {
4670    /// Arg type.
4671    type Arg = Identifier;
4672
4673    /// Sub Statements.
4674    type SubStmts = (
4675        Vec<IfFeatureStmt>,
4676        Option<StatusStmt>,
4677        Option<DescriptionStmt>,
4678        Option<ReferenceStmt>,
4679        TypedefOrGrouping,
4680        Option<InputStmt>,
4681        Option<OutputStmt>,
4682    );
4683
4684    /// Return statement keyword.
4685    fn keyword() -> Keyword {
4686        "action"
4687    }
4688
4689    /// Return true if this statement has sub-statements optionally.
4690    fn opt_substmts() -> bool {
4691        true
4692    }
4693
4694    /// Return substatements definition.
4695    fn substmts_def() -> Vec<SubStmtDef> {
4696        vec![
4697            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
4698            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
4699            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
4700            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
4701            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
4702            SubStmtDef::Optional(SubStmtWith::Stmt(InputStmt::keyword)),
4703            SubStmtDef::Optional(SubStmtWith::Stmt(OutputStmt::keyword)),
4704        ]
4705    }
4706
4707    /// Constructor with a single arg. Panic if it is not defined.
4708    fn new_with_arg(arg: Self::Arg) -> YangStmt
4709    where
4710        Self: Sized,
4711    {
4712        YangStmt::ActionStmt(ActionStmt {
4713            arg,
4714            if_feature: Vec::new(),
4715            status: None,
4716            description: None,
4717            reference: None,
4718            typedef_or_grouping: TypedefOrGrouping::new(),
4719            input: None,
4720            output: None,
4721        })
4722    }
4723
4724    /// Constructor with tuple of substatements. Panic if it is not defined.
4725    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4726    where
4727        Self: Sized,
4728    {
4729        YangStmt::ActionStmt(ActionStmt {
4730            arg,
4731            if_feature: substmts.0,
4732            status: substmts.1,
4733            description: substmts.2,
4734            reference: substmts.3,
4735            typedef_or_grouping: substmts.4,
4736            input: substmts.5,
4737            output: substmts.6,
4738        })
4739    }
4740
4741    /// Parse substatements.
4742    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4743        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4744
4745        Ok((
4746            collect_vec_stmt!(stmts, IfFeatureStmt)?,
4747            collect_opt_stmt!(stmts, StatusStmt)?,
4748            collect_opt_stmt!(stmts, DescriptionStmt)?,
4749            collect_opt_stmt!(stmts, ReferenceStmt)?,
4750            TypedefOrGrouping::new_with_substmts((
4751                collect_vec_stmt!(stmts, TypedefStmt)?,
4752                collect_vec_stmt!(stmts, GroupingStmt)?,
4753            )),
4754            collect_opt_stmt!(stmts, InputStmt)?,
4755            collect_opt_stmt!(stmts, OutputStmt)?,
4756        ))
4757    }
4758}
4759
4760///
4761/// The "input" Statement.
4762///
4763#[derive(Debug, Clone, PartialEq, Getters)]
4764pub struct InputStmt {
4765    /// "must" statement.
4766    must: Vec<MustStmt>,
4767
4768    /// "typedef" / "grouping" statement.
4769    typedef_or_grouping: TypedefOrGrouping,
4770
4771    /// "data-def" statement.
4772    data_def: DataDefStmt,
4773}
4774
4775impl InputStmt {
4776    pub fn typedef(&self) -> &Vec<TypedefStmt> {
4777        &self.typedef_or_grouping.typedef()
4778    }
4779
4780    pub fn grouping(&self) -> &Vec<GroupingStmt> {
4781        &self.typedef_or_grouping.grouping()
4782    }
4783
4784    pub fn container(&self) -> &Vec<ContainerStmt> {
4785        &self.data_def.container()
4786    }
4787
4788    pub fn leaf(&self) -> &Vec<LeafStmt> {
4789        &self.data_def.leaf()
4790    }
4791
4792    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
4793        &self.data_def.leaf_list()
4794    }
4795
4796    pub fn list(&self) -> &Vec<ListStmt> {
4797        &self.data_def.list()
4798    }
4799
4800    pub fn choice(&self) -> &Vec<ChoiceStmt> {
4801        &self.data_def.choice()
4802    }
4803
4804    pub fn anydata(&self) -> &Vec<AnydataStmt> {
4805        &self.data_def.anydata()
4806    }
4807
4808    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
4809        &self.data_def.anyxml()
4810    }
4811
4812    pub fn uses(&self) -> &Vec<UsesStmt> {
4813        &self.data_def.uses()
4814    }
4815}
4816
4817impl Stmt for InputStmt {
4818    /// Arg type.
4819    type Arg = NoArg;
4820
4821    /// Sub Statements.
4822    type SubStmts = (Vec<MustStmt>, TypedefOrGrouping, DataDefStmt);
4823
4824    /// Return statement keyword.
4825    fn keyword() -> Keyword {
4826        "input"
4827    }
4828
4829    /// Return true if this statement has substatements.
4830    fn has_substmts() -> bool {
4831        true
4832    }
4833
4834    /// Return substatements definition.
4835    fn substmts_def() -> Vec<SubStmtDef> {
4836        vec![
4837            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
4838            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
4839            SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
4840        ]
4841    }
4842
4843    /// Constructor with tuple of substatements. Panic if it is not defined.
4844    fn new_with_substmts(_arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4845    where
4846        Self: Sized,
4847    {
4848        YangStmt::InputStmt(InputStmt {
4849            must: substmts.0,
4850            typedef_or_grouping: substmts.1,
4851            data_def: substmts.2,
4852        })
4853    }
4854
4855    /// Parse substatements.
4856    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4857        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4858
4859        Ok((
4860            collect_vec_stmt!(stmts, MustStmt)?,
4861            TypedefOrGrouping::new_with_substmts((
4862                collect_vec_stmt!(stmts, TypedefStmt)?,
4863                collect_vec_stmt!(stmts, GroupingStmt)?,
4864            )),
4865            DataDefStmt::new_with_substmts((
4866                collect_vec_stmt!(stmts, ContainerStmt)?,
4867                collect_vec_stmt!(stmts, LeafStmt)?,
4868                collect_vec_stmt!(stmts, LeafListStmt)?,
4869                collect_vec_stmt!(stmts, ListStmt)?,
4870                collect_vec_stmt!(stmts, ChoiceStmt)?,
4871                collect_vec_stmt!(stmts, AnydataStmt)?,
4872                collect_vec_stmt!(stmts, AnyxmlStmt)?,
4873                collect_vec_stmt!(stmts, UsesStmt)?,
4874            )),
4875        ))
4876    }
4877}
4878
4879///
4880/// The "output" Statement.
4881///
4882#[derive(Debug, Clone, PartialEq, Getters)]
4883pub struct OutputStmt {
4884    /// "must" statement.
4885    must: Vec<MustStmt>,
4886
4887    /// "typedef" / "grouping" statement.
4888    typedef_or_grouping: TypedefOrGrouping,
4889
4890    /// "data-def" statement.
4891    data_def: DataDefStmt,
4892}
4893
4894impl OutputStmt {
4895    pub fn typedef(&self) -> &Vec<TypedefStmt> {
4896        &self.typedef_or_grouping.typedef()
4897    }
4898
4899    pub fn grouping(&self) -> &Vec<GroupingStmt> {
4900        &self.typedef_or_grouping.grouping()
4901    }
4902
4903    pub fn container(&self) -> &Vec<ContainerStmt> {
4904        &self.data_def.container()
4905    }
4906
4907    pub fn leaf(&self) -> &Vec<LeafStmt> {
4908        &self.data_def.leaf()
4909    }
4910
4911    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
4912        &self.data_def.leaf_list()
4913    }
4914
4915    pub fn list(&self) -> &Vec<ListStmt> {
4916        &self.data_def.list()
4917    }
4918
4919    pub fn choice(&self) -> &Vec<ChoiceStmt> {
4920        &self.data_def.choice()
4921    }
4922
4923    pub fn anydata(&self) -> &Vec<AnydataStmt> {
4924        &self.data_def.anydata()
4925    }
4926
4927    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
4928        &self.data_def.anyxml()
4929    }
4930
4931    pub fn uses(&self) -> &Vec<UsesStmt> {
4932        &self.data_def.uses()
4933    }
4934}
4935
4936impl Stmt for OutputStmt {
4937    /// Arg type.
4938    type Arg = NoArg;
4939
4940    /// Sub Statements.
4941    type SubStmts = (Vec<MustStmt>, TypedefOrGrouping, DataDefStmt);
4942
4943    /// Return statement keyword.
4944    fn keyword() -> Keyword {
4945        "output"
4946    }
4947
4948    /// Return true if this statement has substatements.
4949    fn has_substmts() -> bool {
4950        true
4951    }
4952
4953    /// Return substatements definition.
4954    fn substmts_def() -> Vec<SubStmtDef> {
4955        vec![
4956            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
4957            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
4958            SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
4959        ]
4960    }
4961
4962    /// Constructor with tuple of substatements. Panic if it is not defined.
4963    fn new_with_substmts(_arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
4964    where
4965        Self: Sized,
4966    {
4967        YangStmt::OutputStmt(OutputStmt {
4968            must: substmts.0,
4969            typedef_or_grouping: substmts.1,
4970            data_def: substmts.2,
4971        })
4972    }
4973
4974    /// Parse substatements.
4975    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
4976        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
4977
4978        Ok((
4979            collect_vec_stmt!(stmts, MustStmt)?,
4980            TypedefOrGrouping::new_with_substmts((
4981                collect_vec_stmt!(stmts, TypedefStmt)?,
4982                collect_vec_stmt!(stmts, GroupingStmt)?,
4983            )),
4984            DataDefStmt::new_with_substmts((
4985                collect_vec_stmt!(stmts, ContainerStmt)?,
4986                collect_vec_stmt!(stmts, LeafStmt)?,
4987                collect_vec_stmt!(stmts, LeafListStmt)?,
4988                collect_vec_stmt!(stmts, ListStmt)?,
4989                collect_vec_stmt!(stmts, ChoiceStmt)?,
4990                collect_vec_stmt!(stmts, AnydataStmt)?,
4991                collect_vec_stmt!(stmts, AnyxmlStmt)?,
4992                collect_vec_stmt!(stmts, UsesStmt)?,
4993            )),
4994        ))
4995    }
4996}
4997
4998///
4999/// The "notification" Statement.
5000///
5001#[derive(Debug, Clone, PartialEq, Getters)]
5002pub struct NotificationStmt {
5003    /// "identifier-arg".
5004    arg: Identifier,
5005
5006    /// "if-feature" statement.
5007    if_feature: Vec<IfFeatureStmt>,
5008
5009    /// "must" statement.
5010    must: Vec<MustStmt>,
5011
5012    /// "status" statement.
5013    status: Option<StatusStmt>,
5014
5015    /// "description" statement.
5016    description: Option<DescriptionStmt>,
5017
5018    /// "reference" statement.
5019    reference: Option<ReferenceStmt>,
5020
5021    /// "typedef" / "grouping" statement.
5022    typedef_or_grouping: TypedefOrGrouping,
5023
5024    /// "data-def" statement.
5025    data_def: DataDefStmt,
5026}
5027
5028impl NotificationStmt {
5029    pub fn typedef(&self) -> &Vec<TypedefStmt> {
5030        &self.typedef_or_grouping.typedef()
5031    }
5032
5033    pub fn grouping(&self) -> &Vec<GroupingStmt> {
5034        &self.typedef_or_grouping.grouping()
5035    }
5036
5037    pub fn container(&self) -> &Vec<ContainerStmt> {
5038        &self.data_def.container()
5039    }
5040
5041    pub fn leaf(&self) -> &Vec<LeafStmt> {
5042        &self.data_def.leaf()
5043    }
5044
5045    pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
5046        &self.data_def.leaf_list()
5047    }
5048
5049    pub fn list(&self) -> &Vec<ListStmt> {
5050        &self.data_def.list()
5051    }
5052
5053    pub fn choice(&self) -> &Vec<ChoiceStmt> {
5054        &self.data_def.choice()
5055    }
5056
5057    pub fn anydata(&self) -> &Vec<AnydataStmt> {
5058        &self.data_def.anydata()
5059    }
5060
5061    pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
5062        &self.data_def.anyxml()
5063    }
5064
5065    pub fn uses(&self) -> &Vec<UsesStmt> {
5066        &self.data_def.uses()
5067    }
5068}
5069
5070impl Stmt for NotificationStmt {
5071    /// Arg type.
5072    type Arg = Identifier;
5073
5074    /// Sub Statements.
5075    type SubStmts = (
5076        Vec<IfFeatureStmt>,
5077        Vec<MustStmt>,
5078        Option<StatusStmt>,
5079        Option<DescriptionStmt>,
5080        Option<ReferenceStmt>,
5081        TypedefOrGrouping,
5082        DataDefStmt,
5083    );
5084
5085    /// Return statement keyword.
5086    fn keyword() -> Keyword {
5087        "notification"
5088    }
5089
5090    /// Return true if this statement has sub-statements optionally.
5091    fn opt_substmts() -> bool {
5092        true
5093    }
5094
5095    /// Return substatements definition.
5096    fn substmts_def() -> Vec<SubStmtDef> {
5097        vec![
5098            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
5099            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
5100            SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
5101            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
5102            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
5103            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
5104            SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
5105        ]
5106    }
5107
5108    /// Constructor with a single arg. Panic if it is not defined.
5109    fn new_with_arg(arg: Self::Arg) -> YangStmt
5110    where
5111        Self: Sized,
5112    {
5113        YangStmt::NotificationStmt(NotificationStmt {
5114            arg,
5115            if_feature: Vec::new(),
5116            must: Vec::new(),
5117            status: None,
5118            description: None,
5119            reference: None,
5120            typedef_or_grouping: TypedefOrGrouping::new(),
5121            data_def: DataDefStmt::new(),
5122        })
5123    }
5124
5125    /// Constructor with tuple of substatements. Panic if it is not defined.
5126    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
5127    where
5128        Self: Sized,
5129    {
5130        YangStmt::NotificationStmt(NotificationStmt {
5131            arg,
5132            if_feature: substmts.0,
5133            must: substmts.1,
5134            status: substmts.2,
5135            description: substmts.3,
5136            reference: substmts.4,
5137            typedef_or_grouping: substmts.5,
5138            data_def: substmts.6,
5139        })
5140    }
5141
5142    /// Parse substatements.
5143    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
5144        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
5145
5146        Ok((
5147            collect_vec_stmt!(stmts, IfFeatureStmt)?,
5148            collect_vec_stmt!(stmts, MustStmt)?,
5149            collect_opt_stmt!(stmts, StatusStmt)?,
5150            collect_opt_stmt!(stmts, DescriptionStmt)?,
5151            collect_opt_stmt!(stmts, ReferenceStmt)?,
5152            TypedefOrGrouping::new_with_substmts((
5153                collect_vec_stmt!(stmts, TypedefStmt)?,
5154                collect_vec_stmt!(stmts, GroupingStmt)?,
5155            )),
5156            DataDefStmt::new_with_substmts((
5157                collect_vec_stmt!(stmts, ContainerStmt)?,
5158                collect_vec_stmt!(stmts, LeafStmt)?,
5159                collect_vec_stmt!(stmts, LeafListStmt)?,
5160                collect_vec_stmt!(stmts, ListStmt)?,
5161                collect_vec_stmt!(stmts, ChoiceStmt)?,
5162                collect_vec_stmt!(stmts, AnydataStmt)?,
5163                collect_vec_stmt!(stmts, AnyxmlStmt)?,
5164                collect_vec_stmt!(stmts, UsesStmt)?,
5165            )),
5166        ))
5167    }
5168}
5169
5170///
5171/// The "deviation" Statement.
5172///
5173#[derive(Debug, Clone, PartialEq, Getters)]
5174pub struct DeviationStmt {
5175    /// "deviation-arg".
5176    arg: DeviationArg,
5177
5178    /// "description" statement.
5179    description: Option<DescriptionStmt>,
5180
5181    /// "reference" statement.
5182    reference: Option<ReferenceStmt>,
5183
5184    /// "deviate" statement.
5185    deviate: Vec<DeviateStmt>,
5186}
5187
5188impl Stmt for DeviationStmt {
5189    /// Arg type.
5190    type Arg = DeviationArg;
5191
5192    /// Sub Statements.
5193    type SubStmts = (
5194        Option<DescriptionStmt>,
5195        Option<ReferenceStmt>,
5196        Vec<DeviateStmt>,
5197    );
5198
5199    /// Return statement keyword.
5200    fn keyword() -> Keyword {
5201        "deviation"
5202    }
5203
5204    /// Return true if this statement has substatements.
5205    fn has_substmts() -> bool {
5206        true
5207    }
5208
5209    /// Return substatements definition.
5210    fn substmts_def() -> Vec<SubStmtDef> {
5211        vec![
5212            SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
5213            SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
5214            SubStmtDef::OneOrMore(SubStmtWith::Stmt(DeviateStmt::keyword)),
5215        ]
5216    }
5217
5218    /// Constructor with tuple of substatements. Panic if it is not defined.
5219    fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
5220    where
5221        Self: Sized,
5222    {
5223        YangStmt::DeviationStmt(DeviationStmt {
5224            arg,
5225            description: substmts.0,
5226            reference: substmts.1,
5227            deviate: substmts.2,
5228        })
5229    }
5230
5231    /// Parse substatements.
5232    fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
5233        let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
5234
5235        Ok((
5236            collect_opt_stmt!(stmts, DescriptionStmt)?,
5237            collect_opt_stmt!(stmts, ReferenceStmt)?,
5238            collect_vec_stmt!(stmts, DeviateStmt)?,
5239        ))
5240    }
5241}
5242
5243///
5244/// The "deviate" Statement.
5245///
5246#[derive(Debug, Clone, PartialEq)]
5247pub enum DeviateStmt {
5248    /// "deviate not-supported".
5249    NotSupported,
5250
5251    /// "deviate add".
5252    Add(DeviateAddStmt),
5253
5254    /// "deviate replace".
5255    Replace(DeviateReplaceStmt),
5256
5257    /// "deviate delete".
5258    Delete(DeviateDeleteStmt),
5259}
5260
5261impl Stmt for DeviateStmt {
5262    /// Arg type.
5263    type Arg = String;
5264
5265    /// Sub Statements.
5266    type SubStmts = ();
5267
5268    /// Return statement keyword.
5269    fn keyword() -> Keyword {
5270        "deviate"
5271    }
5272
5273    /// Parse a statement and return the object wrapped in enum.
5274    fn parse(parser: &mut Parser) -> Result<YangStmt, YangError>
5275    where
5276        Self::Arg: StmtArg,
5277        Self: Sized,
5278    {
5279        let arg = Self::Arg::parse_arg(parser)?;
5280
5281        match &arg as &str {
5282            "add" => {
5283                let stmt = DeviateAddStmt::parse(parser)?;
5284                Ok(YangStmt::DeviateStmt(DeviateStmt::Add(stmt)))
5285            }
5286            "delete" => {
5287                let stmt = DeviateDeleteStmt::parse(parser)?;
5288                Ok(YangStmt::DeviateStmt(DeviateStmt::Delete(stmt)))
5289            }
5290            "replace" => {
5291                let stmt = DeviateReplaceStmt::parse(parser)?;
5292                Ok(YangStmt::DeviateStmt(DeviateStmt::Replace(stmt)))
5293            }
5294            "not-supported" => {
5295                let token = parser.get_token()?;
5296                match token {
5297                    Token::StatementEnd => Ok(YangStmt::DeviateStmt(DeviateStmt::NotSupported)),
5298                    _ => Err(YangError::UnexpectedToken(token.to_string())),
5299                }
5300            }
5301            _ => Err(YangError::UnexpectedToken(arg.to_string())),
5302        }
5303    }
5304}
5305
5306///
5307/// The "deviate add" Statement.
5308///
5309#[derive(Debug, Clone, PartialEq, Getters)]
5310pub struct DeviateAddStmt {
5311    /// "units" statement.
5312    units: Option<UnitsStmt>,
5313
5314    /// "must" statement.
5315    must: Vec<MustStmt>,
5316
5317    /// "unique" statement.
5318    unique: Vec<UniqueStmt>,
5319
5320    /// "default" statement.
5321    default: Vec<DefaultStmt>,
5322
5323    /// "config" statement.
5324    config: Option<ConfigStmt>,
5325
5326    /// "mandatory" statement.
5327    mandatory: Option<MandatoryStmt>,
5328
5329    /// "min-elements" statement.
5330    min_elements: Option<MinElementsStmt>,
5331
5332    /// "max-elements" statement.
5333    max_elements: Option<MaxElementsStmt>,
5334}
5335
5336impl Compound for DeviateAddStmt {
5337    /// Return substatements definition.
5338    fn substmts_def() -> Vec<SubStmtDef> {
5339        vec![
5340            SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
5341            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
5342            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(UniqueStmt::keyword)),
5343            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
5344            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
5345            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
5346            SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
5347            SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
5348        ]
5349    }
5350}
5351
5352impl DeviateAddStmt {
5353    pub fn parse(parser: &mut Parser) -> Result<DeviateAddStmt, YangError> {
5354        let token = parser.get_token()?;
5355        match token {
5356            Token::BlockBegin => {
5357                let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
5358
5359                let token = parser.get_token()?;
5360                match token {
5361                    Token::BlockEnd => Ok(DeviateAddStmt {
5362                        units: collect_opt_stmt!(stmts, UnitsStmt)?,
5363                        must: collect_vec_stmt!(stmts, MustStmt)?,
5364                        unique: collect_vec_stmt!(stmts, UniqueStmt)?,
5365                        default: collect_vec_stmt!(stmts, DefaultStmt)?,
5366                        config: collect_opt_stmt!(stmts, ConfigStmt)?,
5367                        mandatory: collect_opt_stmt!(stmts, MandatoryStmt)?,
5368                        min_elements: collect_opt_stmt!(stmts, MinElementsStmt)?,
5369                        max_elements: collect_opt_stmt!(stmts, MaxElementsStmt)?,
5370                    }),
5371                    _ => Err(YangError::UnexpectedToken(token.to_string())),
5372                }
5373            }
5374            Token::StatementEnd => Ok(DeviateAddStmt {
5375                units: None,
5376                must: Vec::new(),
5377                unique: Vec::new(),
5378                default: Vec::new(),
5379                config: None,
5380                mandatory: None,
5381                min_elements: None,
5382                max_elements: None,
5383            }),
5384            _ => Err(YangError::UnexpectedToken(token.to_string())),
5385        }
5386    }
5387}
5388
5389///
5390/// The "deviate delete" Statement.
5391///
5392#[derive(Debug, Clone, PartialEq, Getters)]
5393pub struct DeviateDeleteStmt {
5394    /// "units" statement.
5395    units: Option<UnitsStmt>,
5396
5397    /// "must" statement.
5398    must: Vec<MustStmt>,
5399
5400    /// "unique" statement.
5401    unique: Vec<UniqueStmt>,
5402
5403    /// "default" statement.
5404    default: Vec<DefaultStmt>,
5405}
5406
5407impl Compound for DeviateDeleteStmt {
5408    /// Return substatements definition.
5409    fn substmts_def() -> Vec<SubStmtDef> {
5410        vec![
5411            SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
5412            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
5413            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(UniqueStmt::keyword)),
5414            SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
5415        ]
5416    }
5417}
5418
5419impl DeviateDeleteStmt {
5420    /// Parse a statement and return the object wrapped in enum.
5421    fn parse(parser: &mut Parser) -> Result<DeviateDeleteStmt, YangError> {
5422        let token = parser.get_token()?;
5423        match token {
5424            Token::BlockBegin => {
5425                let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
5426                let token = parser.get_token()?;
5427
5428                match token {
5429                    Token::BlockEnd => Ok(DeviateDeleteStmt {
5430                        units: collect_opt_stmt!(stmts, UnitsStmt)?,
5431                        must: collect_vec_stmt!(stmts, MustStmt)?,
5432                        unique: collect_vec_stmt!(stmts, UniqueStmt)?,
5433                        default: collect_vec_stmt!(stmts, DefaultStmt)?,
5434                    }),
5435                    _ => Err(YangError::UnexpectedToken(token.to_string())),
5436                }
5437            }
5438            Token::StatementEnd => Ok(DeviateDeleteStmt {
5439                units: None,
5440                must: Vec::new(),
5441                unique: Vec::new(),
5442                default: Vec::new(),
5443            }),
5444            _ => Err(YangError::UnexpectedToken(token.to_string())),
5445        }
5446    }
5447}
5448
5449///
5450/// The "deviate replace" Statement.
5451///
5452#[derive(Debug, Clone, PartialEq, Getters)]
5453pub struct DeviateReplaceStmt {
5454    /// "type" statement.
5455    type_: Option<TypeStmt>,
5456
5457    /// "units" statement.
5458    units: Option<UnitsStmt>,
5459
5460    /// "default" statement.
5461    default: Option<DefaultStmt>,
5462
5463    /// "config" statement.
5464    config: Option<ConfigStmt>,
5465
5466    /// "mandatory" statement.
5467    mandatory: Option<MandatoryStmt>,
5468
5469    /// "min-elements" statement.
5470    min_elements: Option<MinElementsStmt>,
5471
5472    /// "max-elements" statement.
5473    max_elements: Option<MaxElementsStmt>,
5474}
5475
5476impl Compound for DeviateReplaceStmt {
5477    /// Return substatements definition.
5478    fn substmts_def() -> Vec<SubStmtDef> {
5479        vec![
5480            SubStmtDef::Optional(SubStmtWith::Stmt(TypeStmt::keyword)),
5481            SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
5482            SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
5483            SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
5484            SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
5485            SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
5486            SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
5487        ]
5488    }
5489}
5490
5491impl DeviateReplaceStmt {
5492    pub fn parse(parser: &mut Parser) -> Result<DeviateReplaceStmt, YangError> {
5493        let token = parser.get_token()?;
5494        match token {
5495            Token::BlockBegin => {
5496                let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
5497
5498                let token = parser.get_token()?;
5499                match token {
5500                    Token::BlockEnd => Ok(DeviateReplaceStmt {
5501                        type_: collect_opt_stmt!(stmts, TypeStmt)?,
5502                        units: collect_opt_stmt!(stmts, UnitsStmt)?,
5503                        default: collect_opt_stmt!(stmts, DefaultStmt)?,
5504                        config: collect_opt_stmt!(stmts, ConfigStmt)?,
5505                        mandatory: collect_opt_stmt!(stmts, MandatoryStmt)?,
5506                        min_elements: collect_opt_stmt!(stmts, MinElementsStmt)?,
5507                        max_elements: collect_opt_stmt!(stmts, MaxElementsStmt)?,
5508                    }),
5509                    _ => Err(YangError::UnexpectedToken(token.to_string())),
5510                }
5511            }
5512            Token::StatementEnd => Ok(DeviateReplaceStmt {
5513                type_: None,
5514                units: None,
5515                default: None,
5516                config: None,
5517                mandatory: None,
5518                min_elements: None,
5519                max_elements: None,
5520            }),
5521            _ => Err(YangError::UnexpectedToken(token.to_string())),
5522        }
5523    }
5524}
5525
5526///
5527/// Unknown Statement.
5528///
5529#[derive(Debug, Clone, PartialEq, Getters)]
5530pub struct UnknownStmt {
5531    /// Keyword
5532    keyword: UnknownStmtKeyword,
5533
5534    /// Optional arg.
5535    arg: Option<String>,
5536
5537    /// YANG statement.
5538    yang: Vec<YangStmt>,
5539}
5540
5541impl UnknownStmt {
5542    /// Parse a statement and return the object wrapped in enum.
5543    pub fn parse(parser: &mut Parser, keyword: &str) -> Result<YangStmt, YangError>
5544    where
5545        Self: Sized,
5546    {
5547        let keyword = UnknownStmtKeyword::from_str(keyword)
5548            .map_err(|e| YangError::ArgumentParseError(e.str))?;
5549
5550        let token = parser.get_token()?;
5551        let arg = match token {
5552            Token::Identifier(s) | Token::QuotedString(s) => Some(s),
5553            Token::StatementEnd => {
5554                parser.save_token(token);
5555                None
5556            }
5557            _ => return Err(YangError::UnexpectedToken(token.to_string())),
5558        };
5559
5560        let token = parser.get_token()?;
5561        let mut yang = Vec::new();
5562        match token {
5563            Token::StatementEnd => {}
5564            Token::BlockBegin => loop {
5565                let token = parser.get_token()?;
5566
5567                match token {
5568                    Token::BlockEnd => break,
5569                    Token::StatementEnd => {}
5570                    Token::QuotedString(ref keyword) | Token::Identifier(ref keyword) => {
5571                        let stmt = SubStmtUtil::call_stmt_parser(parser, keyword as &str)?;
5572                        yang.push(stmt);
5573                    }
5574                    Token::EndOfInput => return Err(YangError::UnexpectedEof),
5575                    _ => return Err(YangError::UnexpectedToken(token.to_string())),
5576                }
5577            },
5578            _ => return Err(YangError::UnexpectedToken(token.to_string())),
5579        }
5580
5581        Ok(YangStmt::UnknownStmt(UnknownStmt { keyword, arg, yang }))
5582    }
5583}
5584
5585#[cfg(test)]
5586mod tests {
5587    use super::*;
5588    use std::str::FromStr;
5589
5590    #[test]
5591    pub fn test_import_stmt() {
5592        // Assuming keyword is already parsed, and arg and body are given to stmt parser.
5593        let s = r#"openconfig-inet-types {
5594                       prefix oc-inet;
5595                       revision-date 2017-07-06;
5596                   }"#;
5597
5598        let mut parser = Parser::new(s.to_string());
5599        match ImportStmt::parse(&mut parser) {
5600            Ok(yang) => match yang {
5601                YangStmt::ImportStmt(stmt) => {
5602                    assert_eq!(
5603                        stmt.arg(),
5604                        &Identifier::from_str("openconfig-inet-types").unwrap()
5605                    );
5606                    assert_eq!(
5607                        stmt.prefix(),
5608                        &PrefixStmt {
5609                            arg: Identifier::from_str("oc-inet").unwrap()
5610                        }
5611                    );
5612                    assert_eq!(
5613                        stmt.revision_date(),
5614                        &Some(RevisionDateStmt {
5615                            arg: DateArg::from_str("2017-07-06").unwrap()
5616                        })
5617                    );
5618                    assert_eq!(stmt.description(), &None);
5619                    assert_eq!(stmt.reference(), &None);
5620                }
5621                _ => panic!("Unexpected stmt {:?}", yang),
5622            },
5623            Err(err) => panic!("{}", err.to_string()),
5624        }
5625    }
5626
5627    #[test]
5628    pub fn test_include_stmt() {
5629        // Assuming keyword is already parsed, and arg and body are given to stmt parser.
5630        let s = r#"openconfig-inet-types {
5631                       prefix oc-inet;
5632                       revision-date 2017-07-06;
5633                   }"#;
5634
5635        let mut parser = Parser::new(s.to_string());
5636        match IncludeStmt::parse(&mut parser) {
5637            Ok(yang) => panic!("{:?}", yang),
5638            Err(err) => assert_eq!(err.to_string(), "Unexpected token Identifier '\"prefix\"'"),
5639        }
5640
5641        let s = r#"openconfig-inet-types {
5642                       revision-date 2017-07-06;
5643                   }"#;
5644
5645        let mut parser = Parser::new(s.to_string());
5646        match IncludeStmt::parse(&mut parser) {
5647            Ok(yang) => match yang {
5648                YangStmt::IncludeStmt(stmt) => {
5649                    assert_eq!(
5650                        stmt.arg(),
5651                        &Identifier::from_str("openconfig-inet-types").unwrap()
5652                    );
5653                    assert_eq!(
5654                        stmt.revision_date(),
5655                        &Some(RevisionDateStmt {
5656                            arg: DateArg::from_str("2017-07-06").unwrap()
5657                        })
5658                    );
5659                    assert_eq!(stmt.description(), &None);
5660                    assert_eq!(stmt.reference(), &None);
5661                }
5662                _ => panic!("Unexpected stmt {:?}", yang),
5663            },
5664            Err(err) => panic!("{}", err.to_string()),
5665        }
5666    }
5667
5668    #[test]
5669    pub fn test_extension_stmt() {
5670        // Assuming keyword is already parsed, and arg and body are given to stmt parser.
5671        let s = r#"openconfig-version {
5672    argument "semver" {
5673      yin-element false;
5674    }
5675    description
5676      "The OpenConfig version number for the module. This is
5677      ...";
5678    }"#;
5679
5680        let mut parser = Parser::new(s.to_string());
5681        match ExtensionStmt::parse(&mut parser) {
5682            Ok(yang) => match yang {
5683                YangStmt::ExtensionStmt(stmt) => {
5684                    assert_eq!(
5685                        stmt.arg(),
5686                        &Identifier::from_str("openconfig-version").unwrap()
5687                    );
5688                    match stmt.argument() {
5689                        Some(argument_stmt) => {
5690                            assert_eq!(
5691                                argument_stmt.arg(),
5692                                &Identifier::from_str("semver").unwrap()
5693                            );
5694                            match argument_stmt.yin_element() {
5695                                Some(yin_element_stmt) => {
5696                                    assert_eq!(
5697                                        yin_element_stmt.arg(),
5698                                        &YinElementArg::from_str("false").unwrap()
5699                                    );
5700                                }
5701                                None => panic!("No yin-element-stmt"),
5702                            }
5703                        }
5704                        None => panic!("No argument-stmt"),
5705                    }
5706                    assert_eq!(stmt.status(), &None);
5707                    match stmt.description() {
5708                        Some(description_stmt) => {
5709                            assert_eq!(
5710                                description_stmt.arg(),
5711                                "The OpenConfig version number for the module. This is\n..."
5712                            );
5713                        }
5714                        None => panic!("No description-stmt"),
5715                    }
5716                    assert_eq!(stmt.reference(), &None);
5717                }
5718                _ => panic!("Unexpected stmt {:?}", yang),
5719            },
5720            Err(err) => panic!("{}", err.to_string()),
5721        }
5722    }
5723
5724    #[test]
5725    pub fn test_identity_stmt() {
5726        // Assuming keyword is already parsed, and arg and body are given to stmt parser.
5727        let s = r#"SFP {
5728    base TRANSCEIVER_FORM_FACTOR_TYPE;
5729    description
5730      "Small form-factor pluggable transceiver supporting up to
5731      10 Gb/s signal";
5732    }"#;
5733        let mut parser = Parser::new(s.to_string());
5734        match IdentityStmt::parse(&mut parser) {
5735            Ok(yang) => match yang {
5736                YangStmt::IdentityStmt(stmt) => {
5737                    assert_eq!(stmt.arg(), &Identifier::from_str("SFP").unwrap());
5738                    assert_eq!(stmt.if_feature(), &vec![]);
5739                    assert_eq!(
5740                        stmt.base(),
5741                        &vec![BaseStmt {
5742                            arg: IdentifierRef::from_str("TRANSCEIVER_FORM_FACTOR_TYPE").unwrap()
5743                        }]
5744                    );
5745                    assert_eq!(stmt.status(), &None);
5746                    assert_eq!(stmt.description(), &Some(DescriptionStmt { arg: String::from("Small form-factor pluggable transceiver supporting up to\n10 Gb/s signal") }));
5747                    assert_eq!(stmt.reference(), &None);
5748                }
5749                _ => panic!("Unexpected stmt {:?}", yang),
5750            },
5751            Err(err) => panic!("{}", err.to_string()),
5752        }
5753    }
5754
5755    //    #[test]
5756    //    pub fn test_feature_stmt() {
5757    //        // TBD
5758    //    }
5759
5760    #[test]
5761    pub fn test_typedef_stmt() {
5762        let s = r#"zero-based-counter32 {
5763    type yang:counter32;
5764    default "0";
5765    description
5766     "The zero-based-counter32 type represents a counter32
5767      that has the defined 'initial' value zero....";
5768    reference
5769      "RFC 4502: Remote Network Monitoring Management Information
5770                 Base Version 2";
5771    }"#;
5772
5773        let mut parser = Parser::new(s.to_string());
5774        match TypedefStmt::parse(&mut parser) {
5775            Ok(yang) => match yang {
5776                YangStmt::TypedefStmt(stmt) => {
5777                    assert_eq!(
5778                        stmt.arg(),
5779                        &Identifier::from_str("zero-based-counter32").unwrap()
5780                    );
5781                    assert_eq!(
5782                        stmt.type_(),
5783                        &TypeStmt {
5784                            arg: IdentifierRef::from_str("yang:counter32").unwrap(),
5785                            type_body: None
5786                        }
5787                    );
5788                    assert_eq!(stmt.units(), &None);
5789                    assert_eq!(
5790                        stmt.default(),
5791                        &Some(DefaultStmt {
5792                            arg: String::from("0")
5793                        })
5794                    );
5795                    assert_eq!(stmt.description(), &Some(DescriptionStmt { arg: String::from("The zero-based-counter32 type represents a counter32\nthat has the defined 'initial' value zero....") }));
5796                    assert_eq!(stmt.reference(), &Some(ReferenceStmt { arg: String::from("RFC 4502: Remote Network Monitoring Management Information\n          Base Version 2") }));
5797                }
5798                _ => panic!("Unexpected stmt {:?}", yang),
5799            },
5800            Err(err) => panic!("{}", err.to_string()),
5801        }
5802    }
5803
5804    #[test]
5805    pub fn test_deviation_stmt() {
5806        // Assuming keyword is already parsed, and arg and body are given to stmt parser.
5807
5808        // Deviation add.
5809        let s = r#""/oc-if:interfaces/oc-if:interface/oc-if:hold-time" +
5810            "/oc-if:config/oc-if:up" {
5811      deviate add;
5812  }"#;
5813        let mut parser = Parser::new(s.to_string());
5814        match DeviationStmt::parse(&mut parser) {
5815            Ok(yang) => match yang {
5816                YangStmt::DeviationStmt(stmt) => {
5817                    assert_eq!(stmt.arg(), &AbsoluteSchemaNodeid::from_str("/oc-if:interfaces/oc-if:interface/oc-if:hold-time/oc-if:config/oc-if:up").unwrap());
5818                    assert_eq!(stmt.description(), &None);
5819                    assert_eq!(stmt.reference(), &None);
5820                    assert_eq!(stmt.deviate().len(), 1);
5821                    let deviate_stmt = stmt.deviate().get(0).unwrap();
5822                    match deviate_stmt {
5823                        DeviateStmt::Add(deviate_add_stmt) => {
5824                            assert_eq!(deviate_add_stmt.units(), &None);
5825                            assert_eq!(deviate_add_stmt.must().len(), 0);
5826                            assert_eq!(deviate_add_stmt.unique().len(), 0);
5827                            assert_eq!(deviate_add_stmt.config(), &None);
5828                            assert_eq!(deviate_add_stmt.mandatory(), &None);
5829                            assert_eq!(deviate_add_stmt.min_elements(), &None);
5830                            assert_eq!(deviate_add_stmt.max_elements(), &None);
5831                        }
5832                        _ => panic!("Unexpected stmt {:?}", deviate_stmt),
5833                    }
5834                }
5835                _ => panic!("Unexpected stmt {:?}", yang),
5836            },
5837            Err(err) => panic!("{}", err.to_string()),
5838        }
5839
5840        // Deviation delete.
5841        let s = r#""/oc-if:interfaces/oc-if:interface/oc-if:hold-time" +
5842            "/oc-if:config/oc-if:up" {
5843      deviate delete {
5844        default 0;
5845      }
5846      description
5847        "Hold-time 0 is not configurable on XE, use no dampening.";
5848  }"#;
5849        let mut parser = Parser::new(s.to_string());
5850        match DeviationStmt::parse(&mut parser) {
5851            Ok(yang) => match yang {
5852                YangStmt::DeviationStmt(stmt) => {
5853                    assert_eq!(stmt.arg(), &AbsoluteSchemaNodeid::from_str("/oc-if:interfaces/oc-if:interface/oc-if:hold-time/oc-if:config/oc-if:up").unwrap());
5854                    assert_eq!(
5855                        stmt.description(),
5856                        &Some(DescriptionStmt {
5857                            arg: String::from(
5858                                "Hold-time 0 is not configurable on XE, use no dampening."
5859                            )
5860                        })
5861                    );
5862                    assert_eq!(stmt.reference(), &None);
5863                    assert_eq!(stmt.deviate().len(), 1);
5864                    let deviate_stmt = stmt.deviate().get(0).unwrap();
5865                    match deviate_stmt {
5866                        DeviateStmt::Delete(deviate_delete_stmt) => {
5867                            assert_eq!(deviate_delete_stmt.units(), &None);
5868                            assert_eq!(deviate_delete_stmt.must().len(), 0);
5869                            assert_eq!(deviate_delete_stmt.unique().len(), 0);
5870                            assert_eq!(
5871                                deviate_delete_stmt.default(),
5872                                &vec![DefaultStmt {
5873                                    arg: String::from("0")
5874                                }]
5875                            );
5876                        }
5877                        _ => panic!("Unexpected stmt {:?}", deviate_stmt),
5878                    }
5879                }
5880                _ => panic!("Unexpected stmt {:?}", yang),
5881            },
5882            Err(err) => panic!("{}", err.to_string()),
5883        }
5884
5885        // Deviation replace
5886        let s = r#""/oc-if:interfaces/oc-if:interface/oc-if:state" +
5887            "/oc-if:last-change" {
5888      deviate replace {
5889        type yang:date-and-time;
5890      }
5891      description
5892        "Change the type of the last-change flag to date-and-time";
5893  }"#;
5894        let mut parser = Parser::new(s.to_string());
5895        match DeviationStmt::parse(&mut parser) {
5896            Ok(yang) => match yang {
5897                YangStmt::DeviationStmt(stmt) => {
5898                    assert_eq!(
5899                        stmt.arg(),
5900                        &AbsoluteSchemaNodeid::from_str(
5901                            "/oc-if:interfaces/oc-if:interface/oc-if:state/oc-if:last-change"
5902                        )
5903                        .unwrap()
5904                    );
5905                    assert_eq!(
5906                        stmt.description(),
5907                        &Some(DescriptionStmt {
5908                            arg: String::from(
5909                                "Change the type of the last-change flag to date-and-time"
5910                            )
5911                        })
5912                    );
5913                    assert_eq!(stmt.reference(), &None);
5914                    assert_eq!(stmt.deviate().len(), 1);
5915                    let deviate_stmt = stmt.deviate().get(0).unwrap();
5916                    match deviate_stmt {
5917                        DeviateStmt::Replace(deviate_replace_stmt) => {
5918                            assert_eq!(
5919                                deviate_replace_stmt.type_(),
5920                                &Some(TypeStmt {
5921                                    arg: IdentifierRef::from_str("yang:date-and-time").unwrap(),
5922                                    type_body: None
5923                                })
5924                            );
5925                            assert_eq!(deviate_replace_stmt.units(), &None);
5926                            assert_eq!(deviate_replace_stmt.default(), &None);
5927                            assert_eq!(deviate_replace_stmt.config(), &None);
5928                            assert_eq!(deviate_replace_stmt.mandatory(), &None);
5929                            assert_eq!(deviate_replace_stmt.min_elements(), &None);
5930                            assert_eq!(deviate_replace_stmt.max_elements(), &None);
5931                        }
5932                        _ => panic!("Unexpected stmt {:?}", deviate_stmt),
5933                    }
5934                }
5935                _ => panic!("Unexpected stmt {:?}", yang),
5936            },
5937            Err(err) => panic!("{}", err.to_string()),
5938        }
5939
5940        // Deviation not-supported
5941        let s = r#""/oc-if:interfaces/oc-if:interface/oc-vlan:routed-vlan" +
5942            "/oc-ip:ipv4/oc-ip:addresses/oc-ip:address/oc-ip:vrrp" {
5943      deviate not-supported;
5944      description
5945        "IPv4 VRRP not supported in 16.6.1.";
5946  }"#;
5947        let mut parser = Parser::new(s.to_string());
5948        match DeviationStmt::parse(&mut parser) {
5949            Ok(yang) => match yang {
5950                YangStmt::DeviationStmt(stmt) => {
5951                    assert_eq!(stmt.arg(), &AbsoluteSchemaNodeid::from_str("/oc-if:interfaces/oc-if:interface/oc-vlan:routed-vlan/oc-ip:ipv4/oc-ip:addresses/oc-ip:address/oc-ip:vrrp").unwrap());
5952                    assert_eq!(
5953                        stmt.description(),
5954                        &Some(DescriptionStmt {
5955                            arg: String::from("IPv4 VRRP not supported in 16.6.1.")
5956                        })
5957                    );
5958                    assert_eq!(stmt.reference(), &None);
5959                    assert_eq!(stmt.deviate().len(), 1);
5960                    let deviate_stmt = stmt.deviate().get(0).unwrap();
5961                    match deviate_stmt {
5962                        DeviateStmt::NotSupported => {}
5963                        _ => panic!("Unexpected stmt {:?}", deviate_stmt),
5964                    }
5965                }
5966                _ => panic!("Unexpected stmt {:?}", yang),
5967            },
5968            Err(err) => panic!("{}", err.to_string()),
5969        }
5970    }
5971}