Skip to content

Installation

Executable

go install (≥1.18)

cddlc is available as a standalone golang binary through go install.

go install github.com/HannesKimara/cddlc/cmd/cddlc@latest

The installation can be tested by running,

cddlc --help

which will print the help to the terminal.

NAME:
   cddl - CDDL validator and code generator

USAGE:
   cddl [global options] command [command options] [arguments...]

COMMANDS:
   init           Initialize a new cddlc project
   generate, gen  Generate code from definition file
   doctor         Show information about the current build
   help, h        Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help (default: false)

Go Library

GoDoc

The cddlc module exports go packages used for tokenizing and parsing CDDL documents. To get, run:

go get -u github.com/HannesKimara/cddlc

To parse a sample CDDL document to its AST representation

package main

import (
    "fmt"
    "io/ioutil"
    "log"

    "github.com/HannesKimara/cddlc/lexer"
    "github.com/HannesKimara/cddlc/parser"
)

func main() {
    src, err := ioutil.ReadFile("foo.cddl")
    if err != nil {
        log.Fatal(err)
    }
    lex := lexer.NewLexer(string(src))
    p := parser.NewParser(lex)
    cddl, err := p.ParseFile()

    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Found %d rules\n", cddl.Rules)
}
public-key = [24*24 byte]

person = {
    name: tstr .size 3
    age: (0..120)
    address: $Address ; Address as a type plug
    public-key: public-key
}