anweiss / cddl

Concise data definition language (RFC 8610) implementation and JSON and CBOR validator in Rust
https://cddl.anweiss.tech
MIT License
91 stars 13 forks source link

zcbor test cases failing #199

Open nslowell opened 1 year ago

nslowell commented 1 year ago

I have successfully used https://github.com/NordicSemiconductor/zcbor for generating C code from CDDLs, but my CDDLs and their provided test cases are getting error messages when I try to run them through this tool or the website.

Can you provide some clarification on why the errors are occurring? Is this tool missing support?

Example for https://github.com/NordicSemiconductor/zcbor/blob/main/tests/cases/corner_cases.cddl:

    -
 14 -     onetofourbytes: uint .size 0b1..0o4, ; Testing binary and octal
    -                                 ^^^^^^^ missing definition for rule b1..0o4
    -
 34 - TaggedUnion = #6.4321(bool) // #6.2345(uint)
    -                             ^^ expected rule identifier followed by an assignment token '=', '/=' or '//='
    -
 46 -     #6.0(tentothirtybytetstr: tstr .size 10..30),
    -          ^^^^^^^^^^^^^^^^^^^ invalid tag syntax
    -
 64 -     #6.10(boolval: bool),
    -           ^^^^^^^ invalid tag syntax
    -
 73 - Union = Group / MultiGroup / (3,4) / "\"hello\""
    -                                 ^ expected rule identifier followed by an assignment token '=', '/=' or '//='
    -
 77 -     union: (7=>uint) / (-8=>uint),
    -                    ^ missing closing delimiter
    -
 86 - Level1 = [Level2]
    -           ^^^^^^ missing definition for rule Level2
 87 - Level2 = [2**3Level3] ; Use ** here to test backwards compatibility.
    -             ^ invalid group entry syntax
    -
116 -     unabstractedunion1: (choice1: 1 // choice2: 2),
    -                                     ^^ invalid group entry syntax
    -
121 -     upto4nils: 0*0x04nil,
    -                       ^^ missing definition for rule il
    -
140 -     floats: *float,
    -             ^ invalid group entry syntax
    -
196 -     "r" : (result:result_code),
    -                              ^ missing closing delimiter
anweiss commented 1 year ago

Thanks for reporting this @nslowell. I need to add support for hex, octal and binary numbers which is why 0b1..0o4 isn't parsing correctly.

Some of your CDDL looks a bit wonky too. You're using a lot of (key: value) syntax that is confusing the parser. Anything in the form of key: value is a group entry but you're trying to use that syntax to describe types. For example, the #6.10(boolval: bool) is invalid CDDL because the boolval: bool tag type you've specified is not actually a type but rather a group entry.

nslowell commented 1 year ago

Thanks for responding. I will highlight again that this is CDDL from the creators of zcbor, it's not my direct CDDL. My actual CDDL is simpler--though perhaps still a little "wonky"--but it runs through zcbor without error, so I assumed it was acceptable CDDL. Perhaps there is some interpretation confusion with the RFC.

I will ask NordicSemiconductor for their input, but in the meantime, I welcome any updates. Thanks, again.