Editor for a reference with variable number of components in a child

Hi, everyone!

I've recently started learning MPS and I find it to be an amazing platform and also the elephant in the room when it comes to projectional editors. The experience has been very smooth so far, helped tremendously by Václav Pech's recordings. But, obviously, I hit a road block, which is why I'm asking for your help here.

Consider a language which has the notions of function definitions and function calls, but with very lax syntactic requirements. A function definition can be *any* piece of text interspersed with parameter holes. Similarly, a function call is that piece of text, where the parameter holes have been filled in with parameter values. For example:

Function definition (parameter holes are demarcated by angle brackets, everything else is the function name):

defn: Draw line from point (x: <x0>, y: <y0>) to point (x: <x1>, y: <y1>)

Function call:
Draw line from point (x: 0, y: 0) to point (x: 42, y: 42)

Implementing the editor for the definition part was relatively straightforward. I have a `FunctionDefinition` concept with a single child called `parts` which contains `[1..n]` `DefinitionPart`s. A `DefinitionPart` can be either a `ConstantPart` (a string part of the function name) or a `ParameterPart`. This allows me to write a function's name as any sequence of constant parts intercalated with parameter parts.

What I don't know is how to implement the `FunctionCall` editor. The end result should be something like this. In a function call position, when the user hits CTRL+SPACE, they should get a list of existing function definitions. When they choose one, the function name should be inserted, with the parameter holes replaced by placeholder cells. Like this:

Draw line from point (x: << ... >>, y: << ... >>) to point (x: << ... >>, y: << ... >>)

My `FunctionCall` concept references a `FunctionDefinition` concept, which achieves auto-completion without problems, but I don't know how to model the `children` property of the concept and the concept's associated editor. Presumably, it should contain an `actualArguments` child that holds a `[0..n]` of some concept denoting arguments. What I find really hard is displaying an editor that contains the same number of parameter placeholders as the `FunctionDefinition` reference, and also how to map this fixed number to the `[0..n]` cardinality of the `actualArguments` child.

Maybe I'm overcomplicating things or I'm missing something really obvious, however, I'd really like to obtain the UX I've mentioned above. The auto-completed function reference should display the parameter placeholder for however many parameters the function definition has specified.

Any pointers, ideas or suggestions are welcome. Thanks!

Please sign in to leave a comment.