Idea for Middle Transforms

Hello all,

What do you think about expanding side transforms to include a 'middle' option?  The usage would possibly look like this:

int x = 1234;

User did not hit + by accident, so they go back to fix.

int x = 12<carat>34;

User hits +.  Currently, this results in red text, since + is not valid in an integer literal.

int x = 12+34;

  • statement: <type> <var>;
    • localVariableDeclaration: x
      • type: int
      • initializer: integer constant (12+34)

With a 'middle transform', one could modify the AST when invalid characters were written in the middle, perhaps in this case something like:

side transform actions binaryAdd

     middle transformed node: IntegerConstant ...

     ...

     actions :

          add custom items (output concept: PlusExpression)

               simple item

                     matching text

                          +

                     ...

                     do transform

                         (operationContext, scope, model, sourceNode, leftPattern, rightPattern)->node< > {

                              node<PlusExpression> additionNode = new node<PlusExpression>();

                              node<IntegerConstant> lval = new Node<IntegerConstant>();

                              node<IntegerConstant> rval = new Node<IntegerConstant>();

                              lval.value = Integer.parseInt(leftPattern);

                              rval.value = Integer.parseInt(rightPattern);

                              additionNode.leftExpression = lval;

                              additionNode.rightExpression = rval;

                              sourceNode.replace with(additionNode);

                              return additionNode;

                         }

Now, when the user hits +, they would get the following:

  • statement: <type> <var>;
    • localVariableDeclaration: x
      • type: int
      • initializer: +
        • leftExpression: integer (12)
        • rightExpression: integer (34)

What do you think of this idea?

Thanks,

Robert

2 comments
Comment actions Permalink

Robert,

Unfrotunately, a solution which you proposed won't work. We might have a lot of option (integer constant, variable references, float constant, expressions from language extensions) on the left and on the right, and code in the actions aspect should take into account both sides. However, ability to type code in the middle of a cell is a very useful thing, and we will thing about implementing it.

Regards,

Konstantin

0
Comment actions Permalink

Hello, Konstantin,

Thanks for your response - that is true, what I proposed probably wouldn't work well for anything but very simple scenarios.  Typing code in the middle of a cell was the goal, though, so I am happy to hear it will be considered! :-)

Thanks!

Robert

0

Please sign in to leave a comment.