Skip to content

Commit

Permalink
issue #92 - typedefs, defaults and leaf-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Hubler committed Oct 23, 2023
1 parent 11116a6 commit 12dceff
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
20 changes: 15 additions & 5 deletions meta/core_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,8 +1671,10 @@ func (m *LeafList) DefaultValue() interface{} {
func (m *LeafList) setDefaultValue(d interface{}) {
if s, valid := d.([]string); valid {
m.defaultVals = s
} else if s, valid := d.(string); valid {
m.defaultVals = []string{s}
} else {
panic("expected []string")
panic("expected []string or string")
}
}

Expand Down Expand Up @@ -2281,8 +2283,10 @@ func (m *Refine) DefaultValue() interface{} {
func (m *Refine) setDefaultValue(d interface{}) {
if s, valid := d.([]string); valid {
m.defaultVals = s
} else if s, valid := d.(string); valid {
m.defaultVals = []string{s}
} else {
panic("expected []string")
panic("expected []string or string")
}
}

Expand Down Expand Up @@ -3351,8 +3355,10 @@ func (m *AddDeviate) DefaultValue() interface{} {
func (m *AddDeviate) setDefaultValue(d interface{}) {
if s, valid := d.([]string); valid {
m.defaultVals = s
} else if s, valid := d.(string); valid {
m.defaultVals = []string{s}
} else {
panic("expected []string")
panic("expected []string or string")
}
}

Expand Down Expand Up @@ -3473,8 +3479,10 @@ func (m *ReplaceDeviate) DefaultValue() interface{} {
func (m *ReplaceDeviate) setDefaultValue(d interface{}) {
if s, valid := d.([]string); valid {
m.defaultVals = s
} else if s, valid := d.(string); valid {
m.defaultVals = []string{s}
} else {
panic("expected []string")
panic("expected []string or string")
}
}

Expand Down Expand Up @@ -3556,8 +3564,10 @@ func (m *DeleteDeviate) DefaultValue() interface{} {
func (m *DeleteDeviate) setDefaultValue(d interface{}) {
if s, valid := d.([]string); valid {
m.defaultVals = s
} else if s, valid := d.(string); valid {
m.defaultVals = []string{s}
} else {
panic("expected []string")
panic("expected []string or string")
}
}

Expand Down
4 changes: 3 additions & 1 deletion meta/core_gen.in
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ func (m *{{.Name}}) DefaultValue() interface{} {
func (m *{{.Name}}) setDefaultValue(d interface{}) {
if s, valid := d.([]string); valid {
m.defaultVals = s
} else if s, valid := d.(string); valid {
m.defaultVals = []string{s}
} else {
panic("expected []string")
panic("expected []string or string")
}
}

Expand Down
9 changes: 8 additions & 1 deletion parser/testdata/typedef/gold/typedef-x.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
"range":"-11.111..22.222",
"errorMessage":"This is an error-message for range in typedef"}],
"fractionDigits":4,
"format":"decimal64"}}}]}}
"format":"decimal64"}}},
{
"ident":"l",
"leaf-list":{
"default":"[7]",
"type":{
"ident":"ls",
"format":"stringList"}}}]}}
17 changes: 17 additions & 0 deletions parser/testdata/typedef/gold/typedef-x.lex
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ description "descriptio"...
[string] "\"This is l"...
; ";"
} "}"
typedef "typedef"
[ident] "ls"
{ "{"
type "type"
[ident] "string"
; ";"
default "default"
[string] "7"
; ";"
} "}"
leaf-list "leaf-list"
[ident] "l"
{ "{"
type "type"
[ident] "ls"
; ";"
} "}"
} "}"
9 changes: 9 additions & 0 deletions parser/testdata/typedef/typedef-x.yang
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ module typedef-x {
type new_type_decimal;
description "This is leaf-derived-type";
}

typedef ls {
type string ;
default 7;
}

leaf-list l {
type ls;
}
}

0 comments on commit 12dceff

Please sign in to comment.