Skip to content

Conversation

@holodorum
Copy link
Collaborator

Let's say we have a YAML file that contains a multiline string that actually is embedded code. It should be relatively easy to format this as a KSON embed block (optionally with a tag).

This commit allows us to do that. The beauty is that when you want to go back from your KSON document (with the multiline string as embedblock), you can transpile to YAML/JSON without retaining the embed tags. That means your data can stay the same through a roundtrip, but you can benefit from better tooling while working on this embedded code.

The way it's implemented is by adding embedBlockRules to FormatOption. During format we create the AST, walk it to find the StringNodes that should be embed blocks, then pass this to the compile config which will use it to format these nodes as embed blocks.

Navigation of the document was done with JsonPointer
 tokens. Which was a list of Strings. Instead this has been
 refactored to use a `JsonPointer` class.
`JsonPointer`doesn't allow wildcards in the pointer. That is
not an issue for `JsonPointer`'s in a schema. However, if we
want to navigate a KsonValue using more expressive pointers we
can't.

Options to deal with this would be using `JsonPath`, `JmsePath`.
However, before we commit to that I'd propose we use a simple
improvement of `JsonPointer`, namely `JsonPointerPlus`. It adds
the possibility to use wildcards `*`, and glob matching for a
property key (only with ? (matching a single character) and *
(matching all characters)).
JsonPointerPlus can now be used to navigate `KsonValues`'s!
We want to create our own JsonPointer language which extends the
JsonPointer language from RFC 6901 with glob pattern matching.
The name JsonPointerGlob captures that intention better.
used `*` spelled out before because it gave issues with kotlin
documentation. By escaping one of the `**` we don't run into this
anymore
literal tokens in JsonPointerGlob need to be escaped
The doc contained an ambiguity where we escaped `/**` with `/\*\*` to
prevent starting a new commnet block. However, that's also the way one
would escape the asterisk in `JsonPointerGlob`.
the recursive descent was returned early which might surprise us in the
future as @dmarcotte pointed out. This refactor makes it more explicit
that `RecursiveDescent` tokens are handled differently from the other
tokens.
Even though the language of `JsonPointerGlob` seems sensible and
intuitive it could well be that we need to update and tweak it a bit.
To signal that I've added an Experimental-annotation we opt-in to.
Let's say we have a YAML file that contains a multiline string that
actually is embedded code. It should be relatively easy to format this
as a KSON embed block (optionally with a tag).

This commit allows us to do that. The beauty is that when you want to go
back from your KSON document (with the multiline string as embedblock),
you can Transpile to YAML without retaining the embed tags. That means
your data can stay the same through a roundtrip, but you can benefit
from better tooling while working on this embedded code.

The way it's implemented is by adding `embedBlockRules` to
`FormatOption`. During format we create the AST, walk it to find the
StringNodes that should be embed blocks, then pass this to the compile
config which will use it to format these nodes as embed blocks.
@holodorum
Copy link
Collaborator Author

Note: this will currently fail since Krossover does not support lists yet. I've opened a PR that adds support for lists, the tests pass when I used a locally published version of that branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant