Skip to content

Commit

Permalink
allow if-feature in enums
Browse files Browse the repository at this point in the history
  • Loading branch information
dhubler committed Jan 13, 2024
1 parent 7c61743 commit be6ef6f
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 364 deletions.
2 changes: 2 additions & 0 deletions meta/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,10 +1163,12 @@ type Bit struct {
}

type Enum struct {
parent Meta
ident string
desc string
ref string
val int
ifs []*IfFeature
extensions []*Extension
}

Expand Down
17 changes: 17 additions & 0 deletions meta/core_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4216,6 +4216,14 @@ func (m *Enum) Ident() string {
return m.ident
}

// Parent is where this extension is define unless the extension is a
// secondary extension like a description and then this is the parent
// of that description
func (m *Enum) Parent() Meta {
return m.parent
}


// Description of Enum
func (m *Enum) Description() string {
return m.desc
Expand All @@ -4242,6 +4250,15 @@ func (m *Enum) addExtension(extension *Extension) {
}


func (m *Enum) IfFeatures() []*IfFeature {
return m.ifs
}

func (m *Enum) addIfFeature(i *IfFeature) {
i.parent = m
m.ifs = append(m.ifs, i)
}



// Description of Range
Expand Down
722 changes: 361 additions & 361 deletions parser/parser.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ error_app_tag_stmt :
}
}


if_feature_stmt :
kywd_if_feature string_value statement_end {
l := yylex.(*lexer)
Expand Down Expand Up @@ -1489,6 +1488,7 @@ enum_body_stmt :
| status_stmt
| reference_stmt
| enum_value
| if_feature_stmt
| unknown_stmt

enum_value :
Expand Down
15 changes: 14 additions & 1 deletion parser/testdata/feature/gold/x.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@
"leaf":{
"type":{
"ident":"string",
"format":"string"}}}]}}],
"format":"string"}}}]}},
{
"ident":"l3",
"leaf":{
"type":{
"ident":"enumeration",
"enumeration":[
{
"label":"one",
"id":0},
{
"label":"two",
"id":1}],
"format":"enum"}}}],
"feature":[
{
"ident":"blacklisted"},
Expand Down
18 changes: 18 additions & 0 deletions parser/testdata/feature/gold/x.lex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ type "type"
; ";"
} "}"
} "}"
leaf "leaf"
[ident] "l3"
{ "{"
type "type"
[ident] "enumeratio"...
{ "{"
enum "enum"
[string] "one"
{ "{"
if-feature "if-feature"
[string] "\"x\""
; ";"
} "}"
enum "enum"
[string] "two"
; ";"
} "}"
} "}"
uses "uses"
[ident] "g"
{ "{"
Expand Down
9 changes: 9 additions & 0 deletions parser/testdata/feature/x.yang
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ module x {
}
}

leaf l3 {
type enumeration {
enum one {
if-feature "x";
}
enum two;
}
}

uses g {
if-feature blacklisted;
}
Expand Down
2 changes: 1 addition & 1 deletion yang/fc-yang.yang
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module fc-yang {

/*
* NOTES:
*
* !! contains CIRCULAR references however there is no other way around
* this. According to RFC7950 this is not allowed.
*/
Expand Down

0 comments on commit be6ef6f

Please sign in to comment.