From: Oren Ben-K. <or...@be...> - 2004-04-12 21:15:19
|
Surprisingly as it may sound, I have actually found some time to work on the new productions. It is coming along nicely, and I think the new set will be much more readable/understandable. While working on it, I got to the point where I deal with the fact that simple plain keys can't be empty. Recap: we decided that to ensure that there's no ambiguities in parsing block-style mappings. Since we allow omitting the value if it is null, if we also allowed empty simple keys, the following would be ambiguous: --- : null key, non-null value ? non-null key; either has null value or next line is value : non-null value; either has null key or previous line is key ? non-null key, null value ... So, the current rules say that null keys are not allowed. One must write: --- ~: null key, non-null value ? non-null key, next line is value : non-null value, prev line is key ? non-null key, null value ... At any rate, this got me thinking about another case where empty plain scalars cause us trouble. This is inside flow collections, specifically flow sequences. Currently, one can't place a , after the last entry, because this implies an additional empty plain scalar entry: # This: --- [ 1, , 2, ] # Is the same as: --- - 1 - - 2 - ... However, as Brian pointed out, it is much nicer to ignore a final , as this makes for much easier authoring. This can easily be supported if we forbid empty plain scalars inside flow collections. If this were the case, the above would be written as any of the following: --- [ 1, ~, 2, ~ ] --- [ 1, ~, 2, ~, ] ... Note the final , does not change the semantics of the collection. This rule leaves just two places where empty plain scalars are allowed: as values for a mapping key, and as values of a block sequence entry: --- forbidden here: # allowed here --- [ forbidden, here ] --- - # allowed here ... So... how do you all feel about forbidding empty plain scalars in flow sequences (and allowing a trailing , in flow collections)? My guess is that it will not affect any actual YAML files out there. In fact, how do you feel about disallowing them in general? I'm having second thoughts about how useful they are in the first place. I think the reason we supported them initially was to have the most intuitive syntax for the empty string. However, we now "recommend" the use of the (non-core, not-required, etc.) !null tag for empty plain scalars. Empty strings need to be written as "" or '' _anyway_ (if nulls are used), and I think nulls are "strange" enough (and rare enough) that requiring them to be written as ~ is justified, especially since that makes the text much more readable. So... how do you feel about banning empty plain scalars altogether? My guess is that this will also not break any YAML files - or, put another way, my guess is that if any YAML file today uses such scalars, the value is taken to be the empty string rather than a null, and we are better off dealing with this problem ASAP. Thoughts? Have fun, Oren Ben-Kiki |