Skip to content

Commit

Permalink
issue #114 - allow numbers in quote in yang
Browse files Browse the repository at this point in the history
  • Loading branch information
dhubler committed Jul 22, 2024
1 parent 0ef5e8b commit 0f3d0ba
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 57 deletions.
4 changes: 3 additions & 1 deletion parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ func lexBegin(l *lexer) stateFunc {
if l.acceptToken(ttype) {
if !l.acceptToken(kywd_unbounded) {
if !l.acceptInteger(token_number) {
return l.error("expecting integer")
if !l.acceptToken(token_string) {
return l.error("expecting integer")
}
}
}
return l.acceptEndOfStatement()
Expand Down
115 changes: 59 additions & 56 deletions parser/parser_samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,71 @@ var yangTestFiles = []struct {
dir string
fname string
}{
{"/ddef", "container"},
{"/ddef", "assort"},
{"/ddef", "unique"},
{"/import", "x"},
{"/import", "example-barmod"},
{"/include", "x"},
{"/include", "top"},
{"/types", "anydata"},
{"/types", "enum"},
{"/types", "container"},
{"/types", "leaf"},
{"/types", "union"},
{"/types", "leafref"},
{"/types", "leafref-i1"},
{"/types", "union-units"},
{"/types", "bits"},
{"/typedef", "x"},
{"/typedef", "typedef-x"},
{"/typedef", "import"},
{"/grouping", "x"},
{"/grouping", "scope"},
{"/grouping", "refine"},
{"/grouping", "augment"},
{"/grouping", "empty"},
{"/grouping", "issue-46"},
{"/grouping", "refine-default"},
{"/grouping", "recurse-1"},
{"/grouping", "recurse-2"},
{"/grouping", "recurse-3"},
{"/extension", "x"},
{"/extension", "y"},
{"/extension", "yin"},
/*
{"/ddef", "container"},
{"/ddef", "assort"},
{"/ddef", "unique"},
{"/import", "x"},
{"/import", "example-barmod"},
{"/include", "x"},
{"/include", "top"},
{"/types", "anydata"},
{"/types", "enum"},
{"/types", "container"},
{"/types", "leaf"},
{"/types", "union"},
{"/types", "leafref"},
{"/types", "leafref-i1"},
{"/types", "union-units"},
{"/types", "bits"},
{"/typedef", "x"},
{"/typedef", "typedef-x"},
{"/typedef", "import"},
{"/grouping", "x"},
{"/grouping", "scope"},
{"/grouping", "refine"},
{"/grouping", "augment"},
{"/grouping", "empty"},
{"/grouping", "issue-46"},
{"/grouping", "refine-default"},
{"/grouping", "recurse-1"},
{"/grouping", "recurse-2"},
{"/grouping", "recurse-3"},
{"/extension", "x"},
{"/extension", "y"},
{"/extension", "yin"},
// not all the extensions are dumped but at least all extensions are
// parsed. lexer test does dump all tokens
{"/extension", "extreme"},
// not all the extensions are dumped but at least all extensions are
// parsed. lexer test does dump all tokens
{"/extension", "extreme"},
{"/augment", "x"},
{"/augment", "aug-with-uses"},
{"/augment", "aug-choice"},
{"/augment", "refine"},
{"/identity", "x"},
{"/feature", "x"},
{"/when", "x"},
{"/must", "x"},
{"/choice", "no-case"},
{"/choice", "choice-mandatory"},
{"/choice", "choice-default"},
{"/choice", "choice-x"},
{"/general", "status"},
{"/general", "rpc-groups"},
{"/general", "notify-groups"},
{"/general", "anydata"},
{"/augment", "x"},
{"/augment", "aug-with-uses"},
{"/augment", "aug-choice"},
{"/augment", "refine"},
{"/identity", "x"},
{"/feature", "x"},
{"/when", "x"},
{"/must", "x"},
{"/choice", "no-case"},
{"/choice", "choice-mandatory"},
{"/choice", "choice-default"},
{"/choice", "choice-x"},
{"/general", "status"},
{"/general", "rpc-groups"},
{"/general", "notify-groups"},
{"/general", "anydata"},
{"/general", "rpc"},
{"/general", "rpc"},
{"/general", "rev"},
{"/general", "rev"},
{"/deviate", "x"},
{"/deviate", "x"},
{"", "turing-machine"},
{"", "basic_config2"},
{"", "turing-machine"},
{"", "basic_config2"},
*/
{"", "issue-114"},
}

// recursive, we can parse it but dumping to json is infinite recursion
Expand Down
21 changes: 21 additions & 0 deletions parser/testdata/gold/issue-114.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"module":{
"ident":"issue-114",
"description":"allowing for numbers wrapped in double quotes",
"namespace":"freeconf.org",
"prefix":"i",
"version":"\"1.1\"",
"dataDef":[
{
"ident":"a",
"list":{
"key":[],
"minElements":1,
"maxElements":10,
"dataDef":[
{
"ident":"x",
"leaf":{
"type":{
"ident":"string",
"format":"string"}}}]}}]}}
33 changes: 33 additions & 0 deletions parser/testdata/gold/issue-114.lex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module "module"
[ident] "issue-114"
{ "{"
yang-version "yang-versi"...
[string] "\"1.1\""
; ";"
namespace "namespace"
[string] "\"freeconf."...
; ";"
prefix "prefix"
[string] "\"i\""
; ";"
description "descriptio"...
[string] "\"allowing "...
; ";"
list "list"
[ident] "a"
{ "{"
min-elements "min-elemen"...
[string] "\"1\""
; ";"
max-elements "max-elemen"...
[string] "\"10\""
; ";"
leaf "leaf"
[ident] "x"
{ "{"
type "type"
[ident] "string"
; ";"
} "}"
} "}"
} "}"
14 changes: 14 additions & 0 deletions parser/testdata/issue-114.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module issue-114 {
yang-version "1.1";
namespace "freeconf.org";
prefix "i";
description "allowing for numbers wrapped in double quotes";

list a {
min-elements "1";
max-elements "10";
leaf x {
type string;
}
}
}

0 comments on commit 0f3d0ba

Please sign in to comment.