Insert statements from a weaving rule to a given position in a list

Hey,

I need a weaving rule to insert some statements in a statement list. But this new statements must be inserted previous to the current node. If I just take the block statement as context node the new statement is appended at the end.
I need this because I want to replace some expressions by own declared elements (for example variables). So I must insert the new statement before my current one therefore I can reference it.
2 comments
Comment actions Permalink
jetbrains.mps.baseLanguageInternal.ExtractStatementListExpression does what you need.

The following example
int x = 20;        _ _
string s = "result = " + extract(|  int y = 10;     |=> x + y + z);
   |_ int z = x * y; _|
prettyPrint();
is generated into
int x = 20;
int y = 10;
int z = y * x;
String a = "result = " + (x + y + z);
prettyPrint();
0
Comment actions Permalink
Thanks for this hint! Unfortunately using this concept isn't that easy, if you use your own statementlist and statements. I had to apply my scopes and add a generator script, which extracts the statements but now it works fine.
0

Please sign in to leave a comment.