kdl-org / kdl

the kdl document language specifications
https://kdl.dev
Other
1.14k stars 62 forks source link

Add Schema spec for node and value tags #135

Closed larsgw closed 3 years ago

larsgw commented 3 years ago

Let me preface this with the fact that I don't really like this right now (even though I did agree with the inclusion of tags). It's just that there's two ways to interpret their meaning, so two ways that people use them, so two ways that they need to be validated. Anyway, first of all this adds specs for validating value tags:

document {
    node {
        value {
            type "string"
            tag {
                enum "base64" "base58"
            }
        }
        prop "foo" {
            tag {
                enum "bar" "baz"
            }
        }
    }
}

This tag can have any of the nodes from the validation block. I could have made a shortcut to do tag "bar" "baz" instead but I feel like pattern might be useful and then there would be two ways to do an enum.

Second, as I mentioned I feel there are two ways to use node tags. One way is to use them as a key, in which case you want to be able to control e.g. max 1 and/or a sort of tag-names. For that purpose the following structure is made available in this PR:

document {
    // also tag-names and other-tags-allowed
    tag "author" {
        min 1
        node "person" ref="#person"
        node "organization" ref="#person"
    }
}

The other way is to use it as an annotation of nodes which requires a much simpler structure:

document {
    node "person" {
        tag {
            enum "author" "contributor"
        }
    }
}