[Pharo-users] RBPattern syntax

Henrik Sperre Johansen henrik.s.johansen at veloxit.no
Tue Feb 19 08:04:14 EST 2019


Manuel Leuenberger wrote
> Hi,
> 
> I am looking into the RB pattern language for refactoring and I am having
> trouble matching and replacing non-trivial pattern. Given the following
> excerpt, I want to match "b shape 
> <rest>
> ." and replace it with "b shape: [ :x | x 
> <rest>
>  ]"
> 
> 	b shape circle
> 		size: 15;
> 		color: (Color veryLightGray alpha: 0.4);
> 		if: [ :value | toBeRed includes: value ] fillColor: Color red.
> 
> How can I do this? I tried using "b shape ``@messages", but this only
> matches "b shape circle". Using "b shape `message `;middle; `;last" for
> some reason then also matches the following, which I think it should not:
> 
> 	b edges
> 		moveBehind;
> 		connectToAll: [ :v | 
> 			v \\ 20 ~~ 0
> 				ifTrue: [ Array with: v + 1 with: v + 20 ]
> 				ifFalse: [ Array with: v + 20 ] ].
> 
> There seems not be too much documentation about the pattern language, only
> found tests, some short help description from RB and Yuriy's MatchTool.
> How can I match the node correctly?
> 
> Cheers,
> Manuel

The best documentation is at https://refactory.com/rewrite-tool/
What isn't covered, is cascade nodes (`@;messages1), but my first naive
attempt did not work as I expected on your example;
'(b shape `@method: `@keywords) 
   @;messages1: `@args'
-> 
'b shape: [ :x |  
   (x `@method: `@keywords) 
      @;messages1: `@args ]'

b shape circle
   size: 15;
   color: (Color veryLightGray alpha: 0.4);
   if: [ :value | toBeRed includes: value ] fillColor: Color red
->
b
   shape: [ :x | x circle size: 15 ];
   shape: [ :x | x circle color: (Color veryLightGray alpha: 0.4) ];
   shape: [ :x | x circle if: [ :value | toBeRed includes: value ]
fillColor: Color red ]



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



More information about the Pharo-users mailing list