mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 07:10:41 +01:00
[feat] Add abstract syntax tree modification and write to .pkl file capabilities to language bindings #84
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shiftyp on GitHub (Feb 20, 2024).
Purpose
I'd like to create a wizard application for managing kubernetes manifests, which reads and writes to a set of .pkl files. At the moment it's possible to read from a .pkl file and convert pkl types and primitives to language types and primitives, but I don't see any ability to then write and modify the underlying .pkl files.
Impact
This feature would open up new applications for Pkl in automation contexts. Many programs have wizards for example that create configuration files for users, or have the ability to maintain a configuration file as a feature. This addition to the language bindings would allow Pkl to be used in these contexts, increasing the number of appropriate use cases and adoption of the language.
@bioball commented on GitHub (Feb 22, 2024):
This seems like a hard problem. You would need to understand how a Pkl program turns into data, which is non-trivial. For example:
How would your wizard understand how to modify this program if, say, somebody adds a new pod?
@shiftyp commented on GitHub (Feb 22, 2024):
In the use case I'm looking towards Pkl would be an intermediate format internal to the program, not ingested as an input. So, if the user were to add a pod it would be through the wizard itself, and the wizard would modify the underlying Pkl code, which would then output new manifests. Pkl is attractive as opposed to using plain YAML or JSON and a schema, because it has the potential to make the manifest generation within the wizard more easily maintainable,, testable, extensible, and migratable.
My thinking in the automation context is similar, where Pkl is generated and modified as an intermediate format, or an output format, but not an input format where the automation would need to reverse engineer user generated code. Does that answer the question?
@shiftyp commented on GitHub (Feb 22, 2024):
I imagine there would be other use cases for AST traversal and modification (linting for example) that could ingest and make sense of user generated code however.
@holzensp commented on GitHub (Mar 12, 2024):
If you just want to be static content, you can use
PcfRendererto produce it. Pcf is a static subset of Pkl. Adding aamends "mytemplate.pkl"to the start of a.pcffile (and renaming it to.pkl) essentially gives you all validation right away (some caveats about polymorphism).