Repository navigation
Conversation
Author
|
You can try a VS Code extended grammar and language server that supports Further instructions here: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Its homepage introduces KDL as a document language that “looks like you're invoking a bunch of CLI commands.” Piping follows naturally from that pitch: if nodes look like commands, pipes are the missing piece for expressing composition in a familiar, fluent way.
Node pipes let you write deeply nested single-child structures as a left-to-right chain.
This can be enabled with the
experimentalNodePipesparser flag. Documents using it are not valid KDL for other parsers.Usage:
Semantics
A #> Bis equivalent toB { A }: the node on the left becomes the sole child of the node on the right.Chains are left-associative:
A #> B #> Cis equivalent toC { B { A } }.The left-hand side of
#>is always a single node, which may have children of its own:The right-hand side of
#>cannot have a children block.text "Hello" #> padding 8 { border }is invalid. Use the nested form instead.The parsed document is identical to the nested form: queries, (de)serialization, and all other APIs see regular nested nodes.
The
#>token#>is a pipe wherever it appears between nodes, with or without surrounding whitespace:a #> b,a#>b, anda #>bare all equivalent.Parsers without this extension reject documents that use node pipes.
Enabling the flag doesn't change the meaning of any valid KDL document, and the rules about when strings must be quoted are unchanged.
When the
experimentalSuffixedNumbersflag is also enabled,#>immediately after a number is parsed as a number suffix.In
loop 4#> ease,4has the suffix tag>.Add whitespace before the pipe in that case:
loop 4 #> ease.Other candidate tokens considered:
|>->>>:>~>=>a=">"/>>//,/*and/-\>\, which continues a line in KDL]>[and]are reserved[and]for its own future useOnly tokens that currently produce an error are safe: parsers without the feature reject documents that use the token.
#>won over those because:#can't appear in identifiers, so it needs no whitespace rule and no change to the quoting rules./-#>works with no special case.#already marks special syntax in KDL v2, as in#true,#nulland#"raw"#.Multiline chains
Chains can span multiple lines, with
#>either ending a line or starting the next one:Blank lines and comments are allowed between stages.
A line break never changes the meaning of a chain: a leading
#>always continues the node right before it.A semicolon ends the chain:
a; #> bis an error, as is a#>at the start of a document or children block.Slashdash
A slashdash before the first node of a chain comments out the entire chain:
A slashdash before a
#>comments out that single stage:Formatting
Parsing a pipe chain retains the pipe formatting, so
format(parse(text))writes the chain back as it was written.The pipe form is only preserved while the node still has exactly one child, and that child is the same node object it was parsed with.
Editing that child in place (e.g. adding an argument) keeps the pipe form.
Removing the child, adding a second child, or replacing it with another node makes the formatter write the nested form instead.
There's no API to create pipe chains in code: pipe formatting only ever comes from parsing.
Both
clearFormat()andformatCompact()drop pipe formatting and yield the nested form, which is valid KDL for any parser.Locations
When
storeLocationsis enabled, the location of each node in a chain covers only that node's own text.For
text "Hello" #> padding 8, thepaddingnode's location spanspadding 8, and thetextnode's location spanstext "Hello".Whitespace
Slashdashed stages are retained as part of the surrounding whitespace.
Parsing that whitespace with
parse(text, {as: "whitespace in document"})yields a part{type: "slashdash", pipe: true, preface, value}wherevalueis the commented-out node.Limitations
Only supported by the KDL v2 parser.