-
Notifications
You must be signed in to change notification settings - Fork 6
Add FormatOptions to format StringNodes as EmbedBlock's
#295
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
Draft
holodorum
wants to merge
20
commits into
kson-org:main
Choose a base branch
from
holodorum:embed-block-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
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.
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
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.
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
embedBlockRulestoFormatOption. During format we create the AST, walk it to find theStringNodesthat should be embed blocks, then pass this to the compile config which will use it to format these nodes as embed blocks.