Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mutually recursive types #14

Closed
gotwarlost opened this issue May 31, 2016 · 2 comments
Closed

Support mutually recursive types #14

gotwarlost opened this issue May 31, 2016 · 2 comments
Labels

Comments

@gotwarlost
Copy link
Contributor

Self-recursion works.

$ rdl version
rdl 1.4.7 
$ cat x.rdl
type Node Struct {
    Node left;
    Node right;
}
$ rdl -ps generate json x.rdl 
{
    "name": "x",
    "types": [
        {
            "StructTypeDef": {
                "type": "Struct",
                "name": "Node",
                "fields": [
                    {
                        "name": "left",
                        "type": "Node"
                    },
                    {
                        "name": "right",
                        "type": "Node"
                    }
                ]
            }
        }
    ]
}

However, mutual recursion doesn't

$ cat x.rdl
type Node Struct {
    Node left;
    Node right;
    Tree tree;
}

type Tree Struct {
    Node root;
}
$ rdl -ps generate json x.rdl 
*** Error (x.rdl, line 4): No such type: Tree
  1 type Node Struct {
  2     Node left;
  3     Node right;
  4     Tree tree;
  5 }
  6 
  7 type Tree Struct {
  8     Node root;
  9 }
 10 
@boynton
Copy link
Collaborator

boynton commented Jun 8, 2016

Also, recursive references should only be valid if the fields are optional.
[see #23]

@boynton
Copy link
Collaborator

boynton commented Jun 22, 2016

The mutual recursion described above is not usefully representable in JSON, i.e. the "tree" field of Node would be a complete copy of tree for every node. If you want to represent a network of references, you must define the references (i.e. UUIDs, URLs, or Strings), and use them to refer to common objects. RDL does not represent "references" to data, just structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants