From 493940563c443f9710623164fee0524fd72a188a Mon Sep 17 00:00:00 2001 From: Douglas Hubler Date: Mon, 22 Jul 2024 08:31:13 -0400 Subject: [PATCH] issue #114 - allow numbers in quote in yang --- parser/lexer.go | 4 +++- parser/parser_samples_test.go | 1 + parser/testdata/gold/issue-114.json | 21 ++++++++++++++++++ parser/testdata/gold/issue-114.lex | 33 +++++++++++++++++++++++++++++ parser/testdata/issue-114.yang | 14 ++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 parser/testdata/gold/issue-114.json create mode 100644 parser/testdata/gold/issue-114.lex create mode 100644 parser/testdata/issue-114.yang diff --git a/parser/lexer.go b/parser/lexer.go index a59bb777..db82e1be 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -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() diff --git a/parser/parser_samples_test.go b/parser/parser_samples_test.go index 8be86d92..4d95ee67 100644 --- a/parser/parser_samples_test.go +++ b/parser/parser_samples_test.go @@ -76,6 +76,7 @@ var yangTestFiles = []struct { {"", "turing-machine"}, {"", "basic_config2"}, + {"", "issue-114"}, } // recursive, we can parse it but dumping to json is infinite recursion diff --git a/parser/testdata/gold/issue-114.json b/parser/testdata/gold/issue-114.json new file mode 100644 index 00000000..85b5f4f2 --- /dev/null +++ b/parser/testdata/gold/issue-114.json @@ -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"}}}]}}]}} \ No newline at end of file diff --git a/parser/testdata/gold/issue-114.lex b/parser/testdata/gold/issue-114.lex new file mode 100644 index 00000000..d0eaa610 --- /dev/null +++ b/parser/testdata/gold/issue-114.lex @@ -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" +; ";" +} "}" +} "}" +} "}" diff --git a/parser/testdata/issue-114.yang b/parser/testdata/issue-114.yang new file mode 100644 index 00000000..d54e8643 --- /dev/null +++ b/parser/testdata/issue-114.yang @@ -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; + } + } +} \ No newline at end of file