Left Transform - Why they behave like they behave?

Hello to everybody! Can you please explain the subject to me? Why left transforms do not give us behavior of a usual text editor? Why it should look like this:
  <caret>1 -> press '+', then '2' -> 2 + 1
?
I'm sure the usual behavior of a text editor was considered and decided to be not implementable. So, why isn't it implementable?
0
6 comments
Which left transform do you have in mind? Is it your own one or one implemented as part of some of the MPS languages?
In principal, nothing should stop you from transforming into 1 + 2.
0
I assume you misread my example. It says that to get binary op expression, you need to go to the left of the wanted right argument, press binary op sign, then type the left argument. That is taken from side transforms tutorial.
0
OK, I see you effectively want MPS to split an integer constant at the current position when you hit '+'.
<caret>1 -> press '2' -> 2<caret>1 -> press '+' -> 2 + 1

Then you may like a sketch of a demo KeyMap I created for a simplified expression language, which does exactly that:

keymap IntegerConstant   
         
everyModel true     
applicable concept: SimpleMathIntegerConstant     
keymap items:            
         
item description : <no description>     
     keystrokes :  <any> + <+>         
     caret policy : INTERMEDIATE_POSITION              
     show in popup : false              
     menu always shown : false         
     is applicable : <always>
         
     execute : (node, selectedNodes, editorContext)->void {

  int index = ((EditorCell_Label) editorContext.getSelectedCell()).getSelectionStart();
  String operator = "+";
  string value = "" + node.value;
  String leftValue = value.substring(0, index);
  String rightValue = value.substring(index);

  node<ArithmeticSimpleMathExpression> arithmeticNode = new initialized node<ArithmeticSimpleMathExpression>();
  node<SimpleMathIntegerConstant> leftNode = new initialized node<SimpleMathIntegerConstant>();
  leftNode.value = Integer.parseInt(leftValue);
  node<SimpleMathIntegerConstant> rightNode = new initialized node<SimpleMathIntegerConstant>();
  rightNode.value = Integer.parseInt(rightValue);
  arithmeticNode.left = leftNode;
  arithmeticNode.operator = operator;
  arithmeticNode.right = rightNode;
  node.replace with(arithmeticNode);
}
;
0
I tried to apply the same principle to BaseLanguage's IntegerConstant, and it seems to work just fine.

PlusBL.png
0
Thanks a lot! I'm actually just learn how to work with MPS so i'll try it a bit later. But that means we can make baseLanguage behave almost just like text at least in part of binary expressions (right?) and that's awesome!
0
It's an on-going battle to give projectional editing a text-like feel. There are also limits to how far it is feasible to go and where to stop and live with the projectional differences.
I'm undecided regarding the discussed ability to seamlessly expand expressions to the left. The keymap-based trick is quite limited and would not allow future language extensions to hook in their additional operators and so they would not benefit from the key-map. While this may be a limitation to BaseLanguage, it may be acceptable for more focused single-purpose expression DSLs, though.
0

Please sign in to leave a comment.