Replies: 5 comments 13 replies
-
This is the value I see in cue. Previously I've used Eclipse Xtext and Xtend to develop DSLs, from which I could then generate code for various layers (c++, protobuffer definitions, UI components etc). Combining Cue with something equivilant to Eclipse Xtend would allow for generating basically any kind of file - json, sql, etc |
Beta Was this translation helpful? Give feedback.
-
Thanks @verdverm - hof looks excellent! Will try it today! |
Beta Was this translation helpful? Give feedback.
-
I've created a rough command line tool for dumping AST to JSON, and compiling CUE source from JSON, here: |
Beta Was this translation helpful? Give feedback.
-
UpdateI'm having a lot of success using Cuelang as a modeling language to define state machines (still using the cue->json-schema approach). From these models I'm generating executable cpp, diagrams, and TLA+ code for model checking and formal verification of temporal properties. There are two features that would be nice improvements to my cue models:
1. boolean not applied to structsConsider this snippet which shows how I'm composing guard functions:
It would be a lot nicer if I could do:
In cue, this would mean that 2. allow a leading conjunction/disjunction symbolThis would allow long conjunction/disjunction expressions to be formatted like bullet lists. TLA+ has this and although it's a seemingly minor syntax sugar, it is really nice in practice. For example, instead of this:
Being able to do this:
And even better if we could do this:
|
Beta Was this translation helpful? Give feedback.
-
@eadlam: first let's address 2: I see the appeal of such a formatting. It will be very tricky though, for various reasons.
Using the proposed, this could be expected to mean Furthermore, the proposed syntax would ideally be an expression (especially considering the indicated desire to have this nested), but this doesn't play well with the comma elision mechanism. Consider for instance:
Would this be equivalent to The only thing I could imagine is to lead with some kind of escape character, like
vs
This seems quite awkward to me, though. Maybe a compromise solution is to allow
vs
This is more verbose, but the mechanism would be more widely applicable. It is a bit ugly, but at least it has fairly unambiguous semantics. This latter use would also be consistent with the use of |
Beta Was this translation helpful? Give feedback.
-
Originally opened by @myitcv in cuelang/cue#1027
Originally posted in Slack by @eadlam:
I’ve been exploring code generation with cue for the last 6 months. I’ve built a configuration system which defines types in cue and exports those types to capnp. Then I refine those types to fully specified configs which I materialize to json. The generated capnp cpp classes can then load the json.My code generation pipeline is cue->openapi->capnp->cpp. I generate the capnp specs from openapi using Python.In general, I think the ability to represent the cue AST in json is extremely valuable, as it provides a language agnostic interface for code generation.Since OpenAPI is not fully capable of representing the cue AST, I think it would be great to move forward with generating a cue-specific json schema.My next project is to model a whole system in cue and generate state machines and potentially TLA+ code from that model. I believe cue can model systems to the same degree that SysML can, and may provide a viable code-first approach to model based software engineering. A fully compatible json schema would be a huge enabler for this effort.
Response from @mpvl:
Open to proposals how that would look like.
Response from @myitcv:
@eadlam is the AST by itself a sufficient interface for code generation? My suspicion is that it would not be.
Response from @eadlam:
With the current OpenAPI export, I have access to types and partially specified dependent types. With that I believe I can generate hierarchical state machine scaffolding, including states, event types, simple guard functions, pre/post conditions and at least the method signature for more complex action/guard functions.
Although that still leaves the action/guard functions for developers to implement, it’s still a sizable chunk of executable code which also happens to be at the same level of abstraction one needs for model checking.
The remaining actions/guards that the developer implements would be simple functions that take a mutable state object and immutable event object, and update the state in some way. Cue’s partially specified types can then be used to generate tests that the state properties remain within correct bounds.
As I said, I think the OpenAPI spec is actually sufficient to do all this. I imagine I could do more with the AST, but I don’t know that for sure.
I guess there are really two separate things that I'm interested in:
Beta Was this translation helpful? Give feedback.
All reactions