You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add proc parseCddl*(source: string, ignoreComments = false): CddlSchema, convert a CDDL into an AST
Add proc toCddl*(n: CddlNode, pretty = false, verify = true): string which converts an AST to CDDL. It also parses the resulting CDDL and checks the AST is the same as the original.
Add proc dumpTree*(n: CddlNode): string, similar to Nim macro dumpTree, it returns the AST structure.
Add func isValid*(n: CddlNode): bool =, checks an AST structure is valid.
Add roundtrip tests. The toCddl cannot keep the original format, but it should produce the same CDDL schema; so the roundtrip test is done on a pre-formatted schema that matches toCddl output.
Add cbor_serialization/cddl/parser2_schema.md which contains a cddl of the parser Node. It can be used to generate a matching DS. The type_generator is not able to parse it yet (requires union support).
@arnetheduck is cbor_serialization/cddl/parser2_schema.md what you meant by schema of the schema? it can be used to encode a schema into CBOR for example.
For the toCddl (printer) output, you can check tests/test_cddl_parser_36_dump_pretty.txt to see what it produces. It also checks the resulting AST matches the original one (similar to what nph does I think); so it cannot construct a different/invalid CDDL; there is a param to disable it because it can be slow (it needs to parse the output).
No need to review the code I think. It's mostly tests, though. One thing to notice is the CddlNode has the =copy disallowed in Nim +2.2 with ORC to avoid unintended AST copies; an alternative would be making the CddlNode a ref, but then you cannot store it in a const (although, it's still not clear to me what's the use case).
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #37
Changes:
cbor_serialization/cddl/parsercbor_serialization/cddl/parser2CddlNodenode based ASTproc parseCddl*(source: string, ignoreComments = false): CddlSchema, convert a CDDL into an ASTproc toCddl*(n: CddlNode, pretty = false, verify = true): stringwhich converts an AST to CDDL. It also parses the resulting CDDL and checks the AST is the same as the original.proc dumpTree*(n: CddlNode): string, similar to Nim macro dumpTree, it returns the AST structure.func isValid*(n: CddlNode): bool =, checks an AST structure is valid.toCddlcannot keep the original format, but it should produce the same CDDL schema; so the roundtrip test is done on a pre-formatted schema that matchestoCddloutput.cbor_serialization/cddl/parser2_schema.mdwhich contains a cddl of the parser Node. It can be used to generate a matching DS. Thetype_generatoris not able to parse it yet (requires union support).