Use "(" or "[" inside the generator

Hello everyone! I'm using JetBrains MPS 2022

I want to generate this code:

<ion-radio-group [(ngModel)]="question1">
      <ion-list-header>
        <ion-label>Question 1: Is this ok?</ion-label>
      </ion-list-header>
      <ion-item>
        <ion-label>Yes</ion-label>
        <ion-radio slot="start" value="Yes"></ion-radio>
      </ion-item>
      <ion-item>
        <ion-label>No</ion-label>
        <ion-radio slot="start" value="No"></ion-radio>
      </ion-item>
    </ion-radio-group>
 
I have managed to get an output in XML with that code except for the ngModel, which I am not able to put "[(" inside an element. I have this:
 
<ion-content>  
<ion-radio-group ngModel="question1">
<ion-list-header>
<ion-label>Is this work?</ion-label>

</ion-list-header>
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio slot="start" value="Yes"></ion-radio>
</ion-item>
<ion-item>
<ion-label>No</ion-label>
<ion-radio slot="start" value="No"></ion-radio>
</ion-item>

</ion-radio-group>
</ion-content>
0
7 comments
Official comment

If. you only need it in the generator templates, you can perhaps use a quick and dirty way to use a property macro the generate the desired name of the attribute. See the datamodel attribute in the picture below:

If you also want to be able to edit attributes with these values in user models (aka in sandbox), then there's more work to do.

!. You have to extend the core.xml language with your own subconcept of XmlAttribute.

2. Change the constraint that validates names of attributes:

3. And finally you have to tap into the substitute menus to ensure your new concept is presented in the completion menus at the right moments:

4. Also a slightly customized substitute menu of XmlAttribute could be added, for example, like this:

Do not forget to import the new language (Control + L) in the models where you want to use your new concept.

This is because the characters such as "[" and "(" are not legal as names in XML. The j.m.core.xml language enforces these rules in the editor.

0

Is there a way to modify the editor so that it accepts it?

0

Vaclav!  You are the best!

Thanks u very much! I used the first one! All is perfect!

0

It looks like you want to use parentheses "(" or square brackets "[" inside a generator. Generators are often used in programming to create sequences of values on-the-fly, like in list comprehensions or when iterating over large datasets sorteo tris de hoy. The syntax for using "(" or "[" inside a generator might differ based on the programming language you are using. Here, I'll provide examples in Python

0

The formula for calculating the area of a rectangle is (length x width), where 'length' represents the length of the rectangle, and 'width' represents the width of the rectangle with How to record

In this sentence, parentheses are used to enclose the mathematical formula, and square brackets are used to provide explanations for the variables within the formula.

0

Please sign in to leave a comment.