-
Notifications
You must be signed in to change notification settings - Fork 6
YAML as a Kson compilation target #80
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
Merged
Merged
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
Fix typo so that we're properly noting that _trailing_ comments are discouraged, not line comments
An essential and long-anticipated piece of the puzzle: Kson now compiles to Yaml. This is anticipated to be one of the main ways Kson is integrated into existing systems: as a better interface on existing Yaml interfaces. Notes on other compilation targets not yet implemented: - Json compilation is also planned and should follow fairly well from the work in this commit - Compiling directly to native objects on each platform is also naturally coming at some point, though the Yaml and Json transpilations take priority since they are fully interoperable with existing systems, and hence immediately beneficial
Validate that the compiled YAML we're verifying in our tests is, in fact, legal Yaml. We may need deeper verifications at some point, but for now this is a good guardrail against accidentally writing bad/invalid Yaml compilation tests
Since we finished refactoring all errors out of the lexer in ede3d3b, `messageSink` is always guaranteed to have no errors from the Lexer, so both conditional check and the `// parsing failed at the lexing stage` comment are stale and possibly confusing. Clean this up for clarity.
Parsing to Yaml will be a common use case for Kson, so expose it clearly in our public interface in `Kson.parseToYaml`
Fix a couple of typos and have some second thoughts on the working in this comment. I believe these edits improve the clarity.
The [NumberFormatException] reference stopped resolving correctly after the recent Kotlin upgrade and the warning it created prompted me to improve what this comment was trying to accomplish: Replace the comment with an explicit and helpful RuntimeException to better communicate our expectations if/when anyone ever trips on this. A developer accidentally tripping this may have missed the comment, but the new exception really captures the semantics of `NumberNode`'s demand to only be given strings which are guaranteed to parse as `Double`
Rather than check the `yamlResult` produced by our compiler, we instead check the `expectedYaml` created by the test writer We want to tell the test writer they are expecting illegal Yaml as early as possible so they can fix their expectations rather than mistakenly adjust the underlying code to try to satisfy an invalid expectation
The content of our StringNode and IdentifierNode is better named `stringContent` since these are strings that sometimes conform to the unquoted "identifier" syntax, but always contain string content. `keyword` was especially misleading in the content of StringNode
When compiling to Yaml, we need to preserve leading whitespace, no matter what, even on blank/all-whitespace lines. Fix and test.
When compiling Kson to YAML, embed blocks are normally compiled to multiline strings since a primary use case for the embed tags is to facilitate better editor tooling, especially in the case of embedded code, so to use Kson as an interface on some Yaml that expects code embedded in multiline strings, Kson's embed blocks must collapse down to Yaml multiline string. However, the embed tag metadata is valuable, so this provides an option, `retainEmbedTags`, to preserve it in our compiled Yaml. With this enabled, embed blocks with an embed tag compile to Yaml objects like this: ```yaml embedTag: "sql" embedContent: | select from table ```
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.
An essential and long-anticipated piece of the puzzle: Kson now compiles to Yaml (including preserving the input's Kson comments in the compiled Yaml output!). This is expected to be one of the main ways Kson is initially integrated into existing systems: as a better interface on existing Yaml interfaces.
Notes on other compilation targets not yet implemented:
The heart of the work is in cfe0d6c, with the surrounding commits being a mix of shoring up this support and improving a few small things spotted around the project while implementing this.