From: Oren Ben-K. <or...@be...> - 2005-06-13 20:17:53
|
I'm working on the parser code and there's an issue I'm undecided on. I know what the current spec says, but I'm wondering what it _should_ say. Consider the simple mapping: --- !foo &a { bar: baz } It is clearly valid to have all the node properties to have the same indentation: --- !foo &a bar: baz ... Can the content is more indented than the properties? --- !foo &a bar: baz ... If the above is valid, how about: --- !foo &a bar: baz ... That is, what's the indentation level of the mapping: 0 (by "!foo") or 4 (by "bar:")? Or maybe the content may not be more indented than the properties, and both the above are errors? Can the properties be more indented than the content? --- !foo &a bar: baz ... Or must all node properties be at exactly the same indentation as the content, period? This would make all the examples (except the first one) invalid. Have fun, Oren Ben-Kiki |
From: Brian I. <in...@tt...> - 2005-06-13 22:58:46
|
On 13/06/05 23:17 +0300, Oren Ben-Kiki wrote: > I'm working on the parser code and there's an issue I'm undecided on. I > know what the current spec says, but I'm wondering what it _should_ > say. > > Consider the simple mapping: > > --- !foo &a { bar: baz } > > It is clearly valid to have all the node properties to have the same > indentation: > > --- > !foo > &a > bar: > baz > ... I was not aware that the properties could span lines. ie I thought you could only do: --- !foo &a bar: baz or --- &a !foo bar : baz etc. But if this is the way we want to go, then why put any indentation restrictions on the properties at all? (Since they are not seemingly ambigous.) Keep in mind that we are talking about the edge case of what we allow, *not* what we endorse as good style in any way! Cheers, Brian |
From: Oren Ben-K. <or...@be...> - 2005-06-14 05:15:17
|
Brian Ingerson wrote: > I was not aware that the properties could span lines. Well, we haven't really discussed this much. It was implicit in the spec for ages now, but who reads it ;-) The reason you might want it is that tags could get long (especially verbatim tags). Anchors could be long too (think Java object IDS, for example). It helps readability a lot to be able to put them in their own lines. > But if this is the way we want to go, then why put any indentation > restrictions on the properties at all? (Since they are not > seemingly ambigous.) Well, its clear that the properties must be more indented than the parent node. For example, the following must be invalid: --- foo: bar: !tag &anchor key: value ... But this might be valid: --- foo: bar: !tag &anchor key1: value key2: value ... And so might this: --- foo: bar: !tag &anchor key1: value key2: value ... This is a complicated rule to specify and implement (not to mention being as ugly as sin), but as you point out it doesn't cause ambiguities. > Keep in mind that we are talking about the edge case of what we > allow, *not* what we endorse as good style in any way! Which is in line with what TRANS wrote: > Is there a general YAML-dev philosophy about enforcing good form? Now, YAML doesn't try to rule out all possible bad forms. On the other hand, we do have readability as goal #1, and the reason we have Python-like indentation rules in the first place is to support it. I tend towards saying that properties must be indented exactly as the node content itself. This helps readability and simplifies the indentation rules (and their implementation :-). That is, write: --- foo: bar: !very-long-tag &very-long-anchor key1: value1 key2: value2 ... Any good reason not to make this the rule? Have fun, Oren Ben-Kiki |