There are times that I want to format my code in a tabular format. Recently we're struggling with some of our RelaxNG compact schemas for our REST XML because we have something like this:
promo-element = element promo { ids-group?, promo-body, links-element? }
Note how everything but the promo-body is optional? The ids are forbidden in a POST, but required for PUT and GET. The links-element, however, is required for GET but forbidden on POST and PUT (actually, we allow them and ignore them).
So really, we want three definitions here.
GET-promo-element = element promo { ids-group?, promo-body, links-element? } POST-promo-element = element promo { promo-body, } PUT-promo-element = element promo { ids-group, promo-body, }
This doesn't look too bad, but take a look at our series element:
series-element = element series { pid-addressable-attr-group?, revision-attributes-group, collection-attr-group, crid-group?, ids-group?, relations-group, title-description-group, master-brand-group?, related-element?, genres-group?, formats-group?, stack-element, promotions-group?, warnings-group?, links-element? }
Imagine taking the above and laying it out vertically in three separate definitions and knowing it's going to grow over time. Seeing what's related to what could get confusing (it would be much worse to have this duplicated information spread across multiple files.
That's why it would be nice to implement this:
GET-promo-element = - POST-promo-element = - PUT-promo-element = element promo { - element promo { - element promo { ids-group, - - ids-group, promo-body, - promo-body, - promo-body, links-element - - links-element? } - } - }
Everything lines up nicely, it's easy to see how things relate, and it's completely invalid RelaxNG -- until you split those three columns. Editing it would be a pain, though. Editors work vertically, not horizontally (vim has some interesting support here, but it's clumsy).
Well, some editors can edit tabular data decently.
Particularly the table editor in org-mode (find "tables" in the page) is nice. It can be used outside of org buffers as well.
Not sure it can use arbitrary column separators though, but that might be possible.
From looking at that definition it looks like you can split the list in three parts for each method, of which the middle one is identical. You can express this perfectly well in RNG.
Re:Insufficient factoring?
Ovid on 2008-11-29T01:37:54
Of course you can and that's an option we explored. However, look at the larger RNG definition. Many of the required/forbidden/optional elements vary quite a bite for GET/POST/PUT and the split of the three of them, with dependencies, we felt was much easier to read when separate definitions rather than multiple paths on the same definition.