-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blank lines #64
Add blank lines #64
Conversation
…lines after collections in collections
Edited the top comment to reflect updates. In addition to what's mentioned there, the parsing of comments within map pairs has been updated a bit: the const doc = YAML.parseDocument(`
#0
key: #1
#2
value #3`)
> pair = doc.contents.items[0]
Pair {
key:
Scalar {
value: 'key',
range: [ 4, 7 ],
type: 'PLAIN',
commentBefore: '0' },
value:
Scalar {
value: 'value',
range: [ 19, 27 ],
type: 'PLAIN',
commentBefore: '2',
comment: '3' },
type: 'PAIR',
comment: '1' } Assigning a multi-line comment to |
…Document#contents
I think this might be about done now? I may let this sit open for a little while before merging, in case I change my mind. |
Note: This is still a work in progress, and the API described here may still develop a bit. When ready, this fixes #42.
At the CST level this adds a
BLANK_LINE
node type, which may represent multiple consecutive empty lines. The parsing ofrange.end
and for plain valuesvalueRange.end
needed to get adjusted/corrected a bit to allow for this.As a special case, empty lines following block scalar values with "keep" chomping (i.e. with
+
in their header) are considered to be a part of the node value, and therefore won't be parsed asBLANK_LINE
nodes.AST nodes get new
spaceBefore
boolean attributes that represent empty lines. Multiple empty lines are collapsed into one, and empty lines between a node and its preceding comment are dropped. When stringifying, the order in which a node is represented is:spaceBefore
commentBefore
value
comment
Comments at the very beginning that are separated from the rest of the contents with a blank line are captured in the document's
commentBefore
value; similarly top-level comments at the very end are included in itscomment
. When stringifying, these document comments will be separated from the contents where possible. Blank lines at the very beginning and end of the document are trimmed when parsing.I'm considering droppingspaceAfter
as unnecessary (and as of yet only partly implemented), but at least for now the parsing algorithm is pretty greedy, and grabs trailing blank lines into the innermost collection that they could belong to, which effectively requiresspaceAfter
in the AST.Edit:
spaceAfter
is now gone, and blank lines & less-indented comments at collection end now get assigned to the parent collection.Edit 2: Document comments now get automatic spaces, and the document no longer has a
spaceBefore
property.Todo
spaceAfter
or make sure it always works