Skip to content

Commit be6ef6f

Browse files
committed
allow if-feature in enums
1 parent 7c61743 commit be6ef6f

File tree

8 files changed

+423
-364
lines changed

8 files changed

+423
-364
lines changed

meta/core.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,12 @@ type Bit struct {
11631163
}
11641164

11651165
type Enum struct {
1166+
parent Meta
11661167
ident string
11671168
desc string
11681169
ref string
11691170
val int
1171+
ifs []*IfFeature
11701172
extensions []*Extension
11711173
}
11721174

meta/core_gen.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4216,6 +4216,14 @@ func (m *Enum) Ident() string {
42164216
return m.ident
42174217
}
42184218

4219+
// Parent is where this extension is define unless the extension is a
4220+
// secondary extension like a description and then this is the parent
4221+
// of that description
4222+
func (m *Enum) Parent() Meta {
4223+
return m.parent
4224+
}
4225+
4226+
42194227
// Description of Enum
42204228
func (m *Enum) Description() string {
42214229
return m.desc
@@ -4242,6 +4250,15 @@ func (m *Enum) addExtension(extension *Extension) {
42424250
}
42434251

42444252

4253+
func (m *Enum) IfFeatures() []*IfFeature {
4254+
return m.ifs
4255+
}
4256+
4257+
func (m *Enum) addIfFeature(i *IfFeature) {
4258+
i.parent = m
4259+
m.ifs = append(m.ifs, i)
4260+
}
4261+
42454262

42464263

42474264
// Description of Range

parser/parser.go

Lines changed: 361 additions & 361 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ error_app_tag_stmt :
608608
}
609609
}
610610

611-
612611
if_feature_stmt :
613612
kywd_if_feature string_value statement_end {
614613
l := yylex.(*lexer)
@@ -1489,6 +1488,7 @@ enum_body_stmt :
14891488
| status_stmt
14901489
| reference_stmt
14911490
| enum_value
1491+
| if_feature_stmt
14921492
| unknown_stmt
14931493

14941494
enum_value :

parser/testdata/feature/gold/x.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,20 @@
2323
"leaf":{
2424
"type":{
2525
"ident":"string",
26-
"format":"string"}}}]}}],
26+
"format":"string"}}}]}},
27+
{
28+
"ident":"l3",
29+
"leaf":{
30+
"type":{
31+
"ident":"enumeration",
32+
"enumeration":[
33+
{
34+
"label":"one",
35+
"id":0},
36+
{
37+
"label":"two",
38+
"id":1}],
39+
"format":"enum"}}}],
2740
"feature":[
2841
{
2942
"ident":"blacklisted"},

parser/testdata/feature/gold/x.lex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ type "type"
4747
; ";"
4848
} "}"
4949
} "}"
50+
leaf "leaf"
51+
[ident] "l3"
52+
{ "{"
53+
type "type"
54+
[ident] "enumeratio"...
55+
{ "{"
56+
enum "enum"
57+
[string] "one"
58+
{ "{"
59+
if-feature "if-feature"
60+
[string] "\"x\""
61+
; ";"
62+
} "}"
63+
enum "enum"
64+
[string] "two"
65+
; ";"
66+
} "}"
67+
} "}"
5068
uses "uses"
5169
[ident] "g"
5270
{ "{"

parser/testdata/feature/x.yang

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ module x {
2424
}
2525
}
2626

27+
leaf l3 {
28+
type enumeration {
29+
enum one {
30+
if-feature "x";
31+
}
32+
enum two;
33+
}
34+
}
35+
2736
uses g {
2837
if-feature blacklisted;
2938
}

yang/fc-yang.yang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module fc-yang {
1313

1414
/*
1515
* NOTES:
16-
16+
*
1717
* !! contains CIRCULAR references however there is no other way around
1818
* this. According to RFC7950 this is not allowed.
1919
*/

0 commit comments

Comments
 (0)