freon4dsl / Freon4dsl

Web Native language Workbench with Projectional Web Editor
https://www.freon4dsl.dev
MIT License
63 stars 9 forks source link

Initialize model-unit #324

Open globallyunique opened 3 months ago

globallyunique commented 3 months ago

How can some concepts be created automatically when an instance of a model-unit is created, e.g., add a blank item to a list so the user doesn't need to add it.

joswarmer commented 3 months ago

The only place to do this is in the generated code, there is no standard way to do this. To support this in a way that does not toch the generated code we would e.g have to insert some kind of call back function in the generated code or something similar.

dslmeinte commented 3 months ago

I think an optional callback would be good to have, or maybe an optional custom factory? You could even define an instance template next to the DSL's structure definition (in .ast or next to it).

joswarmer commented 3 months ago

We probably need many more "tuning" options indeed.

joswarmer commented 3 months ago

Another option is using the generation gap pattern, this allows for all kind of tuning of the AST code, not just for initialization.

globallyunique commented 3 months ago

Before I go down a path that isn't possible, for now, could I create a custom Box Provider that is a sub-class of the generated provider, switch my Box provider to be used by changing the mapping in CustomXXXnModelProjection, and override the getContent method to do something like check if there is anything in the model and if not add it?

joswarmer commented 3 months ago

This should not be done on the box providers, they are only used by the editor, so won't change the model unless it is opened in the editor. They are also not meant to be replaced, not even sure what will happen if you do.

joswarmer commented 3 months ago

@dslmeinte An optional factory is also an option indeed. And defining a template is also interesting, but less flexible as you cannot add code easily (unless treated as text).

dslmeinte commented 3 months ago

@joswarmer Exactly: a programmatic (i.e., coded in a GPL) custom optional factory is the most flexible option.

joswarmer commented 3 months ago

Actually the generation gap pattern is even more flexible as it allows not only the initialisation to be adjusted but everything else as well.

joswarmer commented 1 month ago

Mandatory children that have only one possible concrete concept type are now added automatically with their parent.

joswarmer commented 1 month ago

For now the creation of mandatory children solves the main problem, we don't plan to make this generic as described above.