From: Clark C . E. <cc...@cl...> - 2001-11-07 17:14:53
|
Regarding open issue of top level class assignment -- let us allow the class of a top level sequence/map to be set by a comment... | Proposed solution: | | A. Since list is used by Perl and Python to | mean two different things, we adopt "tuple" | from python and "array" from Perl. Let us | call these classes org.yaml.array (!array) | and org.yaml.tuple (!tuple). | | B. We call our sequential yaml construct (-) | a seq(uence). And we call our functional | construct (:) a map. Thus the word "list" | is no longer part of the YAML vocabulary | to reduce confusion. | | C. The starting production is map xor seq. | A YAML text may not begin with a scalar, | however, a YAML text can begin with a | one-tuple... which is damn close. | | D. The default class for a top level sequence | is a !tuple and the default class for | secondary and further indented sequences | is an !array. E. The throw-away comment syntax is used to provide both the version number and any indicators to be applied to the top leve map or sequence. Subsequent YAML directives are ignored to enable concatination. #YAML v1.0 !array &001 ... With the proposal, your syntax below should work... as a top level sequence would be the starting production, with a default class of !tuple -- giving this syntax: | $yaml = YAML->emit_string($a, $b, $c); | ($a, $b, $c) = YAML->parse_string($yaml); The yaml file would look something like... - value for $a - value for $b - value for $c Of course, if you had four items in the file, or three items, or a map, etc., then the parse_string would probably return back a value which couldn't be cast into a 3-list, no? ... On to how the syntax chanages... | a: map a: map | - an | - array #YAML !array - an - array | # a log file | - | date: Tue Nov 6 11:49:14 PST 2001 | message: yaml died | - | date: Tue Nov 6 11:49:15 PST 2001 | message: yaml cam back to life # log file # #YAML !array - date: Tue Nov 6 11:49:14 PST 2001 message: yaml died - date: Tue Nov 6 11:49:15 PST 2001 message: yaml cam back to life | a scalar - a scalar | !!My::Class | key: value #YAML !!My::Class key: value | # an implicit integer | 5 # an implict integer - 5 | # What's this? | -42 | #I'd like it to be an implicit integer # implicit negative integer - -42 | # and this be an array | - 42 #YAML v1.0 !array - 42 | # definitely an implicit integer. right? | \ | -42 - \ -42 | #an explicit int | !int -42 #an explict int - !int -42 | # the following is a parse error | # (to reserve for future use) | ---- still a parse error | "- A scalar" - "- A scalar" | \ | "A multi | line scalar" - \ "A multi line scalar" | \ | Also a multi | line scalar #YAML v1.0 - \ Also a multi line scalar | | | # A block of Perl | sub one { | 1; | } - | # A block of Perl (this comment is content) sub one { 1; } | # an implicit null | ~ #an implict null - ~ | !org.borg.schmorg \ | A multi line | explicitly classed | scalar. - !org.borg.schmorg \ A multi line explicitly classed scalar. Does this grok? If you don't like the tuple being the default class... then we can always make the array the default class everywhere. In this case, those "singleton" items would be marked as a tuple, and those marked "array" could be unmarked. This proposal has several advantages: 1. The syntax only has one exception, a special comment marker for top-level class, anchor. 2. The exception is overrided to further provide a YAML version mechanism, which we needed. 3. None of the core productions change. 4. YAML files can be resonably concatinated. (a) the top level production must be the same, sequence to sequence or map to map. (b) duplicate keys in a map / map concatination are an error... (c) It is possible to a YAML file and insert it into another YAML file at any level... while it preserves its meaning. Best, Clark |