use std::str::FromStr;
use url::Url;
use derive_getters::Getters;
use super::arg::*;
use super::compound::Compound;
use super::compound::*;
use super::core::*;
use super::error::*;
use super::parser::*;
use super::substmt::*;
use crate::collect_a_stmt;
use crate::collect_opt_stmt;
use crate::collect_vec_stmt;
pub trait Stmt {
type Arg;
type SubStmts;
fn keyword() -> Keyword;
fn has_substmts() -> bool {
false
}
fn opt_substmts() -> bool {
false
}
fn substmts_def() -> Vec<SubStmtDef> {
panic!("{:?}", Self::keyword());
}
fn new_with_arg(_arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
panic!("{:?}", Self::keyword());
}
fn new_with_substmts(_arg: Self::Arg, _substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
panic!("{:?}", Self::keyword());
}
fn parse_substmts(_parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
panic!("{:?}", Self::keyword());
}
fn parse(parser: &mut Parser) -> Result<YangStmt, YangError>
where
Self::Arg: StmtArg,
Self: Sized,
{
let arg = Self::Arg::parse_arg(parser)?;
if Self::has_substmts() {
let token = parser.get_token()?;
match token {
Token::BlockBegin => {
let substmts = Self::parse_substmts(parser)?;
let token = parser.get_token()?;
match token {
Token::BlockEnd => Ok(Self::new_with_substmts(arg, substmts)),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
} else if Self::opt_substmts() {
let token = parser.get_token()?;
match token {
Token::StatementEnd => Ok(Self::new_with_arg(arg)),
Token::BlockBegin => {
let substmts = Self::parse_substmts(parser)?;
let token = parser.get_token()?;
match token {
Token::BlockEnd => Ok(Self::new_with_substmts(arg, substmts)),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
} else {
let token = parser.get_token()?;
match token {
Token::StatementEnd => Ok(Self::new_with_arg(arg)),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ModuleStmt {
arg: Identifier,
module_header: ModuleHeaderStmts,
linkage: LinkageStmts,
meta: MetaStmts,
revision: RevisionStmts,
body: BodyStmts,
}
impl Stmt for ModuleStmt {
type Arg = Identifier;
type SubStmts = (
ModuleHeaderStmts,
LinkageStmts,
MetaStmts,
RevisionStmts,
BodyStmts,
);
fn keyword() -> Keyword {
"module"
}
fn has_substmts() -> bool {
true
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ModuleStmt(ModuleStmt {
arg,
module_header: substmts.0,
linkage: substmts.1,
meta: substmts.2,
revision: substmts.3,
body: substmts.4,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let module_header = ModuleHeaderStmts::parse(parser)?;
let linkage = LinkageStmts::parse(parser)?;
let meta = MetaStmts::parse(parser)?;
let revision = RevisionStmts::parse(parser)?;
let body = BodyStmts::parse(parser)?;
Ok((module_header, linkage, meta, revision, body))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct SubmoduleStmt {
arg: Identifier,
submodule_header: SubmoduleHeaderStmts,
linkage: LinkageStmts,
meta: MetaStmts,
revision: RevisionStmts,
body: BodyStmts,
}
impl Stmt for SubmoduleStmt {
type Arg = Identifier;
type SubStmts = (
SubmoduleHeaderStmts,
LinkageStmts,
MetaStmts,
RevisionStmts,
BodyStmts,
);
fn keyword() -> Keyword {
"submodule"
}
fn has_substmts() -> bool {
true
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::SubmoduleStmt(SubmoduleStmt {
arg,
submodule_header: substmts.0,
linkage: substmts.1,
meta: substmts.2,
revision: substmts.3,
body: substmts.4,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let submodule_header = SubmoduleHeaderStmts::parse(parser)?;
let linkage = LinkageStmts::parse(parser)?;
let meta = MetaStmts::parse(parser)?;
let revision = RevisionStmts::parse(parser)?;
let body = BodyStmts::parse(parser)?;
Ok((submodule_header, linkage, meta, revision, body))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct YangVersionStmt {
arg: YangVersionArg,
}
impl Stmt for YangVersionStmt {
type Arg = YangVersionArg;
type SubStmts = ();
fn keyword() -> Keyword {
"yang-version"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::YangVersionStmt(YangVersionStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ImportStmt {
arg: Identifier,
prefix: PrefixStmt,
revision_date: Option<RevisionDateStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for ImportStmt {
type Arg = Identifier;
type SubStmts = (
PrefixStmt,
Option<RevisionDateStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"import"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::HasOne(SubStmtWith::Stmt(PrefixStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(RevisionDateStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ImportStmt(ImportStmt {
arg,
prefix: substmts.0,
revision_date: substmts.1,
description: substmts.2,
reference: substmts.3,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_a_stmt!(stmts, PrefixStmt)?,
collect_opt_stmt!(stmts, RevisionDateStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct IncludeStmt {
arg: Identifier,
revision_date: Option<RevisionDateStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for IncludeStmt {
type Arg = Identifier;
type SubStmts = (
Option<RevisionDateStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"include"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(RevisionDateStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::IncludeStmt(IncludeStmt {
arg,
revision_date: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::IncludeStmt(IncludeStmt {
arg,
revision_date: substmts.0,
description: substmts.1,
reference: substmts.2,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, RevisionDateStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct NamespaceStmt {
arg: Url,
}
impl Stmt for NamespaceStmt {
type Arg = Url;
type SubStmts = ();
fn keyword() -> Keyword {
"namespace"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::NamespaceStmt(NamespaceStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct PrefixStmt {
arg: Identifier,
}
impl Stmt for PrefixStmt {
type Arg = Identifier;
type SubStmts = ();
fn keyword() -> Keyword {
"prefix"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::PrefixStmt(PrefixStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct BelongsToStmt {
arg: Identifier,
prefix: PrefixStmt,
}
impl Stmt for BelongsToStmt {
type Arg = Identifier;
type SubStmts = (PrefixStmt,);
fn keyword() -> Keyword {
"belongs-to"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![SubStmtDef::HasOne(SubStmtWith::Stmt(PrefixStmt::keyword))]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::BelongsToStmt(BelongsToStmt {
arg,
prefix: substmts.0,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((collect_a_stmt!(stmts, PrefixStmt)?,))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct OrganizationStmt {
arg: String,
}
impl Stmt for OrganizationStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"organization"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::OrganizationStmt(OrganizationStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ContactStmt {
arg: String,
}
impl Stmt for ContactStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"contact"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ContactStmt(ContactStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct DescriptionStmt {
arg: String,
}
impl Stmt for DescriptionStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"description"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::DescriptionStmt(DescriptionStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ReferenceStmt {
arg: String,
}
impl Stmt for ReferenceStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"reference"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ReferenceStmt(ReferenceStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct UnitsStmt {
arg: String,
}
impl Stmt for UnitsStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"units"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::UnitsStmt(UnitsStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct RevisionStmt {
arg: DateArg,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for RevisionStmt {
type Arg = DateArg;
type SubStmts = (Option<DescriptionStmt>, Option<ReferenceStmt>);
fn keyword() -> Keyword {
"revision"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::RevisionStmt(RevisionStmt {
arg,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::RevisionStmt(RevisionStmt {
arg,
description: substmts.0,
reference: substmts.1,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct RevisionDateStmt {
arg: DateArg,
}
impl Stmt for RevisionDateStmt {
type Arg = DateArg;
type SubStmts = ();
fn keyword() -> Keyword {
"revision-date"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::RevisionDateStmt(RevisionDateStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ExtensionStmt {
arg: Identifier,
argument: Option<ArgumentStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for ExtensionStmt {
type Arg = Identifier;
type SubStmts = (
Option<ArgumentStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"extension"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(ArgumentStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ExtensionStmt(ExtensionStmt {
arg,
argument: None,
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ExtensionStmt(ExtensionStmt {
arg,
argument: substmts.0,
status: substmts.1,
description: substmts.2,
reference: substmts.3,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, ArgumentStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ArgumentStmt {
arg: Identifier,
yin_element: Option<YinElementStmt>,
}
impl Stmt for ArgumentStmt {
type Arg = Identifier;
type SubStmts = (Option<YinElementStmt>,);
fn keyword() -> Keyword {
"argument"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![SubStmtDef::Optional(SubStmtWith::Stmt(
YinElementStmt::keyword,
))]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ArgumentStmt(ArgumentStmt {
arg,
yin_element: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ArgumentStmt(ArgumentStmt {
arg,
yin_element: substmts.0,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((collect_opt_stmt!(stmts, YinElementStmt)?,))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct YinElementStmt {
arg: YinElementArg,
}
impl Stmt for YinElementStmt {
type Arg = YinElementArg;
type SubStmts = ();
fn keyword() -> Keyword {
"yin-element"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::YinElementStmt(YinElementStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct IdentityStmt {
arg: Identifier,
if_feature: Vec<IfFeatureStmt>,
base: Vec<BaseStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for IdentityStmt {
type Arg = Identifier;
type SubStmts = (
Vec<IfFeatureStmt>,
Vec<BaseStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"identity"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(BaseStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::IdentityStmt(IdentityStmt {
arg,
if_feature: Vec::new(),
base: Vec::new(),
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::IdentityStmt(IdentityStmt {
arg,
if_feature: substmts.0,
base: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, BaseStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct BaseStmt {
arg: IdentifierRef,
}
impl Stmt for BaseStmt {
type Arg = IdentifierRef;
type SubStmts = ();
fn keyword() -> Keyword {
"base"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::BaseStmt(BaseStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct FeatureStmt {
arg: Identifier,
if_feature: Vec<IfFeatureStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for FeatureStmt {
type Arg = Identifier;
type SubStmts = (
Vec<IfFeatureStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"feature"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::FeatureStmt(FeatureStmt {
arg,
if_feature: Vec::new(),
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::FeatureStmt(FeatureStmt {
arg,
if_feature: substmts.0,
status: substmts.1,
description: substmts.2,
reference: substmts.3,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct IfFeatureStmt {
arg: IfFeatureExpr,
}
impl Stmt for IfFeatureStmt {
type Arg = IfFeatureExpr;
type SubStmts = ();
fn keyword() -> Keyword {
"if-feature"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::IfFeatureStmt(IfFeatureStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct TypedefStmt {
arg: Identifier,
type_: TypeStmt,
units: Option<UnitsStmt>,
default: Option<DefaultStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for TypedefStmt {
type Arg = Identifier;
type SubStmts = (
TypeStmt,
Option<UnitsStmt>,
Option<DefaultStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"typedef"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::HasOne(SubStmtWith::Stmt(TypeStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::TypedefStmt(TypedefStmt {
arg,
type_: substmts.0,
units: substmts.1,
default: substmts.2,
status: substmts.3,
description: substmts.4,
reference: substmts.5,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_a_stmt!(stmts, TypeStmt)?,
collect_opt_stmt!(stmts, UnitsStmt)?,
collect_opt_stmt!(stmts, DefaultStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct TypeStmt {
arg: IdentifierRef,
type_body: Option<TypeBodyStmts>,
}
impl Stmt for TypeStmt {
type Arg = IdentifierRef;
type SubStmts = Option<TypeBodyStmts>;
fn keyword() -> Keyword {
"type"
}
fn opt_substmts() -> bool {
true
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::TypeStmt(TypeStmt {
arg,
type_body: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::TypeStmt(TypeStmt {
arg,
type_body: substmts,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let type_body = TypeBodyStmts::parse(parser)?;
Ok(Some(type_body))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct RangeStmt {
arg: RangeArg,
error_message: Option<ErrorMessageStmt>,
error_app_tag: Option<ErrorAppTagStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for RangeStmt {
type Arg = RangeArg;
type SubStmts = (
Option<ErrorMessageStmt>,
Option<ErrorAppTagStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"range"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::RangeStmt(RangeStmt {
arg,
error_message: None,
error_app_tag: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::RangeStmt(RangeStmt {
arg,
error_message: substmts.0,
error_app_tag: substmts.1,
description: substmts.2,
reference: substmts.3,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, ErrorMessageStmt)?,
collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct FractionDigitsStmt {
arg: FractionDigitsArg,
}
impl Stmt for FractionDigitsStmt {
type Arg = FractionDigitsArg;
type SubStmts = ();
fn keyword() -> Keyword {
"fraction-digits"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::FractionDigitsStmt(FractionDigitsStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct LengthStmt {
arg: LengthArg,
error_message: Option<ErrorMessageStmt>,
error_app_tag: Option<ErrorAppTagStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for LengthStmt {
type Arg = LengthArg;
type SubStmts = (
Option<ErrorMessageStmt>,
Option<ErrorAppTagStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"length"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::LengthStmt(LengthStmt {
arg,
error_message: None,
error_app_tag: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::LengthStmt(LengthStmt {
arg,
error_message: substmts.0,
error_app_tag: substmts.1,
description: substmts.2,
reference: substmts.3,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, ErrorMessageStmt)?,
collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct PatternStmt {
arg: String,
modifier: Option<ModifierStmt>,
error_message: Option<ErrorMessageStmt>,
error_app_tag: Option<ErrorAppTagStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for PatternStmt {
type Arg = String;
type SubStmts = (
Option<ModifierStmt>,
Option<ErrorMessageStmt>,
Option<ErrorAppTagStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"pattern"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(ModifierStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::PatternStmt(PatternStmt {
arg,
modifier: None,
error_message: None,
error_app_tag: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::PatternStmt(PatternStmt {
arg,
modifier: substmts.0,
error_message: substmts.1,
error_app_tag: substmts.2,
description: substmts.3,
reference: substmts.4,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, ModifierStmt)?,
collect_opt_stmt!(stmts, ErrorMessageStmt)?,
collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ModifierStmt {
arg: ModifierArg,
}
impl Stmt for ModifierStmt {
type Arg = ModifierArg;
type SubStmts = ();
fn keyword() -> Keyword {
"modifier"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ModifierStmt(ModifierStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct DefaultStmt {
arg: String,
}
impl Stmt for DefaultStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"default"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::DefaultStmt(DefaultStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct EnumStmt {
arg: String,
if_feature: Vec<IfFeatureStmt>,
value: Option<ValueStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for EnumStmt {
type Arg = String;
type SubStmts = (
Vec<IfFeatureStmt>,
Option<ValueStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"enum"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ValueStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::EnumStmt(EnumStmt {
arg,
if_feature: Vec::new(),
value: None,
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::EnumStmt(EnumStmt {
arg,
if_feature: substmts.0,
value: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, ValueStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct PathStmt {
arg: PathArg,
}
impl Stmt for PathStmt {
type Arg = PathArg;
type SubStmts = ();
fn keyword() -> Keyword {
"path"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::PathStmt(PathStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct RequireInstanceStmt {
arg: RequireInstanceArg,
}
impl Stmt for RequireInstanceStmt {
type Arg = RequireInstanceArg;
type SubStmts = ();
fn keyword() -> Keyword {
"require-instance"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::RequireInstanceStmt(RequireInstanceStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct BitStmt {
arg: Identifier,
if_feature: Vec<IfFeatureStmt>,
position: Option<PositionStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for BitStmt {
type Arg = Identifier;
type SubStmts = (
Vec<IfFeatureStmt>,
Option<PositionStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"bit"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(PositionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::BitStmt(BitStmt {
arg,
if_feature: Vec::new(),
position: None,
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::BitStmt(BitStmt {
arg,
if_feature: substmts.0,
position: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, PositionStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct PositionStmt {
arg: PositionValueArg,
}
impl Stmt for PositionStmt {
type Arg = PositionValueArg;
type SubStmts = ();
fn keyword() -> Keyword {
"position"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::PositionStmt(PositionStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct StatusStmt {
arg: StatusArg,
}
impl Stmt for StatusStmt {
type Arg = StatusArg;
type SubStmts = ();
fn keyword() -> Keyword {
"status"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::StatusStmt(StatusStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ConfigStmt {
arg: ConfigArg,
}
impl Stmt for ConfigStmt {
type Arg = ConfigArg;
type SubStmts = ();
fn keyword() -> Keyword {
"config"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ConfigStmt(ConfigStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct MandatoryStmt {
arg: MandatoryArg,
}
impl Stmt for MandatoryStmt {
type Arg = MandatoryArg;
type SubStmts = ();
fn keyword() -> Keyword {
"mandatory"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::MandatoryStmt(MandatoryStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct PresenceStmt {
arg: String,
}
impl Stmt for PresenceStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"presence"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::PresenceStmt(PresenceStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct OrderedByStmt {
arg: OrderedByArg,
}
impl Stmt for OrderedByStmt {
type Arg = OrderedByArg;
type SubStmts = ();
fn keyword() -> Keyword {
"ordered-by"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::OrderedByStmt(OrderedByStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct MustStmt {
arg: String,
error_message: Option<ErrorMessageStmt>,
error_app_tag: Option<ErrorAppTagStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for MustStmt {
type Arg = String;
type SubStmts = (
Option<ErrorMessageStmt>,
Option<ErrorAppTagStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"must"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorMessageStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ErrorAppTagStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::MustStmt(MustStmt {
arg,
error_message: None,
error_app_tag: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::MustStmt(MustStmt {
arg,
error_message: substmts.0,
error_app_tag: substmts.1,
description: substmts.2,
reference: substmts.3,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, ErrorMessageStmt)?,
collect_opt_stmt!(stmts, ErrorAppTagStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ErrorMessageStmt {
arg: String,
}
impl Stmt for ErrorMessageStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"error-message"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ErrorMessageStmt(ErrorMessageStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ErrorAppTagStmt {
arg: String,
}
impl Stmt for ErrorAppTagStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"error-app-tag"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ErrorAppTagStmt(ErrorAppTagStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct MinElementsStmt {
arg: MinValueArg,
}
impl Stmt for MinElementsStmt {
type Arg = MinValueArg;
type SubStmts = ();
fn keyword() -> Keyword {
"min-elements"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::MinElementsStmt(MinElementsStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct MaxElementsStmt {
arg: MaxValueArg,
}
impl Stmt for MaxElementsStmt {
type Arg = MaxValueArg;
type SubStmts = ();
fn keyword() -> Keyword {
"max-elements"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::MaxElementsStmt(MaxElementsStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ValueStmt {
arg: IntegerValue,
}
impl Stmt for ValueStmt {
type Arg = IntegerValue;
type SubStmts = ();
fn keyword() -> Keyword {
"value"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ValueStmt(ValueStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct GroupingStmt {
arg: Identifier,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
typedef_or_grouping: TypedefOrGrouping,
data_def: DataDefStmt,
action: Vec<ActionStmt>,
notification: Vec<NotificationStmt>,
}
impl GroupingStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for GroupingStmt {
type Arg = Identifier;
type SubStmts = (
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
TypedefOrGrouping,
DataDefStmt,
Vec<ActionStmt>,
Vec<NotificationStmt>,
);
fn keyword() -> Keyword {
"grouping"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ActionStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::GroupingStmt(GroupingStmt {
arg,
status: None,
description: None,
reference: None,
typedef_or_grouping: TypedefOrGrouping::new(),
data_def: DataDefStmt::new(),
action: Vec::new(),
notification: Vec::new(),
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::GroupingStmt(GroupingStmt {
arg,
status: substmts.0,
description: substmts.1,
reference: substmts.2,
typedef_or_grouping: substmts.3,
data_def: substmts.4,
action: substmts.5,
notification: substmts.6,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
collect_vec_stmt!(stmts, ActionStmt)?,
collect_vec_stmt!(stmts, NotificationStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ContainerStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
must: Vec<MustStmt>,
presence: Option<PresenceStmt>,
config: Option<ConfigStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
typedef_or_grouping: TypedefOrGrouping,
data_def: DataDefStmt,
action: Vec<ActionStmt>,
notification: Vec<NotificationStmt>,
}
impl ContainerStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for ContainerStmt {
type Arg = Identifier;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Vec<MustStmt>,
Option<PresenceStmt>,
Option<ConfigStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
TypedefOrGrouping,
DataDefStmt,
Vec<ActionStmt>,
Vec<NotificationStmt>,
);
fn keyword() -> Keyword {
"container"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(PresenceStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ActionStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ContainerStmt(ContainerStmt {
arg,
when: None,
if_feature: Vec::new(),
must: Vec::new(),
presence: None,
config: None,
status: None,
description: None,
reference: None,
typedef_or_grouping: TypedefOrGrouping::new(),
data_def: DataDefStmt::new(),
action: Vec::new(),
notification: Vec::new(),
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ContainerStmt(ContainerStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
must: substmts.2,
presence: substmts.3,
config: substmts.4,
status: substmts.5,
description: substmts.6,
reference: substmts.7,
typedef_or_grouping: substmts.8,
data_def: substmts.9,
action: substmts.10,
notification: substmts.11,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, PresenceStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
collect_vec_stmt!(stmts, ActionStmt)?,
collect_vec_stmt!(stmts, NotificationStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct LeafStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
type_: TypeStmt,
units: Option<UnitsStmt>,
must: Vec<MustStmt>,
default: Option<DefaultStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for LeafStmt {
type Arg = Identifier;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
TypeStmt,
Option<UnitsStmt>,
Vec<MustStmt>,
Option<DefaultStmt>,
Option<ConfigStmt>,
Option<MandatoryStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"leaf"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::HasOne(SubStmtWith::Stmt(TypeStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::LeafStmt(LeafStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
type_: substmts.2,
units: substmts.3,
must: substmts.4,
default: substmts.5,
config: substmts.6,
mandatory: substmts.7,
status: substmts.8,
description: substmts.9,
reference: substmts.10,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_a_stmt!(stmts, TypeStmt)?,
collect_opt_stmt!(stmts, UnitsStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, DefaultStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MandatoryStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct LeafListStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
type_: TypeStmt,
units: Option<UnitsStmt>,
must: Vec<MustStmt>,
default: Vec<DefaultStmt>,
config: Option<ConfigStmt>,
min_elements: Option<MinElementsStmt>,
max_elements: Option<MaxElementsStmt>,
ordered_by: Option<OrderedByStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for LeafListStmt {
type Arg = Identifier;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
TypeStmt,
Option<UnitsStmt>,
Vec<MustStmt>,
Vec<DefaultStmt>,
Option<ConfigStmt>,
Option<MinElementsStmt>,
Option<MaxElementsStmt>,
Option<OrderedByStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"leaf-list"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::HasOne(SubStmtWith::Stmt(TypeStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(OrderedByStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::LeafListStmt(LeafListStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
type_: substmts.2,
units: substmts.3,
must: substmts.4,
default: substmts.5,
config: substmts.6,
min_elements: substmts.7,
max_elements: substmts.8,
ordered_by: substmts.9,
status: substmts.10,
description: substmts.11,
reference: substmts.12,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_a_stmt!(stmts, TypeStmt)?,
collect_opt_stmt!(stmts, UnitsStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_vec_stmt!(stmts, DefaultStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MinElementsStmt)?,
collect_opt_stmt!(stmts, MaxElementsStmt)?,
collect_opt_stmt!(stmts, OrderedByStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ListStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
must: Vec<MustStmt>,
key: Option<KeyStmt>,
unique: Vec<UniqueStmt>,
config: Option<ConfigStmt>,
min_elements: Option<MinElementsStmt>,
max_elements: Option<MaxElementsStmt>,
ordered_by: Option<OrderedByStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
typedef_or_grouping: TypedefOrGrouping,
data_def: DataDefStmt,
action: Vec<ActionStmt>,
notification: Vec<NotificationStmt>,
}
impl ListStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for ListStmt {
type Arg = Identifier;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Vec<MustStmt>,
Option<KeyStmt>,
Vec<UniqueStmt>,
Option<ConfigStmt>,
Option<MinElementsStmt>,
Option<MaxElementsStmt>,
Option<OrderedByStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
TypedefOrGrouping,
DataDefStmt,
Vec<ActionStmt>,
Vec<NotificationStmt>,
);
fn keyword() -> Keyword {
"list"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(KeyStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(UniqueStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(OrderedByStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(ActionStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(NotificationStmt::keyword)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ListStmt(ListStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
must: substmts.2,
key: substmts.3,
unique: substmts.4,
config: substmts.5,
min_elements: substmts.6,
max_elements: substmts.7,
ordered_by: substmts.8,
status: substmts.9,
description: substmts.10,
reference: substmts.11,
typedef_or_grouping: substmts.12,
data_def: substmts.13,
action: substmts.14,
notification: substmts.15,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, KeyStmt)?,
collect_vec_stmt!(stmts, UniqueStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MinElementsStmt)?,
collect_opt_stmt!(stmts, MaxElementsStmt)?,
collect_opt_stmt!(stmts, OrderedByStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
collect_vec_stmt!(stmts, ActionStmt)?,
collect_vec_stmt!(stmts, NotificationStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct KeyStmt {
arg: KeyArg,
}
impl Stmt for KeyStmt {
type Arg = KeyArg;
type SubStmts = ();
fn keyword() -> Keyword {
"key"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::KeyStmt(KeyStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct UniqueStmt {
arg: UniqueArg,
}
impl Stmt for UniqueStmt {
type Arg = UniqueArg;
type SubStmts = ();
fn keyword() -> Keyword {
"unique"
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::UniqueStmt(UniqueStmt { arg })
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ChoiceStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
default: Option<DefaultStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
short_case_or_case: ShortCaseOrCaseStmt,
}
impl ChoiceStmt {
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.short_case_or_case.choice()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.short_case_or_case.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.short_case_or_case.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.short_case_or_case.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.short_case_or_case.list()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.short_case_or_case.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.short_case_or_case.anyxml()
}
pub fn case(&self) -> &Vec<CaseStmt> {
&self.short_case_or_case.case()
}
}
impl Stmt for ChoiceStmt {
type Arg = Identifier;
fn keyword() -> Keyword {
"choice"
}
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Option<DefaultStmt>,
Option<ConfigStmt>,
Option<MandatoryStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
ShortCaseOrCaseStmt,
);
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(ShortCaseOrCaseStmt::keywords)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ChoiceStmt(ChoiceStmt {
arg,
when: None,
if_feature: Vec::new(),
default: None,
config: None,
mandatory: None,
status: None,
description: None,
reference: None,
short_case_or_case: ShortCaseOrCaseStmt::new(),
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ChoiceStmt(ChoiceStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
default: substmts.2,
config: substmts.3,
mandatory: substmts.4,
status: substmts.5,
description: substmts.6,
reference: substmts.7,
short_case_or_case: substmts.8,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, DefaultStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MandatoryStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
ShortCaseOrCaseStmt::new_with_substmts((
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, CaseStmt)?,
)),
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct CaseStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
data_def: DataDefStmt,
}
impl CaseStmt {
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for CaseStmt {
type Arg = Identifier;
fn keyword() -> Keyword {
"case"
}
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
DataDefStmt,
);
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::CaseStmt(CaseStmt {
arg,
when: None,
if_feature: Vec::new(),
status: None,
description: None,
reference: None,
data_def: DataDefStmt::new(),
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::CaseStmt(CaseStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
data_def: substmts.5,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct AnydataStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
must: Vec<MustStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for AnydataStmt {
type Arg = Identifier;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Vec<MustStmt>,
Option<ConfigStmt>,
Option<MandatoryStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"anydata"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::AnydataStmt(AnydataStmt {
arg,
when: None,
if_feature: Vec::new(),
must: Vec::new(),
config: None,
mandatory: None,
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::AnydataStmt(AnydataStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
must: substmts.2,
config: substmts.3,
mandatory: substmts.4,
status: substmts.5,
description: substmts.6,
reference: substmts.7,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MandatoryStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct AnyxmlStmt {
arg: Identifier,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
must: Vec<MustStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for AnyxmlStmt {
type Arg = Identifier;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Vec<MustStmt>,
Option<ConfigStmt>,
Option<MandatoryStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"anyxml"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::AnyxmlStmt(AnyxmlStmt {
arg,
when: None,
if_feature: Vec::new(),
must: Vec::new(),
config: None,
mandatory: None,
status: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::AnyxmlStmt(AnyxmlStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
must: substmts.2,
config: substmts.3,
mandatory: substmts.4,
status: substmts.5,
description: substmts.6,
reference: substmts.7,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MandatoryStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct UsesStmt {
arg: IdentifierRef,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
refine: Vec<RefineStmt>,
uses_augment: Vec<AugmentStmt>,
}
impl Stmt for UsesStmt {
type Arg = IdentifierRef;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
Vec<RefineStmt>,
Vec<AugmentStmt>,
);
fn keyword() -> Keyword {
"uses"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(RefineStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(AugmentStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::UsesStmt(UsesStmt {
arg,
when: None,
if_feature: Vec::new(),
status: None,
description: None,
reference: None,
refine: Vec::new(),
uses_augment: Vec::new(),
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::UsesStmt(UsesStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
refine: substmts.5,
uses_augment: substmts.6,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
collect_vec_stmt!(stmts, RefineStmt)?,
collect_vec_stmt!(stmts, AugmentStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct RefineStmt {
arg: RefineArg,
if_feature: Vec<IfFeatureStmt>,
must: Vec<MustStmt>,
presence: Option<PresenceStmt>,
default: Vec<DefaultStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
min_elements: Option<MinElementsStmt>,
max_elements: Option<MaxElementsStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for RefineStmt {
type Arg = RefineArg;
type SubStmts = (
Vec<IfFeatureStmt>,
Vec<MustStmt>,
Option<PresenceStmt>,
Vec<DefaultStmt>,
Option<ConfigStmt>,
Option<MandatoryStmt>,
Option<MinElementsStmt>,
Option<MaxElementsStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
);
fn keyword() -> Keyword {
"refine"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(PresenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::RefineStmt(RefineStmt {
arg,
if_feature: Vec::new(),
must: Vec::new(),
presence: None,
default: Vec::new(),
config: None,
mandatory: None,
min_elements: None,
max_elements: None,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::RefineStmt(RefineStmt {
arg,
if_feature: substmts.0,
must: substmts.1,
presence: substmts.2,
default: substmts.3,
config: substmts.4,
mandatory: substmts.5,
min_elements: substmts.6,
max_elements: substmts.7,
description: substmts.8,
reference: substmts.9,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, PresenceStmt)?,
collect_vec_stmt!(stmts, DefaultStmt)?,
collect_opt_stmt!(stmts, ConfigStmt)?,
collect_opt_stmt!(stmts, MandatoryStmt)?,
collect_opt_stmt!(stmts, MinElementsStmt)?,
collect_opt_stmt!(stmts, MaxElementsStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct AugmentStmt {
arg: SchemaNodeid,
when: Option<WhenStmt>,
if_feature: Vec<IfFeatureStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
data_def_or_else: DataDefOrElse,
}
impl AugmentStmt {
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def_or_else.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def_or_else.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def_or_else.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def_or_else.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def_or_else.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def_or_else.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def_or_else.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def_or_else.uses()
}
pub fn case(&self) -> &Vec<CaseStmt> {
&self.data_def_or_else.case()
}
pub fn action(&self) -> &Vec<ActionStmt> {
&self.data_def_or_else.action()
}
pub fn notification(&self) -> &Vec<NotificationStmt> {
&self.data_def_or_else.notification()
}
}
impl Stmt for AugmentStmt {
type Arg = SchemaNodeid;
type SubStmts = (
Option<WhenStmt>,
Vec<IfFeatureStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
DataDefOrElse,
);
fn keyword() -> Keyword {
"augment"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(WhenStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefOrElse::keywords)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::AugmentStmt(AugmentStmt {
arg,
when: substmts.0,
if_feature: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
data_def_or_else: substmts.5,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, WhenStmt)?,
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
DataDefOrElse::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
collect_vec_stmt!(stmts, CaseStmt)?,
collect_vec_stmt!(stmts, ActionStmt)?,
collect_vec_stmt!(stmts, NotificationStmt)?,
)),
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct WhenStmt {
arg: String,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
}
impl Stmt for WhenStmt {
type Arg = String;
type SubStmts = (Option<DescriptionStmt>, Option<ReferenceStmt>);
fn keyword() -> Keyword {
"when"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::WhenStmt(WhenStmt {
arg,
description: None,
reference: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::WhenStmt(WhenStmt {
arg,
description: substmts.0,
reference: substmts.1,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct RpcStmt {
arg: Identifier,
if_feature: Vec<IfFeatureStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
typedef_or_grouping: TypedefOrGrouping,
input: Option<InputStmt>,
output: Option<OutputStmt>,
}
impl RpcStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
}
impl Stmt for RpcStmt {
type Arg = Identifier;
type SubStmts = (
Vec<IfFeatureStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
TypedefOrGrouping,
Option<InputStmt>,
Option<OutputStmt>,
);
fn keyword() -> Keyword {
"rpc"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::Optional(SubStmtWith::Stmt(InputStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(OutputStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::RpcStmt(RpcStmt {
arg,
if_feature: Vec::new(),
status: None,
description: None,
reference: None,
typedef_or_grouping: TypedefOrGrouping::new(),
input: None,
output: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::RpcStmt(RpcStmt {
arg,
if_feature: substmts.0,
status: substmts.1,
description: substmts.2,
reference: substmts.3,
typedef_or_grouping: substmts.4,
input: substmts.5,
output: substmts.6,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
collect_opt_stmt!(stmts, InputStmt)?,
collect_opt_stmt!(stmts, OutputStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct ActionStmt {
arg: Identifier,
if_feature: Vec<IfFeatureStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
typedef_or_grouping: TypedefOrGrouping,
input: Option<InputStmt>,
output: Option<OutputStmt>,
}
impl ActionStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
}
impl Stmt for ActionStmt {
type Arg = Identifier;
type SubStmts = (
Vec<IfFeatureStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
TypedefOrGrouping,
Option<InputStmt>,
Option<OutputStmt>,
);
fn keyword() -> Keyword {
"action"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::Optional(SubStmtWith::Stmt(InputStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(OutputStmt::keyword)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::ActionStmt(ActionStmt {
arg,
if_feature: Vec::new(),
status: None,
description: None,
reference: None,
typedef_or_grouping: TypedefOrGrouping::new(),
input: None,
output: None,
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::ActionStmt(ActionStmt {
arg,
if_feature: substmts.0,
status: substmts.1,
description: substmts.2,
reference: substmts.3,
typedef_or_grouping: substmts.4,
input: substmts.5,
output: substmts.6,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
collect_opt_stmt!(stmts, InputStmt)?,
collect_opt_stmt!(stmts, OutputStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct InputStmt {
must: Vec<MustStmt>,
typedef_or_grouping: TypedefOrGrouping,
data_def: DataDefStmt,
}
impl InputStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for InputStmt {
type Arg = NoArg;
type SubStmts = (Vec<MustStmt>, TypedefOrGrouping, DataDefStmt);
fn keyword() -> Keyword {
"input"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
]
}
fn new_with_substmts(_arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::InputStmt(InputStmt {
must: substmts.0,
typedef_or_grouping: substmts.1,
data_def: substmts.2,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, MustStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct OutputStmt {
must: Vec<MustStmt>,
typedef_or_grouping: TypedefOrGrouping,
data_def: DataDefStmt,
}
impl OutputStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for OutputStmt {
type Arg = NoArg;
type SubStmts = (Vec<MustStmt>, TypedefOrGrouping, DataDefStmt);
fn keyword() -> Keyword {
"output"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::OneOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
]
}
fn new_with_substmts(_arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::OutputStmt(OutputStmt {
must: substmts.0,
typedef_or_grouping: substmts.1,
data_def: substmts.2,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, MustStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct NotificationStmt {
arg: Identifier,
if_feature: Vec<IfFeatureStmt>,
must: Vec<MustStmt>,
status: Option<StatusStmt>,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
typedef_or_grouping: TypedefOrGrouping,
data_def: DataDefStmt,
}
impl NotificationStmt {
pub fn typedef(&self) -> &Vec<TypedefStmt> {
&self.typedef_or_grouping.typedef()
}
pub fn grouping(&self) -> &Vec<GroupingStmt> {
&self.typedef_or_grouping.grouping()
}
pub fn container(&self) -> &Vec<ContainerStmt> {
&self.data_def.container()
}
pub fn leaf(&self) -> &Vec<LeafStmt> {
&self.data_def.leaf()
}
pub fn leaf_list(&self) -> &Vec<LeafListStmt> {
&self.data_def.leaf_list()
}
pub fn list(&self) -> &Vec<ListStmt> {
&self.data_def.list()
}
pub fn choice(&self) -> &Vec<ChoiceStmt> {
&self.data_def.choice()
}
pub fn anydata(&self) -> &Vec<AnydataStmt> {
&self.data_def.anydata()
}
pub fn anyxml(&self) -> &Vec<AnyxmlStmt> {
&self.data_def.anyxml()
}
pub fn uses(&self) -> &Vec<UsesStmt> {
&self.data_def.uses()
}
}
impl Stmt for NotificationStmt {
type Arg = Identifier;
type SubStmts = (
Vec<IfFeatureStmt>,
Vec<MustStmt>,
Option<StatusStmt>,
Option<DescriptionStmt>,
Option<ReferenceStmt>,
TypedefOrGrouping,
DataDefStmt,
);
fn keyword() -> Keyword {
"notification"
}
fn opt_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(IfFeatureStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(StatusStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(TypedefOrGrouping::keywords)),
SubStmtDef::ZeroOrMore(SubStmtWith::Selection(DataDefStmt::keywords)),
]
}
fn new_with_arg(arg: Self::Arg) -> YangStmt
where
Self: Sized,
{
YangStmt::NotificationStmt(NotificationStmt {
arg,
if_feature: Vec::new(),
must: Vec::new(),
status: None,
description: None,
reference: None,
typedef_or_grouping: TypedefOrGrouping::new(),
data_def: DataDefStmt::new(),
})
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::NotificationStmt(NotificationStmt {
arg,
if_feature: substmts.0,
must: substmts.1,
status: substmts.2,
description: substmts.3,
reference: substmts.4,
typedef_or_grouping: substmts.5,
data_def: substmts.6,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_vec_stmt!(stmts, IfFeatureStmt)?,
collect_vec_stmt!(stmts, MustStmt)?,
collect_opt_stmt!(stmts, StatusStmt)?,
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
TypedefOrGrouping::new_with_substmts((
collect_vec_stmt!(stmts, TypedefStmt)?,
collect_vec_stmt!(stmts, GroupingStmt)?,
)),
DataDefStmt::new_with_substmts((
collect_vec_stmt!(stmts, ContainerStmt)?,
collect_vec_stmt!(stmts, LeafStmt)?,
collect_vec_stmt!(stmts, LeafListStmt)?,
collect_vec_stmt!(stmts, ListStmt)?,
collect_vec_stmt!(stmts, ChoiceStmt)?,
collect_vec_stmt!(stmts, AnydataStmt)?,
collect_vec_stmt!(stmts, AnyxmlStmt)?,
collect_vec_stmt!(stmts, UsesStmt)?,
)),
))
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct DeviationStmt {
arg: DeviationArg,
description: Option<DescriptionStmt>,
reference: Option<ReferenceStmt>,
deviate: Vec<DeviateStmt>,
}
impl Stmt for DeviationStmt {
type Arg = DeviationArg;
type SubStmts = (
Option<DescriptionStmt>,
Option<ReferenceStmt>,
Vec<DeviateStmt>,
);
fn keyword() -> Keyword {
"deviation"
}
fn has_substmts() -> bool {
true
}
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(DescriptionStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ReferenceStmt::keyword)),
SubStmtDef::OneOrMore(SubStmtWith::Stmt(DeviateStmt::keyword)),
]
}
fn new_with_substmts(arg: Self::Arg, substmts: Self::SubStmts) -> YangStmt
where
Self: Sized,
{
YangStmt::DeviationStmt(DeviationStmt {
arg,
description: substmts.0,
reference: substmts.1,
deviate: substmts.2,
})
}
fn parse_substmts(parser: &mut Parser) -> Result<Self::SubStmts, YangError> {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
Ok((
collect_opt_stmt!(stmts, DescriptionStmt)?,
collect_opt_stmt!(stmts, ReferenceStmt)?,
collect_vec_stmt!(stmts, DeviateStmt)?,
))
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum DeviateStmt {
NotSupported,
Add(DeviateAddStmt),
Replace(DeviateReplaceStmt),
Delete(DeviateDeleteStmt),
}
impl Stmt for DeviateStmt {
type Arg = String;
type SubStmts = ();
fn keyword() -> Keyword {
"deviate"
}
fn parse(parser: &mut Parser) -> Result<YangStmt, YangError>
where
Self::Arg: StmtArg,
Self: Sized,
{
let arg = Self::Arg::parse_arg(parser)?;
match &arg as &str {
"add" => {
let stmt = DeviateAddStmt::parse(parser)?;
Ok(YangStmt::DeviateStmt(DeviateStmt::Add(stmt)))
}
"delete" => {
let stmt = DeviateDeleteStmt::parse(parser)?;
Ok(YangStmt::DeviateStmt(DeviateStmt::Delete(stmt)))
}
"replace" => {
let stmt = DeviateReplaceStmt::parse(parser)?;
Ok(YangStmt::DeviateStmt(DeviateStmt::Replace(stmt)))
}
"not-supported" => {
let token = parser.get_token()?;
match token {
Token::StatementEnd => Ok(YangStmt::DeviateStmt(DeviateStmt::NotSupported)),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
_ => Err(YangError::UnexpectedToken(arg.to_string())),
}
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct DeviateAddStmt {
units: Option<UnitsStmt>,
must: Vec<MustStmt>,
unique: Vec<UniqueStmt>,
default: Vec<DefaultStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
min_elements: Option<MinElementsStmt>,
max_elements: Option<MaxElementsStmt>,
}
impl Compound for DeviateAddStmt {
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(UniqueStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
]
}
}
impl DeviateAddStmt {
pub fn parse(parser: &mut Parser) -> Result<DeviateAddStmt, YangError> {
let token = parser.get_token()?;
match token {
Token::BlockBegin => {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
let token = parser.get_token()?;
match token {
Token::BlockEnd => Ok(DeviateAddStmt {
units: collect_opt_stmt!(stmts, UnitsStmt)?,
must: collect_vec_stmt!(stmts, MustStmt)?,
unique: collect_vec_stmt!(stmts, UniqueStmt)?,
default: collect_vec_stmt!(stmts, DefaultStmt)?,
config: collect_opt_stmt!(stmts, ConfigStmt)?,
mandatory: collect_opt_stmt!(stmts, MandatoryStmt)?,
min_elements: collect_opt_stmt!(stmts, MinElementsStmt)?,
max_elements: collect_opt_stmt!(stmts, MaxElementsStmt)?,
}),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
Token::StatementEnd => Ok(DeviateAddStmt {
units: None,
must: Vec::new(),
unique: Vec::new(),
default: Vec::new(),
config: None,
mandatory: None,
min_elements: None,
max_elements: None,
}),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct DeviateDeleteStmt {
units: Option<UnitsStmt>,
must: Vec<MustStmt>,
unique: Vec<UniqueStmt>,
default: Vec<DefaultStmt>,
}
impl Compound for DeviateDeleteStmt {
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(MustStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(UniqueStmt::keyword)),
SubStmtDef::ZeroOrMore(SubStmtWith::Stmt(DefaultStmt::keyword)),
]
}
}
impl DeviateDeleteStmt {
fn parse(parser: &mut Parser) -> Result<DeviateDeleteStmt, YangError> {
let token = parser.get_token()?;
match token {
Token::BlockBegin => {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
let token = parser.get_token()?;
match token {
Token::BlockEnd => Ok(DeviateDeleteStmt {
units: collect_opt_stmt!(stmts, UnitsStmt)?,
must: collect_vec_stmt!(stmts, MustStmt)?,
unique: collect_vec_stmt!(stmts, UniqueStmt)?,
default: collect_vec_stmt!(stmts, DefaultStmt)?,
}),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
Token::StatementEnd => Ok(DeviateDeleteStmt {
units: None,
must: Vec::new(),
unique: Vec::new(),
default: Vec::new(),
}),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct DeviateReplaceStmt {
type_: Option<TypeStmt>,
units: Option<UnitsStmt>,
default: Option<DefaultStmt>,
config: Option<ConfigStmt>,
mandatory: Option<MandatoryStmt>,
min_elements: Option<MinElementsStmt>,
max_elements: Option<MaxElementsStmt>,
}
impl Compound for DeviateReplaceStmt {
fn substmts_def() -> Vec<SubStmtDef> {
vec![
SubStmtDef::Optional(SubStmtWith::Stmt(TypeStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(UnitsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(DefaultStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(ConfigStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MandatoryStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MinElementsStmt::keyword)),
SubStmtDef::Optional(SubStmtWith::Stmt(MaxElementsStmt::keyword)),
]
}
}
impl DeviateReplaceStmt {
pub fn parse(parser: &mut Parser) -> Result<DeviateReplaceStmt, YangError> {
let token = parser.get_token()?;
match token {
Token::BlockBegin => {
let mut stmts = SubStmtUtil::parse_substmts(parser, Self::substmts_def())?;
let token = parser.get_token()?;
match token {
Token::BlockEnd => Ok(DeviateReplaceStmt {
type_: collect_opt_stmt!(stmts, TypeStmt)?,
units: collect_opt_stmt!(stmts, UnitsStmt)?,
default: collect_opt_stmt!(stmts, DefaultStmt)?,
config: collect_opt_stmt!(stmts, ConfigStmt)?,
mandatory: collect_opt_stmt!(stmts, MandatoryStmt)?,
min_elements: collect_opt_stmt!(stmts, MinElementsStmt)?,
max_elements: collect_opt_stmt!(stmts, MaxElementsStmt)?,
}),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
Token::StatementEnd => Ok(DeviateReplaceStmt {
type_: None,
units: None,
default: None,
config: None,
mandatory: None,
min_elements: None,
max_elements: None,
}),
_ => Err(YangError::UnexpectedToken(token.to_string())),
}
}
}
#[derive(Debug, Clone, PartialEq, Getters)]
pub struct UnknownStmt {
keyword: UnknownStmtKeyword,
arg: Option<String>,
yang: Vec<YangStmt>,
}
impl UnknownStmt {
pub fn parse(parser: &mut Parser, keyword: &str) -> Result<YangStmt, YangError>
where
Self: Sized,
{
let keyword = UnknownStmtKeyword::from_str(keyword)
.map_err(|e| YangError::ArgumentParseError(e.str))?;
let token = parser.get_token()?;
let arg = match token {
Token::Identifier(s) | Token::QuotedString(s) => Some(s),
Token::StatementEnd => {
parser.save_token(token);
None
}
_ => return Err(YangError::UnexpectedToken(token.to_string())),
};
let token = parser.get_token()?;
let mut yang = Vec::new();
match token {
Token::StatementEnd => {}
Token::BlockBegin => loop {
let token = parser.get_token()?;
match token {
Token::BlockEnd => break,
Token::StatementEnd => {}
Token::QuotedString(ref keyword) | Token::Identifier(ref keyword) => {
let stmt = SubStmtUtil::call_stmt_parser(parser, keyword as &str)?;
yang.push(stmt);
}
Token::EndOfInput => return Err(YangError::UnexpectedEof),
_ => return Err(YangError::UnexpectedToken(token.to_string())),
}
},
_ => return Err(YangError::UnexpectedToken(token.to_string())),
}
Ok(YangStmt::UnknownStmt(UnknownStmt { keyword, arg, yang }))
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
#[test]
pub fn test_import_stmt() {
let s = r#"openconfig-inet-types {
prefix oc-inet;
revision-date 2017-07-06;
}"#;
let mut parser = Parser::new(s.to_string());
match ImportStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::ImportStmt(stmt) => {
assert_eq!(
stmt.arg(),
&Identifier::from_str("openconfig-inet-types").unwrap()
);
assert_eq!(
stmt.prefix(),
&PrefixStmt {
arg: Identifier::from_str("oc-inet").unwrap()
}
);
assert_eq!(
stmt.revision_date(),
&Some(RevisionDateStmt {
arg: DateArg::from_str("2017-07-06").unwrap()
})
);
assert_eq!(stmt.description(), &None);
assert_eq!(stmt.reference(), &None);
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
}
#[test]
pub fn test_include_stmt() {
let s = r#"openconfig-inet-types {
prefix oc-inet;
revision-date 2017-07-06;
}"#;
let mut parser = Parser::new(s.to_string());
match IncludeStmt::parse(&mut parser) {
Ok(yang) => panic!("{:?}", yang),
Err(err) => assert_eq!(err.to_string(), "Unexpected token Identifier '\"prefix\"'"),
}
let s = r#"openconfig-inet-types {
revision-date 2017-07-06;
}"#;
let mut parser = Parser::new(s.to_string());
match IncludeStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::IncludeStmt(stmt) => {
assert_eq!(
stmt.arg(),
&Identifier::from_str("openconfig-inet-types").unwrap()
);
assert_eq!(
stmt.revision_date(),
&Some(RevisionDateStmt {
arg: DateArg::from_str("2017-07-06").unwrap()
})
);
assert_eq!(stmt.description(), &None);
assert_eq!(stmt.reference(), &None);
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
}
#[test]
pub fn test_extension_stmt() {
let s = r#"openconfig-version {
argument "semver" {
yin-element false;
}
description
"The OpenConfig version number for the module. This is
...";
}"#;
let mut parser = Parser::new(s.to_string());
match ExtensionStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::ExtensionStmt(stmt) => {
assert_eq!(
stmt.arg(),
&Identifier::from_str("openconfig-version").unwrap()
);
match stmt.argument() {
Some(argument_stmt) => {
assert_eq!(
argument_stmt.arg(),
&Identifier::from_str("semver").unwrap()
);
match argument_stmt.yin_element() {
Some(yin_element_stmt) => {
assert_eq!(
yin_element_stmt.arg(),
&YinElementArg::from_str("false").unwrap()
);
}
None => panic!("No yin-element-stmt"),
}
}
None => panic!("No argument-stmt"),
}
assert_eq!(stmt.status(), &None);
match stmt.description() {
Some(description_stmt) => {
assert_eq!(
description_stmt.arg(),
"The OpenConfig version number for the module. This is\n..."
);
}
None => panic!("No description-stmt"),
}
assert_eq!(stmt.reference(), &None);
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
}
#[test]
pub fn test_identity_stmt() {
let s = r#"SFP {
base TRANSCEIVER_FORM_FACTOR_TYPE;
description
"Small form-factor pluggable transceiver supporting up to
10 Gb/s signal";
}"#;
let mut parser = Parser::new(s.to_string());
match IdentityStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::IdentityStmt(stmt) => {
assert_eq!(stmt.arg(), &Identifier::from_str("SFP").unwrap());
assert_eq!(stmt.if_feature(), &vec![]);
assert_eq!(
stmt.base(),
&vec![BaseStmt {
arg: IdentifierRef::from_str("TRANSCEIVER_FORM_FACTOR_TYPE").unwrap()
}]
);
assert_eq!(stmt.status(), &None);
assert_eq!(stmt.description(), &Some(DescriptionStmt { arg: String::from("Small form-factor pluggable transceiver supporting up to\n10 Gb/s signal") }));
assert_eq!(stmt.reference(), &None);
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
}
#[test]
pub fn test_typedef_stmt() {
let s = r#"zero-based-counter32 {
type yang:counter32;
default "0";
description
"The zero-based-counter32 type represents a counter32
that has the defined 'initial' value zero....";
reference
"RFC 4502: Remote Network Monitoring Management Information
Base Version 2";
}"#;
let mut parser = Parser::new(s.to_string());
match TypedefStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::TypedefStmt(stmt) => {
assert_eq!(
stmt.arg(),
&Identifier::from_str("zero-based-counter32").unwrap()
);
assert_eq!(
stmt.type_(),
&TypeStmt {
arg: IdentifierRef::from_str("yang:counter32").unwrap(),
type_body: None
}
);
assert_eq!(stmt.units(), &None);
assert_eq!(
stmt.default(),
&Some(DefaultStmt {
arg: String::from("0")
})
);
assert_eq!(stmt.description(), &Some(DescriptionStmt { arg: String::from("The zero-based-counter32 type represents a counter32\nthat has the defined 'initial' value zero....") }));
assert_eq!(stmt.reference(), &Some(ReferenceStmt { arg: String::from("RFC 4502: Remote Network Monitoring Management Information\n Base Version 2") }));
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
}
#[test]
pub fn test_deviation_stmt() {
let s = r#""/oc-if:interfaces/oc-if:interface/oc-if:hold-time" +
"/oc-if:config/oc-if:up" {
deviate add;
}"#;
let mut parser = Parser::new(s.to_string());
match DeviationStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::DeviationStmt(stmt) => {
assert_eq!(stmt.arg(), &AbsoluteSchemaNodeid::from_str("/oc-if:interfaces/oc-if:interface/oc-if:hold-time/oc-if:config/oc-if:up").unwrap());
assert_eq!(stmt.description(), &None);
assert_eq!(stmt.reference(), &None);
assert_eq!(stmt.deviate().len(), 1);
let deviate_stmt = stmt.deviate().get(0).unwrap();
match deviate_stmt {
DeviateStmt::Add(deviate_add_stmt) => {
assert_eq!(deviate_add_stmt.units(), &None);
assert_eq!(deviate_add_stmt.must().len(), 0);
assert_eq!(deviate_add_stmt.unique().len(), 0);
assert_eq!(deviate_add_stmt.config(), &None);
assert_eq!(deviate_add_stmt.mandatory(), &None);
assert_eq!(deviate_add_stmt.min_elements(), &None);
assert_eq!(deviate_add_stmt.max_elements(), &None);
}
_ => panic!("Unexpected stmt {:?}", deviate_stmt),
}
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
let s = r#""/oc-if:interfaces/oc-if:interface/oc-if:hold-time" +
"/oc-if:config/oc-if:up" {
deviate delete {
default 0;
}
description
"Hold-time 0 is not configurable on XE, use no dampening.";
}"#;
let mut parser = Parser::new(s.to_string());
match DeviationStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::DeviationStmt(stmt) => {
assert_eq!(stmt.arg(), &AbsoluteSchemaNodeid::from_str("/oc-if:interfaces/oc-if:interface/oc-if:hold-time/oc-if:config/oc-if:up").unwrap());
assert_eq!(
stmt.description(),
&Some(DescriptionStmt {
arg: String::from(
"Hold-time 0 is not configurable on XE, use no dampening."
)
})
);
assert_eq!(stmt.reference(), &None);
assert_eq!(stmt.deviate().len(), 1);
let deviate_stmt = stmt.deviate().get(0).unwrap();
match deviate_stmt {
DeviateStmt::Delete(deviate_delete_stmt) => {
assert_eq!(deviate_delete_stmt.units(), &None);
assert_eq!(deviate_delete_stmt.must().len(), 0);
assert_eq!(deviate_delete_stmt.unique().len(), 0);
assert_eq!(
deviate_delete_stmt.default(),
&vec![DefaultStmt {
arg: String::from("0")
}]
);
}
_ => panic!("Unexpected stmt {:?}", deviate_stmt),
}
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
let s = r#""/oc-if:interfaces/oc-if:interface/oc-if:state" +
"/oc-if:last-change" {
deviate replace {
type yang:date-and-time;
}
description
"Change the type of the last-change flag to date-and-time";
}"#;
let mut parser = Parser::new(s.to_string());
match DeviationStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::DeviationStmt(stmt) => {
assert_eq!(
stmt.arg(),
&AbsoluteSchemaNodeid::from_str(
"/oc-if:interfaces/oc-if:interface/oc-if:state/oc-if:last-change"
)
.unwrap()
);
assert_eq!(
stmt.description(),
&Some(DescriptionStmt {
arg: String::from(
"Change the type of the last-change flag to date-and-time"
)
})
);
assert_eq!(stmt.reference(), &None);
assert_eq!(stmt.deviate().len(), 1);
let deviate_stmt = stmt.deviate().get(0).unwrap();
match deviate_stmt {
DeviateStmt::Replace(deviate_replace_stmt) => {
assert_eq!(
deviate_replace_stmt.type_(),
&Some(TypeStmt {
arg: IdentifierRef::from_str("yang:date-and-time").unwrap(),
type_body: None
})
);
assert_eq!(deviate_replace_stmt.units(), &None);
assert_eq!(deviate_replace_stmt.default(), &None);
assert_eq!(deviate_replace_stmt.config(), &None);
assert_eq!(deviate_replace_stmt.mandatory(), &None);
assert_eq!(deviate_replace_stmt.min_elements(), &None);
assert_eq!(deviate_replace_stmt.max_elements(), &None);
}
_ => panic!("Unexpected stmt {:?}", deviate_stmt),
}
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
let s = r#""/oc-if:interfaces/oc-if:interface/oc-vlan:routed-vlan" +
"/oc-ip:ipv4/oc-ip:addresses/oc-ip:address/oc-ip:vrrp" {
deviate not-supported;
description
"IPv4 VRRP not supported in 16.6.1.";
}"#;
let mut parser = Parser::new(s.to_string());
match DeviationStmt::parse(&mut parser) {
Ok(yang) => match yang {
YangStmt::DeviationStmt(stmt) => {
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());
assert_eq!(
stmt.description(),
&Some(DescriptionStmt {
arg: String::from("IPv4 VRRP not supported in 16.6.1.")
})
);
assert_eq!(stmt.reference(), &None);
assert_eq!(stmt.deviate().len(), 1);
let deviate_stmt = stmt.deviate().get(0).unwrap();
match deviate_stmt {
DeviateStmt::NotSupported => {}
_ => panic!("Unexpected stmt {:?}", deviate_stmt),
}
}
_ => panic!("Unexpected stmt {:?}", yang),
},
Err(err) => panic!("{}", err.to_string()),
}
}
}