How to generate dynamically current number of fields in editor?

Well.. I'm writing an SQL language such as MySQL.

In a sandbox I can put in:

create database MyDB;

create table MyDB > MyTable (property1 dbPropertyTypeInteger property2 dbPropertyTypeString);

// when I write "insert" command appropriate number of parameters with appropriate types should be generated. HOW?

insert into talbe MyTable (__emptyCellofTypeInteger__       __emptyCellofTypeString__)

// I think, it could be done with behaviour aspect, but I can't figure out how to import created nodes back into node tree

concept behavior dbRow {

constructor {

  foreach property in this.tableRef.property {

    node<dbField> newField = new node<dbField>(property);

    this.children.add(newField);

  }

}

}

// this doesn't change the editor's output

dbRow:

  children: dbField field 1..n

  reference: dbTable 1

3 comments
Comment actions Permalink

Alexander,

I've tried to do the same thing in MPS - works fine.

This might mean that you are using wrong operations.

I suppose two mistakes could be made:

1) You can't add anything to "children" collection - this won't work. Instead, you should add the new node to a specific child collection. E.g. this.dbField.add(new...)

2) Check that "add" operation is the "add child" operation (see the caption on the right side of completion menu) from smodel language, not "add element" operation from collections language (both are displayed as "add", but behave absolutely different)

Regards,

Mihail

0
Comment actions Permalink

Thanks for your reply

I've tried to use behaviour aspect, but then remembered that it's concstructor is invoked as soon as concept is created.

In my case the construction should be made after one field of my concept is initialized.

...

insert into <tableRef>  (<<..>>)

...

After selecting appropriate tableRef there should appear empty fields of type declared in table->children->dbPropertyType and since that time nobody could change their amount.

I've tried transform action but failed again.

In my former programming practice I could insert something like "I was here!" to see there compiler was and there it wasn't running the program.

Is there a way to do some logging during work with model in a sandbox?

There is a project in attachment



Attachment(s):
DataBaseLanguage.rar.zip
0
Comment actions Permalink

Alexander,

You was right - it seems that constructor is called before the reference is set.

If you need complex node initialization, you can use "node factories". You can look at BL_node_factories for an example.


About logging - we have the logging language for that purposes. If you would like to see when some code is executed, you should import (ctrl+L) this language into your model. After that, you can use "info", "warn" and "error" statements from this language, which will add messages to MPS Messages View.

0

Please sign in to leave a comment.