Skip to content

Commit

Permalink
issue #16 - imply case in choice when it is not there. YANG 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dhubler committed Jul 8, 2018
1 parent dbbe6fa commit 9bc5c8f
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 413 deletions.
11 changes: 9 additions & 2 deletions meta/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meta
import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/freeconf/gconf/c2"
Expand Down Expand Up @@ -542,8 +543,14 @@ func (y *Choice) resolve(pool schemaPool) error {

func (y *Choice) buildCases() {
y.cases = make(map[string]*ChoiceCase)
for _, ddef := range y.defs.dataDefs {
y.cases[ddef.Ident()] = ddef.(*ChoiceCase)
for i, ddef := range y.defs.dataDefs {
if ddef, ok := ddef.(*ChoiceCase); ok {
y.cases[ddef.Ident()] = ddef
} else {
implicit := NewChoiceCase(y, strconv.Itoa(i))
implicit.add(ddef)
y.cases[implicit.Ident()] = implicit
}
}
}

Expand Down
823 changes: 413 additions & 410 deletions meta/yang/parser.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion meta/yang/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ choice_stmt_body :
| description
| reference_stmt
| case_stmts
| body_stmts
| if_feature_stmt
| when_stmt

Expand Down Expand Up @@ -530,7 +531,7 @@ type_stmt :

type_stmt_def :
kywd_type token_ident {
if push(yylex, meta.NewDataType($2)) {
if push(yylex, meta.NewType($2)) {
goto ret1
}
}
Expand Down
1 change: 1 addition & 0 deletions meta/yang/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ var yangTestFiles = []struct {
{"/feature", "x"},
{"/when", "x"},
{"/must", "x"},
{"/choice", "no-case"},
{"", "turing-machine"},
}

Expand Down
16 changes: 16 additions & 0 deletions meta/yang/testdata/choice/gold/no-case.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"module":{
"ident":"x",
"revision":{
"rev-date":"0"},
"dataDef":[
{
"ident":"c",
"choice":{
"dataDef":[
{
"ident":"x",
"leaf":{
"type":{
"ident":"string",
"format":"string"}}}]}}]}}
18 changes: 18 additions & 0 deletions meta/yang/testdata/choice/gold/no-case.lex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module "module"
[ident] "x"
{ "{"
revision "revision"
[string] "0"
; ";"
choice "choice"
[ident] "c"
{ "{"
leaf "leaf"
[ident] "x"
{ "{"
type "type"
[ident] "string"
; ";"
} "}"
} "}"
} "}"
8 changes: 8 additions & 0 deletions meta/yang/testdata/choice/no-case.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module x {
revision 0;
choice c {
leaf x {
type string;
}
}
}

0 comments on commit 9bc5c8f

Please sign in to comment.