You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Obviously, it's a lot more compact, but I think it's also more legible. Looking at it using YAML sans Table Style, how quickly did you notice that VAULT_IS_ENABLED is receiving the string true as a value, not having the boolean required set? This is a common issue I run into right now - not noticing that the key (and maybe type) has changed.
I suppose I'll try formally specifying the rules about this now:
Anywhere you can start a sequence with an indented -, it's also valid to begin a table with an indented |.
All lines of a table have the same indentation and begin and end with |. The table ends when the next line is dedented. Comments and blank lines within tables are acceptable.
Lines within a table are broken down into cells by the character |. These cells are indexed from left to right.
The first line of a table (the header line) defines the keys. Each remaining line of the table is a mapping within a sequence.
Each cell of the header line contains either a simple key (name, value, and required in the examples above) or a compound key (valueFrom.secretKeyRef in the second example above).
Cells within a mapping line contain either nothing (whitespace), a Scalar, or a Flow Sequence or Flow Mapping.
Mapping lines do not need to contain as many cells as the header line, but they may not contain more.
If a mapping line has fewer cells than the header line, the mapping lacks key/values for the trailing keys in the header line.
If a mapping line contains nothing but whitespace, the mapping lacks a key/value for the key in the header line at the same index as the cell within the mapping.
How was that for rules? I wasn't sure if I could express them clearly enough in English. Do people understand? What ambiguity is there? Is there an existing complete BNF for Yaml? I searched through the existing spec, and although it mentions "bnf" a few times, I'm not sure it fully lays it out anywhere... if there is one, I can update it to include "Table Style".
It might be worth looking at the goals of YAML:
✅ "YAML should be easily readable by humans." I think that was established above already.
✅ "YAML data should be portable between programming languages." That can be done by updating the spec...
✅ "YAML should match the native data structures of dynamic languages." - I've seen this Table syntax used in Gherkin feature files/Karate test framework quite a bit. It's also in markdown.
✅ "YAML should have a consistent model to support generic tools." I don't think my proposal touches this...
✅ "YAML should support one-pass processing." Later lines do not change how earlier lines are interpreted, so I believe we're good here.
✅ "YAML should be expressive and extensible." I don't think this proposal removes much potential for future extensions...
✅ "YAML should be easy to implement and use." Adding Table Style shouldn't be any more difficult than existing features of YAML.
The text was updated successfully, but these errors were encountered:
Is there an existing complete BNF for Yaml? I searched through the existing spec, and although it mentions "bnf" a few times, I'm not sure it fully lays it out anywhere.
In the YAML 1.2 spec, The grammar is not consolidated into one place, but distributed across various sections. You can copy the combined text of all production definitions by running the following in the browser console with the spec open: copy($$('pre.rule').map(x => x.textContent).join('\n\n')).
... valid syntax and also kind of readable, yet redundant in the keys.
And I agree: some humans are well-experienced with spreadsheets.
Additional feature
Maybe make the header line somewhat more distinguishable from the other rows?
I really like the AsciiDoc approach to tables.
Applied to your example, that would be like:
It's fairly common for YAML files to include sequences of several mappings where all the mappings have the same or very similar keys.
Such lists of mappings are tedious to write and a fairly common source of errors.
On projects I work on, I've introduced an extension to the YAML format that adds in a "Table Style" for expressing such sequences.
Before I stumble through trying to explain the syntax, maybe I'll start with some examples:
Without Table Style:
Could instead be expressed using "Table Style" as this:
Obviously, it's a lot more compact, but I think it's also more legible. Looking at it using YAML sans Table Style, how quickly did you notice that VAULT_IS_ENABLED is receiving the string true as a value, not having the boolean required set? This is a common issue I run into right now - not noticing that the key (and maybe type) has changed.
Here's another example - first without:
And now with Table Style:
I suppose I'll try formally specifying the rules about this now:
-
, it's also valid to begin a table with an indented|
.|
. The table ends when the next line is dedented. Comments and blank lines within tables are acceptable.|
. These cells are indexed from left to right.name
,value
, andrequired
in the examples above) or a compound key (valueFrom.secretKeyRef
in the second example above).How was that for rules? I wasn't sure if I could express them clearly enough in English. Do people understand? What ambiguity is there? Is there an existing complete BNF for Yaml? I searched through the existing spec, and although it mentions "bnf" a few times, I'm not sure it fully lays it out anywhere... if there is one, I can update it to include "Table Style".
It might be worth looking at the goals of YAML:
✅ "YAML should be easily readable by humans." I think that was established above already.
✅ "YAML data should be portable between programming languages." That can be done by updating the spec...
✅ "YAML should match the native data structures of dynamic languages." - I've seen this Table syntax used in Gherkin feature files/Karate test framework quite a bit. It's also in markdown.
✅ "YAML should have a consistent model to support generic tools." I don't think my proposal touches this...
✅ "YAML should support one-pass processing." Later lines do not change how earlier lines are interpreted, so I believe we're good here.
✅ "YAML should be expressive and extensible." I don't think this proposal removes much potential for future extensions...
✅ "YAML should be easy to implement and use." Adding Table Style shouldn't be any more difficult than existing features of YAML.
The text was updated successfully, but these errors were encountered: